[gedit/wip/redesign2: 2/19] Port snippets to new menu api
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/redesign2: 2/19] Port snippets to new menu api
- Date: Sun, 5 Jan 2014 15:10:22 +0000 (UTC)
commit 258cfc85174a49e119dead4a533f1b656e01c53b
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Jan 2 15:11:20 2014 +0100
Port snippets to new menu api
plugins/snippets/snippets/manager.py | 27 +++++++++++------------
plugins/snippets/snippets/snippets.ui | 24 +++-----------------
plugins/snippets/snippets/windowactivatable.py | 27 ++++++++----------------
3 files changed, 26 insertions(+), 52 deletions(-)
---
diff --git a/plugins/snippets/snippets/manager.py b/plugins/snippets/snippets/manager.py
index 7ff7342..6cdf061 100644
--- a/plugins/snippets/snippets/manager.py
+++ b/plugins/snippets/snippets/manager.py
@@ -288,10 +288,10 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
self.builder = builder
handlers_dic = {
- 'on_action_new_snippet_activated': self.on_action_new_snippet_activated,
- 'on_action_remove_snippet_activated': self.on_action_remove_snippet_activated,
- 'on_action_import_snippets_activated': self.on_action_import_snippets_activated,
- 'on_action_export_snippets_activated': self.on_action_export_snippets_activated,
+ 'on_add_snippet_button_clicked': self.on_add_snippet_button_clicked,
+ 'on_remove_snippet_button_clicked': self.on_remove_snippet_button_clicked,
+ 'on_import_snippets_button_clicked': self.on_import_snippets_button_clicked,
+ 'on_export_snippets_button_clickded': self.on_export_snippets_button_clicked,
'on_entry_tab_trigger_focus_out': self.on_entry_tab_trigger_focus_out,
'on_entry_tab_trigger_changed': self.on_entry_tab_trigger_changed,
'on_entry_accelerator_focus_out': self.on_entry_accelerator_focus_out,
@@ -392,18 +392,17 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
return (override, remove, system)
def update_toolbar_buttons(self):
- action_remove = self['remove_snippet_action']
- action_add = self['add_snippet_action']
+ button_add = self['add_snippet_button']
button_remove = self['remove_snippet_button']
- action_add.set_sensitive(self.language_path != None)
+ button_add.set_sensitive(self.language_path != None)
override, remove, system = self.selected_snippets_state()
if not (override ^ remove) or system:
- action_remove.set_sensitive(False)
+ button_remove.set_sensitive(False)
button_remove.set_icon_name('list-remove-symbolic')
else:
- action_remove.set_sensitive(True)
+ button_remove.set_sensitive(True)
if override:
button_remove.set_icon_name('edit-undo-symbolic')
@@ -714,7 +713,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
self.snippet['text'] = text
self.snippet_changed()
- def on_action_new_snippet_activated(self, action):
+ def on_add_snippet_button_clicked(self, button):
snippet = self.new_snippet()
if not snippet:
@@ -785,7 +784,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
self.import_snippets(f)
- def on_action_import_snippets_activated(self, action):
+ def on_import_snippets_button_clicked(self, button):
dlg = Gtk.FileChooserDialog(parent=self.get_toplevel(), title=_("Import snippets"),
action=Gtk.FileChooserAction.OPEN,
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
@@ -893,7 +892,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
else:
return self.export_snippets_real(filename, export_snippets, show_dialogs)
- def on_action_export_snippets_activated(self, action):
+ def on_export_snippets_button_clicked(self, button):
snippets = self.selected_snippets()
if not snippets or len(snippets) == 0:
@@ -975,7 +974,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
self.tree_view.expand_row(self.model.get_path(parent), False)
return dummy
- def on_action_remove_snippet_activated(self, action):
+ def on_remove_snippet_button_clicked(self, button):
override, remove, system = self.selected_snippets_state()
if not (override ^ remove) or system:
@@ -1109,7 +1108,7 @@ class Manager(Gtk.Dialog, Gtk.Buildable):
def on_tree_view_snippets_key_press(self, treeview, event):
if event.keyval == Gdk.keyval_from_name('Delete'):
- self.on_action_remove_snippet_activated(None)
+ self.on_remove_snippet_button_clicked(None)
return True
def on_tree_view_snippets_row_expanded(self, treeview, piter, path):
diff --git a/plugins/snippets/snippets/snippets.ui b/plugins/snippets/snippets/snippets.ui
index a8327e0..5595557 100644
--- a/plugins/snippets/snippets/snippets.ui
+++ b/plugins/snippets/snippets/snippets.ui
@@ -1,15 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <object class="GtkAction" id="add_snippet_action">
- <signal name="activate" handler="on_action_new_snippet_activated" swapped="no"/>
- </object>
- <object class="GtkAction" id="export_snippets_action">
- <signal name="activate" handler="on_action_export_snippets_activated" swapped="no"/>
- </object>
- <object class="GtkAction" id="import_snippets_action">
- <signal name="activate" handler="on_action_import_snippets_activated" swapped="no"/>
- </object>
<object class="GtkListStore" id="model1">
<columns>
<!-- column-name gchararray -->
@@ -42,9 +33,6 @@
</row>
</data>
</object>
- <object class="GtkAction" id="remove_snippet_action">
- <signal name="activate" handler="on_action_remove_snippet_activated" swapped="no"/>
- </object>
<object class="GeditDocument" id="source_buffer"/>
<object class="GeditSnippetsManager" id="snippets_manager">
<property name="visible">True</property>
@@ -181,11 +169,10 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Create new snippet</property>
<property name="tooltip_text" translatable="yes">Create new snippet</property>
- <property name="related_action">add_snippet_action</property>
- <property name="use_action_appearance">False</property>
<property name="label" translatable="yes">Add Snippet</property>
<property name="use_underline">True</property>
<property name="icon_name">list-add-symbolic</property>
+ <signal name="clicked" handler="on_add_snippet_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -199,11 +186,10 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Delete selected
snippet</property>
<property name="tooltip_text" translatable="yes">Delete selected
snippet</property>
- <property name="related_action">remove_snippet_action</property>
- <property name="use_action_appearance">False</property>
<property name="label" translatable="yes">Remove Snippet</property>
<property name="use_underline">True</property>
<property name="icon_name">list-remove-symbolic</property>
+ <signal name="clicked" handler="on_remove_snippet_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -217,11 +203,10 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Import snippets</property>
<property name="tooltip_text" translatable="yes">Import snippets</property>
- <property name="related_action">import_snippets_action</property>
- <property name="use_action_appearance">False</property>
<property name="label" translatable="yes">Import Snippets</property>
<property name="use_underline">True</property>
<property name="icon_name">document-open-symbolic</property>
+ <signal name="clicked" handler="on_import_snippets_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -235,11 +220,10 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Export selected
snippets</property>
<property name="tooltip_text" translatable="yes">Export selected
snippets</property>
- <property name="related_action">export_snippets_action</property>
- <property name="use_action_appearance">False</property>
<property name="label" translatable="yes">Export Snippets</property>
<property name="use_underline">True</property>
<property name="icon_name">document-save-as-symbolic</property>
+ <signal name="clicked" handler="on_export_snippets_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
diff --git a/plugins/snippets/snippets/windowactivatable.py b/plugins/snippets/snippets/windowactivatable.py
index d34e279..ab5e038 100644
--- a/plugins/snippets/snippets/windowactivatable.py
+++ b/plugins/snippets/snippets/windowactivatable.py
@@ -19,7 +19,7 @@ import re
import os
import gettext
-from gi.repository import Gtk, Gdk, Gedit, GObject
+from gi.repository import Gtk, Gdk, Gedit, GObject, Gio
from .document import Document
from .library import Library
@@ -146,25 +146,16 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable, Signals):
controller.parse_and_run_snippet(message.props.snippet, iter)
def insert_menu(self):
- manager = self.window.get_ui_manager()
+ action = Gio.SimpleAction(name="snippets")
+ action.connect('activate', self.on_action_snippets_activate)
+ self.window.add_action(action)
- self.action_group = Gtk.ActionGroup("GeditSnippetPluginActions")
- self.action_group.set_translation_domain('gedit')
- self.action_group.add_actions([('ManageSnippets', None,
- _('Manage _Snippets...'), \
- None, _('Manage snippets'), \
- self.on_action_snippets_activate)])
-
- 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.UIManagerItemType.MENUITEM, False)
+ item = Gio.MenuItem.new(_("Manage _Snippets..."), "win.snippets")
+ self.menu = self.extend_gear_menu("ext9")
+ self.menu.append_menu_item(item)
def remove_menu(self):
- manager = self.window.get_ui_manager()
- manager.remove_ui(self.merge_id)
- manager.remove_action_group(self.action_group)
- self.action_group = None
+ self.window.remove_action("snippets")
def find_snippet(self, snippets, tag):
result = []
@@ -205,7 +196,7 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable, Signals):
def create_configure_dialog(self):
SharedData().show_manager(self.window, self.plugin_info.get_data_dir())
- def on_action_snippets_activate(self, action):
+ def on_action_snippets_activate(self, action, parameter):
self.create_configure_dialog()
def accelerator_activated(self, group, obj, keyval, mod):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]