[gedit-plugins] Port commander to libpeas/gtk3



commit 90e154a3eb7861def17f426f05057799f74530cb
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Wed Apr 6 00:21:22 2011 +0200

    Port commander to libpeas/gtk3
    
    https://bugzilla.gnome.org/show_bug.cgi?id=640075

 plugins/commander/commander/Makefile.am            |    3 +-
 plugins/commander/commander/__init__.py            |   37 ++--
 plugins/commander/commander/commands/__init__.py   |   22 +-
 .../commander/commander/commands/accel_group.py    |   16 +-
 plugins/commander/commander/commands/completion.py |    1 -
 .../commander/commands/rollbackimporter.py         |    2 -
 plugins/commander/commander/entry.py               |  267 ++++++++++----------
 plugins/commander/commander/info.py                |  182 +++++++-------
 plugins/commander/commander/modules.py             |    1 +
 plugins/commander/commander/transparentwindow.py   |   76 +++----
 .../{windowhelper.py => windowactivatable.py}      |   47 ++--
 plugins/commander/modules/bookmark.py              |    4 +
 plugins/commander/modules/doc.py                   |    6 +-
 plugins/commander/modules/edit.py                  |   27 +-
 plugins/commander/modules/find/__init__.py         |    8 +-
 plugins/commander/modules/find/finder.py           |    4 +-
 plugins/commander/modules/find/regex.py            |    1 -
 plugins/commander/modules/move.py                  |   14 +-
 plugins/commander/modules/set.py                   |   16 +-
 plugins/commander/modules/shell.py                 |    4 +-
 20 files changed, 358 insertions(+), 380 deletions(-)
---
diff --git a/plugins/commander/commander/Makefile.am b/plugins/commander/commander/Makefile.am
index c639a8a..9a0fe3f 100644
--- a/plugins/commander/commander/Makefile.am
+++ b/plugins/commander/commander/Makefile.am
@@ -9,8 +9,9 @@ plugin_PYTHON =	\
 	history.py \
 	info.py \
 	__init__.py \
+	modules.py \
 	transparentwindow.py \
 	utils.py \
-	windowhelper.py
+	windowactivatable.py
 
 -include $(top_srcdir)/git.mk
diff --git a/plugins/commander/commander/__init__.py b/plugins/commander/commander/__init__.py
index 90b89b4..07abd0f 100644
--- a/plugins/commander/commander/__init__.py
+++ b/plugins/commander/commander/__init__.py
@@ -27,37 +27,32 @@ path = os.path.dirname(__file__)
 if not path in sys.path:
 	sys.path.insert(0, path)
 
-import gedit
-from windowhelper import WindowHelper
+from windowactivatable import WindowActivatable
 import commander.commands as commands
+from gi.repository import GObject, Gedit
+import glib
+
+class CommanderPlugin(GObject.Object, Gedit.AppActivatable):
+	__gtype_name__ = "CommanderPlugin"
+
+	app = GObject.property(type=Gedit.App)
 
-class Commander(gedit.Plugin):
 	def __init__(self):
-		gedit.Plugin.__init__(self)
+		GObject.Object.__init__(self)
 
-		self._instances = {}
+	def do_activate(self):
 		self._path = os.path.dirname(__file__)
 
 		if not self._path in sys.path:
 			sys.path.insert(0, self._path)
 
 		commands.Commands().set_dirs([
-			os.path.expanduser('~/.gnome2/gedit/commander/modules'),
-			os.path.join(self.get_data_dir(), 'modules')
+			os.path.join(glib.get_user_config_dir(), 'gedit/commander/modules'),
+			os.path.join(self.plugin_info.get_data_dir(), 'modules')
 		])
 
-	def activate(self, window):
-		self._instances[window] = WindowHelper(self, window)
-
-	def deactivate(self, window):
-		self._instances[window].deactivate()
-		del self._instances[window]
-
-		if len(self._instances) == 0:
-			commands.Commands().stop()
-
-			if self._path in sys.path:
-				sys.path.remove(self._path)
+	def deactivate(self):
+		commands.Commands().stop()
 
-	def update_ui(self, window):
-		self._instances[window].update_ui()
+		if self._path in sys.path:
+			sys.path.remove(self._path)
diff --git a/plugins/commander/commander/commands/__init__.py b/plugins/commander/commander/commands/__init__.py
index f61458b..c933318 100644
--- a/plugins/commander/commander/commands/__init__.py
+++ b/plugins/commander/commander/commands/__init__.py
@@ -20,7 +20,7 @@
 #  Boston, MA 02111-1307, USA.
 
 import os
-import gio
+from gi.repository import GObject, Gio
 import sys
 import bisect
 import types
@@ -156,7 +156,7 @@ class Commands(Singleton):
 		self._modules = None
 
 		for k in self._timeouts:
-			glib.source_remove(self._timeouts[k])
+			GObject.source_remove(self._timeouts[k])
 
 		self._timeouts = {}
 
@@ -193,12 +193,12 @@ class Commands(Singleton):
 		return list(self._modules)
 
 	def add_monitor(self, d):
-		gfile = gio.File(d)
+		gfile = Gio.file_new_for_path(d)
 		monitor = None
 
 		try:
-			monitor = gfile.monitor_directory(gio.FILE_MONITOR_NONE, None)
-		except gio.Error, e:
+			monitor = gfile.monitor_directory(Gio.FileMonitorFlags.NONE, None)
+		except Gio.Error, e:
 			# Could not create monitor, this happens on systems where file monitoring is
 			# not supported, but we don't really care
 			pass
@@ -433,10 +433,10 @@ class Commands(Singleton):
 		return False
 
 	def on_monitor_changed(self, monitor, gfile1, gfile2, evnt):
-		if evnt == gio.FILE_MONITOR_EVENT_CHANGED:
+		if evnt == Gio.FileMonitorEvent.CHANGED:
 			# Reload the module
 			self.reload_module(gfile1.get_path())
-		elif evnt == gio.FILE_MONITOR_EVENT_DELETED:
+		elif evnt == Gio.FileMonitorEvent.DELETED:
 			path = gfile1.get_path()
 			mod = self.resolve_module(path, False)
 
@@ -444,17 +444,17 @@ class Commands(Singleton):
 				return
 
 			if path in self._timeouts:
-				glib.source_remove(self._timeouts[path])
+				GObject.source_remove(self._timeouts[path])
 
 			# We add a timeout because a common save strategy causes a
 			# DELETE/CREATE event chain
-			self._timeouts[path] = glib.timeout_add(500, self.on_timeout_delete, path, mod)
-		elif evnt == gio.FILE_MONITOR_EVENT_CREATED:
+			self._timeouts[path] = GObject.timeout_add(500, self.on_timeout_delete, path, mod)
+		elif evnt == Gio.FileMonitorEvent.CREATED:
 			path = gfile1.get_path()
 
 			# Check if this CREATE followed a previous DELETE
 			if path in self._timeouts:
-				glib.source_remove(self._timeouts[path])
+				GObject.source_remove(self._timeouts[path])
 				del self._timeouts[path]
 
 			# Reload the module
diff --git a/plugins/commander/commander/commands/accel_group.py b/plugins/commander/commander/commands/accel_group.py
index 326f1ae..a02137d 100644
--- a/plugins/commander/commander/commands/accel_group.py
+++ b/plugins/commander/commander/commands/accel_group.py
@@ -19,7 +19,7 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330,
 #  Boston, MA 02111-1307, USA.
 
-import gtk
+from gi.repository import Gtk
 
 class Accelerator:
 	def __init__(self, accelerators, arguments={}):
@@ -49,12 +49,12 @@ class AccelGroup:
 		mapping = self.accelerators
 
 		for i in range(num):
-			parsed = gtk.accelerator_parse(accel.accelerators[i])
+			parsed = Gtk.accelerator_parse(accel.accelerators[i])
 
-			if not gtk.accelerator_valid(*parsed):
+			if not Gtk.accelerator_valid(*parsed):
 				return
 
-			named = gtk.accelerator_name(*parsed)
+			named = Gtk.accelerator_name(*parsed)
 			inmap = named in mapping
 
 			if i == num - 1 and inmap:
@@ -76,12 +76,12 @@ class AccelGroup:
 		if not accels:
 			return
 
-		parsed = gtk.accelerator_parse(accels[0])
+		parsed = Gtk.accelerator_parse(accels[0])
 
-		if not gtk.accelerator_valid(*parsed):
+		if not Gtk.accelerator_valid(*parsed):
 			return
 
-		named = gtk.accelerator_name(*parsed)
+		named = Gtk.accelerator_name(*parsed)
 
 		if not named in accelerators:
 			return
@@ -98,7 +98,7 @@ class AccelGroup:
 		self.remove_real(self.accelerators, accel.accelerators)
 
 	def activate(self, key, mod):
-		named = gtk.accelerator_name(key, mod)
+		named = Gtk.accelerator_name(key, mod)
 
 		if not named in self.accelerators:
 			return None
diff --git a/plugins/commander/commander/commands/completion.py b/plugins/commander/commander/commands/completion.py
index 8a263cd..18788d6 100644
--- a/plugins/commander/commander/commands/completion.py
+++ b/plugins/commander/commander/commands/completion.py
@@ -24,7 +24,6 @@ import bisect
 import sys
 import os
 import re
-import gio
 
 from xml.sax import saxutils
 
diff --git a/plugins/commander/commander/commands/rollbackimporter.py b/plugins/commander/commander/commands/rollbackimporter.py
index 1ab03a7..8dce690 100644
--- a/plugins/commander/commander/commands/rollbackimporter.py
+++ b/plugins/commander/commander/commands/rollbackimporter.py
@@ -53,5 +53,3 @@ class RollbackImporter:
 
 		self._new_modules = []
 
-
-
diff --git a/plugins/commander/commander/entry.py b/plugins/commander/commander/entry.py
index c3d8b8e..30e80e2 100644
--- a/plugins/commander/commander/entry.py
+++ b/plugins/commander/commander/entry.py
@@ -19,7 +19,7 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330,
 #  Boston, MA 02111-1307, USA.
 
-import gtk
+from gi.repository import GObject, Gdk, Gtk
 import cairo
 import glib
 import os
@@ -40,44 +40,54 @@ from info import Info
 from xml.sax import saxutils
 import traceback
 
-class Entry(gtk.EventBox):
+class Entry(Gtk.EventBox):
+	__gtype_name__ = "CommanderEntry"
+
 	def __init__(self, view):
-		gtk.EventBox.__init__(self)
+		Gtk.EventBox.__init__(self)
 		self._view = view
 
-		hbox = gtk.HBox(False, 3)
+		self.set_visible_window(False)
+
+		hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 3)
 		hbox.show()
 		hbox.set_border_width(3)
 
-		self._entry = gtk.Entry()
-		self._entry.modify_font(self._view.style.font_desc)
+		# context for the view
+		self._entry = Gtk.Entry()
 		self._entry.set_has_frame(False)
-		self._entry.set_name('command-bar')
-		self._entry.modify_text(gtk.STATE_NORMAL, self._view.style.text[gtk.STATE_NORMAL])
-		self._entry.set_app_paintable(True)
+		self._entry.set_name('gedit-commander-entry')
+		self._entry.show()
 
-		self._entry.connect('realize', self.on_realize)
-		self._entry.connect('expose-event', self.on_entry_expose)
+		css = Gtk.CssProvider()
+		css.load_from_data("""
+ binding-set terminal-like-bindings {
+	unbind "<Control>A";
+
+	bind "<Control>W" { "delete-from-cursor" (word-ends, -1) };
+	bind "<Control>A" { "move-cursor" (buffer-ends, -1, 0) };
+	bind "<Control>U" { "delete-from-cursor" (display-line-ends, -1) };
+	bind "<Control>K" { "delete-from-cursor" (display-line-ends, 1) };
+	bind "<Control>E" { "move-cursor" (buffer-ends, 1, 0) };
+	bind "Escape" { "delete-from-cursor" (display-lines, 1) };
+};
+
+GtkEntry#gedit-commander-entry {
+	gtk-key-bindings: terminal-like-bindings
+}
+""", -1)
 
-		self._entry.show()
+		# FIXME: remove hardcopy of 600 (GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
+		# https://bugzilla.gnome.org/show_bug.cgi?id=646860
+		self._entry.get_style_context().add_provider(css, 600)
 
-		self._prompt_label = gtk.Label('<b>&gt;&gt;&gt;</b>')
-		self._prompt_label.set_use_markup(True)
-		self._prompt_label.modify_font(self._view.style.font_desc)
+		self._prompt_label = Gtk.Label(label='<b>&gt;&gt;&gt;</b>', use_markup=True)
 		self._prompt_label.show()
-		self._prompt_label.modify_fg(gtk.STATE_NORMAL, self._view.style.text[gtk.STATE_NORMAL])
-
-		self.modify_bg(gtk.STATE_NORMAL, self.background_gdk())
-		self._entry.modify_base(gtk.STATE_NORMAL, self.background_gdk())
 
 		self._entry.connect('focus-out-event', self.on_entry_focus_out)
 		self._entry.connect('key-press-event', self.on_entry_key_press)
 
-		self.connect_after('size-allocate', self.on_size_allocate)
-		self.connect_after('expose-event', self.on_expose)
-		self.connect_after('realize', self.on_realize)
-
-		self._history = History(os.path.expanduser('~/.gnome2/gedit/commander/history'))
+		self._history = History(os.path.join(glib.get_user_config_dir(), 'gedit/commander/history'))
 		self._prompt = None
 
 		self._accel_group = None
@@ -85,112 +95,114 @@ class Entry(gtk.EventBox):
 		hbox.pack_start(self._prompt_label, False, False, 0)
 		hbox.pack_start(self._entry, True, True, 0)
 
+		self.copy_style_from_view()
+		self.view_style_updated_id = self._view.connect('style-updated', self.on_view_style_updated)
+
 		self.add(hbox)
 		self.attach()
-
 		self._entry.grab_focus()
+
 		self._wait_timeout = 0
 		self._info_window = None
 
 		self.connect('destroy', self.on_destroy)
+		self.connect_after('size-allocate', self.on_size_allocate)
+		self.view_draw_id = self._view.connect_after('draw', self.on_draw)
 
 		self._history_prefix = None
 		self._suspended = None
 		self._handlers = [
-			[0, gtk.keysyms.Up, self.on_history_move, -1],
-			[0, gtk.keysyms.Down, self.on_history_move, 1],
-			[None, gtk.keysyms.Return, self.on_execute, None],
-			[None, gtk.keysyms.KP_Enter, self.on_execute, None],
-			[0, gtk.keysyms.Tab, self.on_complete, None],
-			[0, gtk.keysyms.ISO_Left_Tab, self.on_complete, None]
+			[0, Gdk.KEY_Up, self.on_history_move, -1],
+			[0, Gdk.KEY_Down, self.on_history_move, 1],
+			[None, Gdk.KEY_Return, self.on_execute, None],
+			[None, Gdk.KEY_KP_Enter, self.on_execute, None],
+			[0, Gdk.KEY_Tab, self.on_complete, None],
+			[0, Gdk.KEY_ISO_Left_Tab, self.on_complete, None]
 		]
 
 		self._re_complete = re.compile('("((?:\\\\"|[^"])*)"?|\'((?:\\\\\'|[^\'])*)\'?|[^\s]+)')
 		self._command_state = commands.Commands.State()
 
-	def view(self):
-		return self._view
-
-	def on_realize(self, widget):
-		widget.window.set_back_pixmap(None, False)
-
-	def on_entry_expose(self, widget, evnt):
-		ct = evnt.window.cairo_create()
-		ct.rectangle(evnt.area.x, evnt.area.y, evnt.area.width, evnt.area.height)
-
-		bg = self.background_color()
-		ct.set_source_rgb(bg[0], bg[1], bg[2])
-		ct.fill()
-
-		return False
-
-	def on_expose(self, widget, evnt):
-		ct = evnt.window.cairo_create()
-		color = self.background_color()
-
-		ct.rectangle(evnt.area.x, evnt.area.y, evnt.area.width, evnt.area.height)
-		ct.clip()
+	def on_view_style_updated(self, widget):
+		self.copy_style_from_view()
+
+	def get_border_color(self):
+		color = self.get_background_color().copy()
+		color.red = 1 - color.red
+		color.green = 1 - color.green
+		color.blue = 1 - color.blue
+		color.alpha = 0.5
+
+		return color
+
+	def get_background_color(self):
+		context = self._view.get_style_context()
+		return context.get_background_color(Gtk.StateFlags.NORMAL)
+	
+	def get_foreground_color(self):
+		context = self._view.get_style_context()
+		return context.get_color(Gtk.StateFlags.NORMAL)
+
+	def get_font(self):
+		context = self._view.get_style_context()
+		return context.get_font(Gtk.StateFlags.NORMAL)
+
+	def copy_style_from_view(self, widget=None):
+		if widget != None:
+			context = self._view.get_style_context()
+			font = context.get_font(Gtk.StateFlags.NORMAL)
+
+			widget.override_color(Gtk.StateFlags.NORMAL, self.get_foreground_color())
+			widget.override_background_color(Gtk.StateFlags.NORMAL, self.get_background_color())
+			widget.override_font(self.get_font())
+		else:
+			if self._entry:
+				self.copy_style_from_view(self._entry)
 
-		# Draw separator line
-		ct.move_to(0, 0)
-		ct.set_line_width(1)
-		ct.line_to(self.allocation.width, 0)
+			if self._prompt_label:
+				self.copy_style_from_view(self._prompt_label)
 
-		ct.set_source_rgb(1 - color[0], 1 - color[1], 1 - color[2])
-		ct.stroke()
-		return False
+	def view(self):
+		return self._view
 
 	def on_size_allocate(self, widget, alloc):
-		vwwnd = self._view.get_window(gtk.TEXT_WINDOW_BOTTOM).get_parent()
-		size = vwwnd.get_size()
-		position = vwwnd.get_position()
+		alloc = self.get_allocation()
+		self._view.set_border_window_size(Gtk.TextWindowType.BOTTOM, alloc.height)
 
-		self._view.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, alloc.height)
+		# NOTE: we need to do this explicitly somehow, otherwise the window
+		# size will not be updated unless something else happens, not exactly
+		# sure what. This might be caused by the multi notebook, or custom
+		# animation layouting?
+		self._view.get_parent().resize_children()
 
 	def attach(self):
 		# Attach ourselves in the text view, and position just above the
 		# text window
-		self._view.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 1)
-		alloc = self._view.allocation
-
-		self.show()
-		self._view.add_child_in_window(self, gtk.TEXT_WINDOW_BOTTOM, 0, 0)
-		self.set_size_request(alloc.width, -1)
-
-	def background_gdk(self):
-		bg = self.background_color()
+		win = self._view.get_window(Gtk.TextWindowType.TEXT)
+		alloc = self.get_allocation()
 
-		bg = map(lambda x: int(x * 65535), bg)
-		return gtk.gdk.Color(bg[0], bg[1], bg[2])
+		self._view.set_border_window_size(Gtk.TextWindowType.BOTTOM, max(alloc.height, 1))
+		self._view.add_child_in_window(self, Gtk.TextWindowType.BOTTOM, 0, 0)
 
-	def background_color(self):
-		bg = self._view.get_style().base[self._view.state]
+		win = self._view.get_window(Gtk.TextWindowType.BOTTOM)
 
-		vals = [bg.red, bg.green, bg.blue, 1]
+		# Set same color as gutter, i.e. bg color of the view
+		context = self._view.get_style_context()
+		color = context.get_background_color(Gtk.StateFlags.NORMAL)
+		win.set_background_rgba(color)
 
-		for i in range(3):
-			val = vals[i] / 65535.0
-
-			if val < 0.0001:
-				vals[i] = 0.1
-			elif val > 0.9999:
-				vals[i] = 0.9
-			elif val < 0.1:
-				vals[i] = val * 1.2
-			else:
-				vals[i] = val * 0.8
-
-		return vals
+		self.show()
+		self.set_size_request(win.get_width(), -1)
 
 	def on_entry_focus_out(self, widget, evnt):
-		if self._entry.flags() & gtk.SENSITIVE:
+		if self._entry.get_sensitive():
 			self.destroy()
 
 	def on_entry_key_press(self, widget, evnt):
-		state = evnt.state & gtk.accelerator_get_default_mod_mask()
+		state = evnt.state & Gtk.accelerator_get_default_mod_mask()
 		text = self._entry.get_text()
 
-		if evnt.keyval == gtk.keysyms.Escape:
+		if evnt.keyval == Gdk.KEY_Escape:
 			if self._info_window:
 				if self._suspended:
 					self._suspended.resume()
@@ -329,7 +341,7 @@ class Entry(gtk.EventBox):
 			self._entry.set_sensitive(True)
 
 	def _show_wait_cancel(self):
-		self._cancel_button = self.info_add_action(gtk.STOCK_STOP, self.on_wait_cancel)
+		self._cancel_button = self.info_add_action(Gtk.STOCK_STOP, self.on_wait_cancel)
 		self.info_status('<i>Waiting to finish...</i>')
 
 		self._wait_timeout = 0
@@ -342,7 +354,7 @@ class Entry(gtk.EventBox):
 
 	def on_suspend_resume(self):
 		if self._wait_timeout:
-			glib.source_remove(self._wait_timeout)
+			GObject.source_remove(self._wait_timeout)
 			self._wait_timeout = 0
 		else:
 			self._cancel_button.destroy()
@@ -366,7 +378,7 @@ class Entry(gtk.EventBox):
 
 	def destroy(self):
 		self.hide()
-		gtk.EventBox.destroy(self)
+		Gtk.EventBox.destroy(self)
 
 	def run_command(self, cb):
 		self._suspended = None
@@ -392,7 +404,7 @@ class Entry(gtk.EventBox):
 			self._suspended = ret
 			ret.register(self.on_suspend_resume)
 
-			self._wait_timeout = glib.timeout_add(500, self._show_wait_cancel)
+			self._wait_timeout = GObject.timeout_add(500, self._show_wait_cancel)
 			self._entry.set_sensitive(False)
 		else:
 			self.command_history_done()
