Skip to content

Commit

Permalink
LibraryControl: Map the EditItem shortcut to the "Rename" action when…
Browse files Browse the repository at this point in the history
… in the sidebar
  • Loading branch information
cr7pt0gr4ph7 committed Apr 23, 2024
1 parent 6b67e6d commit faf60e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
21 changes: 17 additions & 4 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,11 +980,24 @@ void LibraryControl::slotEditItem(double v) {
if (v <= 0) {
return;
}
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;

switch (m_focusedWidget) {
case FocusWidget::Sidebar: {
m_pSidebarWidget->editSelectedItem();
break;
}
case FocusWidget::TracksTable: {
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
pActiveView->editSelectedItem();
break;
}
default: {
break;
}
}
pActiveView->editSelectedItem();
}

void LibraryControl::slotGoToItem(double v) {
Expand Down
25 changes: 15 additions & 10 deletions src/widget/wlibrarysidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ void WLibrarySidebar::dropEvent(QDropEvent * event) {
}
}

void WLibrarySidebar::editSelectedItem() {
// Rename crate or playlist (internal, external, history)
QModelIndex selIndex = selectedIndex();
if (!selIndex.isValid()) {
return;
}
if (isExpanded(selIndex)) {
// Root views / knots can not be renamed
return;
}
emit renameItem(selIndex);
return;
}

void WLibrarySidebar::toggleSelectedItem() {
QModelIndex index = selectedIndex();
if (index.isValid()) {
Expand Down Expand Up @@ -312,16 +326,7 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
emit setLibraryFocus(FocusWidget::TracksTable);
return;
case kRenameSidebarItemShortcutKey: { // F2
// Rename crate or playlist (internal, external, history)
QModelIndex selIndex = selectedIndex();
if (!selIndex.isValid()) {
return;
}
if (isExpanded(selIndex)) {
// Root views / knots can not be renamed
return;
}
emit renameItem(selIndex);
editSelectedItem();
return;
}
case kHideRemoveShortcutKey: { // Del (macOS: Cmd+Backspace)
Expand Down
1 change: 1 addition & 0 deletions src/widget/wlibrarysidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class WLibrarySidebar : public QTreeView, public WBaseWidget {
void focusInEvent(QFocusEvent* event) override;
void timerEvent(QTimerEvent* event) override;
void toggleSelectedItem();
void editSelectedItem();
bool isLeafNodeSelected();
bool isChildIndexSelected(const QModelIndex& index);
bool isFeatureRootIndexSelected(LibraryFeature* pFeature);
Expand Down

0 comments on commit faf60e6

Please sign in to comment.