[shotwell/wip/gtk4: 99/154] Fix multi-line entry dialogs




commit 7e414d8f3678c3808451ecc64dd939f258e043dc
Author: Jens Georg <mail jensge org>
Date:   Sun Apr 10 09:47:08 2022 +0200

    Fix multi-line entry dialogs

 data/ui/multitextentrydialog.ui       | 96 ++++++++++-------------------------
 src/Dialogs.vala                      |  8 +--
 src/MediaPage.vala                    | 12 +++--
 src/PhotoPage.vala                    | 14 ++---
 src/dialogs/MultiTextEntryDialog.vala | 18 ++++---
 src/events/EventPage.vala             | 16 +++---
 src/events/EventsDirectoryPage.vala   | 16 +++---
 7 files changed, 80 insertions(+), 100 deletions(-)
---
diff --git a/data/ui/multitextentrydialog.ui b/data/ui/multitextentrydialog.ui
index 6477129d..db25195a 100644
--- a/data/ui/multitextentrydialog.ui
+++ b/data/ui/multitextentrydialog.ui
@@ -1,91 +1,51 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
 <interface domain="shotwell">
-  <requires lib="gtk+" version="3.18"/>
+  <requires lib="gtk" version="4.0"/>
   <object class="GtkTextBuffer" id="textbuffer1"/>
   <template class="MultiTextEntryDialog" parent="GtkDialog">
-    <property name="can_focus">False</property>
     <property name="default_width">500</property>
     <property name="default_height">300</property>
-    <property name="type_hint">normal</property>
-    <child internal-child="vbox">
+    <child internal-child="content_area">
       <object class="GtkBox" id="dialog-vbox4">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="hexpand">True</property>
-        <property name="vexpand">True</property>
+        <property name="hexpand">1</property>
+        <property name="vexpand">1</property>
         <property name="orientation">vertical</property>
         <property name="spacing">6</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="cancel_button">
-                <property name="label" translatable="yes">_Cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="ok_button">
-                <property name="label" translatable="yes">_OK</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
           <object class="GtkScrolledWindow" id="scrolledwindow1">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="shadow_type">in</property>
-            <child>
+            <property name="vexpand">1</property>
+            <property name="focusable">1</property>
+            <property name="child">
               <object class="GtkTextView" id="entry">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="hexpand">True</property>
-                <property name="vexpand">True</property>
+                <property name="focusable">1</property>
+                <property name="hexpand">1</property>
+                <property name="vexpand">1</property>
                 <property name="wrap_mode">word</property>
                 <property name="buffer">textbuffer1</property>
-                <property name="accepts_tab">False</property>
+                <property name="accepts_tab">0</property>
               </object>
-            </child>
+            </property>
           </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
         </child>
       </object>
     </child>
     <action-widgets>
-      <action-widget response="-6">cancel_button</action-widget>
-      <action-widget response="-5">ok_button</action-widget>
+      <action-widget response="cancel">cancel_button</action-widget>
+      <action-widget response="ok" default="true">ok_button</action-widget>
     </action-widgets>
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
+        <property name="label" translatable="yes">_Cancel</property>
+        <property name="focusable">1</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="ok_button">
+        <property name="label" translatable="yes">_OK</property>
+        <property name="focusable">1</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/src/Dialogs.vala b/src/Dialogs.vala
index c8f926b2..2b09d764 100644
--- a/src/Dialogs.vala
+++ b/src/Dialogs.vala
@@ -646,8 +646,8 @@ public abstract class MultiTextEntryDialogMediator {
         return true;
     }
 
-    protected string? _execute() {
-        return dialog.execute();
+    protected async string? _execute() {
+        return yield dialog.execute();
     }
 }
 
@@ -700,8 +700,8 @@ public class EditCommentDialog : MultiTextEntryDialogMediator {
         base(title_tmp, _("Comment:"), comment);
     }
     
-    public virtual string? execute() {
-        return MediaSource.prep_comment(_execute());
+    public async virtual string? execute() {
+        return MediaSource.prep_comment(yield _execute());
     }
     
     protected override bool on_modify_validate(string text) {
diff --git a/src/MediaPage.vala b/src/MediaPage.vala
index 43480788..ad054c58 100644
--- a/src/MediaPage.vala
+++ b/src/MediaPage.vala
@@ -722,12 +722,18 @@ public abstract class MediaPage : CheckerboardPage {
         if (get_view().get_selected_count() == 0)
             return;
         
+            print ("==============>\n ");
         Gee.List<MediaSource> media_sources = (Gee.List<MediaSource>) get_view().get_selected_sources();
         
         EditCommentDialog edit_comment_dialog = new EditCommentDialog(media_sources[0].get_comment());
-        string? new_comment = edit_comment_dialog.execute();
-        if (new_comment != null)
-            get_command_manager().execute(new EditMultipleCommentsCommand(media_sources, new_comment));
+
+        edit_comment_dialog.execute.begin((source, res) => {
+            string? new_comment = edit_comment_dialog.execute.end(res);
+            if (new_comment == null)
+                return;
+            
+            get_command_manager().execute(new EditMultipleCommentsCommand(media_sources, new_comment));    
+        });
     }
 
     protected virtual void on_display_titles(GLib.SimpleAction action, Variant? value) {
diff --git a/src/PhotoPage.vala b/src/PhotoPage.vala
index f0c669b3..1e1d77af 100644
--- a/src/PhotoPage.vala
+++ b/src/PhotoPage.vala
@@ -2022,12 +2022,14 @@ public abstract class EditingHostPage : SinglePhotoPage {
             return;
         
         EditCommentDialog edit_comment_dialog = new EditCommentDialog(item.get_comment());
-        string? new_comment = edit_comment_dialog.execute();
-        if (new_comment == null)
-            return;
-        
-        EditCommentCommand command = new EditCommentCommand(item, new_comment);
-        get_command_manager().execute(command);
+        edit_comment_dialog.execute.begin((source, res) => {
+            string? new_comment = edit_comment_dialog.execute.end(res);
+            if (new_comment == null)
+                return;
+            
+            EditCommentCommand command = new EditCommentCommand(item, new_comment);
+            get_command_manager().execute(command);
+        });
     }
 
     public void on_adjust_date_time() {
diff --git a/src/dialogs/MultiTextEntryDialog.vala b/src/dialogs/MultiTextEntryDialog.vala
index 6b847a9d..2b557407 100644
--- a/src/dialogs/MultiTextEntryDialog.vala
+++ b/src/dialogs/MultiTextEntryDialog.vala
@@ -28,16 +28,22 @@ public class MultiTextEntryDialog : Gtk.Dialog {
         entry.grab_focus();
     }
 
-    public string? execute() {
+    public async string? execute() {
         string? text = null;
 
         show();
 
-        #if 0
-        // TODO
-        if (run() == Gtk.ResponseType.OK)
-            text = entry.buffer.text;
-            #endif
+        SourceFunc continue_async = execute.callback;
+
+        response.connect((source, response_id) => {
+            if (response_id == Gtk.ResponseType.OK) {
+                text = entry.buffer.text;
+            }
+
+            continue_async();
+        });
+
+        yield;
 
         destroy();
 
diff --git a/src/events/EventPage.vala b/src/events/EventPage.vala
index 12b21295..8a2a5e2c 100644
--- a/src/events/EventPage.vala
+++ b/src/events/EventPage.vala
@@ -102,13 +102,15 @@ public class EventPage : CollectionPage {
     private void on_edit_event_comment() {
         EditCommentDialog edit_comment_dialog = new EditCommentDialog(page_event.get_comment(),
         true);
-        string? new_comment = edit_comment_dialog.execute();
-        if (new_comment == null)
-            return;
-        
-        EditEventCommentCommand command = new EditEventCommentCommand(page_event, new_comment);
-        get_command_manager().execute(command);
-        return;
+        edit_comment_dialog.execute.begin((source, res) => {
+            string? new_comment = edit_comment_dialog.execute.end(res);
+            if (new_comment == null)
+                return;
+            
+            EditEventCommentCommand command = new EditEventCommentCommand(page_event, new_comment);
+            get_command_manager().execute(command);
+    
+        });
     }
 
     protected override void on_edit_comment() {
diff --git a/src/events/EventsDirectoryPage.vala b/src/events/EventsDirectoryPage.vala
index 09ad7ced..163fc6d8 100644
--- a/src/events/EventsDirectoryPage.vala
+++ b/src/events/EventsDirectoryPage.vala
@@ -191,12 +191,16 @@ public abstract class EventsDirectoryPage : CheckerboardPage {
         
         EditCommentDialog edit_comment_dialog = new EditCommentDialog(item.event.get_comment(),
         true);
-        string? new_comment = edit_comment_dialog.execute();
-        if (new_comment == null)
-            return;
-        
-        EditEventCommentCommand command = new EditEventCommentCommand(item.event, new_comment);
-        get_command_manager().execute(command);
+
+        edit_comment_dialog.execute.begin((source, res) => {
+            string? new_comment = edit_comment_dialog.execute.end(res);
+            if (new_comment == null)
+                return;
+            
+            EditEventCommentCommand command = new EditEventCommentCommand(item.event, new_comment);
+            get_command_manager().execute(command);
+    
+        });
     }
     
     private void on_merge() {


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