Commit 6411a90f authored by Kavan Mevada's avatar Kavan Mevada 🦊 Committed by Bilal Elmoussaoui

undo delete recording

fixes #10
parent 2f1e6de5
Pipeline #203256 passed with stages
in 1 minute and 36 seconds
This diff is collapsed.
......@@ -2,7 +2,11 @@
const { GObject, GstPlayer, Gtk, Gst } = imports.gi;
const { Row, RowState } = imports.row;
var RecordingsListBox = new GObject.registerClass(class RecordingsListBox extends Gtk.ListBox {
var RecordingsListBox = new GObject.registerClass({
Signals: {
'row-deleted': { param_types: [GObject.TYPE_OBJECT, GObject.TYPE_INT] },
},
}, class RecordingsListBox extends Gtk.ListBox {
_init(model, player) {
this._player = player;
super._init({
......@@ -76,7 +80,7 @@ var RecordingsListBox = new GObject.registerClass(class RecordingsListBox extend
const index = row.get_index();
this.isolateAt(index, false);
model.remove(index);
this.emit('row-deleted', row._recording, index);
});
return row;
......@@ -99,7 +103,6 @@ var RecordingsListBox = new GObject.registerClass(class RecordingsListBox extend
this.activeRow = row;
}
isolateAt(index, expanded) {
const before = this.get_row_at_index(index - 1);
const current = this.get_row_at_index(index);
......
......@@ -98,6 +98,8 @@ var Row = GObject.registerClass({
this._waveformStack.visible_child_name = 'loading';
});
this._duration.label = formatTime(recording.duration / Gst.SECOND);
recording.connect('notify::duration', () => {
this._duration.label = formatTime(recording.duration / Gst.SECOND);
});
......@@ -119,11 +121,7 @@ var Row = GObject.registerClass({
this._seekBackward.connect('clicked', _ => this.emit('seek-backward'));
this._seekForward.connect('clicked', _ => this.emit('seek-forward'));
this._deleteBtn.connect('clicked', () => {
recording.delete();
this.emit('deleted');
});
this._deleteBtn.connect('clicked', () => this.emit('deleted'));
}
onSaveRecording() {
......
......@@ -18,7 +18,7 @@
*
*/
const { GObject, GstPlayer, Gtk, Handy } = imports.gi;
const { GLib, GObject, GstPlayer, Gtk, Handy } = imports.gi;
const { Recorder } = imports.recorder;
const { RecordingList } = imports.recordingList;
......@@ -29,7 +29,7 @@ const { WaveForm, WaveType } = imports.waveform;
var Window = GObject.registerClass({
Template: 'resource:///org/gnome/SoundRecorder/ui/window.ui',
InternalChildren: ['recorderTime', 'mainStack', 'recorderBox', 'emptyIcon', 'playbackStack', 'headerRevealer', 'column'],
InternalChildren: ['recorderTime', 'mainStack', 'recorderBox', 'emptyIcon', 'playbackStack', 'headerRevealer', 'notificationRevealer', 'notificationMessage', 'notificationUndoBtn', 'notificationCancelBtn', 'column'],
}, class Window extends Handy.ApplicationWindow {
_init(params) {
......@@ -64,6 +64,25 @@ var Window = GObject.registerClass({
this._recordingList.connect('items-changed', this._refreshView.bind(this));
this._recordingListBox = new RecordingsListBox(this._recordingList, this.player);
this._recordingListBox.connect('row-deleted', (_listBox, recording, index) => {
this._recordingList.remove(index);
this.notify(_('"%s" deleted').format(recording.name),
_ => recording.delete(),
_ => this._recordingList.insert(index, recording),
);
});
this._notificationCancelBtn.connect('clicked', _ => {
this._notificationRevealer.reveal_child = false;
if (this.deleteSignalId && this.deleteSignalId > 0) {
GLib.source_remove(this.deleteSignalId);
this.deleteSignalId = 0;
}
this._notificationUndoBtn.disconnect(this.cancelSignalId);
});
this._column.add(this._recordingListBox);
this._emptyIcon.icon_name = `${pkg.name}-symbolic`;
......@@ -120,4 +139,24 @@ var Window = GObject.registerClass({
else
this._mainStack.visible_child_name = 'recordings';
}
notify(message, callback, cancelCallback) {
this._notificationMessage.label = message;
this._notificationRevealer.reveal_child = true;
this.deleteSignalId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 3, () => {
callback();
this._notificationRevealer.reveal_child = false;
this._notificationUndoBtn.disconnect(this.cancelSignalId);
});
this.cancelSignalId = this._notificationUndoBtn.connect('clicked', _ => {
cancelCallback();
this._notificationRevealer.reveal_child = false;
if (this.deleteSignalId && this.deleteSignalId > 0) {
GLib.source_remove(this.deleteSignalId);
this.deleteSignalId = 0;
}
this._notificationUndoBtn.disconnect(this.cancelSignalId);
});
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment