[gnome-clocks/wip/vala] Add selection menu
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/wip/vala] Add selection menu
- Date: Sun, 17 Feb 2013 14:29:44 +0000 (UTC)
commit fa00e899cfe052b1fd125d48e93ddbb9eaf46ed5
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Feb 17 15:29:13 2013 +0100
Add selection menu
src/alarm.vala | 8 ++++++++
src/clock.vala | 6 ++++++
src/menu.ui | 13 +++++++++++++
src/widgets.vala | 33 +++++++++++++++++++++++++++------
src/window.vala | 15 ++++++++++++++-
src/world.vala | 8 ++++++++
6 files changed, 76 insertions(+), 7 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index a60fb25..cdfe8ac 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -520,6 +520,14 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
dialog.show_all ();
}
+ public void activate_select_all () {
+ icon_view.select_all ();
+ }
+
+ public void activate_select_none () {
+ icon_view.unselect_all ();
+ }
+
public void update_toolbar () {
switch (toolbar.mode) {
case Toolbar.Mode.NORMAL:
diff --git a/src/clock.vala b/src/clock.vala
index a260505..96cede9 100644
--- a/src/clock.vala
+++ b/src/clock.vala
@@ -25,6 +25,12 @@ public interface Clock : GLib.Object {
public virtual void activate_new () {
}
+ public virtual void activate_select_all () {
+ }
+
+ public virtual void activate_select_none () {
+ }
+
public virtual void update_toolbar () {
}
}
diff --git a/src/menu.ui b/src/menu.ui
index 105f87b..37d050f 100644
--- a/src/menu.ui
+++ b/src/menu.ui
@@ -21,4 +21,17 @@
</item>
</section>
</menu>
+ <menu id="selection-menu">
+ <section>
+ <item>
+ <attribute name="action">win.select-all</attribute>
+ <attribute name="label" translatable="yes">Select All</attribute>
+ <attribute name="accel"><Primary>a</attribute>
+ </item>
+ <item>
+ <attribute name="action">win.select-none</attribute>
+ <attribute name="label" translatable="yes">Select None</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/src/widgets.vala b/src/widgets.vala
index 31a6c42..528169f 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -229,11 +229,6 @@ public class IconView : Gtk.IconView {
// clear selection
if (_mode != Mode.SELECTION) {
unselect_all ();
- var model = get_model () as Gtk.ListStore;
- model.foreach ((model, path, iter) => {
- ((Gtk.ListStore) model).set (iter, selection_col, false);
- return false;
- });
}
thumb_renderer.toggle_visible = (_mode == Mode.SELECTION);
@@ -291,7 +286,8 @@ public class IconView : Gtk.IconView {
return false;
}
- // Redefine since we handle selection manually
+ // Redefine selection handling methods since we handle selection manually
+
public new List<Gtk.TreePath>? get_selected_items () {
List<Gtk.TreePath>? items = null;
model.foreach ((model, path, iter) => {
@@ -305,6 +301,24 @@ public class IconView : Gtk.IconView {
items.reverse ();
return (owned) items;
}
+
+ public new void select_all () {
+ var model = get_model () as Gtk.ListStore;
+ model.foreach ((model, path, iter) => {
+ ((Gtk.ListStore) model).set (iter, selection_col, true);
+ return false;
+ });
+ selection_changed ();
+ }
+
+ public new void unselect_all () {
+ var model = get_model () as Gtk.ListStore;
+ model.foreach ((model, path, iter) => {
+ ((Gtk.ListStore) model).set (iter, selection_col, false);
+ return false;
+ });
+ selection_changed ();
+ }
}
public class ContentView : Gtk.Bin {
@@ -315,6 +329,7 @@ public class ContentView : Gtk.Bin {
private Gtk.Widget empty_page;
private IconView icon_view;
private Toolbar main_toolbar;
+ private GLib.MenuModel selection_menu;
private Gtk.Toolbar selection_toolbar;
private Gtk.Overlay overlay;
private Gtk.ScrolledWindow scrolled_window;
@@ -324,6 +339,9 @@ public class ContentView : Gtk.Bin {
icon_view = iv;
main_toolbar = t;
+ var builder = Utils.load_ui ("menu.ui");
+ selection_menu = builder.get_object ("selection-menu") as GLib.MenuModel;
+
overlay = new Gtk.Overlay ();
overlay.add (icon_view);
@@ -425,6 +443,7 @@ public class ContentView : Gtk.Bin {
case Toolbar.Mode.SELECTION:
var done_button = main_toolbar.add_button (null, _("Done"), false);
main_toolbar.set_labels (_("Click on items to select them"), null);
+ main_toolbar.set_labels_menu (selection_menu);
done_button.get_style_context ().add_class ("suggested-action");
done_button.clicked.connect (() => {
selection_toolbar.set_visible (false);
@@ -432,6 +451,8 @@ public class ContentView : Gtk.Bin {
});
break;
case Toolbar.Mode.NORMAL:
+ main_toolbar.set_labels (null, null);
+ main_toolbar.set_labels_menu (null);
var select_button = main_toolbar.add_button ("object-select-symbolic", null, false);
select_button.clicked.connect (() => {
icon_view.mode = IconView.Mode.SELECTION;
diff --git a/src/window.vala b/src/window.vala
index 4078afc..dfefa64 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -24,8 +24,13 @@ public class Window : Gtk.ApplicationWindow {
private const int DEFAULT_HEIGHT = 540;
private const GLib.ActionEntry[] action_entries = {
+ // app menu
{ "new", on_new_activate },
- { "about", on_about_activate }
+ { "about", on_about_activate },
+
+ // selection menu
+ { "select-all", on_select_all_activate },
+ { "select-none", on_select_none_activate }
};
private Toolbar toolbar;
@@ -108,6 +113,14 @@ public class Window : Gtk.ApplicationWindow {
((Clock) stack.visible_child).activate_new ();
}
+ private void on_select_all_activate () {
+ ((Clock) stack.visible_child).activate_select_all ();
+ }
+
+ private void on_select_none_activate () {
+ ((Clock) stack.visible_child).activate_select_none ();
+ }
+
private void on_about_activate () {
const string copyright = "Copyright \xc2\xa9 2011 Collabora Ltd.\n" +
"Copyright \xc2\xa9 2012-2013 Collabora Ltd., Seif Lotfy, Emily Gonyer\n" +
diff --git a/src/world.vala b/src/world.vala
index fbf25bb..a6f06c2 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -341,6 +341,14 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
dialog.show ();
}
+ public void activate_select_all () {
+ icon_view.select_all ();
+ }
+
+ public void activate_select_none () {
+ icon_view.unselect_all ();
+ }
+
public void update_toolbar () {
toolbar.clear ();
switch (toolbar.mode) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]