diff --git a/krusader/Panel/PanelView/krview.h b/krusader/Panel/PanelView/krview.h --- a/krusader/Panel/PanelView/krview.h +++ b/krusader/Panel/PanelView/krview.h @@ -254,7 +254,7 @@ uint count() const { return _count; } void getSelectedItems(QStringList *names, bool fallbackToFocused = true); void getItemsByMask(QString mask, QStringList *names, bool dirs = true, bool files = true); - void getSelectedKrViewItems(KrViewItemList *items); + KrViewItemList getSelectedKrViewItems(); void selectAllIncludingDirs() { changeSelection(KRQuery("*"), true, true); } void select(const KRQuery &filter = KRQuery("*")) { changeSelection(filter, true); } void unselect(const KRQuery &filter = KRQuery("*")) { changeSelection(filter, false); } diff --git a/krusader/Panel/PanelView/krview.cpp b/krusader/Panel/PanelView/krview.cpp --- a/krusader/Panel/PanelView/krview.cpp +++ b/krusader/Panel/PanelView/krview.cpp @@ -398,19 +398,24 @@ } } -void KrView::getSelectedKrViewItems(KrViewItemList *items) +KrViewItemList KrView::getSelectedKrViewItems() { - for (KrViewItem * it = getFirst(); it != 0; it = getNext(it)) - if (it->isSelected() && (it->name() != "..")) items->append(it); + KrViewItemList items; + for (KrViewItem * it = getFirst(); it != 0; it = getNext(it)) { + if (it->isSelected() && (it->name() != "..")) { + items.append(it); + } + } // if all else fails, take the current item - QString item = getCurrentItem(); - if (items->empty() && - !item.isEmpty() && - item != ".." && - getCurrentKrViewItem() != 0) { - items->append(getCurrentKrViewItem()); + if (items.empty()) { + KrViewItem *currentItem = getCurrentKrViewItem(); + if (currentItem && !currentItem->isDummy()) { + items.append(getCurrentKrViewItem()); + } } + + return items; } QString KrView::statistics() @@ -476,8 +481,7 @@ makeItemVisible(temp); } else if (makeVisible && firstMatch != 0) { // if no selected item is visible... - KrViewItemList selectedItems; - getSelectedKrViewItems(&selectedItems); + const KrViewItemList selectedItems = getSelectedKrViewItems(); bool anyVisible = false; for (KrViewItem *item : selectedItems) { if (isItemVisible(item)) { diff --git a/krusader/Panel/panelcontextmenu.cpp b/krusader/Panel/panelcontextmenu.cpp --- a/krusader/Panel/panelcontextmenu.cpp +++ b/krusader/Panel/panelcontextmenu.cpp @@ -59,9 +59,9 @@ { PanelContextMenu menu(panel); QAction * res = menu.exec(pos); - int result = -1; - if (res && res->data().canConvert()) - result = res->data().toInt(); + int result = res && res->data().canConvert() ? + res->data().toInt() : + -1; menu.performAction(result); } @@ -127,8 +127,7 @@ QAction * openAct = addAction(i18n("Open/Run")); openAct->setData(QVariant(OPEN_ID)); if (!multipleSelections) { // meaningful only if one file is selected - KrViewItemList viewItems; - panel->view->getSelectedKrViewItems(&viewItems); + const KrViewItemList viewItems = panel->view->getSelectedKrViewItems(); openAct->setIcon(viewItems.first()->icon()); openAct->setText(file->isExecutable() && !file->isDir() ? i18n("Run") : i18n("Open")); @@ -407,8 +406,7 @@ for (const KFileItem item : _items) { selectedNames.append(item.name()); } - KrViewItemList otherItems; - panel->otherPanel()->view->getSelectedKrViewItems(&otherItems); + const KrViewItemList otherItems = panel->otherPanel()->view->getSelectedKrViewItems(); for (KrViewItem *otherItem : otherItems) { const QString name = otherItem->name(); if (!selectedNames.contains(name)) { diff --git a/krusader/Panel/panelfunc.cpp b/krusader/Panel/panelfunc.cpp --- a/krusader/Panel/panelfunc.cpp +++ b/krusader/Panel/panelfunc.cpp @@ -983,8 +983,7 @@ if (!panel->func->files()->isLocal()) return; // only local, non-virtual files are supported - KrViewItemList items; - panel->view->getSelectedKrViewItems(&items); + const KrViewItemList items = panel->view->getSelectedKrViewItems(); QStringList fileNames; for (KrViewItem *item : items) { diff --git a/krusader/Search/krsearchdialog.h b/krusader/Search/krsearchdialog.h --- a/krusader/Search/krsearchdialog.h +++ b/krusader/Search/krsearchdialog.h @@ -59,7 +59,6 @@ void startSearch(); void stopSearch(); void feedToListBox(); - void copyToClipBoard(); void slotFound(const FileItem &file, const QString &foundText); void closeDialog(bool isAccept = true); void executed(const QString &name); @@ -73,11 +72,14 @@ protected slots: void reject() Q_DECL_OVERRIDE; -private: - bool gui2query(); +private slots: void editCurrent(); void viewCurrent(); void compareByContent(); + void copyToClipBoard(); + +private: + bool gui2query(); /** * Placing search query to clipboard is optional (opt-in). @@ -113,6 +115,11 @@ bool isBusy; bool closed; + QAction *viewAction; + QAction *editAction; + QAction *compareAction; + QAction *copyAction; + static QString lastSearchText; static int lastSearchType; static bool lastSearchForCase; diff --git a/krusader/Search/krsearchdialog.cpp b/krusader/Search/krsearchdialog.cpp --- a/krusader/Search/krsearchdialog.cpp +++ b/krusader/Search/krsearchdialog.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -189,12 +190,41 @@ filterTabs = FilterTabs::addTo(searcherTabs, FilterTabs::Default); generalFilter = (GeneralFilter *)filterTabs->get("GeneralFilter"); + + // creating the result tab + QWidget* resultTab = new QWidget(searcherTabs); QGridLayout* resultLayout = new QGridLayout(resultTab); resultLayout->setSpacing(6); resultLayout->setContentsMargins(6, 6, 6, 6); - // creating the result tab + // actions + viewAction = new QAction(Icon("document-edit-preview"), i18n("View File"), this); + viewAction->setShortcut(Qt::Key_F3); + connect(viewAction, &QAction::triggered, this, &KrSearchDialog::viewCurrent); + addAction(viewAction); + + editAction = new QAction(Icon("document-edit-sign"), i18n("Edit File"), this); + editAction->setShortcut(Qt::Key_F4); + connect(editAction, &QAction::triggered, this, &KrSearchDialog::editCurrent); + addAction(editAction); + + compareAction = new QAction(i18n("Compare by content"), this); + compareAction->setShortcut(Qt::Key_F10); + connect(compareAction, &QAction::triggered, this, &KrSearchDialog::compareByContent); + addAction(compareAction); + + copyAction = KStandardAction::create(KStandardAction::Copy, this, SLOT(copyToClipBoard()), this); + copyAction->setText(i18n("Copy to Clipboard")); + addAction(copyAction); + + connect(searcherTabs, &QTabWidget::currentChanged, this, [=](int index) { + bool resultTabShown = index == searcherTabs->indexOf(resultTab); + viewAction->setEnabled(resultTabShown); + editAction->setEnabled(resultTabShown); + compareAction->setEnabled(resultTabShown); + copyAction->setEnabled(resultTabShown); + }); // creating the result list view result = new SearchResultContainer(this); @@ -515,43 +545,30 @@ if (resultView->widget()->hasFocus()) { if ((e->key() | e->modifiers()) == (Qt::CTRL | Qt::Key_I)) { searchBar->showBar(KrSearchBar::MODE_FILTER); - } else if (e->key() == Qt::Key_F4) { - tryPlaceSearchQueryToClipboard(); - editCurrent(); - return; - } else if (e->key() == Qt::Key_F3) { - tryPlaceSearchQueryToClipboard(); - viewCurrent(); - return; - } else if (e->key() == Qt::Key_F10) { - compareByContent(); - return; - } else if (KrGlobal::copyShortcut == QKeySequence(e->key() | e->modifiers())) { - copyToClipBoard(); - return; } } QDialog::keyPressEvent(e); } void KrSearchDialog::editCurrent() { + tryPlaceSearchQueryToClipboard(); KrViewItem *current = resultView->getCurrentKrViewItem(); if (current) KrViewer::edit(current->getFileItem()->getUrl(), this); } void KrSearchDialog::viewCurrent() { + tryPlaceSearchQueryToClipboard(); KrViewItem *current = resultView->getCurrentKrViewItem(); if (current) KrViewer::view(current->getFileItem()->getUrl(), this); } void KrSearchDialog::compareByContent() { - KrViewItemList list; - resultView->getSelectedKrViewItems(&list); + const KrViewItemList list = resultView->getSelectedKrViewItems(); if (list.count() != 2) return; @@ -564,24 +581,14 @@ QMenu popup; popup.setTitle(i18n("Krusader Search")); - QAction *actView = popup.addAction(i18n("View File (F3)")); - QAction *actEdit = popup.addAction(i18n("Edit File (F4)")); - QAction *actComp = popup.addAction(i18n("Compare by content (F10)")); - if(resultView->numSelected() != 2) - actComp->setEnabled(false); - QAction *actClip = popup.addAction(i18n("Copy selected to clipboard")); - - QAction *result = popup.exec(pos); - - // check out the user's option - if (result == actView) - viewCurrent(); - else if (result == actEdit) - editCurrent(); - else if (result == actClip) - copyToClipBoard(); - else if (result == actComp) - compareByContent(); + popup.addAction(viewAction); + popup.addAction(editAction); + popup.addAction(compareAction); + compareAction->setEnabled(resultView->numSelected() == 2); + popup.addSeparator(); + popup.addAction(copyAction); + + popup.exec(pos); } void KrSearchDialog::feedToListBox() @@ -637,9 +644,11 @@ void KrSearchDialog::copyToClipBoard() { + const KrViewItemList selectedItems = resultView->getSelectedKrViewItems(); QList urls; - foreach(FileItem *fileitem, result->fileItems()) - urls.push_back(fileitem->getUrl()); + for (KrViewItem *item : selectedItems) { + urls.append(item->getFileItem()->getUrl()); + } if (urls.count() == 0) return; diff --git a/krusader/actionsbase.cpp b/krusader/actionsbase.cpp --- a/krusader/actionsbase.cpp +++ b/krusader/actionsbase.cpp @@ -113,7 +113,7 @@ QAction *ActionsBase::stdAction(KStandardAction::StandardAction id, ActionGroup &group, const char *slot) { - QAction *action = KStandardAction::create(id, 0, 0, _mainWindow->actions()); + QAction *action = KStandardAction::create(id, nullptr, nullptr, _mainWindow->actions()); group.addAction(action, slot); return action; }