Ejemplo n.º 1
0
    def executeUiEvent(self, evName, cmd):
        if "PublishCommandEvent" != evName:
            return

        sernaDoc = self.sernaDoc()
        structEditor = sernaDoc.structEditor()

        widget = sernaDoc.widget()

        if structEditor and not structEditor.groveEditor is None:
            saveAction = structEditor.findAction("saveDocument")
            if saveAction and saveAction.isEnabled():
                buttons = QMessageBox.Ok | QMessageBox.Cancel
                answer = QMessageBox.warning(widget, "Publishing", "Current "
                                             "document will be saved", buttons)
                if QMessageBox.Ok != answer:
                    return

                if not self.executeCommandEvent("SaveDocument"):
                    QMessageBox.critical(widget, "Publishing",
                                         "Document save failed")
                    return

        catMgr = structEditor.catalogManager()
        catalogFiles = unicode(catMgr.getCatalogsList())

        if os.pathsep in catalogFiles:
            cats = []
            for cat in catalogFiles.split(os.pathsep):
                cat = cat.replace(' ', '%20')
                cats.append(cat)
            catalogFiles = ' '.join(cats)

        sernaDoc.getDsi().getProperty("xml-catalogs").setString(catalogFiles.__str__())

        if not self._dialog:
            self._dialog = PublishDialog(self, widget, self.pluginProperties())

        self._dialog.showDialog()
        QApplication.setActiveWindow(self._dialog)
        self._dialog.setFocus(Qt.ActiveWindowFocusReason)
        self._dialog.exec_()
Ejemplo n.º 2
0
class PublishingPlugin(DocumentPlugin):
    __publishersRegistry = None
    __transformersFactory = None

    @staticmethod
    def getPublishersRegistry(props=None):
        if PublishingPlugin.__publishersRegistry is None:
            PublishingPlugin.__publishersRegistry = PublishersRegistry(props)
        return PublishingPlugin.__publishersRegistry

    @staticmethod
    def getTransformersFactory(props=None):
        if PublishingPlugin.__transformersFactory is None:
            PublishingPlugin.__transformersFactory = TransformersFactory(props)
        return PublishingPlugin.__transformersFactory

    def __init__(self, sernaDoc, properties):
        DocumentPlugin.__init__(self, sernaDoc, properties)
        self.buildPluginExecutors(True)
        pp = self.pluginProperties()
        self._pluginDir = unicode(pp.getProperty("resolved-path").getString())
        self._dialog = None
        config_root = SernaConfig.root()
        java_home = config_root.getProperty("vars/java_home").getString()
        set_java_home(unicode(java_home))

    def __str__(self):
        return PLUGIN_ID

    def launchViewer(self, url):
        urlProperty = PropertyNode("")
        urlProperty.makeDescendant("url", url)
        self.executeCommandEvent("LaunchBrowser", urlProperty)

    def executeUiEvent(self, evName, cmd):
        if "PublishCommandEvent" != evName:
            return

        sernaDoc = self.sernaDoc()
        structEditor = sernaDoc.structEditor()

        widget = sernaDoc.widget()

        if structEditor and not structEditor.groveEditor is None:
            saveAction = structEditor.findAction("saveDocument")
            if saveAction and saveAction.isEnabled():
                buttons = QMessageBox.Ok | QMessageBox.Cancel
                answer = QMessageBox.warning(widget, "Publishing", "Current "
                                             "document will be saved", buttons)
                if QMessageBox.Ok != answer:
                    return

                if not self.executeCommandEvent("SaveDocument"):
                    QMessageBox.critical(widget, "Publishing",
                                         "Document save failed")
                    return

        catMgr = structEditor.catalogManager()
        catalogFiles = unicode(catMgr.getCatalogsList())

        if os.pathsep in catalogFiles:
            cats = []
            for cat in catalogFiles.split(os.pathsep):
                cat = cat.replace(' ', '%20')
                cats.append(cat)
            catalogFiles = ' '.join(cats)

        sernaDoc.getDsi().getProperty("xml-catalogs").setString(catalogFiles.__str__())

        if not self._dialog:
            self._dialog = PublishDialog(self, widget, self.pluginProperties())

        self._dialog.showDialog()
        QApplication.setActiveWindow(self._dialog)
        self._dialog.setFocus(Qt.ActiveWindowFocusReason)
        self._dialog.exec_()