Commit 9678e95a authored by Christian Hergert's avatar Christian Hergert

html-preview: use menu merging

Now that we can merge menus, just use that instead of manually extending
the menu. Use action:enabled instead of hiding the menu item. I'd rather
we hide the menu item, maybe there is an attribute/hint for that...
parent a7cca903
......@@ -6,16 +6,16 @@ plugindir = $(libdir)/gnome-builder/plugins
dist_plugin_DATA = html-preview.plugin
moduledir = $(libdir)/gnome-builder/plugins/html_preview_plugin
dist_module_DATA = \
html_preview_plugin/__init__.py \
$(NULL)
dist_module_DATA = html_preview_plugin/__init__.py
resourcedir = $(datadir)/gnome-builder/plugins/html_preview_plugin
dist_resource_DATA = \
html_preview_plugin/markdown.css \
html_preview_plugin/markdown-view.js \
html_preview_plugin/marked.js \
$(NULL)
html_preview_plugin/marked.js
resourcegtkdir = $(datadir)/gnome-builder/plugins/html_preview_plugin/gtk
dist_resourcegtk_DATA = html_preview_plugin/gtk/menus.ui
endif
......
......@@ -55,20 +55,19 @@ class HtmlPreviewData(GObject.Object, Ide.ApplicationAddin):
class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
def do_load(self, editor):
self.menu = HtmlPreviewMenu(editor.get_menu())
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')
action = Gio.SimpleAction(name='preview-as-html', enabled=True)
action.connect('activate', lambda *_: self.preview_activated(editor))
actions.add_action(action)
actions.add_action(self.action)
def do_unload(self, editor):
self.menu.hide()
actions = editor.get_action_group('view')
actions.remove_action('preview-as-html')
def do_language_changed(self, language_id):
self.menu.hide()
if language_id in ('html', 'markdown'):
self.menu.show()
enabled = (language_id in ('html', 'markdown'))
self.action.set_enabled(enabled)
def preview_activated(self, editor):
document = editor.get_document()
......@@ -77,19 +76,6 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorViewAddin):
print (stack)
stack.add(view)
class HtmlPreviewMenu:
exten = None
def __init__(self, menu):
self.exten = Ide.MenuExtension.new_for_section(menu, 'preview-section')
def show(self):
item = Gio.MenuItem.new(_("Preview as HTML"), 'view.preview-as-html')
self.exten.append_menu_item(item)
def hide(self):
self.exten.remove_items()
class HtmlPreviewView(Ide.LayoutView):
markdown = False
......
<?xml version="1.0"?>
<interface>
<menu id="ide-layout-stack-menu">
<section id="ide-layout-stack-menu-preview-section">
<item>
<attribute name="label" translatable="yes">Preview as HTML</attribute>
<attribute name="action">view.preview-as-html</attribute>
</item>
</section>
</menu>
</interface>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment