[gnome-sound-recorder] store window state to avoid in-between states



commit 40aa3649597e6a50f3fe675a8cb2e5d1d603c72a
Author: Kavan Mevada <kavanmevada gmail com>
Date:   Fri Aug 14 21:28:47 2020 +0530

    store window state to avoid in-between states
    
    fixes #80

 data/ui/window.ui | 124 ++++++++++++++++++++++++++----------------------------
 src/window.js     |  70 +++++++++++++++++++++---------
 2 files changed, 110 insertions(+), 84 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index b856aa2..23f283a 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -112,6 +112,66 @@
                 <property name="can_focus">False</property>
                 <property name="hexpand">True</property>
                 <property name="vexpand">True</property>
+                <child>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">center</property>
+                    <property name="valign">center</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <object class="GtkImage" id="emptyIcon">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">center</property>
+                        <property name="valign">center</property>
+                        <property name="pixel_size">96</property>
+                        <style>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="margin_top">8</property>
+                        <property name="label" translatable="yes">Add Recordings</property>
+                        <style>
+                          <class name="dim-label"/>
+                          <class name="title-1"/>
+                        </style>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="margin_top">4</property>
+                        <property name="label" translatable="yes">Use the &lt;b&gt;Record&lt;/b&gt; button 
to make sound recordings</property>
+                        <property name="use_markup">True</property>
+                        <property name="justify">center</property>
+                        <property name="wrap">True</property>
+                        <property name="max_width_chars">50</property>
+                        <style>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="name">empty</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
                 <child>
                   <object class="GtkScrolledWindow" id="scrolledWindow">
                     <property name="visible">True</property>
@@ -303,70 +363,6 @@
                   </object>
                   <packing>
                     <property name="name">recorder</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="halign">center</property>
-                    <property name="valign">center</property>
-                    <property name="orientation">vertical</property>
-                    <child>
-                      <object class="GtkImage" id="emptyIcon">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="halign">center</property>
-                        <property name="valign">center</property>
-                        <property name="pixel_size">96</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="margin_top">8</property>
-                        <property name="label" translatable="yes">Add Recordings</property>
-                        <style>
-                          <class name="dim-label"/>
-                          <class name="title-1"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="margin_top">4</property>
-                        <property name="label" translatable="yes">Use the &lt;b&gt;Record&lt;/b&gt; button 
to make sound recordings</property>
-                        <property name="use_markup">True</property>
-                        <property name="justify">center</property>
-                        <property name="wrap">True</property>
-                        <property name="max_width_chars">50</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="name">empty</property>
-                    <property name="position">2</property>
                   </packing>
                 </child>
               </object>
diff --git a/src/window.js b/src/window.js
index f04105e..9707aba 100644
--- a/src/window.js
+++ b/src/window.js
@@ -26,6 +26,11 @@ const { RecordingsListBox } = imports.recordingsListBox;
 const { formatTime } = imports.utils;
 const { WaveForm, WaveType } = imports.waveform;
 
+var WindowState = {
+    EMPTY: 0,
+    LIST: 1,
+    RECORDER: 2,
+};
 
 var Window = GObject.registerClass({
     Template: 'resource:///org/gnome/SoundRecorder/ui/window.ui',
@@ -60,8 +65,14 @@ var Window = GObject.registerClass({
         });
 
         this._recordingList = new RecordingList();
-        this._refreshView();
-        this._recordingList.connect('items-changed', this._refreshView.bind(this));
+        this._recordingList.connect('items-changed', _ => {
+            if (this.state !== WindowState.RECORDER) {
+                if (this._recordingList.get_n_items() === 0)
+                    this.state = WindowState.EMPTY;
+                else
+                    this.state = WindowState.LIST;
+            }
+        });
 
         this._recordingListBox = new RecordingsListBox(this._recordingList, this.player);
 
@@ -106,38 +117,29 @@ var Window = GObject.registerClass({
         if (activeRow && activeRow.editMode)
             activeRow.editMode = false;
 
-        this._headerRevealer.reveal_child = false;
-        this._mainStack.visible_child_name = 'recorder';
         this._playbackStack.visible_child_name = 'recorder-pause';
-
+        this.state = WindowState.RECORDER;
         this.recorder.start();
     }
 
     onRecorderCancel() {
         const recording = this.recorder.stop();
         recording.delete();
-        this._setMainView();
+
+        if (this._recordingList.get_n_items() === 0)
+            this.state = WindowState.EMPTY;
+        else
+            this.state = WindowState.LIST;
+
+        this.waveform.destroy();
     }
 
     onRecorderStop() {
         const recording = this.recorder.stop();
         this._recordingList.insert(0, recording);
         this._recordingListBox.get_row_at_index(0).editMode = true;
-        this._setMainView();
-    }
-
-    _setMainView() {
+        this.state = WindowState.LIST;
         this.waveform.destroy();
-        this._playbackStack.visible_child_name = 'recorder-start';
-        this._mainStack.visible_child_name = 'recordings';
-        this._headerRevealer.reveal_child = true;
-    }
-
-    _refreshView() {
-        if (this._recordingList.get_n_items() === 0)
-            this._mainStack.visible_child_name = 'empty';
-        else
-            this._mainStack.visible_child_name = 'recordings';
     }
 
     notify(message, callback, cancelCallback) {
@@ -159,4 +161,32 @@ var Window = GObject.registerClass({
             this._notificationUndoBtn.disconnect(this.cancelSignalId);
         });
     }
+
+    set state(state) {
+        let visibleChild;
+        let isHeaderVisible;
+
+        switch (state) {
+        case WindowState.RECORDER:
+            visibleChild = 'recorder';
+            isHeaderVisible = false;
+            break;
+        case WindowState.LIST:
+            visibleChild = 'recordings';
+            isHeaderVisible = true;
+            break;
+        case WindowState.EMPTY:
+            visibleChild = 'empty';
+            isHeaderVisible = true;
+            break;
+        }
+
+        this._mainStack.visible_child_name = visibleChild;
+        this._headerRevealer.reveal_child = isHeaderVisible;
+        this._state = state;
+    }
+
+    get state() {
+        return this._state;
+    }
 });


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