diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 4 | ||||
-rw-r--r-- | plugins/quickopen/Makefile.am | 6 | ||||
-rw-r--r-- | plugins/quickopen/quickopen.plugin.desktop.in (renamed from plugins/quickopen/quickopen.pluma-plugin.desktop.in) | 2 | ||||
-rwxr-xr-x | plugins/quickopen/quickopen/__init__.py | 26 | ||||
-rwxr-xr-x | plugins/quickopen/quickopen/popup.py | 156 | ||||
-rwxr-xr-x | plugins/quickopen/quickopen/virtualdirs.py | 22 | ||||
-rwxr-xr-x | plugins/quickopen/quickopen/windowhelper.py | 34 |
7 files changed, 134 insertions, 116 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 03fa0d08..c4f95ea8 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -5,6 +5,7 @@ DIST_SUBDIRS = \ filebrowser \ modelines \ pythonconsole \ + quickopen \ sort \ spell \ taglist \ @@ -18,13 +19,14 @@ SUBDIRS = \ filebrowser \ modelines \ pythonconsole \ + quickopen \ sort \ taglist \ time \ trailsave # python plugins are disabled for now -#SUBDIRS += snippets quickopen +#SUBDIRS += snippets if ENABLE_ENCHANT SUBDIRS += spell diff --git a/plugins/quickopen/Makefile.am b/plugins/quickopen/Makefile.am index 74cc89a0..4e5f8d85 100644 --- a/plugins/quickopen/Makefile.am +++ b/plugins/quickopen/Makefile.am @@ -2,10 +2,10 @@ SUBDIRS = quickopen plugindir = $(PLUMA_PLUGINS_LIBS_DIR) -plugin_in_files = quickopen.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 = quickopen.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/quickopen/quickopen.pluma-plugin.desktop.in b/plugins/quickopen/quickopen.plugin.desktop.in index 0dcc3704..891a0c3f 100644 --- a/plugins/quickopen/quickopen.pluma-plugin.desktop.in +++ b/plugins/quickopen/quickopen.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Loader=python Module=quickopen IAge=2 diff --git a/plugins/quickopen/quickopen/__init__.py b/plugins/quickopen/quickopen/__init__.py index 1a617d93..54e95984 100755 --- a/plugins/quickopen/quickopen/__init__.py +++ b/plugins/quickopen/quickopen/__init__.py @@ -17,25 +17,29 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301, USA. -import pluma +from gi.repository import GObject, Peas from windowhelper import WindowHelper -class QuickOpenPlugin(pluma.Plugin): +class QuickOpenPlugin(GObject.Object, Peas.Activatable): + __gtype_name__ = "QuickOpenPlugin" + + object = GObject.Property(type=GObject.Object) + def __init__(self): - pluma.Plugin.__init__(self) + GObject.Object.__init__(self) self._popup_size = (450, 300) - self._helpers = {} - def activate(self, window): - self._helpers[window] = WindowHelper(window, self) + def do_activate(self): + window = self.object + self._helper = WindowHelper(window, self) - def deactivate(self, window): - self._helpers[window].deactivate() - del self._helpers[window] + def do_deactivate(self): + self._helper.deactivate() + self._helper = None - def update_ui(self, window): - self._helpers[window].update_ui() + def do_update_state(self): + self._helper.update_ui() def get_popup_size(self): return self._popup_size diff --git a/plugins/quickopen/quickopen/popup.py b/plugins/quickopen/quickopen/popup.py index edd9ab08..b571b68b 100755 --- a/plugins/quickopen/quickopen/popup.py +++ b/plugins/quickopen/quickopen/popup.py @@ -17,39 +17,38 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301, USA. -import gtk -import gtk.gdk -import gobject import os -import gio -import pango -import glib import fnmatch -import pluma import xml.sax.saxutils +from gi.repository import GObject, Gio, GLib, Gdk, Gtk, Pango, Pluma from virtualdirs import VirtualDirectory -class Popup(gtk.Dialog): +class Popup(Gtk.Dialog): + __gtype_name__ = "QuickOpenPopup" + def __init__(self, window, paths, handler): - gtk.Dialog.__init__(self, + Gtk.Dialog.__init__(self, title=_('Quick Open'), parent=window, - flags=gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR | gtk.DIALOG_MODAL) + flags=Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, + buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) - self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) - self._open_button = self.add_button(gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT) + self._open_button = self.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT) self._handler = handler self._build_ui() + self._size = (0, 0) self._dirs = [] self._cache = {} self._theme = None self._cursor = None self._shift_start = None - accel_group = gtk.AccelGroup() - accel_group.connect_group(gtk.keysyms.l, gtk.gdk.CONTROL_MASK, 0, self.on_focus_entry) + self._busy_cursor = Gdk.Cursor(Gdk.CursorType.WATCH) + + accel_group = Gtk.AccelGroup() + accel_group.connect(Gdk.KEY_l, Gdk.ModifierType.CONTROL_MASK, 0, self.on_focus_entry) self.add_accel_group(accel_group) @@ -60,52 +59,55 @@ class Popup(gtk.Dialog): self._dirs.append(path) unique.append(path.get_uri()) + def get_final_size(self): + return self._size + def _build_ui(self): vbox = self.get_content_area() vbox.set_spacing(3) - self._entry = gtk.Entry() + self._entry = Gtk.Entry() self._entry.connect('changed', self.on_changed) self._entry.connect('key-press-event', self.on_key_press_event) - sw = gtk.ScrolledWindow(None, None) - sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - sw.set_shadow_type(gtk.SHADOW_OUT) + sw = Gtk.ScrolledWindow() + sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + sw.set_shadow_type(Gtk.ShadowType.OUT) - tv = gtk.TreeView() + tv = Gtk.TreeView() tv.set_headers_visible(False) - self._store = gtk.ListStore(gio.Icon, str, object, int) + self._store = Gtk.ListStore(Gio.Icon, str, GObject.Object, Gio.FileType) tv.set_model(self._store) self._treeview = tv tv.connect('row-activated', self.on_row_activated) - renderer = gtk.CellRendererPixbuf() - column = gtk.TreeViewColumn() + renderer = Gtk.CellRendererPixbuf() + column = Gtk.TreeViewColumn() column.pack_start(renderer, False) - column.set_attributes(renderer, gicon=0) + column.add_attribute(renderer, "gicon", 0) - renderer = gtk.CellRendererText() + renderer = Gtk.CellRendererText() column.pack_start(renderer, True) - column.set_attributes(renderer, markup=1) + column.add_attribute(renderer, "markup", 1) - column.set_cell_data_func(renderer, self.on_cell_data_cb) + column.set_cell_data_func(renderer, self.on_cell_data_cb, None) tv.append_column(column) sw.add(tv) selection = tv.get_selection() selection.connect('changed', self.on_selection_changed) - selection.set_mode(gtk.SELECTION_MULTIPLE) + selection.set_mode(Gtk.SelectionMode.MULTIPLE) vbox.pack_start(self._entry, False, False, 0) vbox.pack_start(sw, True, True, 0) - lbl = gtk.Label() + lbl = Gtk.Label() lbl.set_alignment(0, 0.5) - lbl.set_ellipsize(pango.ELLIPSIZE_MIDDLE) + lbl.set_ellipsize(Pango.EllipsizeMode.MIDDLE) self._info_label = lbl vbox.pack_start(lbl, False, False, 0) @@ -114,23 +116,23 @@ class Popup(gtk.Dialog): self.on_selection_changed(tv.get_selection()) vbox.show_all() - def on_cell_data_cb(self, column, cell, model, piter): + def on_cell_data_cb(self, column, cell, model, piter, user_data): path = model.get_path(piter) if self._cursor and path == self._cursor.get_path(): style = self._treeview.get_style() - bg = style.bg[gtk.STATE_PRELIGHT] + bg = style.bg[Gtk.StateType.PRELIGHT] cell.set_property('cell-background-gdk', bg) - cell.set_property('style', pango.STYLE_ITALIC) + cell.set_property('style', Pango.Style.ITALIC) else: cell.set_property('cell-background-set', False) cell.set_property('style-set', False) def _icon_from_stock(self, stock): - theme = gtk.icon_theme_get_default() - size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) - pixbuf = theme.load_icon(stock, size[0], gtk.ICON_LOOKUP_USE_BUILTIN) + theme = Gtk.icon_theme_get_default() + size = Gtk.icon_size_lookup(Gtk.IconSize.MENU) + pixbuf = theme.load_icon(stock, size[0], Gtk.IconLookupFlags.USE_BUILTIN) return pixbuf @@ -138,19 +140,25 @@ class Popup(gtk.Dialog): entries = [] try: - entries = gfile.enumerate_children("standard::*") - except glib.GError: + ret = gfile.enumerate_children("standard::*", Gio.FileQueryInfoFlags.NONE, None) + except GLib.GError: pass + if isinstance(ret, Gio.FileEnumerator): + while True: + entry = ret.next_file(None) + + if not entry: + break + + entries.append((gfile.get_child(entry.get_name()), entry)) + else: + entries = ret + children = [] for entry in entries: - if isinstance(gfile, VirtualDirectory): - child, entry = entry - else: - child = gfile.get_child(entry.get_name()) - - children.append((child, entry.get_name(), entry.get_file_type(), entry.get_icon())) + children.append((entry[0], entry[1].get_name(), entry[1].get_file_type(), entry[1].get_icon())) return children @@ -195,12 +203,12 @@ class Popup(gtk.Dialog): lentry = entry[1].lower() if not lpart or lpart in lentry or self._match_glob(lentry, lpart): - if entry[2] == gio.FILE_TYPE_DIRECTORY: + if entry[2] == Gio.FileType.DIRECTORY: if len(parts) > 1: newdirs.append(entry[0]) else: found.append(entry) - elif entry[2] == gio.FILE_TYPE_REGULAR and \ + elif entry[2] == Gio.FileType.REGULAR and \ (not lpart or len(parts) == 1): found.append(entry) @@ -244,7 +252,7 @@ class Popup(gtk.Dialog): return os.sep.join(out) def _get_icon(self, f): - query = f.query_info(gio.FILE_ATTRIBUTE_STANDARD_ICON) + query = f.query_info(Gio.FILE_ATTRIBUTE_STANDARD_ICON, Gio.FileQueryInfoFlags.NONE, None) if not query: return None @@ -296,9 +304,17 @@ class Popup(gtk.Dialog): def _show_virtuals(self): for d in self._dirs: if isinstance(d, VirtualDirectory): - for entry in d.enumerate_children("standard::*"): + for entry in d.enumerate_children("standard::*", 0, None): self._append_to_store((entry[1].get_icon(), xml.sax.saxutils.escape(entry[1].get_name()), entry[0], entry[1].get_file_type())) + def _set_busy(self, busy): + if busy: + self.get_window().set_cursor(self._busy_cursor) + else: + self.get_window().set_cursor(None) + + Gdk.flush() + def _remove_cursor(self): if self._cursor: path = self._cursor.get_path() @@ -307,7 +323,7 @@ class Popup(gtk.Dialog): self._store.row_changed(path, self._store.get_iter(path)) def do_search(self): - self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) + self._set_busy(True) self._remove_cursor() text = self._entry.get_text().strip() @@ -329,10 +345,11 @@ class Popup(gtk.Dialog): if piter: self._treeview.get_selection().select_path(self._store.get_path(piter)) - self.window.set_cursor(None) + self.get_window().set_cursor(None) + self._set_busy(False) def do_show(self): - gtk.Window.do_show(self) + Gtk.Window.do_show(self) self._entry.grab_focus() self._entry.set_text("") @@ -350,7 +367,7 @@ class Popup(gtk.Dialog): model, rows = selection.get_selected_rows() start = rows[0] - self._shift_start = gtk.TreeRowReference(self._store, start) + self._shift_start = Gtk.TreeRowReference(self._store, start) else: start = self._shift_start.get_path() @@ -375,7 +392,7 @@ class Popup(gtk.Dialog): self._remove_cursor() if hasctrl or hasshift: - self._cursor = gtk.TreeRowReference(self._store, path) + self._cursor = Gtk.TreeRowReference(self._store, path) piter = self._store.get_iter(path) self._store.row_changed(path, piter) @@ -418,10 +435,10 @@ class Popup(gtk.Dialog): uri = self._entry.get_text() gfile = None - if pluma.utils.uri_is_valid(uri): - gfile = gio.File(uri) + if Pluma.utils_is_valid_uri(uri): + gfile = Gio.file_new_for_uri(uri) elif os.path.isabs(uri): - f = gio.File(uri) + f = Gio.file_new_for_uri(uri) if f.query_exists(): gfile = f @@ -436,7 +453,7 @@ class Popup(gtk.Dialog): s = model.get_iter(row) info = model.get(s, 2, 3) - if info[1] != gio.FILE_TYPE_DIRECTORY: + if info[1] != Gio.FileType.DIRECTORY: ret = ret and self._handler(info[0]) else: text = self._entry.get_text() @@ -479,20 +496,20 @@ class Popup(gtk.Dialog): def on_key_press_event(self, widget, event): move_mapping = { - gtk.keysyms.Down: 1, - gtk.keysyms.Up: -1, - gtk.keysyms.Page_Down: 5, - gtk.keysyms.Page_Up: -5 + Gdk.KEY_Down: 1, + Gdk.KEY_Up: -1, + Gdk.KEY_Page_Down: 5, + Gdk.KEY_Page_Up: -5 } - if event.keyval == gtk.keysyms.Escape: + if event.keyval == Gdk.KEY_Escape: self.destroy() return True elif event.keyval in move_mapping: - return self._move_selection(move_mapping[event.keyval], event.state & gtk.gdk.CONTROL_MASK, event.state & gtk.gdk.SHIFT_MASK) - elif event.keyval in [gtk.keysyms.Return, gtk.keysyms.KP_Enter, gtk.keysyms.Tab, gtk.keysyms.ISO_Left_Tab]: + return self._move_selection(move_mapping[event.keyval], event.state & Gdk.ModifierType.CONTROL_MASK, event.state & Gdk.ModifierType.SHIFT_MASK) + elif event.keyval in [Gdk.KEY_Return, Gdk.KEY_KP_Enter, Gdk.KEY_Tab, Gdk.KEY_ISO_Left_Tab]: return self._activate() - elif event.keyval == gtk.keysyms.space and event.state & gtk.gdk.CONTROL_MASK: + elif event.keyval == Gdk.KEY_space and event.state & Gdk.ModifierType.CONTROL_MASK: self.toggle_cursor() return False @@ -501,9 +518,16 @@ class Popup(gtk.Dialog): self._activate() def do_response(self, response): - if response != gtk.RESPONSE_ACCEPT or not self._activate(): + if response != Gtk.ResponseType.ACCEPT or not self._activate(): self.destroy() + def do_configure_event(self, event): + if self.get_realized(): + alloc = self.get_allocation() + self._size = (alloc.width, alloc.height) + + return Gtk.Dialog.do_configure_event(self, event) + def on_selection_changed(self, selection): model, rows = selection.get_selected_rows() @@ -529,6 +553,4 @@ class Popup(gtk.Dialog): def on_focus_entry(self, group, accel, keyval, modifier): self._entry.grab_focus() -gobject.type_register(Popup) - # ex:ts=8:et: diff --git a/plugins/quickopen/quickopen/virtualdirs.py b/plugins/quickopen/quickopen/virtualdirs.py index 9fc1c796..a2d6985a 100755 --- a/plugins/quickopen/quickopen/virtualdirs.py +++ b/plugins/quickopen/quickopen/virtualdirs.py @@ -17,10 +17,9 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301, USA. -import gtk -import gio +from gi.repository import Gio, Gtk -class VirtualDirectory: +class VirtualDirectory(object): def __init__(self, name): self._name = name self._children = [] @@ -31,7 +30,7 @@ class VirtualDirectory: def get_parent(self): return None - def enumerate_children(self, attr): + def enumerate_children(self, attr, flags, callback): return self._children def append(self, child): @@ -39,7 +38,7 @@ class VirtualDirectory: return try: - info = child.query_info("standard::*") + info = child.query_info("standard::*", Gio.FileQueryInfoFlags.NONE, None) if info: self._children.append((child, info)) @@ -47,17 +46,14 @@ class VirtualDirectory: pass class RecentDocumentsDirectory(VirtualDirectory): - def __init__(self, maxitems=10, screen=None): + def __init__(self, maxitems=10): VirtualDirectory.__init__(self, 'recent') self._maxitems = maxitems - self.fill(screen) + self.fill() - def fill(self, screen): - if screen: - manager = gtk.recent_manager_get_for_screen(screen) - else: - manager = gtk.recent_manager_get_default() + def fill(self): + manager = Gtk.RecentManager.get_default() items = manager.get_items() items.sort(lambda a, b: cmp(b.get_visited(), a.get_visited())) @@ -66,7 +62,7 @@ class RecentDocumentsDirectory(VirtualDirectory): for item in items: if item.has_group('pluma'): - self.append(gio.File(item.get_uri())) + self.append(Gio.file_new_for_uri(item.get_uri())) added += 1 if added >= self._maxitems: diff --git a/plugins/quickopen/quickopen/windowhelper.py b/plugins/quickopen/quickopen/windowhelper.py index 57ec414f..c23629cf 100755 --- a/plugins/quickopen/quickopen/windowhelper.py +++ b/plugins/quickopen/quickopen/windowhelper.py @@ -17,13 +17,9 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301, USA. -import pluma -import gtk from popup import Popup import os -import pluma.commands -import gio -import glib +from gi.repository import Gio, GLib, Gtk, Pluma from virtualdirs import RecentDocumentsDirectory from virtualdirs import CurrentDocumentsDirectory @@ -64,9 +60,9 @@ class WindowHelper: def _install_menu(self): manager = self._window.get_ui_manager() - self._action_group = gtk.ActionGroup("PlumaQuickOpenPluginActions") + self._action_group = Gtk.ActionGroup("PlumaQuickOpenPluginActions") self._action_group.add_actions([ - ("QuickOpen", gtk.STOCK_OPEN, _("Quick open"), + ("QuickOpen", Gtk.STOCK_OPEN, _("Quick open"), '<Ctrl><Alt>O', _("Quickly open documents"), self.on_quick_open_activate) ]) @@ -97,7 +93,7 @@ class WindowHelper: uri = msg.get_value('uri') if uri: - gfile = gio.File(uri) + gfile = Gio.file_new_for_uri(uri) if gfile.is_native(): paths.append(gfile) @@ -106,7 +102,7 @@ class WindowHelper: pass # Recent documents - paths.append(RecentDocumentsDirectory(screen=self._window.get_screen())) + paths.append(RecentDocumentsDirectory()) # Local bookmarks for path in self._local_bookmarks(): @@ -116,16 +112,16 @@ class WindowHelper: desktopdir = self._desktop_dir() if desktopdir: - paths.append(gio.File(desktopdir)) + paths.append(Gio.file_new_for_path(desktopdir)) # Home directory - paths.append(gio.File(os.path.expanduser('~'))) + paths.append(Gio.file_new_for_path(os.path.expanduser('~'))) self._popup = Popup(self._window, paths, self.on_activated) self._popup.set_default_size(*self._plugin.get_popup_size()) self._popup.set_transient_for(self._window) - self._popup.set_position(gtk.WIN_POS_CENTER_ON_PARENT) + self._popup.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self._window.get_group().add_window(self._popup) @@ -141,15 +137,15 @@ class WindowHelper: for line in file(filename, 'r').xreadlines(): uri = line.strip().split(" ")[0] - f = gio.File(uri) + f = Gio.file_new_for_uri(uri) if f.is_native(): try: - info = f.query_info("standard::type") + info = f.query_info(Gio.FILE_ATTRIBUTE_STANDARD_TYPE, Gio.FileQueryInfoFlags.NONE, None) - if info and info.get_file_type() == gio.FILE_TYPE_DIRECTORY: + if info and info.get_file_type() == Gio.FileType.DIRECTORY: paths.append(f) - except glib.GError: + except GLib.GError: pass return paths @@ -185,13 +181,11 @@ class WindowHelper: self._popup.show() def on_popup_destroy(self, popup): - alloc = popup.get_allocation() - self._plugin.set_popup_size((alloc.width, alloc.height)) - + self._plugin.set_popup_size(popup.get_final_size()) self._popup = None def on_activated(self, gfile): - pluma.commands.load_uri(self._window, gfile.get_uri(), None, -1) + Pluma.commands_load_uri(self._window, gfile.get_uri(), None, -1) return True # ex:ts=8:et: |