Sun, 02 Feb 2014 20:02:23 +0100
Started implementing the tags functionality.
# -*- coding: utf-8 -*- # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the Django tags menu handler. """ from PyQt4.QtCore import QObject from E5Gui.E5Application import e5App class DjangoTagsMenuHandler(QObject): """ Class implementing the Django tags menu handler. """ def __init__(self, ui, parent=None): """ Constructor @param ui reference to the user interface object (UI.UserInterface) @param parent reference to the parent object (QObject) """ super(DjangoTagsMenuHandler, self).__init__(parent) self.__ui = ui self.__findDialog = None def initMenus(self, mainMenu): """ Public method to initialize the various menus. @param mainMenu reference to the main tags menu (QMenu) """ mainMenu.addAction(self.tr("Django Template Tags Locator"), self.__findTemplateTag) def __findTemplateTag(self): """ Private slot to find a template tag and insert its text. """ if self.__findDialog is None: from .FindTemplateTagDialog import FindTemplateTagDialog self.__findDialog = FindTemplateTagDialog(self.__ui) self.__findDialog.tag.connect(self.__applyTemplate) self.__findDialog.show() def __applyTemplate(self, tag): """ Private slot to generate and insert the template text. @param tag name of the tag to insert (string) """ editor = e5App().getObject("ViewManager").activeWindow() if editor is None: return templateText = self.__generateTemplateText(tag) editor.beginUndoAction() editor.replaceSelectedText(templateText) editor.endUndoAction() def __generateTemplateText(self, tag): """ Private slot to generate the template text. @param tag name of the tag to insert (string) """ # TODO: implement the tag generation logic return "needs real tags"