diff --git a/README.markdown b/README.md similarity index 93% rename from README.markdown rename to README.md index 4137cac..1eec6e8 100644 --- a/README.markdown +++ b/README.md @@ -1,9 +1,9 @@ Gedit Source Code Browser ========================= -![No Longer Maintained](https://img.shields.io/badge/maintained-no-red.svg) +![Currently Maintained](https://img.shields.io/badge/maintained-yes-brightgreen.svg) -A source code class and function browser plugin for Gedit 3. +A source code class and function browser plugin for Gedit 40. This plugin will add a new tab to the side pane in the Gedit text editor which shows symbols (functions, classes, variables, etc.) for the active document. @@ -17,7 +17,7 @@ for a list of the 41 programming languages supported by this plugin. Requirements ------------ -This plugins is for Gedit 3 and is **not compatible with Gedit 2.x**. +This plugins is for Gedit 40. The Gedit Source Code Browser plugin uses [Exuberant Ctags](http://ctags.sourceforge.net/) to parse symbols @@ -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/MicahCarrick/gedit-source-code-browser.git + git clone git://github.com/Supreeeme/gedit-source-code-browser.git 2. Copy the file `sourcecodebrowser.plugin` and the folder `sourcecodebrowser` to `~/.local/share/gedit/plugins/`. diff --git a/screenshot.png b/screenshot.png index c4e54a2..2384bab 100644 Binary files a/screenshot.png and b/screenshot.png differ 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..7698b20 100644 --- a/sourcecodebrowser/__init__.py +++ b/sourcecodebrowser/__init__.py @@ -1,3 +1,3 @@ -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..36176ea 100644 --- a/sourcecodebrowser/ctags.py +++ b/sourcecodebrowser/ctags.py @@ -95,12 +95,15 @@ def _parse_text(self, text): Parses ctags text which may have come from a TAG file or from raw output from a ctags command. """ + #print(str(text, 'utf-8')) for line in text.splitlines(): name = None file = None ex_command = None kind = None - for i, field in enumerate(line.split("\t")): + for i, f in enumerate(line.split(b'\t')): + # print(i, f) + field = str(f, 'utf-8') if i == 0: tag = Tag(field) elif i == 1: tag.file = field elif i == 2: tag.ex_command = field @@ -132,7 +135,7 @@ def get_tree(self): if not p in node: node[p] = {'tag':None, 'children':{}} node = node[p] - print node + print(node) node['tag'] = tag else: if not parent in self.tree: @@ -146,4 +149,7 @@ def get_tree(self): return tree """ - + +if __name__ == "__main__": + the_parser = Parser() + the_parser.parse("ctags -nu --fields=fiKlmnsSzt -f - ctags.py", "ctags") diff --git a/sourcecodebrowser/data/configure_dialog.ui b/sourcecodebrowser/data/configure_dialog.ui index a1f46e3..18c6ac2 100644 --- a/sourcecodebrowser/data/configure_dialog.ui +++ b/sourcecodebrowser/data/configure_dialog.ui @@ -1,6 +1,7 @@ + - + False 5 @@ -8,6 +9,9 @@ dialog True True + + + False @@ -20,10 +24,10 @@ gtk-close + False True True True - False True @@ -45,13 +49,32 @@ True False vertical + + + Use _bottom panel + False + True + True + False + True + 0 + True + + + + False + True + 6 + 0 + + Show _line numbers in tree + False True True False - False True 0 True @@ -67,10 +90,10 @@ Load symbols from _remote files + False True True False - False True 0 True @@ -86,10 +109,10 @@ Start with rows _expanded + False True True False - False True 0 True @@ -105,10 +128,10 @@ _Sort list alphabetically + False True True False - False True 0 True @@ -124,13 +147,15 @@ True - False + True + True True - False - 0 + True + 5 ctags executable + 0 False @@ -139,18 +164,16 @@ - + True True - - ctags - True - + True + + False True - 6 1 @@ -159,6 +182,7 @@ False True 6 + end 4 diff --git a/sourcecodebrowser/data/org.gnome.gedit.plugins.sourcecodebrowser.gschema.xml b/sourcecodebrowser/data/org.gnome.gedit.plugins.sourcecodebrowser.gschema.xml index c7313f2..f8fd62f 100644 --- a/sourcecodebrowser/data/org.gnome.gedit.plugins.sourcecodebrowser.gschema.xml +++ b/sourcecodebrowser/data/org.gnome.gedit.plugins.sourcecodebrowser.gschema.xml @@ -1,6 +1,11 @@ + + true + Use bottom panel + Use the bottom panel for the source tree. + false Show Line Numbers diff --git a/sourcecodebrowser/plugin.py b/sourcecodebrowser/plugin.py index 19123fc..a3614c6 100644 --- a/sourcecodebrowser/plugin.py +++ b/sourcecodebrowser/plugin.py @@ -2,9 +2,16 @@ import sys import logging import tempfile -import ctags +from . import ctags +import gi from gi.repository import GObject, GdkPixbuf, Gedit, Gtk, PeasGtk, Gio +try: + gi.require_version('Tepl', '6') + from gi.repository import Tepl +except: + Tepl = None + logging.basicConfig() LOG_LEVEL = logging.WARN SETTINGS_SCHEMA = "org.gnome.gedit.plugins.sourcecodebrowser" @@ -15,7 +22,7 @@ class SourceTree(Gtk.VBox): """ Source Tree Widget - A treeview storing the heirarchy of source code symbols within a particular + A treeview storing the hierarchy of source code symbols within a particular document. Requries exhuberant-ctags. """ __gsignals__ = { @@ -32,6 +39,7 @@ def __init__(self): # preferences (should be set by plugin) self.show_line_numbers = True + self.use_bottom_panel = False self.ctags_executable = 'ctags' self.expand_rows = True self.sort_list = True @@ -74,7 +82,7 @@ def clear(self): self._store.clear() def create_ui(self): - """ Craete the main user interface and pack into box. """ + """ Create the main user interface and pack into box. """ self._store = Gtk.TreeStore(GdkPixbuf.Pixbuf, # icon GObject.TYPE_STRING, # name GObject.TYPE_STRING, # kind @@ -115,7 +123,7 @@ def _get_tag_iter(self, tag, parent_iter=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 - is not found under the specirfied parent_iter. + is not found under the specified parent_iter. """ kind_iter = self._store.iter_children(parent_iter) while kind_iter: @@ -263,6 +271,9 @@ def get_widget(self, has_schema): builder.get_object("show_line_numbers").set_active( self._settings.get_boolean('show-line-numbers') ) + builder.get_object("use_bottom_panel").set_active( + self._settings.get_boolean('use-bottom-panel') + ) builder.get_object("expand_rows").set_active( self._settings.get_boolean('expand-rows') ) @@ -272,7 +283,7 @@ def get_widget(self, has_schema): builder.get_object("sort_list").set_active( self._settings.get_boolean('sort-list') ) - builder.get_object("ctags_executable").set_text( + builder.get_object("ctags_executable").set_filename( self._settings.get_string('ctags-executable') ) builder.connect_signals(self) @@ -281,6 +292,9 @@ def get_widget(self, has_schema): def on_show_line_numbers_toggled(self, button, data=None): self._settings.set_boolean('show-line-numbers', button.get_active()) + def on_use_bottom_panel_toggled(self, button, data=None): + self._settings.set_boolean('use-bottom-panel', button.get_active()) + def on_expand_rows_toggled(self, button, data=None): self._settings.set_boolean('expand-rows', button.get_active()) @@ -290,8 +304,8 @@ def on_load_remote_files_toggled(self, button, data=None): 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()) + def on_ctags_executable_changed(self, button, data=None): + self._settings.set_string('ctags-executable', button.get_filename()) class SourceCodeBrowserPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable): @@ -327,12 +341,12 @@ def do_activate(self): self._sourcetree = SourceTree() self._sourcetree.ctags_executable = self.ctags_executable self._sourcetree.show_line_numbers = self.show_line_numbers + self._sourcetree.use_bottom_panel = self.use_bottom_panel 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) + self._insert_sourcetree_pane() self._handlers = [] - hid = self._sourcetree.connect("focus", self.on_sourcetree_focus) + hid = self._sourcetree.connect("focus" if Tepl else "draw", self.on_sourcetree_focus) self._handlers.append((self._sourcetree, hid)) if self.ctags_version is not None: hid = self._sourcetree.connect('tag-activated', self.on_tag_activated) @@ -345,15 +359,33 @@ def do_activate(self): self._handlers.append((self.window, hid)) else: self._sourcetree.set_sensitive(False) - + + def _insert_sourcetree_pane(self): + if self._sourcetree.use_bottom_panel: + panel = self.window.get_bottom_panel() + panel.add_titled(self._sourcetree, "SymbolBrowserPlugin", "Source Tags") + panel.show() + self._sourcetree.show_all() + panel.set_visible_child(self._sourcetree) + else: + panel = self.window.get_side_panel() + panel.add_titled(self._sourcetree, "SymbolBrowserPlugin", "Source Code") + + def _remove_sourcetree_pane(self): + if self._sourcetree.use_bottom_panel: + panel = self.window.get_bottom_panel() + panel.remove(self._sourcetree) + else: + panel = self.window.get_side_panel() + panel.remove(self._sourcetree) + def do_deactivate(self): """ Deactivate the plugin """ self._log.debug("Deactivating plugin") for obj, hid in self._handlers: obj.disconnect(hid) self._handlers = None - pane = self.window.get_side_panel() - pane.remove_item(self._sourcetree) + self._remove_sourcetree_pane() self._sourcetree = None def _has_settings_schema(self): @@ -369,11 +401,13 @@ def _init_settings(self): settings = Gio.Settings.new(SETTINGS_SCHEMA) self.load_remote_files = settings.get_boolean("load-remote-files") self.show_line_numbers = settings.get_boolean("show-line-numbers") + self.use_bottom_panel = settings.get_boolean("use-bottom-panel") self.expand_rows = settings.get_boolean("expand-rows") self.sort_list = settings.get_boolean("sort-list") self.ctags_executable = settings.get_string("ctags-executable") settings.connect("changed::load-remote-files", self.on_setting_changed) settings.connect("changed::show-line-numbers", self.on_setting_changed) + settings.connect("changed::use-bottom-panel", self.on_setting_changed) settings.connect("changed::expand-rows", self.on_setting_changed) settings.connect("changed::sort-list", self.on_setting_changed) settings.connect("changed::ctags-executable", self.on_setting_changed) @@ -383,6 +417,7 @@ def _init_settings(self): self._settings = None self.load_remote_files = True self.show_line_numbers = False + self.use_bottom_panel = False self.expand_rows = True self.sort_list = True self.ctags_executable = 'ctags' @@ -392,13 +427,18 @@ def _load_active_document_symbols(self): self._sourcetree.clear() 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 self._sourcetree.use_bottom_panel: + panel = self.window.get_bottom_panel() + visible_child = panel.get_visible_child() + panel.props.visible_child = self._sourcetree + else: + panel = self.window.get_side_panel() + if panel.get_visible_child() != self._sourcetree: return document = self.window.get_active_document() if document: - location = document.get_location() + location = document.get_file().get_location() if location: uri = location.get_uri() self._log.debug("Loading %s...", uri) @@ -421,6 +461,8 @@ def _load_active_document_symbols(self): os.unlink(filename) self._loaded_document = document self._is_loaded = True + if self._sourcetree.use_bottom_panel and visible_child != self._sourcetree: + panel.props.visible_child = visible_child def on_active_tab_changed(self, window, tab, data=None): self._load_active_document_symbols() @@ -429,6 +471,7 @@ def on_setting_changed(self, settings, key, data=None): """ self.load_remote_files = True self.show_line_numbers = False + self.use_bottom_panel = False self.expand_rows = True self.ctags_executable = 'ctags' """ @@ -436,6 +479,8 @@ def on_setting_changed(self, settings, key, data=None): self.load_remote_files = self._settings.get_boolean(key) elif key == 'show-line-numbers': self.show_line_numbers = self._settings.get_boolean(key) + elif key == 'use-bottom-panel': + self.use_bottom_panel = self._settings.get_boolean(key) elif key == 'expand-rows': self.expand_rows = self._settings.get_boolean(key) elif key == 'sort-list': @@ -446,6 +491,9 @@ def on_setting_changed(self, settings, key, data=None): if self._sourcetree is not None: self._sourcetree.ctags_executable = self.ctags_executable self._sourcetree.show_line_numbers = self.show_line_numbers + self._remove_sourcetree_pane() + self._sourcetree.use_bottom_panel = self.use_bottom_panel + self._insert_sourcetree_pane() self._sourcetree.expand_rows = self.expand_rows self._sourcetree.sort_list = self.sort_list self._sourcetree.expanded_rows = {} @@ -470,8 +518,11 @@ def on_tag_activated(self, sourcetree, location, data=None): document = self.window.get_active_document() view = self.window.get_active_view() line = int(line) - 1 # lines start from 0 - document.goto_line(line) - view.scroll_to_cursor() + if Tepl: + Tepl.View.goto_line(view, line) + else: + document.goto_line(line) + view.scroll_to_cursor() def _version_check(self): """ Make sure the exhuberant ctags is installed. """ @@ -481,4 +532,4 @@ def _version_check(self): (self.ctags_executable)) - +