Enable reordering accounts and sender mailboxes via keyboard

This commit is contained in:
Michael Gratton 2018-12-02 16:19:55 +11:00
parent f630e03485
commit 79c74c4310
4 changed files with 66 additions and 6 deletions

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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(

View file

@ -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()