Commit 0121bc03 authored by Eric Armbruster's avatar Eric Armbruster 🍁 Committed by Christoph Cullmann
Browse files

filetree: show only relevant actions in context menu

parent 2985f58d
Pipeline #237143 passed with stage
in 10 minutes and 31 seconds
......@@ -382,51 +382,57 @@ void KateFileTree::contextMenuEvent(QContextMenuEvent *event)
m_customSorting->setChecked(sortRole == CustomSorting);
KTextEditor::Document *doc = docFromIndex(m_indexContextMenu);
const bool isFile = (nullptr != doc);
QMenu menu;
if (isFile) {
QMenu *openWithMenu = menu.addMenu(i18nc("@action:inmenu", "Open With"));
openWithMenu->setIcon(QIcon::fromTheme(QStringLiteral("system-run")));
connect(openWithMenu, &QMenu::aboutToShow, this, [this, openWithMenu]() {
slotFixOpenWithMenu(openWithMenu);
});
connect(openWithMenu, &QMenu::triggered, this, &KateFileTree::slotOpenWithMenuAction);
bool isDir = m_proxyModel->isDir(m_indexContextMenu);
bool isWidgetDir = m_proxyModel->isWidgetDir(m_indexContextMenu);
bool isWidget = m_indexContextMenu.data(KateFileTreeModel::WidgetRole).value<QWidget *>() != nullptr;
menu.addSeparator();
menu.addAction(m_filelistCopyFilename);
menu.addAction(m_filelistRenameFile);
menu.addAction(m_filelistDeleteDocument);
menu.addAction(m_filelistReloadDocument);
if (doc->url().isValid() && doc->url().isLocalFile()) {
auto a = menu.addAction(i18n("Show File Git History"));
connect(a, &QAction::triggered, this, [doc] {
auto url = doc->url();
if (url.isValid() && url.isLocalFile()) {
FileHistory::showFileHistory(url.toLocalFile());
}
QMenu menu;
if (doc) {
if (doc->url().isValid()) {
QMenu *openWithMenu = menu.addMenu(i18nc("@action:inmenu", "Open With"));
openWithMenu->setIcon(QIcon::fromTheme(QStringLiteral("system-run")));
connect(openWithMenu, &QMenu::aboutToShow, this, [this, openWithMenu]() {
slotFixOpenWithMenu(openWithMenu);
});
}
connect(openWithMenu, &QMenu::triggered, this, &KateFileTree::slotOpenWithMenuAction);
menu.addSeparator();
menu.addAction(m_filelistCopyFilename);
menu.addAction(m_filelistRenameFile);
menu.addAction(m_filelistDeleteDocument);
menu.addAction(m_filelistReloadDocument);
if (doc->url().isLocalFile()) {
auto a = menu.addAction(i18n("Show File Git History"));
connect(a, &QAction::triggered, this, [doc] {
auto url = doc->url();
if (url.isValid() && url.isLocalFile()) {
FileHistory::showFileHistory(url.toLocalFile());
}
});
}
menu.addSeparator();
menu.addAction(m_filelistOpenContainingFolder);
menu.addSeparator();
menu.addAction(m_filelistOpenContainingFolder);
menu.addSeparator();
menu.addAction(m_filelistCloseDocument);
menu.addAction(m_filelistCloseOtherDocument);
menu.addSeparator();
menu.addAction(m_filelistCloseDocument);
menu.addAction(m_filelistCloseOtherDocument);
menu.addSeparator();
menu.addAction(m_filelistPrintDocument);
menu.addAction(m_filelistPrintDocumentPreview);
const bool hasFileName = doc->url().isValid();
m_filelistOpenContainingFolder->setEnabled(hasFileName);
m_filelistCopyFilename->setEnabled(hasFileName);
m_filelistRenameFile->setEnabled(hasFileName);
m_filelistDeleteDocument->setEnabled(hasFileName);
} else {
menu.addAction(m_filelistReloadDocument);
menu.addSeparator();
menu.addAction(m_filelistPrintDocument);
menu.addAction(m_filelistPrintDocumentPreview);
} else {
// untitled documents
menu.addAction(m_filelistCloseDocument);
menu.addSeparator();
}
} else if (isDir || isWidgetDir || isWidget) {
if (isDir) {
menu.addAction(m_filelistReloadDocument);
}
menu.addSeparator();
menu.addAction(m_filelistCloseDocument);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment