[geary/wip/279-convo-list-context-labels: 1/4] Tidy up Shift Key handling in the Controller and MainWindow
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/279-convo-list-context-labels: 1/4] Tidy up Shift Key handling in the Controller and MainWindow
- Date: Sun, 4 Aug 2019 02:52:30 +0000 (UTC)
commit defb76ea88be1fa87846eba61445fa0520893bd2
Author: Michael Gratton <mike vee net>
Date: Sun Aug 4 12:46:23 2019 +1000
Tidy up Shift Key handling in the Controller and MainWindow
Add new MainWindow::is_shift_down property, move impl from Controller
there.
src/client/application/application-controller.vala | 19 ++++++-------------
src/client/components/main-toolbar.vala | 11 ++++++++---
src/client/components/main-window.vala | 20 +++++++++++++++++++-
3 files changed, 33 insertions(+), 17 deletions(-)
---
diff --git a/src/client/application/application-controller.vala
b/src/client/application/application-controller.vala
index 0bb01681..268d2b40 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -279,7 +279,6 @@ public class Application.Controller : Geary.BaseObject {
// Create the main window (must be done after creating actions.)
main_window = new MainWindow(this.application);
main_window.retry_service_problem.connect(on_retry_service_problem);
- main_window.on_shift_key.connect(on_shift_key);
main_window.notify["has-toplevel-focus"].connect(on_has_toplevel_focus);
setup_actions();
@@ -1049,9 +1048,12 @@ public class Application.Controller : Geary.BaseObject {
// Update widgets and such to match capabilities of the current folder ... sensitivity is handled
// by other utility methods
private void update_ui() {
- main_window.main_toolbar.selected_conversations = this.selected_conversations.size;
- main_window.main_toolbar.show_trash_button = current_folder_supports_trash() ||
- !(current_folder is Geary.FolderSupport.Remove);
+ this.main_window.main_toolbar.selected_conversations =
+ this.selected_conversations.size;
+ this.main_window.main_toolbar.update_trash_button(
+ !this.main_window.is_shift_down &&
+ current_folder_supports_trash()
+ );
}
private void on_folder_selected(Geary.Folder? folder) {
@@ -1424,15 +1426,6 @@ public class Application.Controller : Geary.BaseObject {
return sender.cancel_exit();
}
- private void on_shift_key(bool pressed) {
- if (main_window != null && main_window.main_toolbar != null
- && current_account != null && current_folder != null) {
- main_window.main_toolbar.show_trash_button =
- (!pressed && current_folder_supports_trash()) ||
- !(current_folder is Geary.FolderSupport.Remove);
- }
- }
-
// this signal does not necessarily indicate that the application previously didn't have
// focus and now it does
private void on_has_toplevel_focus() {
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 3dc590eb..e492d721 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -24,8 +24,7 @@ public class MainToolbar : Gtk.Box {
public FolderPopover move_folder_menu { get; private set; default = new FolderPopover(); }
// How many conversations are selected right now. Should automatically be updated.
public int selected_conversations { get; set; }
- // Whether to show the trash or the delete button
- public bool show_trash_button { get; set; default = true; }
+
// Folder header elements
[GtkChild]
@@ -52,6 +51,8 @@ public class MainToolbar : Gtk.Box {
[GtkChild]
private Gtk.ToggleButton find_button;
+ private bool show_trash_button = true;
+
// Load these at construction time
private Gtk.Image trash_image = new Gtk.Image.from_icon_name("user-trash-symbolic", Gtk.IconSize.MENU);
private Gtk.Image delete_image = new Gtk.Image.from_icon_name("edit-delete-symbolic", Gtk.IconSize.MENU);
@@ -84,7 +85,6 @@ public class MainToolbar : Gtk.Box {
// Setup conversation header elements
this.notify["selected-conversations"].connect(() => update_conversation_buttons());
- this.notify["show-trash-button"].connect(() => update_conversation_buttons());
this.mark_message_button.popover = new Gtk.Popover.from_model(null, mark_menu);
this.copy_message_button.popover = copy_folder_menu;
this.move_message_button.popover = move_folder_menu;
@@ -116,6 +116,11 @@ public class MainToolbar : Gtk.Box {
conversation_header.show();
}
+ public void update_trash_button(bool show_trash) {
+ this.show_trash_button = show_trash;
+ update_conversation_buttons();
+ }
+
private void set_window_buttons() {
string[] buttons = Gtk.Settings.get_default().gtk_decoration_layout.split(":");
this.show_close_button_left = this.show_close_button;
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 695a6096..6d04c416 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -28,6 +28,9 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
get; private set; default = null;
}
+ /** Specifies if the Shift key is currently being held. */
+ public bool is_shift_down { get; private set; default = false; }
+
private Geary.AggregateProgressMonitor progress_monitor = new Geary.AggregateProgressMonitor();
// Used to save/load the window state between sessions.
@@ -727,7 +730,12 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
Gtk.Widget? focus = get_focus();
if (focus == null ||
(!(focus is Gtk.Entry) && !(focus is ComposerWebView))) {
- on_shift_key(event.type == Gdk.EventType.KEY_PRESS);
+ this.is_shift_down = (event.type == Gdk.EventType.KEY_PRESS);
+ this.main_toolbar.update_trash_button(
+ !this.is_shift_down &&
+ current_folder_supports_trash()
+ );
+ on_shift_key(this.is_shift_down);
}
}
}
@@ -736,6 +744,16 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
return (SimpleAction) lookup_action(name);
}
+ private bool current_folder_supports_trash() {
+ Geary.Folder? current = this.current_folder;
+ return (
+ current != null &&
+ current.special_folder_type != TRASH &&
+ !current_folder.properties.is_local_only &&
+ (current_folder as Geary.FolderSupport.Move) != null
+ );
+ }
+
private void on_scan_completed(Geary.App.ConversationMonitor monitor) {
// Done scanning. Check if we have enough messages to fill
// the conversation list; if not, trigger a load_more();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]