[gnome-builder] html preview: add missing docutils message
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] html preview: add missing docutils message
- Date: Tue, 14 Mar 2017 23:34:04 +0000 (UTC)
commit bfc72e2c03c42f43177edff1c2fe11af7e8fecd0
Author: Sebastien Lafargue <slafargue gnome org>
Date: Tue Mar 14 22:30:52 2017 +0100
html preview: add missing docutils message
.../html-preview/html_preview_plugin/__init__.py | 43 ++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/plugins/html-preview/html_preview_plugin/__init__.py
b/plugins/html-preview/html_preview_plugin/__init__.py
index b4ac668..6f6cbe5 100644
--- a/plugins/html-preview/html_preview_plugin/__init__.py
+++ b/plugins/html-preview/html_preview_plugin/__init__.py
@@ -63,12 +63,22 @@ class HtmlPreviewData(GObject.Object, Ide.ApplicationAddin):
class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
def do_load(self, editor):
+ self.workbench = editor.get_ancestor(Ide.Workbench)
+
self.action = Gio.SimpleAction(name='preview-as-html', enabled=True)
self.action.connect('activate', lambda *_: self.preview_activated(editor))
actions = editor.get_action_group('view')
actions.add_action(self.action)
+ self.install_action = Gio.SimpleAction(name='install-docutils', enabled=True)
+ self.install_action.connect('activate', lambda *_: self.install_docutils(editor))
+
+ group = Gio.SimpleActionGroup()
+ group.insert(self.install_action)
+
+ self.workbench.insert_action_group('html-preview', group)
+
def do_unload(self, editor):
actions = editor.get_action_group('view')
actions.remove_action('preview-as-html')
@@ -78,9 +88,13 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
self.action.set_enabled(enabled)
def preview_activated(self, editor):
+ global can_preview_rst
+
document = editor.get_document()
language = document.get_language()
+
if language and language.get_id() == 'rst' and not can_preview_rst:
+ self.show_missing_message(editor)
return
view = HtmlPreviewView(document, visible=True)
@@ -88,6 +102,35 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
stack = editor.get_ancestor(Ide.LayoutStack)
stack.add(view)
+ def show_missing_message(self, editor):
+ message = Ide.WorkbenchMessage(
+ id='org.gnome.builder.docutils.install',
+ title=_('Your computer is missing python3-docutils'),
+ show_close_button=True,
+ visible=True)
+
+ message.add_action(_('Install'), 'html-preview.install-docutils')
+ self.workbench.push_message(message)
+
+ def install_docutils(self, editor):
+ transfer = Ide.PkconTransfer(packages=['python3-docutils'])
+ context = self.workbench.get_context()
+ manager = context.get_transfer_manager()
+
+ manager.execute_async(transfer, None, self.docutils_installed, None)
+
+ def docutils_installed(self, object, result, data):
+ global can_preview_rst
+ global publish_string
+
+ try:
+ from docutils.core import publish_string
+ except ImportError:
+ return
+
+ can_preview_rst = True
+ self.workbench.pop_message('org.gnome.builder.docutils.install')
+
class HtmlPreviewView(Ide.LayoutView):
markdown = False
rst = False
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]