[shotwell/wip/gtk4: 42/88] Fix single-line entry dialogs
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/gtk4: 42/88] Fix single-line entry dialogs
- Date: Mon, 30 May 2022 17:34:43 +0000 (UTC)
commit 51f0b64e898004f49d6d3ab8ce71adcd0daa0f5a
Author: Jens Georg <mail jensge org>
Date: Sun Apr 10 09:24:42 2022 +0200
Fix single-line entry dialogs
data/ui/textentrydialog.ui | 94 +++++++++----------------------------
src/AppWindow.vala | 1 +
src/Dialogs.vala | 20 ++++----
src/MediaPage.vala | 34 ++++++++------
src/PhotoPage.vala | 37 ++++++++-------
src/dialogs/TextEntry.vala | 19 ++++++--
src/events/EventsDirectoryPage.vala | 13 ++---
src/tags/TagsBranch.vala | 11 +++--
8 files changed, 101 insertions(+), 128 deletions(-)
---
diff --git a/data/ui/textentrydialog.ui b/data/ui/textentrydialog.ui
index 6a2dc789..43b6702e 100644
--- a/data/ui/textentrydialog.ui
+++ b/data/ui/textentrydialog.ui
@@ -1,104 +1,56 @@
<?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"/>
<template class="TextEntryDialog" parent="GtkDialog">
- <property name="can_focus">False</property>
- <property name="type_hint">dialog</property>
- <child internal-child="vbox">
+ <child internal-child="content_area">
<object class="GtkBox">
- <property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</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="button1">
- <property name="label" translatable="yes">_Cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="button2">
- <property name="label" translatable="yes">_Save</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">True</property>
- <property name="fill">True</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="GtkBox" id="dialog-vbox2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="border_width">3</property>
+ <property name="margin-top">3</property>
+ <property name="margin-bottom">3</property>
+ <property name="margin-start">3</property>
+ <property name="margin-end">3</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
<object class="GtkLabel" id="label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">label</property>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
</child>
<child>
<object class="GtkEntry" id="entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="focusable">1</property>
<property name="invisible_char">●</property>
- <property name="activates_default">True</property>
+ <property name="activates_default">1</property>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
<child>
<placeholder/>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button1</action-widget>
- <action-widget response="-5">button2</action-widget>
+ <action-widget response="-5" default="true">button2</action-widget>
</action-widgets>
+ <child type="action">
+ <object class="GtkButton" id="button1">
+ <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="button2">
+ <property name="label" translatable="yes">_Save</property>
+ <property name="focusable">1</property>
+ <property name="use_underline">1</property>
+ </object>
+ </child>
</template>
</interface>
diff --git a/src/AppWindow.vala b/src/AppWindow.vala
index 1145e4da..387f2ad3 100644
--- a/src/AppWindow.vala
+++ b/src/AppWindow.vala
@@ -497,6 +497,7 @@ public abstract class AppWindow : PageWindow {
// Occasionally, with_markup doesn't actually do anything, but set_markup always works.
dialog.set_markup(build_alert_body_text(title, message, should_escape));
+ dialog.set_transient_for(parent != null ? parent : get_instance());
dialog.use_markup = true;
dialog.show();
diff --git a/src/Dialogs.vala b/src/Dialogs.vala
index 4a466f5c..c8f926b2 100644
--- a/src/Dialogs.vala
+++ b/src/Dialogs.vala
@@ -629,8 +629,8 @@ public abstract class TextEntryDialogMediator {
return true;
}
- protected string? _execute() {
- return dialog.execute();
+ protected async string? _execute() {
+ return yield dialog.execute();
}
}
@@ -670,8 +670,8 @@ public class EventRenameDialog : TextEntryDialogMediator {
base (_("Rename Event"), _("Name:"), event_name);
}
- public virtual string? execute() {
- return Event.prep_event_name(_execute());
+ public async virtual string? execute() {
+ return Event.prep_event_name(yield _execute());
}
}
@@ -682,8 +682,8 @@ public class EditTitleDialog : TextEntryDialogMediator {
_("Title:"), photo_title);
}
- public virtual string? execute() {
- return MediaSource.prep_title(_execute());
+ public virtual async string? execute() {
+ return MediaSource.prep_title(yield _execute());
}
protected override bool on_modify_validate(string text) {
@@ -845,8 +845,8 @@ public class AddTagsDialog : TagsDialog {
base (title, _("Tags (separated by commas):"));
}
- public string[]? execute() {
- string? text = _execute();
+ public async string[]? execute() {
+ string? text = yield _execute();
if (text == null)
return null;
@@ -897,8 +897,8 @@ public class ModifyTagsDialog : TagsDialog {
return text;
}
- public Gee.ArrayList<Tag>? execute() {
- string? text = _execute();
+ public async Gee.ArrayList<Tag>? execute() {
+ string? text = yield _execute();
if (text == null)
return null;
diff --git a/src/MediaPage.vala b/src/MediaPage.vala
index 04c65acb..01fb63fb 100644
--- a/src/MediaPage.vala
+++ b/src/MediaPage.vala
@@ -563,13 +563,15 @@ public abstract class MediaPage : CheckerboardPage {
return;
AddTagsDialog dialog = new AddTagsDialog();
- string[]? names = dialog.execute();
+ dialog.execute.begin((source, res) => {
+ string[]? names = dialog.execute.end(res);
- if (names != null) {
- get_command_manager().execute(new AddTagsCommand(
- HierarchicalTagIndex.get_global_index().get_paths_for_names_array(names),
- (Gee.Collection<MediaSource>) get_view().get_selected_sources()));
- }
+ if (names != null) {
+ get_command_manager().execute(new AddTagsCommand(
+ HierarchicalTagIndex.get_global_index().get_paths_for_names_array(names),
+ (Gee.Collection<MediaSource>) get_view().get_selected_sources()));
+ }
+ });
}
private void on_modify_tags() {
@@ -579,12 +581,13 @@ public abstract class MediaPage : CheckerboardPage {
MediaSource media = (MediaSource) get_view().get_selected_at(0).get_source();
ModifyTagsDialog dialog = new ModifyTagsDialog(media);
- Gee.ArrayList<Tag>? new_tags = dialog.execute();
-
- if (new_tags == null)
- return;
+
+ dialog.execute.begin((source, res) => {
+ Gee.ArrayList<Tag>? new_tags = dialog.execute.end(res);
+ if (new_tags != null)
+ get_command_manager().execute(new ModifyTagsCommand(media, new_tags));
+ });
- get_command_manager().execute(new ModifyTagsCommand(media, new_tags));
}
private void set_display_tags(bool display) {
@@ -710,9 +713,12 @@ public abstract class MediaPage : CheckerboardPage {
Gee.List<MediaSource> media_sources = (Gee.List<MediaSource>) get_view().get_selected_sources();
EditTitleDialog edit_title_dialog = new EditTitleDialog(media_sources[0].get_title());
- string? new_title = edit_title_dialog.execute();
- if (new_title != null)
- get_command_manager().execute(new EditMultipleTitlesCommand(media_sources, new_title));
+ edit_title_dialog.execute.begin((source, res) => {
+ string? new_title = edit_title_dialog.execute.end(res);
+ if (new_title != null)
+ get_command_manager().execute(new EditMultipleTitlesCommand(media_sources, new_title));
+
+ });
}
protected virtual void on_edit_comment() {
diff --git a/src/PhotoPage.vala b/src/PhotoPage.vala
index f3e9a15e..f0c669b3 100644
--- a/src/PhotoPage.vala
+++ b/src/PhotoPage.vala
@@ -2006,12 +2006,12 @@ public abstract class EditingHostPage : SinglePhotoPage {
return;
EditTitleDialog edit_title_dialog = new EditTitleDialog(item.get_title());
- string? new_title = edit_title_dialog.execute();
- if (new_title == null)
- return;
-
- EditTitleCommand command = new EditTitleCommand(item, new_title);
- get_command_manager().execute(command);
+ edit_title_dialog.execute.begin((source, res) => {
+ string? new_title = edit_title_dialog.execute.end(res);
+ if (new_title != null)
+ get_command_manager().execute(new EditTitleCommand(item, new_title));
+
+ });
}
public void on_edit_comment() {
@@ -3186,24 +3186,27 @@ public class LibraryPhotoPage : EditingHostPage {
private void on_add_tags() {
AddTagsDialog dialog = new AddTagsDialog();
- string[]? names = dialog.execute();
- if (names != null) {
- get_command_manager().execute(new AddTagsCommand(
- HierarchicalTagIndex.get_global_index().get_paths_for_names_array(names),
- (Gee.Collection<LibraryPhoto>) get_view().get_selected_sources()));
- }
+ dialog.execute.begin((source, res) => {
+ string[]? names = dialog.execute.end(res);
+ if (names != null) {
+ get_command_manager().execute(new AddTagsCommand(
+ HierarchicalTagIndex.get_global_index().get_paths_for_names_array(names),
+ (Gee.Collection<LibraryPhoto>) get_view().get_selected_sources()));
+ }
+ });
}
private void on_modify_tags() {
LibraryPhoto photo = (LibraryPhoto) get_view().get_selected_at(0).get_source();
ModifyTagsDialog dialog = new ModifyTagsDialog(photo);
- Gee.ArrayList<Tag>? new_tags = dialog.execute();
-
- if (new_tags == null)
- return;
+ dialog.execute.begin((source, res) => {
+ var new_tags = dialog.execute.end(res);
+ if (new_tags == null)
+ return;
- get_command_manager().execute(new ModifyTagsCommand(photo, new_tags));
+ get_command_manager().execute(new ModifyTagsCommand(photo, new_tags));
+ });
}
#if ENABLE_FACES
diff --git a/src/dialogs/TextEntry.vala b/src/dialogs/TextEntry.vala
index 23a74ed2..952ddde3 100644
--- a/src/dialogs/TextEntry.vala
+++ b/src/dialogs/TextEntry.vala
@@ -43,7 +43,7 @@ public class TextEntryDialog : Gtk.Dialog {
set_default_response(Gtk.ResponseType.OK);
}
- public string? execute() {
+ public async string? execute() {
string? text = null;
// validate entry to start with
@@ -51,11 +51,20 @@ public class TextEntryDialog : Gtk.Dialog {
show();
- if (0 == Gtk.ResponseType.OK)
- text = entry.get_text();
+ SourceFunc continue_async = execute.callback;
+ int response_id = 0;
+
+ response.connect((source, res) => {
+ response_id = res;
+ entry.changed.disconnect(on_entry_changed);
+ destroy();
+ continue_async();
+ });
- entry.changed.disconnect(on_entry_changed);
- destroy();
+ yield;
+
+ if (response_id == Gtk.ResponseType.OK)
+ text = entry.get_text();
return text;
}
diff --git a/src/events/EventsDirectoryPage.vala b/src/events/EventsDirectoryPage.vala
index 977b13aa..09ad7ced 100644
--- a/src/events/EventsDirectoryPage.vala
+++ b/src/events/EventsDirectoryPage.vala
@@ -173,12 +173,13 @@ public abstract class EventsDirectoryPage : CheckerboardPage {
EventDirectoryItem item = (EventDirectoryItem) get_view().get_selected_at(0);
EventRenameDialog rename_dialog = new EventRenameDialog(item.event.get_raw_name());
- string? new_name = rename_dialog.execute();
- if (new_name == null)
- return;
-
- RenameEventCommand command = new RenameEventCommand(item.event, new_name);
- get_command_manager().execute(command);
+ rename_dialog.execute.begin((source, res) => {
+ var new_name = rename_dialog.execute.end(res);
+ if (new_name != null) {
+ RenameEventCommand command = new RenameEventCommand(item.event, new_name);
+ get_command_manager().execute(command);
+ }
+ });
}
protected void on_edit_comment() {
diff --git a/src/tags/TagsBranch.vala b/src/tags/TagsBranch.vala
index ef6f10de..5c712ffd 100644
--- a/src/tags/TagsBranch.vala
+++ b/src/tags/TagsBranch.vala
@@ -133,11 +133,12 @@ public class Tags.Header : Sidebar.Header, Sidebar.InternalDropTargetEntry,
public bool internal_drop_received(Gee.List<MediaSource> media) {
AddTagsDialog dialog = new AddTagsDialog();
- string[]? names = dialog.execute();
- if (names == null || names.length == 0)
- return false;
-
- AppWindow.get_command_manager().execute(new AddTagsCommand(names, media));
+ dialog.execute.begin((source, res) => {
+ string[]? tags = dialog.execute.end(res);
+ if (tags != null && tags.length > 0) {
+ AppWindow.get_command_manager().execute(new AddTagsCommand(tags, media));
+ }
+ });
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]