@@ -604,47 +616,32 @@ class Entry(gtk.EventBox):
 
 		return True
 
+	def on_draw(self, widget, ct):
+		win = widget.get_window(Gtk.TextWindowType.BOTTOM)
+
+		if not Gtk.cairo_should_draw_window(ct, win):
+			return False
+
+		Gtk.cairo_transform_to_window(ct, widget, win)
+
+		color = self.get_border_color()
+		width = win.get_width()
+
+		ct.set_source_rgba(color.red, color.green, color.blue, color.alpha)
+		ct.move_to(0, 0)
+		ct.line_to(width, 0)
+		ct.stroke()
+
+		return False
+
 	def on_destroy(self, widget):
-		self._view.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 0)
+		self._view.set_border_window_size(Gtk.TextWindowType.BOTTOM, 0)
+		self._view.disconnect(self.view_style_updated_id)
+		self._view.disconnect(self.view_draw_id)
 
 		if self._info_window:
 			self._info_window.destroy()
 
 		self._history.save()
 
-gtk.rc_parse_string("""
-binding "TerminalLike" {
-	unbind "<Control>A"
-
-	bind "<Control>W" {
-		"delete-from-cursor" (word-ends, -1)
-	}
-	bind "<Control>A" {
-		"move-cursor" (buffer-ends, -1, 0)
-	}
-	bind "<Control>U" {
-		"delete-from-cursor" (display-line-ends, -1)
-	}
-	bind "<Control>K" {
-		"delete-from-cursor" (display-line-ends, 1)
-	}
-	bind "<Control>E" {
-		"move-cursor" (buffer-ends, 1, 0)
-	}
-	bind "Escape" {
-		"delete-from-cursor" (display-lines, 1)
-	}
-}
-
-style "NoBackground" {
-	engine "pixmap" {
-		image {
-			function = FLAT_BOX
-			detail = "entry_bg"
-		}
-	}
-}
-
-widget "*.command-bar" binding "TerminalLike"
-widget "*.command-bar" style "NoBackground"
-""")
+# vi:ex:ts=4:et
diff --git a/plugins/commander/commander/info.py b/plugins/commander/commander/info.py
index 062f5de..3e19400 100644
--- a/plugins/commander/commander/info.py
+++ b/plugins/commander/commander/info.py
@@ -20,28 +20,35 @@
 #  Boston, MA 02111-1307, USA.
 
 from transparentwindow import TransparentWindow
-import gtk
+from gi.repository import Pango, Gdk, Gtk
 import math
-import pango
 
 class Info(TransparentWindow):
+	__gtype_name__ = "CommanderInfo"
+
 	def __init__(self, entry):
-		TransparentWindow.__init__(self, gtk.WINDOW_POPUP)
+		super(Info, self).__init__(Gtk.WindowType.POPUP)
 
 		self._entry = entry
-		self._vbox = gtk.VBox(False, 3)
+		self._vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
 
 		self.set_transient_for(entry.get_toplevel())
 
-		self._vw = gtk.ScrolledWindow()
-		self._vw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
+		self._vw = Gtk.ScrolledWindow()
+		self._vw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
 		self._vw.show()
 
-		self._text = gtk.TextView()
-		self._text.modify_font(entry._view.style.font_desc)
-		self._text.modify_text(gtk.STATE_NORMAL, entry._entry.style.text[gtk.STATE_NORMAL])
-		self._text.connect('expose-event', self.on_text_expose)
-		self._text.set_wrap_mode(gtk.WRAP_WORD_CHAR)
+		self._text = Gtk.TextView()
+
+		font = self._entry.get_font()
+		fgcolor = self._entry.get_foreground_color()
+		bgcolor = self.background_color()
+
+		self._text.override_font(font)
+		self._text.override_color(Gtk.StateFlags.NORMAL, fgcolor)
+		self._text.override_background_color(Gtk.StateFlags.NORMAL, bgcolor)
+
+		self._text.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
 
 		buf = self._text.get_buffer()
 
@@ -51,7 +58,7 @@ class Info(TransparentWindow):
 		self._text.set_editable(False)
 
 		self._vw.add(self._text)
-		self._vbox.pack_end(self._vw, expand=False, fill=False)
+		self._vbox.pack_end(self._vw, False, False, 0)
 		self._vbox.show()
 		self._button_bar = None
 
@@ -62,28 +69,26 @@ class Info(TransparentWindow):
 		self.props.can_focus = False
 		self.set_border_width(8)
 
-		self._text.connect('realize', self.on_text_realize)
-
 		self.attach()
 		self.show()
 
-		self.connect_after('size-allocate', self.on_size_allocate)
-		self._vw.connect_after('size-allocate', self.on_text_size_allocate)
-
 		self.max_lines = 10
 
+		self.connect_after('size-allocate', self.on_size_allocate)
+		self.connect_after('draw', self.on_draw)
+
 		self._attr_map = {
-			pango.ATTR_STYLE: 'style',
-			pango.ATTR_WEIGHT: 'weight',
-			pango.ATTR_VARIANT: 'variant',
-			pango.ATTR_STRETCH: 'stretch',
-			pango.ATTR_SIZE: 'size',
-			pango.ATTR_FOREGROUND: 'foreground',
-			pango.ATTR_BACKGROUND: 'background',
-			pango.ATTR_UNDERLINE: 'underline',
-			pango.ATTR_STRIKETHROUGH: 'strikethrough',
-			pango.ATTR_RISE: 'rise',
-			pango.ATTR_SCALE: 'scale'
+			Pango.AttrType.STYLE: 'style',
+			Pango.AttrType.WEIGHT: 'weight',
+			Pango.AttrType.VARIANT: 'variant',
+			Pango.AttrType.STRETCH: 'stretch',
+			Pango.AttrType.SIZE: 'size',
+			Pango.AttrType.FOREGROUND: 'foreground',
+			Pango.AttrType.BACKGROUND: 'background',
+			Pango.AttrType.UNDERLINE: 'underline',
+			Pango.AttrType.STRIKETHROUGH: 'strikethrough',
+			Pango.AttrType.RISE: 'rise',
+			Pango.AttrType.SCALE: 'scale'
 		}
 
 	def empty(self):
@@ -92,9 +97,15 @@ class Info(TransparentWindow):
 
 	def status(self, text=None):
 		if self._status_label == None and text != None:
-			self._status_label = gtk.Label('')
-			self._status_label.modify_font(self._text.style.font_desc)
-			self._status_label.modify_fg(gtk.STATE_NORMAL, self._text.style.text[gtk.STATE_NORMAL])
+			self._status_label = Gtk.Label()
+
+			context = self._text.get_style_context()
+			state = context.get_state()
+			font_desc = context.get_font(state)
+
+			self._status_label.override_font(font_desc)
+
+			self._status_label.override_color(Gtk.StateFlags.NORMAL, context.get_color(Gtk.StateFlags.NORMAL))
 			self._status_label.show()
 			self._status_label.set_alignment(0, 0.5)
 			self._status_label.set_padding(10, 0)
@@ -120,7 +131,7 @@ class Info(TransparentWindow):
 			if not attr.type in self._attr_map:
 				continue
 
-			if attr.type == pango.ATTR_FOREGROUND or attr.type == pango.ATTR_BACKGROUND:
+			if attr.type == Pango.AttrType.FOREGROUND or attr.type == Pango.AttrType.BACKGROUND:
 				value = attr.color
 			else:
 				value = attr.value
@@ -148,14 +159,19 @@ class Info(TransparentWindow):
 			return
 
 		try:
-			ret = pango.parse_markup(line)
+			ret = Pango.parse_markup(line, -1, u'\x00')
 		except Exception, e:
 			print 'Could not parse markup:', e
 			buf.insert(buf.get_end_iter(), line)
 			return
 
-		piter = ret[0].get_iterator()
-		text = ret[1]
+		# TODO: fix this when pango supports get_iterator
+		text = ret[2]
+		buf.insert(buf.get_end_iter(), text)
+
+		return
+
+		piter = ret[1].get_iterator()
 
 		while piter:
 			attrs = piter.get_attrs()
@@ -183,16 +199,16 @@ class Info(TransparentWindow):
 	def contents_changed(self):
 		buf = self._text.get_buffer()
 
-		if self.toomany_lines() and (self._vw.get_policy()[1] != gtk.POLICY_ALWAYS):
-			self._vw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
+		if self.toomany_lines() and (self._vw.get_policy()[1] != Gtk.PolicyType.ALWAYS):
+			self._vw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
 
 			layout = self._text.create_pango_layout('Some text to measure')
 			extents = layout.get_pixel_extents()
 
-			self._text.set_size_request(-1, extents[1][3] * self.max_lines)
-		elif not self.toomany_lines() and (self._vw.get_policy()[1] == gtk.POLICY_ALWAYS):
-			self._vw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
-			self._text.set_size_request(-1, -1)
+			self._vw.set_min_content_height(extents[1].height * self.max_lines)
+		elif not self.toomany_lines() and (self._vw.get_policy()[1] == Gtk.PolicyType.ALWAYS):
+			self._vw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
+			self._vw.set_min_content_height(0)
 
 		if not self.toomany_lines():
 			size = self.get_size()
@@ -200,19 +216,19 @@ class Info(TransparentWindow):
 
 	def ensure_button_bar(self):
 		if not self._button_bar:
-			self._button_bar = gtk.HBox(False, 3)
+			self._button_bar = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=3)
 			self._button_bar.show()
 			self._vbox.pack_start(self._button_bar, False, False, 0)
 
 	def add_action(self, stock, callback, data=None):
-		image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU)
+		image = Gtk.Image.new_from_stock(stock, Gtk.IconSize.MENU)
 		image.show()
 
-		image.set_data('COMMANDER_ACTION_STOCK_ITEM', [stock, gtk.ICON_SIZE_MENU])
+		image.set_data('COMMANDER_ACTION_STOCK_ITEM', [stock, Gtk.IconSize.MENU])
 
 		self.ensure_button_bar()
 
-		ev = gtk.EventBox()
+		ev = Gtk.EventBox()
 		ev.set_visible_window(False)
 		ev.add(image)
 		ev.show()
@@ -233,8 +249,8 @@ class Info(TransparentWindow):
 
 	def on_action_enter_notify(self, widget, evnt):
 		img = widget.get_child()
-		img.set_state(gtk.STATE_PRELIGHT)
-		widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
+		img.set_state(Gtk.StateType.PRELIGHT)
+		widget.get_window().set_cursor(Gdk.Cursor.new(Gdk.HAND2))
 
 		stock = img.get_data('COMMANDER_ACTION_STOCK_ITEM')
 		pix = img.render_icon(stock[0], stock[1])
@@ -242,8 +258,8 @@ class Info(TransparentWindow):
 
 	def on_action_leave_notify(self, widget, evnt):
 		img = widget.get_child()
-		img.set_state(gtk.STATE_NORMAL)
-		widget.window.set_cursor(None)
+		img.set_state(Gtk.StateType.NORMAL)
+		widget.get_window().set_cursor(None)
 
 		stock = img.get_data('COMMANDER_ACTION_STOCK_ITEM')
 		pix = img.render_icon(stock[0], stock[1])
@@ -258,27 +274,8 @@ class Info(TransparentWindow):
 	def clear(self):
 		self._text.get_buffer().set_text('')
 
-	def on_text_expose(self, widget, evnt):
-		if evnt.window != widget.get_window(gtk.TEXT_WINDOW_TEXT):
-			return False
-
-		ct = evnt.window.cairo_create()
-		ct.save()
-
-		area = evnt.area
-		ct.rectangle(area.x, area.y, area.width, area.height)
-		ct.clip()
-
-		self.draw_background(ct, self._text, False)
-
-		ct.restore()
-		return False
-
-	def on_text_realize(self, widget):
-		self._text.get_window(gtk.TEXT_WINDOW_TEXT).set_back_pixmap(None, False)
-
 	def attach(self):
-		vwwnd = self._entry._view.get_window(gtk.TEXT_WINDOW_TEXT)
+		vwwnd = self._entry._view.get_window(Gtk.TextWindowType.TEXT)
 		origin = vwwnd.get_origin()
 		geom = vwwnd.get_geometry()
 
@@ -286,8 +283,10 @@ class Info(TransparentWindow):
 
 		self.realize()
 
-		self.move(origin[0], origin[1] + geom[3] - self.allocation.height)
-		self.resize(geom[2] - margin * 2, self.allocation.height)
+		alloc = self.get_allocation()
+
+		self.move(origin[1], origin[2] + geom[3] - alloc.height)
+		self.resize(geom[2] - margin * 2, alloc.height)
 
 	def on_text_insert_text(self, buf, piter, text, length):
 		self.contents_changed()
@@ -296,38 +295,27 @@ class Info(TransparentWindow):
 		self.contents_changed()
 
 	def on_size_allocate(self, widget, allocation):
-		vwwnd = self._entry._view.get_window(gtk.TEXT_WINDOW_TEXT)
+		vwwnd = self._entry.view().get_window(Gtk.TextWindowType.TEXT)
 		origin = vwwnd.get_origin()
 		geom = vwwnd.get_geometry()
 
-		self.move(origin[0] + (geom[2] - self.allocation.width) / 2, origin[1] + geom[3] - self.allocation.height)
-
-	def on_expose(self, widget, evnt):
-		ret = TransparentWindow.on_expose(self, widget, evnt)
+		alloc = self.get_allocation()
 
-		if ret:
-			return True
+		self.move(origin[1] + (geom[2] - alloc.width) / 2, origin[2] + geom[3] - alloc.height)
 
-		ct = evnt.window.cairo_create()
-		ct.save()
+	def on_draw(self, widget, ct):
+		color = self._entry.get_border_color()
 
-		area = evnt.area
-		ct.rectangle(area.x, area.y, area.width, area.height)
-		ct.clip()
+		self.background_shape(ct, self.get_allocation())
 
-		color = self.background_color()
-
-		self.background_shape(ct)
-
-		ct.set_source_rgba(1 - color[0], 1 - color[1], 1 - color[2], 0.3)
+		ct.set_source_rgba(color.red, color.green, color.blue, color.alpha)
 		ct.stroke()
 
-		ct.restore()
 		return False
 
-	def background_shape(self, ct):
-		w = self.allocation.width
-		h = self.allocation.height
+	def background_shape(self, ct, alloc):
+		w = alloc.width
+		h = alloc.height
 
 		ct.set_line_width(1)
 		radius = 10
@@ -335,8 +323,8 @@ class Info(TransparentWindow):
 		ct.move_to(0.5, h)
 
 		if self.is_composited():
