[gnome-subtitles/gtk3] Set Languages Dialog refactor.



commit 11dbaeda03aac1ff9c4d200ee77351e986888d30
Author: Pedro Castro <pedro gnomesubtitles org>
Date:   Tue Jan 30 18:48:51 2018 +0000

    Set Languages Dialog refactor.

 gnome-subtitles.csproj                             |   11 +-
 src/Glade/MainWindow.ui                            |   32 +--
 src/Glade/{ => old.glade}/SetLanguageDialog.glade  |    0
 .../SetLanguageDialog.ui}                          |  131 +++++++------
 .../Core/Command/TranslatorCommand.cs              |   22 +--
 src/GnomeSubtitles/Core/EventHandlers.cs           |    8 +-
 src/GnomeSubtitles/Core/SpellLanguages.cs          |   14 ++-
 src/GnomeSubtitles/Dialog/EncodingsDialog.cs       |    5 +-
 src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs  |    7 +-
 src/GnomeSubtitles/Dialog/HeadersDialog.cs         |   13 +-
 src/GnomeSubtitles/Dialog/SetLanguageDialog.cs     |  148 ---------------
 src/GnomeSubtitles/Dialog/SetLanguagesDialog.cs    |  195 ++++++++++++++++++++
 .../Dialog/SetTranslationLanguageDialog.cs         |   31 ---
 src/GnomeSubtitles/Ui/Menus.cs                     |    3 +-
 src/GnomeSubtitles/Ui/WidgetNames.cs               |    3 +-
 .../WidgetStyles.cs}                               |   18 +-
 16 files changed, 327 insertions(+), 314 deletions(-)
---
diff --git a/gnome-subtitles.csproj b/gnome-subtitles.csproj
index e709aca..d0d49a7 100644
--- a/gnome-subtitles.csproj
+++ b/gnome-subtitles.csproj
@@ -161,9 +161,6 @@
     <Compile Include="src\GnomeSubtitles\Dialog\MessageDialog.cs" />
     <Compile Include="src\GnomeSubtitles\Dialog\PreferencesDialog.cs" />
     <Compile Include="src\GnomeSubtitles\Dialog\SearchDialog.cs" />
-    <Compile Include="src\GnomeSubtitles\Dialog\SetLanguageDialog.cs" />
-    <Compile Include="src\GnomeSubtitles\Dialog\SetTextLanguageDialog.cs" />
-    <Compile Include="src\GnomeSubtitles\Dialog\SetTranslationLanguageDialog.cs" />
     <Compile Include="src\GnomeSubtitles\Dialog\TimingsAdjustDialog.cs" />
     <Compile Include="src\GnomeSubtitles\Dialog\TimingsShiftDialog.cs" />
     <Compile Include="src\GnomeSubtitles\Dialog\TimingsSynchronizeDialog.cs" />
@@ -285,6 +282,8 @@
     <Compile Include="src\GnomeSubtitles\Dialog\FileSaveDialog.cs" />
     <Compile Include="src\GnomeSubtitles\Dialog\FileTranslationSaveDialog.cs" />
     <Compile Include="src\SubLib\Util\Logger.cs" />
+    <Compile Include="src\GnomeSubtitles\Dialog\SetLanguagesDialog.cs" />
+    <Compile Include="src\GnomeSubtitles\Ui\WidgetStyles.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ItemGroup>
@@ -292,15 +291,9 @@
     <Folder Include="src\SubLib\Util\" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="src\Glade\AboutDialog.glade">
-      <LogicalName>AboutDialog.glade</LogicalName>
-    </None>
     <None Include="src\Glade\SearchDialog.glade">
       <LogicalName>SearchDialog.glade</LogicalName>
     </None>
-    <None Include="src\Glade\SetLanguageDialog.glade">
-      <LogicalName>SetLanguageDialog.glade</LogicalName>
-    </None>
     <None Include="src\Glade\TimingsAdjustDialog.glade">
       <LogicalName>TimingsAdjustDialog.glade</LogicalName>
     </None>
diff --git a/src/Glade/MainWindow.ui b/src/Glade/MainWindow.ui
index 6122edb..397aeec 100644
--- a/src/Glade/MainWindow.ui
+++ b/src/Glade/MainWindow.ui
@@ -248,8 +248,8 @@
                         <property name="label" translatable="yes">_Redo</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnEditRedo" swapped="no"/>
-                        <accelerator key="y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="z" signal="activate" modifiers="GDK_SHIFT_MASK | 
GDK_CONTROL_MASK"/>
+                        <accelerator key="y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </object>
                     </child>
                     <child>
@@ -571,8 +571,8 @@
                         <property name="label" translatable="yes">Find Ne_xt</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindNext" swapped="no"/>
-                        <accelerator key="F3" signal="activate"/>
                         <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F3" signal="activate"/>
                       </object>
                     </child>
                     <child>
@@ -582,8 +582,8 @@
                         <property name="label" translatable="yes">Find Pre_vious</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindPrevious" swapped="no"/>
-                        <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
                         <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK | 
GDK_CONTROL_MASK"/>
+                        <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
                       </object>
                     </child>
                     <child>
@@ -824,8 +824,8 @@
                         <property name="label" translatable="yes">_Play / Pause</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoPlayPause" swapped="no"/>
-                        <accelerator key="F5" signal="activate"/>
                         <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F5" signal="activate"/>
                       </object>
                     </child>
                     <child>
@@ -847,8 +847,8 @@
                         <property name="label" translatable="yes">R_ewind</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoRewind" swapped="no"/>
-                        <accelerator key="F6" signal="activate"/>
                         <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F6" signal="activate"/>
                       </object>
                     </child>
                     <child>
@@ -859,8 +859,8 @@
                         <property name="label" translatable="yes">_Forward</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoForward" swapped="no"/>
-                        <accelerator key="F7" signal="activate"/>
                         <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F7" signal="activate"/>
                       </object>
                     </child>
                     <child>
@@ -888,8 +888,8 @@
                         <property name="label" translatable="yes">Seek _to Selection</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSeekToSelection" swapped="no"/>
-                        <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | 
GDK_CONTROL_MASK"/>
                         <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK | 
GDK_CONTROL_MASK"/>
+                        <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | 
GDK_CONTROL_MASK"/>
                       </object>
                     </child>
                     <child>
@@ -900,8 +900,8 @@
                         <property name="label" translatable="yes">Select _Nearest Subtitle</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSelectNearestSubtitle" swapped="no"/>
-                        <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </object>
                     </child>
                     <child>
@@ -969,23 +969,13 @@
                       </object>
                     </child>
                     <child>
-                      <object class="GtkMenuItem" id="toolsSetTextLanguage">
-                        <property name="visible">True</property>
-                        <property name="sensitive">False</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Set T_ext Language</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="OnToolsSetTextLanguage" swapped="no"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="toolsSetTranslationLanguage">
+                      <object class="GtkMenuItem" id="toolsSetLanguages">
                         <property name="visible">True</property>
                         <property name="sensitive">False</property>
                         <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Set Translati_on Language</property>
+                        <property name="label" translatable="yes">Set _Languages</property>
                         <property name="use_underline">True</property>
-                        <signal name="activate" handler="OnToolsSetTranslationLanguage" swapped="no"/>
+                        <signal name="activate" handler="OnToolsSetLanguages" swapped="no"/>
                       </object>
                     </child>
                     <child>
diff --git a/src/Glade/SetLanguageDialog.glade b/src/Glade/old.glade/SetLanguageDialog.glade
similarity index 100%
copy from src/Glade/SetLanguageDialog.glade
copy to src/Glade/old.glade/SetLanguageDialog.glade
diff --git a/src/Glade/SetLanguageDialog.glade b/src/Glade/old.glade/SetLanguageDialog.ui
similarity index 66%
rename from src/Glade/SetLanguageDialog.glade
rename to src/Glade/old.glade/SetLanguageDialog.ui
index 7c59112..55e47f8 100644
--- a/src/Glade/SetLanguageDialog.glade
+++ b/src/Glade/old.glade/SetLanguageDialog.ui
@@ -1,33 +1,34 @@
-<?xml version="1.0"?>
-<glade-interface>
-  <!-- interface-requires gtk+ 2.16 -->
-  <!-- interface-naming-policy toplevel-contextual -->
-  <widget class="GtkDialog" id="dialog">
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkDialog" id="dialog">
+    <property name="can_focus">False</property>
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Set language</property>
     <property name="modal">True</property>
     <property name="destroy_with_parent">True</property>
     <property name="type_hint">dialog</property>
-    <property name="has_separator">False</property>
     <child internal-child="vbox">
