[gnome-clocks/zbrown/ditch-selection-mode: 3/3] general: ditch the remains of selection mode
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/zbrown/ditch-selection-mode: 3/3] general: ditch the remains of selection mode
- Date: Sun, 23 Feb 2020 18:47:12 +0000 (UTC)
commit d7c1ceefc8f0317355dd0711777d8b27a311f7db
Author: Zander Brown <zbrown gnome org>
Date: Sun Feb 23 18:43:54 2020 +0000
general: ditch the remains of selection mode
data/gnome-clocks.gresource.xml | 1 -
data/gtk/menus.ui | 16 ---
data/ui/headerbar.ui | 64 ---------
src/alarm.vala | 6 -
src/application.vala | 1 -
src/clock.vala | 14 --
src/headerbar.vala | 39 -----
src/stopwatch.vala | 2 -
src/timer.vala | 5 -
src/widgets.vala | 307 ----------------------------------------
src/window.vala | 40 ------
src/world.vala | 5 -
12 files changed, 500 deletions(-)
---
diff --git a/data/gnome-clocks.gresource.xml b/data/gnome-clocks.gresource.xml
index 83fab71..3f03601 100644
--- a/data/gnome-clocks.gresource.xml
+++ b/data/gnome-clocks.gresource.xml
@@ -3,7 +3,6 @@
<gresource prefix="/org/gnome/clocks">
<file>css/gnome-clocks.css</file>
<file>css/gnome-clocks.highcontrast.css</file>
- <file preprocess="xml-stripblanks">gtk/menus.ui</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file preprocess="xml-stripblanks">ui/window.ui</file>
<file preprocess="xml-stripblanks">ui/headerbar.ui</file>
diff --git a/data/ui/headerbar.ui b/data/ui/headerbar.ui
index 8e07ef9..9302e62 100644
--- a/data/ui/headerbar.ui
+++ b/data/ui/headerbar.ui
@@ -78,15 +78,6 @@
<property name="name">switcher</property>
</packing>
</child>
- <child>
- <object class="ClocksSelectionMenuButton">
- <property name="visible">True</property>
- <property name="n-items" bind-source="ClocksHeaderBar" bind-property="n-selected"
bind-flags="sync-create" />
- </object>
- <packing>
- <property name="name">selection</property>
- </packing>
- </child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@@ -206,19 +197,6 @@
<property name="name">menu</property>
</packing>
</child>
- <child>
- <object class="GtkButton">
- <property name="label" translatable="yes">_Cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="action_name">win.select-cancel</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="name">cancel</property>
- </packing>
- </child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@@ -234,48 +212,6 @@
<property name="pack_type">end</property>
</packing>
</child>
- <child>
- <object class="GtkStack" id="select_stack">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="transition_type">crossfade</property>
- <child>
- <object class="GtkButton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="action_name">win.select</property>
- <property name="tooltip-text" translatable="yes">Select</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">object-select-symbolic</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="name">select</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="name">empty</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="pack_type">end</property>
- </packing>
- </child>
</template>
<object class="GtkStack" id="ignore-me"></object>
</interface>
diff --git a/src/alarm.vala b/src/alarm.vala
index c23283e..5e5cfcc 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -39,10 +39,6 @@ private class Item : Object, ContentItem {
public string title_icon { get; set; default = null; }
- public bool selectable { get; set; default = true; }
-
- public bool selected { get; set; default = false; }
-
public bool editing { get; set; default = false; }
public string id { get; construct set; }
@@ -789,8 +785,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
public ViewMode view_mode { get; set; default = NORMAL; }
public PanelId panel_id { get; construct set; }
public ButtonMode button_mode { get; set; default = NEW; }
- public bool can_select { get; set; default = false; }
- public bool n_selected { get; set; }
public string title { get; set; default = _("Clocks"); }
public string subtitle { get; set; }
// Translators: Tooltip for the + button
diff --git a/src/application.vala b/src/application.vala
index 509ce54..24ac931 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -131,7 +131,6 @@ public class Application : Gtk.Application {
update_theme (settings);
set_accels_for_action ("win.new", { "<Primary>n" });
- set_accels_for_action ("win.select-all", { "<Primary>a" });
set_accels_for_action ("win.show-primary-menu", { "F10" });
set_accels_for_action ("win.show-help-overlay", { "<Primary>question" });
set_accels_for_action ("win.help", { "F1" });
diff --git a/src/clock.vala b/src/clock.vala
index 404ad89..739edae 100644
--- a/src/clock.vala
+++ b/src/clock.vala
@@ -28,8 +28,6 @@ public interface Clocks.Clock : GLib.Object {
public abstract PanelId panel_id { get; protected construct set; }
public abstract ButtonMode button_mode { get; set; }
public abstract ViewMode view_mode { get; set; }
- public abstract bool can_select { get; set; }
- public abstract bool n_selected { get; set; }
public abstract string title { get; protected set; }
public abstract string subtitle { get; protected set; }
public abstract string new_label { get; }
@@ -40,18 +38,6 @@ public interface Clocks.Clock : GLib.Object {
public virtual void activate_back () {
}
- public virtual void activate_select () {
- }
-
- public virtual void activate_select_cancel () {
- }
-
- public virtual void activate_select_all () {
- }
-
- public virtual void activate_select_none () {
- }
-
public virtual bool escape_pressed () {
return false;
}
diff --git a/src/headerbar.vala b/src/headerbar.vala
index 367e662..90d3eaf 100644
--- a/src/headerbar.vala
+++ b/src/headerbar.vala
@@ -28,7 +28,6 @@ public enum Clocks.ButtonMode {
public enum Clocks.ViewMode {
NORMAL,
- SELECTION,
STANDALONE
}
@@ -46,22 +45,10 @@ public class Clocks.HeaderBar : Hdy.HeaderBar {
var width = get_allocated_width ();
switch (_mode) {
- case SELECTION:
- title_stack.visible_child_name = "selection";
- get_style_context ().add_class ("selection-mode");
- start_button_stack.hide ();
- end_button_stack.show ();
- select_stack.hide ();
- end_button_stack.visible_child_name = "cancel";
- centering_policy = LOOSE;
- switcher_bar.reveal = width <= 500;
- break;
case NORMAL:
title_stack.visible_child_name = "switcher";
- get_style_context ().remove_class ("selection-mode");
start_button_stack.show ();
end_button_stack.show ();
- select_stack.show ();
end_button_stack.visible_child_name = "menu";
centering_policy = STRICT;
switcher_bar.reveal = width <= 500;
@@ -70,13 +57,10 @@ public class Clocks.HeaderBar : Hdy.HeaderBar {
title_stack.visible_child_name = "title";
start_button_stack.show ();
end_button_stack.hide ();
- select_stack.hide ();
centering_policy = STRICT;
switcher_bar.reveal = false;
break;
}
-
- show_close_button = _mode != SELECTION;
}
}
@@ -101,35 +85,16 @@ public class Clocks.HeaderBar : Hdy.HeaderBar {
}
}
- public bool can_select {
- get {
- return _can_select;
- }
-
- set {
- _can_select = value;
- if (_can_select) {
- select_stack.visible_child_name = "select";
- } else {
- select_stack.visible_child_name = "empty";
- }
- }
- }
-
public Gtk.Stack stack { get; set; }
public Hdy.ViewSwitcherBar switcher_bar { get; set; }
- public uint n_selected { get; set; }
public string new_label { get; set; }
- private bool _can_select;
private ViewMode _mode;
private ButtonMode _button_mode;
[GtkChild]
private Gtk.Stack start_button_stack;
[GtkChild]
- private Gtk.Stack select_stack;
- [GtkChild]
private Gtk.Stack end_button_stack;
[GtkChild]
private Hdy.Squeezer squeezer;
@@ -144,10 +109,6 @@ public class Clocks.HeaderBar : Hdy.HeaderBar {
[GtkChild]
private Gtk.Revealer reveal_subtitle;
- class construct {
- typeof (SelectionMenuButton).ensure ();
- }
-
public override void size_allocate (Gtk.Allocation allocation) {
base.size_allocate (allocation);
squeezer.set_child_enabled (title_wide_switcher, allocation.width > 800);
diff --git a/src/stopwatch.vala b/src/stopwatch.vala
index 7a2077c..88c6039 100644
--- a/src/stopwatch.vala
+++ b/src/stopwatch.vala
@@ -119,8 +119,6 @@ public class Face : Gtk.Box, Clocks.Clock {
public PanelId panel_id { get; construct set; }
public ButtonMode button_mode { get; set; default = NONE; }
public ViewMode view_mode { get; set; default = NORMAL; }
- public bool can_select { get; set; default = false; }
- public bool n_selected { get; set; }
public string title { get; set; default = _("Clocks"); }
public string subtitle { get; set; }
public string new_label { get; default = null; }
diff --git a/src/timer.vala b/src/timer.vala
index 523029b..2ea8342 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -29,9 +29,6 @@ public class Item : Object, ContentItem {
public State state { get; private set; default = State.STOPPED; }
- public bool selectable { get; set; default = false; }
- public bool selected { get; set; default = false; }
-
public string name { get ; set; }
public int hours { get; set; default = 0; }
public int minutes { get; set; default = 0; }
@@ -407,8 +404,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
public ButtonMode button_mode { get; set; default = NONE; }
public ViewMode view_mode { get; set; default = NORMAL; }
public bool is_running { get; set; default = false; }
- public bool can_select { get; set; default = false; }
- public bool n_selected { get; set; }
public string title { get; set; default = _("Clocks"); }
public string subtitle { get; set; }
// Translators: Tooltip for the + button
diff --git a/src/widgets.vala b/src/widgets.vala
index 3d1f3b0..8542917 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -20,8 +20,6 @@ namespace Clocks {
public interface ContentItem : GLib.Object {
public abstract string name { get; set; }
- public abstract bool selectable { get; set; default = true; }
- public abstract bool selected { get; set; default = false; }
public abstract void serialize (GLib.VariantBuilder builder);
}
@@ -29,7 +27,6 @@ public class ContentStore : GLib.Object, GLib.ListModel {
private ListStore store;
private CompareDataFunc sort_func;
- public signal void selection_changed ();
public ContentStore () {
store = new ListStore (typeof (ContentItem));
@@ -58,18 +55,12 @@ public class ContentStore : GLib.Object, GLib.ListModel {
assert (store.get_n_items () == 0);
}
- private void on_item_selection_toggle (Object o, ParamSpec p) {
- selection_changed ();
- }
-
public void add (ContentItem item) {
if (sort_func == null) {
store.append (item);
} else {
store.insert_sorted (item, sort_func);
}
-
- item.notify["selected"].connect (on_item_selection_toggle);
}
public int get_index (ContentItem item) {
@@ -114,18 +105,6 @@ public class ContentStore : GLib.Object, GLib.ListModel {
return null;
}
- public uint get_n_selected () {
- uint n_selected = 0;
- var n = store.get_n_items ();
- for (int i = 0; i < n; i++) {
- var item = store.get_object (i) as ContentItem;
- if (item.selected) {
- n_selected++;
- }
- }
- return n_selected;
- }
-
public void delete_item (ContentItem item) {
var n = store.get_n_items ();
for (int i = 0; i < n; i++) {
@@ -137,66 +116,11 @@ public class ContentStore : GLib.Object, GLib.ListModel {
store.sort (sort_func);
}
- selection_changed ();
-
return;
}
}
}
- public void delete_selected () {
- // remove everything and readd the ones not selected
- uint n_deleted = 0;
- Object[] not_selected = {};
- var n = store.get_n_items ();
- for (int i = 0; i < n; i++) {
- var o = store.get_object (i);
- if (!((ContentItem)o).selected) {
- not_selected += o;
- } else {
- n_deleted++;
- SignalHandler.disconnect_by_func (o, (void *)on_item_selection_toggle, (void *)this);
- }
- }
-
- if (n_deleted > 0) {
- store.splice (0, n, not_selected);
- if (sort_func != null) {
- store.sort (sort_func);
- }
-
- selection_changed ();
- }
- }
-
- private void select_unselect_all (bool select) {
- uint n_toggled = 0;
-
- var n = store.get_n_items ();
- for (int i = 0; i < n; i++) {
- var item = store.get_object (i) as ContentItem;
- var selected = item.selectable && select;
- if (selected != item.selected) {
- SignalHandler.block_by_func (item, (void *)on_item_selection_toggle, (void *)this);
- item.selected = selected;
- SignalHandler.unblock_by_func (item, (void *)on_item_selection_toggle, (void *)this);
- n_toggled++;
- }
- }
-
- if (n_toggled > 0) {
- selection_changed ();
- }
- }
-
- public void select_all () {
- select_unselect_all (true);
- }
-
- public void unselect_all () {
- select_unselect_all (false);
- }
-
public Variant serialize () {
var builder = new GLib.VariantBuilder (new VariantType ("aa{sv}"));
var n = store.get_n_items ();
@@ -219,237 +143,6 @@ public class ContentStore : GLib.Object, GLib.ListModel {
}
}
-private class SelectionMenuButton : Gtk.MenuButton {
- public uint n_items {
- get {
- return _n_items;
- }
- set {
- if (_n_items != value) {
- _n_items = value;
- string label;
- if (n_items == 0) {
- label = _("Click on items to select them");
- } else {
- label = ngettext ("%u selected", "%u selected", n_items).printf (n_items);
- }
- menubutton_label.label = label;
- }
- }
- }
-
- private uint _n_items;
- private Gtk.Label menubutton_label;
-
- construct {
- var app = (Gtk.Application) GLib.Application.get_default ();
- menu_model = app.get_menu_by_id ("selection-menu");
- menubutton_label = new Gtk.Label (_("Click on items to select them"));
- var arrow = new Gtk.Image.from_icon_name ("pan-down-symbolic", Gtk.IconSize.BUTTON);
- var grid = new Gtk.Grid ();
- grid.set_column_spacing (6);
- grid.attach (menubutton_label, 0, 0, 1, 1);
- grid.attach (arrow, 1, 0, 1, 1);
- add (grid);
- valign = Gtk.Align.CENTER;
- get_style_context ().add_class ("selection-menu");
- show_all ();
- }
-}
-
-public class ContentView : Gtk.Bin {
- public ViewMode mode {
- get {
- return _mode;
- }
-
- set {
- if (_mode != value) {
- _mode = value;
-
- switch (_mode) {
- case SELECTION:
- action_bar.show ();
- break;
- case NORMAL:
- case STANDALONE:
- action_bar.hide ();
- // clear current selection
- model.unselect_all ();
- break;
- }
- }
- }
- }
- public uint n_selected { get; private set; }
-
- private ViewMode _mode;
- private ContentStore model;
- private Gtk.FlowBox flow_box;
- private Gtk.Grid grid;
- private Gtk.ActionBar action_bar;
- private Gtk.Button delete_button;
-
- construct {
- get_style_context ().add_class ("content-view");
-
- flow_box = new Gtk.FlowBox ();
- flow_box.selection_mode = Gtk.SelectionMode.NONE;
- flow_box.min_children_per_line = 3;
-
- flow_box.child_activated.connect ((child) => {
- var item = model.get_item (child.get_index ()) as ContentItem;
- if (item != null) {
- item_activated (item);
- }
- });
-
- var scrolled_window = new Gtk.ScrolledWindow (null, null);
- scrolled_window.add (flow_box);
- scrolled_window.hexpand = true;
- scrolled_window.vexpand = true;
- scrolled_window.halign = Gtk.Align.FILL;
- scrolled_window.valign = Gtk.Align.FILL;
-
- grid = new Gtk.Grid ();
- grid.attach (scrolled_window, 0, 0, 1, 1);
-
- action_bar = new Gtk.ActionBar ();
- action_bar.no_show_all = true;
- grid.attach (action_bar, 0, 1, 1, 1);
-
- delete_button = new Gtk.Button ();
- delete_button.label = _("Delete");
- delete_button.visible = true;
- delete_button.sensitive = false;
- delete_button.halign = Gtk.Align.END;
- delete_button.hexpand = true;
- delete_button.clicked.connect (() => {
- model.delete_selected ();
- mode = NORMAL;
- });
-
- action_bar.pack_end (delete_button);
-
- add (grid);
- grid.show_all ();
- }
-
- public signal void item_activated (ContentItem item);
-
- public delegate Gtk.Widget ContentViewCreateWidgetFunc (ContentItem item);
-
- public void bind_model (ContentStore store, owned ContentViewCreateWidgetFunc create_func) {
- model = store;
-
- model.selection_changed.connect (() => {
- var n_items = model.get_n_selected ();
- n_selected = n_items;
-
- if (n_items != 0) {
- delete_button.sensitive = true;
- } else {
- delete_button.sensitive = false;
- }
- });
-
- flow_box.bind_model (model, (object) => {
- var item = (ContentItem) object;
- var inner = create_func (item);
-
- // wrap the widget in an event box to handle righ-click
- var event_box = new Gtk.EventBox ();
- event_box.add (inner);
- event_box.button_press_event.connect ((event) => {
- // On right click, switch to selection mode automatically
- if (item.selectable && event.button == Gdk.BUTTON_SECONDARY) {
- mode = SELECTION;
- }
-
- if (item.selectable && mode == SELECTION) {
- item.selected = !item.selected;
- return true;
- } else if (event.button == Gdk.BUTTON_PRIMARY) {
- item_activated (item);
- return true;
- }
-
- return false;
- });
-
- // wrap the widget in overlay for the selection check box
- var overlay = new Gtk.Overlay ();
- overlay.halign = Gtk.Align.START;
- overlay.valign = Gtk.Align.START;
- overlay.add (event_box);
-
- var check = new Gtk.CheckButton ();
- check.no_show_all = true;
- check.halign = Gtk.Align.END;
- check.valign = Gtk.Align.END;
- check.margin_bottom = 8;
- check.margin_end = 8;
-
- item.bind_property ("selected", check, "active", BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE
| BindingFlags.BIDIRECTIONAL);
- item.bind_property ("selectable", check, "visible", BindingFlags.DEFAULT |
BindingFlags.SYNC_CREATE,
- (binding, selectable, ref visible) => {
- visible = this.mode == SELECTION && (item).selectable;
- return true;
- });
-
- bind_property ("mode", check, "visible", BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE,
- (binding, mode, ref visible) => {
- visible = mode == ViewMode.SELECTION && (item).selectable;
- return true;
- });
-
- overlay.add_overlay (check);
-
- // manually wrap in flowboxchild ourselves since we want to set alignment
- var flow_box_child = new Gtk.FlowBoxChild ();
- flow_box_child.halign = Gtk.Align.START;
- flow_box_child.valign = Gtk.Align.START;
- flow_box_child.add (overlay);
- flow_box_child.get_style_context ().add_class ("tile");
-
- // flowbox does not handle :hover and setting the PRELIGHT state does not
- // seem to get propagated to the children despite what the documentation
- // says... emulate it ourselves with css classes :(
- event_box.enter_notify_event.connect ((event) => {
- flow_box_child.get_style_context ().add_class ("prelight");
- return false;
- });
-
- event_box.leave_notify_event.connect ((event) => {
- if (event.detail != Gdk.NotifyType.INFERIOR) {
- flow_box_child.get_style_context ().remove_class ("prelight");
- }
- return false;
- });
-
- flow_box_child.show_all ();
-
- return flow_box_child;
- });
- }
-
- public void select_all () {
- mode = SELECTION;
- model.select_all ();
- }
-
- public void unselect_all () {
- model.unselect_all ();
- }
-
- public bool escape_pressed () {
- if (mode == SELECTION) {
- mode = NORMAL;
- return true;
- }
- return false;
- }
-}
public class AmPmToggleButton : Gtk.Button {
public enum AmPm {
diff --git a/src/window.vala b/src/window.vala
index 820e73f..ab4e3fb 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -27,12 +27,6 @@ public class Window : Gtk.ApplicationWindow {
{ "back", on_back_activate },
{ "help", on_help_activate },
{ "about", on_about_activate },
- { "select", on_select_activate },
- { "select-cancel", on_select_cancel_activate },
-
- // selection menu
- { "select-all", on_select_all_activate },
- { "select-none", on_select_none_activate }
};
[GtkChild]
@@ -53,8 +47,6 @@ public class Window : Gtk.ApplicationWindow {
// DIY DzlBindingGroup
private Binding bind_button_mode = null;
private Binding bind_view_mode = null;
- private Binding bind_can_select = null;
- private Binding bind_selected = null;
private Binding bind_title = null;
private Binding bind_subtitle = null;
private Binding bind_new_label = null;
@@ -193,22 +185,6 @@ public class Window : Gtk.ApplicationWindow {
((Clock) stack.visible_child).activate_back ();
}
- private void on_select_activate () {
- ((Clock) stack.visible_child).activate_select ();
- }
-
- private void on_select_cancel_activate () {
- ((Clock) stack.visible_child).activate_select_cancel ();
- }
-
- 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 ();
- }
-
public void show_world () {
world.reset_view ();
stack.visible_child = world;
@@ -339,22 +315,6 @@ public class Window : Gtk.ApplicationWindow {
"view-mode",
SYNC_CREATE);
- if (bind_can_select != null) {
- bind_can_select.unbind ();
- }
- bind_can_select = panel.bind_property ("can-select",
- header_bar,
- "can-select",
- SYNC_CREATE);
-
- if (bind_selected != null) {
- bind_selected.unbind ();
- }
- bind_selected = panel.bind_property ("n-selected",
- header_bar,
- "n-selected",
- SYNC_CREATE);
-
if (bind_title != null) {
bind_title.unbind ();
}
diff --git a/src/world.vala b/src/world.vala
index 0f488a5..75e3d88 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -72,9 +72,6 @@ public class Item : Object, ContentItem {
public bool automatic { get; set; default = false; }
- public bool selectable { get; set; default = false; }
- public bool selected { get; set; default = false; }
-
public string name {
get {
// We store it in a _name member even if we overwrite it every time
@@ -495,8 +492,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
public PanelId panel_id { get; construct set; }
public ButtonMode button_mode { get; set; default = NEW; }
public ViewMode view_mode { get; set; default = NORMAL; }
- public bool can_select { get; set; default = false; }
- public bool n_selected { get; set; }
public string title { get; set; default = _("Clocks"); }
public string subtitle { get; set; }
// Translators: Tooltip for the + button
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]