Пример #1
0
    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            if haveWebEngine:
                from enki.plugins.preview.preview import PreviewDock
                self._dock = PreviewDock()

                self._saveAction = QAction(QIcon(':enkiicons/save.png'),
                                           'Save Preview as HTML', self._dock)
                self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
                self._saveAction.triggered.connect(self._dock.onPreviewSave)
            else:
                self._dock = NoWebkitDock()

        if haveWebEngine:
            core.actionManager().addAction("mFile/aSavePreview",
                                           self._saveAction)

        self._dock.closed.connect(self._onDockClosed)
        self._dock.shown.connect(self._onDockShown)
        core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)

        core.actionManager().addAction("mView/aPreview",
                                       self._dock.showAction())
        self._dockInstalled = True
        if core.config()['Preview']['Enabled']:
            self._dock.show()
Пример #2
0
    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            from enki.plugins.preview.preview import PreviewDock
            self._dock = PreviewDock()
            self._dock.closed.connect(self._onDockClosed)
            self._dock.shown.connect(self._onDockShown)
            self._saveAction = QAction(QIcon(':enkiicons/save.png'), 'Save Preview as HTML', self._dock)
            self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
            self._saveAction.triggered.connect(self._dock.onSave)

        core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)

        core.actionManager().addAction("mView/aPreview", self._dock.showAction())
        core.actionManager().addAction("mFile/aSavePreview", self._saveAction)
        self._dockInstalled = True
        if core.config()['Preview']['Enabled']:
            self._dock.show()
Пример #3
0
class Plugin(QObject):
    """Plugin interface implementation.
    """

    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(self._onDocumentChanged)  # Disconnected.
        core.workspace().languageChanged.connect(self._onDocumentChanged)  # Disconnected.

        # Install our CodeChat page into the settings dialog.
        core.uiSettingsManager().aboutToExecute.connect(self._onSettingsDialogAboutToExecute)  # Disconnected.
        # Update preview dock when the settings dialog (which contains the
        # CodeChat enable checkbox) is changed.
        core.uiSettingsManager().dialogAccepted.connect(self._onDocumentChanged)  # Disconnected.

        # Provide a "Set Sphinx Path" menu item.
        core.uiSettingsManager().dialogAccepted.connect(self._setSphinxActionVisibility)
        self._sphinxAction = QAction("Set Sphinx path", self._dock)
        self._sphinxAction.setShortcut(QKeySequence("Alt+Shift+S"))
        core.actionManager().addAction("mTools/aSetSphinxPath", self._sphinxAction)
        self._sphinxAction.triggered.connect(self.onSphinxPath)
        # Only enable this command if the File browser has a valid path.
        self.onFileBrowserPathChanged()
        core.project().changed.connect(self.onFileBrowserPathChanged)

        # If user's config .json file lacks it, populate CodeChat's default
        # config key and Sphinx's default config key.
        if not "CodeChat" in core.config():
            core.config()["CodeChat"] = {}
            core.config()["CodeChat"]["Enabled"] = False
            core.config().flush()
        if not "Sphinx" in core.config():
            core.config()["Sphinx"] = {}
            core.config()["Sphinx"]["Enabled"] = False
            core.config()["Sphinx"]["Executable"] = "sphinx-build"
            core.config()["Sphinx"]["ProjectPath"] = ""
            core.config()["Sphinx"]["BuildOnSave"] = False
            core.config()["Sphinx"]["OutputPath"] = os.path.join("_build", "html")
            core.config()["Sphinx"]["AdvancedMode"] = False
            core.config()["Sphinx"]["Cmdline"] = (
                "sphinx-build -d " + os.path.join("_build", "doctrees") + " . " + os.path.join("_build", "html")
            )
            core.config().flush()

        self._setSphinxActionVisibility()

    def terminate(self):
        """Uninstall the plugin
        """
        core.actionManager().removeAction("mTools/aSetSphinxPath")
        core.project().changed.disconnect(self.onFileBrowserPathChanged)

        if self._dockInstalled:
            self._removeDock()

        if self._dock is not None:
            self._dock.terminate()

        core.workspace().currentDocumentChanged.disconnect(self._onDocumentChanged)
        core.workspace().languageChanged.disconnect(self._onDocumentChanged)
        core.uiSettingsManager().aboutToExecute.disconnect(self._onSettingsDialogAboutToExecute)
        core.uiSettingsManager().dialogAccepted.disconnect(self._onDocumentChanged)
        if self._dock:
            self._dock.closed.disconnect(self._onDockClosed)
            self._dock.shown.disconnect(self._onDockShown)
            self._saveAction.triggered.disconnect(self._dock.onPreviewSave)

    def _onDocumentChanged(self):
        """Document or Language changed.
        Create dock, if necessary
        """
        if self._canPreview(core.workspace().currentDocument()):
            if not self._dockInstalled:
                self._createDock()
        else:
            if self._dockInstalled:
                self._removeDock()

    def _canPreview(self, document):
        """Check if the given document can be shown in the Preview dock.
        """
        if document is None:
            return False

        if document.qutepart.language() in ("Markdown", "Restructured Text") or isHtmlFile(document):
            return True

        if canUseCodeChat(document.filePath()):
            return True

        if sphinxEnabledForFile(document.filePath()):
            return True

        return False

    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            from enki.plugins.preview.preview import PreviewDock

            self._dock = PreviewDock()
            self._dock.closed.connect(self._onDockClosed)  # Disconnected.
            self._dock.shown.connect(self._onDockShown)  # Disconnected.

            self._saveAction = QAction(QIcon(":enkiicons/save.png"), "Save Preview as HTML", self._dock)
            self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
            self._saveAction.triggered.connect(self._dock.onPreviewSave)  # Disconnected.

        core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)

        core.actionManager().addAction("mView/aPreview", self._dock.showAction())
        core.actionManager().addAction("mFile/aSavePreview", self._saveAction)
        self._dockInstalled = True
        if core.config()["Preview"]["Enabled"]:
            self._dock.show()

    def _onDockClosed(self):
        """Dock has been closed by user. Change Enabled option
        """
        if core.config()["Preview"]["Enabled"]:
            core.config()["Preview"]["Enabled"] = False
            core.config().flush()

    def _onDockShown(self):
        """Dock has been shown by user. Change Enabled option
        """
        if not core.config()["Preview"]["Enabled"]:
            core.config()["Preview"]["Enabled"] = True
            core.config().flush()

    def _removeDock(self):
        """Remove dock from GUI
        """
        core.actionManager().removeAction("mView/aPreview")
        core.actionManager().removeAction("mFile/aSavePreview")
        core.mainWindow().removeDockWidget(self._dock)
        self._dockInstalled = False

    def _onSettingsDialogAboutToExecute(self, dialog):
        """The UI settings dialog is about to execute. Install preview-related
           settings."""
        CodeChatSettingsWidget(dialog)
        SphinxSettingsWidget(dialog)

    def _setSphinxActionVisibility(self):
        self._sphinxAction.setVisible(core.config()["Sphinx"]["Enabled"])

    def onFileBrowserPathChanged(self):
        """Enable the onSphinxPath command only when there's a valid project
           path."""
        self._sphinxAction.setEnabled(bool(core.project().path()))

    def onSphinxPath(self):
        """Set the Sphinx path to the current project path."""
        assert core.project().path()
        core.config()["Sphinx"]["ProjectPath"] = core.project().path()
        core.config().flush()
        if core.config()["Preview"]["Enabled"] and self._dock is not None:
            self._dock._scheduleDocumentProcessing()
Пример #4
0
class Plugin(QObject):
    """Plugin interface implementation
    """
    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)
        
        if not 'Preview' in core.config():  # migration from old configs versions
            core.config()['Preview'] = {'Enabled': True,
                                        'JavaScriptEnabled' : True}

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(self._onDocumentChanged)
        core.workspace().languageChanged.connect(self._onDocumentChanged)
        core.mainWindow().stateRestored.connect(self._onMainWindowStateRestored)
    
    def del_(self):
        """Uninstall the plugin
        """
        if self._dockInstalled:
            self._removeDock()
        
        if self._dock is not None:
            self._dock.del_()
    
    def _onDocumentChanged(self):
        """Document or Language changed.
        Create dock, if necessary
        """
        if self._canHighlight(core.workspace().currentDocument()):
            if not self._dockInstalled:
                self._createDock()
        else:
            if self._dockInstalled:
                self._removeDock()
    
    def _onMainWindowStateRestored(self):
        """When main window state is restored - dock is made visible, even if should not. Qt bug?
        Hide dock, if can't view current document
        """
        if (not self._canHighlight(core.workspace().currentDocument())) and \
           self._dock is not None:
               self._dock.hide()
    
    def _canHighlight(self, document):
        """Check if can highlight document
        """
        if document is None:
            return False
        
        if document.qutepart.language() == 'reStructuredText' or \
           isHtmlFile(document):
            return True
        
        if isMarkdownFile(document):
            return True
        
        return False

    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            from enki.plugins.preview.preview import PreviewDock
            self._dock = PreviewDock()
            self._dock.closed.connect(self._onDockClosed)
            self._dock.showAction().triggered.connect(self._onDockShown)
            self._saveAction = QAction(QIcon(':enkiicons/save.png'), 'Save Preview as HTML', self._dock)
            self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
            self._saveAction.triggered.connect(self._dock.onSave)
        
        restored = core.mainWindow().restoreDockWidget(self._dock)
        if not restored:
            core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)
        
        core.actionManager().addAction("mView/aPreview", self._dock.showAction())
        core.actionManager().addAction("mFile/aSavePreview", self._saveAction)
        self._dockInstalled = True
        if core.config()['Preview']['Enabled']:
            self._dock.show()
    
    def _onDockClosed(self):
        """Dock has been closed by user. Change Enabled option
        """
        core.config()['Preview']['Enabled'] = False
        core.config().flush()
    
    def _onDockShown(self):
        """Dock has been shown by user. Change Enabled option
        """
        core.config()['Preview']['Enabled'] = True
        core.config().flush()
    
    def _removeDock(self):
        """Remove dock from GUI
        """
        core.actionManager().removeAction("mView/aPreview")
        core.actionManager().removeAction("mFile/aSavePreview")
        core.mainWindow().removeDockWidget(self._dock)
        self._dockInstalled = False
