コード例 #1
0
ファイル: koTools.py プロジェクト: ekhavana/KomodoEdit
class _KoMacroTool(_KoTool):
    _com_interfaces_ = [components.interfaces.koIMacroTool]
    typeName = 'macro'
    prettytype = 'Macro'
    _iconurl = _icons.get('macro')

    def __init__(self, *args):
        _KoTool.__init__(self, *args)
        self.flavors.insert(0, 'text/x-moz-url')
        self.name = "New Macro"
        self._attributes['language'] = 'JavaScript'
        self._attributes['async'] = False
        self._attributes['trigger_enabled'] = False
        self._attributes['trigger'] = ""

    def delete(self):
        try:
            self._getObserverSvc().notifyObservers(self, 'macro-unload', '')
        except Exception:
            pass
        _KoTool.delete(self)

    def updateSelf(self):
        if self.initialized:
            return
        info = _tbdbSvc.getMacroInfo(self.id)
        #log.debug("macro info: %s", info)
        self._finishUpdatingSelf(info)

    def get_url(self):
        if self._attributes['language'] == 'JavaScript':
            ext = ".js"
        elif self._attributes['language'] == 'Python':
            ext = ".py"
        # The important parts are the ID and the extension, so the
        # name itself can be sluggified so the autosave routine
        # doesn't get caught up with special characters in the name.
        return "macro2://%s/%s%s" % (self.id, koToolbox2.slugify(
            self.name), ext)

    def save(self):
        # Write the changed data to the file system
        self.saveContentToDisk()
        _tbdbSvc.saveContent(self.id, self.value)
        _tbdbSvc.saveMacroInfo(self.id, self.name, self.value,
                               self._attributes)
        self._postSave()
        _toolsManager.removeChangedCachedTool(self.id)

    def saveProperties(self):
        # Write the changed data to the file system
        self.saveToolToDisk()
        _tbdbSvc.saveMacroInfo(self.id, self.name, self.value,
                               self._attributes)

    def _asyncMacroCheck(self, async):
        if async:
            lastErrorSvc = components.classes["@activestate.com/koLastErrorService;1"]\
                .getService(components.interfaces.koILastErrorService)
            err = "Asynchronous python macros not yet implemented"
            lastErrorSvc.setLastError(1, err)
            raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE, err)

    def evalAsPython(self, domdocument, window, scimoz, koDoc, view, code,
                     async):
        self._asyncMacroCheck(async)
        projectUtils.evalPythonMacro(
            WrapObject(self, self._com_interfaces_[0]), domdocument, window,
            scimoz, koDoc, view, code)

    def evalAsPythonObserver(self, domdocument, window, scimoz, koDoc, view,
                             code, async, subject, topic, data):
        self._asyncMacroCheck(async)
        projectUtils.evalPythonMacro(
            WrapObject(self, self._com_interfaces_[0]), domdocument, window,
            scimoz, koDoc, view, code, subject, topic, data)
コード例 #2
0
ファイル: koTools.py プロジェクト: ekhavana/KomodoEdit
 def evalAsPython(self, domdocument, window, scimoz, koDoc, view, code,
                  async):
     self._asyncMacroCheck(async)
     projectUtils.evalPythonMacro(
         WrapObject(self, self._com_interfaces_[0]), domdocument, window,
         scimoz, koDoc, view, code)
コード例 #3
0
 def evalAsPython(self, domdocument, window, scimoz, koDoc,
                  view, code, async):
     self._asyncMacroCheck(async)
     projectUtils.evalPythonMacro(WrapObject(self,self._com_interfaces_[0]),
                     domdocument, window, scimoz, koDoc, view, code)