[gnome-sound-recorder/bilelmoussaoui/fixes: 11/12] row: port to actions




commit 5839d79a78ff0f9357d7b80834652e3c079ff3f9
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Wed Sep 9 05:46:26 2020 +0200

    row: port to actions

 data/ui/row.ui |  17 ++++++----
 src/row.js     | 101 +++++++++++++++++++++++++++++++++++----------------------
 2 files changed, 74 insertions(+), 44 deletions(-)
---
diff --git a/data/ui/row.ui b/data/ui/row.ui
index 90627d9..0cf0415 100644
--- a/data/ui/row.ui
+++ b/data/ui/row.ui
@@ -235,7 +235,7 @@
                             <property name="halign">end</property>
                             <property name="receives_default">False</property>
                             <property name="tooltip_text" translatable="yes">Save</property>
-                            <signal name="clicked" handler="onSaveRecording" swapped="no"/>
+                            <property name="action_name">recording.save</property>
                             <child>
                               <object class="GtkImage">
                                 <property name="visible">True</property>
@@ -264,11 +264,12 @@
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <child>
-                          <object class="GtkButton" id="deleteBtn">
+                          <object class="GtkButton">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="valign">center</property>
                             <property name="halign">center</property>
+                            <property name="action_name">recording.delete</property>
                             <property name="receives_default">True</property>
                             <property name="tooltip_text" translatable="yes">Delete</property>
                             <child>
@@ -298,11 +299,12 @@
                         <property name="halign">center</property>
                         <property name="spacing">18</property>
                         <child>
-                          <object class="GtkButton" id="seekBackward">
+                          <object class="GtkButton">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="valign">center</property>
                             <property name="halign">center</property>
+                            <property name="action_name">recording.seek-backward</property>
                             <property name="receives_default">True</property>
                             <property name="tooltip_text" translatable="yes">Seek 10s Backward</property>
                             <child>
@@ -325,12 +327,13 @@
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <child>
-                              <object class="GtkButton" id="playButton">
+                              <object class="GtkButton">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="valign">center</property>
                                 <property name="halign">center</property>
                                 <property name="receives_default">True</property>
+                                <property name="action_name">recording.play</property>
                                 <property name="tooltip_text" translatable="yes">Play</property>
                                 <child>
                                   <object class="GtkImage">
@@ -350,11 +353,12 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkButton" id="pauseButton">
+                              <object class="GtkButton">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="valign">center</property>
                                 <property name="halign">center</property>
+                                <property name="action_name">recording.pause</property>
                                 <property name="receives_default">True</property>
                                 <property name="tooltip_text" translatable="yes">Pause</property>
                                 <child>
@@ -381,11 +385,12 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="seekForward">
+                          <object class="GtkButton">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="valign">center</property>
                             <property name="halign">center</property>
+                            <property name="action_name">recording.seek-forward</property>
                             <property name="receives_default">True</property>
                             <property name="tooltip_text" translatable="yes">Seek 10s Forward</property>
                             <child>
diff --git a/src/row.js b/src/row.js
index 56e4c1a..c5040c2 100644
--- a/src/row.js
+++ b/src/row.js
@@ -11,9 +11,9 @@ var RowState = {
 var Row = GObject.registerClass({
     Template: 'resource:///org/gnome/SoundRecorder/ui/row.ui',
     InternalChildren: [
-        'playbackStack', 'mainStack', 'playButton', 'waveformStack', 'pauseButton',
-        'name', 'entry', 'date', 'duration', 'revealer', 'playbackControls', 'rightStack',
-        'saveBtn', 'seekBackward', 'seekForward',  'deleteBtn',
+        'playbackStack', 'mainStack', 'waveformStack', 'rightStack',
+        'name', 'entry', 'date', 'duration', 'revealer', 'playbackControls',
+        'saveBtn',
     ],
     Signals: {
         'play': { param_types: [GObject.TYPE_STRING] },
@@ -33,6 +33,8 @@ var Row = GObject.registerClass({
     _init(recording) {
         this._recording = recording;
         this._expanded = false;
+        this._editMode = false;
+
         super._init({});
 
         this.waveform = new WaveForm({
@@ -44,6 +46,7 @@ var Row = GObject.registerClass({
             margin_end: 12,
         }, WaveType.PLAYER);
         this._waveformStack.add_named(this.waveform, 'wave');
+
         if (this._recording._peaks.length > 0) {
             this.waveform.peaks = this._recording.peaks;
             this._waveformStack.visible_child_name = 'wave';
@@ -51,17 +54,18 @@ var Row = GObject.registerClass({
             this._recording.loadPeaks();
         }
 
+        if (recording.timeCreated > 0)
+            this._date.label = displayDateTime(recording.timeCreated);
+        else
+            this._date.label = displayDateTime(recording.timeModified);
+
         recording.bind_property('name', this._name, 'label', GObject.BindingFlags.SYNC_CREATE | 
GObject.BindingFlags.DEFAULT);
         recording.bind_property('name', this._entry, 'text', GObject.BindingFlags.SYNC_CREATE | 
GObject.BindingFlags.DEFAULT);
         this.bind_property('expanded', this._revealer, 'reveal_child', GObject.BindingFlags.SYNC_CREATE | 
GObject.BindingFlags.DEFAULT);
 
-        this._editMode = false;
-
-        let actionGroup = new Gio.SimpleActionGroup();
+        this.actionGroup = new Gio.SimpleActionGroup();
 
-        let renameAction = new Gio.SimpleAction({ name: 'rename' });
         let exportAction = new Gio.SimpleAction({ name: 'export' });
-
         exportAction.connect('activate', () => {
             const window = Gio.Application.get_default().get_active_window();
             const dialog = Gtk.FileChooserNative.new(_('Export Recording'), window, 
Gtk.FileChooserAction.SAVE, _('_Export'), _('_Cancel'));
@@ -75,15 +79,58 @@ var Row = GObject.registerClass({
             });
             dialog.show();
         });
+        this.actionGroup.add_action(exportAction);
+
+        let saveRenameAction = new Gio.SimpleAction({ name: 'save', enabled: false });
+        saveRenameAction.connect('activate', this.onRenameRecording.bind(this));
+        this.actionGroup.add_action(saveRenameAction);
 
-        renameAction.connect('activate', () => {
+        this.renameAction = new Gio.SimpleAction({ name: 'rename', enabled: true });
+        this.renameAction.connect('activate', action => {
             this.editMode = true;
+            action.enabled = false;
+        });
+        this.renameAction.bind_property('enabled', saveRenameAction, 'enabled', 
GObject.BindingFlags.INVERT_BOOLEAN);
+        this.actionGroup.add_action(this.renameAction);
+
+        let pauseAction = new Gio.SimpleAction({ name: 'pause', enabled: false });
+        pauseAction.connect('activate', () => {
+            this.emit('pause');
+            this.state = RowState.PAUSED;
+        });
+        this.actionGroup.add_action(pauseAction);
+
+        let playAction = new Gio.SimpleAction({ name: 'play', enabled: true });
+        playAction.connect('activate', () => {
+            this.emit('play', this._recording.uri);
+            this.state = RowState.PLAYING;
+        });
+        playAction.bind_property('enabled', pauseAction, 'enabled', GObject.BindingFlags.INVERT_BOOLEAN);
+        this.actionGroup.add_action(playAction);
+
+        let deleteAction = new Gio.SimpleAction({ name: 'delete' });
+        deleteAction.connect('activate', () => {
+            this.emit('deleted');
+        });
+        this.actionGroup.add_action(deleteAction);
+
+        let seekBackAction = new Gio.SimpleAction({ name: 'seek-backward' });
+        seekBackAction.connect('activate', () => {
+            this.emit('seek-backward');
         });
+        this.actionGroup.add_action(seekBackAction);
 
-        actionGroup.add_action(renameAction);
-        actionGroup.add_action(exportAction);
-        this.insert_action_group('recording', actionGroup);
+        let seekForwardAction = new Gio.SimpleAction({ name: 'seek-forward' });
+        seekForwardAction.connect('activate', () => {
+            this.emit('seek-forward');
+        });
+        this.actionGroup.add_action(seekForwardAction);
+
+        this.insert_action_group('recording', this.actionGroup);
 
+        this.waveform.connect('button-press-event', _ => {
+            pauseAction.activate();
+        });
 
         this._entry.connect('key-press-event', (_, event) => {
             const key = event.get_keyval()[1];
@@ -93,12 +140,6 @@ var Row = GObject.registerClass({
                 this.editMode = false;
         });
 
-        if (recording.timeCreated > 0)
-            this._date.label = displayDateTime(recording.timeCreated);
-        else
-            this._date.label = displayDateTime(recording.timeModified);
-
-
         this._recording.connect('peaks-updated', _recording => {
             this._waveformStack.visible_child_name = 'wave';
             this.waveform.peaks = _recording.peaks;
@@ -117,33 +158,15 @@ var Row = GObject.registerClass({
         recording.connect('notify::duration', () => {
             this._duration.label = formatTime(recording.duration / Gst.SECOND);
         });
-
-        this.waveform.connect('button-press-event', _ => {
-            this.emit('pause');
-            this.state = RowState.PAUSED;
-        });
-
-        this._playButton.connect('clicked', () => {
-            this.emit('play', recording.uri);
-            this.state = RowState.PLAYING;
-        });
-
-        this._pauseButton.connect('clicked', () => {
-            this.emit('pause');
-            this.state = RowState.PAUSED;
-        });
-
-        this._seekBackward.connect('clicked', _ => this.emit('seek-backward'));
-        this._seekForward.connect('clicked', _ => this.emit('seek-forward'));
-        this._deleteBtn.connect('clicked', () => this.emit('deleted'));
     }
 
-    onSaveRecording() {
+    onRenameRecording() {
         try {
             if (this._name.label !== this._entry.text)
                 this._recording.name = this._entry.text;
 
             this.editMode = false;
+            this.renameAction.enabled = true;
             this._entry.get_style_context().remove_class('error');
         } catch (e) {
             this._entry.get_style_context().add_class('error');
@@ -184,9 +207,11 @@ var Row = GObject.registerClass({
 
         switch (rowState) {
         case RowState.PLAYING:
+            this.actionGroup.lookup('play').set_enabled(false);
             this._playbackStack.visible_child_name = 'pause';
             break;
         case RowState.PAUSED:
+            this.actionGroup.lookup('play').set_enabled(true);
             this._playbackStack.visible_child_name = 'play';
             break;
         }


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