Changeset View
Changeset View
Standalone View
Standalone View
src/dolphincontextmenu.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 60 | DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, | |||
---|---|---|---|---|---|
64 | QMenu(parent), | 64 | QMenu(parent), | ||
65 | m_pos(pos), | 65 | m_pos(pos), | ||
66 | m_mainWindow(parent), | 66 | m_mainWindow(parent), | ||
67 | m_fileInfo(fileInfo), | 67 | m_fileInfo(fileInfo), | ||
68 | m_baseUrl(baseUrl), | 68 | m_baseUrl(baseUrl), | ||
69 | m_baseFileItem(nullptr), | 69 | m_baseFileItem(nullptr), | ||
70 | m_selectedItems(), | 70 | m_selectedItems(), | ||
71 | m_selectedItemsProperties(nullptr), | 71 | m_selectedItemsProperties(nullptr), | ||
72 | m_context(NoContext), | 72 | m_context(static_cast<int>(ContextType::NoContext)), | ||
elvisangelaccio: If we change the type of `m_context`, we don't need the `static_cast`. | |||||
73 | m_copyToMenu(parent), | 73 | m_copyToMenu(parent), | ||
74 | m_customActions(), | 74 | m_customActions(), | ||
75 | m_command(None), | 75 | m_command(Command::None), | ||
76 | m_removeAction(nullptr) | 76 | m_removeAction(nullptr) | ||
77 | { | 77 | { | ||
78 | // The context menu either accesses the URLs of the selected items | 78 | // The context menu either accesses the URLs of the selected items | ||
79 | // or the items itself. To increase the performance both lists are cached. | 79 | // or the items itself. To increase the performance both lists are cached. | ||
80 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | 80 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | ||
81 | m_selectedItems = view->selectedItems(); | 81 | m_selectedItems = view->selectedItems(); | ||
82 | } | 82 | } | ||
83 | 83 | | |||
84 | DolphinContextMenu::~DolphinContextMenu() | 84 | DolphinContextMenu::~DolphinContextMenu() | ||
85 | { | 85 | { | ||
86 | delete m_selectedItemsProperties; | 86 | delete m_selectedItemsProperties; | ||
87 | m_selectedItemsProperties = nullptr; | 87 | m_selectedItemsProperties = nullptr; | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions) | 90 | void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions) | ||
91 | { | 91 | { | ||
92 | m_customActions = actions; | 92 | m_customActions = actions; | ||
93 | } | 93 | } | ||
94 | 94 | | |||
95 | DolphinContextMenu::Command DolphinContextMenu::open() | 95 | DolphinContextMenu::Command DolphinContextMenu::open() | ||
96 | { | 96 | { | ||
97 | // get the context information | 97 | // get the context information | ||
98 | if (m_baseUrl.scheme() == QLatin1String("trash")) { | 98 | if (m_baseUrl.scheme() == QLatin1String("trash")) { | ||
99 | m_context |= TrashContext; | 99 | m_context |= static_cast<int>(ContextType::Trash); | ||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) { | 102 | if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) { | ||
103 | m_context |= ItemContext; | 103 | m_context |= static_cast<int>(ContextType::Item); | ||
104 | // TODO: handle other use cases like devices + desktop files | 104 | // TODO: handle other use cases like devices + desktop files | ||
105 | } | 105 | } | ||
106 | 106 | | |||
107 | // open the corresponding popup for the context | 107 | // open the corresponding popup for the context | ||
108 | if (m_context & TrashContext) { | 108 | if (m_context & static_cast<int>(ContextType::Trash)) { | ||
109 | if (m_context & ItemContext) { | 109 | if (m_context & static_cast<int>(ContextType::Item)) { | ||
110 | openTrashItemContextMenu(); | 110 | openTrashItemContextMenu(); | ||
111 | } else { | 111 | } else { | ||
112 | openTrashContextMenu(); | 112 | openTrashContextMenu(); | ||
113 | } | 113 | } | ||
114 | } else if (m_context & ItemContext) { | 114 | } else if (m_context & static_cast<int>(ContextType::Item)) { | ||
115 | openItemContextMenu(); | 115 | openItemContextMenu(); | ||
116 | } else { | 116 | } else { | ||
117 | Q_ASSERT(m_context == NoContext); | 117 | Q_ASSERT(ContextType(m_context) == ContextType::NoContext); | ||
118 | openViewportContextMenu(); | 118 | openViewportContextMenu(); | ||
119 | } | 119 | } | ||
120 | 120 | | |||
121 | return m_command; | 121 | return m_command; | ||
122 | } | 122 | } | ||
123 | 123 | | |||
124 | void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) | 124 | void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) | ||
125 | { | 125 | { | ||
126 | if (m_removeAction && ev->key() == Qt::Key_Shift) { | 126 | if (m_removeAction && ev->key() == Qt::Key_Shift) { | ||
127 | m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed); | 127 | m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed); | ||
128 | } | 128 | } | ||
129 | QMenu::keyPressEvent(ev); | 129 | QMenu::keyPressEvent(ev); | ||
130 | } | 130 | } | ||
131 | 131 | | |||
132 | void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) | 132 | void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) | ||
133 | { | 133 | { | ||
134 | if (m_removeAction && ev->key() == Qt::Key_Shift) { | 134 | if (m_removeAction && ev->key() == Qt::Key_Shift) { | ||
135 | m_removeAction->update(DolphinRemoveAction::ShiftState::Released); | 135 | m_removeAction->update(DolphinRemoveAction::ShiftState::Released); | ||
136 | } | 136 | } | ||
137 | QMenu::keyReleaseEvent(ev); | 137 | QMenu::keyReleaseEvent(ev); | ||
138 | } | 138 | } | ||
139 | 139 | | |||
140 | void DolphinContextMenu::openTrashContextMenu() | 140 | void DolphinContextMenu::openTrashContextMenu() | ||
141 | { | 141 | { | ||
142 | Q_ASSERT(m_context & TrashContext); | 142 | Q_ASSERT(m_context & static_cast<int>(ContextType::Trash)); | ||
143 | 143 | | |||
144 | QAction* emptyTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"), this); | 144 | QAction* emptyTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"), this); | ||
145 | KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); | 145 | KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); | ||
146 | emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); | 146 | emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); | ||
147 | addAction(emptyTrashAction); | 147 | addAction(emptyTrashAction); | ||
148 | 148 | | |||
149 | addCustomActions(); | 149 | addCustomActions(); | ||
150 | 150 | | |||
Show All 10 Lines | 159 | if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { | |||
161 | KJobWidgets::setWindow(job, m_mainWindow); | 161 | KJobWidgets::setWindow(job, m_mainWindow); | ||
162 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | 162 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | ||
163 | } | 163 | } | ||
164 | } | 164 | } | ||
165 | } | 165 | } | ||
166 | 166 | | |||
167 | void DolphinContextMenu::openTrashItemContextMenu() | 167 | void DolphinContextMenu::openTrashItemContextMenu() | ||
168 | { | 168 | { | ||
169 | Q_ASSERT(m_context & TrashContext); | 169 | Q_ASSERT(m_context & static_cast<int>(ContextType::Trash)); | ||
170 | Q_ASSERT(m_context & ItemContext); | 170 | Q_ASSERT(m_context & static_cast<int>(ContextType::Item)); | ||
171 | 171 | | |||
172 | QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow); | 172 | QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow); | ||
173 | addAction(restoreAction); | 173 | addAction(restoreAction); | ||
174 | 174 | | |||
175 | QAction* deleteAction = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)); | 175 | QAction* deleteAction = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)); | ||
176 | addAction(deleteAction); | 176 | addAction(deleteAction); | ||
177 | 177 | | |||
178 | QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties")); | 178 | QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties")); | ||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | 303 | if (activatedAction) { | |||
304 | if (activatedAction == addToPlacesAction) { | 304 | if (activatedAction == addToPlacesAction) { | ||
305 | const QUrl selectedUrl(m_fileInfo.url()); | 305 | const QUrl selectedUrl(m_fileInfo.url()); | ||
306 | if (selectedUrl.isValid()) { | 306 | if (selectedUrl.isValid()) { | ||
307 | PlacesItemModel model; | 307 | PlacesItemModel model; | ||
308 | const QString text = selectedUrl.fileName(); | 308 | const QString text = selectedUrl.fileName(); | ||
309 | model.createPlacesItem(text, selectedUrl, KIO::iconNameForUrl(selectedUrl)); | 309 | model.createPlacesItem(text, selectedUrl, KIO::iconNameForUrl(selectedUrl)); | ||
310 | } | 310 | } | ||
311 | } else if (activatedAction == openParentAction) { | 311 | } else if (activatedAction == openParentAction) { | ||
312 | m_command = OpenParentFolder; | 312 | m_command = Command::OpenParentFolder; | ||
313 | } else if (activatedAction == openParentInNewWindowAction) { | 313 | } else if (activatedAction == openParentInNewWindowAction) { | ||
314 | m_command = OpenParentFolderInNewWindow; | 314 | m_command = Command::OpenParentFolderInNewWindow; | ||
315 | } else if (activatedAction == openParentInNewTabAction) { | 315 | } else if (activatedAction == openParentInNewTabAction) { | ||
316 | m_command = OpenParentFolderInNewTab; | 316 | m_command = Command::OpenParentFolderInNewTab; | ||
317 | } | 317 | } | ||
318 | } | 318 | } | ||
319 | } | 319 | } | ||
320 | 320 | | |||
321 | void DolphinContextMenu::openViewportContextMenu() | 321 | void DolphinContextMenu::openViewportContextMenu() | ||
322 | { | 322 | { | ||
323 | // setup 'Create New' menu | 323 | // setup 'Create New' menu | ||
324 | KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu(); | 324 | KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu(); | ||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |
If we change the type of m_context, we don't need the static_cast.