-      <widget class="GtkVBox" id="dialogVBox">
+      <object class="GtkBox" id="dialogVBox">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
-        <child>
-          <widget class="GtkVBox" id="vBox">
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialogActionArea">
             <property name="visible">True</property>
-            <property name="border_width">5</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">11</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
             <child>
-              <widget class="GtkLabel" id="introLabel">
+              <object class="GtkButton" id="buttonCancel">
+                <property name="label">gtk-cancel</property>
                 <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="use_underline">True</property>
-                <property name="wrap">True</property>
-                <property name="mnemonic_widget">languagesTreeView</property>
-              </widget>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
@@ -35,45 +36,43 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkScrolledWindow" id="scrolledWindow">
+              <object class="GtkButton" id="buttonOK">
+                <property name="label">gtk-ok</property>
                 <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="languagesTreeView">
-                    <property name="height_request">180</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="headers_visible">False</property>
-                    <signal name="row_activated" handler="OnLanguageRowActivated"/>
-                  </widget>
-                </child>
-              </widget>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </object>
               <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="position">1</property>
               </packing>
             </child>
-          </widget>
+          </object>
           <packing>
-            <property name="position">1</property>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
           </packing>
         </child>
-        <child internal-child="action_area">
-          <widget class="GtkHButtonBox" id="dialogActionArea">
+        <child>
+          <object class="GtkVBox" id="vBox">
             <property name="visible">True</property>
-            <property name="layout_style">end</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">5</property>
+            <property name="spacing">11</property>
             <child>
-              <widget class="GtkButton" id="buttonCancel">
-                <property name="label">gtk-cancel</property>
-                <property name="response_id">-6</property>
+              <object class="GtkLabel" id="introLabel">
                 <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>
+                <property name="can_focus">False</property>
+                <property name="use_underline">True</property>
+                <property name="wrap">True</property>
+                <property name="mnemonic_widget">languagesTreeView</property>
+                <property name="xalign">0</property>
+              </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
@@ -81,29 +80,41 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="buttonOK">
-                <property name="label">gtk-ok</property>
-                <property name="response_id">-5</property>
+              <object class="GtkScrolledWindow" id="scrolledWindow">
                 <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>
+                <property name="shadow_type">etched-in</property>
+                <child>
+                  <object class="GtkTreeView" id="languagesTreeView">
+                    <property name="height_request">180</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="headers_visible">False</property>
+                    <signal name="row-activated" handler="OnLanguageRowActivated" swapped="no"/>
+                    <child internal-child="selection">
+                      <object class="GtkTreeSelection"/>
+                    </child>
+                  </object>
+                </child>
+              </object>
               <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
                 <property name="position">1</property>
               </packing>
             </child>
-          </widget>
+          </object>
           <packing>
             <property name="expand">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
           </packing>
         </child>
-      </widget>
+      </object>
     </child>
-  </widget>
-</glade-interface>
+    <action-widgets>
+      <action-widget response="-6">buttonCancel</action-widget>
+      <action-widget response="-5">buttonOK</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/src/GnomeSubtitles/Core/Command/TranslatorCommand.cs 
b/src/GnomeSubtitles/Core/Command/TranslatorCommand.cs
index 49bc91d..6095288 100644
--- a/src/GnomeSubtitles/Core/Command/TranslatorCommand.cs
+++ b/src/GnomeSubtitles/Core/Command/TranslatorCommand.cs
@@ -64,20 +64,18 @@ public class TranslatorCommand : FixedSingleSelectionCommand {
        }
 
        private bool DoTranslation () {
-               if (Base.Ui.View.Selection.Count != 1) //TODO: for now, only works if 1 subtitle is selected
+               if (Base.Ui.View.Selection.Count != 1) { //TODO: for now, only works if 1 subtitle is selected
                        return false;
-
-               /* Show language selection dialogs if no languages are selected */
-               if (!Base.SpellLanguages.HasActiveTextLanguage) {
-                       Base.Dialogs.Get(typeof(SetTextLanguageDialog)).Show();
-                       if (!Base.SpellLanguages.HasActiveTextLanguage)
-                               return false;
                }
 
-               if (!Base.SpellLanguages.HasActiveTranslationLanguage) {
-                       Base.Dialogs.Get(typeof(SetTranslationLanguageDialog)).Show();
-                       if (!Base.SpellLanguages.HasActiveTranslationLanguage)
-                               return false;
+               /* Show language selection dialog if one of the languages isn't selected */
+               if (!Base.SpellLanguages.HasActiveTextLanguage || 
!Base.SpellLanguages.HasActiveTranslationLanguage) {
+                       SetLanguagesDialog dialog = Base.Dialogs.Get(typeof(SetLanguagesDialog)) as 
SetLanguagesDialog;
+                       dialog.Show();
+                       dialog.WaitForResponse();
+                       if (!Base.SpellLanguages.HasActiveTextLanguage || 
!Base.SpellLanguages.HasActiveTranslationLanguage) {
+                               return false; //Both must be selected, if they aren't we just don't do 
anything here
+                       }
                }
 
                try {
@@ -93,7 +91,7 @@ public class TranslatorCommand : FixedSingleSelectionCommand {
                                subtitle.Text.Set(translatedText);
                        }
 
-                       //TODO: if only one subtitle selected, set the cursor on the translated text box and 
select its text. If multiple subtitles translated, select those subtitles.
+                       //TODO: if only one subtitle is selected, set the cursor on the translated text box 
and select its text. If multiple subtitles translated, select those subtitles.
                        return true;
                }
                catch (TranslatorException e) { //TODO know which exceptions are originally thrown. Check if 
it's possible to have the second error message in the application language.
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index ee4f823..46d3e24 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -380,12 +380,8 @@ public class EventHandlers {
                Base.SpellLanguages.Enabled = enabled;
        }
 
-       public void OnToolsSetTextLanguage (object o, EventArgs args) {
-               Base.Dialogs.Get(typeof(SetTextLanguageDialog)).Show();
-       }
-
-       public void OnToolsSetTranslationLanguage (object o, EventArgs args) {
-               Base.Dialogs.Get(typeof(SetTranslationLanguageDialog)).Show();
+       public void OnToolsSetLanguages (object o, EventArgs args) {
+               Base.Dialogs.Get(typeof(SetLanguagesDialog)).Show();
        }
 
        public void OnToolsTranslateText (object o, EventArgs args) {
diff --git a/src/GnomeSubtitles/Core/SpellLanguages.cs b/src/GnomeSubtitles/Core/SpellLanguages.cs
index f968577..1b5024c 100644
--- a/src/GnomeSubtitles/Core/SpellLanguages.cs
+++ b/src/GnomeSubtitles/Core/SpellLanguages.cs
@@ -20,6 +20,7 @@
 using Gtk;
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using SubLib.Core.Domain;
 using SubLib.Util;
@@ -172,9 +173,18 @@ public class SpellLanguages {
                enchant_broker_list_dicts (broker, languageListHandler, IntPtr.Zero);
 
                enchant_broker_free(broker);
-
+                
                languages.Sort();
-               Logger.Info("[Spellcheck] Found {0} languages", languages.Count);
+               Logger.Info("[Spellcheck] Found {0} languages: {1}", languages.Count, 
GetLanguageIDsAsString(languages));
+       }
+
+       private string GetLanguageIDsAsString (ArrayList languages) {
+               List<string> ids = new List<string>();
+               foreach (SpellLanguage language in languages) {
+                       ids.Add(language.ID);
+               }
+
+               return String.Join(",", ids);
        }
 
        private void GetActiveLanguagesFromConfig () {
diff --git a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs b/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
index 5396e3d..3325e8e 100644
--- a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
+++ b/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
@@ -19,6 +19,7 @@
 
 using GnomeSubtitles.Core;
 using GnomeSubtitles.Dialog;
+using GnomeSubtitles.Ui;
 using Gtk;
 using Mono.Unix;
 using System;
@@ -55,8 +56,8 @@ public class EncodingsDialog : BaseDialog {
        private Gtk.Dialog BuildDialog (Window parent) {
                Gtk.Dialog dialog = new Gtk.Dialog(Catalog.GetString("Character Encodings"), parent, 
DialogFlags.Modal | DialogFlagsUseHeaderBar);
 
-               dialog.DefaultWidth = 600;
-               dialog.DefaultHeight = 400;
+               dialog.DefaultWidth = WidgetStyles.DialogWidthMedium;
+               dialog.DefaultHeight = WidgetStyles.DialogHeightMedium;
 
                Grid grid = new Grid();
                grid.RowSpacing = 6;
diff --git a/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs 
b/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
index 9590dd5..31e639c 100644
--- a/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2017 Pedro Castro
+ * Copyright (C) 2007-2018 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
@@ -18,7 +18,6 @@
  */
 
 using GnomeSubtitles.Core;
-//using Glade;
 using Gtk;
 using Mono.Unix;
 using SubLib.Core.Domain;
@@ -41,10 +40,6 @@ public class FilePropertiesDialog : BaseDialog {
 
                Gtk.Dialog dialog = new Gtk.Dialog(Catalog.GetString("File Properties"), Base.Ui.Window, 
DialogFlags.Modal | DialogFlagsUseHeaderBar);
 
-//             dialog.DefaultResponse = ResponseType.Ok;
-//             dialog.DefaultWidth = 600;
-//             dialog.DefaultHeight = 550;
-
                Grid grid = new Grid();
                grid.BorderWidth = 15;
                grid.ColumnSpacing = 15;
diff --git a/src/GnomeSubtitles/Dialog/HeadersDialog.cs b/src/GnomeSubtitles/Dialog/HeadersDialog.cs
index 8a2c270..6e6a87a 100644
--- a/src/GnomeSubtitles/Dialog/HeadersDialog.cs
+++ b/src/GnomeSubtitles/Dialog/HeadersDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2017 Pedro Castro
+ * Copyright (C) 2006-2018 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
@@ -18,12 +18,13 @@
  */
 
 using GnomeSubtitles.Core;
-using System;
+using GnomeSubtitles.Ui;
 using Gtk;
-using SubLib.Core.Domain;
 using Mono.Unix;
-using System.Reflection;
+using SubLib.Core.Domain;
 using SubLib.IO.SubtitleFormats;
+using System;
+using System.Reflection;
 
 namespace GnomeSubtitles.Dialog {
 
@@ -49,8 +50,8 @@ public class HeadersDialog : BaseDialog {
                        Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel, 
Util.GetStockLabel("gtk-apply"), ResponseType.Ok);
 
                dialog.DefaultResponse = ResponseType.Ok;
-               dialog.DefaultWidth = 600;
-               dialog.DefaultHeight = 550;
+               dialog.DefaultWidth = WidgetStyles.DialogWidthMedium;
+               dialog.DefaultHeight = WidgetStyles.DialogHeightLarge;
 
                Notebook notebook = new Notebook();
                notebook.Expand = true;
diff --git a/src/GnomeSubtitles/Dialog/SetLanguagesDialog.cs b/src/GnomeSubtitles/Dialog/SetLanguagesDialog.cs
new file mode 100644
index 0000000..ebf6900
--- /dev/null
+++ b/src/GnomeSubtitles/Dialog/SetLanguagesDialog.cs
@@ -0,0 +1,195 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2008-2018 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome Subtitles is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+using GnomeSubtitles.Core;
+using GnomeSubtitles.Ui;
+using Gtk;
+using Mono.Unix;
+using SubLib.Core.Domain;
+using System;
+
+namespace GnomeSubtitles.Dialog {
+
+public class SetLanguagesDialog : BaseDialog {
+
+       /* Widgets */
+       private TreeView textTreeView = null;
+       private TreeView transTreeView = null;
+
+
+       public SetLanguagesDialog () : base() {
+               Init(BuildDialog());
+       }
+
+       private Gtk.Dialog BuildDialog () {
+               Gtk.Dialog dialog = new Gtk.Dialog(Catalog.GetString("Set Languages"), Base.Ui.Window, 
DialogFlags.Modal | DialogFlagsUseHeaderBar,
+                       Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel, 
Util.GetStockLabel("gtk-apply"), ResponseType.Ok);
+
+               dialog.DefaultResponse = ResponseType.Ok;
+               dialog.DefaultWidth = WidgetStyles.DialogWidthMedium;
+               dialog.DefaultHeight = WidgetStyles.DialogHeightMedium;
+
+               Grid grid = new Grid();
+               grid.RowSpacing = 6;
+               grid.ColumnSpacing = 12;
+               grid.BorderWidth = 6;
+               grid.ColumnHomogeneous = true;
+
+               /* Left part: Text Language */
+
+               Label textLabel = new Label("<b>" + Catalog.GetString("Text Language") + "</b>");
+               textLabel.UseMarkup = true;
+               textLabel.Halign = Align.Start;
+               grid.Attach(textLabel, 0, 0, 1, 1);
+
+               textTreeView = CreateTreeView();
+               ScrolledWindow textScrolledWindow = CreateLanguagesScrolledWindow(textTreeView);
+               SelectActiveLanguage(textTreeView, SubtitleTextType.Text);
+               grid.Attach(textScrolledWindow, 0, 1, 1, 1);
+
+               /* Right part: Translation Language */
+
+               Label transLabel = new Label("<b>" + Catalog.GetString("Translation Language") + "</b>");
+               transLabel.UseMarkup = true;
+               transLabel.Halign = Align.Start;
+               grid.Attach(transLabel, 1, 0, 1, 1);
+
+               transTreeView = CreateTreeView();
+               ScrolledWindow transScrolledWindow = CreateLanguagesScrolledWindow(transTreeView);
+               if (Base.Document.IsTranslationLoaded) {
+                       SelectActiveLanguage(transTreeView, SubtitleTextType.Translation);
+               } else {
+                       transScrolledWindow.Sensitive = false;
+               }
+               grid.Attach(transScrolledWindow, 1, 1, 1, 1);
+
+               dialog.ContentArea.Add(grid);
+               dialog.ContentArea.ShowAll();
+
+               ConnectSignals();
+
+               return dialog;
+       }
+
+       private TreeView CreateTreeView () {
+               TreeView treeView = new TreeView();
+               treeView.HeadersVisible = false;
+
+               TreeViewColumn col = new TreeViewColumn("col", new CellRendererText(), "text", 0);
+               treeView.AppendColumn(col);
+
+               treeView.Model = CreateLanguagesListStore();
+               return treeView;
+       }
+
+       private ScrolledWindow CreateLanguagesScrolledWindow (TreeView treeView) {
+               ScrolledWindow scrolledWindow = new ScrolledWindow();
+               scrolledWindow.ShadowType = ShadowType.EtchedIn;
+               scrolledWindow.Expand = true;
+               scrolledWindow.Add(treeView);
+               return scrolledWindow;
+       }
+
+       private ListStore CreateLanguagesListStore () {
+               ListStore store = new ListStore(typeof(string));
+
+               foreach (SpellLanguage language in Base.SpellLanguages.Languages) {
+                       store.AppendValues(language.Name);
+               }
+
+               return store;
+       }
+
+       private void SelectActiveLanguage (TreeView treeView, SubtitleTextType textType) {
+               int count = treeView.Model.IterNChildren();
+               if (count == 0)
+                       return;
+
+               int activeLanguageIndex = GetActiveLanguageIndex(textType, count);
+
+               TreePath path = Core.Util.IntToPath(activeLanguageIndex);
+               treeView.ScrollToCell(path, null, true, 0.5f, 0.5f);
+               treeView.SetCursor(path, null, false);
+       }
+
+       private int GetActiveLanguageIndex (SubtitleTextType textType, int count) {
+               int activeLanguageIndex = Base.SpellLanguages.GetActiveLanguageIndex(textType);
+               /* Set active language to the first if invalid */
+               if ((activeLanguageIndex == -1) || (activeLanguageIndex >= count))
+                       activeLanguageIndex = 0;
+
+               return activeLanguageIndex;
+       }
+
+       private void SetSpellLanguages () {
+               int selectedTextLanguageIndex = GetSelectedLanguageIndex(textTreeView);
+               Base.SpellLanguages.SetActiveLanguageIndex(SubtitleTextType.Text, selectedTextLanguageIndex);
+
+               if (transTreeView.Sensitive) {
+                       int selectedTransLanguageIndex = GetSelectedLanguageIndex(transTreeView);
+                       Base.SpellLanguages.SetActiveLanguageIndex(SubtitleTextType.Translation, 
selectedTransLanguageIndex);
+               }
+       }
+
+       private int GetSelectedLanguageIndex (TreeView treeView) {
+               int count = treeView.Selection.CountSelectedRows();
+               if (count != 1)
+                       return -1;
+
+               TreePath path = GetSelectedPath(treeView);
+               if (path == null)
+                       return -1;
+
+               return Core.Util.PathToInt(path);
+       }
+
+       private TreePath GetSelectedPath (TreeView tree) {
+               TreePath[] paths = tree.Selection.GetSelectedRows();
+               if ((paths == null) || (paths.Length != 1))
+                       return null;
+
+               TreePath selected = paths[0];
+               return selected;
+       }
+
+       /* Event members */
+
+       private void ConnectSignals () {
+               textTreeView.RowActivated += OnLanguageRowActivated;
+               transTreeView.RowActivated += OnLanguageRowActivated;
+       }
+
+       protected override bool ProcessResponse (ResponseType response) {
+               if (response == ResponseType.Ok) {
+                       SetSpellLanguages();
+                       SetReturnValue(true);
+               }
+               return false;
+       }
+
+       private void OnLanguageRowActivated (object o, RowActivatedArgs args) {
+               SetSpellLanguages();
+               SetReturnValue(true);
+               Destroy();
+       }
+
+
+}
+
+}
\ No newline at end of file
diff --git a/src/GnomeSubtitles/Ui/Menus.cs b/src/GnomeSubtitles/Ui/Menus.cs
index fe263f6..9608fd7 100644
--- a/src/GnomeSubtitles/Ui/Menus.cs
+++ b/src/GnomeSubtitles/Ui/Menus.cs
@@ -194,7 +194,7 @@ public class Menus {
                SetVideoDocumentLoadedSensitivity(documentLoaded);
                /* Tools Menu */
                SetToolsAutocheckSpellingSensitivity(documentLoaded);
-               SetSensitivity(WidgetNames.ToolsSetTextLanguage, documentLoaded);
+               SetSensitivity(WidgetNames.ToolsSetLanguages, documentLoaded);
                /* Toolbar */
                SetSensitivity(WidgetNames.SaveButton, documentLoaded);
                SetSensitivity(WidgetNames.InsertSubtitleButton, documentLoaded);
@@ -234,7 +234,6 @@ public class Menus {
                SetSensitivity(WidgetNames.FileTranslationSaveAs, sensitivity);
                SetSensitivity(WidgetNames.FileTranslationClose, sensitivity);
                SetSensitivity(WidgetNames.FileTranslationReload, sensitivity);
-               SetSensitivity(WidgetNames.ToolsSetTranslationLanguage, sensitivity);
 
                bool oneSubtitleSelected = (Core.Base.Ui.View.Selection.Count == 1);
                SetSensitivity(WidgetNames.ToolsTranslateText, sensitivity && oneSubtitleSelected);
diff --git a/src/GnomeSubtitles/Ui/WidgetNames.cs b/src/GnomeSubtitles/Ui/WidgetNames.cs
index 667719a..c3dd1dc 100644
--- a/src/GnomeSubtitles/Ui/WidgetNames.cs
+++ b/src/GnomeSubtitles/Ui/WidgetNames.cs
@@ -91,8 +91,7 @@ public class WidgetNames {
 
        /* Tools Menu */
        public const string ToolsAutocheckSpelling = "toolsAutocheckSpelling";
-       public const string ToolsSetTextLanguage = "toolsSetTextLanguage";
-       public const string ToolsSetTranslationLanguage = "toolsSetTranslationLanguage";
+       public const string ToolsSetLanguages = "toolsSetLanguages";
        public const string ToolsTranslateText = "toolsTranslateText";
        public const string ToolsTranslateTranslation = "toolsTranslateTranslation";
 
diff --git a/src/GnomeSubtitles/Dialog/SetTextLanguageDialog.cs b/src/GnomeSubtitles/Ui/WidgetStyles.cs
similarity index 67%
rename from src/GnomeSubtitles/Dialog/SetTextLanguageDialog.cs
rename to src/GnomeSubtitles/Ui/WidgetStyles.cs
index 0b8723d..31cbdc3 100644
--- a/src/GnomeSubtitles/Dialog/SetTextLanguageDialog.cs
+++ b/src/GnomeSubtitles/Ui/WidgetStyles.cs
@@ -1,6 +1,6 @@
-/*
+/*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2009 Pedro Castro
+ * Copyright (C) 2018 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
@@ -17,14 +17,18 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using SubLib.Core.Domain;
+namespace GnomeSubtitles.Ui {
 
-namespace GnomeSubtitles.Dialog {
+public class WidgetStyles {
 
-public class SetTextLanguageDialog : SetLanguageDialog {
+       /* Dialogs */
+       public const int DialogWidthSmall = 450;
+       public const int DialogWidthMedium = 600;
+       public const int DialogWidthLarge = 750;
 
-       public SetTextLanguageDialog () : base(SubtitleTextType.Text) {
-       }
+       public const int DialogHeightSmall = 250;
+       public const int DialogHeightMedium = 400;
+       public const int DialogHeightLarge = 550;
 
 }
 


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