-			ct.arc(radius + 0.5, radius, radius, math.pi, math.pi * 1.5)
-			ct.arc(w - radius - 0.5, radius, radius, math.pi * 1.5, math.pi * 2)
+			ct.arc(radius + 0.5, radius + 0.5, radius, math.pi, math.pi * 1.5)
+			ct.arc(w - radius - 0.5, radius + 0.5, radius, math.pi * 1.5, math.pi * 2)
 		else:
 			ct.line_to(0.5, 0)
 			ct.line_to(w - 0.5, 0)
@@ -344,8 +332,12 @@ class Info(TransparentWindow):
 		ct.line_to(w - 0.5, h)
 
 	def background_color(self):
-		return self._entry.background_color()
+		color = self._entry.get_background_color().copy()
+		color.alpha = 0.9
+
+		return color
 
 	def on_text_size_allocate(self, widget, alloc):
 		pass
 
+# vi:ex:ts=4:et
diff --git a/plugins/commander/commander/modules.py b/plugins/commander/commander/modules.py
new file mode 100644
index 0000000..d3d0f3e
--- /dev/null
+++ b/plugins/commander/commander/modules.py
@@ -0,0 +1 @@
+# All modules are imported here by the commander
diff --git a/plugins/commander/commander/transparentwindow.py b/plugins/commander/commander/transparentwindow.py
index fb7d4e3..50296f1 100644
--- a/plugins/commander/commander/transparentwindow.py
+++ b/plugins/commander/commander/transparentwindow.py
@@ -19,73 +19,61 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330,
 #  Boston, MA 02111-1307, USA.
 
-import gtk
+from gi.repository import GObject, Gdk, Gtk, Gedit
 import cairo
 
-class TransparentWindow(gtk.Window):
-	def __init__(self, lvl=gtk.WINDOW_TOPLEVEL):
-		gtk.Window.__init__(self, lvl)
+class TransparentWindow(Gtk.Window):
+	__gtype_name__ = "CommanderTransparentWindow"
 
-		self.set_decorated(False)
-		self.set_app_paintable(True)
-		self.set_skip_pager_hint(True)
-		self.set_skip_taskbar_hint(True)
-		self.set_events(gtk.gdk.ALL_EVENTS_MASK)
+	def __init__(self, lvl=Gtk.WindowType.TOPLEVEL):
+		Gtk.Window.__init__(self,
+							type=lvl,
+							decorated=False,
+							app_paintable=True,
+							skip_pager_hint=True,
+							skip_taskbar_hint=True)
 
+		self.set_events(Gdk.EventMask.ALL_EVENTS_MASK)
 		self.set_rgba()
 
 	def set_rgba(self):
-		cmap = self.get_screen().get_rgba_colormap()
+		visual = self.get_screen().get_rgba_visual()
 
-		if not cmap:
-			return
+		if not visual:
+			visual = self.get_screen().get_system_visual()
 
-		self.set_colormap(cmap)
-		self.connect('realize', self.on_realize)
-		self.connect('expose-event', self.on_expose)
+		self.set_visual(visual)
 
-	def on_realize(self, widget):
-		self.window.set_back_pixmap(None, False)
+	def do_screen_changed(self, prev):
+		super(TransparentWindow, self).do_screen_changed(prev)
+
+		self.set_rgba()
 
 	def background_color(self):
-		return [0, 0, 0, 0.8]
+		return Gdk.RGBA(0, 0, 0, 0.8)
 
-	def background_shape(self, ct):
-		ct.rectangle(0, 0, self.allocation.width, self.allocation.height)
+	def background_shape(self, ct, alloc):
+		ct.rectangle(0, 0, alloc.width, alloc.height)
 
-	def draw_background(self, ct, widget=None, shape=True):
+	def draw_background(self, ct, widget=None):
 		if widget == None:
 			widget = self
 
 		ct.set_operator(cairo.OPERATOR_SOURCE)
-		ct.rectangle(0, 0, widget.allocation.width, widget.allocation.height)
-		ct.set_source_rgba(0, 0, 0, 0)
+		alloc = widget.get_allocation()
 
-		if not shape:
-			ct.fill_preserve()
-		else:
-			ct.fill()
+		ct.rectangle(0, 0, alloc.width, alloc.height)
+		ct.set_source_rgba(0, 0, 0, 0)
+		ct.fill()
 
 		color = self.background_color()
+		self.background_shape(ct, alloc)
 
-		if shape:
-			self.background_shape(ct)
-
-		ct.set_source_rgba(color[0], color[1], color[2], color[3])
+		ct.set_source_rgba(color.red, color.green, color.blue, color.alpha)
 		ct.fill()
 
-	def on_expose(self, widget, evnt):
-		if not self.window:
-			return
-
-		ct = evnt.window.cairo_create()
-		ct.save()
-
-		area = evnt.area
-		ct.rectangle(area.x, area.y, area.width, area.height)
-		ct.clip()
-
+	def do_draw(self, ct):
 		self.draw_background(ct)
-
-		ct.restore()
 		return False
+
+# vi:ex:ts=4:et
diff --git a/plugins/commander/commander/windowhelper.py b/plugins/commander/commander/windowactivatable.py
similarity index 72%
rename from plugins/commander/commander/windowhelper.py
rename to plugins/commander/commander/windowactivatable.py
index a613d9a..13dc814 100644
--- a/plugins/commander/commander/windowhelper.py
+++ b/plugins/commander/commander/windowactivatable.py
@@ -19,8 +19,7 @@
 #  Foundation, Inc., 59 Temple Place, Suite 330,
 #  Boston, MA 02111-1307, USA.
 
-import gedit
-import gtk
+from gi.repository import GObject, Gtk, Gedit
 from entry import Entry
 from info import Info
 from gpdefs import *
@@ -43,42 +42,46 @@ ui_str = """
 </ui>
 """
 
-class WindowHelper:
-	def __init__(self, plugin, window):
-		self._window = window
-		self._plugin = plugin
+class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
+	__gtype_name__ = "CommanderWindowActivatable"
+
+	window = GObject.property(type=Gedit.Window)
+
+	def __init__(self):
+		GObject.Object.__init__(self)
+
+	def do_activate(self):
 		self._entry = None
 		self._view = None
 
 		self.install_ui()
 
+	def do_deactivate(self):
+		self.uninstall_ui()
+
+	def do_update_state(self):
+		pass
+
 	def install_ui(self):
-		manager = self._window.get_ui_manager()
+		manager = self.window.get_ui_manager()
 
-		self._action_group = gtk.ActionGroup("GeditCommanderPluginActions")
-		self._action_group.add_toggle_actions([('CommanderModeAction', None, _('Commander Mode'), '<Ctrl>period', _('Start commander mode'), self.on_commander_mode)])
+		self._action_group = Gtk.ActionGroup("GeditCommanderPluginActions")
+		self._action_group.add_toggle_actions([('CommanderModeAction', None,
+		                                       _('Commander Mode'), '<Ctrl>period',
+		                                       _('Start commander mode'), self.on_commander_mode)])
 
 		manager.insert_action_group(self._action_group, -1)
 		self._merge_id = manager.add_ui_from_string(ui_str)
 
 	def uninstall_ui(self):
-		manager = self._window.get_ui_manager()
+		manager = self.window.get_ui_manager()
 		manager.remove_ui(self._merge_id)
 		manager.remove_action_group(self._action_group)
 
 		manager.ensure_update()
 
