From 49823ec05414e11275f313fb0ca5a48fcab7ddda Mon Sep 17 00:00:00 2001
From: Julian Sparber <julian@sparber.net>
Date: Tue, 6 Oct 2020 10:41:33 +0200
Subject: [PATCH 056/124] application-main-window: add navigation via signle
 click on folder/conversation

Opening a conversation in a new window is currently disabled, because we
need a new key/button combination.
---
 src/client/application/application-main-window.vala   | 11 +++++++++++
 .../conversation-list/conversation-list-view.vala     |  1 +
 src/client/folder-list/folder-list-tree.vala          | 10 ++++++++++
 src/client/sidebar/sidebar-tree.vala                  | 11 +++++++++++
 4 files changed, 33 insertions(+)

diff --git a/src/client/application/application-main-window.vala b/src/client/application/application-main-window.vala
index c3cf2d58..97960660 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -1230,6 +1230,7 @@ public class Application.MainWindow :
         this.folder_list.folder_selected.connect(on_folder_selected);
         this.folder_list.move_conversation.connect(on_move_conversation);
         this.folder_list.copy_conversation.connect(on_copy_conversation);
+        this.folder_list.folder_activated.connect(on_folder_activated);
         this.folder_list_scrolled.add(this.folder_list);
 
         // Conversation list
@@ -2135,7 +2136,16 @@ public class Application.MainWindow :
         }
     }
 
+    private void on_folder_activated(Geary.Folder? folder) {
+        if (folder != null)
+            focus_next_pane();
+    }
+
     private void on_conversation_activated(Geary.App.Conversation activated) {
+        if (main_leaflet.folded) {
+            focus_next_pane();
+        }
+        /* TODO: find correct UX for opening the conversation in a new window
         if (this.selected_folder != null) {
             if (this.selected_folder.used_as != DRAFTS) {
                 this.application.new_window.begin(
@@ -2154,6 +2164,7 @@ public class Application.MainWindow :
                 );
             }
         }
+        */
     }
 
     private void on_find_in_conversation_action() {
diff --git a/src/client/conversation-list/conversation-list-view.vala b/src/client/conversation-list/conversation-list-view.vala
index a4d5cca6..dcced90d 100644
--- a/src/client/conversation-list/conversation-list-view.vala
+++ b/src/client/conversation-list/conversation-list-view.vala
@@ -42,6 +42,7 @@ public class ConversationListView : Gtk.TreeView, Geary.BaseInterface {
         base_ref();
         set_show_expanders(false);
         set_headers_visible(false);
+        set_activate_on_single_click(true);
 
         this.config = config;
 
diff --git a/src/client/folder-list/folder-list-tree.vala b/src/client/folder-list/folder-list-tree.vala
index fb91347e..f820d12f 100644
--- a/src/client/folder-list/folder-list-tree.vala
+++ b/src/client/folder-list/folder-list-tree.vala
@@ -16,6 +16,7 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
 
 
     public signal void folder_selected(Geary.Folder? folder);
+    public signal void folder_activated(Geary.Folder? folder);
     public signal void copy_conversation(Geary.Folder folder);
     public signal void move_conversation(Geary.Folder folder);
 
@@ -30,7 +31,9 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
     public Tree() {
         base(TARGET_ENTRY_LIST, Gdk.DragAction.COPY | Gdk.DragAction.MOVE, drop_handler);
         base_ref();
+        set_activate_on_single_click(true);
         entry_selected.connect(on_entry_selected);
+        entry_activated.connect(on_entry_activated);
 
         // GtkTreeView binds Ctrl+N to "move cursor to next".  Not so interested in that, so we'll
         // remove it.
@@ -87,6 +90,13 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
         }
     }
 
+    private void on_entry_activated(Sidebar.SelectableEntry selectable) {
+        AbstractFolderEntry? entry = selectable as AbstractFolderEntry;
+        if (entry != null) {
+            folder_activated(entry.folder);
+        }
+    }
+
     public void set_user_folders_root_name(Geary.Account account, string name) {
         if (account_branches.has_key(account))
             account_branches.get(account).user_folder_group.rename(name);
diff --git a/src/client/sidebar/sidebar-tree.vala b/src/client/sidebar/sidebar-tree.vala
index a5f95092..78d73e98 100644
--- a/src/client/sidebar/sidebar-tree.vala
+++ b/src/client/sidebar/sidebar-tree.vala
@@ -80,6 +80,8 @@ public class Sidebar.Tree : Gtk.TreeView {
 
     public signal void entry_selected(Sidebar.SelectableEntry selectable);
 
+    public signal void entry_activated(Sidebar.SelectableEntry selectable);
+
     public signal void selected_entry_removed(Sidebar.SelectableEntry removed);
 
     public signal void branch_added(Sidebar.Branch branch);
@@ -298,6 +300,15 @@ public class Sidebar.Tree : Gtk.TreeView {
         return true;
     }
 
+    public override void row_activated(Gtk.TreePath path, Gtk.TreeViewColumn column) {
+      EntryWrapper? wrapper = get_wrapper_at_path(path);
+      if (wrapper != null) {
+          Sidebar.SelectableEntry? selectable = wrapper.entry as Sidebar.SelectableEntry;
+          if (selectable != null)
+              entry_activated(selectable);
+      }
+    }
+
     public override void cursor_changed() {
         Gtk.TreePath? path = get_selected_path();
         if (path == null) {
-- 
2.29.2

