gave it a quick go, but no luck #17

Open
wants to merge 10 commits into
from
View
5 README.md
@@ -24,7 +24,7 @@ With this plugin, you can:
- Expand abbreviation with `Ctrl+E`
- Expand abbreviation as you type with `Ctrl+Alt+E`
- Wrap with abbreviation with `Ctrl+Shift+E`
-- Balance tag inward or outward with `Ctrl+Alt+I` or `Ctrl+Alt+O`
+- Balance tag inward or outward with `Ctrl+Alt+I` or `Ctrl+Alt+Shift+O`
- Merge lines with `Ctrl+Alt+M`
- Go to previous or next edit point with `Alt+Left` and `Alt+Right`
- Remove tag with `Ctrl+Alt+R`
@@ -37,10 +37,9 @@ Installation
------------
1. Download [zip](http://github.com/mikecrittenden/zen-coding-gedit/zipball/master) or [tar](http://github.com/mikecrittenden/zen-coding-gedit/tarball/master) source and unpack it.
-2. Move `zencoding.gedit-plugin` and the `zencoding` folder into `~/.gnome2/gedit/plugins/`
+2. Move `zencoding.plugin` and the `zencoding` folder into `~/.local/share/gedit/plugins/`
3. In Gedit, go to Edit → Preferences → Plugins to enable the plugin.
4. Try it out using the shortcut keys listed above.
-
Credits
-------
View
6 zencoding.gedit-plugin → zencoding.plugin
@@ -1,12 +1,12 @@
-[Gedit Plugin]
+[Plugin]
Loader=python
Module=zencoding
-IAge=2
+IAge=3
Name=Zen Coding
Name[ru]=Дзэн-разработка
Description=Enables Zen Coding's CSS and HTML tools for Gedit.
Description[fr]=Des sélecteurs CSS pour écrire du code HTML.
Description[ru]=Упрощает набор HTML и CSS с помощью механизма сокращений Zen Coding.
Authors=Franck Marcia <franck.marcia@gmail.com>, Mike Crittenden <mike@mikethecoder.com>
Copyright=Franck Marcia <franck.marcia@gmail.com>\nMike Crittenden <mike@mikethecoder.com>
-Website=http://github.com/mikecrittenden/zen-coding-gedit
+Website=http://github.com/aeischeid/zen-coding-gedit
View
105 zencoding/plugin.py
@@ -4,9 +4,8 @@
#
# Author Franck Marcia (franck.marcia@gmail.com)
#
-
-import gedit, gobject, gtk, os
-
+from gi.repository import Gedit, GObject, Gtk
+import os
from zen_editor import ZenEditor
zencoding_ui_str = """
@@ -36,84 +35,86 @@
</ui>
"""
-class ZenCodingPlugin(gedit.Plugin):
+class ZenCodingPlugin(GObject.Object, Gedit.WindowActivatable):
"""A Gedit plugin to implement Zen Coding's HTML and CSS shorthand expander."""
- def activate(self, window):
+ window = GObject.property(type=Gedit.Window)
+
+ def do_activate(self):
actions = [
- ('ZenCodingMenuAction', None, '_Zen Coding', None, "Zen Coding tools", None),
- ('ZenCodingExpandAction', None, '_Expand abbreviation', '<Ctrl>E', "Expand abbreviation to raw HTML/CSS", self.expand_abbreviation),
- ('ZenCodingExpandWAction', None, 'E_xpand dynamic abbreviation...', '<Ctrl><Alt>E', "Dynamically expand abbreviation as you type", self.expand_with_abbreviation),
- ('ZenCodingWrapAction', None, '_Wrap with abbreviation...', '<Ctrl><Shift>E', "Wrap with code expanded from abbreviation", self.wrap_with_abbreviation),
- ('ZenCodingInwardAction', None, 'Balance tag _inward', '<Ctrl><Alt>I', "Select inner tag's content", self.match_pair_inward),
- ('ZenCodingOutwardAction', None, 'Balance tag _outward', '<Ctrl><Alt>O', "Select outer tag's content", self.match_pair_outward),
- ('ZenCodingMergeAction', None, '_Merge lines', '<Ctrl><Alt>M', "Merge all lines of the current selection", self.merge_lines),
- ('ZenCodingPrevAction', None, '_Previous edit point', '<Alt>Left', "Place the cursor at the previous edit point", self.prev_edit_point),
- ('ZenCodingNextAction', None, '_Next edit point', '<Alt>Right', "Place the cursor at the next edit point", self.next_edit_point),
- ('ZenCodingRemoveAction', None, '_Remove tag', '<Ctrl><Alt>R', "Remove a tag", self.remove_tag),
- ('ZenCodingSplitAction', None, 'Split or _join tag', '<Ctrl><Alt>J', "Toggle between single and double tag", self.split_join_tag),
- ('ZenCodingCommentAction', None, 'Toggle _comment', '<Ctrl><Alt>C', "Toggle an XML or HTML comment", self.toggle_comment)
+ ('ZenCodingMenuAction', None, '_Zen Coding', None, "Zen Coding tools", None),
+ ('ZenCodingExpandAction', None, '_Expand abbreviation', '<Ctrl>E', "Expand abbreviation to raw HTML/CSS", self.expand_abbreviation),
+ ('ZenCodingExpandWAction', None, '_Expand dynamic abbreviation...', '<Ctrl><Alt>E', "Dynamically expand abbreviation as you type", self.expand_with_abbreviation),
+ ('ZenCodingWrapAction', None, '_Wrap with abbreviation...', '<Ctrl><Shift>E', "Wrap with code expanded from abbreviation", self.wrap_with_abbreviation),
+ ('ZenCodingInwardAction', None, 'Balance tag _inward', '<Ctrl><Alt>I', "Select inner tag's content", self.match_pair_inward),
+ ('ZenCodingOutwardAction', None, 'Balance tag _outward', '<Ctrl><Alt><Shift>O',"Select outer tag's content", self.match_pair_outward),
+ ('ZenCodingMergeAction', None, '_Merge lines', '<Ctrl><Alt>M', "Merge all lines of the current selection", self.merge_lines),
+ ('ZenCodingPrevAction', None, '_Previous edit point', '<Alt>Left', "Place the cursor at the previous edit point", self.prev_edit_point),
+ ('ZenCodingNextAction', None, '_Next edit point', '<Alt>Right', "Place the cursor at the next edit point", self.next_edit_point),
+ ('ZenCodingRemoveAction', None, '_Remove tag', '<Ctrl><Alt>R', "Remove a tag", self.remove_tag),
+ ('ZenCodingSplitAction', None, 'Split or _join tag', '<Ctrl><Alt>J', "Toggle between single and double tag", self.split_join_tag),
+ ('ZenCodingCommentAction', None, 'Toggle _comment', '<Ctrl><Alt>C', "Toggle an XML or HTML comment", self.toggle_comment)
]
windowdata = dict()
- window.set_data("ZenCodingPluginDataKey", windowdata)
- windowdata["action_group"] = gtk.ActionGroup("GeditZenCodingPluginActions")
- windowdata["action_group"].add_actions(actions, window)
- manager = window.get_ui_manager()
+ self.window.ZenCodingPluginDataKey = windowdata
+ windowdata["action_group"] = Gtk.ActionGroup("GeditZenCodingPluginActions")
+ windowdata["action_group"].add_actions(actions)
+ manager = self.window.get_ui_manager()
manager.insert_action_group(windowdata["action_group"], -1)
windowdata["ui_id"] = manager.add_ui_from_string(zencoding_ui_str)
- window.set_data("ZenCodingPluginInfo", windowdata)
+ self.window.ZenCodingPluginInfo = windowdata
self.editor = ZenEditor()
error = self.editor.get_user_settings_error()
if error:
- md = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
- gtk.BUTTONS_CLOSE, "There is an error in user settings:")
+ md = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.CLOSE, "There is an error in user settings:")
message = "{0} on line {1} at character {2}\n\nUser settings will not be available."
md.set_title("Zen Coding error")
md.format_secondary_text(message.format(error['msg'], error['lineno'], error['offset']))
md.run()
md.destroy()
- def deactivate(self, window):
- windowdata = window.get_data("ZenCodingPluginDataKey")
- manager = window.get_ui_manager()
+ def do_deactivate(self):
+ windowdata = self.window.ZenCodingPluginDataKey
+ manager = self.window.get_ui_manager()
manager.remove_ui(windowdata["ui_id"])
manager.remove_action_group(windowdata["action_group"])
- def update_ui(self, window):
- view = window.get_active_view()
- windowdata = window.get_data("ZenCodingPluginDataKey")
+ def do_update_state(self):
+ view = self.window.get_active_view()
+ windowdata = self.window.ZenCodingPluginDataKey
windowdata["action_group"].set_sensitive(bool(view and view.get_editable()))
- def expand_abbreviation(self, action, window):
- self.editor.expand_abbreviation(window)
+ def expand_abbreviation(self, action):
+ self.editor.expand_abbreviation(self.window)
- def expand_with_abbreviation(self, action, window):
- self.editor.expand_with_abbreviation(window)
+ def expand_with_abbreviation(self, action):
+ self.editor.expand_with_abbreviation(self.window)
- def wrap_with_abbreviation(self, action, window):
- self.editor.wrap_with_abbreviation(window)
+ def wrap_with_abbreviation(self, action):
+ self.editor.wrap_with_abbreviation(self.window)
- def match_pair_inward(self, action, window):
- self.editor.match_pair_inward(window)
+ def match_pair_inward(self, action):
+ self.editor.match_pair_inward(self.window)
- def match_pair_outward(self, action, window):
- self.editor.match_pair_outward(window)
+ def match_pair_outward(self, action):
+ self.editor.match_pair_outward(self.window)
- def merge_lines(self, action, window):
- self.editor.merge_lines(window)
+ def merge_lines(self, action):
+ self.editor.merge_lines(self.window)
- def prev_edit_point(self, action, window):
- self.editor.prev_edit_point(window)
+ def prev_edit_point(self, action):
+ self.editor.prev_edit_point(self.window)
- def next_edit_point(self, action, window):
- self.editor.next_edit_point(window)
+ def next_edit_point(self, action):
+ self.editor.next_edit_point(self.window)
- def remove_tag(self, action, window):
- self.editor.remove_tag(window)
+ def remove_tag(self, action):
+ self.editor.remove_tag(self.window)
- def split_join_tag(self, action, window):
- self.editor.split_join_tag(window)
+ def split_join_tag(self, action):
+ self.editor.split_join_tag(self.window)
- def toggle_comment(self, action, window):
- self.editor.toggle_comment(window)
+ def toggle_comment(self, action):
+ self.editor.toggle_comment(self.window)
View
22 zencoding/zen_dialog.py
@@ -2,9 +2,7 @@
@author Franck Marcia (franck.marcia@gmail.com)
'''
-import pygtk
-pygtk.require('2.0')
-import gtk
+from gi.repository import Gtk
class ZenDialog():
@@ -16,23 +14,23 @@ def __init__(self, editor, x, y, callback, text=""):
self.abbreviation = text
self.callback = callback
- self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ self.window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
self.window.set_decorated(False)
self.window.connect("destroy", self.quit)
self.window.connect("focus-out-event", self.focus_lost)
self.window.connect("key-press-event", self.key_pressed)
self.window.set_resizable(False)
self.window.move(x, y - 27)
- self.frame = gtk.Frame()
+ self.frame = Gtk.Frame()
self.window.add(self.frame)
self.frame.show()
- self.box = gtk.HBox()
+ self.box = Gtk.HBox(False, 0)
self.frame.add(self.box)
self.box.show()
- self.entry = gtk.Entry()
+ self.entry = Gtk.Entry()
self.entry.connect("changed", self.update)
self.entry.set_text(text)
self.entry.set_has_frame(False)
@@ -67,10 +65,10 @@ def update(self, entry):
def quit(self, widget=None, event=None):
self.window.hide()
self.window.destroy()
- gtk.main_quit()
+ Gtk.main_quit()
def main(self):
- gtk.main()
+ Gtk.main()
def main(editor, window, callback, text=""):
@@ -81,9 +79,9 @@ def main(editor, window, callback, text=""):
offset_start, offset_end = editor.get_selection_range()
insert = editor.buffer.get_iter_at_offset(offset_start)
location = editor.view.get_iter_location(insert)
- window = editor.view.get_window(gtk.TEXT_WINDOW_TEXT)
- xo, yo = window.get_origin()
- xb, yb = editor.view.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT, location.x + location.width, location.y)
+ window = editor.view.get_window(Gtk.TextWindowType.TEXT)
+ thing, xo, yo = window.get_origin()
+ xb, yb = editor.view.buffer_to_window_coords(Gtk.TextWindowType.TEXT, location.x + location.width, location.y)
# Open dialog at coordinates with eventual text.
my_zen_dialog = ZenDialog(editor, xo + xb, yo + yb, callback, text)
View
4 zencoding/zen_editor.py
@@ -124,7 +124,7 @@ def get_current_line(self):
offset_start, offset_end = self.get_current_line_range()
iter_start = self.buffer.get_iter_at_offset(offset_start)
iter_end = self.buffer.get_iter_at_offset(offset_end)
- return self.buffer.get_text(iter_start, iter_end).decode(self.encoding)
+ return self.buffer.get_text(iter_start, iter_end, False).decode(self.encoding)
def replace_content(self, value, offset_start=None, offset_end=None):
"""
@@ -170,7 +170,7 @@ def get_content(self):
"""
iter_start = self.buffer.get_iter_at_offset(0)
iter_end = self.get_end_iter()
- return self.buffer.get_text(iter_start, iter_end).decode(self.encoding)
+ return self.buffer.get_text(iter_start, iter_end, False).decode(self.encoding)
def get_syntax(self):
"""