[geary/wip/714104-refine-account-dialog] Enable reordering accounts and sender mailboxes via keyboard



commit 79c74c431012244afa71c6fed132826c0f8a0130
Author: Michael Gratton <mike vee net>
Date:   Sun Dec 2 16:19:55 2018 +1100

    Enable reordering accounts and sender mailboxes via keyboard

 src/client/accounts/accounts-editor-edit-pane.vala | 21 ++++++++++++---
 src/client/accounts/accounts-editor-list-pane.vala | 18 ++++++++++---
 src/client/accounts/accounts-editor-row.vala       | 31 ++++++++++++++++++++++
 src/client/accounts/accounts-editor.vala           |  2 ++
 4 files changed, 66 insertions(+), 6 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-edit-pane.vala 
b/src/client/accounts/accounts-editor-edit-pane.vala
index bb793d74..5043c8f1 100644
--- a/src/client/accounts/accounts-editor-edit-pane.vala
+++ b/src/client/accounts/accounts-editor-edit-pane.vala
@@ -175,6 +175,7 @@ internal class Accounts.EditorEditPane : Gtk.Grid, EditorPane, AccountPane {
 
     internal MailboxRow new_mailbox_row(Geary.RFC822.MailboxAddress sender) {
         MailboxRow row = new MailboxRow(this.account, sender);
+        row.move_to.connect(on_sender_row_moved);
         row.dropped.connect(on_sender_row_dropped);
         return row;
     }
@@ -187,11 +188,23 @@ internal class Accounts.EditorEditPane : Gtk.Grid, EditorPane, AccountPane {
         update_actions();
     }
 
+    private void on_sender_row_moved(EditorRow source, int new_position) {
+        this.commands.execute.begin(
+            new ReorderMailboxCommand(
+                (MailboxRow) source,
+                new_position,
+                this.account,
+                this.senders_list
+            ),
+            null
+        );
+    }
+
     private void on_sender_row_dropped(EditorRow source, EditorRow target) {
         this.commands.execute.begin(
             new ReorderMailboxCommand(
                 (MailboxRow) source,
-                (MailboxRow) target,
+                target.get_index(),
                 this.account,
                 this.senders_list
             ),
@@ -614,12 +627,12 @@ internal class Accounts.ReorderMailboxCommand : Application.Command {
 
 
     public ReorderMailboxCommand(MailboxRow source,
-                                 MailboxRow target,
+                                 int target_index,
                                  Geary.AccountInformation account,
                                  Gtk.ListBox list) {
         this.source = source;
         this.source_index = source.get_index();
-        this.target_index = target.get_index();
+        this.target_index = target_index;
 
         this.account = account;
         this.list = list;
@@ -641,6 +654,8 @@ internal class Accounts.ReorderMailboxCommand : Application.Command {
 
         this.list.remove(this.source);
         this.list.insert(this.source, destination);
+
+        this.source.grab_focus();
     }
 
 }
diff --git a/src/client/accounts/accounts-editor-list-pane.vala 
b/src/client/accounts/accounts-editor-list-pane.vala
index bae6576a..aa49936d 100644
--- a/src/client/accounts/accounts-editor-list-pane.vala
+++ b/src/client/accounts/accounts-editor-list-pane.vala
@@ -159,6 +159,7 @@ internal class Accounts.EditorListPane : Gtk.Grid, EditorPane {
     private void add_account(Geary.AccountInformation account,
                              Manager.Status status) {
         AccountListRow row = new AccountListRow(account, status);
+        row.move_to.connect(on_editor_row_moved);
         row.dropped.connect(on_editor_row_dropped);
         this.accounts_list.add(row);
     }
@@ -218,10 +219,19 @@ internal class Accounts.EditorListPane : Gtk.Grid, EditorPane {
         }
     }
 
+    private void on_editor_row_moved(EditorRow source, int new_position) {
+        this.commands.execute.begin(
+            new ReorderAccountCommand(
+                (AccountListRow) source, new_position, this.accounts
+            ),
+            null
+        );
+    }
+
     private void on_editor_row_dropped(EditorRow source, EditorRow target) {
         this.commands.execute.begin(
             new ReorderAccountCommand(
-                (AccountListRow) source, (AccountListRow) target, this.accounts
+                (AccountListRow) source, target.get_index(), this.accounts
             ),
             null
         );
@@ -473,11 +483,11 @@ internal class Accounts.ReorderAccountCommand : Application.Command {
 
 
     public ReorderAccountCommand(AccountListRow source,
-                                 AccountListRow target,
+                                 int target_index,
                                  Manager manager) {
         this.source = source;
         this.source_index = source.get_index();
-        this.target_index = target.get_index();
+        this.target_index = target_index;
 
         this.manager = manager;
     }
@@ -507,6 +517,8 @@ internal class Accounts.ReorderAccountCommand : Application.Command {
             }
             ord++;
         }
+
+        this.source.grab_focus();
     }
 
 }
diff --git a/src/client/accounts/accounts-editor-row.vala b/src/client/accounts/accounts-editor-row.vala
index 31927004..ec55ff09 100644
--- a/src/client/accounts/accounts-editor-row.vala
+++ b/src/client/accounts/accounts-editor-row.vala
@@ -21,6 +21,7 @@ internal class Accounts.EditorRow<PaneType> : Gtk.ListBoxRow {
     private bool drag_entered = false;
 
 
+    public signal void move_to(int new_position);
     public signal void dropped(EditorRow target);
 
 
@@ -55,6 +56,36 @@ internal class Accounts.EditorRow<PaneType> : Gtk.ListBoxRow {
         // No-op by default
     }
 
+    public override bool key_press_event(Gdk.EventKey event) {
+        bool ret = Gdk.EVENT_PROPAGATE;
+
+        if (event.state == Gdk.ModifierType.CONTROL_MASK) {
+            int index = get_index();
+            if (event.keyval == Gdk.Key.Up) {
+                index -= 1;
+                if (index >= 0) {
+                    move_to(index);
+                    ret = Gdk.EVENT_STOP;
+                }
+            } else if (event.keyval == Gdk.Key.Down) {
+                index += 1;
+                Gtk.ListBox? parent = get_parent() as Gtk.ListBox;
+                if (parent != null &&
+                    index < parent.get_children().length() &&
+                    !(parent.get_row_at_index(index) is AddRow)) {
+                    move_to(index);
+                    ret = Gdk.EVENT_STOP;
+                }
+            }
+        }
+
+        if (ret != Gdk.EVENT_STOP) {
+            ret = base.key_press_event(event);
+        }
+
+        return ret;
+    }
+
     /** Adds a drag handle to the row and enables drag signals. */
     protected void enable_drag() {
         Gtk.drag_source_set(
diff --git a/src/client/accounts/accounts-editor.vala b/src/client/accounts/accounts-editor.vala
index 9f37b86b..07da5b0b 100644
--- a/src/client/accounts/accounts-editor.vala
+++ b/src/client/accounts/accounts-editor.vala
@@ -71,6 +71,8 @@ public class Accounts.Editor : Gtk.Dialog {
     public override bool key_press_event(Gdk.EventKey event) {
         bool ret = Gdk.EVENT_PROPAGATE;
 
+        // Allow the user to use Esc, Back and Alt+arrow keys to
+        // navigate between panes.
         if (get_current_pane() != this.editor_list_pane) {
             Gdk.ModifierType state = (
                 event.state & Gtk.accelerator_get_default_mod_mask()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]