summaryrefslogtreecommitdiff
path: root/src/dialogs/TextEntry.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2018-05-01 14:35:32 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2018-05-01 14:35:32 +0200
commite230b6f78546827521107be23797048482c8b193 (patch)
tree948c1e77382c484819ea399bba4edcdc19cc6bf0 /src/dialogs/TextEntry.vala
parent211da5fc3048ca2b6ccee2166b0aaaade55cb84f (diff)
parent49120f48474fc8fdc2448c75d961bc238213cfac (diff)
Update upstream source from tag 'upstream/0.28.2'
Update to upstream version '0.28.2' with Debian dir 811236a8e9a1308bf427065dcb6270419ff4f965
Diffstat (limited to 'src/dialogs/TextEntry.vala')
-rw-r--r--src/dialogs/TextEntry.vala66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/dialogs/TextEntry.vala b/src/dialogs/TextEntry.vala
new file mode 100644
index 0000000..d82fdbd
--- /dev/null
+++ b/src/dialogs/TextEntry.vala
@@ -0,0 +1,66 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2017 Jens Georg <mail@jensge.org>
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+[GtkTemplate (ui = "/org/gnome/Shotwell/ui/textentrydialog.ui")]
+public class TextEntryDialog : Gtk.Dialog {
+ public delegate bool OnModifyValidateType(string text);
+
+ private unowned OnModifyValidateType on_modify_validate;
+
+ [GtkChild]
+ private Gtk.Entry entry;
+
+ [GtkChild]
+ private Gtk.Label label;
+
+ public TextEntryDialog() {
+ Object (use_header_bar: Resources.use_header_bar());
+ }
+
+ public void setup(OnModifyValidateType? modify_validate, string title, string label,
+ string? initial_text, Gee.Collection<string>? completion_list, string? completion_delimiter) {
+ set_title(title);
+ set_parent_window(AppWindow.get_instance().get_parent_window());
+ set_transient_for(AppWindow.get_instance());
+ on_modify_validate = modify_validate;
+
+ this.label.set_text(label);
+
+ entry.set_text(initial_text != null ? initial_text : "");
+ entry.grab_focus();
+ entry.changed.connect(on_entry_changed);
+
+ if (completion_list != null) { // Textfield with autocompletion
+ EntryMultiCompletion completion = new EntryMultiCompletion(completion_list,
+ completion_delimiter);
+ entry.set_completion(completion);
+ }
+
+ set_default_response(Gtk.ResponseType.OK);
+ }
+
+ public string? execute() {
+ string? text = null;
+
+ // validate entry to start with
+ set_response_sensitive(Gtk.ResponseType.OK, on_modify_validate(entry.get_text()));
+
+ show_all();
+
+ if (run() == Gtk.ResponseType.OK)
+ text = entry.get_text();
+
+ entry.changed.disconnect(on_entry_changed);
+ destroy();
+
+ return text;
+ }
+
+ public void on_entry_changed() {
+ set_response_sensitive(Gtk.ResponseType.OK, on_modify_validate(entry.get_text()));
+ }
+}