📄 projecteditor.py
字号:
wsdlDoc = serviceRef.ideDocument
if wsdl and wsdlDoc:
modified = False
# add schema namespace to wsdl file
for schemaRef in schemaRefs:
schema = schemaRef.document
if schema and schema.fileName in filePaths:
schemaLongNS = schema.targetNamespace
schemaShortNS = self.GetAppDocMgr().findShortNS(schemaLongNS)
if not schemaShortNS:
schemaShortNS = xmlutils.genShortNS(wsdl, schemaLongNS)
xmlutils.addNSAttribute(wsdl, schemaShortNS, schemaLongNS)
modified = True
if modified:
wsdlDoc.OnSaveDocument(wsdlDoc.GetFilename())
class NewProjectWizard(Wizard.BaseWizard):
WIZTITLE = _("New Project Wizard")
def __init__(self, parent):
self._parent = parent
self._fullProjectPath = None
Wizard.BaseWizard.__init__(self, parent, self.WIZTITLE)
self._projectLocationPage = self.CreateProjectLocation(self)
wx.wizard.EVT_WIZARD_PAGE_CHANGING(self, self.GetId(), self.OnWizPageChanging)
def CreateProjectLocation(self,wizard):
page = Wizard.TitledWizardPage(wizard, _("Name and Location"))
page.GetSizer().Add(wx.StaticText(page, -1, _("\nEnter the name and location for the project.\n")))
self._projectName, self._dirCtrl, sizer, self._fileValidation = UICommon.CreateDirectoryControl(page, fileExtension="agp", appDirDefaultStartDir=True, fileLabel=_("Name:"), dirLabel=_("Location:"))
page.GetSizer().Add(sizer, 1, flag=wx.EXPAND)
wizard.Layout()
wizard.FitToPage(page)
return page
def RunWizard(self, existingTables = None, existingRelationships = None):
status = Wizard.BaseWizard.RunWizard(self, self._projectLocationPage)
if status:
wx.ConfigBase_Get().Write(PROJECT_DIRECTORY_KEY, self._dirCtrl.GetValue())
docManager = wx.GetApp().GetTopWindow().GetDocumentManager()
if os.path.exists(self._fullProjectPath):
# What if the document is already open and we're overwriting it?
documents = docManager.GetDocuments()
for document in documents:
if os.path.normcase(document.GetFilename()) == os.path.normcase(self._fullProjectPath): # If the renamed document is open, update it
document.DeleteAllViews()
break
os.remove(self._fullProjectPath)
for template in docManager.GetTemplates():
if template.GetDocumentType() == ProjectDocument:
doc = template.CreateDocument(self._fullProjectPath, flags = wx.lib.docview.DOC_NEW)
doc.OnSaveDocument(self._fullProjectPath)
projectService = wx.GetApp().GetService(ProjectService)
view = projectService.GetView()
view.AddProjectToView(doc)
break
self.Destroy()
return status
def OnWizPageChanging(self, event):
if event.GetDirection(): # It's going forwards
if event.GetPage() == self._projectLocationPage:
if not self._fileValidation(validClassName=True):
event.Veto()
return
self._fullProjectPath = os.path.join(self._dirCtrl.GetValue(),UICommon.MakeNameEndInExtension(self._projectName.GetValue(), PROJECT_EXTENSION))
def OnShowCreatePages(self):
self.Hide()
import DataModelEditor
requestedPos = self.GetPositionTuple()
projectService = wx.GetApp().GetService(ProjectService)
projectView = projectService.GetView()
wiz = DataModelEditor.ImportExportWizard(projectView.GetFrame(), pos=requestedPos)
if wiz.RunWizard(dontDestroy=True):
self._schemaName.SetValue(wiz.GetSchemaFileName())
wiz.Destroy()
self.Show(True)
class ProjectTemplate(wx.lib.docview.DocTemplate):
def CreateDocument(self, path, flags):
if path:
doc = wx.lib.docview.DocTemplate.CreateDocument(self, path, flags)
if path:
doc.GetModel()._projectDir = os.path.dirname(path)
return doc
else:
wiz = NewProjectWizard(wx.GetApp().GetTopWindow())
wiz.RunWizard()
wiz.Destroy()
return None # never return the doc, otherwise docview will think it is a new file and rename it
class ProjectAddFilesCommand(wx.lib.docview.Command):
def __init__(self, projectDoc, filePaths, folderPath=None, types=None, names=None):
wx.lib.docview.Command.__init__(self, canUndo = True)
self._projectDoc = projectDoc
self._allFilePaths = filePaths
self._folderPath = folderPath
self._types = types
self._names = names
if not self._types:
self._types = []
projectService = wx.GetApp().GetService(ProjectService)
for filePath in self._allFilePaths:
self._types.append(projectService.FindFileTypeDefault(filePath))
# list of files that will really be added
self._newFiles = []
for filePath in self._allFilePaths:
if not projectDoc.GetModel().FindFile(filePath):
self._newFiles.append(filePath)
def GetName(self):
if len(self._allFilePaths) == 1:
return _("Add File %s") % os.path.basename(self._allFilePaths[0])
else:
return _("Add Files")
def Do(self):
return self._projectDoc.AddFiles(self._allFilePaths, self._folderPath, self._types, self._names)
def Undo(self):
return self._projectDoc.RemoveFiles(self._newFiles)
class ProjectRemoveFilesCommand(wx.lib.docview.Command):
def __init__(self, projectDoc, files):
wx.lib.docview.Command.__init__(self, canUndo = True)
self._projectDoc = projectDoc
self._files = files
def GetName(self):
if len(self._files) == 1:
return _("Remove File %s") % os.path.basename(self._files[0].filePath)
else:
return _("Remove Files")
def Do(self):
return self._projectDoc.RemoveFiles(files=self._files)
def Undo(self):
return self._projectDoc.AddFiles(files=self._files)
class ProjectRenameFileCommand(wx.lib.docview.Command):
def __init__(self, projectDoc, oldFilePath, newFilePath, isProject = False):
wx.lib.docview.Command.__init__(self, canUndo = True)
self._projectDoc = projectDoc
self._oldFilePath = oldFilePath
self._newFilePath = newFilePath
self._isProject = isProject
def GetName(self):
return _("Rename File %s to %s") % (os.path.basename(self._oldFilePath), os.path.basename(self._newFilePath))
def Do(self):
return self._projectDoc.RenameFile(self._oldFilePath, self._newFilePath, self._isProject)
def Undo(self):
return self._projectDoc.RenameFile(self._newFilePath, self._oldFilePath, self._isProject)
class ProjectRenameFolderCommand(wx.lib.docview.Command):
def __init__(self, doc, oldFolderPath, newFolderPath):
wx.lib.docview.Command.__init__(self, canUndo = True)
self._doc = doc
self._oldFolderPath = oldFolderPath
self._newFolderPath = newFolderPath
def GetName(self):
return _("Rename Folder %s to %s") % (os.path.basename(self._oldFolderPath), os.path.basename(self._newFolderPath))
def Do(self):
return self._doc.RenameFolder(self._oldFolderPath, self._newFolderPath)
def Undo(self):
return self._doc.RenameFolder(self._newFolderPath, self._oldFolderPath)
class ProjectAddFolderCommand(wx.lib.docview.Command):
def __init__(self, view, doc, folderpath):
wx.lib.docview.Command.__init__(self, canUndo = True)
self._doc = doc
self._view = view
self._folderpath = folderpath
def GetName(self):
return _("Add Folder %s") % (os.path.basename(self._folderpath))
def Do(self):
if self._view.GetDocument() != self._doc:
return True
status = self._view.AddFolder(self._folderpath)
if status:
self._view._treeCtrl.UnselectAll()
item = self._view._treeCtrl.FindFolder(self._folderpath)
self._view._treeCtrl.SelectItem(item)
return status
def Undo(self):
if self._view.GetDocument() != self._doc:
return True
return self._view.DeleteFolder(self._folderpath)
class ProjectRemoveFolderCommand(wx.lib.docview.Command):
def __init__(self, view, doc, folderpath):
wx.lib.docview.Command.__init__(self, canUndo = True)
self._doc = doc
self._view = view
self._folderpath = folderpath
def GetName(self):
return _("Remove Folder %s") % (os.path.basename(self._folderpath))
def Do(self):
if self._view.GetDocument() != self._doc:
return True
return self._view.DeleteFolder(self._folderpath)
def Undo(self):
if self._view.GetDocument() != self._doc:
return True
status = self._view.AddFolder(self._folderpath)
if status:
self._view._treeCtrl.UnselectAll()
item = self._view._treeCtrl.FindFolder(self._folderpath)
self._view._treeCtrl.SelectItem(item)
return status
class ProjectMoveFilesCommand(wx.lib.docview.Command):
def __init__(self, doc, files, folderPath):
wx.lib.docview.Command.__init__(self, canUndo = True)
self._doc = doc
self._files = files
self._newFolderPath = folderPath
self._oldFolderPaths = []
for file in self._files:
self._oldFolderPaths.append(file.logicalFolder)
def GetName(self):
if len(self._files) == 1:
return _("Move File %s") % os.path.basename(self._files[0].filePath)
else:
return _("Move Files")
def Do(self):
return self._doc.MoveFiles(self._files, self._newFolderPath)
def Undo(self):
return self._doc.MoveFiles(self._files, self._oldFolderPaths)
class ProjectTreeCtrl(wx.TreeCtrl):
#----------------------------------------------------------------------------
# Overridden Methods
#----------------------------------------------------------------------------
def __init__(self, parent, id, style):
wx.TreeCtrl.__init__(self, parent, id, style = style)
templates = wx.GetApp().GetDocumentManager().GetTemplates()
iconList = wx.ImageList(16, 16, initialCount = len(templates))
self._iconIndexLookup = []
for template in templates:
icon = template.GetIcon()
if icon:
if icon.GetHeight() != 16 or icon.GetWidth() != 16:
icon.SetHeight(16)
icon.SetWidth(16)
if wx.GetApp().GetDebug():
print "Warning: icon for '%s' isn't 16x16, not crossplatform" % template._docTypeName
iconIndex = iconList.AddIcon(icon)
self._iconIndexLookup.append((template, iconIndex))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -