v0.21.0: click to rename
Clicking the already-selected playlist in the sidebar opens inline rename, and renaming an existing playlist starts with the cursor at the end rather than the whole name selected. New playlists still select all.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.20.6"
|
||||
__version__ = "0.21.0"
|
||||
|
||||
+30
-1
@@ -1,6 +1,6 @@
|
||||
from PyQt6.QtWidgets import (
|
||||
QWidget, QVBoxLayout, QPushButton, QTreeWidget, QTreeWidgetItem, QMenu,
|
||||
QInputDialog, QMessageBox, QAbstractItemView,
|
||||
QInputDialog, QMessageBox, QAbstractItemView, QLineEdit,
|
||||
)
|
||||
from PyQt6.QtCore import Qt, QTimer, QPoint, pyqtSignal
|
||||
from PyQt6.QtGui import QBrush, QPainter, QPixmap
|
||||
@@ -175,6 +175,14 @@ class PlaylistTree(QTreeWidget):
|
||||
self.customContextMenuRequested.connect(self._show_context_menu)
|
||||
self.currentItemChanged.connect(self._on_selection_changed)
|
||||
self.itemChanged.connect(self._on_item_renamed)
|
||||
# Clicking the already-selected playlist renames it (Qt waits out the
|
||||
# double-click interval first, and a press that becomes a drag never
|
||||
# opens the editor).
|
||||
self.setEditTriggers(self.editTriggers()
|
||||
| QAbstractItemView.EditTrigger.SelectedClicked)
|
||||
# Only a brand-new playlist opens its editor with everything selected,
|
||||
# so typing replaces "untitled playlist"; see edit().
|
||||
self._select_all_next_edit = False
|
||||
|
||||
# Edge auto-scroll during a drag (Qt's built-in autoscroll never runs
|
||||
# because our dragMoveEvent accepts the event itself). Mirrors
|
||||
@@ -293,6 +301,7 @@ class PlaylistTree(QTreeWidget):
|
||||
item = self._find_item(playlist.persistent_id)
|
||||
if item is not None:
|
||||
self.setCurrentItem(item) # selects + navigates to the new playlist
|
||||
self._select_all_next_edit = True
|
||||
self.editItem(item, 0) # live inline rename; editor selects all
|
||||
|
||||
def create_smart_playlist_interactive(self, parent_pid: str = ""):
|
||||
@@ -309,6 +318,7 @@ class PlaylistTree(QTreeWidget):
|
||||
item = self._find_item(playlist.persistent_id)
|
||||
if item is not None:
|
||||
self.setCurrentItem(item)
|
||||
self._select_all_next_edit = True
|
||||
self.editItem(item, 0)
|
||||
|
||||
def edit_smart_playlist(self, pid: str):
|
||||
@@ -329,6 +339,25 @@ class PlaylistTree(QTreeWidget):
|
||||
if current.data(0, KIND_ROLE) in ("playlist", "smart"):
|
||||
self.playlist_selected.emit(current.data(0, PID_ROLE))
|
||||
|
||||
def edit(self, index, trigger=QAbstractItemView.EditTrigger.AllEditTriggers,
|
||||
event=None):
|
||||
"""Every inline rename (click, double-click, F2, context menu) comes
|
||||
through here. Qt selects the editor's whole text inside this call,
|
||||
after the delegate has run, so renaming an existing playlist undoes
|
||||
that afterwards: nothing selected, cursor at the end. Defaulted args
|
||||
because this override shadows PyQt's one-argument edit() slot too."""
|
||||
opened = super().edit(index, trigger, event)
|
||||
# A SelectedClicked edit returns True having only armed Qt's
|
||||
# double-click timer; the editor opens when that fires (through here
|
||||
# again), so only a real editor settles the one-shot flag.
|
||||
editor = self.indexWidget(index) if opened else None
|
||||
if isinstance(editor, QLineEdit):
|
||||
if not self._select_all_next_edit:
|
||||
editor.deselect()
|
||||
editor.end(False)
|
||||
self._select_all_next_edit = False
|
||||
return opened
|
||||
|
||||
def _on_item_renamed(self, item, _column):
|
||||
pid = item.data(0, PID_ROLE)
|
||||
if pid:
|
||||
|
||||
Reference in New Issue
Block a user