Skip to content

New "ctags append" config feature #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions sourcecodebrowser/data/configure_dialog.ui
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<!-- interface-requires gtk+ 3.0 -->
<requires lib="gtk+" version="3.0"/>
<object class="GtkDialog" id="configure_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
Expand All @@ -20,10 +21,10 @@
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-close</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
Expand All @@ -48,10 +49,10 @@
<child>
<object class="GtkCheckButton" id="show_line_numbers">
<property name="label" translatable="yes">Show _line numbers in tree</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
Expand All @@ -67,10 +68,10 @@
<child>
<object class="GtkCheckButton" id="load_remote_files">
<property name="label" translatable="yes">Load symbols from _remote files</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
Expand All @@ -86,10 +87,10 @@
<child>
<object class="GtkCheckButton" id="expand_rows">
<property name="label" translatable="yes">Start with rows _expanded</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
Expand All @@ -105,10 +106,10 @@
<child>
<object class="GtkCheckButton" id="sort_list">
<property name="label" translatable="yes">_Sort list alphabetically</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
Expand Down Expand Up @@ -144,7 +145,6 @@
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="text" translatable="yes">ctags</property>
<property name="invisible_char_set">True</property>
<signal name="changed" handler="on_ctags_executable_changed" swapped="no"/>
</object>
<packing>
Expand All @@ -162,6 +162,45 @@
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">ctags append str</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="ctags_append">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<signal name="changed" handler="on_ctags_append_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">6</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">6</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<summary>Ctags Executable</summary>
<description>Specifies the executable path for Exuberant Ctags.</description>
</key>
<key type="s" name="ctags-append">
<default>''</default>
<summary>Ctags Append</summary>
<description>Specifies any command line modifiers to apply to Ctags when run by the parser.</description>
</key>
</schema>
</schemalist>

23 changes: 19 additions & 4 deletions sourcecodebrowser/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import sys
import logging
import tempfile
import ctags
from . import ctags
from gi.repository import GObject, GdkPixbuf, Gedit, Gtk, PeasGtk, Gio

logging.basicConfig()
LOG_LEVEL = logging.WARN
SETTINGS_SCHEMA = "org.gnome.gedit.plugins.sourcecodebrowser"
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
DATA_DIR = "/usr/share/gedit/plugins/sourcecodebrowser"
ICON_DIR = os.path.join(DATA_DIR, 'icons', '16x16')

class SourceTree(Gtk.VBox):
Expand All @@ -33,6 +33,7 @@ def __init__(self):
# preferences (should be set by plugin)
self.show_line_numbers = True
self.ctags_executable = 'ctags'
self.ctags_append = ''
self.expand_rows = True
self.sort_list = True
self.create_ui()
Expand Down Expand Up @@ -74,7 +75,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
Expand Down Expand Up @@ -218,7 +219,7 @@ def parse_file(self, path, uri):
filename to pass to ctags, and the uri is the actual URI as known by
Gedit. They would be different for remote files.
"""
command = "ctags -nu --fields=fiKlmnsSzt -f - '%s'" % path
command = "ctags " + self.ctags_append + "-nu --fields=fiKlmnsSzt -f - '%s'" % path
#self._log.debug(command)
try:
parser = ctags.Parser()
Expand Down Expand Up @@ -275,6 +276,9 @@ def get_widget(self, has_schema):
builder.get_object("ctags_executable").set_text(
self._settings.get_string('ctags-executable')
)
builder.get_object("ctags_append").set_text(
self._settings.get_string('ctags-append')
)
builder.connect_signals(self)
return widget

Expand All @@ -293,6 +297,9 @@ def on_sort_list_toggled(self, button, data=None):
def on_ctags_executable_changed(self, editable, data=None):
self._settings.set_string('ctags-executable', editable.get_text())

def on_ctags_append_changed(self, editable, data=None):
self._settings.set_string('ctags-append', editable.get_text())


class SourceCodeBrowserPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable):
"""
Expand Down Expand Up @@ -326,6 +333,7 @@ def do_activate(self):
self._version_check()
self._sourcetree = SourceTree()
self._sourcetree.ctags_executable = self.ctags_executable
self._sourcetree.ctags_append = self.ctags_append
self._sourcetree.show_line_numbers = self.show_line_numbers
self._sourcetree.expand_rows = self.expand_rows
self._sourcetree.sort_list = self.sort_list
Expand Down Expand Up @@ -372,11 +380,13 @@ def _init_settings(self):
self.expand_rows = settings.get_boolean("expand-rows")
self.sort_list = settings.get_boolean("sort-list")
self.ctags_executable = settings.get_string("ctags-executable")
self.ctags_append = settings.get_string("ctags-append")
settings.connect("changed::load-remote-files", self.on_setting_changed)
settings.connect("changed::show-line-numbers", 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)
settings.connect("changed::ctags-append", self.on_setting_changed)
self._settings = settings
else:
self._log.warn("Settings schema not installed. Plugin will not be configurable.")
Expand All @@ -386,6 +396,7 @@ def _init_settings(self):
self.expand_rows = True
self.sort_list = True
self.ctags_executable = 'ctags'
self.ctags_append = ''

def _load_active_document_symbols(self):
""" Load the symbols for the given URI. """
Expand Down Expand Up @@ -431,6 +442,7 @@ def on_setting_changed(self, settings, key, data=None):
self.show_line_numbers = False
self.expand_rows = True
self.ctags_executable = 'ctags'
self.ctags_append = ''
"""
if key == 'load-remote-files':
self.load_remote_files = self._settings.get_boolean(key)
Expand All @@ -442,9 +454,12 @@ 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)
elif key == 'ctags-append':
self.ctags_append = self._settings.get_string(key)

if self._sourcetree is not None:
self._sourcetree.ctags_executable = self.ctags_executable
self._sourcetree.ctags_append = self.ctags_append
self._sourcetree.show_line_numbers = self.show_line_numbers
self._sourcetree.expand_rows = self.expand_rows
self._sourcetree.sort_list = self.sort_list
Expand Down