Changeset View
Changeset View
Standalone View
Standalone View
kate/kateviewspace.cpp
Show All 17 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | #include "kateviewspace.h" | 20 | #include "kateviewspace.h" | ||
21 | 21 | | |||
22 | #include "katemainwindow.h" | 22 | #include "katemainwindow.h" | ||
23 | #include "kateviewmanager.h" | 23 | #include "kateviewmanager.h" | ||
24 | #include "katedocmanager.h" | 24 | #include "katedocmanager.h" | ||
25 | #include "kateapp.h" | 25 | #include "kateapp.h" | ||
26 | #include "katefileactions.h" | ||||
26 | #include "katesessionmanager.h" | 27 | #include "katesessionmanager.h" | ||
27 | #include "katedebug.h" | 28 | #include "katedebug.h" | ||
28 | #include "katetabbar.h" | 29 | #include "katetabbar.h" | ||
29 | #include "kactioncollection.h" | 30 | #include "kactioncollection.h" | ||
30 | #include "kateupdatedisabler.h" | 31 | #include "kateupdatedisabler.h" | ||
31 | 32 | | |||
32 | #include <KAcceleratorManager> | 33 | #include <KAcceleratorManager> | ||
33 | #include <KConfigGroup> | 34 | #include <KConfigGroup> | ||
34 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
35 | #include <KIO/OpenFileManagerWindowJob> | | |||
36 | 36 | | |||
37 | #include <QApplication> | 37 | #include <QApplication> | ||
38 | #include <QClipboard> | 38 | #include <QClipboard> | ||
39 | #include <QHelpEvent> | 39 | #include <QHelpEvent> | ||
40 | #include <QMenu> | 40 | #include <QMenu> | ||
41 | #include <QMessageBox> | ||||
41 | #include <QStackedWidget> | 42 | #include <QStackedWidget> | ||
42 | #include <QToolButton> | 43 | #include <QToolButton> | ||
43 | #include <QToolTip> | 44 | #include <QToolTip> | ||
44 | #include <QWhatsThis> | 45 | #include <QWhatsThis> | ||
45 | 46 | | |||
46 | //BEGIN KateViewSpace | 47 | //BEGIN KateViewSpace | ||
47 | KateViewSpace::KateViewSpace(KateViewManager *viewManager, | 48 | KateViewSpace::KateViewSpace(KateViewManager *viewManager, | ||
48 | QWidget *parent, const char *name) | 49 | QWidget *parent, const char *name) | ||
▲ Show 20 Lines • Show All 530 Lines • ▼ Show 20 Line(s) | 579 | { | |||
579 | // right now, show no context menu on empty tab bar space | 580 | // right now, show no context menu on empty tab bar space | ||
580 | if (id < 0) { | 581 | if (id < 0) { | ||
581 | return; | 582 | return; | ||
582 | } | 583 | } | ||
583 | 584 | | |||
584 | KTextEditor::Document *doc = m_docToTabId.key(id); | 585 | KTextEditor::Document *doc = m_docToTabId.key(id); | ||
585 | Q_ASSERT(doc); | 586 | Q_ASSERT(doc); | ||
586 | 587 | | |||
588 | auto addActionFromCollection = [this](QMenu* menu, const char* action_name) { | ||||
589 | QAction* action = m_viewManager->mainWindow()->action(action_name); | ||||
590 | return menu->addAction(action->icon(), action->text()); | ||||
591 | }; | ||||
592 | | ||||
587 | QMenu menu(this); | 593 | QMenu menu(this); | ||
588 | QAction *aCloseTab = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close")), i18n("&Close Document")); | 594 | QAction *aCloseTab = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close")), i18n("&Close Document")); | ||
589 | QAction *aCloseOthers = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close-other")), i18n("Close Other &Documents")); | 595 | QAction *aCloseOthers = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close-other")), i18n("Close Other &Documents")); | ||
590 | menu.addSeparator(); | 596 | menu.addSeparator(); | ||
591 | QAction *aCopyPath = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy File &Path")); | 597 | QAction *aCopyPath = addActionFromCollection(&menu, "file_copy_filepath"); | ||
592 | QAction *aOpenFolder = menu.addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("&Open Containing Folder")); | 598 | QAction *aOpenFolder = addActionFromCollection(&menu, "file_open_containing_folder"); | ||
599 | QAction *aFileProperties = addActionFromCollection(&menu, "file_properties"); | ||||
600 | menu.addSeparator(); | ||||
601 | QAction *aRenameFile = addActionFromCollection(&menu, "file_rename"); | ||||
602 | QAction *aDeleteFile = addActionFromCollection(&menu, "file_delete"); | ||||
603 | menu.addSeparator(); | ||||
604 | QMenu *mCompareWithActive = new QMenu(i18n("Compare with active document"), &menu); | ||||
605 | mCompareWithActive->setIcon(QIcon::fromTheme(QStringLiteral("kompare"))); | ||||
606 | menu.addMenu(mCompareWithActive); | ||||
593 | 607 | | |||
594 | if (KateApp::self()->documentManager()->documentList().count() < 2) { | 608 | if (KateApp::self()->documentManager()->documentList().count() < 2) { | ||
595 | aCloseOthers->setEnabled(false); | 609 | aCloseOthers->setEnabled(false); | ||
596 | } | 610 | } | ||
611 | | ||||
597 | if (doc->url().isEmpty()) { | 612 | if (doc->url().isEmpty()) { | ||
598 | aCopyPath->setEnabled(false); | 613 | aCopyPath->setEnabled(false); | ||
599 | aOpenFolder->setEnabled(false); | 614 | aOpenFolder->setEnabled(false); | ||
615 | aRenameFile->setEnabled(false); | ||||
616 | aDeleteFile->setEnabled(false); | ||||
617 | aFileProperties->setEnabled(false); | ||||
618 | mCompareWithActive->setEnabled(false); | ||||
619 | } | ||||
620 | | ||||
621 | auto activeDocument = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView()->document(); // used for mCompareWithActive which is used with another tab which is not active | ||||
622 | // both documents must have urls and must not be the same to have the compare feature enabled | ||||
623 | if (activeDocument->url().isEmpty() || activeDocument == doc) { | ||||
624 | mCompareWithActive->setEnabled(false); | ||||
625 | } | ||||
626 | | ||||
627 | if (mCompareWithActive->isEnabled()) { | ||||
628 | for (auto&& diffTool : KateFileActions::supportedDiffTools()) { | ||||
629 | QAction *compareAction = mCompareWithActive->addAction(diffTool); | ||||
630 | compareAction->setData(diffTool); | ||||
631 | } | ||||
600 | } | 632 | } | ||
601 | 633 | | |||
602 | QAction *choice = menu.exec(globalPos); | 634 | QAction *choice = menu.exec(globalPos); | ||
603 | 635 | | |||
636 | if (!choice) { | ||||
637 | return; | ||||
638 | } | ||||
639 | | ||||
604 | if (choice == aCloseTab) { | 640 | if (choice == aCloseTab) { | ||
605 | closeTabRequest(id); | 641 | closeTabRequest(id); | ||
606 | } else if (choice == aCloseOthers) { | 642 | } else if (choice == aCloseOthers) { | ||
607 | KateApp::self()->documentManager()->closeOtherDocuments(doc); | 643 | KateApp::self()->documentManager()->closeOtherDocuments(doc); | ||
608 | } else if (choice == aCopyPath) { | 644 | } else if (choice == aCopyPath) { | ||
609 | QApplication::clipboard()->setText(doc->url().toDisplayString(QUrl::PreferLocalFile)); | 645 | KateFileActions::copyFilePathToClipboard(doc); | ||
610 | } else if (choice == aOpenFolder) { | 646 | } else if (choice == aOpenFolder) { | ||
611 | KIO::highlightInFileManager({doc->url()}); | 647 | KateFileActions::openContainingFolder(doc); | ||
648 | } else if (choice == aFileProperties) { | ||||
649 | KateFileActions::openFilePropertiesDialog(doc); | ||||
650 | } else if (choice == aRenameFile) { | ||||
651 | KateFileActions::renameDocumentFile(this, doc); | ||||
652 | } else if (choice == aDeleteFile) { | ||||
653 | KateFileActions::deleteDocumentFile(this, doc); | ||||
654 | } else if (choice->parent() == mCompareWithActive) { | ||||
655 | QString actionData = choice->data().toString(); // name of the executable of the diff program | ||||
656 | if (!KateFileActions::compareWithExternalProgram(activeDocument, doc, actionData)) { | ||||
657 | QMessageBox::information(this, i18n("Could not start program"), | ||||
658 | i18n("The selected program could not be started. Maybe it is not installed."), | ||||
659 | QMessageBox::StandardButton::Ok); | ||||
660 | } | ||||
612 | } | 661 | } | ||
613 | } | 662 | } | ||
614 | 663 | | |||
615 | void KateViewSpace::saveConfig(KConfigBase *config, int myIndex , const QString &viewConfGrp) | 664 | void KateViewSpace::saveConfig(KConfigBase *config, int myIndex , const QString &viewConfGrp) | ||
616 | { | 665 | { | ||
617 | // qCDebug(LOG_KATE)<<"KateViewSpace::saveConfig("<<myIndex<<", "<<viewConfGrp<<") - currentView: "<<currentView()<<")"; | 666 | // qCDebug(LOG_KATE)<<"KateViewSpace::saveConfig("<<myIndex<<", "<<viewConfGrp<<") - currentView: "<<currentView()<<")"; | ||
618 | QString groupname = QString(viewConfGrp + QStringLiteral("-ViewSpace %1")).arg(myIndex); | 667 | QString groupname = QString(viewConfGrp + QStringLiteral("-ViewSpace %1")).arg(myIndex); | ||
619 | 668 | | |||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |