Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for new standards, fixes #1 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 31 additions & 62 deletions YRedo.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,42 @@
from gi.repository import GObject, Gedit, Gtk
from gi.repository import GObject, Gedit, Gio

# Menu item example, insert a new item in the Tools menu
ui_str = """<ui>
<menubar name="MenuBar">
<menu name="EditMenu" action="Edit">
<placeholder name="EditOps_6">
<separator />
<menuitem name="EditYRedo" action="EditYRedo"/>
<separator />
</placeholder>
</menu>
</menubar>
</ui>
"""

class YRedoPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = "YRedoPlugin"
class YRedoPluginWindow(GObject.Object, Gedit.WindowActivatable):
window = GObject.Property(type=Gedit.Window)

window = GObject.property(type=Gedit.Window)

def __init__(self):
GObject.Object.__init__(self)
def __init__(self):
GObject.Object.__init__(self)

def do_activate(self):
self._insert_menu()
pass
def do_activate(self):
action = Gio.SimpleAction(name="yredo")
action.connect('activate', self._yredo_activate)
self.window.add_action(action)

def do_deactivate(self):
self._remove_menu()
self._action_group = None
pass
def _yredo_activate(self, action, parameter, user_data=None):
doc = self.window.get_active_document()
if not doc:
return
doc.redo()

def do_update_state(self):
pass

def _insert_menu(self):
# Get the Gtk.UIManager
manager = self.window.get_ui_manager()

# Create a new action group
self._action_group = Gtk.ActionGroup("YRedoPluginActions")
self._action_group.add_actions([("EditYRedo", Gtk.STOCK_REDO, _("Redo"),
"<Control>Y", _("Redo last action"),
self.on_redo_activate)])

# Insert the action group
manager.insert_action_group(self._action_group, -1)
class YRedoPlugin(GObject.Object, Gedit.AppActivatable):
__gtype_name__ = "YRedoPlugin"
app = GObject.Property(type=Gedit.App)

# Merge the UI
self._ui_id = manager.add_ui_from_string(ui_str)
def __init__(self):
GObject.Object.__init__(self)

def _remove_menu(self):
# Get the Gtk.UIManager
manager = self.window.get_ui_manager()
def do_activate(self):
self.app.set_accels_for_action("win.yredo", [
"<Control>Y"
])
# self.menu_ext = self.extend_menu("tools-section")
# item = Gio.MenuItem.new("YRedo", "win.yredo")
# self.menu_ext.prepend_menu_item(item)

# Remove the ui
manager.remove_ui(self._ui_id)
def do_deactivate(self):
self.app.set_accels_for_action("win.redo", [])
# self.menu_ext = None

# Remove the action group
manager.remove_action_group(self._action_group)

# Make sure the manager updates
manager.ensure_update()

# Menu activate handlers
def on_redo_activate(self, action):
doc = self.window.get_active_document()
if not doc:
return

doc.redo()

def do_update_state(self):
pass