-	def deactivate(self):
-		self.uninstall_ui()
-
-		self._window = None
-		self._plugin = None
-
-	def update_ui(self):
-		pass
-
-	def on_commander_mode(self, action):
-		view = self._window.get_active_view()
+	def on_commander_mode(self, action, user_data=None):
+		view = self.window.get_active_view()
 
 		if not view:
 			return False
@@ -96,6 +99,6 @@ class WindowHelper:
 
 		return True
 
-	def on_entry_destroy(self, widget):
+	def on_entry_destroy(self, widget, user_data=None):
 		self._entry = None
 		self._action_group.get_action('CommanderModeAction').set_active(False)
diff --git a/plugins/commander/modules/bookmark.py b/plugins/commander/modules/bookmark.py
index 7e47add..fdf379f 100644
--- a/plugins/commander/modules/bookmark.py
+++ b/plugins/commander/modules/bookmark.py
@@ -36,6 +36,7 @@ If installed and active, you can add/remove/toggle bookmarks using the
 commander."""
 
     check_bookmark_plugin(window)
+
     window.get_message_bus().send('/plugins/bookmarks', 'toggle', view=view)
 
 def add(view, window):
@@ -45,6 +46,7 @@ Add bookmark on the current line. If there already is a bookmark on the current
 line, nothing happens."""
 
     check_bookmark_plugin(window)
+
     window.get_message_bus().send('/plugins/bookmarks', 'add', view=view)
 
 def remove(view, window):
@@ -54,6 +56,7 @@ Remove bookmark from the current line. If there is no bookmark on the current
 line, nothing happens."""
 
     check_bookmark_plugin(window)
+
     window.get_message_bus().send('/plugins/bookmarks', 'remove', view=view)
 
 def toggle(view, window):
@@ -62,6 +65,7 @@ def toggle(view, window):
 Toggle bookmark on the current line."""
 
     check_bookmark_plugin(window)
+
     window.get_message_bus().send('/plugins/bookmarks', 'toggle', view=view)
 
 def next(view, window):
diff --git a/plugins/commander/modules/doc.py b/plugins/commander/modules/doc.py
index 16eb1fe..864f705 100644
--- a/plugins/commander/modules/doc.py
+++ b/plugins/commander/modules/doc.py
@@ -90,9 +90,11 @@ class Documenter:
         self.view = view
         self.iter = iter
 
-        bus = self.window.get_message_bus()
+        bus = self.get_window().get_message_bus()
+        self.canplaceholder = (bus.lookup('/plugins/snippets', 'parse-and-activate').name != 'invalid')
+
+        self.canplaceholder = False
 
-        self.canplaceholder = bus.lookup('/plugins/snippets', 'parse-and-activate') != None
         self.placeholder = 1
         self.text = ''
 
diff --git a/plugins/commander/modules/edit.py b/plugins/commander/modules/edit.py
index 55688ea..9ebf086 100644
--- a/plugins/commander/modules/edit.py
+++ b/plugins/commander/modules/edit.py
@@ -20,13 +20,12 @@
 #  Boston, MA 02111-1307, USA.
 
 import os
-import gio
-import gedit
 import glob
 import sys
 import types
 import inspect
-import gio
+
+from gi.repository import Gio, Gedit
 
 import commander.commands as commands
 import commander.commands.completion
@@ -55,13 +54,13 @@ def __default__(filename, view):
 
     if matches:
         for match in matches:
-            files.append(gio.File(match))
+            files.append(Gio.File.new_for_path(match))
     else:
-        files.append(gio.File(filename))
+        files.append(Gio.File.new_for_path(filename))
 
     if files:
         window = view.get_toplevel()
-        gedit.commands.load_locations(window, files)
+        Gedit.commands_load_locations(window, files)
 
     return commander.commands.result.HIDE
 
@@ -92,7 +91,7 @@ def rename(view, newfile):
         raise commander.commands.exceptions.Execute('Current document file does not exist')
 
     if os.path.isabs(newfile):
-        dest = gio.File(newfile)
+        dest = Gio.File.new_for_path(newfile)
     else:
         dest = f.get_parent().resolve_relative_path(newfile)
 
@@ -119,7 +118,7 @@ def rename(view, newfile):
             yield commander.commands.result.HIDE
 
     try:
-        f.move(dest, _dummy_cb, flags=gio.FILE_COPY_OVERWRITE)
+        f.move(dest, _dummy_cb, flags=Gio.FileCopyFlags.OVERWRITE)
 
         doc.set_location(dest)
         yield commander.commands.result.HIDE
@@ -134,12 +133,12 @@ def _mod_has_alias(mod, alias):
 
 def _edit_command(view, mod, func=None):
     try:
-        location = gio.File(inspect.getsourcefile(mod))
+        location = Gio.File.new_for_path(inspect.getsourcefile(mod))
     except:
         return False
 
     if not func:
-        gedit.commands.load_location(view.get_toplevel(), location)
+        Gedit.commands_load_location(view.get_toplevel(), location)
     else:
         try:
             lines = inspect.getsourcelines(func)
@@ -147,7 +146,7 @@ def _edit_command(view, mod, func=None):
         except:
             line = 0
 
-        gedit.commands.load_location(view.get_toplevel(), location, None, line)
+        Gedit.commands_load_location(view.get_toplevel(), location, None, line)
 
     return True
 
@@ -206,7 +205,7 @@ Use this to apply the cool new feature\"\"\"
 def new_command(view, entry, name):
     """Create a new commander command module: edit.new-command &lt;command&gt;"""
 
-    filename = os.path.expanduser('~/.gnome2/gedit/commander/modules/' + name + '.py')
+    filename = os.path.join(glib.get_user_config_dir(), 'gedit/commander/modules/' + name + '.py')
 
     if os.path.isfile(filename):
         raise commander.commands.exceptions.Execute('Commander module `' + name + '\' already exists')
@@ -224,13 +223,13 @@ def new_command(view, entry, name):
 
 def save(view):
     window = view.get_toplevel()
-    gedit.commands.save_document(window, view.get_buffer())
+    Gedit.commands_save_document(window, view.get_buffer())
 
     return commander.commands.result.HIDE
 
 def save_all(view):
     window = view.get_toplevel()
-    gedit.commands.save_all_documents(window)
+    Gedit.commands_save_all_documents(window)
 
     return commander.commands.result.HIDE
 
diff --git a/plugins/commander/modules/find/__init__.py b/plugins/commander/modules/find/__init__.py
index 3dc60cb..3262292 100644
--- a/plugins/commander/modules/find/__init__.py
+++ b/plugins/commander/modules/find/__init__.py
@@ -20,7 +20,7 @@
 #  Boston, MA 02111-1307, USA.
 
 import commander.commands as commands
-import gedit
+from gi.repository import Gedit
 import re
 import regex
 from xml.sax import saxutils
@@ -52,7 +52,7 @@ def __default__(entry, argstr):
     """Find in document: find &lt;text&gt;
 
 Quickly find phrases in the document"""
-    fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
+    fd = TextFinder(entry, Gedit.SearchFlags.CASE_SENSITIVE)
     yield fd.find(argstr)
 
 def _find_insensitive(entry, argstr):
@@ -66,7 +66,7 @@ def replace(entry, findstr, replstr=None):
     """Find/replace in document: find.replace &lt;find&gt; [&lt;replace&gt;]
 
 Quickly find and replace phrases in the document"""
-    fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
+    fd = TextFinder(entry, Gedit.SearchFlags.CASE_SENSITIVE)
     yield fd.replace(findstr, False, replstr)
 
 def replace_i(entry, findstr, replstr=None):
