mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
Refactoring to reduce size of openItemContextMenu and add the ContextType TimelineOrSearchContext
Reviewers: #dolphin, elvisangelaccio Reviewed By: #dolphin, elvisangelaccio Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D25615
This commit is contained in:
parent
89d53b98c7
commit
8b0c12a59c
|
@ -94,8 +94,13 @@ void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions)
|
||||||
DolphinContextMenu::Command DolphinContextMenu::open()
|
DolphinContextMenu::Command DolphinContextMenu::open()
|
||||||
{
|
{
|
||||||
// get the context information
|
// get the context information
|
||||||
if (m_baseUrl.scheme() == QLatin1String("trash")) {
|
const auto scheme = m_baseUrl.scheme();
|
||||||
|
if (scheme == QLatin1String("trash")) {
|
||||||
m_context |= TrashContext;
|
m_context |= TrashContext;
|
||||||
|
} else if (scheme == QLatin1String("search")) {
|
||||||
|
m_context |= SearchContext;
|
||||||
|
} else if (scheme == QLatin1String("timeline")) {
|
||||||
|
m_context |= TimelineContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) {
|
if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) {
|
||||||
|
@ -183,6 +188,36 @@ void DolphinContextMenu::openTrashItemContextMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinContextMenu::addDirectoryItemContextMenu(KFileItemActions &fileItemActions)
|
||||||
|
{
|
||||||
|
// insert 'Open in new window' and 'Open in new tab' entries
|
||||||
|
|
||||||
|
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
|
||||||
|
|
||||||
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window")));
|
||||||
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab")));
|
||||||
|
|
||||||
|
// Insert 'Open With' entries
|
||||||
|
addOpenWithActions(fileItemActions);
|
||||||
|
|
||||||
|
// set up 'Create New' menu
|
||||||
|
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow);
|
||||||
|
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
|
||||||
|
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
|
||||||
|
newFileMenu->checkUpToDate();
|
||||||
|
newFileMenu->setPopupFiles(m_fileInfo.url());
|
||||||
|
newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
|
||||||
|
connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
|
||||||
|
connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
|
||||||
|
|
||||||
|
QMenu* menu = newFileMenu->menu();
|
||||||
|
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
|
||||||
|
menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
|
||||||
|
addMenu(menu);
|
||||||
|
|
||||||
|
addSeparator();
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinContextMenu::openItemContextMenu()
|
void DolphinContextMenu::openItemContextMenu()
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_fileInfo.isNull());
|
Q_ASSERT(!m_fileInfo.isNull());
|
||||||
|
@ -197,31 +232,10 @@ void DolphinContextMenu::openItemContextMenu()
|
||||||
fileItemActions.setItemListProperties(selectedItemsProps);
|
fileItemActions.setItemListProperties(selectedItemsProps);
|
||||||
|
|
||||||
if (m_selectedItems.count() == 1) {
|
if (m_selectedItems.count() == 1) {
|
||||||
|
// single files
|
||||||
if (m_fileInfo.isDir()) {
|
if (m_fileInfo.isDir()) {
|
||||||
// insert 'Open in new window' and 'Open in new tab' entries
|
addDirectoryItemContextMenu(fileItemActions);
|
||||||
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window")));
|
} else if (m_context & TimelineContext || m_context & SearchContext) {
|
||||||
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab")));
|
|
||||||
|
|
||||||
// Insert 'Open With' entries
|
|
||||||
addOpenWithActions(fileItemActions);
|
|
||||||
|
|
||||||
// set up 'Create New' menu
|
|
||||||
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow);
|
|
||||||
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
|
|
||||||
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
|
|
||||||
newFileMenu->checkUpToDate();
|
|
||||||
newFileMenu->setPopupFiles(m_fileInfo.url());
|
|
||||||
newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
|
|
||||||
connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
|
|
||||||
connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
|
|
||||||
|
|
||||||
QMenu* menu = newFileMenu->menu();
|
|
||||||
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
|
|
||||||
menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
|
|
||||||
addMenu(menu);
|
|
||||||
|
|
||||||
addSeparator();
|
|
||||||
} else if (m_baseUrl.scheme().contains(QLatin1String("search")) || m_baseUrl.scheme().contains(QLatin1String("timeline"))) {
|
|
||||||
addOpenWithActions(fileItemActions);
|
addOpenWithActions(fileItemActions);
|
||||||
|
|
||||||
openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")),
|
openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")),
|
||||||
|
@ -252,8 +266,9 @@ void DolphinContextMenu::openItemContextMenu()
|
||||||
addSeparator();
|
addSeparator();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// multiple files
|
||||||
bool selectionHasOnlyDirs = true;
|
bool selectionHasOnlyDirs = true;
|
||||||
foreach (const KFileItem& item, m_selectedItems) {
|
for (const auto &item : qAsConst(m_selectedItems)) {
|
||||||
const QUrl& url = DolphinView::openItemAsFolderUrl(item);
|
const QUrl& url = DolphinView::openItemAsFolderUrl(item);
|
||||||
if (url.isEmpty()) {
|
if (url.isEmpty()) {
|
||||||
selectionHasOnlyDirs = false;
|
selectionHasOnlyDirs = false;
|
||||||
|
|
|
@ -146,7 +146,9 @@ private:
|
||||||
{
|
{
|
||||||
NoContext = 0,
|
NoContext = 0,
|
||||||
ItemContext = 1,
|
ItemContext = 1,
|
||||||
TrashContext = 2
|
TrashContext = 2,
|
||||||
|
TimelineContext = 4,
|
||||||
|
SearchContext = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
QPoint m_pos;
|
QPoint m_pos;
|
||||||
|
@ -167,6 +169,8 @@ private:
|
||||||
Command m_command;
|
Command m_command;
|
||||||
|
|
||||||
DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
|
DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
|
||||||
|
void addDirectoryItemContextMenu(KFileItemActions &fileItemActions);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue