def _createToolBar(self, parent): self.toolBarModel = self._createToolBarModel() self.toolBarContext = ZStandardPerspectiveToolBarActionContext(parent, self.currentViewSelection) contentProvider = ZModelBasedToolBarContentProvider(self.toolBarModel, self.toolBarContext) eventHandler = ZModelBasedToolBarEventHandler(self.toolBarModel, self.toolBarContext) self.toolBar = ZPersistentToolBar(self._getUserPrefsKey() + u".toolbar", contentProvider, eventHandler, parent, ZToolBar.STYLE_SHOW_TEXT) #$NON-NLS-1$ self.toolBarStaticLine = wx.StaticLine(parent, wx.ID_ANY)
def __init__(self, prefsId, model, parent, style = 0, context = None): toolBarContext = None if context is not None: toolBarContext = context else: toolBarContext = ZToolBarActionContext(self) self.contentProvider = ZModelBasedToolBarContentProvider(model, toolBarContext) self.eventHandler = ZModelBasedToolBarEventHandler(model, toolBarContext) ZPersistentToolBar.__init__(self, prefsId, self.contentProvider, self.eventHandler, parent, style)
def __init__(self, prefsId, model, parent, style=0, context=None): toolBarContext = None if context is not None: toolBarContext = context else: toolBarContext = ZToolBarActionContext(self) self.contentProvider = ZModelBasedToolBarContentProvider( model, toolBarContext) self.eventHandler = ZModelBasedToolBarEventHandler( model, toolBarContext) ZPersistentToolBar.__init__(self, prefsId, self.contentProvider, self.eventHandler, parent, style)
class _ZEditorWindow(IZEditorWindow, ZBaseWindow, IZTabContainerListener, ZPersistentDialogMixin): def __init__(self): self.editorFactory = ZEditorFactory() self.menuBar = None self.toolBar = None self.statusBar = None self.editors = [] self.tabToEditorMap = {} self.parent = None ZBaseWindow.__init__(self, self.parent, u"", name = u"ZEditorWindow", size = wx.Size(640, 550)) #$NON-NLS-2$ #$NON-NLS-1$ ZPersistentDialogMixin.__init__(self, IZBlogAppUserPrefsKeys.EDITOR_WINDOW, False) self.Layout() # end __init__() def _createWindowWidgets(self, parent): self.toolBarParent = parent self.toolBar = ZPersistentToolBar(IZBlogAppUserPrefsKeys.EDITOR_WINDOW_TOOLBAR, None, None, parent, ZToolBar.STYLE_SHOW_TEXT) self.tbStaticLine = wx.StaticLine(parent) self.tabContainer = ZTabContainer(parent) self.tabContainer.setListener(self) # end _createWindowWidgets() def _populateWindowWidgets(self): self.SetIcons(getResourceRegistry().getIconBundle(ICON_IMAGES)) # end _populateWindowWidgets() def _layoutWindowWidgets(self): sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.toolBar, 0, wx.EXPAND) sizer.Add(self.tbStaticLine, 0, wx.EXPAND) sizer.Add(self.tabContainer, 1, wx.EXPAND | wx.TOP, 5) return sizer # end _layoutWindowWidgets() def _bindWidgetEvents(self): self.Bind(wx.EVT_CLOSE, self.onClose, self) self.Bind(ZEVT_TOOLBAR_RESIZE, self.onToolBarResize, self.toolBar) self.Bind(ZEVT_EDITOR_CLOSE, self.onEditorClose) self.Bind(ZEVT_EDITOR_TITLE_CHANGED, self.onEditorTitleChanged) self.Bind(ZEVT_EDITOR_DIRTY, self.onEditorDirty) self.Bind(ZEVT_EDITOR_STATUS_BAR_CHANGED, self.onEditorStatusBarChanged) self.Bind(ZEVT_EDITOR_MENU_BAR_CHANGED, self.onEditorMenuBarChanged) self.Bind(ZEVT_EDITOR_TOOL_BAR_CHANGED, self.onEditorToolBarChanged) # end _bindWidgetEvents() def openDocument(self, document): editor = self.findEditor(document.getId()) # If not already editing this document, create a new one. if editor is None: editor = self.editorFactory.createEditor(self.tabContainer, document) self._addEditor(editor) tabId = self.tabContainer.addTab(ZTabInfo(document.getTitle(), editor.getBitmap()), editor) self.tabToEditorMap[tabId] = editor # Bring the given editor into focus. self._focusOnEditor(editor) self.Raise() return editor # end openDocument() def findEditor(self, documentId): if documentId is None: return None for editor in self.editors: if editor.getDocumentId() == documentId: return editor return None # end findEditor() def closeEditor(self, editor): tabId = self._findTabIdForEditor(editor) self.tabContainer.removeTab(tabId) del self.tabToEditorMap[tabId] editor.destroy() self.editors.remove(editor) if len(self.editors) == 0: self.Close() # end closeEditor() def _addEditor(self, editor): self.editors.append(editor) # end _addEditor() def _focusOnEditor(self, editor): tabId = self._findTabIdForEditor(editor) if tabId is not None: self.tabContainer.selectTab(tabId) self.tabContainer.SetFocus() # end _focusOnEditor() def _findTabIdForEditor(self, editor): for (tabId, teditor) in self.tabToEditorMap.items(): if editor == teditor: return tabId return None # end _findTabIdForEditor() def _findEditorByTabId(self, tabId): if tabId in self.tabToEditorMap: return self.tabToEditorMap[tabId] return None # end _findEditorByTabId() def _getSelectedEditor(self): tabId = self.tabContainer.getSelectedTabId() return self._findEditorByTabId(tabId) # end _getSelectedEditor() def getEditors(self): return self.editors # end getEditors() def close(self): u"""close() -> boolean Called to close the window. Returns True if the close succeeded, False otherwise.""" #$NON-NLS-1$ for editor in self.editors: if editor.isDirty(): rval = ZShowYesNoCancelMessage(self, _extstr(u"editorwin.SaveDocumentMessage") % editor.getTitle(), _extstr(u"editorwin.SaveDocument")) #$NON-NLS-2$ #$NON-NLS-1$ if rval == wx.ID_CANCEL: return False elif rval == wx.ID_YES: editor.save() elif rval == wx.ID_NO: pass for editor in self.editors: editor.destroy() self.editors = [] return True # end close() def onEditorTitleChanged(self, event): selEditor = self._getSelectedEditor() editor = event.getEditor() if selEditor == editor: title = self._getEditorTitle(editor) self.SetTitle(title) tabId = self._findTabIdForEditor(editor) self.tabContainer.setTabName(tabId, title) event.Skip() # end onEditorTitleChanged() def onEditorClose(self, event): if self.onEditorClosing(event.getEditor()): self.closeEditor(event.getEditor()) event.Skip() # end onEditorClose() def onEditorDirty(self, event): selEditor = self._getSelectedEditor() editor = event.getEditor() if selEditor == editor: title = self._getEditorTitle(editor) self.SetTitle(title) tabId = self._findTabIdForEditor(editor) self.tabContainer.setTabName(tabId, title) event.Skip() # end onEditorDirty() def onEditorStatusBarChanged(self, event): selEditor = self._getSelectedEditor() editor = event.getEditor() if selEditor == editor: self.statusBar.refresh() event.Skip() # end onEditorStatusBarChanged() def onEditorMenuBarChanged(self, event): selEditor = self._getSelectedEditor() editor = event.getEditor() if selEditor == editor: self.menuBar.refresh() event.Skip() # end onEditorMenuBarChanged() def onEditorToolBarChanged(self, event): selEditor = self._getSelectedEditor() editor = event.getEditor() if selEditor == editor: self.toolBar.refresh() event.Skip() # end onEditorToolBarChanged() def onEditorClosing(self, editor): u"""Returns True or False based on dirty status of editor and user input. Returns False if the close should be veto'd.""" #$NON-NLS-1$ if editor.isDirty(): rval = ZShowYesNoCancelMessage(self, _extstr(u"editorwin.SaveDocumentMessage") % editor.getTitle(), _extstr(u"editorwin.SaveDocument")) #$NON-NLS-2$ #$NON-NLS-1$ if rval == wx.ID_CANCEL: return False elif rval == wx.ID_YES: editor.save() elif rval == wx.ID_NO: pass return True # end onEditorClosing() def onToolBarResize(self, event): self.toolBarParent.Layout() event.Skip() # end onToolBarResize() def onClose(self, event): if self.close(): global EDITOR_WINDOW EDITOR_WINDOW = None event.Skip() else: event.Veto() # end onClose() def onTabClosing(self, tabId): u"""Should return True to prevent the tab from being closed.""" #$NON-NLS-1$ editor = self._findEditorByTabId(tabId) cancelClose = not self.onEditorClosing(editor) if not cancelClose: editor.destroy() return cancelClose # end onTabClosing() def onTabClosed(self, tabId): editor = self._findEditorByTabId(tabId) if editor is not None: del self.tabToEditorMap[tabId] self.editors.remove(editor) if len(self.editors) == 0: self.Close() # end onTabClosed() def onTabSelectionChanged(self, fromTabId, toTabId): #@UnusedVariable editor = self._findEditorByTabId(toTabId) if editor is not None: self.SetTitle(self._getEditorTitle(editor)) self._updateMenuBar(editor) self._updateToolBar(editor) self._updateStatusBar(editor) # end onTabSelectionChanged() def _updateMenuBar(self, editor): menuBarModel = editor.getMenuBarModel() menuContext = editor.getMenuActionContext() contentProvider = ZModelBasedMenuContentProvider(menuBarModel, menuContext) eventHandler = ZModelBasedMenuEventHandler(menuBarModel, menuContext) if self.menuBar is None: self.menuBar = ZMenuBar(self, contentProvider, eventHandler) self.SetMenuBar(self.menuBar) self.Layout() else: self.menuBar.setContentProvider(contentProvider, eventHandler) # end _updateMenuBar() def _updateToolBar(self, editor): toolBarModel = editor.getToolBarModel() toolContext = editor.getToolBarActionContext() contentProvider = ZModelBasedToolBarContentProvider(toolBarModel, toolContext) eventHandler = ZModelBasedToolBarEventHandler(toolBarModel, toolContext) self.toolBar.setContentProvider(contentProvider, eventHandler) self.Layout() # end _updateToolBar() def _updateStatusBar(self, editor): statusBarModel = editor.getStatusBarModel() provider = ZStatusBarModelBasedContentProvider(statusBarModel) if self.statusBar is None: self.statusBar = ZStatusBar(self, provider) self.SetStatusBar(self.statusBar) self.Layout() else: self.statusBar.setContentProvider(provider) self.statusBar.refresh() # end _updateStatusBar() def _getEditorTitle(self, editor): title = editor.getTitle() if not title: title = u"(%s)" % _extstr(u"editorwin.No_Title") #$NON-NLS-1$ #$NON-NLS-2$ if editor.isDirty(): title = u"* " + title #$NON-NLS-1$ return title
def _createWindowWidgets(self, parent): self.toolBarParent = parent self.toolBar = ZPersistentToolBar(IZBlogAppUserPrefsKeys.EDITOR_WINDOW_TOOLBAR, None, None, parent, ZToolBar.STYLE_SHOW_TEXT) self.tbStaticLine = wx.StaticLine(parent) self.tabContainer = ZTabContainer(parent) self.tabContainer.setListener(self)
class ZStandardPerspective(IZPerspective): def __init__(self): self.currentViewSelection = None self.panel = None self.splitterWindow = None self.navView = None self.ctxView = None self.sizer = None # end __init__() def destroy(self): self._saveLayout() self.navView.destroy() self.ctxView.destroy() # end destroy() def createUIPanel(self, parent): self.panel = ZTransparentPanel(parent, wx.ID_ANY) self.splitterWindow = ZSplitterWindow(self.panel) self._createToolBar(self.panel) self._createNavigatorView(self.splitterWindow) self._createContextInfoView(self.splitterWindow) self._doSplit() self._bindViewEvents() self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.toolBar, 0, wx.EXPAND) self.sizer.Add(self.toolBarStaticLine, 0, wx.EXPAND) self.sizer.Add(self.splitterWindow, 1, wx.EXPAND | wx.ALL, 5) self.panel.SetAutoLayout(True) self.panel.SetSizer(self.sizer) self.panel.Layout() self._restoreLayout() return self.panel # end createUI() def _doSplit(self): self.splitterWindow.SplitVertically(self.navView, self.ctxView) self.splitterWindow.SetMinimumPaneSize(100) self.splitterWindow.SetSashSize(8) self.splitterWindow.SetSashGravity(0.0) # end _doSplit() def _createToolBar(self, parent): self.toolBarModel = self._createToolBarModel() self.toolBarContext = ZStandardPerspectiveToolBarActionContext(parent, self.currentViewSelection) contentProvider = ZModelBasedToolBarContentProvider(self.toolBarModel, self.toolBarContext) eventHandler = ZModelBasedToolBarEventHandler(self.toolBarModel, self.toolBarContext) self.toolBar = ZPersistentToolBar(self._getUserPrefsKey() + u".toolbar", contentProvider, eventHandler, parent, ZToolBar.STYLE_SHOW_TEXT) #$NON-NLS-1$ self.toolBarStaticLine = wx.StaticLine(parent, wx.ID_ANY) # end _createToolBar() def _createToolBarModel(self): model = ZPluginToolBarModel(IZBlogAppToolBarIds.ZID_STANDARD_PERSPECTIVE_TOOLBAR) model.setDefaultToolSize(24) # 'Write' Tool toolId = model.addItemWithAction(_extstr(u"standard.Write"), 1, ZWriteToolBarAction()) #$NON-NLS-1$ model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"write")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"write")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"write_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"write_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.setToolDescription(toolId, _extstr(u"standard.Author_some_new_content_")) #$NON-NLS-1$ # 'New Account' Tool toolId = model.addItemWithAction(_extstr(u"standard.AddAccount"), 3, ZNewAccountToolBarAction()) #$NON-NLS-1$ model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"addAccount")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"addAccount")) #$NON-NLS-2$ #$NON-NLS-1$ model.setToolDescription(toolId, _extstr(u"standard.AddAccountDescriton")) #$NON-NLS-1$ # 'New Storage' Tool toolId = model.addItemWithAction(_extstr(u"standard.AddStorage"), 3, ZNewMediaStorageToolBarAction()) #$NON-NLS-1$ model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"addStorage")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"addStorage")) #$NON-NLS-2$ #$NON-NLS-1$ model.setToolDescription(toolId, _extstr(u"standard.AddStorageDescription")) #$NON-NLS-1$ model.addSeparator(10) # 'Publish' Tool toolId = model.addItemWithAction(_extstr(u"standard.Publish"), 15, ZPublishToolBarAction()) #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-1$ model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"publish")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"publish")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"publish_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"publish_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.setToolDescription(toolId, _extstr(u"standard.Publish_some_content_")) #$NON-NLS-1$ # 'Download' Tool toolId = model.addDropDownItemWithAction(_extstr(u"standard.Download"), 20, ZDownloadToolBarAction()) #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-1$ model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"download")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"download")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"download_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"download_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.setToolDescription(toolId, _extstr(u"standard.Download_content_")) #$NON-NLS-1$ # 'View (online)' Tool toolId = model.addItemWithAction(_extstr(u"standard.ViewOnline"), 25, ZViewOnlineToolBarAction()) #$NON-NLS-1$ model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"viewOnline")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"viewOnline")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"api", u"viewOnline_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"api", u"viewOnline_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.setToolDescription(toolId, _extstr(u"standard.ViewOnlineDescription")) #$NON-NLS-1$ model.addSeparator(50) # 'Delete' Tool toolId = model.addItemWithAction(_extstr(u"standard.Delete"), 55, ZDeleteToolBarAction()) #$NON-NLS-2$ #$NON-NLS-3$ #$NON-NLS-1$ model.addToolBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"delete")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"delete")) #$NON-NLS-2$ #$NON-NLS-1$ model.addToolDisabledBitmap(toolId, 24, getToolbarBitmap(24, u"file", u"delete_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.addToolDisabledBitmap(toolId, 32, getToolbarBitmap(32, u"file", u"delete_disabled")) #$NON-NLS-1$ #$NON-NLS-2$ model.setToolDescription(toolId, _extstr(u"standard.DeleteDescription")) #$NON-NLS-1$ return model # end _createToolBarModel() def _createContextInfoView(self, parent): self.ctxView = ZContextInfoView(parent) # end _createContextInfoView() def _createNavigatorView(self, parent): self.navView = ZNavigatorView(parent) # end _createNavigatorView() def _bindViewEvents(self): self.toolBar.Bind(ZEVT_TOOLBAR_RESIZE, self.onToolBarResize, self.toolBar) ZEVT_VIEW_SELECTION_CHANGED(self.navView, self.onViewSelectionChanged) # end _bindViewEvents() def onToolBarResize(self, event): self.panel.Layout() self.panel.Refresh() event.Skip() # end onToolBarResize() def onViewSelectionChanged(self, event): self.toolBarContext.setViewSelection(event.getSelection()) self.toolBar.refresh() event.Skip() # end onViewSelectionChanged() def _saveLayout(self): if self.panel.IsShown(): key = self._getUserPrefsKey() + u".sash-width" #$NON-NLS-1$ userPrefs = getApplicationModel().getUserProfile().getPreferences() userPrefs.setUserPreference(key, self.splitterWindow.GetSashPosition()) # end _saveLayout() def _restoreLayout(self): key = self._getUserPrefsKey() + u".sash-width" #$NON-NLS-1$ userPrefs = getApplicationModel().getUserProfile().getPreferences() sashPos = userPrefs.getUserPreferenceInt(key, 200) self.splitterWindow.SetSashPosition(sashPos) # end _restoreLayout() def _getUserPrefsKey(self): return IZBlogAppUserPrefsKeys.STANDARD_PERSPECTIVE_LAYOUT