+ def OnAddDirToProject(self, event):
+ frame = wx.Dialog(None, -1, _("Add All Files from Directory to Project"), size= (320,200))
+ borderSizer = wx.BoxSizer(wx.HORIZONTAL)
+
+ contentSizer = wx.BoxSizer(wx.VERTICAL)
+ lineSizer = wx.BoxSizer(wx.HORIZONTAL)
+ lineSizer.Add(wx.StaticText(frame, -1, _("Directory:")), 0, wx.ALIGN_CENTER | wx.RIGHT, HALF_SPACE)
+ dirCtrl = wx.TextCtrl(frame, -1, os.path.dirname(self.GetDocument().GetFilename()), size=(200,-1))
+ dirCtrl.SetToolTipString(dirCtrl.GetValue())
+ lineSizer.Add(dirCtrl, 0, wx.LEFT, HALF_SPACE)
+ findDirButton = wx.Button(frame, -1, "Browse...")
+ lineSizer.Add(findDirButton, 0, wx.LEFT, HALF_SPACE)
+ contentSizer.Add(lineSizer, 0, wx.BOTTOM, SPACE)
+
+ def OnBrowseButton(event):
+ dlg = wx.DirDialog(frame, _("Choose a directory:"), style=wx.DD_DEFAULT_STYLE)
+ dir = dirCtrl.GetValue()
+ if len(dir):
+ dlg.SetPath(dir)
+ if dlg.ShowModal() == wx.ID_OK:
+ dirCtrl.SetValue(dlg.GetPath())
+ dirCtrl.SetToolTipString(dirCtrl.GetValue())
+ dirCtrl.SetInsertionPointEnd()
+
+ dlg.Destroy()
+ wx.EVT_BUTTON(findDirButton, -1, OnBrowseButton)
+
+ visibleTemplates = []
+ for template in self.GetDocumentManager()._templates:
+ if template.IsVisible():
+ visibleTemplates.append(template)
+
+ choices = []
+ allfilter = ''
+ descr = ''
+ for template in visibleTemplates:
+ if len(descr) > 0:
+ descr = descr + _('|')
+ allfilter = allfilter + _(';')
+ descr = template.GetDescription() + _(" (") + template.GetFileFilter() + _(")")
+ choices.append(descr)
+ allfilter = allfilter + template.GetFileFilter()
+ choices.insert(0, _("All (%s)") % allfilter)
+ filterChoice = wx.Choice(frame, -1, size=(210, -1), choices=choices)
+ filterChoice.SetSelection(0)
+ filterChoice.SetToolTipString(_("Select file type filter."))
+ lineSizer = wx.BoxSizer(wx.HORIZONTAL)
+ lineSizer.Add(wx.StaticText(frame, -1, _("Files of type:")), 0, wx.ALIGN_CENTER | wx.RIGHT, HALF_SPACE)
+ lineSizer.Add(filterChoice, 1, wx.LEFT, HALF_SPACE)
+ contentSizer.Add(lineSizer, 0, wx.BOTTOM|wx.EXPAND, SPACE)
+
+ subfolderCtrl = wx.CheckBox(frame, -1, _("Add files from subdirectories"))
+ subfolderCtrl.SetValue(True)
+ contentSizer.Add(subfolderCtrl, 0, wx.BOTTOM, SPACE)
+
+ borderSizer.Add(contentSizer, 0, wx.TOP|wx.BOTTOM|wx.LEFT, SPACE)
+
+ buttonSizer = wx.BoxSizer(wx.VERTICAL)
+ findBtn = wx.Button(frame, wx.ID_OK, _("Add"))
+ findBtn.SetDefault()
+ buttonSizer.Add(findBtn, 0, wx.BOTTOM, HALF_SPACE)
+ buttonSizer.Add(wx.Button(frame, wx.ID_CANCEL), 0)
+ borderSizer.Add(buttonSizer, 0, wx.ALL, SPACE)
+
+ frame.SetSizer(borderSizer)
+ frame.Fit()
+
+ status = frame.ShowModal()
+
+ passedCheck = False
+ while status == wx.ID_OK and not passedCheck:
+ if not os.path.exists(dirCtrl.GetValue()):
+ dlg = wx.MessageDialog(frame,
+ _("'%s' does not exist.") % dirCtrl.GetValue(),
+ _("Find in Directory"),
+ wx.OK | wx.ICON_EXCLAMATION
+ )
+ dlg.ShowModal()
+ dlg.Destroy()
+
+ status = frame.ShowModal()
+ else:
+ passedCheck = True
+
+ if status == wx.ID_OK:
+ frame.Destroy()
+
+ wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
+
+ doc = self.GetDocument()
+ searchSubfolders = subfolderCtrl.IsChecked()
+ dirString = dirCtrl.GetValue()
+
+ if os.path.isfile(dirString):
+ # If they pick a file explicitly, we won't prevent them from adding it even if it doesn't match the filter.
+ # We'll assume they know what they're doing.
+ paths = [dirString]
+ else:
+ paths = []
+
+ index = filterChoice.GetSelection()
+ if index:
+ template = visibleTemplates[index-1]
+
+ # do search in files on disk
+ for root, dirs, files in os.walk(dirString):
+ if not searchSubfolders and root != dirString:
+ break
+
+ for name in files:
+ if index == 0: # all
+ for template in visibleTemplates:
+ if template.FileMatchesTemplate(name):
+ filename = os.path.join(root, name)
+
+ # if already in project, don't add it, otherwise undo will remove it from project even though it was already in it.
+ if doc.IsFileInProject(filename):
+ break
+
+ paths.append(filename)
+ break
+ else: # use selected filter
+ if template.FileMatchesTemplate(name):
+ filename = os.path.join(root, name)
+ # if already in project, don't add it, otherwise undo will remove it from project even though it was already in it.
+ if not doc.IsFileInProject(filename):
+ paths.append(filename)
+
+ wx.GetApp().GetTopWindow().SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
+
+ doc.GetCommandProcessor().Submit(ProjectAddFilesCommand(doc, paths))
+ self.Activate(True) # after add, should put focus on project editor
+ else:
+ frame.Destroy()
+
+