[shotwell] Extract MultiTextEntryDialog



commit a0916895cf7e7a6d448b66374572762739227abe
Author: Jens Georg <mail jensge org>
Date:   Wed Dec 20 16:42:49 2017 +0100

    Extract MultiTextEntryDialog

 org.gnome.Shotwell.gresource.xml      |    1 +
 src/Dialogs.vala                      |   57 --------------------
 src/dialogs/MultiTextEntryDialog.vala |   45 ++++++++++++++++
 src/meson.build                       |    1 +
 ui/multitextentrydialog.ui            |   91 +++++++++++++++++++++++++++++++++
 ui/shotwell.ui                        |   25 ---------
 6 files changed, 138 insertions(+), 82 deletions(-)
---
diff --git a/org.gnome.Shotwell.gresource.xml b/org.gnome.Shotwell.gresource.xml
index 3d432fc..4d17435 100644
--- a/org.gnome.Shotwell.gresource.xml
+++ b/org.gnome.Shotwell.gresource.xml
@@ -11,6 +11,7 @@
       <file preprocess="xml-stripblanks">ui/import_queue.ui</file>
       <file preprocess="xml-stripblanks">ui/import.ui</file>
       <file preprocess="xml-stripblanks">ui/media.ui</file>
+      <file preprocess="xml-stripblanks">ui/multitextentrydialog.ui</file>
       <file preprocess="xml-stripblanks">ui/offline.ui</file>
       <file preprocess="xml-stripblanks">ui/photo_context.ui</file>
       <file preprocess="xml-stripblanks">ui/photo.ui</file>
diff --git a/src/Dialogs.vala b/src/Dialogs.vala
index 3916b08..dc08212 100644
--- a/src/Dialogs.vala
+++ b/src/Dialogs.vala
@@ -617,10 +617,7 @@ public abstract class MultiTextEntryDialogMediator {
     private MultiTextEntryDialog dialog;
     
     public MultiTextEntryDialogMediator(string title, string label, string? initial_text = null) {
-        Gtk.Builder builder = AppWindow.create_builder();
         dialog = new MultiTextEntryDialog();
-        dialog.get_content_area().add((Gtk.Box) builder.get_object("dialog-vbox4"));
-        dialog.set_builder(builder);
         dialog.setup(on_modify_validate, title, label, initial_text);
     }
     
@@ -648,60 +645,6 @@ public string build_alert_body_text(string? primary_text, string? secondary_text
 }
 
 
-
-public class MultiTextEntryDialog : Gtk.Dialog {
-    public delegate bool OnModifyValidateType(string text);
-    
-    private unowned OnModifyValidateType on_modify_validate;
-    private Gtk.TextView entry;
-    private Gtk.Builder builder;
-    private Gtk.Button button1;
-    private Gtk.Button button2;
-    
-    public MultiTextEntryDialog() {
-        bool use_header;
-        Gtk.Settings.get_default ().get ("gtk-dialogs-use-header", out use_header);
-        Object (use_header_bar: use_header ? 1 : 0);
-    }
-    
-    public void set_builder(Gtk.Builder builder) {
-        this.builder = builder;
-    }
-    
-    public void setup(OnModifyValidateType? modify_validate, string title, string label, string? 
initial_text) {
-        set_title(title);
-        set_resizable(true);
-        set_default_size(500,300);
-        set_parent_window(AppWindow.get_instance().get_parent_window());
-        set_transient_for(AppWindow.get_instance());
-        on_modify_validate = modify_validate;
-        
-        entry = builder.get_object("textview1") as Gtk.TextView;
-        entry.set_wrap_mode (Gtk.WrapMode.WORD);
-        entry.buffer = new Gtk.TextBuffer(null);
-        entry.buffer.text = (initial_text != null ? initial_text : "");
-        
-        entry.grab_focus();
-        
-        button1 = (Gtk.Button) add_button(Resources.CANCEL_LABEL, Gtk.ResponseType.CANCEL);
-        button2 = (Gtk.Button) add_button(Resources.SAVE_LABEL, Gtk.ResponseType.OK);
-        set_default_response(Gtk.ResponseType.OK);
-    }
-        
-    public string? execute() {
-        string? text = null;
-        
-        show_all();
-        
-        if (run() == Gtk.ResponseType.OK)
-            text = entry.buffer.text;
-        
-        destroy();
-        
-        return text;
-    }
-}
-
 public class EventRenameDialog : TextEntryDialogMediator {
     public EventRenameDialog(string? event_name) {
         base (_("Rename Event"), _("Name:"), event_name);
diff --git a/src/dialogs/MultiTextEntryDialog.vala b/src/dialogs/MultiTextEntryDialog.vala
new file mode 100644
index 0000000..8671d43
--- /dev/null
+++ b/src/dialogs/MultiTextEntryDialog.vala
@@ -0,0 +1,45 @@
+/* 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/multitextentrydialog.ui")]
+public class MultiTextEntryDialog : Gtk.Dialog {
+    public delegate bool OnModifyValidateType(string text);
+
+    private unowned OnModifyValidateType on_modify_validate;
+    [GtkChild]
+        private Gtk.TextView entry;
+
+    public MultiTextEntryDialog() {
+        bool use_header;
+        Gtk.Settings.get_default ().get ("gtk-dialogs-use-header", out use_header);
+        Object (use_header_bar: use_header ? 1 : 0);
+    }
+
+    public void setup(OnModifyValidateType? modify_validate, string title, string label, string? 
initial_text) {
+        set_title(title);
+        set_parent_window(AppWindow.get_instance().get_parent_window());
+        set_transient_for(AppWindow.get_instance());
+        on_modify_validate = modify_validate;
+
+        entry.buffer.text = (initial_text != null ? initial_text : "");
+
+        entry.grab_focus();
+    }
+
+    public string? execute() {
+        string? text = null;
+
+        show_all();
+
+        if (run() == Gtk.ResponseType.OK)
+            text = entry.buffer.text;
+
+        destroy();
+
+        return text;
+    }
+}
diff --git a/src/meson.build b/src/meson.build
index 9af2da7..3006480 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -198,6 +198,7 @@ executable('shotwell',
             'dialogs/SetBackground.vala',
             'dialogs/TextEntry.vala',
             'dialogs/ExportDialog.vala',
+            'dialogs/MultiTextEntryDialog.vala',
             '.unitize/_UnitInternals.vala',
             '.unitize/_UtilInternals.vala',
             '.unitize/_ThreadsInternals.vala',
diff --git a/ui/multitextentrydialog.ui b/ui/multitextentrydialog.ui
new file mode 100644
index 0000000..6477129
--- /dev/null
+++ b/ui/multitextentrydialog.ui
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface domain="shotwell">
+  <requires lib="gtk+" version="3.18"/>
+  <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">
+      <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="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>
+              <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="wrap_mode">word</property>
+                <property name="buffer">textbuffer1</property>
+                <property name="accepts_tab">False</property>
+              </object>
+            </child>
+          </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-widgets>
+  </template>
+</interface>
diff --git a/ui/shotwell.ui b/ui/shotwell.ui
index 332f3db..602a7c8 100644
--- a/ui/shotwell.ui
+++ b/ui/shotwell.ui
@@ -178,31 +178,6 @@
       <placeholder/>
     </child>
   </object>
-  <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="border_width">3</property>
-    <property name="orientation">vertical</property>
-    <child>
-      <object class="GtkScrolledWindow" id="scrolledwindow1">
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="shadow_type">in</property>
-        <child>
-          <object class="GtkTextView" id="textview1">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="hexpand">True</property>
-            <property name="vexpand">True</property>
-            <property name="wrap_mode">word</property>
-            <property name="accepts_tab">False</property>
-          </object>
-        </child>
-      </object>
-      <packing>
-        <property name="expand">True</property>
   <object class="GtkBox" id="plugin-manifest">
     <property name="visible">True</property>
     <property name="can_focus">False</property>


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