From 80d5760e88fd9c6a630baf3e7bff9cef024047fb Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Sat, 23 Nov 2013 15:22:56 -0500 Subject: [PATCH 01/11] Fixes for python3 --- sourcecodebrowser.plugin | 2 +- sourcecodebrowser/__init__.py | 3 +-- sourcecodebrowser/ctags.py | 2 +- sourcecodebrowser/plugin.py | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sourcecodebrowser.plugin b/sourcecodebrowser.plugin index c929aca..f3945c1 100644 --- a/sourcecodebrowser.plugin +++ b/sourcecodebrowser.plugin @@ -1,5 +1,5 @@ [Plugin] -Loader=python +Loader=python3 Module=sourcecodebrowser IAge=3 Name=Source Code Browser diff --git a/sourcecodebrowser/__init__.py b/sourcecodebrowser/__init__.py index b302f1f..ceb9cbd 100644 --- a/sourcecodebrowser/__init__.py +++ b/sourcecodebrowser/__init__.py @@ -1,3 +1,2 @@ -import plugin -from plugin import SourceCodeBrowserPlugin +from sourcecodebrowser.plugin import SourceCodeBrowserPlugin diff --git a/sourcecodebrowser/ctags.py b/sourcecodebrowser/ctags.py index 7e978c6..ed45e05 100644 --- a/sourcecodebrowser/ctags.py +++ b/sourcecodebrowser/ctags.py @@ -95,7 +95,7 @@ def _parse_text(self, text): Parses ctags text which may have come from a TAG file or from raw output from a ctags command. """ - for line in text.splitlines(): + for line in str(text, encoding='utf8').splitlines(): name = None file = None ex_command = None diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index 19123fc..ab01efe 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -2,7 +2,7 @@ import sys import logging import tempfile -import ctags +from sourcecodebrowser import ctags from gi.repository import GObject, GdkPixbuf, Gedit, Gtk, PeasGtk, Gio logging.basicConfig() From a506186f0d8d09798fdb98d980923446e13834cf Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 22 Apr 2013 13:57:12 +0200 Subject: [PATCH 02/11] Port to Python 3 / Gedit 3.8 --- sourcecodebrowser.plugin | 2 +- sourcecodebrowser/__init__.py | 5 ++--- sourcecodebrowser/ctags.py | 4 ++-- sourcecodebrowser/plugin.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/sourcecodebrowser.plugin b/sourcecodebrowser.plugin index c929aca..f3945c1 100644 --- a/sourcecodebrowser.plugin +++ b/sourcecodebrowser.plugin @@ -1,5 +1,5 @@ [Plugin] -Loader=python +Loader=python3 Module=sourcecodebrowser IAge=3 Name=Source Code Browser diff --git a/sourcecodebrowser/__init__.py b/sourcecodebrowser/__init__.py index b302f1f..db939c2 100644 --- a/sourcecodebrowser/__init__.py +++ b/sourcecodebrowser/__init__.py @@ -1,3 +1,2 @@ -import plugin -from plugin import SourceCodeBrowserPlugin - +from . import plugin +from .plugin import SourceCodeBrowserPlugin diff --git a/sourcecodebrowser/ctags.py b/sourcecodebrowser/ctags.py index 7e978c6..a581f6a 100644 --- a/sourcecodebrowser/ctags.py +++ b/sourcecodebrowser/ctags.py @@ -88,8 +88,8 @@ def parse(self, command, executable=None): #args = [arg.replace('%20', ' ') for arg in shlex.split(command)] args = shlex.split(command) p = subprocess.Popen(args, 0, shell=False, stdout=subprocess.PIPE, executable=executable) - symbols = self._parse_text(p.communicate()[0]) - + symbols = self._parse_text(p.communicate()[0].decode('utf8')) + def _parse_text(self, text): """ Parses ctags text which may have come from a TAG file or from raw output diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index 19123fc..f785c56 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -2,7 +2,7 @@ import sys import logging import tempfile -import ctags +from . import ctags from gi.repository import GObject, GdkPixbuf, Gedit, Gtk, PeasGtk, Gio logging.basicConfig() From 886840b7b3c07d46329d7f63ce197064b114b8c1 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Mon, 12 May 2014 11:21:03 +0200 Subject: [PATCH 03/11] Port to gedit 3.12 GEdit version 3.12 changed the API for plugins; in particular, this patch interfaces correctly with the side panel, which is now a GtkStack. --- sourcecodebrowser/plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index f785c56..4e861cb 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -330,7 +330,7 @@ def do_activate(self): self._sourcetree.expand_rows = self.expand_rows self._sourcetree.sort_list = self.sort_list panel = self.window.get_side_panel() - panel.add_item(self._sourcetree, "SymbolBrowserPlugin", "Source Code", self.icon) + panel.add_titled(self._sourcetree, "SymbolBrowserPlugin", "Source Code") self._handlers = [] hid = self._sourcetree.connect("focus", self.on_sourcetree_focus) self._handlers.append((self._sourcetree, hid)) @@ -353,7 +353,7 @@ def do_deactivate(self): obj.disconnect(hid) self._handlers = None pane = self.window.get_side_panel() - pane.remove_item(self._sourcetree) + pane.remove(self._sourcetree) self._sourcetree = None def _has_settings_schema(self): @@ -393,7 +393,7 @@ def _load_active_document_symbols(self): self._is_loaded = False # do not load if not the active tab in the panel panel = self.window.get_side_panel() - if not panel.item_is_active(self._sourcetree): + if panel.get_visible_child() != self._sourcetree: return document = self.window.get_active_document() From 2d42e723d8283983dc83a64b7451d63be86d1f92 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Mon, 12 May 2014 12:22:51 +0200 Subject: [PATCH 04/11] Try to load symbols on draw event We must make sure that symbols are loaded for current document even if the sourcetree does not get the focus: it is sufficient that it is drawn. --- sourcecodebrowser/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index 4e861cb..9869f83 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -332,7 +332,7 @@ def do_activate(self): panel = self.window.get_side_panel() panel.add_titled(self._sourcetree, "SymbolBrowserPlugin", "Source Code") self._handlers = [] - hid = self._sourcetree.connect("focus", self.on_sourcetree_focus) + hid = self._sourcetree.connect("draw", self.on_sourcetree_draw) self._handlers.append((self._sourcetree, hid)) if self.ctags_version is not None: hid = self._sourcetree.connect('tag-activated', self.on_tag_activated) @@ -451,7 +451,7 @@ def on_setting_changed(self, settings, key, data=None): self._sourcetree.expanded_rows = {} self._load_active_document_symbols() - def on_sourcetree_focus(self, direction, data=None): + def on_sourcetree_draw(self, sourcetree, data=None): if not self._is_loaded: self._load_active_document_symbols() return False From 0c5fcfa7b2d6f7df8f2cd5b056b017f5caf1b5c3 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Wed, 14 May 2014 00:33:59 +0200 Subject: [PATCH 05/11] Fix copying of remote files with Python 3 This closes LP #1313112 --- sourcecodebrowser/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index 9869f83..aca5e2d 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -413,7 +413,7 @@ def _load_active_document_symbols(self): contents = document.get_text(document.get_start_iter(), document.get_end_iter(), True) - os.write(fd, contents) + os.write(fd, bytes(contents, 'UTF-8')) os.close(fd) while Gtk.events_pending(): Gtk.main_iteration() From 89c821fac56711a185514bb3d3d9504ecffac628 Mon Sep 17 00:00:00 2001 From: Pietro Battiston Date: Wed, 14 May 2014 01:02:32 +0200 Subject: [PATCH 06/11] Replace the deprecated Gtk.VBox with Gtk.Box --- sourcecodebrowser/plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index aca5e2d..15af4ef 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -11,7 +11,7 @@ DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') ICON_DIR = os.path.join(DATA_DIR, 'icons', '16x16') -class SourceTree(Gtk.VBox): +class SourceTree(Gtk.Box): """ Source Tree Widget @@ -23,7 +23,8 @@ class SourceTree(Gtk.VBox): } def __init__(self): - Gtk.VBox.__init__(self) + Gtk.Box.__init__(self) + self.set_orientation(Gtk.Orientation.VERTICAL) self._log = logging.getLogger(self.__class__.__name__) self._log.setLevel(LOG_LEVEL) self._pixbufs = {} From b145c12ea7d543e24b421ed6ea04eda901ba3970 Mon Sep 17 00:00:00 2001 From: Megh Parikh Date: Fri, 10 Apr 2015 18:54:54 +0530 Subject: [PATCH 07/11] Update README.markdown --- README.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 8cb6373..fde6f8d 100644 --- a/README.markdown +++ b/README.markdown @@ -36,7 +36,7 @@ Installation 1. Download this repository by clicking the Downloads button at the top of the github page or issue the following command in a terminal: - git clone git://github.com/Quixotix/gedit-source-code-browser.git + ```git clone git://github.com/toobaz/gedit-source-code-browser.git --depth=1``` 2. Copy the file `sourcecodebrowser.plugin` and the folder `sourcecodebrowser` to `~/.local/share/gedit/plugins/`. @@ -49,11 +49,13 @@ Installation 5. (Optional) If you want to enable the configuration dialog you need to compile the settings schema. You must do this as root. + ``` cd /home/<YOUR USER NAME>/.local/share/gedit/plugins/sourcecodebrowser/data/ cp org.gnome.gedit.plugins.sourcecodebrowser.gschema.xml /usr/share/glib-2.0/schemas/ glib-compile-schemas /usr/share/glib-2.0/schemas/ + ``` Screenshots ----------- From 8360ad9f130f6112e7102c66a368245372d7c689 Mon Sep 17 00:00:00 2001 From: Megh Parikh Date: Fri, 10 Apr 2015 18:58:17 +0530 Subject: [PATCH 08/11] Update README.markdown --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index fde6f8d..a74e22e 100644 --- a/README.markdown +++ b/README.markdown @@ -50,7 +50,7 @@ Installation the settings schema. You must do this as root. ``` - cd /home/<YOUR USER NAME>/.local/share/gedit/plugins/sourcecodebrowser/data/ + cd /home//.local/share/gedit/plugins/sourcecodebrowser/data/ cp org.gnome.gedit.plugins.sourcecodebrowser.gschema.xml /usr/share/glib-2.0/schemas/ From 696c4371a232cea417ba306b8b535eed237120ff Mon Sep 17 00:00:00 2001 From: nuclearmistake Date: Fri, 26 Aug 2016 12:35:59 -0400 Subject: [PATCH 09/11] Fix for gedit 3.10 --- sourcecodebrowser/plugin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index 15af4ef..6378849 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -331,7 +331,10 @@ def do_activate(self): self._sourcetree.expand_rows = self.expand_rows self._sourcetree.sort_list = self.sort_list panel = self.window.get_side_panel() - panel.add_titled(self._sourcetree, "SymbolBrowserPlugin", "Source Code") + if hasattr(panel,"add_titled"): + panel.add_titled(self._sourcetree, "SymbolBrowserPlugin", "Source Code") + else: + panel.add_item(self._sourcetree, "SymbolBrowserPlugin", "Source Code") self._handlers = [] hid = self._sourcetree.connect("draw", self.on_sourcetree_draw) self._handlers.append((self._sourcetree, hid)) @@ -394,8 +397,6 @@ def _load_active_document_symbols(self): self._is_loaded = False # do not load if not the active tab in the panel panel = self.window.get_side_panel() - if panel.get_visible_child() != self._sourcetree: - return document = self.window.get_active_document() if document: From 957c8ec9fb8b91c7cf1a6fac85fe6ab4965b5699 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Sat, 1 Oct 2016 17:05:44 -0400 Subject: [PATCH 10/11] Fix, thanks to the nucleartags dude --- sourcecodebrowser/ctags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sourcecodebrowser/ctags.py b/sourcecodebrowser/ctags.py index 6b00093..a581f6a 100644 --- a/sourcecodebrowser/ctags.py +++ b/sourcecodebrowser/ctags.py @@ -95,7 +95,7 @@ def _parse_text(self, text): Parses ctags text which may have come from a TAG file or from raw output from a ctags command. """ - for line in str(text, encoding='utf8').splitlines(): + for line in text.splitlines(): name = None file = None ex_command = None From 71ed19fd388314a58083aaaaa4c536b452dceeec Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Tue, 31 Oct 2017 10:40:44 -0400 Subject: [PATCH 11/11] Fixes, and remove trailing whitespace --- sourcecodebrowser/__init__.py | 4 +- sourcecodebrowser/ctags.py | 2 +- sourcecodebrowser/plugin.py | 175 +++++++++++++++++----------------- 3 files changed, 89 insertions(+), 92 deletions(-) diff --git a/sourcecodebrowser/__init__.py b/sourcecodebrowser/__init__.py index 6d373b2..c8c4e2c 100644 --- a/sourcecodebrowser/__init__.py +++ b/sourcecodebrowser/__init__.py @@ -1,2 +1,2 @@ -from import plugin -from plugin import SourceCodeBrowserPlugin +from . import plugin +from . plugin import SourceCodeBrowserPlugin diff --git a/sourcecodebrowser/ctags.py b/sourcecodebrowser/ctags.py index 6b00093..a581f6a 100644 --- a/sourcecodebrowser/ctags.py +++ b/sourcecodebrowser/ctags.py @@ -95,7 +95,7 @@ def _parse_text(self, text): Parses ctags text which may have come from a TAG file or from raw output from a ctags command. """ - for line in str(text, encoding='utf8').splitlines(): + for line in text.splitlines(): name = None file = None ex_command = None diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index f7b9c15..3fa0bc3 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -2,7 +2,7 @@ import sys import logging import tempfile -import ctags +from . import ctags from gi.repository import GObject, GdkPixbuf, Gedit, Gtk, PeasGtk, Gio logging.basicConfig() @@ -10,18 +10,18 @@ SETTINGS_SCHEMA = "org.gnome.gedit.plugins.sourcecodebrowser" DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') ICON_DIR = os.path.join(DATA_DIR, 'icons', '16x16') - + class SourceTree(Gtk.Box): """ Source Tree Widget - + A treeview storing the heirarchy of source code symbols within a particular document. Requries exhuberant-ctags. """ __gsignals__ = { "tag-activated": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT,)), - } - + } + def __init__(self): Gtk.Box.__init__(self) self.set_orientation(Gtk.Orientation.VERTICAL) @@ -30,7 +30,7 @@ def __init__(self): self._pixbufs = {} self._current_uri = None self.expanded_rows = {} - + # preferences (should be set by plugin) self.show_line_numbers = True self.ctags_executable = 'ctags' @@ -38,52 +38,52 @@ def __init__(self): self.sort_list = True self.create_ui() self.show_all() - + def get_missing_pixbuf(self): """ Used for symbols that do not have a known image. """ if not 'missing' in self._pixbufs: filename = os.path.join(ICON_DIR, "missing-image.png") self._pixbufs['missing'] = GdkPixbuf.Pixbuf.new_from_file(filename) - + return self._pixbufs['missing'] - + def get_pixbuf(self, icon_name): - """ + """ Get the pixbuf for a specific icon name fron an internal dictionary of pixbufs. If the icon is not already in the dictionary, it will be loaded - from an external file. + from an external file. """ - if icon_name not in self._pixbufs: + if icon_name not in self._pixbufs: filename = os.path.join(ICON_DIR, icon_name + ".png") if os.path.exists(filename): try: self._pixbufs[icon_name] = GdkPixbuf.Pixbuf.new_from_file(filename) except Exception as e: - self._log.warn("Could not load pixbuf for icon '%s': %s", - icon_name, + self._log.warn("Could not load pixbuf for icon '%s': %s", + icon_name, str(e)) self._pixbufs[icon_name] = self.get_missing_pixbuf() else: self._pixbufs[icon_name] = self.get_missing_pixbuf() - + return self._pixbufs[icon_name] def clear(self): """ Clear the tree view so that new data can be loaded. """ - if self.expand_rows: + if self.expand_rows: self._save_expanded_rows() self._store.clear() - + def create_ui(self): """ Craete the main user interface and pack into box. """ self._store = Gtk.TreeStore(GdkPixbuf.Pixbuf, # icon GObject.TYPE_STRING, # name GObject.TYPE_STRING, # kind - GObject.TYPE_STRING, # uri - GObject.TYPE_STRING, # line - GObject.TYPE_STRING) # markup + GObject.TYPE_STRING, # uri + GObject.TYPE_STRING, # line + GObject.TYPE_STRING) # markup self._treeview = Gtk.TreeView.new_with_model(self._store) - self._treeview.set_headers_visible(False) + self._treeview.set_headers_visible(False) column = Gtk.TreeViewColumn("Symbol") cell = Gtk.CellRendererPixbuf() column.pack_start(cell, False) @@ -92,14 +92,14 @@ def create_ui(self): column.pack_start(cell, True) column.add_attribute(cell, 'markup', 5) self._treeview.append_column(column) - + self._treeview.connect("row-activated", self.on_row_activated) - + sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.add(self._treeview) self.pack_start(sw, True, True, 0) - + def _get_tag_iter(self, tag, parent_iter=None): """ Get the tree iter for the specified tag, or None if the tag cannot @@ -110,9 +110,9 @@ def _get_tag_iter(self, tag, parent_iter=None): if self._store.get_value(tag_iter, 1) == tag.name: return tag_iter tag_iter = self._store.iter_next(tag_iter) - + return None - + def _get_kind_iter(self, kind, uri, parent_iter=None): """ Get the iter for the specified kind. Creates a new node if the iter @@ -123,27 +123,27 @@ def _get_kind_iter(self, kind, uri, parent_iter=None): if self._store.get_value(kind_iter, 2) == kind.name: return kind_iter kind_iter = self._store.iter_next(kind_iter) - + # Kind node not found, so we'll create it. pixbuf = self.get_pixbuf(kind.icon_name()) markup = "%s" % kind.group_name() - kind_iter = self._store.append(parent_iter, (pixbuf, - kind.group_name(), - kind.name, - uri, - None, + kind_iter = self._store.append(parent_iter, (pixbuf, + kind.group_name(), + kind.name, + uri, + None, markup)) return kind_iter - + def load(self, kinds, tags, uri): """ - Load the tags into the treeview and restore the expanded rows if + Load the tags into the treeview and restore the expanded rows if applicable. """ self._current_uri = uri # load root-level tags first for i, tag in enumerate(tags): - if "class" not in tag.fields: + if "class" not in tag.fields: parent_iter = None pixbuf = self.get_pixbuf(tag.kind.icon_name()) if 'line' in tag.fields and self.show_line_numbers: @@ -151,13 +151,13 @@ def load(self, kinds, tags, uri): else: markup = tag.name kind_iter = self._get_kind_iter(tag.kind, uri, parent_iter) - new_iter = self._store.append(kind_iter, (pixbuf, - tag.name, - tag.kind.name, - uri, - tag.fields['line'], + new_iter = self._store.append(kind_iter, (pixbuf, + tag.name, + tag.kind.name, + uri, + tag.fields['line'], markup)) - # second level tags + # second level tags for tag in tags: if "class" in tag.fields and "." not in tag.fields['class']: pixbuf = self.get_pixbuf(tag.kind.icon_name()) @@ -171,20 +171,20 @@ def load(self, kinds, tags, uri): kind_iter = self._get_kind_iter(parent_tag.kind, uri, None) parent_iter = self._get_tag_iter(parent_tag, kind_iter) kind_iter = self._get_kind_iter(tag.kind, uri, parent_iter) # for sub-kind nodes - new_iter = self._store.append(kind_iter, (pixbuf, - tag.name, - tag.kind.name, - uri, - tag.fields['line'], + new_iter = self._store.append(kind_iter, (pixbuf, + tag.name, + tag.kind.name, + uri, + tag.fields['line'], markup)) - # TODO: We need to go at least one more level to deal with the inline + # TODO: We need to go at least one more level to deal with the inline # classes used in many python projects (eg. Models in Django) # Recursion would be even better. - - # sort - if self.sort_list: + + # sort + if self.sort_list: self._store.set_sort_column_id(1, Gtk.SortType.ASCENDING) - + # expand if uri in self.expanded_rows: for strpath in self.expanded_rows[uri]: @@ -226,25 +226,25 @@ def parse_file(self, path, uri): parser.parse(command, self.ctags_executable) except Exception as e: self._log.warn("Could not execute ctags: %s (executable=%s)", - str(e), + str(e), self.ctags_executable) self.load(parser.kinds, parser.tags, uri) - - + + def _save_expanded_rows(self): self.expanded_rows[self._current_uri] = [] - self._treeview.map_expanded_rows(self._save_expanded_rows_mapping_func, + self._treeview.map_expanded_rows(self._save_expanded_rows_mapping_func, self._current_uri) - + def _save_expanded_rows_mapping_func(self, treeview, path, uri): self.expanded_rows[uri].append(str(path)) - - + + class Config(object): def __init__(self): self._log = logging.getLogger(self.__class__.__name__) self._log.setLevel(LOG_LEVEL) - + def get_widget(self, has_schema): filename = os.path.join(DATA_DIR, 'configure_dialog.ui') builder = Gtk.Builder() @@ -256,7 +256,7 @@ def get_widget(self, has_schema): return None widget = builder.get_object("configure_widget") widget.set_border_width(12) - + if not has_schema: widget.set_sensitive(False) else: @@ -278,30 +278,30 @@ def get_widget(self, has_schema): ) builder.connect_signals(self) return widget - + def on_show_line_numbers_toggled(self, button, data=None): self._settings.set_boolean('show-line-numbers', button.get_active()) - + def on_expand_rows_toggled(self, button, data=None): self._settings.set_boolean('expand-rows', button.get_active()) - + def on_load_remote_files_toggled(self, button, data=None): self._settings.set_boolean('load-remote-files', button.get_active()) - + def on_sort_list_toggled(self, button, data=None): self._settings.set_boolean('sort-list', button.get_active()) - + def on_ctags_executable_changed(self, editable, data=None): self._settings.set_string('ctags-executable', editable.get_text()) - - + + class SourceCodeBrowserPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable): """ Source Code Browser Plugin for Gedit 3.x - + Adds a tree view to the side panel of a Gedit window which provides a list of programming symbols (functions, classes, variables, etc.). - + https://live.gnome.org/Gedit/PythonPluginHowTo """ __gtype_name__ = "SourceCodeBrowserPlugin" @@ -316,10 +316,10 @@ def __init__(self): filename = os.path.join(ICON_DIR, "source-code-browser.png") self.icon = Gtk.Image.new_from_file(filename) - + def do_create_configure_widget(self): return Config().get_widget(self._has_settings_schema()) - + def do_activate(self): """ Activate plugin """ self._log.debug("Activating plugin") @@ -349,7 +349,7 @@ def do_activate(self): self._handlers.append((self.window, hid)) else: self._sourcetree.set_sensitive(False) - + def do_deactivate(self): """ Deactivate the plugin """ self._log.debug("Deactivating plugin") @@ -359,14 +359,14 @@ def do_deactivate(self): pane = self.window.get_side_panel() pane.remove(self._sourcetree) self._sourcetree = None - + def _has_settings_schema(self): schemas = Gio.Settings.list_schemas() if not SETTINGS_SCHEMA in schemas: return False else: return True - + def _init_settings(self): """ Initialize GSettings if available. """ if self._has_settings_schema(): @@ -390,7 +390,7 @@ def _init_settings(self): self.expand_rows = True self.sort_list = True self.ctags_executable = 'ctags' - + def _load_active_document_symbols(self): """ Load the symbols for the given URI. """ self._sourcetree.clear() @@ -407,7 +407,7 @@ def _load_active_document_symbols(self): if uri is not None: if uri[:7] == "file://": # use get_parse_name() to get path in UTF-8 - filename = location.get_parse_name() + filename = location.get_parse_name() self._sourcetree.parse_file(filename, uri) elif self.load_remote_files: basename = location.get_basename() @@ -423,10 +423,10 @@ def _load_active_document_symbols(self): os.unlink(filename) self._loaded_document = document self._is_loaded = True - + def on_active_tab_changed(self, window, tab, data=None): self._load_active_document_symbols() - + def on_setting_changed(self, settings, key, data=None): """ self.load_remote_files = True @@ -444,7 +444,7 @@ def on_setting_changed(self, settings, key, data=None): self.sort_list = self._settings.get_boolean(key) elif key == 'ctags-executable': self.ctags_executable = self._settings.get_string(key) - + if self._sourcetree is not None: self._sourcetree.ctags_executable = self.ctags_executable self._sourcetree.show_line_numbers = self.show_line_numbers @@ -452,19 +452,19 @@ def on_setting_changed(self, settings, key, data=None): self._sourcetree.sort_list = self.sort_list self._sourcetree.expanded_rows = {} self._load_active_document_symbols() - + def on_sourcetree_draw(self, sourcetree, data=None): if not self._is_loaded: self._load_active_document_symbols() return False - + def on_tab_state_changed(self, window, data=None): self._load_active_document_symbols() - + def on_tab_removed(self, window, tab, data=None): if not self.window.get_active_document(): self._sourcetree.clear() - + def on_tag_activated(self, sourcetree, location, data=None): """ Go to the line where the double-clicked symbol is defined. """ uri, line = location @@ -474,13 +474,10 @@ def on_tag_activated(self, sourcetree, location, data=None): line = int(line) - 1 # lines start from 0 document.goto_line(line) view.scroll_to_cursor() - + def _version_check(self): """ Make sure the exhuberant ctags is installed. """ - self.ctags_version = ctags.get_ctags_version(self.ctags_executable) + self.ctags_version = ctags.get_ctags_version(self.ctags_executable) if not self.ctags_version: - self._log.warn("Could not find ctags executable: %s" % + self._log.warn("Could not find ctags executable: %s" % (self.ctags_executable)) - - -