def __init__(self, mainControl): LayeredControlPresenter.__init__(self) self.mainControl = mainControl self.docPage = None self.currentDocPageProxyEvent = ProxyMiscEvent(self) self.currentDocPageProxyEvent.addListener(self) # Connect page history self.pageHistory = PageHistory(self.getMainControl(), self) self.getMainControl().getMiscEvent().addListener(self)
class BasicDocPagePresenter(LayeredControlPresenter): """ Controls the group of all widgets (subcontrols) used to present/edit a particular doc page, currently only the WikiTxtCtrl (subcontrol name "textedit") and WikiHtmlView or WikiHtmlViewIE (name "preview"). This version isn't itself a wx panel and is mainly thought for controlling e.g. a notebook which has the actual subcontrols as children """ def __init__(self, mainControl): LayeredControlPresenter.__init__(self) self.mainControl = mainControl self.docPage = None self.currentDocPageProxyEvent = ProxyMiscEvent(self) self.currentDocPageProxyEvent.addListener(self) # Connect page history self.pageHistory = PageHistory(self.getMainControl(), self) self.getMainControl().getMiscEvent().addListener(self) def getMainControl(self): return self.mainControl def getConfig(self): return self.getMainControl().getConfig() def getDefaultFontFaces(self): return self.getMainControl().presentationExt.faces def getWikiDocument(self): return self.getMainControl().getWikiDocument() def getPageHistory(self): return self.pageHistory def getActiveEditor(self): """ For compatibility with older scripts. """ return self.getSubControl("textedit") def SetStatusText(self, text, field): self.getStatusBar().SetStatusText(uniToGui(text), field) def showStatusMessage(self, msg, duration=0, key=None): self.getMainControl().showStatusMessage(msg, duration, key) def isCurrent(self): return self.getMainControl().getCurrentDocPagePresenter() is self def makeCurrent(self): self.mainControl.getMainAreaPanel().prepareCurrentPresenter(self) def close(self): LayeredControlPresenter.close(self) self.getMainControl().getMiscEvent().removeListener(self) self.pageHistory.close() self.setDocPage(None) # TODO: Was commented out? def getDocPage(self): return self.docPage def setDocPage(self, dp): self.docPage = dp self.currentDocPageProxyEvent.setWatchedSource(dp) def getCurrentDocPageProxyEvent(self): """ This ProxyMiscEvent resends any messsages from the currently active DocPage """ return self.currentDocPageProxyEvent def getWikiWord(self): docPage = self.getDocPage() if docPage is None or not isinstance(docPage, (DocPages.WikiPage, DocPages.AliasWikiPage)): return None return docPage.getWikiWord() def getUnifiedPageName(self): docPage = self.getDocPage() if docPage is None: return None return docPage.getUnifiedPageName() def getLiveText(self): docPage = self.getDocPage() if docPage is None: return None return docPage.getLiveText() def informEditorTextChanged(self, changer): """ Called by the txt editor control """ if self.getDocPage() is not None: self.getDocPage().informEditorTextChanged(changer) self.fireMiscEventProps({"changed editor text": True, "changed live text": True, "changer": changer}) def miscEventHappened(self, miscevt): """ Handle misc events """ if miscevt.getSource() is self.getMainControl(): # TODO? Check if mainControl's current presenter is this one self.fireMiscEventProps(miscevt.getProps()) elif miscevt.getSource() is self.docPage: # if miscevt.has_key("changed editor text"): # self.fireMiscEventProps(miscevt.getProps()) # elif miscevt.has_key("deleted page"): # self.pageHistory.goAfterDeletion() if miscevt.has_key("renamed wiki page"): # oldWord = self.docPage.getWikiWord() newWord = miscevt.get("newWord") self.getSubControl("textedit").loadWikiPage(None) self.openWikiPage(newWord, forceTreeSyncFromRoot=False) def getStatusBar(self): return self.getMainControl().GetStatusBar() def openDocPage(self, unifiedPageName, *args, **kwargs): """ Open a doc page identified by its unified page name """ if len(unifiedPageName) == 0: return if unifiedPageName.startswith(u"wikipage/"): self.openWikiPage(unifiedPageName[9:], *args, **kwargs) else: self.openFuncPage(unifiedPageName, *args, **kwargs) def openFuncPage(self, funcTag, addToHistory=True, **evtprops): if not self.getMainControl().requireReadAccess(): return oldPage = self.getDocPage() evtprops["addToHistory"] = addToHistory try: page = self.getMainControl().getWikiDocument().getFuncPage(funcTag) self.getSubControl("textedit").loadFuncPage(page, evtprops) except (IOError, OSError, DbAccessError), e: self.getMainControl().lostAccess(e) raise self.switchSubControl("textedit") p2 = evtprops.copy() p2.update({"loaded current doc page": True, "loaded current functional page": True, "docPage": page, "oldDocPage": oldPage}) # p2.update({"loaded current page": True}) self.fireMiscEventProps(p2) page.informVisited()