@@ -80,7 +80,7 @@ def replace_all(entry, findstr, replstr=None):
     """Find/replace all in document: find.replace-all &lt;find&gt; [&lt;replace&gt;]
 
 Quickly find and replace all phrases in the document"""
-    fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
+    fd = TextFinder(entry, Gedit.SearchFlags.CASE_SENSITIVE)
     yield fd.replace(findstr, True, replstr)
 
 def replace_all_i(entry, findstr, replstr=None):
diff --git a/plugins/commander/modules/find/finder.py b/plugins/commander/modules/find/finder.py
index 26725e2..2f87b3d 100644
--- a/plugins/commander/modules/find/finder.py
+++ b/plugins/commander/modules/find/finder.py
@@ -22,7 +22,7 @@
 from xml.sax import saxutils
 import commander.commands as commands
 import commander.utils as utils
-import gtk
+from gi.repository import Gdk, Gtk
 
 class Finder:
     FIND_STARTMARK = 'gedit-commander-find-startmark'
@@ -292,7 +292,7 @@ class Finder:
                                        'end': buf.get_iter_at_mark(self.find_result.end)})
 
                 # If there is a selection, replace it with the replacement string
-                if not bounds.start.equal(bounds.end) and (replaceall or not (modifier & gtk.gdk.CONTROL_MASK)):
+                if not bounds.start.equal(bounds.end) and (replaceall or not (modifier & Gdk.EventMask.CONTROL_MASK)):
                     text = bounds.start.get_text(bounds.end)
                     repl = self.get_replace(text)
 
diff --git a/plugins/commander/modules/find/regex.py b/plugins/commander/modules/find/regex.py
index b7a6812..a2a640a 100644
--- a/plugins/commander/modules/find/regex.py
+++ b/plugins/commander/modules/find/regex.py
@@ -22,7 +22,6 @@
 import commander.commands as commands
 import finder
 
-import gedit
 import re
 
 __commander_module__ = True
diff --git a/plugins/commander/modules/move.py b/plugins/commander/modules/move.py
index 21f9886..3206ab7 100644
--- a/plugins/commander/modules/move.py
+++ b/plugins/commander/modules/move.py
@@ -20,7 +20,7 @@
 #  Boston, MA 02111-1307, USA.
 
 import commander.commands as commands
-import gtk
+from gi.repository import Gdk, Gtk
 import re
 
 __commander_module__ = True
@@ -31,32 +31,32 @@ def _move(view, what, num, modifier):
     except:
         raise commands.exceptions.Execute('Invalid number: ' + str(num))
 
-    view.emit('move-cursor', what, num, modifier & gtk.gdk.CONTROL_MASK)
+    view.emit('move-cursor', what, num, modifier & Gdk.EventMask.CONTROL_MASK)
     return commands.result.HIDE
 
 def word(view, modifier, num=1):
     """Move cursor per word: move.word &lt;num&gt;
 
 Move the cursor per word (use negative num to move backwards)"""
-    return _move(view, gtk.MOVEMENT_WORDS, num, modifier)
+    return _move(view, Gtk.MovementStep.WORDS, num, modifier)
 
 def line(view, modifier, num=1):
     """Move cursor per line: move.line &lt;num&gt;
 
 Move the cursor per line (use negative num to move backwards)"""
-    return _move(view, gtk.MOVEMENT_DISPLAY_LINES, num, modifier)
+    return _move(view, Gtk.MovementStep.DISPLAY_LINES, num, modifier)
 
 def char(view, modifier, num=1):
     """Move cursor per char: move.char &lt;num&gt;
 
 Move the cursor per char (use negative num to move backwards)"""
-    return _move(view, gtk.MOVEMENT_VISUAL_POSITIONS, num, modifier)
+    return _move(view, Gtk.MovementStep.VISUAL_POSITIONS, num, modifier)
 
 def paragraph(view, modifier, num=1):
     """Move cursor per paragraph: move.paragraph &lt;num&gt;
 
 Move the cursor per paragraph (use negative num to move backwards)"""
-    return _move(view, gtk.MOVEMENT_PARAGRAPHS, num, modifier)
+    return _move(view, Gtk.MovementStep.PARAGRAPHS, num, modifier)
 
 def regex(view, modifier, regex, num=1):
     """Move cursor per regex: move.regex &lt;num&gt;
@@ -98,7 +98,7 @@ Move the cursor per regex (use negative num to move backwards)"""
         else:
             start.forward_chars(found.start(0))
 
-        if modifier & gtk.gdk.CONTROL_MASK:
+        if modifier & Gdk.EventMask.CONTROL_MASK:
             buf.move_mark(buf.get_selection_bound(), start)
         else:
             buf.move_mark(buf.get_insert(), start)
diff --git a/plugins/commander/modules/set.py b/plugins/commander/modules/set.py
index 8de0602..ebd79c7 100644
--- a/plugins/commander/modules/set.py
+++ b/plugins/commander/modules/set.py
@@ -23,7 +23,7 @@ import commander.commands as commands
 import commander.commands.exceptions
 
 import types
-import gtksourceview2 as gsv
+from gi.repository import GtkSource
 
 __commander_module__ = True
 
@@ -40,7 +40,7 @@ def _complete_options(words, idx):
     return commands.completion.words(ret)(words, idx)
 
 def _complete_language(words, idx):
-    manager = gsv.language_manager_get_default()
+    manager = GtkSource.LanguageManager.get_default()
     ids = manager.get_language_ids()
     ids.append('none')
     ids.sort()
@@ -92,7 +92,7 @@ Set the document language to the language with the specified id"""
         view.get_buffer().set_language(None)
         return False
 
-    manager = gsv.language_manager_get_default()
+    manager = GtkSource.LanguageManager.get_default()
     lang = manager.get_language(language)
 
     if lang:
@@ -138,11 +138,11 @@ Set what kind of spaces should be drawn. Multiple options can be defined, e.g.
 for drawing spaces and tabs: <i>set.draw-spaces space tab</i>"""
     m = {
         'none': 0,
-        'all': gsv.DRAW_SPACES_ALL,
-        'tabs': gsv.DRAW_SPACES_TAB,
-        'newlines': gsv.DRAW_SPACES_NEWLINE,
-        'nbsp': gsv.DRAW_SPACES_NBSP,
-        'spaces': gsv.DRAW_SPACES_SPACE
+        'all': GtkSource.DrawSpacesFlags.ALL,
+        'tabs': GtkSource.DrawSpacesFlags.TAB,
+        'newlines': GtkSource.DrawSpacesFlags.NEWLINE,
+        'nbsp': GtkSource.DrawSpacesFlags.NBSP,
+        'spaces': GtkSource.DrawSpacesFlags.SPACE
     }
 
     flags = 0
diff --git a/plugins/commander/modules/shell.py b/plugins/commander/modules/shell.py
index 188c3de..6171551 100644
--- a/plugins/commander/modules/shell.py
+++ b/plugins/commander/modules/shell.py
@@ -25,7 +25,7 @@ import fcntl
 import os
 import tempfile
 import signal
-import gio
+from gi.repository import GObject, Gio
 
 import commander.commands as commands
 import commander.commands.exceptions
@@ -107,7 +107,7 @@ class Process:
         if hasattr(self.pipe, 'kill'):
             self.pipe.kill()
 
-        glib.source_remove(self.watch)
+        GObject.source_remove(self.watch)
 
         if self.replace:
             self.entry.view().set_editable(True)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]