Move rows works.
This commit is contained in:
parent
444c3e4fb4
commit
647e7d478a
@ -797,6 +797,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# Identify destination playlist
|
||||
visible_tab = self.visible_playlist_tab()
|
||||
source_playlist = visible_tab.playlist_id
|
||||
|
||||
# Get destination playlist id
|
||||
playlists = []
|
||||
for playlist in Playlists.get_all(session):
|
||||
if playlist.id == source_playlist:
|
||||
@ -804,17 +806,17 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
else:
|
||||
playlists.append(playlist)
|
||||
|
||||
# Get destination playlist id
|
||||
dlg = SelectPlaylistDialog(self, playlists=playlists, session=session)
|
||||
dlg.exec()
|
||||
if not dlg.playlist:
|
||||
return
|
||||
destination_playlist_id = dlg.playlist.id
|
||||
|
||||
# Remove moved rows from display
|
||||
# Remove moved rows from display and save
|
||||
visible_tab.remove_rows([plr.row_number for plr in playlistrows])
|
||||
visible_tab.save_playlist(session)
|
||||
|
||||
# Update playlist for the rows in the database
|
||||
# Update destination playlist in the database
|
||||
last_row = PlaylistRows.get_last_used_row(session,
|
||||
destination_playlist_id)
|
||||
if last_row is not None:
|
||||
@ -836,7 +838,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
destination_playlist_tab = self.tabPlaylist.widget(tab)
|
||||
break
|
||||
if destination_playlist_tab:
|
||||
destination_playlist_tab.populate(session, dlg.playlist.id)
|
||||
destination_playlist_tab.populate_display(session, dlg.playlist.id)
|
||||
|
||||
def move_selected(self) -> None:
|
||||
"""
|
||||
@ -918,17 +920,17 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
playlist_tab = self.visible_playlist_tab()
|
||||
dst_playlist_id = playlist_tab.playlist_id
|
||||
dst_row = self.visible_playlist_tab().get_new_row_number()
|
||||
|
||||
with Session() as session:
|
||||
# Create space in destination playlist
|
||||
if playlist_tab.selectionModel().hasSelection():
|
||||
row = playlist_tab.currentRow()
|
||||
PlaylistRows.move_rows_down(session, dst_playlist_id,
|
||||
row, len(self.selected_plrs))
|
||||
session.commit()
|
||||
PlaylistRows.move_rows_down(session, dst_playlist_id,
|
||||
dst_row, len(self.selected_plrs))
|
||||
session.commit()
|
||||
|
||||
# Update plrs
|
||||
row = dst_row
|
||||
src_playlist_id = None
|
||||
dst_row = row
|
||||
for plr in self.selected_plrs:
|
||||
# Update moved rows
|
||||
session.add(plr)
|
||||
@ -941,8 +943,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
session.commit()
|
||||
|
||||
# Update display
|
||||
self.visible_playlist_tab().populate(session, dst_playlist_id,
|
||||
scroll_to_top=False)
|
||||
self.visible_playlist_tab().populate_display(
|
||||
session, dst_playlist_id, scroll_to_top=False)
|
||||
|
||||
# If source playlist is not destination playlist, fixup row
|
||||
# numbers and update display
|
||||
@ -957,8 +959,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
source_playlist_tab = self.tabPlaylist.widget(tab)
|
||||
break
|
||||
if source_playlist_tab:
|
||||
source_playlist_tab.populate(session, src_playlist_id,
|
||||
scroll_to_top=False)
|
||||
source_playlist_tab.populate_display(
|
||||
session, src_playlist_id, scroll_to_top=False)
|
||||
|
||||
# Reset so rows can't be repasted
|
||||
self.selected_plrs = None
|
||||
|
||||
@ -557,6 +557,17 @@ class PlaylistTab(QTableWidget):
|
||||
self.clearSelection()
|
||||
self.setDragEnabled(False)
|
||||
|
||||
def get_new_row_number(self) -> int:
|
||||
"""
|
||||
Return the selected row or the row count if no row selected
|
||||
(ie, new row will be appended)
|
||||
"""
|
||||
|
||||
if self.selectionModel().hasSelection():
|
||||
return self.currentRow()
|
||||
else:
|
||||
return self.rowCount()
|
||||
|
||||
def get_selected_playlistrow_ids(self) -> Optional[List]:
|
||||
"""
|
||||
Return a list of PlaylistRow ids of the selected rows
|
||||
@ -1607,6 +1618,20 @@ class PlaylistTab(QTableWidget):
|
||||
new_metadata = self._meta_get(row) | (1 << attribute)
|
||||
self.item(row, USERDATA).setData(self.ROW_FLAGS, new_metadata)
|
||||
|
||||
def _move_row(self, session: Session, plr: PlaylistRows,
|
||||
new_row_number: int) -> None:
|
||||
"""Move playlist row to new_row_number using parent copy/paste"""
|
||||
|
||||
# Remove source row
|
||||
self.removeRow(plr.row_number)
|
||||
# Fixup plr row number
|
||||
if plr.row_number < new_row_number:
|
||||
plr.row_number = new_row_number - 1
|
||||
else:
|
||||
plr.row_number = new_row_number
|
||||
self.insert_row(session, plr)
|
||||
self.save_playlist(session)
|
||||
|
||||
def _mplayer_play(self, track_id: int) -> None:
|
||||
"""Play track with mplayer"""
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user