[gnome-subtitles/gtk3] Search dialog upgrade to gtk3



commit c31e8069b7d8d9938c7c5969d209f4e227f65993
Author: Pedro Castro <pedro gnomesubtitles org>
Date:   Thu Feb 1 22:28:43 2018 +0000

    Search dialog upgrade to gtk3

 src/Glade/{ => old.glade}/SearchDialog.glade       |    0
 .../SearchDialog.ui}                               |  102 ++++++++-------
 src/GnomeSubtitles/Dialog/SearchDialog.cs          |  135 +++++++++++++------
 src/GnomeSubtitles/Ui/WidgetStyles.cs              |    1 +
 4 files changed, 145 insertions(+), 93 deletions(-)
---
diff --git a/src/Glade/SearchDialog.glade b/src/Glade/old.glade/SearchDialog.glade
similarity index 100%
copy from src/Glade/SearchDialog.glade
copy to src/Glade/old.glade/SearchDialog.glade
diff --git a/src/Glade/SearchDialog.glade b/src/Glade/old.glade/SearchDialog.ui
similarity index 80%
rename from src/Glade/SearchDialog.glade
rename to src/Glade/old.glade/SearchDialog.ui
index ea67ca8..672fa65 100644
--- a/src/Glade/SearchDialog.glade
+++ b/src/Glade/old.glade/SearchDialog.ui
@@ -1,8 +1,8 @@
 <?xml version="1.0"?>
-<glade-interface>
+<interface>
   <!-- interface-requires gtk+ 2.16 -->
   <!-- interface-naming-policy toplevel-contextual -->
-  <widget class="GtkDialog" id="dialog">
+  <object class="GtkDialog" id="dialog">
     <property name="title" translatable="yes">Replace</property>
     <property name="resizable">False</property>
     <property name="window_position">center-on-parent</property>
@@ -10,70 +10,70 @@
     <property name="type_hint">dialog</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
-      <widget class="GtkVBox" id="dialogVBox">
+      <object class="GtkVBox" id="dialogVBox">
         <property name="visible">True</property>
         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
         <property name="orientation">vertical</property>
         <property name="spacing">8</property>
         <child>
-          <widget class="GtkVBox" id="dialogContentVBox">
+          <object class="GtkVBox" id="dialogContentVBox">
             <property name="visible">True</property>
             <property name="border_width">10</property>
             <property name="orientation">vertical</property>
             <property name="spacing">18</property>
             <child>
-              <widget class="GtkTable" id="table">
+              <object class="GtkTable" id="table">
                 <property name="visible">True</property>
                 <property name="n_rows">2</property>
                 <property name="n_columns">2</property>
                 <property name="column_spacing">12</property>
                 <property name="row_spacing">12</property>
                 <child>
-                  <widget class="GtkLabel" id="replaceLabel">
+                  <object class="GtkLabel" id="replaceLabel">
                     <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="label" translatable="yes">Replace _with:</property>
                     <property name="use_underline">True</property>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="top_attach">1</property>
                     <property name="bottom_attach">2</property>
                     <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"></property>
+                    <property name="y_options"/>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkLabel" id="findLabel">
+                  <object class="GtkLabel" id="findLabel">
                     <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="label" translatable="yes">_Search for:</property>
                     <property name="use_underline">True</property>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"></property>
+                    <property name="y_options"/>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkEntry" id="findEntry">
+                  <object class="GtkEntry" id="findEntry">
                     <property name="width_request">300</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="activates_default">True</property>
-                    <signal name="changed" handler="OnFindTextChanged"/>
-                  </widget>
+                    <signal handler="OnFindTextChanged" name="changed"/>
+                  </object>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkEntry" id="replaceEntry">
+                  <object class="GtkEntry" id="replaceEntry">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="activates_default">True</property>
-                    <signal name="changed" handler="OnReplaceTextChanged"/>
-                  </widget>
+                    <signal handler="OnReplaceTextChanged" name="changed"/>
+                  </object>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
@@ -81,60 +81,60 @@
                     <property name="bottom_attach">2</property>
                   </packing>
                 </child>
-              </widget>
+              </object>
               <packing>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkVBox" id="optionsVBox">
+              <object class="GtkVBox" id="optionsVBox">
                 <property name="visible">True</property>
                 <property name="orientation">vertical</property>
                 <property name="spacing">12</property>
                 <child>
-                  <widget class="GtkCheckButton" id="matchCaseCheckButton">
+                  <object class="GtkCheckButton" id="matchCaseCheckButton">
                     <property name="label" translatable="yes">_Match case</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
                     <property name="use_underline">True</property>
                     <property name="draw_indicator">True</property>
-                    <signal name="toggled" handler="OnMatchCaseToggled"/>
-                  </widget>
+                    <signal handler="OnMatchCaseToggled" name="toggled"/>
+                  </object>
                   <packing>
                     <property name="position">0</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkCheckButton" id="backwardsCheckButton">
+                  <object class="GtkCheckButton" id="backwardsCheckButton">
                     <property name="label" translatable="yes">Search _backwards</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
                     <property name="use_underline">True</property>
                     <property name="draw_indicator">True</property>
-                    <signal name="toggled" handler="OnBackwardsToggled"/>
-                  </widget>
+                    <signal handler="OnBackwardsToggled" name="toggled"/>
+                  </object>
                   <packing>
                     <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkCheckButton" id="regexCheckButton">
+                  <object class="GtkCheckButton" id="regexCheckButton">
                     <property name="label" translatable="yes">Search using a Regular _Expression</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="receives_default">False</property>
                     <property name="use_underline">True</property>
                     <property name="draw_indicator">True</property>
-                    <signal name="toggled" handler="OnUseRegexToggled"/>
-                  </widget>
+                    <signal handler="OnUseRegexToggled" name="toggled"/>
+                  </object>
                   <packing>
                     <property name="position">2</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkCheckButton" id="wrapCheckButton">
+                  <object class="GtkCheckButton" id="wrapCheckButton">
                     <property name="label" translatable="yes">_Wrap around</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
@@ -142,36 +142,35 @@
                     <property name="use_underline">True</property>
                     <property name="active">True</property>
                     <property name="draw_indicator">True</property>
-                    <signal name="toggled" handler="OnWrapToggled"/>
-                  </widget>
+                    <signal handler="OnWrapToggled" name="toggled"/>
+                  </object>
                   <packing>
                     <property name="position">3</property>
                   </packing>
                 </child>
-              </widget>
+              </object>
               <packing>
                 <property name="position">1</property>
               </packing>
             </child>
-          </widget>
+          </object>
           <packing>
             <property name="position">1</property>
           </packing>
         </child>
         <child internal-child="action_area">
-          <widget class="GtkHButtonBox" id="dialogActionArea">
+          <object class="GtkHButtonBox" id="dialogActionArea">
             <property name="visible">True</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
             <child>
-              <widget class="GtkButton" id="buttonClose">
+              <object class="GtkButton" id="buttonClose">
                 <property name="label">gtk-close</property>
-                <property name="response_id">-6</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="use_stock">True</property>
-              </widget>
+              </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
@@ -179,15 +178,14 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="buttonReplaceAll">
+              <object class="GtkButton" id="buttonReplaceAll">
                 <property name="label" translatable="yes">Replace _All</property>
-                <property name="response_id">3</property>
                 <property name="visible">True</property>
                 <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
                 <property name="use_underline">True</property>
-              </widget>
+              </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
@@ -195,15 +193,14 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="buttonReplace">
+              <object class="GtkButton" id="buttonReplace">
                 <property name="label" translatable="yes">_Replace</property>
-                <property name="response_id">2</property>
                 <property name="visible">True</property>
                 <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
                 <property name="use_underline">True</property>
-              </widget>
+              </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
@@ -211,9 +208,8 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="buttonFind">
+              <object class="GtkButton" id="buttonFind">
                 <property name="label">gtk-find</property>
-                <property name="response_id">1</property>
                 <property name="visible">True</property>
                 <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
@@ -221,21 +217,27 @@
                 <property name="has_default">True</property>
                 <property name="receives_default">False</property>
                 <property name="use_stock">True</property>
-              </widget>
+              </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
                 <property name="position">3</property>
               </packing>
             </child>
-          </widget>
+          </object>
           <packing>
             <property name="expand">False</property>
             <property name="pack_type">end</property>
             <property name="position">0</property>
           </packing>
         </child>
-      </widget>
+      </object>
     </child>
-  </widget>
-</glade-interface>
+    <action-widgets>
+      <action-widget response="-6">buttonClose</action-widget>
+      <action-widget response="3">buttonReplaceAll</action-widget>
+      <action-widget response="2">buttonReplace</action-widget>
+      <action-widget response="1">buttonFind</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/src/GnomeSubtitles/Dialog/SearchDialog.cs b/src/GnomeSubtitles/Dialog/SearchDialog.cs
index ca82f74..253e4fd 100644
--- a/src/GnomeSubtitles/Dialog/SearchDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SearchDialog.cs
@@ -17,7 +17,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-//using Glade;
+using GnomeSubtitles.Core;
+using GnomeSubtitles.Ui;
 using Gtk;
 using Mono.Unix;
 using System;
@@ -25,9 +26,9 @@ using System.Text.RegularExpressions;
 
 namespace GnomeSubtitles.Dialog {
 
-internal enum SearchDialogResponse { Find = 1, Replace, ReplaceAll, Close = -6 };
+internal enum SearchDialogResponse { Find = 1, Replace, ReplaceAll };
 
-public class SearchDialog : BuilderDialog {
+public class SearchDialog : BaseDialog {
        private string text = String.Empty;             //The text to search for
        private Regex forwardRegex = null;              //The regex that corresponds to the text and the 
options
        private Regex backwardRegex = null;             //The regex that corresponds to the text and the 
options
@@ -38,26 +39,23 @@ public class SearchDialog : BuilderDialog {
        private bool useRegex = false;
        private bool wrap = true;
 
-       /* Constant strings */
-       private const string gladeFilename = "SearchDialog.glade";
-
        /* Widgets */
 
-       [Builder.Object] private Entry findEntry = null;
-       [Builder.Object] private Entry replaceEntry = null;
-       [Builder.Object] private Label replaceLabel = null;
-       [Builder.Object] private Table table = null;
+       private Entry findEntry = null;
+       private Entry replaceEntry = null;
+       private Label replaceLabel = null;
 
-       [Builder.Object] private CheckButton matchCaseCheckButton = null;
-       [Builder.Object] private CheckButton backwardsCheckButton = null;
-       [Builder.Object] private CheckButton regexCheckButton = null;
-       [Builder.Object] private CheckButton wrapCheckButton = null;
+       private CheckButton matchCaseCheckButton = null;
+       private CheckButton backwardsCheckButton = null;
+       private CheckButton regexCheckButton = null;
+       private CheckButton wrapCheckButton = null;
 
-       [Builder.Object] private Button buttonReplaceAll = null;
-       [Builder.Object] private Button buttonReplace = null;
-       [Builder.Object] private Button buttonFind = null;
+       private Button buttonReplaceAll = null;
+       private Button buttonReplace = null;
+       private Button buttonFind = null;
 
-       public SearchDialog () : base(gladeFilename) {
+       public SearchDialog () : base() {
+               base.Init(BuildDialog());
        }
 
        /* Overriden members */
@@ -105,11 +103,11 @@ public class SearchDialog : BuilderDialog {
        public void Show (bool useReplace) {
                if (useReplace) {
                        Dialog.Title = Catalog.GetString("Replace");
-                       table.RowSpacing = 12;
+//                     table.RowSpacing = 12;
                }
                else {
                        Dialog.Title = Catalog.GetString("Find");
-                       table.RowSpacing = 0;
+//                     table.RowSpacing = 0;
                }
 
                replaceEntry.Visible = useReplace;
@@ -124,21 +122,74 @@ public class SearchDialog : BuilderDialog {
 
        /* Private methods */
 
+       private Gtk.Dialog BuildDialog() {
+               Gtk.Dialog dialog = new Gtk.Dialog();
+
+               //Content area
+
+               Grid grid = new Grid();
+
+               grid.BorderWidth = WidgetStyles.BorderWidthLarge;
+               grid.ColumnSpacing = WidgetStyles.ColumnSpacingLarge;
+               grid.RowSpacing = WidgetStyles.RowSpacingLarge;
+
+               Label findLabel = new Label(Catalog.GetString("F_ind"));
+               findLabel.SetAlignment(1, 0.5f);
+               grid.Attach(findLabel, 0, 0, 1, 1);
+
+               findEntry = new Entry();
+               findEntry.Changed += OnFindTextChanged;
+               findEntry.ActivatesDefault = true;
+               grid.Attach(findEntry, 1, 0, 2, 1);
+
+               replaceLabel = new Label(Catalog.GetString("Replace _with"));
+               replaceLabel.SetAlignment(1, 0.5f);
+               grid.Attach(replaceLabel, 0, 1, 1, 1);
+
+               replaceEntry = new Entry();
+               replaceEntry.Changed += OnReplaceTextChanged;
+               replaceEntry.ActivatesDefault = true;
+               grid.Attach(replaceEntry, 1, 1, 2, 1);
+
+               matchCaseCheckButton = new CheckButton(Catalog.GetString("_Match case"));
+               matchCaseCheckButton.Toggled += OnMatchCaseToggled;
+               grid.Attach(matchCaseCheckButton, 1, 2, 1, 1);
+
+               backwardsCheckButton = new CheckButton(Catalog.GetString("Search _backwards"));
+               backwardsCheckButton.Toggled += OnBackwardsToggled;
+               grid.Attach(backwardsCheckButton, 2, 2, 1, 1);
+
+               regexCheckButton = new CheckButton(Catalog.GetString("Regular _expression"));
+               regexCheckButton.Toggled += OnUseRegexToggled;
+               grid.Attach(regexCheckButton, 1, 3, 1, 1);
+
+               wrapCheckButton = new CheckButton(Catalog.GetString("Wra_p around"));
+               wrapCheckButton.Toggled += OnWrapToggled;
+               grid.Attach(wrapCheckButton, 2, 3, 1, 1);
+
+               dialog.ContentArea.Add(grid);
+               dialog.ContentArea.ShowAll();
+
+               //Action area
+               buttonReplaceAll = dialog.AddButton(Catalog.GetString("Replace _All"), 
(int)SearchDialogResponse.ReplaceAll) as Button;
+               buttonReplace = dialog.AddButton(Catalog.GetString("_Replace"), 
(int)SearchDialogResponse.Replace) as Button;
+               buttonFind = dialog.AddButton(Util.GetStockLabel("gtk-find"), (int)SearchDialogResponse.Find) 
as Button;
+
+               dialog.DefaultResponse = (ResponseType)SearchDialogResponse.Find;
+
+               return dialog;
+       }
+
        private bool ValuesHaveChanged () {
-               if (!valuesMayHaveChanged)
+               if (!valuesMayHaveChanged) {
                        return false;
-               if (text != findEntry.Text)
-                       return true;
-               if (matchCase != matchCaseCheckButton.Active)
-                       return true;
-               if (backwards != backwardsCheckButton.Active)
-                       return true;
-               if (useRegex != regexCheckButton.Active)
-                       return true;
-               if (wrap != wrapCheckButton.Active)
-                       return true;
-
-               return false;
+               }
+               
+               return (text != findEntry.Text)
+               || (matchCase != matchCaseCheckButton.Active)
+               || (backwards != backwardsCheckButton.Active)
+               || (useRegex != regexCheckButton.Active)
+               || (wrap != wrapCheckButton.Active);
        }
 
        private void LoadDialogValues () {
@@ -170,25 +221,27 @@ public class SearchDialog : BuilderDialog {
        private void HandleValuesChange () {
                bool updateRegex = ValuesHaveChanged(); //Need to be before SaveDialogValues, as the values 
will be changed
                SaveDialogValues();
-               if (updateRegex)
+               if (updateRegex) {
                        UpdateRegex();
-
+               }
        }
 
        private void Find () {
                HandleValuesChange();
 
                bool found = Core.Base.Ui.View.Search.Find();
-               if (found)
+               if (found) {
                        buttonReplace.Sensitive = true;
+               }
        }
 
        private void Replace () {
                HandleValuesChange();
 
                bool foundNext = Core.Base.Ui.View.Search.Replace();
-               if (!foundNext) //No other text was found to replace, after replacing this one
+               if (!foundNext) { //No other text was found to replace, after replacing this one
                        buttonReplace.Sensitive = false;
+               }
        }
 
        private void ReplaceAll () {
@@ -199,8 +252,9 @@ public class SearchDialog : BuilderDialog {
 
        private void UpdateRegex() {
                RegexOptions options = RegexOptions.Singleline;
-               if (!matchCase)
+               if (!matchCase) {
                        options |= RegexOptions.IgnoreCase;
+               }
 
                string regexText = (useRegex ? text : Regex.Escape(text));
                forwardRegex = new Regex(regexText, options);
@@ -209,8 +263,6 @@ public class SearchDialog : BuilderDialog {
 
        /* Event members */
 
-       #pragma warning disable 169             //Disables warning about handlers not being used
-
        protected override bool ProcessResponse (ResponseType response) {
                SearchDialogResponse searchResponse = (SearchDialogResponse)response;
                switch (searchResponse) {
@@ -223,9 +275,6 @@ public class SearchDialog : BuilderDialog {
                        case SearchDialogResponse.ReplaceAll:
                                ReplaceAll();
                                return true;
-                       case SearchDialogResponse.Close:
-                               Hide();
-                               return false;
                        default:
                                return false;
                }
diff --git a/src/GnomeSubtitles/Ui/WidgetStyles.cs b/src/GnomeSubtitles/Ui/WidgetStyles.cs
index d26a6d4..a356a7b 100644
--- a/src/GnomeSubtitles/Ui/WidgetStyles.cs
+++ b/src/GnomeSubtitles/Ui/WidgetStyles.cs
@@ -44,6 +44,7 @@ public class WidgetStyles {
        public const int BorderWidthLarge = 12;
 
        public const int BoxSpacingMedium = 6;
+       public const int BoxSpacingLarge = 12;
 
 }
 


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