Changeset View
Changeset View
Standalone View
Standalone View
krusader/Search/krsearchdialog.cpp
Show All 33 Lines | |||||
34 | // QtWidgets | 34 | // QtWidgets | ||
35 | #include <QApplication> | 35 | #include <QApplication> | ||
36 | #include <QGridLayout> | 36 | #include <QGridLayout> | ||
37 | #include <QInputDialog> | 37 | #include <QInputDialog> | ||
38 | #include <QHBoxLayout> | 38 | #include <QHBoxLayout> | ||
39 | #include <QMenu> | 39 | #include <QMenu> | ||
40 | 40 | | |||
41 | #include <KConfigCore/KConfig> | 41 | #include <KConfigCore/KConfig> | ||
42 | #include <KConfigWidgets/KStandardAction> | ||||
42 | #include <KI18n/KLocalizedString> | 43 | #include <KI18n/KLocalizedString> | ||
43 | #include <KWidgetsAddons/KMessageBox> | 44 | #include <KWidgetsAddons/KMessageBox> | ||
44 | 45 | | |||
45 | #include "krsearchmod.h" | 46 | #include "krsearchmod.h" | ||
46 | #include "../Dialogs/krdialogs.h" | 47 | #include "../Dialogs/krdialogs.h" | ||
47 | #include "../Dialogs/krspecialwidgets.h" | 48 | #include "../Dialogs/krspecialwidgets.h" | ||
48 | #include "../Dialogs/krsqueezedtextlabel.h" | 49 | #include "../Dialogs/krsqueezedtextlabel.h" | ||
49 | #include "../FileSystem/fileitem.h" | 50 | #include "../FileSystem/fileitem.h" | ||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 135 | { | |||
184 | 185 | | |||
185 | // creating the searcher tabs | 186 | // creating the searcher tabs | ||
186 | 187 | | |||
187 | searcherTabs = new QTabWidget(this); | 188 | searcherTabs = new QTabWidget(this); | ||
188 | 189 | | |||
189 | filterTabs = FilterTabs::addTo(searcherTabs, FilterTabs::Default); | 190 | filterTabs = FilterTabs::addTo(searcherTabs, FilterTabs::Default); | ||
190 | generalFilter = (GeneralFilter *)filterTabs->get("GeneralFilter"); | 191 | generalFilter = (GeneralFilter *)filterTabs->get("GeneralFilter"); | ||
191 | 192 | | |||
193 | | ||||
194 | // creating the result tab | ||||
195 | | ||||
192 | QWidget* resultTab = new QWidget(searcherTabs); | 196 | QWidget* resultTab = new QWidget(searcherTabs); | ||
193 | QGridLayout* resultLayout = new QGridLayout(resultTab); | 197 | QGridLayout* resultLayout = new QGridLayout(resultTab); | ||
194 | resultLayout->setSpacing(6); | 198 | resultLayout->setSpacing(6); | ||
195 | resultLayout->setContentsMargins(6, 6, 6, 6); | 199 | resultLayout->setContentsMargins(6, 6, 6, 6); | ||
196 | 200 | | |||
197 | // creating the result tab | 201 | // actions | ||
202 | viewAction = new QAction(Icon("document-edit-preview"), i18n("View File"), this); | ||||
203 | viewAction->setShortcut(Qt::Key_F3); | ||||
204 | connect(viewAction, &QAction::triggered, this, &KrSearchDialog::viewCurrent); | ||||
205 | addAction(viewAction); | ||||
206 | | ||||
207 | editAction = new QAction(Icon("document-edit-sign"), i18n("Edit File"), this); | ||||
208 | editAction->setShortcut(Qt::Key_F4); | ||||
209 | connect(editAction, &QAction::triggered, this, &KrSearchDialog::editCurrent); | ||||
210 | addAction(editAction); | ||||
211 | | ||||
212 | compareAction = new QAction(i18n("Compare by content"), this); | ||||
213 | compareAction->setShortcut(Qt::Key_F10); | ||||
214 | connect(compareAction, &QAction::triggered, this, &KrSearchDialog::compareByContent); | ||||
215 | addAction(compareAction); | ||||
216 | | ||||
217 | copyAction = KStandardAction::create(KStandardAction::Copy, this, SLOT(copyToClipBoard()), this); | ||||
218 | copyAction->setText(i18n("Copy to Clipboard")); | ||||
219 | addAction(copyAction); | ||||
220 | | ||||
221 | connect(searcherTabs, &QTabWidget::currentChanged, this, [=](int index) { | ||||
222 | bool resultTabShown = index == searcherTabs->indexOf(resultTab); | ||||
223 | viewAction->setEnabled(resultTabShown); | ||||
224 | editAction->setEnabled(resultTabShown); | ||||
225 | compareAction->setEnabled(resultTabShown); | ||||
226 | copyAction->setEnabled(resultTabShown); | ||||
227 | }); | ||||
198 | 228 | | |||
199 | // creating the result list view | 229 | // creating the result list view | ||
200 | result = new SearchResultContainer(this); | 230 | result = new SearchResultContainer(this); | ||
201 | // the view | 231 | // the view | ||
202 | resultView = KrViewFactory::createView(RESULTVIEW_TYPE, resultTab, krConfig); | 232 | resultView = KrViewFactory::createView(RESULTVIEW_TYPE, resultTab, krConfig); | ||
203 | resultView->init(false); | 233 | resultView->init(false); | ||
204 | resultView->restoreSettings(KConfigGroup(&group, "ResultView")); | 234 | resultView->restoreSettings(KConfigGroup(&group, "ResultView")); | ||
205 | resultView->setMainWindow(this); | 235 | resultView->setMainWindow(this); | ||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Line(s) | 538 | { | |||
510 | 540 | | |||
511 | if (isBusy && e->key() == Qt::Key_Escape) { /* at searching we must not close the window */ | 541 | if (isBusy && e->key() == Qt::Key_Escape) { /* at searching we must not close the window */ | ||
512 | stopSearch(); /* so we simply stop searching */ | 542 | stopSearch(); /* so we simply stop searching */ | ||
513 | return; | 543 | return; | ||
514 | } | 544 | } | ||
515 | if (resultView->widget()->hasFocus()) { | 545 | if (resultView->widget()->hasFocus()) { | ||
516 | if ((e->key() | e->modifiers()) == (Qt::CTRL | Qt::Key_I)) { | 546 | if ((e->key() | e->modifiers()) == (Qt::CTRL | Qt::Key_I)) { | ||
517 | searchBar->showBar(KrSearchBar::MODE_FILTER); | 547 | searchBar->showBar(KrSearchBar::MODE_FILTER); | ||
518 | } else if (e->key() == Qt::Key_F4) { | | |||
519 | tryPlaceSearchQueryToClipboard(); | | |||
520 | editCurrent(); | | |||
521 | return; | | |||
522 | } else if (e->key() == Qt::Key_F3) { | | |||
523 | tryPlaceSearchQueryToClipboard(); | | |||
524 | viewCurrent(); | | |||
525 | return; | | |||
526 | } else if (e->key() == Qt::Key_F10) { | | |||
527 | compareByContent(); | | |||
528 | return; | | |||
529 | } else if (KrGlobal::copyShortcut == QKeySequence(e->key() | e->modifiers())) { | | |||
530 | copyToClipBoard(); | | |||
531 | return; | | |||
532 | } | 548 | } | ||
533 | } | 549 | } | ||
534 | QDialog::keyPressEvent(e); | 550 | QDialog::keyPressEvent(e); | ||
535 | } | 551 | } | ||
536 | 552 | | |||
537 | void KrSearchDialog::editCurrent() | 553 | void KrSearchDialog::editCurrent() | ||
538 | { | 554 | { | ||
555 | tryPlaceSearchQueryToClipboard(); | ||||
539 | KrViewItem *current = resultView->getCurrentKrViewItem(); | 556 | KrViewItem *current = resultView->getCurrentKrViewItem(); | ||
540 | if (current) | 557 | if (current) | ||
541 | KrViewer::edit(current->getFileItem()->getUrl(), this); | 558 | KrViewer::edit(current->getFileItem()->getUrl(), this); | ||
542 | } | 559 | } | ||
543 | 560 | | |||
544 | void KrSearchDialog::viewCurrent() | 561 | void KrSearchDialog::viewCurrent() | ||
545 | { | 562 | { | ||
563 | tryPlaceSearchQueryToClipboard(); | ||||
546 | KrViewItem *current = resultView->getCurrentKrViewItem(); | 564 | KrViewItem *current = resultView->getCurrentKrViewItem(); | ||
547 | if (current) | 565 | if (current) | ||
548 | KrViewer::view(current->getFileItem()->getUrl(), this); | 566 | KrViewer::view(current->getFileItem()->getUrl(), this); | ||
549 | } | 567 | } | ||
550 | 568 | | |||
551 | void KrSearchDialog::compareByContent() | 569 | void KrSearchDialog::compareByContent() | ||
552 | { | 570 | { | ||
553 | KrViewItemList list; | 571 | const KrViewItemList list = resultView->getSelectedKrViewItems(); | ||
554 | resultView->getSelectedKrViewItems(&list); | | |||
555 | if (list.count() != 2) | 572 | if (list.count() != 2) | ||
556 | return; | 573 | return; | ||
557 | 574 | | |||
558 | SLOTS->compareContent(list[0]->getFileItem()->getUrl(),list[1]->getFileItem()->getUrl()); | 575 | SLOTS->compareContent(list[0]->getFileItem()->getUrl(),list[1]->getFileItem()->getUrl()); | ||
559 | } | 576 | } | ||
560 | 577 | | |||
561 | void KrSearchDialog::contextMenu(const QPoint &pos) | 578 | void KrSearchDialog::contextMenu(const QPoint &pos) | ||
562 | { | 579 | { | ||
563 | // create the menu | 580 | // create the menu | ||
564 | QMenu popup; | 581 | QMenu popup; | ||
565 | popup.setTitle(i18n("Krusader Search")); | 582 | popup.setTitle(i18n("Krusader Search")); | ||
566 | 583 | | |||
567 | QAction *actView = popup.addAction(i18n("View File (F3)")); | 584 | popup.addAction(viewAction); | ||
568 | QAction *actEdit = popup.addAction(i18n("Edit File (F4)")); | 585 | popup.addAction(editAction); | ||
569 | QAction *actComp = popup.addAction(i18n("Compare by content (F10)")); | 586 | popup.addAction(compareAction); | ||
570 | if(resultView->numSelected() != 2) | 587 | compareAction->setEnabled(resultView->numSelected() == 2); | ||
571 | actComp->setEnabled(false); | 588 | popup.addSeparator(); | ||
572 | QAction *actClip = popup.addAction(i18n("Copy selected to clipboard")); | 589 | popup.addAction(copyAction); | ||
573 | 590 | | |||
574 | QAction *result = popup.exec(pos); | 591 | popup.exec(pos); | ||
575 | | ||||
576 | // check out the user's option | | |||
577 | if (result == actView) | | |||
578 | viewCurrent(); | | |||
579 | else if (result == actEdit) | | |||
580 | editCurrent(); | | |||
581 | else if (result == actClip) | | |||
582 | copyToClipBoard(); | | |||
583 | else if (result == actComp) | | |||
584 | compareByContent(); | | |||
585 | } | 592 | } | ||
586 | 593 | | |||
587 | void KrSearchDialog::feedToListBox() | 594 | void KrSearchDialog::feedToListBox() | ||
588 | { | 595 | { | ||
589 | VirtualFileSystem virtFilesystem; | 596 | VirtualFileSystem virtFilesystem; | ||
590 | virtFilesystem.scanDir(QUrl::fromLocalFile("/")); | 597 | virtFilesystem.scanDir(QUrl::fromLocalFile("/")); | ||
591 | 598 | | |||
592 | KConfigGroup group(krConfig, "Search"); | 599 | KConfigGroup group(krConfig, "Search"); | ||
Show All 39 Lines | |||||
632 | 639 | | |||
633 | isBusy = false; | 640 | isBusy = false; | ||
634 | 641 | | |||
635 | closeDialog(); | 642 | closeDialog(); | ||
636 | } | 643 | } | ||
637 | 644 | | |||
638 | void KrSearchDialog::copyToClipBoard() | 645 | void KrSearchDialog::copyToClipBoard() | ||
639 | { | 646 | { | ||
647 | const KrViewItemList selectedItems = resultView->getSelectedKrViewItems(); | ||||
640 | QList<QUrl> urls; | 648 | QList<QUrl> urls; | ||
641 | foreach(FileItem *fileitem, result->fileItems()) | 649 | for (KrViewItem *item : selectedItems) { | ||
642 | urls.push_back(fileitem->getUrl()); | 650 | urls.append(item->getFileItem()->getUrl()); | ||
651 | } | ||||
643 | 652 | | |||
644 | if (urls.count() == 0) | 653 | if (urls.count() == 0) | ||
645 | return; | 654 | return; | ||
646 | 655 | | |||
647 | QMimeData *mimeData = new QMimeData; | 656 | QMimeData *mimeData = new QMimeData; | ||
648 | mimeData->setImageData(FileListIcon("file").pixmap()); | 657 | mimeData->setImageData(FileListIcon("file").pixmap()); | ||
649 | mimeData->setUrls(urls); | 658 | mimeData->setUrls(urls); | ||
650 | 659 | | |||
Show All 11 Lines |