Пример #5
0
class Plugin(QObject):
    """Plugin interface implementation.
    """
    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(
            self._onDocumentChanged)
        core.workspace().languageChanged.connect(self._onDocumentChanged)

        # Install our CodeChat page into the settings dialog.
        core.uiSettingsManager().aboutToExecute.connect(
            self._onSettingsDialogAboutToExecute)
        # Update preview dock when the settings dialog (which contains the
        # CodeChat enable checkbox) is changed.
        core.uiSettingsManager().dialogAccepted.connect(
            self._onDocumentChanged)

        # Provide a "Set Sphinx Path" menu item.
        core.uiSettingsManager().dialogAccepted.connect(
            self._setSphinxActionVisibility)
        self._sphinxAction = QAction('Set Sphinx path', self._dock)
        self._sphinxAction.setShortcut(QKeySequence('Alt+Shift+S'))
        core.actionManager().addAction('mTools/aSetSphinxPath',
                                       self._sphinxAction)
        self._sphinxAction.triggered.connect(self.onSphinxPath)
        # Only enable this command if the File browser has a valid path.
        self.onFileBrowserPathChanged()
        core.project().changed.connect(self.onFileBrowserPathChanged)

        # If user's config .json file lacks it, populate CodeChat's default
        # config key and Sphinx's default config key.
        if not 'CodeChat' in core.config():
            core.config()['CodeChat'] = {}
            core.config()['CodeChat']['Enabled'] = False
            core.config().flush()
        if not 'Sphinx' in core.config():
            core.config()['Sphinx'] = {}
            core.config()['Sphinx']['Enabled'] = False
            core.config()['Sphinx']['Executable'] = 'sphinx-build'
            core.config()['Sphinx']['ProjectPath'] = ''
            core.config()['Sphinx']['BuildOnSave'] = False
            core.config()['Sphinx']['OutputPath'] = os.path.join(
                '_build', 'html')
            core.config()['Sphinx']['AdvancedMode'] = False
            core.config()['Sphinx']['Cmdline'] = (
                'sphinx-build -d ' + os.path.join('_build', 'doctrees') +
                ' . ' + os.path.join('_build', 'html'))
            core.config().flush()

        self._setSphinxActionVisibility()

    def terminate(self):
        """Uninstall the plugin
        """
        core.actionManager().removeAction('mTools/aSetSphinxPath')

        if self._dockInstalled:
            self._removeDock()

        if self._dock is not None:
            self._dock.terminate()

        core.workspace().currentDocumentChanged.disconnect(
            self._onDocumentChanged)
        core.workspace().languageChanged.disconnect(self._onDocumentChanged)
        core.uiSettingsManager().aboutToExecute.disconnect(
            self._onSettingsDialogAboutToExecute)
        core.uiSettingsManager().dialogAccepted.disconnect(
            self._onDocumentChanged)
        core.uiSettingsManager().dialogAccepted.disconnect(
            self._setSphinxActionVisibility)
        core.project().changed.disconnect(self.onFileBrowserPathChanged)

        if self._dock:
            self._dock.closed.disconnect(self._onDockClosed)
            self._dock.shown.disconnect(self._onDockShown)
            self._saveAction.triggered.disconnect(self._dock.onPreviewSave)

    def _onDocumentChanged(self):
        """Document or Language changed.
        Create dock, if necessary
        """
        if self._canPreview(core.workspace().currentDocument()):
            if not self._dockInstalled:
                self._createDock()
        else:
            if self._dockInstalled:
                self._removeDock()

    def _canPreview(self, document):
        """Check if the given document can be shown in the Preview dock.
        """
        if document is None:
            return False

        if document.qutepart.language() in ('Markdown', 'reStructuredText') or \
           isHtmlFile(document):
            return True

        if canUseCodeChat(document.filePath()):
            return True

        if sphinxEnabledForFile(document.filePath()):
            return True

        return False

    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            from enki.plugins.preview.preview import PreviewDock
            self._dock = PreviewDock()
            self._dock.closed.connect(self._onDockClosed)  # Disconnected.
            self._dock.shown.connect(self._onDockShown)  # Disconnected.

            self._saveAction = QAction(QIcon(':enkiicons/save.png'),
                                       'Save Preview as HTML', self._dock)
            self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
            self._saveAction.triggered.connect(
                self._dock.onPreviewSave)  # Disconnected.

        core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)

        core.actionManager().addAction("mView/aPreview",
                                       self._dock.showAction())
        core.actionManager().addAction("mFile/aSavePreview", self._saveAction)
        self._dockInstalled = True
        if core.config()['Preview']['Enabled']:
            self._dock.show()

    def _onDockClosed(self):
        """Dock has been closed by user. Change Enabled option
        """
        if core.config()['Preview']['Enabled']:
            core.config()['Preview']['Enabled'] = False
            core.config().flush()

    def _onDockShown(self):
        """Dock has been shown by user. Change Enabled option
        """
        if not core.config()['Preview']['Enabled']:
            core.config()['Preview']['Enabled'] = True
            core.config().flush()

    def _removeDock(self):
        """Remove dock from GUI
        """
        core.actionManager().removeAction("mView/aPreview")
        core.actionManager().removeAction("mFile/aSavePreview")
        core.mainWindow().removeDockWidget(self._dock)
        self._dockInstalled = False

    def _onSettingsDialogAboutToExecute(self, dialog):
        """The UI settings dialog is about to execute. Install preview-related
           settings."""
        CodeChatSettingsWidget(dialog)
        SphinxSettingsWidget(dialog)

    def _setSphinxActionVisibility(self):
        self._sphinxAction.setVisible(core.config()['Sphinx']['Enabled'])

    def onFileBrowserPathChanged(self):
        """Enable the onSphinxPath command only when there's a valid project
           path."""
        self._sphinxAction.setEnabled(bool(core.project().path()))

    def onSphinxPath(self):
        """Set the Sphinx path to the current project path."""
        assert core.project().path()
        core.config()['Sphinx']['ProjectPath'] = core.project().path()
        core.config().flush()
        if core.config()['Preview']['Enabled'] and self._dock is not None:
            self._dock._scheduleDocumentProcessing()
Пример #6
0
class Plugin(QObject):
    """Plugin interface implementation
    """
    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(self._onDocumentChanged)
        core.workspace().languageChanged.connect(self._onDocumentChanged)

        # Install our CodeChat page into the settings dialog.
        core.uiSettingsManager().aboutToExecute.connect(self._onSettingsDialogAboutToExecute)
        # Update preview dock when the settings dialog (which contains the CodeChat
        # enable checkbox) is changed.
        core.uiSettingsManager().dialogAccepted.connect(self._onDocumentChanged)

        # If user's config .json file lacks it, populate CodeChat's default
        # config key.
        if not 'CodeChat' in core.config():
            core.config()['CodeChat'] = {}
            core.config()['CodeChat']['Enabled'] = False
            core.config().flush()

    def del_(self):
        """Uninstall the plugin
        """
        if self._dockInstalled:
            self._removeDock()

        if self._dock is not None:
            self._dock.del_()

    def _onDocumentChanged(self):
        """Document or Language changed.
        Create dock, if necessary
        """
        if self._canHighlight(core.workspace().currentDocument()):
            if not self._dockInstalled:
                self._createDock()
        else:
            if self._dockInstalled:
                self._removeDock()

    def _canHighlight(self, document):
        """Check if can highlight document
        """
        if document is None:
            return False

        if document.qutepart.language() in ('Markdown', 'Restructured Text') or \
           isHtmlFile(document):
            return True
        if CodeChat is not None and core.config()['CodeChat']['Enabled'] is True:
            return True
        return False

    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            from enki.plugins.preview.preview import PreviewDock
            self._dock = PreviewDock()
            self._dock.closed.connect(self._onDockClosed)
            self._dock.shown.connect(self._onDockShown)
            self._saveAction = QAction(QIcon(':enkiicons/save.png'), 'Save Preview as HTML', self._dock)
            self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
            self._saveAction.triggered.connect(self._dock.onSave)

        core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)

        core.actionManager().addAction("mView/aPreview", self._dock.showAction())
        core.actionManager().addAction("mFile/aSavePreview", self._saveAction)
        self._dockInstalled = True
        if core.config()['Preview']['Enabled']:
            self._dock.show()

    def _onDockClosed(self):
        """Dock has been closed by user. Change Enabled option
        """
        if core.config()['Preview']['Enabled']:
            core.config()['Preview']['Enabled'] = False
            core.config().flush()

    def _onDockShown(self):
        """Dock has been shown by user. Change Enabled option
        """
        if not core.config()['Preview']['Enabled']:
            core.config()['Preview']['Enabled'] = True
            core.config().flush()

    def _removeDock(self):
        """Remove dock from GUI
        """
        core.actionManager().removeAction("mView/aPreview")
        core.actionManager().removeAction("mFile/aSavePreview")
        core.mainWindow().removeDockWidget(self._dock)
        self._dockInstalled = False

    def _onSettingsDialogAboutToExecute(self, dialog):
        """The UI settings dialog is about to execute. Install CodeChat-related
           settings."""
        # First, append the CodeChat settings page to the settings dialog.
        widget = SettingsWidget(dialog)
        dialog.appendPage(u"CodeChat", widget)
        # Next, have the CodeChat Enabled checkbox auto-update the corresponding
        # CodeChat config entry.
        dialog.appendOption(CheckableOption(dialog, core.config(),
                                            "CodeChat/Enabled",
                                            widget.cbEnable))
Пример #7
0
class Plugin(QObject):
    """Plugin interface implementation
    """
    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)

        if not 'Preview' in core.config(
        ):  # migration from old configs versions
            core.config()['Preview'] = {
                'Enabled': True,
                'JavaScriptEnabled': True
            }

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(
            self._onDocumentChanged)
        core.workspace().languageChanged.connect(self._onDocumentChanged)
        core.mainWindow().stateRestored.connect(
            self._onMainWindowStateRestored)

    def del_(self):
        """Uninstall the plugin
        """
        if self._dockInstalled:
            self._removeDock()

        if self._dock is not None:
            self._dock.del_()

    def _onDocumentChanged(self):
        """Document or Language changed.
        Create dock, if necessary
        """
        if self._canHighlight(core.workspace().currentDocument()):
            if not self._dockInstalled:
                self._createDock()
        else:
            if self._dockInstalled:
                self._removeDock()

    def _onMainWindowStateRestored(self):
        """When main window state is restored - dock is made visible, even if should not. Qt bug?
        Hide dock, if can't view current document
        """
        if (not self._canHighlight(core.workspace().currentDocument())) and \
           self._dock is not None:
            self._dock.hide()

    def _canHighlight(self, document):
        """Check if can highlight document
        """
        if document is None:
            return False

        if document.qutepart.language() == 'reStructuredText' or \
           isHtmlFile(document):
            return True

        if isMarkdownFile(document):
            return True

        return False

    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            from enki.plugins.preview.preview import PreviewDock
            self._dock = PreviewDock()
            self._dock.closed.connect(self._onDockClosed)
            self._dock.showAction().triggered.connect(self._onDockShown)
            self._saveAction = QAction(QIcon(':enkiicons/save.png'),
                                       'Save Preview as HTML', self._dock)
            self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
            self._saveAction.triggered.connect(self._dock.onSave)

        restored = core.mainWindow().restoreDockWidget(self._dock)
        if not restored:
            core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)

        core.actionManager().addAction("mView/aPreview",
                                       self._dock.showAction())
        core.actionManager().addAction("mFile/aSavePreview", self._saveAction)
        self._dockInstalled = True
        if core.config()['Preview']['Enabled']:
            self._dock.show()

    def _onDockClosed(self):
        """Dock has been closed by user. Change Enabled option
        """
        core.config()['Preview']['Enabled'] = False
        core.config().flush()

    def _onDockShown(self):
        """Dock has been shown by user. Change Enabled option
        """
        core.config()['Preview']['Enabled'] = True
        core.config().flush()

    def _removeDock(self):
        """Remove dock from GUI
        """
        core.actionManager().removeAction("mView/aPreview")
        core.actionManager().removeAction("mFile/aSavePreview")
        core.mainWindow().removeDockWidget(self._dock)
        self._dockInstalled = False
Пример #8
0
class Plugin(QObject):
    """Plugin interface implementation
    """
    def __init__(self):
        """Create and install the plugin
        """
        QObject.__init__(self)

        self._dock = None
        self._saveAction = None
        self._dockInstalled = False
        core.workspace().currentDocumentChanged.connect(self._onDocumentChanged)
        core.workspace().languageChanged.connect(self._onDocumentChanged)

    def del_(self):
        """Uninstall the plugin
        """
        if self._dockInstalled:
            self._removeDock()

        if self._dock is not None:
            self._dock.del_()

    def _onDocumentChanged(self):
        """Document or Language changed.
        Create dock, if necessary
        """
        if self._canHighlight(core.workspace().currentDocument()):
            if not self._dockInstalled:
                self._createDock()
        else:
            if self._dockInstalled:
                self._removeDock()

    def _canHighlight(self, document):
        """Check if can highlight document
        """
        if document is None:
            return False

        if document.qutepart.language() in ('Markdown', 'Restructured Text') or \
           isHtmlFile(document):
            return True

        return False

    def _createDock(self):
        """Install dock
        """
        # create dock
        if self._dock is None:
            from enki.plugins.preview.preview import PreviewDock
            self._dock = PreviewDock()
            self._dock.closed.connect(self._onDockClosed)
            self._dock.shown.connect(self._onDockShown)
            self._saveAction = QAction(QIcon(':enkiicons/save.png'), 'Save Preview as HTML', self._dock)
            self._saveAction.setShortcut(QKeySequence("Alt+Shift+P"))
            self._saveAction.triggered.connect(self._dock.onSave)

        core.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self._dock)

        core.actionManager().addAction("mView/aPreview", self._dock.showAction())
        core.actionManager().addAction("mFile/aSavePreview", self._saveAction)
        self._dockInstalled = True
        if core.config()['Preview']['Enabled']:
            self._dock.show()

    def _onDockClosed(self):
        """Dock has been closed by user. Change Enabled option
        """
        if core.config()['Preview']['Enabled']:
            core.config()['Preview']['Enabled'] = False
            core.config().flush()

    def _onDockShown(self):
        """Dock has been shown by user. Change Enabled option
        """
        if not core.config()['Preview']['Enabled']:
            core.config()['Preview']['Enabled'] = True
            core.config().flush()

    def _removeDock(self):
        """Remove dock from GUI
        """
        core.actionManager().removeAction("mView/aPreview")
        core.actionManager().removeAction("mFile/aSavePreview")
        core.mainWindow().removeDockWidget(self._dock)
        self._dockInstalled = False