From d6c546e2d555d20e1dd259117822b4d4c8b7152c Mon Sep 17 00:00:00 2001
From: Julian Sparber <julian@sparber.net>
Date: Tue, 6 Oct 2020 17:31:49 +0200
Subject: [PATCH 060/124] composer: close the composer when navigating back

---
 src/client/application/application-main-window.vala | 11 +++++++++++
 src/client/composer/composer-widget.vala            |  5 +++++
 ui/application-main-window.ui                       |  2 ++
 3 files changed, 18 insertions(+)

diff --git a/src/client/application/application-main-window.vala b/src/client/application/application-main-window.vala
index 01b7b9c6..e1e55d0e 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -1955,6 +1955,17 @@ public class Application.MainWindow :
         return Gdk.EVENT_STOP;
     }
 
+    [GtkCallback]
+    private void on_main_leaflet_visible_child_changed() {
+        if (main_leaflet.child_transition_running)
+            return;
+
+        if (main_leaflet.visible_child_name == "conversations" && main_leaflet.folded)
+            if (this.conversation_viewer.current_composer != null) {
+                this.conversation_viewer.current_composer.activate_close_action();
+            }
+    }
+
     private void on_offline_infobar_response() {
         this.info_bars.remove(this.offline_infobar);
     }
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 37e93fb4..17430021 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -1361,6 +1361,11 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
         }
     }
 
+    /* Activate the close action */
+    public void activate_close_action() {
+        this.actions.activate_action(ACTION_CLOSE, null);
+    }
+
     internal void set_mode(PresentationMode new_mode) {
         this.current_mode = new_mode;
         this.header.set_mode(new_mode);
diff --git a/ui/application-main-window.ui b/ui/application-main-window.ui
index fe66491b..cbaacbcf 100644
--- a/ui/application-main-window.ui
+++ b/ui/application-main-window.ui
@@ -29,6 +29,8 @@
                 <property name="can_focus">True</property>
                 <property name="can_swipe_back">True</property>
                 <property name="transition_type">over</property>
+                <signal name="notify::visible-child" handler="on_main_leaflet_visible_child_changed" swapped="no"/>
+                <signal name="notify::child-transition-running" handler="on_main_leaflet_visible_child_changed" swapped="no"/>
                 <child>
                   <object class="HdyLeaflet" id="conversations_leaflet">
                     <property name="visible">True</property>
-- 
2.29.2

