[gnome-builder/wip/gtk4-port] plugins/html-preview: basic porting



commit e38d03743ddc8e32d26b942ab978a7f4b9bf120d
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 20 16:38:27 2022 -0700

    plugins/html-preview: basic porting
    
    This isn't really tested yet, because my NVIDIA driver sucks so bad.

 src/plugins/html-preview/gtk/menus.ui    |  2 +-
 src/plugins/html-preview/html_preview.py | 28 ++++++++--------------------
 src/plugins/meson.build                  |  2 +-
 3 files changed, 10 insertions(+), 22 deletions(-)
---
diff --git a/src/plugins/html-preview/gtk/menus.ui b/src/plugins/html-preview/gtk/menus.ui
index 729b91e0d..6f4483abe 100644
--- a/src/plugins/html-preview/gtk/menus.ui
+++ b/src/plugins/html-preview/gtk/menus.ui
@@ -5,7 +5,7 @@
       <item>
         <attribute name="after">editor-document-open-in-new-frame</attribute>
         <attribute name="label" translatable="yes">Open Preview</attribute>
-        <attribute name="action">editor-page.preview-as-html</attribute>
+        <attribute name="action">html-preview.preview-as-html</attribute>
       </item>
     </section>
   </menu>
diff --git a/src/plugins/html-preview/html_preview.py b/src/plugins/html-preview/html_preview.py
index 29b46b602..9a419eb34 100644
--- a/src/plugins/html-preview/html_preview.py
+++ b/src/plugins/html-preview/html_preview.py
@@ -30,7 +30,6 @@ import sys
 import subprocess
 import threading
 
-from gi.repository import Dazzle
 from gi.repository import GLib
 from gi.repository import Gio
 from gi.repository import Gtk
@@ -213,7 +212,8 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorPageAddin):
         self.sphinx_basedir = None
         self.sphinx_builddir = None
 
-        group = view.get_action_group('editor-page')
+        group = Gio.SimpleActionGroup()
+        view.insert_action_group('html-preview', group)
 
         self.action = Gio.SimpleAction(name='preview-as-html', enabled=True)
         self.activate_handler = self.action.connect('activate', self.preview_activated)
@@ -225,19 +225,10 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorPageAddin):
 
         self.do_language_changed(language_id)
 
-        # Add a shortcut for activation inside the editor
-        controller = Dazzle.ShortcutController.find(view)
-        controller.add_command_action('org.gnome.builder.html-preview.preview',
-                                      '<Control><Alt>p',
-                                      Dazzle.ShortcutPhase.CAPTURE,
-                                      'editor-page.preview-as-html')
-
     def do_unload(self, view):
+        view.insert_action_group('html-preview', None)
         self.action.disconnect(self.activate_handler)
 
-        group = view.get_action_group('editor-page')
-        group.remove_action('preview-as-html')
-
         self.action = None
         self.view = None
         self.context = None
@@ -296,15 +287,12 @@ class HtmlPreviewAddin(GObject.Object, Ide.EditorPageAddin):
                                    self.sphinx_builddir,
                                    visible=True)
 
-        column = view.get_ancestor(Ide.GridColumn)
-        grid = column.get_ancestor(Ide.Grid)
-        index = grid.child_get_property(column, 'index')
+        position = view.get_position()
+        _, column = view.get_column()
+        position.set_column(column + 1)
 
-        # If we are past first stack, use the 0 column stack
-        # otherwise create or reuse a stack to the right.
-        index += -1 if index > 0 else 1
-        column = grid.get_nth_column(index)
-        column.add(web_view)
+        workspace = view.get_ancestor(Ide.Workspace)
+        workspace.add_page(web_view, position)
 
         self.action.set_enabled(False)
         web_view.connect('destroy', self.web_view_destroyed)
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 55f58f3a3..308d6106d 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -85,7 +85,7 @@ subdir('greeter')
 #subdir('gvls')
 #subdir('history')
 subdir('html-completion')
-#subdir('html-preview')
+subdir('html-preview')
 subdir('intelephense')
 subdir('jedi-language-server')
 subdir('jhbuild')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]