[simple-scan] Replace scan menu with a popdown



commit 442d0d96a5dd34f3b484077adb5ffe1191550f46
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Aug 31 13:58:57 2018 +1200

    Replace scan menu with a popdown
    
    Design done by Allan Day.

 src/app-window.ui                | 247 ++++++++++++++++++++++++++++-----------
 src/app-window.vala              |  92 ++++++++++-----
 src/scan-type-adf-symbolic.svg   |   9 ++
 src/scan-type-batch-symbolic.svg |   9 ++
 src/simple-scan.gresource.xml    |   4 +
 5 files changed, 266 insertions(+), 95 deletions(-)
---
diff --git a/src/app-window.ui b/src/app-window.ui
index 8a442c9..1f986e9 100644
--- a/src/app-window.ui
+++ b/src/app-window.ui
@@ -197,65 +197,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkMenu" id="scan_button_hb_menu">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <child>
-      <object class="GtkMenuItem" id="scan_single_button_hb_menuitem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes" comments="Toolbar scan menu item to scan a single page 
from the scanner">Single _Page</property>
-        <property name="use_underline">True</property>
-        <signal name="activate" handler="scan_button_clicked_cb" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkMenuItem" id="scan_all_button_hb_menuitem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes" comments="Toolbar scan menu item to scan all pages from a 
document feeder">All Pages From _Feeder</property>
-        <property name="use_underline">True</property>
-        <signal name="activate" handler="continuous_scan_button_clicked_cb" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkMenuItem" id="batch_button_hb_menuitem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes" comments="Toolbar scan menu item to scan continuously from 
the flatbed">_Multiple Pages From Flatbed</property>
-        <property name="use_underline">True</property>
-        <signal name="activate" handler="batch_button_clicked_cb" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkSeparatorMenuItem" id="menuitem3">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-      </object>
-    </child>
-    <child>
-      <object class="GtkRadioMenuItem" id="text_button_hb_menuitem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Text</property>
-        <property name="use_underline">True</property>
-        <property name="draw_as_radio">True</property>
-        <signal name="toggled" handler="text_menuitem_toggled_cb" swapped="no"/>
-      </object>
-    </child>
-    <child>
-      <object class="GtkRadioMenuItem" id="photo_button_hb_menuitem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">Photo</property>
-        <property name="use_underline">True</property>
-        <property name="active">True</property>
-        <property name="draw_as_radio">True</property>
-        <property name="group">text_button_hb_menuitem</property>
-        <signal name="toggled" handler="photo_menuitem_toggled_cb" swapped="no"/>
-      </object>
-    </child>
-  </object>
   <template class="AppWindow" parent="GtkApplicationWindow">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes" comments="Title of scan window">Simple Scan</property>
@@ -424,17 +365,29 @@
               </packing>
             </child>
             <child>
-              <object class="GtkMenuButton" id="open_button">
+              <object class="GtkMenuButton">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="receives_default">False</property>
-                <property name="popup">scan_button_hb_menu</property>
+                <property name="popover">scan_options_popover</property>
                 <child>
-                  <placeholder/>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkImage" id="scan_options_image">
+                        <property name="visible">True</property>
+                        <property name="icon_name">scanner-symbolic</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">True</property>
+                        <property name="icon_name">pan-down-symbolic</property>
+                      </object>
+                    </child>
+                  </object>
                 </child>
-                <style>
-                  <class name="text-button"/>
-                </style>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -502,4 +455,168 @@
       </object>
     </child>
   </template>
+  <object class="GtkPopover" id="scan_options_popover">
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="margin">12</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkRadioButton" id="scan_single_radio">
+            <property name="visible">True</property>
+            <property name="draw_indicator">False</property>
+            <signal name="toggled" handler="scan_single_radio_toggled_cb" swapped="no"/>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="spacing">12</property>
+                <property name="margin_start">12</property>
+                <property name="margin_end">12</property>
+                <property name="margin_top">6</property>
+                <property name="margin_bottom">6</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon_name">scanner-symbolic</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">_Single Page</property>
+                    <property name="use_underline">True</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkRadioButton" id="scan_adf_radio">
+            <property name="visible">True</property>
+            <property name="draw_indicator">False</property>
+            <property name="group">scan_single_radio</property>
+            <signal name="toggled" handler="scan_adf_radio_toggled_cb" swapped="no"/>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="spacing">12</property>
+                <property name="margin_start">12</property>
+                <property name="margin_end">12</property>
+                <property name="margin_top">6</property>
+                <property name="margin_bottom">6</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon_name">scan-type-adf-symbolic</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">All Pages From _Feeder</property>
+                    <property name="use_underline">True</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkRadioButton" id="scan_batch_radio">
+            <property name="visible">True</property>
+            <property name="draw_indicator">False</property>
+            <property name="group">scan_single_radio</property>
+            <signal name="toggled" handler="scan_batch_radio_toggled_cb" swapped="no"/>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="spacing">12</property>
+                <property name="margin_start">12</property>
+                <property name="margin_end">12</property>
+                <property name="margin_top">6</property>
+                <property name="margin_bottom">6</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon_name">scan-type-batch-symbolic</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">_Multiple Pages From Flatbed</property>
+                    <property name="use_underline">True</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkRadioButton" id="text_radio">
+            <property name="visible">True</property>
+            <property name="draw_indicator">False</property>
+            <property name="margin_top">12</property>
+            <signal name="toggled" handler="text_radio_toggled_cb" swapped="no"/>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="spacing">12</property>
+                <property name="margin_start">12</property>
+                <property name="margin_end">12</property>
+                <property name="margin_top">6</property>
+                <property name="margin_bottom">6</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon_name">text-x-generic-symbolic</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">_Text</property>
+                    <property name="use_underline">True</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkRadioButton" id="photo_radio">
+            <property name="visible">True</property>
+            <property name="draw_indicator">False</property>
+            <property name="group">text_radio</property>
+            <signal name="toggled" handler="photo_radio_toggled_cb" swapped="no"/>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="spacing">12</property>
+                <property name="margin_start">12</property>
+                <property name="margin_end">12</property>
+                <property name="margin_top">6</property>
+                <property name="margin_bottom">6</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon_name">image-x-generic-symbolic</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">_Image</property>
+                    <property name="use_underline">True</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/src/app-window.vala b/src/app-window.vala
index 1ffa50f..c088a3d 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -30,6 +30,7 @@ public class AppWindow : Gtk.ApplicationWindow
     };
 
     private Settings settings;
+    private ScanType scan_type = ScanType.SINGLE;
 
     private PreferencesDialog preferences_dialog;
 
@@ -85,9 +86,17 @@ public class AppWindow : Gtk.ApplicationWindow
     private Gtk.Button delete_button;
 
     [GtkChild]
-    private Gtk.RadioMenuItem text_button_hb_menuitem;
+    private Gtk.Image scan_options_image;
     [GtkChild]
-    private Gtk.RadioMenuItem photo_button_hb_menuitem;
+    private Gtk.RadioButton scan_single_radio;
+    [GtkChild]
+    private Gtk.RadioButton scan_adf_radio;
+    [GtkChild]
+    private Gtk.RadioButton scan_batch_radio;
+    [GtkChild]
+    private Gtk.RadioButton text_radio;
+    [GtkChild]
+    private Gtk.RadioButton photo_radio;
 
     [GtkChild]
     private Gtk.MenuButton menu_button;
@@ -601,17 +610,59 @@ public class AppWindow : Gtk.ApplicationWindow
         new_document();
     }
 
+    private void set_scan_type (ScanType scan_type)
+    {
+        this.scan_type = scan_type;
+
+        switch (scan_type)
+        {
+        case ScanType.SINGLE:
+            scan_single_radio.active = true;
+            scan_options_image.icon_name = "scanner-symbolic";
+            break;
+        case ScanType.ADF_BOTH:
+            scan_adf_radio.active = true;
+            scan_options_image.icon_name = "scan-type-adf-symbolic";
+            break;
+        case ScanType.BATCH:
+            scan_batch_radio.active = true;
+            scan_options_image.icon_name = "scan-type-batch-symbolic";
+            break;
+        }
+    }
+
+    [GtkCallback]
+    private void scan_single_radio_toggled_cb (Gtk.ToggleButton button)
+    {
+        if (button.active)
+            set_scan_type (ScanType.SINGLE);
+    }
+
+    [GtkCallback]
+    private void scan_adf_radio_toggled_cb (Gtk.ToggleButton button)
+    {
+        if (button.active)
+            set_scan_type (ScanType.ADF_BOTH);
+    }
+
+    [GtkCallback]
+    private void scan_batch_radio_toggled_cb (Gtk.ToggleButton button)
+    {
+        if (button.active)
+            set_scan_type (ScanType.BATCH);
+    }
+
     private void set_document_hint (string document_hint, bool save = false)
     {
         this.document_hint = document_hint;
 
         if (document_hint == "text")
         {
-            text_button_hb_menuitem.active = true;
+            text_radio.active = true;
         }
         else if (document_hint == "photo")
         {
-            photo_button_hb_menuitem.active = true;
+            photo_radio.active = true;
         }
 
         if (save)
@@ -619,16 +670,16 @@ public class AppWindow : Gtk.ApplicationWindow
     }
 
     [GtkCallback]
-    private void text_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+    private void text_radio_toggled_cb (Gtk.ToggleButton button)
     {
-        if (widget.active)
+        if (button.active)
             set_document_hint ("text", true);
     }
 
     [GtkCallback]
-    private void photo_menuitem_toggled_cb (Gtk.CheckMenuItem widget)
+    private void photo_radio_toggled_cb (Gtk.ToggleButton button)
     {
-        if (widget.active)
+        if (button.active)
             set_document_hint ("photo", true);
     }
 
@@ -659,7 +710,9 @@ public class AppWindow : Gtk.ApplicationWindow
     private void scan_button_clicked_cb (Gtk.Widget widget)
     {
         var options = make_scan_options ();
-        options.type = ScanType.SINGLE;
+        options.type = scan_type;
+        if (options.type == ScanType.ADF_BOTH)
+            options.type = preferences_dialog.get_page_side ();
         status_primary_label.set_text (/* Label shown when scan started */
                                        _("Contacting scanner…"));
         start_scan (selected_device, options);
@@ -671,27 +724,6 @@ public class AppWindow : Gtk.ApplicationWindow
         stop_scan ();
     }
 
-    [GtkCallback]
-    private void continuous_scan_button_clicked_cb (Gtk.Widget widget)
-    {
-        if (scanning)
-            stop_scan ();
-        else
-        {
-            var options = make_scan_options ();
-            options.type = preferences_dialog.get_page_side ();
-            start_scan (selected_device, options);
-        }
-    }
-
-    [GtkCallback]
-    private void batch_button_clicked_cb (Gtk.Widget widget)
-    {
-        var options = make_scan_options ();
-        options.type = ScanType.BATCH;
-        start_scan (selected_device, options);
-    }
-
     private void preferences_cb ()
     {
         preferences_dialog.present ();
diff --git a/src/scan-type-adf-symbolic.svg b/src/scan-type-adf-symbolic.svg
new file mode 100644
index 0000000..4ddb4de
--- /dev/null
+++ b/src/scan-type-adf-symbolic.svg
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="16" height="16" version="1.1" viewBox="0 0 4.2333 4.2333" xmlns="http://www.w3.org/2000/svg";>
+ <g fill="#474747">
+  <path d="m0.52917 3.9688c-0.13229 0-0.26458-0.13229-0.26458-0.26459v-2.1167c0-0.13229 0.13229-0.26459 
0.26458-0.26459h0.26458v1.5875h2.6458v-1.5875h0.26458c0.13229 0 0.26458 0.1323 0.26458 0.26459v2.1167c0 
0.1323-0.13229 0.26459-0.26458 0.26459z"/>
+  <path d="m1.0583 2.6458v-1.5875h2.1167v1.5875z"/>
+  <path d="m1.0583 0.79376v-0.26459h2.1167v0.26459z"/>
+  <path d="m1.0583 0.26459v-0.26458h2.1167v0.26458z"/>
+ </g>
+</svg>
diff --git a/src/scan-type-batch-symbolic.svg b/src/scan-type-batch-symbolic.svg
new file mode 100644
index 0000000..a11715d
--- /dev/null
+++ b/src/scan-type-batch-symbolic.svg
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="16" height="16" version="1.1" viewBox="0 0 4.2333 4.2333" xmlns="http://www.w3.org/2000/svg";>
+ <g fill="#474747">
+  <path d="m2.2521 0.79056c-0.94667 0-1.7198 0.7731-1.7198 1.7198s0.7731 1.7198 1.7198 1.7198 1.7198-0.7731 
1.7198-1.7198-0.7731-1.7198-1.7198-1.7198zm0 0.52916c0.66068 0 1.1906 0.52993 1.1906 1.1906s-0.52993 
1.1906-1.1906 1.1906-1.1906-0.52993-1.1906-1.1906 0.52993-1.1906 1.1906-1.1906z" color="#000000" 
color-rendering="auto" dominant-baseline="auto" enable-background="new" image-rendering="auto" 
shape-rendering="auto" solid-color="#000000" stroke-width=".26458" 
style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/>
+  <path d="m1.8552-0.00318h0.79374c0.14658 0 0.26458 0.118 0.26458 0.26458s-0.118 0.26458-0.26458 
0.26458h-0.79374c-0.14658 0-0.26458-0.118-0.26458-0.26458s0.118-0.26458 0.26458-0.26458z" color="#000000" 
color-rendering="auto" image-rendering="auto" shape-rendering="auto" solid-color="#000000" 
stroke-width=".26458" style="isolation:auto;mix-blend-mode:normal"/>
+  <path d="m2.3844-0.00318v1.0583h-0.26458v-1.0583z" color="#000000" color-rendering="auto" 
image-rendering="auto" shape-rendering="auto" solid-color="#000000" stroke-width=".26458" 
style="isolation:auto;mix-blend-mode:normal"/>
+  <path d="m2.1198 1.5843a1.0583 1.0583 0 0 1 1.0583 1.0583h-1.0583z" color="#000000" 
enable-background="new" stroke-width="0"/>
+ </g>
+</svg>
diff --git a/src/simple-scan.gresource.xml b/src/simple-scan.gresource.xml
index a62619e..2348f75 100644
--- a/src/simple-scan.gresource.xml
+++ b/src/simple-scan.gresource.xml
@@ -5,6 +5,10 @@
     <file preprocess="xml-stripblanks">preferences-dialog.ui</file>
     <file preprocess="xml-stripblanks">authorize-dialog.ui</file>
   </gresource>
+  <gresource prefix="/org/gnome/SimpleScan/icons/scalable/actions">
+    <file>scan-type-adf-symbolic.svg</file>
+    <file>scan-type-batch-symbolic.svg</file>
+  </gresource>
   <gresource prefix="/org/gnome/SimpleScan/gtk">
     <file preprocess="xml-stripblanks">help-overlay.ui</file>
   </gresource>


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