Make getting current row safer
This commit is contained in:
parent
68e524594d
commit
e23f6e2cc8
@ -666,6 +666,17 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
|
def current_row_or_end(self) -> int:
|
||||||
|
"""
|
||||||
|
If a row or rows are selected, return the row number of the first
|
||||||
|
selected row otherwise return the row number for a new row at the
|
||||||
|
of the playlist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.current.selected_rows:
|
||||||
|
return self.current.selected_rows[0]
|
||||||
|
return self.current.base_model.rowCount()
|
||||||
|
|
||||||
def debug(self):
|
def debug(self):
|
||||||
"""Invoke debugger"""
|
"""Invoke debugger"""
|
||||||
|
|
||||||
@ -848,7 +859,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# garbage collected while import threads are still running
|
# garbage collected while import threads are still running
|
||||||
self.importer = FileImporter(
|
self.importer = FileImporter(
|
||||||
self.current.base_model,
|
self.current.base_model,
|
||||||
self.current.selected_rows[0],
|
self.current_row_or_end()
|
||||||
)
|
)
|
||||||
self.importer.do_import()
|
self.importer.do_import()
|
||||||
|
|
||||||
@ -862,27 +873,19 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
dlg.resize(500, 100)
|
dlg.resize(500, 100)
|
||||||
ok = dlg.exec()
|
ok = dlg.exec()
|
||||||
if ok:
|
if ok:
|
||||||
if self.current.selected_rows:
|
|
||||||
new_row_number = self.current.selected_rows[0]
|
|
||||||
else:
|
|
||||||
new_row_number = self.current.base_model.rowCount()
|
|
||||||
self.current.base_model.insert_row(
|
self.current.base_model.insert_row(
|
||||||
proposed_row_number=new_row_number,
|
proposed_row_number=self.current_row_or_end(),
|
||||||
note=dlg.textValue(),
|
note=dlg.textValue(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def insert_track(self) -> None:
|
def insert_track(self) -> None:
|
||||||
"""Show dialog box to select and add track from database"""
|
"""Show dialog box to select and add track from database"""
|
||||||
|
|
||||||
if self.current.selected_rows:
|
|
||||||
new_row_number = self.current.selected_rows[0]
|
|
||||||
else:
|
|
||||||
new_row_number = self.current.base_model.rowCount()
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
dlg = TrackSelectDialog(
|
dlg = TrackSelectDialog(
|
||||||
parent=self,
|
parent=self,
|
||||||
session=session,
|
session=session,
|
||||||
new_row_number=new_row_number,
|
new_row_number=self.current_row_or_end(),
|
||||||
base_model=self.current.base_model,
|
base_model=self.current.base_model,
|
||||||
)
|
)
|
||||||
dlg.exec()
|
dlg.exec()
|
||||||
@ -1147,11 +1150,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
to_playlist_model = self.current.base_model
|
to_playlist_model = self.current.base_model
|
||||||
selected_rows = self.current.selected_rows
|
destination_row = self.current_row_or_end()
|
||||||
if selected_rows:
|
|
||||||
destination_row = selected_rows[0]
|
|
||||||
else:
|
|
||||||
destination_row = self.current.base_model.rowCount()
|
|
||||||
|
|
||||||
# If we move a row to immediately under the current track, make
|
# If we move a row to immediately under the current track, make
|
||||||
# that moved row the next track
|
# that moved row the next track
|
||||||
@ -1516,7 +1515,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
next track. If no next track, return None.
|
next track. If no next track, return None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
row_number = self.current.selected_rows[0]
|
row_number: Optional[int] = None
|
||||||
|
|
||||||
|
if self.current.selected_rows:
|
||||||
|
row_number = self.current.selected_rows[0]
|
||||||
if row_number is None:
|
if row_number is None:
|
||||||
if track_sequence.next:
|
if track_sequence.next:
|
||||||
if track_sequence.next.track_id:
|
if track_sequence.next.track_id:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user