[shotwell] Fix Undo/Redo adaptive labeling
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell] Fix Undo/Redo adaptive labeling
- Date: Mon, 5 Dec 2016 22:43:12 +0000 (UTC)
commit 81c6c321ab01313b4a55b24fc8c645d43561e85e
Author: Jens Georg <mail jensge org>
Date: Mon Dec 5 23:42:05 2016 +0100
Fix Undo/Redo adaptive labeling
Signed-off-by: Jens Georg <mail jensge org>
src/AppWindow.vala | 67 +++++++++++++++++++++++++++++++++++++++++++--------
src/Page.vala | 45 ++++-------------------------------
2 files changed, 61 insertions(+), 51 deletions(-)
---
diff --git a/src/AppWindow.vala b/src/AppWindow.vala
index 4d9bb27..99f054d 100644
--- a/src/AppWindow.vala
+++ b/src/AppWindow.vala
@@ -783,6 +783,51 @@ public abstract class AppWindow : PageWindow {
if (page != null)
update_common_actions(page, page.get_view().get_selected_count(), page.get_view().get_count());
}
+
+ public void update_menu_item_label (string id,
+ string new_label) {
+ var bar = this.get_current_page().get_menubar() as GLib.Menu;
+
+ if (bar == null) {
+ return;
+ }
+
+ var items = bar.get_n_items ();
+ for (var i = 0; i< items; i++) {
+ var model = bar.get_item_link (i, GLib.Menu.LINK_SUBMENU);
+ if (bar == null) {
+ continue;
+ }
+
+ var model_items = model.get_n_items ();
+ for (var j = 0; j < model_items; j++) {
+ var subsection = model.get_item_link (j, GLib.Menu.LINK_SECTION);
+
+ if (subsection == null)
+ continue;
+
+ // Recurse into submenus
+ var sub_items = subsection.get_n_items ();
+ for (var k = 0; k < sub_items; k++) {
+ var it = subsection.iterate_item_attributes (k);
+ while (it.next ()) {
+ if ((it.get_name() == "id" && it.get_value ().get_string () == id) ||
+ (it.get_name() == "action" && it.get_value().get_string().has_suffix("." + id)))
{
+ var md = subsection as GLib.Menu;
+ var m = new GLib.MenuItem.from_model (subsection, k);
+ m.set_label (new_label);
+ md.remove (k);
+ md.insert_item (k, m);
+
+ return;
+ }
+ }
+ }
+ }
+ }
+ }
+
+
public static CommandManager get_command_manager() {
return command_manager;
@@ -795,21 +840,21 @@ public abstract class AppWindow : PageWindow {
private void decorate_command_manager_action(string name, string prefix,
string default_explanation, CommandDescription? desc) {
-#if 0
- Gtk.Action? action = get_common_action(name);
- if (action == null)
+ var action = get_common_action(name) as GLib.SimpleAction;
+ if (action == null) {
return;
-
+ }
+
+ string label = prefix;
+
if (desc != null) {
- action.label = "%s %s".printf(prefix, desc.get_name());
- action.tooltip = desc.get_explanation();
- action.sensitive = true;
+ label += " " + desc.get_name();
+ action.set_enabled(true);
} else {
- action.label = prefix;
- action.tooltip = default_explanation;
- action.sensitive = false;
+ label = prefix;
+ action.set_enabled(false);
}
-#endif
+ this.update_menu_item_label(name, label);
}
public void decorate_undo_action() {
diff --git a/src/Page.vala b/src/Page.vala
index c3e7802..a65a1e2 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -207,6 +207,9 @@ public abstract class Page : Gtk.ScrolledWindow {
private bool menubar_injected = false;
public GLib.MenuModel get_menubar() {
var model = builder.get_object ("MenuBar") as GLib.Menu;
+ if (model == null) {
+ return new GLib.Menu();
+ }
if (!menubar_injected) {
// Collect injected UI elements and add them to the UI manager
@@ -1147,46 +1150,8 @@ public abstract class Page : Gtk.ScrolledWindow {
}
protected void update_menu_item_label (string id,
- string new_label) {
- var bar = this.builder.get_object ("MenuBar") as GLib.Menu;
-
- if (bar == null) {
- return;
- }
-
- var items = bar.get_n_items ();
- for (var i = 0; i< items; i++) {
- var model = bar.get_item_link (i, GLib.Menu.LINK_SUBMENU);
- if (bar == null) {
- continue;
- }
-
- var model_items = model.get_n_items ();
- for (var j = 0; j < model_items; j++) {
- var subsection = model.get_item_link (j, GLib.Menu.LINK_SECTION);
-
- if (subsection == null)
- continue;
-
- // Recurse into submenus
- var sub_items = subsection.get_n_items ();
- for (var k = 0; k < sub_items; k++) {
- var it = subsection.iterate_item_attributes (k);
- while (it.next ()) {
- if ((it.get_name() == "id" && it.get_value ().get_string () == id) ||
- (it.get_name() == "action" && it.get_value().get_string().has_suffix("." + id)))
{
- var md = subsection as GLib.Menu;
- var m = new GLib.MenuItem.from_model (subsection, k);
- m.set_label (new_label);
- md.remove (k);
- md.insert_item (k, m);
-
- return;
- }
- }
- }
- }
- }
+ string new_label) {
+ AppWindow.get_instance().update_menu_item_label (id, new_label);
}
protected GLib.MenuModel? find_extension_point (GLib.MenuModel model,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]