summaryrefslogtreecommitdiff
path: root/plugins/externaltools
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/externaltools')
-rwxr-xr-xplugins/externaltools/tools/__init__.py22
-rwxr-xr-xplugins/externaltools/tools/capture.py18
-rwxr-xr-xplugins/externaltools/tools/functions.py44
-rwxr-xr-xplugins/externaltools/tools/library.py18
-rwxr-xr-xplugins/externaltools/tools/linkparsing.py2
-rwxr-xr-xplugins/externaltools/tools/manager.py272
-rwxr-xr-xplugins/externaltools/tools/outputpanel.py6
7 files changed, 198 insertions, 184 deletions
diff --git a/plugins/externaltools/tools/__init__.py b/plugins/externaltools/tools/__init__.py
index 463c8f58..153d6c6e 100755
--- a/plugins/externaltools/tools/__init__.py
+++ b/plugins/externaltools/tools/__init__.py
@@ -57,12 +57,12 @@ class ToolMenu(object):
action._tool_handler = None
self._action_group.remove_action(action)
-
+
accelmap = Gtk.AccelMap.get()
for s in self._signals:
accelmap.disconnect(s)
-
+
self._signals = []
def _insert_directory(self, directory, path):
@@ -76,7 +76,7 @@ class ToolMenu(object):
manager.add_ui(self._merge_id, path,
action_name, action_name,
Gtk.UIManagerItemType.MENU, False)
-
+
self._insert_directory(item, path + '/' + action_name)
for item in directory.tools:
@@ -87,16 +87,16 @@ class ToolMenu(object):
# Attach the item and the handler to the action object
action._tool_item = item
action._tool_handler = handler
-
+
# Make sure to replace accel
accelpath = '<Actions>/ExternalToolsPluginToolActions/%s' % (action_name, )
-
+
if item.shortcut:
key, mod = Gtk.accelerator_parse(item.shortcut)
Gtk.AccelMap.change_entry(accelpath, key, mod, True)
-
+
self._signals.append(Gtk.AccelMap.get().connect('changed::%s' % (accelpath,), self.on_accelmap_changed, item))
-
+
self._action_group.add_action_with_accel(action, item.shortcut)
manager.add_ui(self._merge_id, path,
@@ -106,7 +106,7 @@ class ToolMenu(object):
def on_accelmap_changed(self, accelmap, path, key, mod, tool):
tool.shortcut = Gtk.accelerator_name(key, mod)
tool.save()
-
+
self._plugin.update_manager(tool)
def update(self):
@@ -119,10 +119,10 @@ class ToolMenu(object):
def filter_language(self, language, item):
if not item.languages:
return True
-
+
if not language and 'plain' in item.languages:
return True
-
+
if language and (language.get_id() in item.languages):
return True
else:
@@ -142,7 +142,7 @@ class ToolMenu(object):
'titled': titled,
'untitled': not titled,
}
-
+
language = document.get_language()
for action in self._action_group.list_actions():
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
index 487c8dbb..73ce2702 100755
--- a/plugins/externaltools/tools/capture.py
+++ b/plugins/externaltools/tools/capture.py
@@ -29,7 +29,7 @@ class Capture(GObject.Object):
CAPTURE_STDERR = 0x02
CAPTURE_BOTH = 0x03
CAPTURE_NEEDS_SHELL = 0x04
-
+
WRITE_BUFFER_SIZE = 0x4000
__gsignals__ = {
@@ -73,7 +73,7 @@ class Capture(GObject.Object):
'shell': self.flags & self.CAPTURE_NEEDS_SHELL,
'env' : self.env
}
-
+
if self.input_text is not None:
popen_args['stdin'] = subprocess.PIPE
if self.flags & self.CAPTURE_STDOUT:
@@ -84,17 +84,17 @@ class Capture(GObject.Object):
self.tried_killing = False
self.idle_write_id = 0
self.read_buffer = ''
-
+
try:
self.pipe = subprocess.Popen(self.command, **popen_args)
except OSError, e:
self.pipe = None
self.emit('stderr-line', _('Could not execute command: %s') % (e, ))
return
-
+
# Signal
self.emit('begin-execute')
-
+
if self.flags & self.CAPTURE_STDOUT:
# Set non blocking
flags = fcntl.fcntl(self.pipe.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK
@@ -132,13 +132,13 @@ class Capture(GObject.Object):
try:
l = len(self.write_buffer)
m = min(l, self.WRITE_BUFFER_SIZE)
-
+
self.pipe.stdin.write(self.write_buffer[:m])
-
+
if m == l:
self.write_buffer = ''
self.pipe.stdin.close()
-
+
self.idle_write_id = 0
return False
@@ -165,7 +165,7 @@ class Capture(GObject.Object):
self.read_buffer += line
lines = self.read_buffer.splitlines(True)
-
+
if not lines[-1].endswith("\n"):
self.read_buffer = lines[-1]
lines = lines[0:-1]
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index e1268443..dd4f82b2 100755
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -30,13 +30,13 @@ def default(val, d):
def current_word(document):
piter = document.get_iter_at_mark(document.get_insert())
start = piter.copy()
-
+
if not piter.starts_word() and (piter.inside_word() or piter.ends_word()):
start.backward_word_start()
-
+
if not piter.ends_word() and piter.inside_word():
piter.forward_word_end()
-
+
return (start, piter)
# ==== Capture related functions ====
@@ -56,32 +56,32 @@ def run_external_tool(window, panel, node):
# Environment vars relative to current document
document = view.get_buffer()
uri = document.get_uri()
-
+
# Current line number
piter = document.get_iter_at_mark(document.get_insert())
capture.set_env(PLUMA_CURRENT_LINE_NUMBER=str(piter.get_line() + 1))
-
+
# Current line text
piter.set_line_offset(0)
end = piter.copy()
-
+
if not end.ends_line():
end.forward_to_line_end()
-
+
capture.set_env(PLUMA_CURRENT_LINE=piter.get_text(end))
-
+
# Selected text (only if input is not selection)
if node.input != 'selection' and node.input != 'selection-document':
bounds = document.get_selection_bounds()
-
+
if bounds:
capture.set_env(PLUMA_SELECTED_TEXT=bounds[0].get_text(bounds[1]))
-
+
bounds = current_word(document)
capture.set_env(PLUMA_CURRENT_WORD=bounds[0].get_text(bounds[1]))
-
+
capture.set_env(PLUMA_CURRENT_DOCUMENT_TYPE=document.get_mime_type())
-
+
if uri is not None:
gfile = Gio.file_new_for_uri(uri)
scheme = gfile.get_uri_scheme()
@@ -106,7 +106,7 @@ def run_external_tool(window, panel, node):
PLUMA_DOCUMENTS_PATH = ' '.join(documents_path))
flags = capture.CAPTURE_BOTH
-
+
if not node.has_hash_bang():
flags |= capture.CAPTURE_NEEDS_SHELL
@@ -131,7 +131,7 @@ def run_external_tool(window, panel, node):
elif input_type == 'selection' or input_type == 'selection-document':
try:
start, end = document.get_selection_bounds()
-
+
print start, end
except ValueError:
if input_type == 'selection-document':
@@ -142,7 +142,7 @@ def run_external_tool(window, panel, node):
else:
start = document.get_iter_at_mark(document.get_insert())
end = start.copy()
-
+
elif input_type == 'line':
start = document.get_iter_at_mark(document.get_insert())
end = start.copy()
@@ -196,12 +196,12 @@ def run_external_tool(window, panel, node):
document.begin_user_action()
capture.connect('stderr-line', capture_stderr_line_panel, panel)
- capture.connect('begin-execute', capture_begin_execute_panel, panel, view, node.name)
+ capture.connect('begin-execute', capture_begin_execute_panel, panel, view, node.name)
capture.connect('end-execute', capture_end_execute_panel, panel, view, output_type)
# Run the command
capture.execute()
-
+
if output_type != 'nothing':
document.end_user_action()
@@ -222,7 +222,7 @@ class MultipleDocumentsSaver:
signals[doc] = doc.connect('saving', self.on_document_saving)
Pluma.commands_save_document(window, doc)
doc.disconnect(signals[doc])
-
+
def on_document_saving(self, doc, size, total_size):
self._counter += 1
self._signal_ids[doc] = doc.connect('saved', self.on_document_saved)
@@ -230,12 +230,12 @@ class MultipleDocumentsSaver:
def on_document_saved(self, doc, error):
if error:
self._error = True
-
+
doc.disconnect(self._signal_ids[doc])
del self._signal_ids[doc]
-
+
self._counter -= 1
-
+
if self._counter == 0 and not self._error:
run_external_tool(self._window, self._panel, self._node)
@@ -275,7 +275,7 @@ def capture_end_execute_panel(capture, exit_code, panel, view, output_type):
mtype, uncertain = Gio.content_type_guess(None, doc.get_text(start, end, False).encode('utf-8'))
lmanager = GtkSource.LanguageManager.get_default()
language = lmanager.guess_language(doc.get_uri(), mtype)
-
+
if language is not None:
doc.set_language(language)
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index b4e6924e..186c33f2 100755
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -286,64 +286,80 @@ class Tool(object):
applicability = self._properties.get('Applicability')
if applicability: return applicability
return 'all'
+
def set_applicability(self, value):
self._set_property_if_changed('Applicability', value)
+
applicability = property(get_applicability, set_applicability)
def get_name(self):
name = self._properties.get('Name')
if name: return name
return os.path.basename(self.filename)
+
def set_name(self, value):
self._set_property_if_changed('Name', value)
+
name = property(get_name, set_name)
def get_shortcut(self):
shortcut = self._properties.get('Shortcut')
if shortcut: return shortcut
return None
+
def set_shortcut(self, value):
self._set_property_if_changed('Shortcut', value)
+
shortcut = property(get_shortcut, set_shortcut)
def get_comment(self):
comment = self._properties.get('Comment')
if comment: return comment
return self.filename
+
def set_comment(self, value):
self._set_property_if_changed('Comment', value)
+
comment = property(get_comment, set_comment)
def get_input(self):
input = self._properties.get('Input')
if input: return input
return 'nothing'
+
def set_input(self, value):
self._set_property_if_changed('Input', value)
+
input = property(get_input, set_input)
def get_output(self):
output = self._properties.get('Output')
if output: return output
return 'output-panel'
+
def set_output(self, value):
self._set_property_if_changed('Output', value)
+
output = property(get_output, set_output)
def get_save_files(self):
save_files = self._properties.get('Save-files')
if save_files: return save_files
return 'nothing'
+
def set_save_files(self, value):
self._set_property_if_changed('Save-files', value)
+
save_files = property(get_save_files, set_save_files)
def get_languages(self):
languages = self._properties.get('Languages')
if languages: return languages
return []
+
def set_languages(self, value):
self._set_property_if_changed('Languages', value)
+
languages = property(get_languages, set_languages)
def has_hash_bang(self):
@@ -358,7 +374,6 @@ class Tool(object):
for line in fp:
if line.strip() == '':
continue
-
return line.startswith('#!')
# There is no property for this one because this function is quite
@@ -404,7 +419,6 @@ class Tool(object):
def save_with_script(self, script):
filename = self.library.get_full_path(self.filename, 'w')
-
fp = open(filename, 'w', 1)
# Make sure to first print header (shebang, modeline), then
diff --git a/plugins/externaltools/tools/linkparsing.py b/plugins/externaltools/tools/linkparsing.py
index 27b9ba89..33ed6142 100755
--- a/plugins/externaltools/tools/linkparsing.py
+++ b/plugins/externaltools/tools/linkparsing.py
@@ -193,7 +193,7 @@ REGEXP_VALAC = r"""
#ruby
#test.rb:5: ...
-# from test.rb:3:in `each'
+# from test.rb:3:in `each'
# fist line parsed by REGEXP_STANDARD
REGEXP_RUBY = r"""
^\s+from\s
diff --git a/plugins/externaltools/tools/manager.py b/plugins/externaltools/tools/manager.py
index 24d7d71a..4da0deb9 100755
--- a/plugins/externaltools/tools/manager.py
+++ b/plugins/externaltools/tools/manager.py
@@ -34,7 +34,7 @@ class LanguagesPopup(Gtk.Window):
def __init__(self, languages):
Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP)
-
+
self.set_default_size(200, 200)
self.props.can_focus = True
@@ -42,9 +42,9 @@ class LanguagesPopup(Gtk.Window):
self.init_languages(languages)
self.show()
-
+
self.grab_add()
-
+
self.keyboard = None
device_manager = Gdk.Display.get_device_manager(self.get_window().get_display())
for device in device_manager.list_devices(Gdk.DeviceType.MASTER):
@@ -76,40 +76,40 @@ class LanguagesPopup(Gtk.Window):
def build(self):
self.model = Gtk.ListStore(str, str, bool)
-
+
self.sw = Gtk.ScrolledWindow()
self.sw.show()
-
+
self.sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
-
+
self.view = Gtk.TreeView(self.model)
self.view.show()
-
+
self.view.set_headers_visible(False)
-
+
column = Gtk.TreeViewColumn()
-
+
renderer = Gtk.CellRendererToggle()
column.pack_start(renderer, False)
column.set_attributes(renderer, active=self.COLUMN_ENABLED)
-
+
renderer.connect('toggled', self.on_language_toggled)
-
+
renderer = Gtk.CellRendererText()
column.pack_start(renderer, True)
column.set_attributes(renderer, text=self.COLUMN_NAME)
-
+
self.view.append_column(column)
self.view.set_row_separator_func(self.on_separator)
-
+
self.sw.add(self.view)
-
+
self.add(self.sw)
-
+
def enabled_languages(self, model, path, piter, ret):
enabled = model.get_value(piter, self.COLUMN_ENABLED)
-
+
if path.get_indices()[0] == 0 and enabled:
return True
@@ -117,42 +117,42 @@ class LanguagesPopup(Gtk.Window):
ret.append(model.get_value(piter, self.COLUMN_ID))
return False
-
+
def languages(self):
ret = []
-
+
self.model.foreach(self.enabled_languages, ret)
return ret
-
+
def on_separator(self, model, piter):
val = model.get_value(piter, self.COLUMN_NAME)
return val == '-'
-
+
def init_languages(self, languages):
manager = GtkSource.LanguageManager()
langs = [manager.get_language(x) for x in manager.get_language_ids()]
langs.sort(key=lambda x: x.get_name())
-
+
self.model.append([_('All languages'), None, not languages])
self.model.append(['-', None, False])
self.model.append([_('Plain Text'), 'plain', 'plain' in languages])
self.model.append(['-', None, False])
-
+
for lang in langs:
self.model.append([lang.get_name(), lang.get_id(), lang.get_id() in languages])
def correct_all(self, model, path, piter, enabled):
if path == (0,):
return False
-
+
model.set_value(piter, self.COLUMN_ENABLED, enabled)
def on_language_toggled(self, renderer, path):
piter = self.model.get_iter(path)
-
+
enabled = self.model.get_value(piter, self.COLUMN_ENABLED)
self.model.set_value(piter, self.COLUMN_ENABLED, not enabled)
-
+
if path == '0':
self.model.foreach(self.correct_all, False)
else:
@@ -165,55 +165,55 @@ class LanguagesPopup(Gtk.Window):
else:
event.window = self.view.get_bin_window()
return self.view.event(event)
-
+
def do_key_release_event(self, event):
event.window = self.view.get_bin_window()
return self.view.event(event)
-
+
def in_window(self, event, window=None):
if not window:
window = self.get_window()
geometry = window.get_geometry()
origin = window.get_origin()
-
+
return event.x_root >= origin[1] and \
event.x_root <= origin[1] + geometry[2] and \
event.y_root >= origin[2] and \
event.y_root <= origin[2] + geometry[3]
-
+
def do_destroy(self):
if self.keyboard:
self.keyboard.ungrab(Gdk.CURRENT_TIME)
self.pointer.ungrab(Gdk.CURRENT_TIME)
-
+
return Gtk.Window.do_destroy(self)
-
+
def setup_event(self, event, window):
fr = event.window.get_origin()
to = window.get_origin()
-
+
event.window = window
event.x += fr[1] - to[1]
event.y += fr[2] - to[2]
-
+
def resolve_widgets(self, root):
res = [root]
-
+
if isinstance(root, Gtk.Container):
root.forall(lambda x, y: res.extend(self.resolve_widgets(x)), None)
-
+
return res
-
+
def resolve_windows(self, window):
if not window:
return []
res = [window]
res.extend(window.get_children())
-
+
return res
-
+
def propagate_mouse_event(self, event, reverse=True):
allwidgets = self.resolve_widgets(self.get_child())
@@ -223,19 +223,19 @@ class LanguagesPopup(Gtk.Window):
for widget in allwidgets:
windows = self.resolve_windows(widget.get_window())
windows.reverse()
-
+
for window in windows:
if not (window.get_events() & event.type):
continue
- if self.in_window(event, window):
+ if self.in_window(event, window):
self.setup_event(event, window)
if widget.event(event):
return True
-
+
return False
-
+
def do_button_press_event(self, event):
if not self.in_window(event):
self.destroy()
@@ -250,19 +250,19 @@ class LanguagesPopup(Gtk.Window):
def do_scroll_event(self, event):
return self.propagate_mouse_event(event, False)
-
+
def do_motion_notify_event(self, event):
return self.propagate_mouse_event(event)
-
+
def do_enter_notify_event(self, event):
return self.propagate_mouse_event(event)
def do_leave_notify_event(self, event):
return self.propagate_mouse_event(event)
-
+
def do_proximity_in_event(self, event):
return self.propagate_mouse_event(event)
-
+
def do_proximity_out_event(self, event):
return self.propagate_mouse_event(event)
@@ -281,12 +281,12 @@ class Manager(GObject.Object):
self._size = (0, 0)
self._languages = {}
self._tool_rows = {}
-
+
self.build()
def get_final_size(self):
return self._size
-
+
def build(self):
callbacks = {
'on_new_tool_button_clicked' : self.on_new_tool_button_clicked,
@@ -305,42 +305,42 @@ class Manager(GObject.Object):
self.ui.add_from_file(os.path.join(self.datadir, 'ui', 'tools.ui'))
self.ui.connect_signals(callbacks)
self.dialog = self.ui.get_object('tool-manager-dialog')
-
+
self.view = self.ui.get_object('view')
-
+
self.__init_tools_model()
self.__init_tools_view()
for name in ['input', 'output', 'applicability', 'save-files']:
self.__init_combobox(name)
-
+
self.do_update()
def expand_from_doc(self, doc):
row = None
-
+
if doc:
if doc.get_language():
lid = doc.get_language().get_id()
-
+
if lid in self._languages:
row = self._languages[lid]
elif 'plain' in self._languages:
row = self._languages['plain']
-
+
if not row and None in self._languages:
row = self._languages[None]
-
+
if not row:
return
-
+
self.view.expand_row(row.get_path(), False)
self.view.get_selection().select_path(row.get_path())
-
+
def run(self, window):
if self.dialog == None:
self.build()
-
+
# Open up language
self.expand_from_doc(window.get_active_document())
@@ -351,7 +351,7 @@ class Manager(GObject.Object):
def add_accelerator(self, item):
if not item.shortcut:
return
-
+
if item.shortcut in self.accelerators:
if not item in self.accelerators[item.shortcut]:
self.accelerators[item.shortcut].append(item)
@@ -375,42 +375,42 @@ class Manager(GObject.Object):
lid = language.get_id()
else:
lid = language
-
+
if not lid in self._languages:
piter = self.model.append(None, [language])
-
+
parent = Gtk.TreeRowReference.new(self.model, self.model.get_path(piter))
self._languages[lid] = parent
else:
parent = self._languages[lid]
-
+
piter = self.model.get_iter(parent.get_path())
child = self.model.append(piter, [tool])
-
+
if not tool in self._tool_rows:
self._tool_rows[tool] = []
-
+
self._tool_rows[tool].append(Gtk.TreeRowReference.new(self.model, self.model.get_path(child)))
return child
def add_tool(self, tool):
manager = GtkSource.LanguageManager()
ret = None
-
+
for lang in tool.languages:
l = manager.get_language(lang)
-
+
if l:
ret = self.add_tool_to_language(tool, l)
elif lang == 'plain':
ret = self.add_tool_to_language(tool, 'plain')
-
+
if not ret:
ret = self.add_tool_to_language(tool, None)
self.add_accelerator(tool)
return ret
-
+
def __init_tools_model(self):
self.tools = ToolLibrary()
self.current_node = None
@@ -430,26 +430,26 @@ class Manager(GObject.Object):
# For languages, sort All before everything else, otherwise alphabetical
t1 = model.get_value(iter1, self.TOOL_COLUMN)
t2 = model.get_value(iter2, self.TOOL_COLUMN)
-
+
if model.iter_parent(iter1) == None:
if t1 == None:
return -1
-
+
if t2 == None:
return 1
-
+
def lang_name(lang):
if isinstance(lang, GtkSource.Language):
return lang.get_name()
else:
return _('Plain Text')
-
+
n1 = lang_name(t1)
n2 = lang_name(t2)
else:
n1 = t1.name
n2 = t2.name
-
+
return cmp(n1.lower(), n2.lower())
def __init_tools_view(self):
@@ -459,12 +459,12 @@ class Manager(GObject.Object):
column.pack_start(renderer, False)
renderer.set_property('editable', True)
self.view.append_column(column)
-
+
column.set_cell_data_func(renderer, self.get_cell_data_cb, None)
renderer.connect('edited', self.on_view_label_cell_edited)
renderer.connect('editing-started', self.on_view_label_cell_editing_started)
-
+
self.selection_changed_id = self.view.get_selection().connect('changed', self.on_view_selection_changed, None)
def __init_combobox(self, name):
@@ -491,10 +491,10 @@ class Manager(GObject.Object):
if piter is not None:
tool = model.get_value(piter, self.TOOL_COLUMN)
-
+
if not isinstance(tool, Tool):
tool = None
-
+
return piter, tool
else:
return None, None
@@ -541,27 +541,27 @@ class Manager(GObject.Object):
for nm in ('input', 'output', 'applicability', 'save-files'):
self[nm].set_active(0)
-
+
self['languages_label'].set_text(_('All Languages'))
-
+
def fill_languages_button(self):
if not self.current_node or not self.current_node.languages:
self['languages_label'].set_text(_('All Languages'))
else:
manager = GtkSource.LanguageManager()
langs = []
-
+
for lang in self.current_node.languages:
if lang == 'plain':
langs.append(_('Plain Text'))
else:
l = manager.get_language(lang)
-
+
if l:
langs.append(l.get_name())
-
+
self['languages_label'].set_text(', '.join(langs))
-
+
def fill_fields(self):
node = self.current_node
self['accelerator'].set_text(default(node.shortcut, ''))
@@ -587,7 +587,7 @@ class Manager(GObject.Object):
for nm in ('input', 'output', 'applicability', 'save-files'):
model = self[nm].get_model()
piter = model.get_iter_first()
-
+
self.set_active_by_name(nm,
default(node.__getattribute__(nm.replace('-', '_')),
model.get_value(piter, self.NAME_COLUMN)))
@@ -620,34 +620,34 @@ class Manager(GObject.Object):
self['tool-table'].set_sensitive(True)
else:
self.clear_fields()
- self['tool-table'].set_sensitive(False)
+ self['tool-table'].set_sensitive(False)
def language_id_from_iter(self, piter):
if not piter:
return None
tool = self.model.get_value(piter, self.TOOL_COLUMN)
-
+
if isinstance(tool, Tool):
piter = self.model.iter_parent(piter)
tool = self.model.get_value(piter, self.TOOL_COLUMN)
-
+
if isinstance(tool, GtkSource.Language):
return tool.get_id()
elif tool:
return 'plain'
-
+
return None
def selected_language_id(self):
# Find current language if there is any
model, piter = self.view.get_selection().get_selected()
-
+
return self.language_id_from_iter(piter)
def on_new_tool_button_clicked(self, button):
self.save_current_tool()
-
+
# block handlers while inserting a new item
self.view.get_selection().handler_block(self.selection_changed_id)
@@ -656,10 +656,10 @@ class Manager(GObject.Object):
self.tools.tree.tools.append(self.current_node)
lang = self.selected_language_id()
-
+
if lang:
self.current_node.languages = [lang]
-
+
piter = self.add_tool(self.current_node)
self.view.set_cursor(self.model.get_path(piter), self.view.get_column(self.TOOL_COLUMN), True)
@@ -671,7 +671,7 @@ class Manager(GObject.Object):
def tool_changed(self, tool, refresh=False):
for row in self._tool_rows[tool]:
self.model.row_changed(row.get_path(), self.model.get_iter(row.get_path()))
-
+
if refresh and tool == self.current_node:
self.fill_fields()
@@ -685,29 +685,29 @@ class Manager(GObject.Object):
if node.is_global():
shortcut = node.shortcut
-
+
if node.parent.revert_tool(node):
self.remove_accelerator(node, shortcut)
self.add_accelerator(node)
self['revert-tool-button'].set_sensitive(False)
self.fill_fields()
-
+
self.tool_changed(node)
else:
parent = self.model.iter_parent(piter)
language = self.language_id_from_iter(parent)
-
+
self.model.remove(piter)
-
+
if language in node.languages:
node.languages.remove(language)
self._tool_rows[node] = filter(lambda x: x.valid(), self._tool_rows[node])
-
+
if not self._tool_rows[node]:
del self._tool_rows[node]
-
+
if node.parent.delete_tool(node):
self.remove_accelerator(node)
self.current_node = None
@@ -717,10 +717,10 @@ class Manager(GObject.Object):
self.view.set_cursor(self.model.get_path(piter), self.view.get_column(self.TOOL_COLUMN), False)
self.view.grab_focus()
-
+
path = self._languages[language].get_path()
parent = self.model.get_iter(path)
-
+
if not self.model.iter_has_child(parent):
self.model.remove(parent)
del self._languages[language]
@@ -729,9 +729,9 @@ class Manager(GObject.Object):
if new_text != '':
piter = self.model.get_iter(path)
tool = self.model.get_value(piter, self.TOOL_COLUMN)
-
+
tool.name = new_text
-
+
self.save_current_tool()
self.tool_changed(tool)
@@ -742,7 +742,7 @@ class Manager(GObject.Object):
if isinstance(editable, Gtk.Entry):
editable.set_text(tool.name)
editable.grab_focus()
-
+
def on_view_selection_changed(self, selection, userdata):
self.save_current_tool()
self.do_update()
@@ -750,19 +750,19 @@ class Manager(GObject.Object):
def accelerator_collision(self, name, node):
if not name in self.accelerators:
return []
-
+
ret = []
-
+
for other in self.accelerators[name]:
if not other.languages or not node.languages:
ret.append(other)
continue
-
+
for lang in other.languages:
if lang in node.languages:
ret.append(other)
continue
-
+
return ret
def set_accelerator(self, keyval, mod):
@@ -775,9 +775,9 @@ class Manager(GObject.Object):
self.current_node.shorcut = None
self.save_current_tool()
return True
-
+
col = self.accelerator_collision(name, self.current_node)
-
+
if col:
dialog = Gtk.MessageDialog(self.dialog,
Gtk.DialogFlags.MODAL,
@@ -787,7 +787,7 @@ class Manager(GObject.Object):
dialog.run()
dialog.destroy()
-
+
self.add_accelerator(self.current_node)
return False
@@ -816,7 +816,7 @@ class Manager(GObject.Object):
if self.set_accelerator(event.keyval, mask):
entry.set_text(default(self.current_node.shortcut, ''))
self['commands'].grab_focus()
-
+
# Capture all `normal characters`
return True
elif Gdk.keyval_to_unicode(event.keyval):
@@ -849,7 +849,7 @@ class Manager(GObject.Object):
return
self.on_tool_manager_dialog_focus_out(dialog, None)
-
+
self.dialog.destroy()
self.dialog = None
self.tools = None
@@ -873,7 +873,7 @@ class Manager(GObject.Object):
label = _('Plain Text')
else:
label = tool.get_name()
-
+
markup = saxutils.escape(label)
editable = False
else:
@@ -885,7 +885,7 @@ class Manager(GObject.Object):
markup = escaped
editable = True
-
+
cell.set_properties(markup=markup, editable=editable)
def tool_in_language(self, tool, lang):
@@ -894,84 +894,84 @@ class Manager(GObject.Object):
ref = self._languages[lang]
parent = ref.get_path()
-
+
for row in self._tool_rows[tool]:
path = row.get_path()
-
+
if path.get_indices()[0] == parent.get_indices()[0]:
return True
-
+
return False
def update_languages(self, popup):
self.current_node.languages = popup.languages()
self.fill_languages_button()
-
+
piter, node = self.get_selected_tool()
ret = None
-
+
if node:
ref = Gtk.TreeRowReference(self.model, self.model.get_path(piter))
-
+
# Update languages, make sure to inhibit selection change stuff
self.view.get_selection().handler_block(self.selection_changed_id)
-
+
# Remove all rows that are no longer
for row in list(self._tool_rows[self.current_node]):
piter = self.model.get_iter(row.get_path())
language = self.language_id_from_iter(piter)
-
+
if (not language and not self.current_node.languages) or \
(language in self.current_node.languages):
continue
-
+
# Remove from language
self.model.remove(piter)
self._tool_rows[self.current_node].remove(row)
-
+
# If language is empty, remove it
parent = self.model.get_iter(self._languages[language].get_path())
-
+
if not self.model.iter_has_child(parent):
self.model.remove(parent)
del self._languages[language]
-
+
# Now, add for any that are new
manager = GtkSource.LanguageManager()
-
+
for lang in self.current_node.languages:
if not self.tool_in_language(self.current_node, lang):
l = manager.get_language(lang)
-
+
if not l:
l = 'plain'
-
+
self.add_tool_to_language(self.current_node, l)
-
+
if not self.current_node.languages and not self.tool_in_language(self.current_node, None):
self.add_tool_to_language(self.current_node, None)
-
+
# Check if we can still keep the current
if not ref or not ref.valid():
# Change selection to first language
path = self._tool_rows[self.current_node][0].get_path()
piter = self.model.get_iter(path)
parent = self.model.iter_parent(piter)
-
+
# Expand parent, select child and scroll to it
self.view.expand_row(self.model.get_path(parent), False)
self.view.get_selection().select_path(path)
self.view.set_cursor(path, self.view.get_column(self.TOOL_COLUMN), False)
-
+
self.view.get_selection().handler_unblock(self.selection_changed_id)
def on_languages_button_clicked(self, button):
popup = LanguagesPopup(self.current_node.languages)
popup.set_transient_for(self.dialog)
-
+
origin = button.get_window().get_origin()
popup.move(origin[1], origin[2] - popup.get_allocation().height)
-
+
popup.connect('destroy', self.update_languages)
# ex:et:ts=4:
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py
index 9613d78c..e063eb20 100755
--- a/plugins/externaltools/tools/outputpanel.py
+++ b/plugins/externaltools/tools/outputpanel.py
@@ -129,11 +129,11 @@ class OutputPanel(UniqueById):
# find all links and apply the appropriate tag for them
links = self.link_parser.parse(text)
for lnk in links:
-
+
insert_iter = buffer.get_iter_at_mark(insert)
lnk.start = insert_iter.get_offset() + lnk.start
lnk.end = insert_iter.get_offset() + lnk.end
-
+
start_iter = buffer.get_iter_at_offset(lnk.start)
end_iter = buffer.get_iter_at_offset(lnk.end)
@@ -156,7 +156,7 @@ class OutputPanel(UniqueById):
panel.show()
panel.activate_item(self.panel)
- def update_cursor_style(self, view, x, y):
+ def update_cursor_style(self, view, x, y):
if self.get_link_at_location(view, x, y) is not None:
cursor = self.link_cursor
else: