[gnome-builder: 79/139] find-other-file: port to libide-editor



commit d5f7733a2035fb4ef8cf8358fdbc5bdf9305b147
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:18:26 2019 -0800

    find-other-file: port to libide-editor
    
    This ports the find-other-file plugin to use the new API provided by
    libide-editor as well as tweaks for suggestion activation.

 src/plugins/find-other-file/find-other-file.plugin | 15 +++++---
 src/plugins/find-other-file/find_other_file.py     | 45 ++++++++++++----------
 src/plugins/find-other-file/meson.build            |  6 +--
 3 files changed, 35 insertions(+), 31 deletions(-)
---
diff --git a/src/plugins/find-other-file/find-other-file.plugin 
b/src/plugins/find-other-file/find-other-file.plugin
index ae00a077c..bb9e3c7ad 100644
--- a/src/plugins/find-other-file/find-other-file.plugin
+++ b/src/plugins/find-other-file/find-other-file.plugin
@@ -1,9 +1,12 @@
 [Plugin]
-Module=find_other_file
-Loader=python3
-Name=Find other files
-Description=Allows the user to rotate through other files similarly named to the open document.
 Authors=Christian Hergert <christian hergert me>
-Copyright=Copyright © 2017 Christian Hergert
 Builtin=true
-Depends=editor
+Copyright=Copyright © 2017 Christian Hergert
+Depends=editor;
+Description=Allows the user to rotate through other files similarly named to the open document.
+Hidden=true
+Loader=python3
+Module=find_other_file
+Name=Find other files
+X-Builder-ABI=@PACKAGE_ABI@
+X-Workspace-Kind=primary;editor;
diff --git a/src/plugins/find-other-file/find_other_file.py b/src/plugins/find-other-file/find_other_file.py
index 2df1f8bfe..26a92bd5d 100644
--- a/src/plugins/find-other-file/find_other_file.py
+++ b/src/plugins/find-other-file/find_other_file.py
@@ -33,30 +33,33 @@ _ATTRIBUTES = ",".join([
     Gio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON,
 ])
 
-class FindOtherFile(GObject.Object, Ide.WorkbenchAddin):
+class FindOtherFile(GObject.Object, Ide.WorkspaceAddin):
     context = None
+    workspace = None
     workbench = None
 
-    def do_load(self, workbench):
-        self.workbench = workbench
-        self.context = workbench.get_context()
+    def do_load(self, workspace):
+        self.workspace = workspace
+        self.workbench = Ide.widget_get_workbench(workspace)
+        self.context = self.workbench.get_context()
 
         action = Gio.SimpleAction.new('find-other-file', None)
         action.connect('activate', self.on_activate)
-        self.workbench.add_action(action)
+        self.workspace.add_action(action)
 
-    def do_unload(self, workbench):
+    def do_unload(self, workspace):
         self.workbench = None
+        self.workspace = None
         self.context = None
 
     def on_activate(self, *args):
-        editor = self.workbench.get_perspective_by_name('editor')
-        view = editor.get_active_view()
-        if type(view) is not Ide.EditorView:
+        editor = self.workspace.get_surface_by_name('editor')
+        page = editor.get_active_page()
+        if type(page) is not Ide.EditorPage:
             return
 
-        buffer = view.get_buffer()
-        file = buffer.get_file().get_file()
+        buffer = page.get_buffer()
+        file = buffer.get_file()
         parent = file.get_parent()
 
         basename = file.get_basename()
@@ -85,9 +88,8 @@ class FindOtherFile(GObject.Object, Ide.WorkbenchAddin):
                     display_name = info.get_attribute_string(Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME)
                     icon = info.get_attribute_object(Gio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON)
                     icon_name = icon.to_string() if icon else None
-                    gfile = parent.get_child(name)
-                    ifile = Ide.File.new(self.context, gfile)
-                    result = OtherFileSearchResult(file=ifile, icon_name=icon_name, title=display_name)
+                    file = parent.get_child(name)
+                    result = OtherFileSearchResult(file=file, icon_name=icon_name, title=display_name)
                     files.append(result)
 
                 info = enumerator.next_file(None)
@@ -97,8 +99,8 @@ class FindOtherFile(GObject.Object, Ide.WorkbenchAddin):
             count = files.get_n_items()
 
             if count == 1:
-                file = files.get_item(0).file.get_file()
-                self.workbench.open_files_async([file], 'editor', 0, None, None)
+                file = files.get_item(0).file
+                self.workbench.open_async(file, 'editor', 0, None, None)
             elif count:
                 self.present_results(files, basename)
 
@@ -107,7 +109,7 @@ class FindOtherFile(GObject.Object, Ide.WorkbenchAddin):
             return
 
     def present_results(self, results, name):
-        headerbar = self.workbench.get_headerbar()
+        headerbar = self.workspace.get_header_bar()
         search = Dazzle.gtk_widget_find_child_typed(headerbar, Ide.SearchEntry)
         search.set_text('')
         search.set_model(results)
@@ -116,7 +118,10 @@ class FindOtherFile(GObject.Object, Ide.WorkbenchAddin):
 
 
 class OtherFileSearchResult(Ide.SearchResult):
-    file = GObject.Property(type=Ide.File)
+    file = GObject.Property(type=Gio.File)
 
-    def do_get_source_location(self):
-        return Ide.SourceLocation.new(self.file, 0, 0, 0)
+    def do_activate(self, last_focus):
+        workspace = Ide.widget_get_workspace(last_focus)
+        editor = workspace.get_surface_by_name('editor')
+        loc = Ide.Location.new(self.file, -1, -1)
+        editor.focus_location(loc)
diff --git a/src/plugins/find-other-file/meson.build b/src/plugins/find-other-file/meson.build
index 7b2e848ec..4df9128b6 100644
--- a/src/plugins/find-other-file/meson.build
+++ b/src/plugins/find-other-file/meson.build
@@ -1,13 +1,9 @@
-if get_option('with_find_other_file')
-
 install_data('find_other_file.py', install_dir: plugindir)
 
 configure_file(
           input: 'find-other-file.plugin',
          output: 'find-other-file.plugin',
-           copy: true,
+  configuration: config_h,
         install: true,
     install_dir: plugindir,
 )
-
-endif


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