summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--plugins/Makefile.am5
-rw-r--r--plugins/snippets/Makefile.am6
-rw-r--r--plugins/snippets/snippets.plugin.desktop.in (renamed from plugins/snippets/snippets.pluma-plugin.desktop.in)2
-rwxr-xr-xplugins/snippets/snippets/Completion.py56
-rwxr-xr-xplugins/snippets/snippets/Document.py142
-rwxr-xr-xplugins/snippets/snippets/Exporter.py2
-rwxr-xr-xplugins/snippets/snippets/Helper.py34
-rwxr-xr-xplugins/snippets/snippets/Importer.py2
-rwxr-xr-xplugins/snippets/snippets/LanguageManager.py4
-rwxr-xr-xplugins/snippets/snippets/Library.py44
-rwxr-xr-xplugins/snippets/snippets/Manager.py246
-rwxr-xr-xplugins/snippets/snippets/Placeholder.py27
-rwxr-xr-xplugins/snippets/snippets/Snippet.py14
-rwxr-xr-xplugins/snippets/snippets/WindowHelper.py15
-rwxr-xr-xplugins/snippets/snippets/__init__.py60
-rw-r--r--plugins/snippets/snippets/snippets.ui3
-rw-r--r--po/POTFILES.in8
-rw-r--r--po/POTFILES.skip8
19 files changed, 340 insertions, 342 deletions
diff --git a/configure.ac b/configure.ac
index bf380917..c8855ca3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -250,6 +250,10 @@ plugins/pythonconsole/Makefile
plugins/pythonconsole/pythonconsole/Makefile
plugins/quickopen/Makefile
plugins/quickopen/quickopen/Makefile
+plugins/snippets/data/lang/Makefile
+plugins/snippets/data/Makefile
+plugins/snippets/Makefile
+plugins/snippets/snippets/Makefile
plugins/sort/Makefile
plugins/spell/Makefile
plugins/spell/org.mate.pluma.plugins.spell.gschema.xml
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index c4f95ea8..28ae8910 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -6,6 +6,7 @@ DIST_SUBDIRS = \
modelines \
pythonconsole \
quickopen \
+ snippets \
sort \
spell \
taglist \
@@ -20,14 +21,12 @@ SUBDIRS = \
modelines \
pythonconsole \
quickopen \
+ snippets \
sort \
taglist \
time \
trailsave
-# python plugins are disabled for now
-#SUBDIRS += snippets
-
if ENABLE_ENCHANT
SUBDIRS += spell
endif
diff --git a/plugins/snippets/Makefile.am b/plugins/snippets/Makefile.am
index 7d536d25..40aeeb90 100644
--- a/plugins/snippets/Makefile.am
+++ b/plugins/snippets/Makefile.am
@@ -2,10 +2,10 @@
SUBDIRS = snippets data
plugindir = $(PLUMA_PLUGINS_LIBS_DIR)
-plugin_in_files = snippets.pluma-plugin.desktop.in
-%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+plugin_in_files = snippets.plugin.desktop.in
+%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
-plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin)
+plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
EXTRA_DIST = $(plugin_in_files)
diff --git a/plugins/snippets/snippets.pluma-plugin.desktop.in b/plugins/snippets/snippets.plugin.desktop.in
index 99a160d1..ea960f3e 100644
--- a/plugins/snippets/snippets.pluma-plugin.desktop.in
+++ b/plugins/snippets/snippets.plugin.desktop.in
@@ -1,4 +1,4 @@
-[Pluma Plugin]
+[Plugin]
Loader=python
Module=snippets
IAge=2
diff --git a/plugins/snippets/snippets/Completion.py b/plugins/snippets/snippets/Completion.py
index 4f24150c..1788ecdf 100755
--- a/plugins/snippets/snippets/Completion.py
+++ b/plugins/snippets/snippets/Completion.py
@@ -1,15 +1,14 @@
-import gtksourceview2 as gsv
-import gobject
-import pluma
-import gtk
+from gi.repository import GObject, Gtk, GtkSource, Pluma
from Library import Library
from LanguageManager import get_language_manager
from Snippet import Snippet
-class Proposal(gobject.GObject, gsv.CompletionProposal):
+class Proposal(GObject.Object, GtkSource.CompletionProposal):
+ __gtype_name__ = "PlumaSnippetsProposal"
+
def __init__(self, snippet):
- gobject.GObject.__init__(self)
+ GObject.Object.__init__(self)
self._snippet = Snippet(snippet)
def snippet(self):
@@ -22,9 +21,11 @@ class Proposal(gobject.GObject, gsv.CompletionProposal):
def do_get_info(self):
return self._snippet.data['text']
-class Provider(gobject.GObject, gsv.CompletionProvider):
+class Provider(GObject.Object, GtkSource.CompletionProvider):
+ __gtype_name__ = "PlumaSnippetsProvider"
+
def __init__(self, name, language_id, handler):
- gobject.GObject.__init__(self)
+ GObject.Object.__init__(self)
self.name = name
self.info_widget = None
@@ -34,10 +35,10 @@ class Provider(gobject.GObject, gsv.CompletionProvider):
self.info_widget = None
self.mark = None
- theme = gtk.icon_theme_get_default()
- w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
+ theme = Gtk.IconTheme.get_default()
+ f, w, h = Gtk.icon_size_lookup(Gtk.IconSize.MENU)
- self.icon = theme.load_icon(gtk.STOCK_JUSTIFY_LEFT, w, 0)
+ self.icon = theme.load_icon(Gtk.STOCK_JUSTIFY_LEFT, w, 0)
def __del__(self):
if self.mark:
@@ -53,7 +54,9 @@ class Provider(gobject.GObject, gsv.CompletionProvider):
self.mark.get_buffer().move_mark(self.mark, it)
def get_word(self, context):
- it = context.get_iter()
+ (valid_context, it) = context.get_iter()
+ if not valid_context:
+ return None
if it.starts_word() or it.starts_line() or not it.ends_word():
return None
@@ -68,9 +71,9 @@ class Provider(gobject.GObject, gsv.CompletionProvider):
def do_get_start_iter(self, context, proposal):
if not self.mark or self.mark.get_deleted():
- return None
+ return (False, None)
- return self.mark.get_buffer().get_iter_at_mark(self.mark)
+ return (True, self.mark.get_buffer().get_iter_at_mark(self.mark))
def do_match(self, context):
return True
@@ -102,13 +105,13 @@ class Provider(gobject.GObject, gsv.CompletionProvider):
def do_get_info_widget(self, proposal):
if not self.info_widget:
- view = pluma.View(pluma.Document())
+ view = Pluma.View.new_with_buffer(Pluma.Document())
manager = get_language_manager()
lang = manager.get_language('snippets')
view.get_buffer().set_language(lang)
- sw = gtk.ScrolledWindow()
+ sw = Gtk.ScrolledWindow()
sw.add(view)
self.info_view = view
@@ -122,20 +125,19 @@ class Provider(gobject.GObject, gsv.CompletionProvider):
buf.set_text(proposal.get_info())
buf.move_mark(buf.get_insert(), buf.get_start_iter())
buf.move_mark(buf.get_selection_bound(), buf.get_start_iter())
- self.info_view.scroll_to_iter(buf.get_start_iter(), False)
-
- info.set_sizing(-1, -1, False, False)
- info.process_resize()
+ self.info_view.scroll_to_iter(buf.get_start_iter(), 0.0, False, 0.5, 0.5)
def do_get_icon(self):
return self.icon
def do_get_activation(self):
- return gsv.COMPLETION_ACTIVATION_USER_REQUESTED
+ return GtkSource.CompletionActivation.USER_REQUESTED
+
+class Defaults(GObject.Object, GtkSource.CompletionProvider):
+ __gtype_name__ = "PlumaSnippetsDefaultsProvider"
-class Defaults(gobject.GObject, gsv.CompletionProvider):
def __init__(self, handler):
- gobject.GObject.__init__(self)
+ GObject.Object.__init__(self)
self.handler = handler
self.proposals = []
@@ -144,7 +146,7 @@ class Defaults(gobject.GObject, gsv.CompletionProvider):
self.proposals = []
for d in defaults:
- self.proposals.append(gsv.CompletionItem(d))
+ self.proposals.append(GtkSource.CompletionItem.new(d, d, None, None))
def do_get_name(self):
return ""
@@ -156,10 +158,6 @@ class Defaults(gobject.GObject, gsv.CompletionProvider):
context.add_proposals(self, self.proposals, True)
def do_get_activation(self):
- return gsv.COMPLETION_ACTIVATION_NONE
-
-gobject.type_register(Proposal)
-gobject.type_register(Provider)
-gobject.type_register(Defaults)
+ return GtkSource.CompletionActivation.USER_REQUESTED
# ex:ts=8:et:
diff --git a/plugins/snippets/snippets/Document.py b/plugins/snippets/snippets/Document.py
index 368e0f5c..d832f0b9 100755
--- a/plugins/snippets/snippets/Document.py
+++ b/plugins/snippets/snippets/Document.py
@@ -18,12 +18,7 @@
import os
import re
-import gtk
-from gtk import gdk
-import gio
-import pluma
-import gtksourceview2 as gsv
-import gobject
+from gi.repository import GLib, Gio, Gdk, Gtk, GtkSource, Pluma
from Library import Library
from Snippet import Snippet
@@ -36,9 +31,9 @@ class DynamicSnippet(dict):
self.valid = True
class Document:
- TAB_KEY_VAL = (gtk.keysyms.Tab, \
- gtk.keysyms.ISO_Left_Tab)
- SPACE_KEY_VAL = (gtk.keysyms.space,)
+ TAB_KEY_VAL = (Gdk.KEY_Tab, \
+ Gdk.KEY_ISO_Left_Tab)
+ SPACE_KEY_VAL = (Gdk.KEY_space,)
def __init__(self, instance, view):
self.view = None
@@ -56,7 +51,6 @@ class Document:
self.timeout_update_id = 0
self.provider = Completion.Provider(_('Snippets'), self.language_id, self.on_proposal_activated)
- self.defaults_provider = Completion.Defaults(self.on_default_activated)
# Always have a reference to the global snippets
Library().ref(None)
@@ -66,7 +60,7 @@ class Document:
# to the view and the plugin instance, disconnect all signal handlers
def stop(self):
if self.timeout_update_id != 0:
- gobject.source_remove(self.timeout_update_id)
+ GLib.source_remove(self.timeout_update_id)
self.timeout_update_id = 0
del self.update_placeholders[:]
del self.jump_placeholders[:]
@@ -106,16 +100,17 @@ class Document:
self.view.get_completion(): ('hide',)}
for obj, sig in signals.items():
- for s in sig:
- self.disconnect_signal(obj, s)
+ if obj:
+ for s in sig:
+ self.disconnect_signal(obj, s)
# Remove all active snippets
for snippet in list(self.active_snippets):
self.deactivate_snippet(snippet, True)
completion = self.view.get_completion()
- completion.remove_provider(self.provider)
- completion.remove_provider(self.defaults_provider)
+ if completion:
+ completion.remove_provider(self.provider)
self.view = view
@@ -130,16 +125,12 @@ class Document:
self.connect_signal(buf, 'notify::language', self.on_notify_language)
self.connect_signal(view, 'notify::editable', self.on_notify_editable)
self.connect_signal(view, 'drag-data-received', self.on_drag_data_received)
- self.connect_signal_after(view, 'expose-event', self.on_expose_event)
+ self.connect_signal_after(view, 'draw', self.on_draw)
self.update_language()
completion = view.get_completion()
completion.add_provider(self.provider)
-
- completion.add_provider(self.defaults_provider)
-
- self.connect_signal(completion, 'hide', self.on_completion_hide)
elif self.language_id != 0:
langid = self.language_id
@@ -187,7 +178,7 @@ class Document:
if not self.view or not self.view.get_editable():
return False
- accelerator = gtk.accelerator_name(keyval, mod)
+ accelerator = Gtk.accelerator_name(keyval, mod)
snippets = Library().from_accelerator(accelerator, \
self.language_id)
@@ -199,8 +190,10 @@ class Document:
self.apply_snippet(snippets[0])
else:
# Do the fancy completion dialog
- self.provider.set_proposals(snippets)
- self.view.show_completion((self,))
+ provider = Completion.Provider(_('Snippets'), self.language_id, self.on_proposal_activated)
+ provider.set_proposals(snippets)
+
+ cm.show([provider], cm.create_context(None))
return True
@@ -335,10 +328,11 @@ class Document:
if next.__class__ == PlaceholderEnd:
last = next
elif len(next.defaults) > 1 and next.get_text() == next.default:
- self.defaults_provider.set_defaults(next.defaults)
+ provider = Completion.Defaults(self.on_default_activated)
+ provider.set_defaults(next.defaults)
cm = self.view.get_completion()
- cm.show([self.defaults_provider], cm.create_context())
+ cm.show([provider], cm.create_context(None))
if last:
# This is the end of the placeholder, remove the snippet etc
@@ -363,19 +357,19 @@ class Document:
bounds = buf.get_selection_bounds()
if bounds:
- return buf.get_text(bounds[0], bounds[1])
+ return buf.get_text(bounds[0], bounds[1], False)
else:
return ''
def env_get_current_word(self, buf):
start, end = buffer_word_boundary(buf)
- return buf.get_text(start, end)
+ return buf.get_text(start, end, False)
def env_get_current_line(self, buf):
start, end = buffer_line_boundary(buf)
- return buf.get_text(start, end)
+ return buf.get_text(start, end, False)
def env_get_current_line_number(self, buf):
start, end = buffer_line_boundary(buf)
@@ -433,7 +427,7 @@ class Document:
def env_get_documents_uri(self, buf):
toplevel = self.view.get_toplevel()
- if isinstance(toplevel, pluma.Window):
+ if isinstance(toplevel, Pluma.Window):
documents_uri = [doc.get_location().get_uri()
for doc in toplevel.get_documents()
if doc.get_location() is not None]
@@ -445,14 +439,14 @@ class Document:
def env_get_documents_path(self, buf):
toplevel = self.view.get_toplevel()
- if isinstance(toplevel, pluma.Window):
+ if isinstance(toplevel, Pluma.Window):
documents_location = [doc.get_location()
for doc in toplevel.get_documents()
if doc.get_location() is not None]
documents_path = [location.get_path()
for location in documents_location
- if pluma.utils.uri_has_file_scheme(location.get_uri())]
+ if Pluma.utils_uri_has_file_scheme(location.get_uri())]
else:
documents_path = []
@@ -585,7 +579,7 @@ class Document:
tmp.forward_word_end()
if tmp.equal(end):
- word = buf.get_text(start, end)
+ word = buf.get_text(start, end, False)
else:
start = end.copy()
else:
@@ -617,10 +611,12 @@ class Document:
return self.apply_snippet(snippets[0], bounds[0], bounds[1])
else:
# Do the fancy completion dialog
- self.provider.set_proposals(snippets)
+ provider = Completion.Provider(_('Snippets'), self.language_id, self.on_proposal_activated)
+ provider.set_proposals(snippets)
+
cm = self.view.get_completion()
-
- cm.show([self.provider], cm.create_context())
+ cm.show([provider], cm.create_context(None))
+
return True
return False
@@ -727,7 +723,7 @@ class Document:
self.jump_placeholders.append((self.active_placeholder, current))
if self.timeout_update_id == 0:
- self.timeout_update_id = gobject.timeout_add(0,
+ self.timeout_update_id = GLib.timeout_add(0,
self.update_snippet_contents)
def on_buffer_changed(self, buf):
@@ -738,7 +734,7 @@ class Document:
self.update_placeholders.append(current)
if self.timeout_update_id == 0:
- self.timeout_update_id = gobject.timeout_add(0, \
+ self.timeout_update_id = GLib.timeout_add(0, \
self.update_snippet_contents)
def on_buffer_insert_text(self, buf, piter, text, length):
@@ -789,19 +785,21 @@ class Document:
def on_view_key_press(self, view, event):
library = Library()
- if not (event.state & gdk.CONTROL_MASK) and \
- not (event.state & gdk.MOD1_MASK) and \
+ state = event.get_state()
+
+ if not (state & Gdk.ModifierType.CONTROL_MASK) and \
+ not (state & Gdk.ModifierType.MOD1_MASK) and \
event.keyval in self.TAB_KEY_VAL:
- if not event.state & gdk.SHIFT_MASK:
+ if not state & Gdk.ModifierType.SHIFT_MASK:
return self.run_snippet()
else:
return self.skip_to_previous_placeholder()
elif not library.loaded and \
- library.valid_accelerator(event.keyval, event.state):
+ library.valid_accelerator(event.keyval, state):
library.ensure_files()
library.ensure(self.language_id)
self.accelerator_activate(event.keyval, \
- event.state & gtk.accelerator_get_default_mod_mask())
+ state & Gtk.accelerator_get_default_mod_mask())
return False
@@ -860,12 +858,12 @@ class Document:
def apply_uri_snippet(self, snippet, mime, uri):
# Remove file scheme
- gfile = gio.File(uri)
+ gfile = Gio.file_new_for_uri(uri)
pathname = ''
dirname = ''
ruri = ''
- if pluma.utils.uri_has_file_scheme(uri):
+ if Pluma.utils_uri_has_file_scheme(uri):
pathname = gfile.get_path()
dirname = gfile.get_parent().get_path()
@@ -898,21 +896,24 @@ class Document:
def in_bounds(self, x, y):
rect = self.view.get_visible_rect()
- rect.x, rect.y = self.view.buffer_to_window_coords(gtk.TEXT_WINDOW_WIDGET, rect.x, rect.y)
+ rect.x, rect.y = self.view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect.x, rect.y)
return not (x < rect.x or x > rect.x + rect.width or y < rect.y or y > rect.y + rect.height)
def on_drag_data_received(self, view, context, x, y, data, info, timestamp):
- if not (gtk.targets_include_uri(context.targets) and data.data and self.in_bounds(x, y)):
+ uris = drop_get_uris(data)
+ if not uris:
+ return
+
+ if not self.in_bounds(x, y):
return
- uris = drop_get_uris(data)
uris.reverse()
stop = False
for uri in uris:
try:
- mime = gio.content_type_guess(uri)
+ mime = Gio.content_type_guess(uri)
except:
mime = None
@@ -932,13 +933,10 @@ class Document:
view.grab_focus()
def find_uri_target(self, context):
- lst = gtk.target_list_add_uri_targets((), 0)
+ lst = Gtk.target_list_add_uri_targets((), 0)
return self.view.drag_dest_find_target(context, lst)
- def on_completion_hide(self, completion):
- self.provider.set_proposals(None)
-
def on_proposal_activated(self, proposal, piter):
buf = self.view.get_buffer()
bounds = buf.get_selection_bounds()
@@ -967,7 +965,7 @@ class Document:
def iter_coords(self, piter):
rect = self.view.get_iter_location(piter)
- rect.x, rect.y = self.view.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT, rect.x, rect.y)
+ rect.x, rect.y = self.view.buffer_to_window_coords(Gtk.TextWindowType.TEXT, rect.x, rect.y)
return rect
@@ -985,7 +983,7 @@ class Document:
return start_rect.y <= area.y + area.height and \
end_rect.y + end_rect.height >= area.y
- def draw_placeholder_rect(self, ctx, placeholder, col):
+ def draw_placeholder_rect(self, ctx, placeholder):
start = placeholder.begin_iter()
start_rect = self.iter_coords(start)
start_line = start.get_line()
@@ -996,13 +994,13 @@ class Document:
line = start.copy()
line.set_line_offset(0)
- geom = self.view.get_window(gtk.TEXT_WINDOW_TEXT).get_geometry()
+ geom = self.view.get_window(Gtk.TextWindowType.TEXT).get_geometry()
ctx.translate(0.5, 0.5)
while line.get_line() <= end_line:
ypos, height = self.view.get_line_yrange(line)
- x_, ypos = self.view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, 0, ypos)
+ x_, ypos = self.view.window_to_buffer_coords(Gtk.TextWindowType.TEXT, 0, ypos)
if line.get_line() == start_line and line.get_line() == end_line:
# Simply draw a box, both are on the same line
@@ -1023,7 +1021,7 @@ class Document:
if not line.forward_line():
break
- def draw_placeholder_bar(self, ctx, placeholder, col):
+ def draw_placeholder_bar(self, ctx, placeholder):
start = placeholder.begin_iter()
start_rect = self.iter_coords(start)
@@ -1040,17 +1038,15 @@ class Document:
ctx.rel_line_to(extend_width * 2, 0)
ctx.stroke()
- def from_color(self, col):
- return [col.red / 0x10000, col.green / 0x10000, col.blue / 0x10000]
-
def draw_placeholder(self, ctx, placeholder):
if isinstance(placeholder, PlaceholderEnd):
return
buf = self.view.get_buffer()
- col = self.from_color(self.view.get_style().text[gtk.STATE_INSENSITIVE])
- ctx.set_source_rgba(col[0], col[1], col[2], 0.5)
+ col = self.view.get_style_context().get_color(Gtk.StateFlags.INSENSITIVE)
+ col.alpha = 0.5
+ Gdk.cairo_set_source_rgba(ctx, col)
if placeholder.tabstop > 0:
ctx.set_dash([], 0)
@@ -1061,23 +1057,25 @@ class Document:
end = placeholder.end_iter()
if start.equal(end):
- self.draw_placeholder_bar(ctx, placeholder, col)
+ self.draw_placeholder_bar(ctx, placeholder)
else:
- self.draw_placeholder_rect(ctx, placeholder, col)
+ self.draw_placeholder_rect(ctx, placeholder)
- def on_expose_event(self, view, event):
- if event.window != view.get_window(gtk.TEXT_WINDOW_TEXT):
- return False
+ def on_draw(self, view, ctx):
+ window = view.get_window(Gtk.TextWindowType.TEXT)
- # Draw something
- ctx = event.window.cairo_create()
- ctx.rectangle(event.area)
- ctx.clip()
+ if not Gtk.cairo_should_draw_window(ctx, window):
+ return False
ctx.set_line_width(1.0)
+ Gtk.cairo_transform_to_window(ctx, view, window)
+ clipped, clip = Gdk.cairo_get_clip_rectangle(ctx)
+
+ if not clipped:
+ return False
for placeholder in self.ordered_placeholders:
- if not self.placeholder_in_area(placeholder, event.area):
+ if not self.placeholder_in_area(placeholder, clip):
continue
ctx.save()
diff --git a/plugins/snippets/snippets/Exporter.py b/plugins/snippets/snippets/Exporter.py
index 51d49104..18369a68 100755
--- a/plugins/snippets/snippets/Exporter.py
+++ b/plugins/snippets/snippets/Exporter.py
@@ -3,7 +3,7 @@ import tempfile
import sys
import shutil
-from snippets.Library import *
+from Library import *
import xml.etree.ElementTree as et
from Helper import *
diff --git a/plugins/snippets/snippets/Helper.py b/plugins/snippets/snippets/Helper.py
index 60ae1c79..d8a19673 100755
--- a/plugins/snippets/snippets/Helper.py
+++ b/plugins/snippets/snippets/Helper.py
@@ -20,11 +20,10 @@ from xml.sax import saxutils
from xml.etree.ElementTree import *
import re
-import gtk
-from gtk import gdk
+from gi.repository import Gtk
def message_dialog(par, typ, msg):
- d = gtk.MessageDialog(par, gtk.DIALOG_MODAL, typ, gtk.BUTTONS_OK, msg)
+ d = Gtk.MessageDialog(par, Gtk.DialogFlags.MODAL, typ, Gtk.ButtonsType.OK, msg)
d.set_property('use-markup', True)
d.run()
@@ -61,8 +60,9 @@ def spaces_instead_of_tabs(view, text):
def insert_with_indent(view, piter, text, indentfirst = True, context = None):
text = spaces_instead_of_tabs(view, text)
lines = text.split('\n')
+ buf = view.get_buffer()
- view.get_buffer().set_data('PlumaSnippetsPluginContext', context)
+ buf._snippets_context = context
if len(lines) == 1:
view.get_buffer().insert(piter, text)
@@ -77,12 +77,14 @@ def insert_with_indent(view, piter, text, indentfirst = True, context = None):
else:
text += lines[i] + '\n'
- view.get_buffer().insert(piter, text[:-1])
+ buf.insert(piter, text[:-1])
- view.get_buffer().set_data('PlumaSnippetsPluginContext', None)
+ buf._snippets_context = None
def get_buffer_context(buf):
- return buf.get_data('PlumaSnippetsPluginContext')
+ if hasattr(buf, "_snippets_context"):
+ return buf._snippets_context
+ return None
def snippets_debug(*s):
return
@@ -170,13 +172,15 @@ def buffer_line_boundary(buf):
return (start, iter)
def drop_get_uris(selection):
- lines = re.split('\\s*[\\n\\r]+\\s*', selection.data.strip())
- result = []
-
- for line in lines:
- if not line.startswith('#'):
- result.append(line)
-
- return result
+ uris = []
+ if selection.targets_include_uri():
+ data = selection.get_data()
+ lines = re.split('\\s*[\\n\\r]+\\s*', data.strip())
+
+ for line in lines:
+ if not line.startswith('#'):
+ uris.append(line)
+
+ return uris
# ex:ts=8:et:
diff --git a/plugins/snippets/snippets/Importer.py b/plugins/snippets/snippets/Importer.py
index 6151027d..b2e8723a 100755
--- a/plugins/snippets/snippets/Importer.py
+++ b/plugins/snippets/snippets/Importer.py
@@ -3,7 +3,7 @@ import tempfile
import sys
import shutil
-from snippets.Library import *
+from Library import *
class Importer:
def __init__(self, filename):
diff --git a/plugins/snippets/snippets/LanguageManager.py b/plugins/snippets/snippets/LanguageManager.py
index 9646ef17..1fb4347c 100755
--- a/plugins/snippets/snippets/LanguageManager.py
+++ b/plugins/snippets/snippets/LanguageManager.py
@@ -1,5 +1,5 @@
-import gtksourceview2 as gsv
import os
+from gi.repository import GtkSource
from Library import Library
@@ -15,7 +15,7 @@ def get_language_manager():
for d in Library().systemdirs:
dirs.append(os.path.join(d, 'lang'))
- manager = gsv.LanguageManager()
+ manager = GtkSource.LanguageManager()
manager.set_search_path(dirs + manager.get_search_path())
return manager
diff --git a/plugins/snippets/snippets/Library.py b/plugins/snippets/snippets/Library.py
index 792f0f7e..5b3773ae 100755
--- a/plugins/snippets/snippets/Library.py
+++ b/plugins/snippets/snippets/Library.py
@@ -21,7 +21,7 @@ import sys
import tempfile
import re
-import gtk
+from gi.repository import Gdk, Gtk
import xml.etree.ElementTree as et
from Helper import *
@@ -84,10 +84,10 @@ class SnippetData:
# Normalize accelerator
if child.tag == 'accelerator' and child.text != None:
- keyval, mod = gtk.accelerator_parse(child.text)
+ keyval, mod = Gtk.accelerator_parse(child.text)
- if gtk.accelerator_valid(keyval, mod):
- child.text = gtk.accelerator_name(keyval, mod)
+ if Gtk.accelerator_valid(keyval, mod):
+ child.text = Gtk.accelerator_name(keyval, mod)
else:
child.text = ''
@@ -113,7 +113,7 @@ class SnippetData:
return False
library = Library()
- keyval, mod = gtk.accelerator_parse(self['accelerator'])
+ keyval, mod = Gtk.accelerator_parse(self['accelerator'])
self.valid = library.valid_tab_trigger(self['tag']) and \
(not self['accelerator'] or library.valid_accelerator(keyval, mod))
@@ -271,7 +271,7 @@ class LanguageContainer:
self.language = language
self.snippets = []
self.snippets_by_prop = {'tag': {}, 'accelerator': {}, 'drop-targets': {}}
- self.accel_group = gtk.AccelGroup()
+ self.accel_group = Gtk.AccelGroup()
self._refs = 0
def _add_prop(self, snippet, prop, value=0):
@@ -284,8 +284,8 @@ class LanguageContainer:
snippets_debug('Added ', prop ,' ', value, ' to ', str(self.language))
if prop == 'accelerator':
- keyval, mod = gtk.accelerator_parse(value)
- self.accel_group.connect_group(keyval, mod, 0, \
+ keyval, mod = Gtk.accelerator_parse(value)
+ self.accel_group.connect(keyval, mod, 0, \
Library().accelerator_activated)
snippets = self.snippets_by_prop[prop]
@@ -309,7 +309,7 @@ class LanguageContainer:
snippets_debug('Removed ', prop, ' ', value, ' from ', str(self.language))
if prop == 'accelerator':
- keyval, mod = gtk.accelerator_parse(value)
+ keyval, mod = Gtk.accelerator_parse(value)
self.accel_group.disconnect_key(keyval, mod)
snippets = self.snippets_by_prop[prop]
@@ -641,9 +641,9 @@ class Singleton(object):
class Library(Singleton):
def __init_once__(self):
- self._accelerator_activated_cb = None
+ self._accelerator_activated_cb = []
self.loaded = False
- self.check_buffer = gtk.TextBuffer()
+ self.check_buffer = Gtk.TextBuffer()
def set_dirs(self, userdir, systemdirs):
self.userdir = userdir
@@ -656,14 +656,20 @@ class Library(Singleton):
self.loaded = False
- def set_accelerator_callback(self, cb):
- self._accelerator_activated_cb = cb
+ def add_accelerator_callback(self, cb):
+ self._accelerator_activated_cb.append(cb)
+
+ def remove_accelerator_callback(self, cb):
+ self._accelerator_activated_cb.remove(cb)
def accelerator_activated(self, group, obj, keyval, mod):
ret = False
- if self._accelerator_activated_cb:
- ret = self._accelerator_activated_cb(group, obj, keyval, mod)
+ for cb in self._accelerator_activated_cb:
+ ret = cb(group, obj, keyval, mod)
+
+ if ret:
+ break
return ret
@@ -921,10 +927,10 @@ class Library(Singleton):
self.loaded = True
def valid_accelerator(self, keyval, mod):
- mod &= gtk.accelerator_get_default_mod_mask()
+ mod &= Gtk.accelerator_get_default_mod_mask()
- return (mod and (gdk.keyval_to_unicode(keyval) or \
- keyval in range(gtk.keysyms.F1, gtk.keysyms.F12 + 1)))
+ return (mod and (Gdk.keyval_to_unicode(keyval) or \
+ keyval in range(Gdk.KEY_F1, Gdk.KEY_F12 + 1)))
def valid_tab_trigger(self, trigger):
if not trigger:
@@ -936,7 +942,7 @@ class Library(Singleton):
self.check_buffer.set_text(trigger)
start, end = self.check_buffer.get_bounds()
- text = self.check_buffer.get_text(start, end)
+ text = self.check_buffer.get_text(start, end, False)
s = start.copy()
e = end.copy()
diff --git a/plugins/snippets/snippets/Manager.py b/plugins/snippets/snippets/Manager.py
index 4c58a3b3..e94cd283 100755
--- a/plugins/snippets/snippets/Manager.py
+++ b/plugins/snippets/snippets/Manager.py
@@ -19,13 +19,7 @@ import os
import tempfile
import shutil
-import gobject
-import gtk
-from gtk import gdk
-import gtksourceview2 as gsv
-import pango
-import pluma
-import gio
+from gi.repository import GObject, Gio, Gdk, Gtk, GtkSource, Pluma
from Snippet import Snippet
from Helper import *
@@ -38,14 +32,15 @@ from LanguageManager import get_language_manager
class Manager:
NAME_COLUMN = 0
SORT_COLUMN = 1
- OBJ_COLUMN = 2
+ LANG_COLUMN = 2
+ SNIPPET_COLUMN = 3
TARGET_URI = 105
model = None
drag_icons = ('mate-mime-application-x-tarz', 'mate-package', 'package')
default_export_name = _('Snippets archive') + '.tar.gz'
dragging = False
- dnd_target_list = [('text/uri-list', 0, TARGET_URI)]
+ dnd_target_list = [Gtk.TargetEntry.new('text/uri-list', 0, TARGET_URI)]
def __init__(self, datadir):
self.datadir = datadir
@@ -69,7 +64,7 @@ class Manager:
def add_new_snippet_node(self, parent):
return self.model.append(parent, ('<i>' + _('Add a new snippet...') + \
- '</i>', '', None))
+ '</i>', '', None, None))
def fill_language(self, piter, expand=True):
# Remove all children
@@ -95,7 +90,7 @@ class Manager:
self.tree_view.expand_row(path, False)
def build_model(self, force_reload = False):
- window = pluma.app_get_default().get_active_window()
+ window = Pluma.App.get_default().get_active_window()
if window:
view = window.get_active_view()
@@ -113,14 +108,15 @@ class Manager:
expand = None
if not self.model or force_reload:
- self.model = gtk.TreeStore(str, str, object)
- self.model.set_sort_column_id(self.SORT_COLUMN, gtk.SORT_ASCENDING)
+ self.model = Gtk.TreeStore(str, str, GObject.Object, object)
+ self.model.set_sort_column_id(self.SORT_COLUMN, Gtk.SortType.ASCENDING)
manager = get_language_manager()
- langs = pluma.language_manager_list_languages_sorted(manager, True)
+ langs = [manager.get_language(x) for x in manager.get_language_ids()]
+ langs.sort(key=lambda x: x.get_name())
- piter = self.model.append(None, (_('Global'), '', None))
+ piter = self.model.append(None, (_('Global'), '', None, None))
# Add dummy node
- self.model.append(piter, ('', '', None))
+ self.model.append(piter, ('', '', None, None))
nm = None
@@ -129,10 +125,10 @@ class Manager:
for lang in langs:
name = lang.get_name()
- parent = self.model.append(None, (name, name, lang))
+ parent = self.model.append(None, (name, name, lang, None))
# Add dummy node
- self.model.append(parent, ('', '', None))
+ self.model.append(parent, ('', '', None, None))
if (nm == name):
expand = parent
@@ -154,33 +150,29 @@ class Manager:
tree_view.set_model(self.model)
if not expand:
- expand = self.model.get_iter_root()
+ expand = self.model.get_iter_first()
tree_view.expand_row(self.model.get_path(expand), False)
self.select_iter(expand)
- def get_cell_data_pixbuf_cb(self, column, cell, model, iter):
- s = model.get_value(iter, self.OBJ_COLUMN)
+ def get_cell_data_pixbuf_cb(self, column, cell, model, iter, data):
+ snippet = model.get_value(iter, self.SNIPPET_COLUMN)
- snippet = isinstance(s, SnippetData)
-
- if snippet and not s.valid:
- cell.set_property('stock-id', gtk.STOCK_DIALOG_ERROR)
+ if snippet and not snippet.valid:
+ cell.set_property('stock-id', Gtk.STOCK_DIALOG_ERROR)
else:
cell.set_property('stock-id', None)
cell.set_property('xalign', 1.0)
- def get_cell_data_cb(self, column, cell, model, iter):
- s = model.get_value(iter, self.OBJ_COLUMN)
-
- snippet = isinstance(s, SnippetData)
+ def get_cell_data_cb(self, column, cell, model, iter, data):
+ snippet = model.get_value(iter, self.SNIPPET_COLUMN)
- cell.set_property('editable', snippet)
+ cell.set_property('editable', snippet != None)
cell.set_property('markup', model.get_value(iter, self.NAME_COLUMN))
def on_tree_view_drag_data_get(self, widget, context, selection_data, info, time):
- gfile = gio.File(self._temp_export)
+ gfile = Gio.file_new_for_path(self._temp_export)
selection_data.set_uris([gfile.get_uri()])
def on_tree_view_drag_begin(self, widget, context):
@@ -191,7 +183,7 @@ class Manager:
self._temp_export = None
if self.dnd_name:
- context.set_icon_name(self.dnd_name, 0, 0)
+ Gtk.drag_set_icon_name(context, self.dnd_name, 0, 0)
dirname = tempfile.mkdtemp()
filename = os.path.join(dirname, self.default_export_name)
@@ -214,21 +206,21 @@ class Manager:
return False
# Check uri target
- if not gtk.targets_include_uri(context.targets):
+ if not Gtk.targets_include_uri(context.targets):
return False
# Check action
action = None
- if context.suggested_action == gdk.ACTION_COPY:
- action = gdk.ACTION_COPY
+ if context.suggested_action == Gdk.DragAction.COPY:
+ action = Gdk.DragAction.COPY
else:
for act in context.actions:
- if act == gdk.ACTION_COPY:
- action = gdk.ACTION_COPY
+ if act == Gdk.DragAction.COPY:
+ action = Gdk.DragAction.COPY
break
- if action == gdk.ACTION_COPY:
- context.drag_status(gdk.ACTION_COPY, timestamp)
+ if action == Gdk.DragAction.COPY:
+ context.drag_status(Gdk.DragAction.COPY, timestamp)
return True
else:
return False
@@ -237,11 +229,11 @@ class Manager:
tv = self.tree_view
# Set it as a drag source for exporting snippets
- tv.drag_source_set(gdk.BUTTON1_MASK, self.dnd_target_list, gdk.ACTION_DEFAULT | gdk.ACTION_COPY)
+ tv.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, self.dnd_target_list, Gdk.DragAction.DEFAULT | Gdk.DragAction.COPY)
# Set it as a drag destination for importing snippets
- tv.drag_dest_set(gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP,
- self.dnd_target_list, gdk.ACTION_DEFAULT | gdk.ACTION_COPY)
+ tv.drag_dest_set(Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,
+ self.dnd_target_list, Gdk.DragAction.DEFAULT | Gdk.DragAction.COPY)
tv.connect('drag_data_get', self.on_tree_view_drag_data_get)
tv.connect('drag_begin', self.on_tree_view_drag_begin)
@@ -249,11 +241,11 @@ class Manager:
tv.connect('drag_data_received', self.on_tree_view_drag_data_received)
tv.connect('drag_motion', self.on_tree_view_drag_motion)
- theme = gtk.icon_theme_get_for_screen(tv.get_screen())
+ theme = Gtk.IconTheme.get_for_screen(tv.get_screen())
self.dnd_name = None
for name in self.drag_icons:
- icon = theme.lookup_icon(name, gtk.ICON_SIZE_DND, 0)
+ icon = theme.lookup_icon(name, Gtk.IconSize.DND, 0)
if icon:
self.dnd_name = name
@@ -262,15 +254,15 @@ class Manager:
def build_tree_view(self):
self.tree_view = self['tree_view_snippets']
- self.column = gtk.TreeViewColumn(None)
+ self.column = Gtk.TreeViewColumn(None)
- self.renderer = gtk.CellRendererText()
+ self.renderer = Gtk.CellRendererText()
self.column.pack_start(self.renderer, False)
- self.column.set_cell_data_func(self.renderer, self.get_cell_data_cb)
+ self.column.set_cell_data_func(self.renderer, self.get_cell_data_cb, None)
- renderer = gtk.CellRendererPixbuf()
+ renderer = Gtk.CellRendererPixbuf()
self.column.pack_start(renderer, True)
- self.column.set_cell_data_func(renderer, self.get_cell_data_pixbuf_cb)
+ self.column.set_cell_data_func(renderer, self.get_cell_data_pixbuf_cb, None)
self.tree_view.append_column(self.column)
@@ -278,13 +270,13 @@ class Manager:
self.renderer.connect('editing-started', self.on_cell_editing_started)
selection = self.tree_view.get_selection()
- selection.set_mode(gtk.SELECTION_MULTIPLE)
+ selection.set_mode(Gtk.SelectionMode.MULTIPLE)
selection.connect('changed', self.on_tree_view_selection_changed)
self.build_dnd()
def build(self):
- self.builder = gtk.Builder()
+ self.builder = Gtk.Builder()
self.builder.add_from_file(os.path.join(self.datadir, 'ui', 'snippets.ui'))
handlers_dic = {
@@ -309,7 +301,7 @@ class Manager:
self.build_model()
image = self['image_remove']
- image.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_SMALL_TOOLBAR)
+ image.set_from_stock(Gtk.STOCK_REMOVE, Gtk.IconSize.SMALL_TOOLBAR)
source_view = self['source_view_snippet']
manager = get_language_manager()
@@ -321,15 +313,13 @@ class Manager:
self.snippets_doc = Document(None, source_view)
combo = self['combo_drop_targets']
- combo.set_text_column(0)
- entry = combo.child
+ entry = combo.get_child()
entry.connect('focus-out-event', self.on_entry_drop_targets_focus_out)
entry.connect('drag-data-received', self.on_entry_drop_targets_drag_data_received)
lst = entry.drag_dest_get_target_list()
- lst = gtk.target_list_add_uri_targets(entry.drag_dest_get_target_list(), self.TARGET_URI)
- entry.drag_dest_set_target_list(lst)
+ lst.add_uri_targets(self.TARGET_URI)
self.dlg = self['dialog_snippets']
@@ -345,9 +335,10 @@ class Manager:
child = self.model.iter_children(piter)
nm = self.model.get_value(child, self.NAME_COLUMN)
- obj = self.model.get_value(child, self.OBJ_COLUMN)
+ lang = self.model.get_value(child, self.LANG_COLUMN)
+ snippet = self.model.get_value(child, self.SNIPPET_COLUMN)
- return (obj or nm)
+ return (lang or snippet or nm)
def fill_if_needed(self, piter, expand=True):
if not self.is_filled(piter):
@@ -358,7 +349,7 @@ class Manager:
piter = self.model.iter_children(parent)
while (piter):
- node = self.model.get_value(piter, self.OBJ_COLUMN)
+ node = self.model.get_value(piter, self.SNIPPET_COLUMN)
if node == snippet.data:
return piter
@@ -400,22 +391,22 @@ class Manager:
if not (override ^ remove) or system:
button_remove.set_sensitive(False)
- image_remove.set_from_stock(gtk.STOCK_DELETE, gtk.ICON_SIZE_BUTTON)
+ image_remove.set_from_stock(Gtk.STOCK_DELETE, Gtk.IconSize.BUTTON)
else:
button_remove.set_sensitive(True)
if override:
- image_remove.set_from_stock(gtk.STOCK_UNDO, gtk.ICON_SIZE_BUTTON)
+ image_remove.set_from_stock(Gtk.STOCK_UNDO, Gtk.IconSize.BUTTON)
tooltip = _('Revert selected snippet')
else:
- image_remove.set_from_stock(gtk.STOCK_DELETE, gtk.ICON_SIZE_BUTTON)
+ image_remove.set_from_stock(Gtk.STOCK_DELETE, Gtk.IconSize.BUTTON)
tooltip = _('Delete selected snippet')
button_remove.set_tooltip_text(tooltip)
def snippet_changed(self, piter = None):
if piter:
- node = self.model.get_value(piter, self.OBJ_COLUMN)
+ node = self.model.get_value(piter, self.SNIPPET_COLUMN)
s = Snippet(node)
else:
s = self.snippet
@@ -424,14 +415,15 @@ class Manager:
if piter:
nm = s.display()
- self.model.set(piter, self.NAME_COLUMN, nm, self.SORT_COLUMN, nm)
+ self.model.set_value(piter, self.NAME_COLUMN, nm)
+ self.model.set_value(piter, self.SORT_COLUMN, nm)
self.update_buttons()
self.entry_tab_trigger_update_valid()
return piter
def add_snippet(self, parent, snippet):
- piter = self.model.append(parent, ('', '', snippet))
+ piter = self.model.append(parent, ('', '', None, snippet))
return self.snippet_changed(piter)
@@ -443,12 +435,11 @@ class Manager:
self.build_model()
self.dlg.present()
-
def snippet_from_iter(self, model, piter):
parent = model.iter_parent(piter)
if parent:
- return model.get_value(piter, self.OBJ_COLUMN)
+ return model.get_value(piter, self.SNIPPET_COLUMN)
else:
return None
@@ -524,7 +515,7 @@ class Manager:
buf.begin_not_undoable_action()
buf.set_text('')
buf.end_not_undoable_action()
- self['combo_drop_targets'].child.set_text('')
+ self['combo_drop_targets'].get_child().set_text('')
else:
sens = True
@@ -532,7 +523,7 @@ class Manager:
self['entry_tab_trigger'].set_text(self.snippet['tag'])
self['entry_accelerator'].set_text( \
self.snippet.accelerator_display())
- self['combo_drop_targets'].child.set_text(', '.join(self.snippet['drop-targets']))
+ self['combo_drop_targets'].get_child().set_text(', '.join(self.snippet['drop-targets']))
buf = self['source_view_snippet'].get_buffer()
buf.begin_not_undoable_action()
@@ -560,11 +551,11 @@ class Manager:
True, 0.5, 0.5)
def get_language(self, path):
- if path[0] == 0:
+ if path.get_indices()[0] == 0:
return None
else:
- return self.model.get_value(self.model.get_iter( \
- (path[0],)), self.OBJ_COLUMN).get_id()
+ return self.model.get_value(self.model.get_iter(path), \
+ self.LANG_COLUMN).get_id()
def new_snippet(self, properties=None):
if not self.language_path:
@@ -580,7 +571,7 @@ class Manager:
dummy = self.model.iter_children(parent)
- if not self.model.get_value(dummy, self.OBJ_COLUMN):
+ if not self.model.get_value(dummy, self.SNIPPET_COLUMN):
return dummy
return None
@@ -608,7 +599,8 @@ class Manager:
if self.snippets_doc:
self.snippets_doc.stop()
- self.default_size = [dlg.allocation.width, dlg.allocation.height]
+ alloc = dlg.get_allocation()
+ self.default_size = [alloc.width, alloc.height]
self.manager = None
self.unref_languages()
@@ -617,8 +609,8 @@ class Manager:
self.dlg = None
def on_dialog_snippets_response(self, dlg, resp):
- if resp == gtk.RESPONSE_HELP:
- pluma.help_display(self.dlg, 'pluma', 'pluma-snippets-plugin')
+ if resp == Gtk.ResponseType.HELP:
+ Pluma.help_display(self, 'pluma', 'pluma-snippets-plugin')
return
self.dlg.destroy()
@@ -629,7 +621,7 @@ class Manager:
if not self.model.iter_parent(piter):
renderer.stop_editing(True)
editable.remove_widget()
- elif isinstance(editable, gtk.Entry):
+ elif isinstance(editable, Gtk.Entry):
if self.snippet:
editable.set_text(self.snippet['description'])
else:
@@ -641,7 +633,7 @@ class Manager:
def on_cell_edited(self, cell, path, new_text):
if new_text != '':
piter = self.model.get_iter(path)
- node = self.model.get_value(piter, self.OBJ_COLUMN)
+ node = self.model.get_value(piter, self.SNIPPET_COLUMN)
if node:
if node == self.snippet.data:
@@ -658,7 +650,7 @@ class Manager:
snippet = self.new_snippet({'description': new_text})
if snippet:
- self.model.set(piter, self.OBJ_COLUMN, snippet.data)
+ self.model.set_value(piter, self.SNIPPET_COLUMN, snippet.data)
self.snippet_changed(piter)
self.snippet = snippet
self.selection_changed()
@@ -675,7 +667,7 @@ class Manager:
if text and not Library().valid_tab_trigger(text):
img = self['image_tab_trigger']
- img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_BUTTON)
+ img.set_from_stock(Gtk.STOCK_DIALOG_ERROR, Gtk.IconSize.BUTTON)
img.show()
#self['hbox_tab_trigger'].set_spacing(3)
@@ -719,7 +711,7 @@ class Manager:
buf = source_view.get_buffer()
text = buf.get_text(buf.get_start_iter(), \
- buf.get_end_iter())
+ buf.get_end_iter(), False)
self.snippet['text'] = text
self.snippet_changed()
@@ -753,7 +745,7 @@ class Manager:
self.tree_view.set_cursor(path, self.column, True)
def file_filter(self, name, pattern):
- fil = gtk.FileFilter()
+ fil = Gtk.FileFilter()
fil.set_name(name)
for p in pattern:
@@ -765,11 +757,11 @@ class Manager:
success = True
for filename in filenames:
- if not pluma.utils.uri_has_file_scheme(filename):
+ if not Pluma.utils_uri_has_file_scheme(filename):
continue
# Remove file://
- gfile = gio.File(filename)
+ gfile = Gio.file_new_for_uri(filename)
filename = gfile.get_path()
importer = Importer(filename)
@@ -778,16 +770,16 @@ class Manager:
if error:
message = _('The following error occurred while importing: %s') % error
success = False
- message_dialog(self.dlg, gtk.MESSAGE_ERROR, message)
+ message_dialog(self.dlg, Gtk.MessageType.ERROR, message)
self.build_model(True)
if success:
message = _('Import successfully completed')
- message_dialog(self.dlg, gtk.MESSAGE_INFO, message)
+ message_dialog(self.dlg, Gtk.MessageType.INFO, message)
def on_import_response(self, dialog, response):
- if response == gtk.RESPONSE_CANCEL or response == gtk.RESPONSE_CLOSE:
+ if response == Gtk.ResponseType.CANCEL or response == Gtk.ResponseType.CLOSE:
dialog.destroy()
return
@@ -797,10 +789,10 @@ class Manager:
self.import_snippets(f)
def on_button_import_snippets_clicked(self, button):
- dlg = gtk.FileChooserDialog(parent=self.dlg, title=_("Import snippets"),
- action=gtk.FILE_CHOOSER_ACTION_OPEN,
- buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
- gtk.STOCK_OPEN, gtk.RESPONSE_OK))
+ dlg = Gtk.FileChooserDialog(parent=self.dlg, title=_("Import snippets"),
+ action=Gtk.FileChooserAction.OPEN,
+ buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
dlg.add_filter(self.file_filter(_('All supported archives'), ('*.gz','*.bz2','*.tar', '*.xml')))
dlg.add_filter(self.file_filter(_('Gzip compressed archive'), ('*.tar.gz',)))
@@ -819,11 +811,11 @@ class Manager:
if error:
message = _('The following error occurred while exporting: %s') % error
- msgtype = gtk.MESSAGE_ERROR
+ msgtype = Gtk.MessageType.ERROR
retval = False
else:
message = _('Export successfully completed')
- msgtype = gtk.MESSAGE_INFO
+ msgtype = Gtk.MessageType.INFO
retval = True
if show_dialogs:
@@ -837,7 +829,7 @@ class Manager:
dialog.destroy()
- if response != gtk.RESPONSE_OK:
+ if response != Gtk.ResponseType.OK:
return
self.export_snippets_real(filename, snippets);
@@ -863,29 +855,29 @@ class Manager:
if len(systemsnippets) != 0 and show_dialogs:
# Ask if system snippets should also be exported
message = _('Do you want to include selected <b>system</b> snippets in your export?')
- mes = gtk.MessageDialog(flags=gtk.DIALOG_MODAL,
- type=gtk.MESSAGE_QUESTION,
- buttons=gtk.BUTTONS_YES_NO,
+ mes = Gtk.MessageDialog(flags=Gtk.DialogFlags.MODAL,
+ type=Gtk.MessageType.QUESTION,
+ buttons=Gtk.ButtonsType.YES_NO,
message_format=message)
mes.set_property('use-markup', True)
resp = mes.run()
mes.destroy()
- if resp == gtk.RESPONSE_NO:
+ if resp == Gtk.ResponseType.NO:
export_snippets = usersnippets
- elif resp != gtk.RESPONSE_YES:
+ elif resp != Gtk.ResponseType.YES:
return False
if len(export_snippets) == 0 and show_dialogs:
message = _('There are no snippets selected to be exported')
- message_dialog(self.dlg, gtk.MESSAGE_INFO, message)
+ message_dialog(self.dlg, Gtk.MessageType.INFO, message)
return False
if not filename:
- dlg = gtk.FileChooserDialog(parent=self.dlg, title=_('Export snippets'),
- action=gtk.FILE_CHOOSER_ACTION_SAVE,
- buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
- gtk.STOCK_SAVE, gtk.RESPONSE_OK))
+ dlg = Gtk.FileChooserDialog(parent=self.dlg, title=_('Export snippets'),
+ action=Gtk.FileChooserAction.SAVE,
+ buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
dlg._export_snippets = export_snippets
dlg.add_filter(self.file_filter(_('All supported archives'), ('*.gz','*.bz2','*.tar')))
@@ -920,27 +912,27 @@ class Manager:
else:
systemsnippets.append(snippet)
- dlg = gtk.FileChooserDialog(parent=self.dlg, title=_('Export snippets'),
- action=gtk.FILE_CHOOSER_ACTION_SAVE,
- buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
- gtk.STOCK_SAVE, gtk.RESPONSE_OK))
+ dlg = Gtk.FileChooserDialog(parent=self.dlg, title=_('Export snippets'),
+ action=Gtk.FileChooserAction.SAVE,
+ buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
dlg._export_snippets = snippets
if len(systemsnippets) != 0:
# Ask if system snippets should also be exported
message = _('Do you want to include selected <b>system</b> snippets in your export?')
- mes = gtk.MessageDialog(flags=gtk.DIALOG_MODAL,
- type=gtk.MESSAGE_QUESTION,
- buttons=gtk.BUTTONS_YES_NO,
+ mes = Gtk.MessageDialog(flags=Gtk.DialogFlags.MODAL,
+ type=Gtk.MessageType.QUESTION,
+ buttons=Gtk.ButtonsType.YES_NO,
message_format=message)
mes.set_property('use-markup', True)
resp = mes.run()
mes.destroy()
- if resp == gtk.RESPONSE_NO:
+ if resp == Gtk.ResponseType.NO:
dlg._export_snippets = usersnippets
- elif resp != gtk.RESPONSE_YES:
+ elif resp != Gtk.ResponseType.YES:
dlg.destroy()
return
@@ -948,7 +940,7 @@ class Manager:
dlg.destroy()
message = _('There are no snippets selected to be exported')
- message_dialog(self.dlg, gtk.MESSAGE_INFO, message)
+ message_dialog(self.dlg, Gtk.MessageType.INFO, message)
return
dlg.add_filter(self.file_filter(_('All supported archives'), ('*.gz','*.bz2','*.tar')))
@@ -975,11 +967,12 @@ class Manager:
parent = self.model.iter_parent(piter)
Library().remove_snippet(node)
+ idx = path.get_indices()
if self.model.remove(piter):
return piter
- elif path[-1] != 0:
- self.select_iter(self.model.get_iter((path[0], path[1] - 1)))
+ elif idx[-1] != 0:
+ self.select_iter(self.model.get_iter((idx[0], idx[1] - 1)))
else:
dummy = self.add_new_snippet_node(parent)
self.tree_view.expand_row(self.model.get_path(parent), False)
@@ -1004,7 +997,7 @@ class Manager:
# Create tree row references
references = []
for path in paths:
- references.append(gtk.TreeRowReference(self.model, path))
+ references.append(Gtk.TreeRowReference(self.model, path))
# Remove/revert snippets
select = None
@@ -1023,7 +1016,7 @@ class Manager:
self.selection_changed()
def set_accelerator(self, keyval, mod):
- accelerator = gtk.accelerator_name(keyval, mod)
+ accelerator = Gtk.accelerator_name(keyval, mod)
self.snippet['accelerator'] = accelerator
return True
@@ -1031,14 +1024,14 @@ class Manager:
def on_entry_accelerator_key_press(self, entry, event):
source_view = self['source_view_snippet']
- if event.keyval == gdk.keyval_from_name('Escape'):
+ if event.keyval == Gdk.keyval_from_name('Escape'):
# Reset
entry.set_text(self.snippet.accelerator_display())
self.tree_view.grab_focus()
return True
- elif event.keyval == gdk.keyval_from_name('Delete') or \
- event.keyval == gdk.keyval_from_name('BackSpace'):
+ elif event.keyval == Gdk.keyval_from_name('Delete') or \
+ event.keyval == Gdk.keyval_from_name('BackSpace'):
# Remove the accelerator
entry.set_text('')
self.snippet['accelerator'] = ''
@@ -1049,7 +1042,7 @@ class Manager:
elif Library().valid_accelerator(event.keyval, event.state):
# New accelerator
self.set_accelerator(event.keyval, \
- event.state & gtk.accelerator_get_default_mod_mask())
+ event.state & Gtk.accelerator_get_default_mod_mask())
entry.set_text(self.snippet.accelerator_display())
self.snippet_changed()
self.tree_view.grab_focus()
@@ -1092,7 +1085,7 @@ class Manager:
None)
self.on_source_view_snippet_focus_out(self['source_view_snippet'],
None)
- self.on_entry_drop_targets_focus_out(self['combo_drop_targets'].child,
+ self.on_entry_drop_targets_focus_out(self['combo_drop_targets'].get_child(),
None)
self.update_language_path()
@@ -1117,7 +1110,7 @@ class Manager:
return False
def on_tree_view_snippets_key_press(self, treeview, event):
- if event.keyval == gdk.keyval_from_name('Delete'):
+ if event.keyval == Gdk.keyval_from_name('Delete'):
self.on_button_remove_snippet_clicked(None)
return True
@@ -1127,9 +1120,6 @@ class Manager:
self.select_iter(piter)
def on_entry_drop_targets_drag_data_received(self, entry, context, x, y, selection_data, info, timestamp):
- if not gtk.targets_include_uri(context.targets):
- return
-
uris = drop_get_uris(selection_data)
if not uris:
@@ -1142,7 +1132,7 @@ class Manager:
for uri in uris:
try:
- mime = gio.content_type_guess(uri)
+ mime = Gio.content_type_guess(uri)
except:
mime = None
diff --git a/plugins/snippets/snippets/Placeholder.py b/plugins/snippets/snippets/Placeholder.py
index 45b5b508..5fa6e559 100755
--- a/plugins/snippets/snippets/Placeholder.py
+++ b/plugins/snippets/snippets/Placeholder.py
@@ -20,12 +20,11 @@ import re
import os
import sys
import signal
-import select
import locale
import subprocess
-from SubstitutionParser import SubstitutionParser
-import gobject
+from gi.repository import GObject, GLib, Gtk
+from SubstitutionParser import SubstitutionParser
from Helper import *
# These are places in a view where the cursor can go and do things
@@ -138,7 +137,7 @@ class Placeholder:
eiter = self.end_iter()
if biter and eiter:
- return self.buf.get_text(self.begin_iter(), self.end_iter())
+ return self.buf.get_text(self.begin_iter(), self.end_iter(), False)
else:
return ''
else:
@@ -323,12 +322,12 @@ class PlaceholderExpand(Placeholder):
def remove_timeout(self):
if self.timeout_id != None:
- gobject.source_remove(self.timeout_id)
+ GLib.source_remove(self.timeout_id)
self.timeout_id = None
def install_timeout(self):
self.remove_timeout()
- self.timeout_id = gobject.timeout_add(1000, self.timeout_cb)
+ self.timeout_id = GLib.timeout_add(1000, self.timeout_cb)
def timeout_cb(self):
self.timeout_id = None
@@ -398,13 +397,13 @@ class PlaceholderShell(PlaceholderExpand):
if not self.shell:
return False
- gobject.source_remove(self.watch_id)
+ GLib.source_remove(self.watch_id)
self.close_shell()
if self.remove_me:
PlaceholderExpand.remove(self)
- message_dialog(None, gtk.MESSAGE_ERROR, 'Execution of the shell ' \
+ message_dialog(None, Gtk.MessageType.ERROR, 'Execution of the shell ' \
'command (%s) exceeded the maximum time; ' \
'execution aborted.' % self.command)
@@ -424,7 +423,7 @@ class PlaceholderShell(PlaceholderExpand):
PlaceholderExpand.remove(self, True)
def process_cb(self, source, condition):
- if condition & gobject.IO_IN:
+ if condition & GObject.IO_IN:
line = source.readline()
if len(line) > 0:
@@ -452,7 +451,7 @@ class PlaceholderShell(PlaceholderExpand):
self.remove_timeout()
if self.shell:
- gobject.source_remove(self.watch_id)
+ GLib.source_remove(self.watch_id)
self.close_shell()
popen_args = {
@@ -465,8 +464,8 @@ class PlaceholderShell(PlaceholderExpand):
self.command = text
self.shell = subprocess.Popen(text, **popen_args)
self.shell_output = ''
- self.watch_id = gobject.io_add_watch(self.shell.stdout, gobject.IO_IN | \
- gobject.IO_HUP, self.process_cb)
+ self.watch_id = GLib.io_add_watch(self.shell.stdout, GObject.IO_IN | \
+ GObject.IO_HUP, self.process_cb)
self.install_timeout()
return True
@@ -590,7 +589,7 @@ class PlaceholderEval(PlaceholderExpand):
except TimeoutError:
self.remove_timeout()
- message_dialog(None, gtk.MESSAGE_ERROR, \
+ message_dialog(None, Gtk.MessageType.ERROR, \
_('Execution of the Python command (%s) exceeds the maximum ' \
'time, execution aborted.') % self.command)
@@ -598,7 +597,7 @@ class PlaceholderEval(PlaceholderExpand):
except Exception, detail:
self.remove_timeout()
- message_dialog(None, gtk.MESSAGE_ERROR,
+ message_dialog(None, Gtk.MessageType.ERROR,
_('Execution of the Python command (%s) failed: %s') %
(self.command, detail))
diff --git a/plugins/snippets/snippets/Snippet.py b/plugins/snippets/snippets/Snippet.py
index ae81fcfc..2d7f67de 100755
--- a/plugins/snippets/snippets/Snippet.py
+++ b/plugins/snippets/snippets/Snippet.py
@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
-import gio
+from gi.repository import Gio, Gtk
from Placeholder import *
from Parser import Parser, Token
@@ -42,12 +42,12 @@ class EvalUtilities:
return len(s.expandtabs(tablen))
def _filename_to_uri(self, filename):
- gfile = gio.File(filename)
+ gfile = Gio.file_new_for_path(filename)
return gfile.get_uri()
def util_readfile(self, filename):
- stream = gio.File(filename).read()
+ stream = Gio.file_new_for_path(filename).read()
if not stream:
return ''
@@ -58,8 +58,8 @@ class EvalUtilities:
return res
def util_filesize(self, filename):
- gfile = gio.File(filename)
- info = gfile.query_info(gio.FILE_ATTRIBUTE_STANDARD_SIZE)
+ gfile = Gio.file_new_for_path(filename)
+ info = gfile.query_info(Gio.FILE_ATTRIBUTE_STANDARD_SIZE)
if not info:
return 0
@@ -111,8 +111,8 @@ class Snippet:
accel = self['accelerator']
if accel:
- keyval, mod = gtk.accelerator_parse(accel)
- accel = gtk.accelerator_get_label(keyval, mod)
+ keyval, mod = Gtk.accelerator_parse(accel)
+ accel = Gtk.accelerator_get_label(keyval, mod)
return accel or ''
diff --git a/plugins/snippets/snippets/WindowHelper.py b/plugins/snippets/snippets/WindowHelper.py
index 72e0a991..3b08d12f 100755
--- a/plugins/snippets/snippets/WindowHelper.py
+++ b/plugins/snippets/snippets/WindowHelper.py
@@ -19,9 +19,7 @@ import re
import os
import gettext
-import gtk
-from gtk import gdk
-import pluma
+from gi.repository import GObject, Gtk, Pluma
from Document import Document
from Library import Library
@@ -45,7 +43,7 @@ class WindowHelper:
# Add controllers to all the current views
for view in self.window.get_views():
- if isinstance(view, pluma.View) and not self.has_controller(view):
+ if isinstance(view, Pluma.View) and not self.has_controller(view):
view._snippet_controller = Document(self, view)
self.update()
@@ -54,12 +52,11 @@ class WindowHelper:
self.window.remove_accel_group(self.accel_group)
self.accel_group = None
- #self.window.remove_accel_group(accel)
self.remove_menu()
# Iterate over all the tabs and remove every controller
for view in self.window.get_views():
- if isinstance(view, pluma.View) and self.has_controller(view):
+ if isinstance(view, Pluma.View) and self.has_controller(view):
view._snippet_controller.stop()
view._snippet_controller = None
@@ -69,7 +66,7 @@ class WindowHelper:
def insert_menu(self):
manager = self.window.get_ui_manager()
- self.action_group = gtk.ActionGroup("PlumaSnippetPluginActions")
+ self.action_group = Gtk.ActionGroup("PlumaSnippetPluginActions")
self.action_group.set_translation_domain('pluma')
self.action_group.add_actions([('ManageSnippets', None,
_('Manage _Snippets...'), \
@@ -79,7 +76,7 @@ class WindowHelper:
self.merge_id = manager.new_merge_id()
manager.insert_action_group(self.action_group, -1)
manager.add_ui(self.merge_id, '/MenuBar/ToolsMenu/ToolsOps_5', \
- 'ManageSnippets', 'ManageSnippets', gtk.UI_MANAGER_MENUITEM, False)
+ 'ManageSnippets', 'ManageSnippets', Gtk.UIManagerItemType.MENUITEM, False)
def remove_menu(self):
manager = self.window.get_ui_manager()
@@ -140,7 +137,7 @@ class WindowHelper:
# Create a new controller for this tab if it has a standard pluma view
view = tab.get_view()
- if isinstance(view, pluma.View) and not self.has_controller(view):
+ if isinstance(view, Pluma.View) and not self.has_controller(view):
view._snippet_controller = Document(self, view)
self.update()
diff --git a/plugins/snippets/snippets/__init__.py b/plugins/snippets/snippets/__init__.py
index 4b8db4b9..2be0fc20 100755
--- a/plugins/snippets/snippets/__init__.py
+++ b/plugins/snippets/snippets/__init__.py
@@ -15,30 +15,22 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import sys
import os
-import shutil
-
-import gtk
-from gtk import gdk
-import pluma
+from gi.repository import GObject, GLib, Gtk, Peas, Pluma
from WindowHelper import WindowHelper
from Library import Library
from Manager import Manager
-from Snippet import Snippet
-class SnippetsPlugin(pluma.Plugin):
- def __init__(self):
- pluma.Plugin.__init__(self)
+class SnippetsPlugin(GObject.Object, Peas.Activatable):
+ __gtype_name__ = "SnippetsPlugin"
- self.dlg = None
+ object = GObject.Property(type=GObject.Object)
- library = Library()
- library.set_accelerator_callback(self.accelerator_activated)
+ def __init__(self):
+ GObject.Object.__init__(self)
- snippetsdir = os.path.expanduser('~/.config/pluma/snippets')
- library.set_dirs(snippetsdir, self.system_dirs())
+ self.dlg = None
def system_dirs(self):
if 'XDG_DATA_DIRS' in os.environ:
@@ -54,28 +46,38 @@ class SnippetsPlugin(pluma.Plugin):
if os.path.isdir(d):
dirs.append(d)
- dirs.append(self.get_data_dir())
+ dirs.append(self.plugin_info.get_data_dir())
return dirs
- def activate(self, window):
- data = WindowHelper(self)
- window._snippets_plugin_data = data
- data.run(window)
+ def do_activate(self):
+ library = Library()
+ library.add_accelerator_callback(self.accelerator_activated)
+
+ snippetsdir = os.path.join(GLib.get_user_config_dir(), '/pluma/snippets')
+ library.set_dirs(snippetsdir, self.system_dirs())
+
+ self._helper = WindowHelper(self)
+
+ window = self.object
+ self._helper.run(window)
+
+ def do_deactivate(self):
+ library = Library()
+ library.remove_accelerator_callback(self.accelerator_activated)
- def deactivate(self, window):
- window._snippets_plugin_data.stop()
- window._snippets_plugin_data = None
+ self._helper.stop()
+ self._helper = None
- def update_ui(self, window):
- window._snippets_plugin_data.update()
+ def do_update_state(self):
+ self._helper.update()
def create_configure_dialog(self):
if not self.dlg:
- self.dlg = Manager(self.get_data_dir())
+ self.dlg = Manager(self.plugin_info.get_data_dir())
else:
self.dlg.run()
- window = pluma.app_get_default().get_active_window()
+ window = Pluma.App.get_default().get_active_window()
if window:
self.dlg.dlg.set_transient_for(window)
@@ -85,7 +87,7 @@ class SnippetsPlugin(pluma.Plugin):
def accelerator_activated(self, group, obj, keyval, mod):
ret = False
- if hasattr(obj, '_snippets_plugin_data'):
- ret = obj._snippets_plugin_data.accelerator_activated(keyval, mod)
+ if _self.helper:
+ ret = self._helper.accelerator_activated(keyval, mod)
return ret
diff --git a/plugins/snippets/snippets/snippets.ui b/plugins/snippets/snippets/snippets.ui
index b8ddc955..6fcaf854 100644
--- a/plugins/snippets/snippets/snippets.ui
+++ b/plugins/snippets/snippets/snippets.ui
@@ -580,10 +580,11 @@
</packing>
</child>
<child>
- <object class="GtkComboBoxEntry" id="combo_drop_targets">
+ <object class="GtkComboBox" id="combo_drop_targets">
<property name="visible">True</property>
<property name="add_tearoffs">False</property>
<property name="has_frame">True</property>
+ <property name="has_entry">True</property>
<property name="focus_on_click">True</property>
<property name="model">model1</property>
<child>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6a7df05d..09e8c814 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -76,6 +76,14 @@ plugins/pythonconsole/pythonconsole/__init__.py
plugins/quickopen/quickopen/popup.py
plugins/quickopen/quickopen/windowhelper.py
plugins/quickopen/quickopen.plugin.desktop.in
+plugins/snippets/snippets.plugin.desktop.in
+[type: gettext/glade]plugins/snippets/snippets/snippets.ui
+plugins/snippets/snippets/Document.py
+plugins/snippets/snippets/WindowHelper.py
+plugins/snippets/snippets/Manager.py
+plugins/snippets/snippets/Exporter.py
+plugins/snippets/snippets/Importer.py
+plugins/snippets/snippets/Placeholder.py
plugins/sort/pluma-sort-plugin.c
plugins/sort/sort.plugin.desktop.in
[type: gettext/glade]plugins/sort/sort.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index c0a846f8..0a9cbf7e 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,14 +1,6 @@
# List of source files that should *not* be translated.
# Please keep this file sorted alphabetically.
data/pluma.desktop.in
-plugins/snippets/snippets.pluma-plugin.desktop.in
-[type: gettext/glade]plugins/snippets/snippets/snippets.ui
-plugins/snippets/snippets/Document.py
-plugins/snippets/snippets/WindowHelper.py
-plugins/snippets/snippets/Manager.py
-plugins/snippets/snippets/Exporter.py
-plugins/snippets/snippets/Importer.py
-plugins/snippets/snippets/Placeholder.py
pluma/pluma-document-output-stream.c
pluma/smclient/eggdesktopfile.c
pluma/smclient/eggsmclient.c