[gnome-music] Support Undo when removing playlists.
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] Support Undo when removing playlists.
- Date: Mon, 19 Jan 2015 11:22:41 +0000 (UTC)
commit 0fe6116586c673f7c94e5b80493ba7a669eb613c
Author: Sagar Ghuge <ghugesss gmail com>
Date: Thu Jan 8 19:18:30 2015 +0530
Support Undo when removing playlists.
https://bugzilla.gnome.org/show_bug.cgi?id=742451
configure.ac | 2 +-
gnomemusic/view.py | 17 +++++++++++++++--
gnomemusic/window.py | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c7c04cb..122007a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,7 +25,7 @@ AC_PROG_CC
AM_PROG_CC_C_O
LT_INIT([disable-static])
-LIBGD_INIT([main-view revealer gir tagged-entry])
+LIBGD_INIT([main-view revealer gir tagged-entry notification])
PKG_PROG_PKG_CONFIG([0.22])
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index d08be62..9a7b87b 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -785,6 +785,7 @@ class Playlist(ViewContainer):
GObject.TYPE_BOOLEAN,
GObject.TYPE_BOOLEAN
)
+
self.playlists_sidebar.set_view_type(Gd.MainViewType.LIST)
self.playlists_sidebar.set_model(self.playlists_model)
self.playlists_sidebar.set_hexpand(False)
@@ -807,7 +808,10 @@ class Playlist(ViewContainer):
self.iter_to_clean = None
self.iter_to_clean_model = None
self.current_playlist = None
+ self.pl_todelete = None
+ self.really_delete = True
self.songs_count = 0
+ self.window = window
self._update_songs_count()
self.player = player
self.player.connect('playlist-item-changed', self.update_model)
@@ -1114,7 +1118,7 @@ class Playlist(ViewContainer):
self._model.get_path(_iter))
@log
- def _on_delete_activate(self, menuitem, data=None):
+ def delete_selected_playlist(self):
self._model.clear()
_iter = self.playlists_sidebar.get_generic_view().get_selection().get_selected()[1]
if not _iter:
@@ -1129,10 +1133,19 @@ class Playlist(ViewContainer):
self.playlists_model.get_path(iter_next))
playlist = self.playlists_model.get_value(_iter, 5)
- playlists.delete_playlist(playlist)
+ self.pl_todelete = playlist
self.playlists_model.remove(_iter)
@log
+ def undo_playlist(self):
+ self._add_playlist_item_to_model(self.pl_todelete)
+
+ @log
+ def _on_delete_activate(self, menuitem, data=None):
+ self.window._init_notification()
+ self.delete_selected_playlist()
+
+ @log
def _on_playlist_created(self, playlists, item):
self._add_playlist_item_to_model(item)
if self.playlists_model.iter_n_children(None) == 1:
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 44146bd..b84f037 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -31,6 +31,7 @@
from gi.repository import Gtk, Gdk, Gio, GLib, Tracker
+from gi.repository import Gd
from gettext import gettext as _, ngettext
from gnomemusic.toolbar import Toolbar, ToolbarState
@@ -308,6 +309,38 @@ class Window(Gtk.ApplicationWindow):
self._stack.get_visible_child().queue_draw()
@log
+ def _init_notification(self):
+ self.notification = Gd.Notification()
+ self.notification.set_timeout(20)
+
+ grid = Gtk.Grid()
+ grid.set_column_spacing(8)
+ self.notification.add(grid)
+
+ undo_button = Gtk.Button.new_with_mnemonic(_("_Undo"))
+ label = _("Playlist %s removed" %(
+ self.views[3].current_playlist.get_title()))
+ grid.add(Gtk.Label.new(label))
+ grid.add(undo_button)
+
+ self.notification.show_all()
+ self._overlay.add_overlay(self.notification)
+
+ self.notification.connect("dismissed", self._notification_dismissed)
+ undo_button.connect("clicked", self._undo_deletion)
+
+ @log
+ def _notification_dismissed(self, widget):
+ if self.views[3].really_delete:
+ Views.playlists.delete_playlist(self.views[3].pl_todelete)
+
+ @log
+ def _undo_deletion(self, widget):
+ self.views[3].really_delete = False
+ self.notification.dismiss()
+ self.views[3].undo_playlist()
+
+ @log
def _on_key_press(self, widget, event):
modifiers = Gtk.accelerator_get_default_mod_mask()
event_and_modifiers = (event.state & modifiers)
@@ -324,6 +357,10 @@ class Window(Gtk.ApplicationWindow):
self.curr_view.set_visible_child(self.curr_view._grid)
self.toolbar.set_state(ToolbarState.MAIN)
else:
+ if (event.keyval == Gdk.KEY_Delete):
+ if self._stack.get_visible_child() == self.views[3]:
+ self._init_notification()
+ self.views[3].delete_selected_playlist()
# Close search bar after Esc is pressed
if event.keyval == Gdk.KEY_Escape:
self.toolbar.searchbar.show_bar(False)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]