[gnome-subtitles/gtk3] Updating Encodings, FileOpen and VideoOpen dialogs



commit 58789ee89ffe6a4ac1ecaef0fd81236111bd813a
Author: Pedro Castro <pedro gnomesubtitles org>
Date:   Sat Nov 25 10:51:36 2017 +0000

    Updating Encodings, FileOpen and VideoOpen dialogs

 gnome-subtitles.csproj                             |    6 --
 src/Glade/{ => old.glade}/EncodingsDialog.glade    |    0
 .../EncodingsDialog.ui}                            |   84 ++++++++++----------
 src/GnomeSubtitles/Dialog/BaseDialog.cs            |   11 ++-
 src/GnomeSubtitles/Dialog/EncodingsDialog.cs       |   82 ++++++++++++++++---
 src/GnomeSubtitles/Dialog/FileOpenDialog.cs        |   36 ++++-----
 .../Dialog/FileTranslationOpenDialog.cs            |    7 +-
 src/GnomeSubtitles/Dialog/VideoOpenDialog.cs       |    4 +-
 .../Ui/Component/EncodingComboBox.cs               |    2 +-
 9 files changed, 140 insertions(+), 92 deletions(-)
---
diff --git a/gnome-subtitles.csproj b/gnome-subtitles.csproj
index f9b0a61..e5d13e1 100644
--- a/gnome-subtitles.csproj
+++ b/gnome-subtitles.csproj
@@ -60,18 +60,12 @@
     <EmbeddedResource Include="src\Glade\AboutDialog.glade">
       <LogicalName>AboutDialog.glade</LogicalName>
     </EmbeddedResource>
-    <EmbeddedResource Include="src\Glade\EncodingsDialog.glade">
-      <LogicalName>EncodingsDialog.glade</LogicalName>
-    </EmbeddedResource>
     <EmbeddedResource Include="src\Glade\FilePropertiesDialog.glade">
       <LogicalName>FilePropertiesDialog.glade</LogicalName>
     </EmbeddedResource>
     <EmbeddedResource Include="src\Glade\FileSaveAsDialog.glade">
       <LogicalName>FileSaveAsDialog.glade</LogicalName>
     </EmbeddedResource>
-    <EmbeddedResource Include="src\Glade\HeadersDialog.glade">
-      <LogicalName>HeadersDialog.glade</LogicalName>
-    </EmbeddedResource>
     <EmbeddedResource Include="src\Glade\PreferencesDialog.glade">
       <LogicalName>PreferencesDialog.glade</LogicalName>
     </EmbeddedResource>
diff --git a/src/Glade/EncodingsDialog.glade b/src/Glade/old.glade/EncodingsDialog.glade
similarity index 100%
copy from src/Glade/EncodingsDialog.glade
copy to src/Glade/old.glade/EncodingsDialog.glade
diff --git a/src/Glade/EncodingsDialog.glade b/src/Glade/old.glade/EncodingsDialog.ui
similarity index 80%
rename from src/Glade/EncodingsDialog.glade
rename to src/Glade/old.glade/EncodingsDialog.ui
index 37bc6ef..ab2b3eb 100644
--- a/src/Glade/EncodingsDialog.glade
+++ b/src/Glade/old.glade/EncodingsDialog.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="width_request">650</property>
     <property name="height_request">400</property>
     <property name="title" translatable="yes">Character codings</property>
@@ -11,28 +11,28 @@
     <property name="type_hint">normal</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="orientation">vertical</property>
         <child>
-          <widget class="GtkHBox" id="contentsHBox">
+          <object class="GtkHBox" id="contentsHBox">
             <property name="visible">True</property>
             <property name="border_width">6</property>
             <property name="spacing">6</property>
             <property name="homogeneous">True</property>
             <child>
-              <widget class="GtkVBox" id="availableVBox">
+              <object class="GtkVBox" id="availableVBox">
                 <property name="visible">True</property>
                 <property name="orientation">vertical</property>
                 <property name="spacing">6</property>
                 <child>
-                  <widget class="GtkLabel" id="availableLabel">
+                  <object class="GtkLabel" id="availableLabel">
                     <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="label" translatable="yes">A_vailable:</property>
                     <property name="use_underline">True</property>
                     <property name="mnemonic_widget">availableTreeView</property>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
@@ -40,69 +40,69 @@
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkScrolledWindow" id="availableScrolledWindow">
+                  <object class="GtkScrolledWindow" id="availableScrolledWindow">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hscrollbar_policy">automatic</property>
                     <property name="vscrollbar_policy">automatic</property>
                     <property name="shadow_type">etched-in</property>
                     <child>
-                      <widget class="GtkTreeView" id="availableTreeView">
+                      <object class="GtkTreeView" id="availableTreeView">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="rules_hint">True</property>
-                        <signal name="row_activated" handler="OnAvailableRowActivated"/>
-                      </widget>
+                        <signal handler="OnAvailableRowActivated" name="row_activated"/>
+                      </object>
                     </child>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkHBox" id="availableHBox">
+                  <object class="GtkHBox" id="availableHBox">
                     <property name="visible">True</property>
                     <child>
-                      <widget class="GtkButton" id="buttonAdd">
+                      <object class="GtkButton" id="buttonAdd">
                         <property name="label">gtk-add</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_stock">True</property>
-                        <signal name="clicked" handler="OnAdd"/>
-                      </widget>
+                        <signal handler="OnAdd" name="clicked"/>
+                      </object>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
                     <property name="position">2</property>
                   </packing>
                 </child>
-              </widget>
+              </object>
               <packing>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkVBox" id="shownVBox">
+              <object class="GtkVBox" id="shownVBox">
                 <property name="visible">True</property>
                 <property name="orientation">vertical</property>
                 <property name="spacing">6</property>
                 <child>
-                  <widget class="GtkLabel" id="shownLabel">
+                  <object class="GtkLabel" id="shownLabel">
                     <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="label" translatable="yes">Shown in menu:</property>
                     <property name="use_underline">True</property>
                     <property name="mnemonic_widget">shownTreeView</property>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
@@ -110,89 +110,91 @@
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkScrolledWindow" id="shownScrolledWindow">
+                  <object class="GtkScrolledWindow" id="shownScrolledWindow">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hscrollbar_policy">automatic</property>
                     <property name="vscrollbar_policy">automatic</property>
                     <property name="shadow_type">etched-in</property>
                     <child>
-                      <widget class="GtkTreeView" id="shownTreeView">
+                      <object class="GtkTreeView" id="shownTreeView">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="rules_hint">True</property>
-                        <signal name="row_activated" handler="OnShownRowActivated"/>
-                      </widget>
+                        <signal handler="OnShownRowActivated" name="row_activated"/>
+                      </object>
                     </child>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkHBox" id="shownHBox">
+                  <object class="GtkHBox" id="shownHBox">
                     <property name="visible">True</property>
                     <child>
-                      <widget class="GtkButton" id="buttonRemove">
+                      <object class="GtkButton" id="buttonRemove">
                         <property name="label">gtk-remove</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_stock">True</property>
-                        <signal name="clicked" handler="OnRemove"/>
-                      </widget>
+                        <signal handler="OnRemove" name="clicked"/>
+                      </object>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
-                  </widget>
+                  </object>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">False</property>
                     <property name="position">2</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="actionArea">
+          <object class="GtkHButtonBox" id="actionArea">
             <property name="visible">True</property>
             <property name="layout_style">end</property>
             <child>
-              <widget class="GtkButton" id="buttonClose">
+              <object class="GtkButton" id="buttonClose">
                 <property name="label">gtk-close</property>
-                <property name="response_id">-7</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="can_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">0</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="-7">buttonClose</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/src/GnomeSubtitles/Dialog/BaseDialog.cs b/src/GnomeSubtitles/Dialog/BaseDialog.cs
index 64fedcd..b7d0748 100644
--- a/src/GnomeSubtitles/Dialog/BaseDialog.cs
+++ b/src/GnomeSubtitles/Dialog/BaseDialog.cs
@@ -28,6 +28,9 @@ public abstract class BaseDialog {
        private Gtk.Dialog dialog = null;
        private bool returnValue = false;
 
+       //Hack because gtk# doesn't support this flag yet (as of 2017). Ref: 
https://git.gnome.org/browse/gtk+/tree/gtk/gtkdialog.h (GTK_DIALOG_USE_HEADER_BAR)
+       protected const DialogFlags DialogFlagsUseHeaderBar = (DialogFlags)4;
+
        public BaseDialog () {
        }
 
@@ -127,10 +130,10 @@ public abstract class BaseDialog {
 
        /* Private members */
 
-       private void SetBaseWindow (Gtk.Dialog dialog, Window window) {
-               dialog.TransientFor = window;
-               dialog.Icon = window.Icon; //TODO is this still needed?
-       }
+//     private void SetBaseWindow (Gtk.Dialog dialog, Window window) {
+//             dialog.TransientFor = window;
+//             dialog.Icon = window.Icon; //TODO is this still needed?
+//     }
 
 }
 
diff --git a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs b/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
index e67fa9a..079d177 100644
--- a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
+++ b/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
@@ -19,35 +19,33 @@
 
 using GnomeSubtitles.Core;
 using GnomeSubtitles.Dialog;
-//using Glade;
 using Gtk;
 using Mono.Unix;
 using System;
+using System.Runtime.InteropServices;
 
 namespace GnomeSubtitles.Dialog {
 
-public class EncodingsDialog : BuilderDialog {
+public class EncodingsDialog : BaseDialog {
        private string[] chosenNames = new string[0];
 
-       /* Constant strings */
-       private const string gladeFilename = "EncodingsDialog.glade";
-
        /* Constant integers */
        const int descColumnNum = 0; //The number of the Description column
        const int nameColumnNum = 1; //The number of the Name column
 
        /* Widgets */
 
-       [Builder.Object] private TreeView availableTreeView = null;
-       [Builder.Object] private TreeView shownTreeView = null;
-       [Builder.Object] private Button buttonAdd = null;
-       [Builder.Object] private Button buttonRemove = null;
+       private Gtk.Dialog dialog = null;
+       private TreeView availableTreeView = null;
+       private TreeView shownTreeView = null;
+       private Button buttonAdd = null;
+       private Button buttonRemove = null;
 
-       public EncodingsDialog () : base(gladeFilename) {
-               FillAvailableEncodings();
-               FillShownEncodings();
+       public EncodingsDialog (Window parent) : base() {
+               BuildDialog(parent);
 
                ConnectSignals();
+               base.Init(dialog);
        }
 
        /* Public properties */
@@ -58,6 +56,59 @@ public class EncodingsDialog : BuilderDialog {
 
        /* Private members */
 
+       private void BuildDialog (Window parent) {
+               dialog = new Gtk.Dialog(Catalog.GetString("Character Encodings"), parent, DialogFlags.Modal | 
DialogFlagsUseHeaderBar);
+
+               dialog.WidthRequest = 600;
+               dialog.HeightRequest = 400;
+
+               Grid grid = new Grid();
+               grid.RowSpacing = 6;
+               grid.ColumnSpacing = 12;
+               grid.BorderWidth = 6;
+               grid.ColumnHomogeneous = true;
+
+               /* Left part: Available VBox */
+
+               Label availLabel = new Label("<b>" + Catalog.GetString("Available Encodings") + "</b>");
+               availLabel.UseMarkup = true;
+               availLabel.Halign = Align.Start;
+               grid.Attach(availLabel, 0, 0, 1, 1);
+
+               ScrolledWindow availScrolledWindow = new ScrolledWindow();
+               availScrolledWindow.ShadowType = ShadowType.EtchedIn;
+               availScrolledWindow.Expand = true;
+               availableTreeView = new TreeView();
+               availScrolledWindow.Add(availableTreeView);
+               grid.Attach(availScrolledWindow, 0, 1, 1, 1);
+
+               buttonAdd = new Button("gtk-add");
+               grid.Attach(buttonAdd, 0, 2, 1, 1);
+
+               /* Right part: Shown VBox */
+
+               Label shownLabel = new Label("<b>" + Catalog.GetString("Chosen Encodings") + "</b>");
+               shownLabel.UseMarkup = true;
+               shownLabel.Halign = Align.Start;
+               grid.Attach(shownLabel, 1, 0, 1, 1);
+
+               ScrolledWindow shownScrolledWindow = new ScrolledWindow();
+               shownScrolledWindow.ShadowType = ShadowType.EtchedIn;
+               shownScrolledWindow.Expand = true;
+               shownTreeView = new TreeView();
+               shownScrolledWindow.Add(shownTreeView);
+               grid.Attach(shownScrolledWindow, 1, 1, 1, 1);
+
+               buttonRemove = new Button("gtk-remove");
+               grid.Attach(buttonRemove, 1, 2, 1, 1);
+
+               FillAvailableEncodings();
+               FillShownEncodings();
+
+               dialog.ContentArea.Add(grid);
+               dialog.ContentArea.ShowAll();
+       }
+
        private void FillAvailableEncodings () {
                SetColumns(availableTreeView);
 
@@ -183,11 +234,14 @@ public class EncodingsDialog : BuilderDialog {
 
        private void ConnectSignals () {
                availableTreeView.Selection.Changed += OnAvailableSelectionChanged;
+               availableTreeView.RowActivated += OnAvailableRowActivated;
+               buttonAdd.Clicked += OnAdd;
+
                shownTreeView.Selection.Changed += OnShownSelectionChanged;
+               shownTreeView.RowActivated += OnShownRowActivated;
+               buttonRemove.Clicked += OnRemove;
        }
 
-       #pragma warning disable 169             //Disables warning about handlers not being used
-
        private void OnAvailableSelectionChanged (object o, EventArgs args) {
                bool sensitive = (availableTreeView.Selection.CountSelectedRows() == 1);
                buttonAdd.Sensitive = sensitive;
diff --git a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
index 964ed40..6aaf7a0 100644
--- a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
@@ -20,7 +20,6 @@
 using GnomeSubtitles.Core;
 using GnomeSubtitles.Ui.Component;
 using GnomeSubtitles.Ui.VideoPreview;
-//using Glade;
 using Gtk;
 using Mono.Unix;
 using SubLib.Core.Domain;
@@ -55,33 +54,27 @@ public class FileOpenDialog : BaseDialog {
        }
 
        protected FileOpenDialog (bool toEnableVideo, string title) : base() {
-               dialog = new FileChooserDialog(title, Base.Ui.Window, FileChooserAction.Open,
-                       Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel, 
Util.GetStockLabel("gtk-open"), ResponseType.Ok);
-
-               dialog.DefaultResponse = ResponseType.Ok;
-
-               InitContentArea();
+               BuildDialog(title);
 
                if (toEnableVideo) {
                        EnableVideo();
                }
 
-               dialog.SetCurrentFolder(GetStartFolder());
+               base.Init(dialog);
+       }
 
-               SetFilters();
+       private void BuildDialog(string title) {
+               dialog = new FileChooserDialog(title, Base.Ui.Window, FileChooserAction.Open,
+                       Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel, 
Util.GetStockLabel("gtk-open"), ResponseType.Ok);
 
-               Init(dialog);
-       }
+               dialog.DefaultResponse = ResponseType.Ok;
 
-       private void InitContentArea() {
-               Grid grid = new Grid();
+               /* Build content area */
 
+               Grid grid = new Grid();
                grid.RowSpacing = 6;
                grid.ColumnSpacing = 6;
-               grid.MarginLeft = 6;
-               grid.MarginRight = 6;
-               grid.MarginTop = 8;
-               grid.MarginBottom = 10;
+               grid.BorderWidth = 6;
 
                Label encodingLabel = new Label(Catalog.GetString("Character Encoding:"));
                encodingLabel.Xalign = 0;
@@ -102,6 +95,10 @@ public class FileOpenDialog : BaseDialog {
 
                dialog.ContentArea.Add(grid);
                dialog.ContentArea.ShowAll();
+
+               /* Other stuff */
+               SetFilters();
+               dialog.SetCurrentFolder(GetStartFolder());
        }
 
        private EncodingComboBox BuildEncodingComboBox () {
@@ -305,15 +302,14 @@ public class FileOpenDialog : BaseDialog {
                        filterPosition++;
                }
 
-               foreach (FileFilter filter in filters)
+               foreach (FileFilter filter in filters) {
                        dialog.AddFilter(filter);
+               }
 
                dialog.Filter = subtitleFilesFilter;
        }
 
 
-       #pragma warning disable 169             //Disables warning about handlers not being used
-
        protected override bool ProcessResponse (ResponseType response) {
                if (response == ResponseType.Ok) {
                        chosenFilename = dialog.Filename;
diff --git a/src/GnomeSubtitles/Dialog/FileTranslationOpenDialog.cs 
b/src/GnomeSubtitles/Dialog/FileTranslationOpenDialog.cs
index 8c16fdf..10c8eb6 100644
--- a/src/GnomeSubtitles/Dialog/FileTranslationOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FileTranslationOpenDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2010 Pedro Castro
+ * Copyright (C) 2007-2017 Pedro Castro
  *
  * Gnome Subtitles is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,10 +30,11 @@ public class FileTranslationOpenDialog : FileOpenDialog {
        /* Public members */
 
        protected override string GetStartFolder () {
-               if (Base.IsDocumentLoaded && Base.Document.IsTranslationLoaded && 
Base.Document.HasTranslationFileProperties && Base.Document.TranslationFile.IsPathRooted)
+               if (Base.IsDocumentLoaded && Base.Document.IsTranslationLoaded && 
Base.Document.HasTranslationFileProperties && Base.Document.TranslationFile.IsPathRooted) {
                        return Base.Document.TranslationFile.Directory;
-               else
+               } else {
                        return base.GetStartFolder();
+               }
        }
 
 }
diff --git a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs b/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
index b55593e..557b313 100644
--- a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
@@ -41,7 +41,7 @@ public class VideoOpenDialog : BaseDialog {
                }
 
                SetFilters();
-               Init(dialog);
+               base.Init(dialog);
        }
 
        /* Public properties */
@@ -82,8 +82,6 @@ public class VideoOpenDialog : BaseDialog {
 
        /* Event members */
 
-       #pragma warning disable 169             //Disables warning about handlers not being used
-
        protected override bool ProcessResponse (ResponseType response) {
                if (response == ResponseType.Ok) {
                        if (dialog.Uri != null) {
diff --git a/src/GnomeSubtitles/Ui/Component/EncodingComboBox.cs 
b/src/GnomeSubtitles/Ui/Component/EncodingComboBox.cs
index 6fe14d8..14f0a6f 100644
--- a/src/GnomeSubtitles/Ui/Component/EncodingComboBox.cs
+++ b/src/GnomeSubtitles/Ui/Component/EncodingComboBox.cs
@@ -221,7 +221,7 @@ public class EncodingComboBox {
                int selectedItem = comboBox.Active;
 
                if (selectedItem == (itemCount - 1)) {
-                       EncodingsDialog dialog = Base.Dialogs.Get(typeof(EncodingsDialog)) as EncodingsDialog;
+                       EncodingsDialog dialog = Base.Dialogs.Get(typeof(EncodingsDialog), comboBox.Toplevel) 
as EncodingsDialog;
                        dialog.Show();
                        dialog.WaitForResponse();
                        SetComboBox(dialog.ChosenNames);


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