Commit beb778c0 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Allow moving albums

parent 37378830
Pipeline #48018 failed with stage
in 9 minutes and 45 seconds
......@@ -338,10 +338,16 @@ popover.background separator {
}
.albumrow:selected {
border-radius: 0px;
background-color: @theme_selected_bg_color;
color: @theme_selected_fg_color;
}
.albumrow:visited {
color: @theme_fg_color;
background-color: alpha(@theme_selected_bg_color, 0.1);
}
.albumrow:selected label {
.albumrow:visited label {
color: @theme_fg_color;
}
......
......@@ -10,7 +10,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk, GLib, GObject, Pango
from gi.repository import Gtk, Gdk, GLib, GObject, Pango
from gettext import gettext as _
......@@ -35,7 +35,8 @@ class AlbumRow(Gtk.ListBoxRow, TracksView, DNDRow):
"insert-album-after": (GObject.SignalFlags.RUN_FIRST, None,
(GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT)),
"remove-album": (GObject.SignalFlags.RUN_FIRST, None, ()),
"populated": (GObject.SignalFlags.RUN_FIRST, None, ())
"populated": (GObject.SignalFlags.RUN_FIRST, None, ()),
"do-selection": (GObject.SignalFlags.RUN_FIRST, None, ())
}
__MARGIN = 4
......@@ -203,7 +204,7 @@ class AlbumRow(Gtk.ListBoxRow, TracksView, DNDRow):
self.__revealer.set_reveal_child(False)
self.get_style_context().add_class("albumrow-hover")
if self.album.id == App().player.current_track.album.id:
self.set_state_flags(Gtk.StateFlags.SELECTED, True)
self.set_state_flags(Gtk.StateFlags.VISITED, True)
else:
if self._responsive_widget is None:
TracksView.populate(self)
......@@ -225,7 +226,7 @@ class AlbumRow(Gtk.ListBoxRow, TracksView, DNDRow):
TracksView.set_playing_indicator(self)
self.set_state_flags(Gtk.StateFlags.NORMAL, True)
elif selected:
self.set_state_flags(Gtk.StateFlags.SELECTED, True)
self.set_state_flags(Gtk.StateFlags.VISITED, True)
else:
self.set_state_flags(Gtk.StateFlags.NORMAL, True)
......@@ -327,7 +328,17 @@ class AlbumRow(Gtk.ListBoxRow, TracksView, DNDRow):
@param widget as Gtk.Widget
@param event as Gdk.Event
"""
self.reveal()
if event.state & Gdk.ModifierType.CONTROL_MASK and\
self.__list_type & RowListType.DND:
if self.get_state_flags() & Gtk.StateFlags.SELECTED:
self.set_state_flags(Gtk.StateFlags.NORMAL, True)
else:
self.set_state_flags(Gtk.StateFlags.SELECTED, True)
elif event.state & Gdk.ModifierType.SHIFT_MASK and\
self.__list_type & RowListType.DND:
self.emit("do-selection")
else:
self.reveal()
def __on_action_button_release_event(self, button, event):
"""
......@@ -606,6 +617,7 @@ class AlbumsListView(LazyLoadingView, ViewController):
row.connect("insert-album", self.__on_insert_album)
row.connect("insert-album-after", self.__on_insert_album_after)
row.connect("remove-album", self.__on_remove_album)
row.connect("do-selection", self.__on_do_selection)
return row
def __auto_scroll(self, up):
......@@ -743,3 +755,25 @@ class AlbumsListView(LazyLoadingView, ViewController):
@param row as AlbumRow
"""
App().player.remove_album(row.album)
def __on_do_selection(self, row):
"""
Select rows from start (or any selected row) to track
@param row as AlbumRow
"""
children = self._box.get_children()
selected = None
end = children.index(row) + 1
for child in children:
if child == row:
break
if child.get_state_flags() & Gtk.StateFlags.SELECTED:
selected = child
if selected is None:
start = 0
else:
start = children.index(selected)
for child in children[start:end]:
child.set_state_flags(Gtk.StateFlags.SELECTED, True)
for child in children[end:]:
child.set_state_flags(Gtk.StateFlags.NORMAL, True)
......@@ -283,6 +283,7 @@ class PlaylistsWidget(Gtk.Grid):
previous_row.set_next_row(row)
row.connect("insert-track", self.__on_insert_track)
row.connect("remove-track", self.__on_remove_track)
row.connect("do-selection", self.__on_do_selection)
row.show()
widget.insert(row, position)
GLib.idle_add(self.__add_tracks, widgets)
......@@ -353,6 +354,7 @@ class PlaylistsWidget(Gtk.Grid):
new_row = PlaylistRow(track, self.__list_type)
new_row.connect("insert-track", self.__on_insert_track)
new_row.connect("remove-track", self.__on_remove_track)
new_row.connect("do-selection", self.__on_do_selection)
new_row.show()
if down:
position += 1
......@@ -397,3 +399,25 @@ class PlaylistsWidget(Gtk.Grid):
else:
row.next_row.set_previous_row(row.previous_row)
row.previous_row.set_next_row(row.next_row)
def __on_do_selection(self, row):
"""
Select rows from start (or any selected row) to track
@param row as Row
"""
children = self.children
selected = None
end = children.index(row) + 1
for child in children:
if child == row:
break
if child.get_state_flags() & Gtk.StateFlags.SELECTED:
selected = child
if selected is None:
start = 0
else:
start = children.index(selected)
for child in children[start:end]:
child.set_state_flags(Gtk.StateFlags.SELECTED, True)
for child in children[end:]:
child.set_state_flags(Gtk.StateFlags.NORMAL, True)
......@@ -288,7 +288,6 @@ class Row(Gtk.ListBoxRow):
elif event.state & Gdk.ModifierType.SHIFT_MASK and\
self._list_type & RowListType.DND:
self.emit("do-selection")
return True
elif event.button == 3:
window = widget.get_window()
if window == event.window:
......
......@@ -193,9 +193,22 @@ class DNDRow:
if r.get_state_flags() & Gtk.StateFlags.SELECTED:
track_ids.append(r.track.id)
r = r.next_row
info = {"data": (wstr, track_ids, None)}
info = {"data": (wstr, track_ids)}
elif hasattr(self, "_album"):
info = {"data": (wstr, self._album.track_ids, self._album.id)}
album_ids = {}
# Delete all selected rows
r = row.previous_row
while r is not None:
if r.get_state_flags() & Gtk.StateFlags.SELECTED:
album_ids[r.album.id] = r.album.track_ids
r = r.previous_row
album_ids[row.album.id] = row.album.track_ids
r = row.next_row
while r is not None:
if r.get_state_flags() & Gtk.StateFlags.SELECTED:
album_ids[r.album.id] = r.album.track_ids
r = r.next_row
info = {"data": (wstr, album_ids)}
text = json.dumps(info)
data.set_text(text, len(text))
......@@ -220,16 +233,17 @@ class DNDRow:
try:
import json
info = json.loads(data.get_text())
(wstr, track_ids, album_id) = info["data"]
(wstr, ids) = info["data"]
if str(row) == wstr:
self.disconnect(self.__drag_data_delete_id)
self.__drag_data_delete_id = None
return
if wstr.find("AlbumRow") == -1:
for track_id in track_ids:
for track_id in ids:
self.emit("insert-track", track_id, down)
else:
self.emit("insert-album", album_id, track_ids, down)
for key in ids.keys():
self.emit("insert-album", int(key), ids[key], down)
except Exception as e:
Logger.error("DNDRow::on_drag_data_received(): %s", e)
# We want delete before insert
......
......@@ -49,6 +49,9 @@ class PlaylistRow(Row, DNDRow):
ArtSize.MEDIUM,
"small-cover-frame")
self.__artwork.set_no_show_all(True)
self.__artwork.set_margin_top(2)
self.__artwork.set_margin_start(2)
self.__artwork.set_margin_bottom(2)
# We force width with a Box
box = Gtk.Box()
box.set_homogeneous(True)
......@@ -112,15 +115,11 @@ class PlaylistRow(Row, DNDRow):
ArtSize.MEDIUM,
self.__artwork.get_scale_factor(),
self.__on_album_artwork)
self.__artwork.set_margin_top(2)
self.set_margin_bottom(2)
def hide_artwork(self):
"""
Hide row artwork
"""
self.__artwork.set_margin_top(0)
self.set_margin_bottom(0)
self.__artwork.set_tooltip_text("")
self.__artwork.clear()
self.__artwork.hide()
......
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