Changeset View
Changeset View
Standalone View
Standalone View
src/dolphincontextmenu.cpp
Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Line(s) | 186 | { | |||
---|---|---|---|---|---|
187 | Q_ASSERT(!m_fileInfo.isNull()); | 187 | Q_ASSERT(!m_fileInfo.isNull()); | ||
188 | 188 | | |||
189 | QAction* openParentAction = nullptr; | 189 | QAction* openParentAction = nullptr; | ||
190 | QAction* openParentInNewWindowAction = nullptr; | 190 | QAction* openParentInNewWindowAction = nullptr; | ||
191 | QAction* openParentInNewTabAction = nullptr; | 191 | QAction* openParentInNewTabAction = nullptr; | ||
192 | QAction* addToPlacesAction = nullptr; | 192 | QAction* addToPlacesAction = nullptr; | ||
193 | const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); | 193 | const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); | ||
194 | 194 | | |||
195 | KFileItemActions fileItemActions; | ||||
196 | fileItemActions.setParentWidget(m_mainWindow); | ||||
197 | fileItemActions.setItemListProperties(selectedItemsProps); | ||||
198 | | ||||
195 | if (m_selectedItems.count() == 1) { | 199 | if (m_selectedItems.count() == 1) { | ||
196 | if (m_fileInfo.isLink()) { | | |||
197 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_target"))); | | |||
198 | addSeparator(); | | |||
199 | } | | |||
200 | if (m_fileInfo.isDir()) { | 200 | if (m_fileInfo.isDir()) { | ||
201 | // insert 'Open in new window' and 'Open in new tab' entries | ||||
202 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); | ||||
203 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); | ||||
204 | | ||||
205 | // Insert 'Open With' entries | ||||
206 | addOpenWithActions(fileItemActions); | ||||
207 | | ||||
208 | // insert 'Add to Places' entry | ||||
209 | if (!placeExists(m_fileInfo.url())) { | ||||
210 | addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), | ||||
211 | i18nc("@action:inmenu Add selected folder to places", | ||||
212 | "Add to Places")); | ||||
213 | } | ||||
214 | | ||||
215 | addSeparator(); | ||||
216 | | ||||
201 | // setup 'Create New' menu | 217 | // set up 'Create New' menu | ||
202 | DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); | 218 | DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); | ||
elvisangelaccio: In the folder case I'd put "Open With" after these actions, without a separator.
On Windows… | |||||
203 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | 219 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | ||
204 | newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); | 220 | newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); | ||
205 | newFileMenu->checkUpToDate(); | 221 | newFileMenu->checkUpToDate(); | ||
206 | newFileMenu->setPopupFiles(m_fileInfo.url()); | 222 | newFileMenu->setPopupFiles(m_fileInfo.url()); | ||
207 | newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); | 223 | newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); | ||
208 | connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); | 224 | connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); | ||
209 | connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); | 225 | connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); | ||
210 | 226 | | |||
211 | QMenu* menu = newFileMenu->menu(); | 227 | QMenu* menu = newFileMenu->menu(); | ||
212 | menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); | 228 | menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); | ||
213 | menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); | 229 | menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); | ||
214 | addMenu(menu); | 230 | addMenu(menu); | ||
215 | addSeparator(); | | |||
216 | | ||||
217 | // insert 'Open in new window' and 'Open in new tab' entries | | |||
218 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); | | |||
219 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); | | |||
220 | | ||||
221 | // insert 'Add to Places' entry | | |||
222 | if (!placeExists(m_fileInfo.url())) { | | |||
223 | addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), | | |||
224 | i18nc("@action:inmenu Add selected folder to places", | | |||
225 | "Add to Places")); | | |||
226 | } | | |||
227 | 231 | | |||
228 | addSeparator(); | 232 | addSeparator(); | ||
229 | } else if (m_baseUrl.scheme().contains(QStringLiteral("search")) || m_baseUrl.scheme().contains(QStringLiteral("timeline"))) { | 233 | } else if (m_baseUrl.scheme().contains(QStringLiteral("search")) || m_baseUrl.scheme().contains(QStringLiteral("timeline"))) { | ||
230 | openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), | 234 | openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), | ||
231 | i18nc("@action:inmenu", | 235 | i18nc("@action:inmenu", | ||
232 | "Open Path"), | 236 | "Open Path"), | ||
233 | this); | 237 | this); | ||
234 | addAction(openParentAction); | 238 | addAction(openParentAction); | ||
235 | 239 | | |||
236 | openParentInNewWindowAction = new QAction(QIcon::fromTheme(QStringLiteral("window-new")), | 240 | openParentInNewWindowAction = new QAction(QIcon::fromTheme(QStringLiteral("window-new")), | ||
237 | i18nc("@action:inmenu", | 241 | i18nc("@action:inmenu", | ||
238 | "Open Path in New Window"), | 242 | "Open Path in New Window"), | ||
239 | this); | 243 | this); | ||
240 | addAction(openParentInNewWindowAction); | 244 | addAction(openParentInNewWindowAction); | ||
241 | 245 | | |||
242 | openParentInNewTabAction = new QAction(QIcon::fromTheme(QStringLiteral("tab-new")), | 246 | openParentInNewTabAction = new QAction(QIcon::fromTheme(QStringLiteral("tab-new")), | ||
243 | i18nc("@action:inmenu", | 247 | i18nc("@action:inmenu", | ||
244 | "Open Path in New Tab"), | 248 | "Open Path in New Tab"), | ||
245 | this); | 249 | this); | ||
246 | addAction(openParentInNewTabAction); | 250 | addAction(openParentInNewTabAction); | ||
247 | 251 | | |||
248 | addSeparator(); | 252 | addSeparator(); | ||
249 | } else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) { | 253 | } else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) { | ||
254 | // Insert 'Open With" entries | ||||
255 | addOpenWithActions(fileItemActions); | ||||
256 | | ||||
250 | // insert 'Open in new window' and 'Open in new tab' entries | 257 | // insert 'Open in new window' and 'Open in new tab' entries | ||
251 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); | 258 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); | ||
252 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); | 259 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); | ||
253 | 260 | | |||
254 | addSeparator(); | 261 | addSeparator(); | ||
262 | } else { | ||||
263 | // Insert 'Open With" entries | ||||
264 | addOpenWithActions(fileItemActions); | ||||
265 | } | ||||
266 | if (m_fileInfo.isLink()) { | ||||
267 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_target"))); | ||||
268 | addSeparator(); | ||||
255 | } | 269 | } | ||
256 | } else { | 270 | } else { | ||
257 | bool selectionHasOnlyDirs = true; | 271 | bool selectionHasOnlyDirs = true; | ||
258 | foreach (const KFileItem& item, m_selectedItems) { | 272 | foreach (const KFileItem& item, m_selectedItems) { | ||
259 | const QUrl& url = DolphinView::openItemAsFolderUrl(item); | 273 | const QUrl& url = DolphinView::openItemAsFolderUrl(item); | ||
260 | if (url.isEmpty()) { | 274 | if (url.isEmpty()) { | ||
261 | selectionHasOnlyDirs = false; | 275 | selectionHasOnlyDirs = false; | ||
262 | break; | 276 | break; | ||
263 | } | 277 | } | ||
264 | } | 278 | } | ||
265 | 279 | | |||
266 | if (selectionHasOnlyDirs) { | 280 | if (selectionHasOnlyDirs) { | ||
267 | // insert 'Open in new tab' entry | 281 | // insert 'Open in new tab' entry | ||
268 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tabs"))); | 282 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tabs"))); | ||
269 | addSeparator(); | | |||
270 | } | 283 | } | ||
284 | // Insert 'Open With" entries | ||||
285 | addOpenWithActions(fileItemActions); | ||||
271 | } | 286 | } | ||
272 | 287 | | |||
273 | insertDefaultItemActions(selectedItemsProps); | 288 | insertDefaultItemActions(selectedItemsProps); | ||
274 | 289 | | |||
275 | addSeparator(); | 290 | addSeparator(); | ||
276 | 291 | | |||
277 | KFileItemActions fileItemActions; | 292 | fileItemActions.addServiceActionsTo(this); | ||
elvisangelaccio: This is now already called at line 196. | |||||
278 | fileItemActions.setItemListProperties(selectedItemsProps); | | |||
279 | addServiceActions(fileItemActions); | | |||
280 | | ||||
281 | fileItemActions.addPluginActionsTo(this); | 293 | fileItemActions.addPluginActionsTo(this); | ||
282 | 294 | | |||
283 | addVersionControlPluginActions(); | 295 | addVersionControlPluginActions(); | ||
284 | 296 | | |||
285 | // insert 'Copy To' and 'Move To' sub menus | 297 | // insert 'Copy To' and 'Move To' sub menus | ||
286 | if (GeneralSettings::showCopyMoveMenu()) { | 298 | if (GeneralSettings::showCopyMoveMenu()) { | ||
287 | m_copyToMenu.setUrls(m_selectedItems.urlList()); | 299 | m_copyToMenu.setUrls(m_selectedItems.urlList()); | ||
288 | m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting()); | 300 | m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting()); | ||
Show All 30 Lines | 329 | { | |||
319 | KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu(); | 331 | KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu(); | ||
320 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | 332 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | ||
321 | newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); | 333 | newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); | ||
322 | newFileMenu->checkUpToDate(); | 334 | newFileMenu->checkUpToDate(); | ||
323 | newFileMenu->setPopupFiles(m_baseUrl); | 335 | newFileMenu->setPopupFiles(m_baseUrl); | ||
324 | addMenu(newFileMenu->menu()); | 336 | addMenu(newFileMenu->menu()); | ||
325 | addSeparator(); | 337 | addSeparator(); | ||
326 | 338 | | |||
339 | // Insert 'Open With' entries | ||||
340 | const KFileItemListProperties baseUrlProperties(KFileItemList() << baseFileItem()); | ||||
341 | KFileItemActions fileItemActions; | ||||
342 | fileItemActions.setParentWidget(m_mainWindow); | ||||
343 | fileItemActions.setItemListProperties(baseUrlProperties); | ||||
344 | addOpenWithActions(fileItemActions); | ||||
345 | | ||||
327 | // Insert 'New Window' and 'New Tab' entries. Don't use "open_in_new_window" and | 346 | // Insert 'New Window' and 'New Tab' entries. Don't use "open_in_new_window" and | ||
328 | // "open_in_new_tab" here, as the current selection should get ignored. | 347 | // "open_in_new_tab" here, as the current selection should get ignored. | ||
329 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_window"))); | 348 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_window"))); | ||
330 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_tab"))); | 349 | addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_tab"))); | ||
331 | 350 | | |||
332 | // Insert 'Add to Places' entry if exactly one item is selected | 351 | // Insert 'Add to Places' entry if exactly one item is selected | ||
333 | QAction* addToPlacesAction = nullptr; | 352 | QAction* addToPlacesAction = nullptr; | ||
334 | if (!placeExists(m_mainWindow->activeViewContainer()->url())) { | 353 | if (!placeExists(m_mainWindow->activeViewContainer()->url())) { | ||
335 | addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), | 354 | addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), | ||
336 | i18nc("@action:inmenu Add current folder to places", "Add to Places")); | 355 | i18nc("@action:inmenu Add current folder to places", "Add to Places")); | ||
337 | } | 356 | } | ||
338 | 357 | | |||
339 | addSeparator(); | 358 | addSeparator(); | ||
340 | 359 | | |||
341 | QAction* pasteAction = createPasteAction(); | 360 | QAction* pasteAction = createPasteAction(); | ||
342 | addAction(pasteAction); | 361 | addAction(pasteAction); | ||
343 | addSeparator(); | 362 | addSeparator(); | ||
344 | 363 | | |||
345 | // Insert service actions | 364 | // Insert service actions | ||
346 | const KFileItemListProperties baseUrlProperties(KFileItemList() << baseFileItem()); | 365 | fileItemActions.addServiceActionsTo(this); | ||
347 | KFileItemActions fileItemActions; | | |||
348 | fileItemActions.setItemListProperties(baseUrlProperties); | | |||
349 | addServiceActions(fileItemActions); | | |||
350 | | ||||
351 | fileItemActions.addPluginActionsTo(this); | 366 | fileItemActions.addPluginActionsTo(this); | ||
352 | 367 | | |||
353 | addVersionControlPluginActions(); | 368 | addVersionControlPluginActions(); | ||
354 | 369 | | |||
355 | addCustomActions(); | 370 | addCustomActions(); | ||
356 | 371 | | |||
357 | QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties")); | 372 | QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties")); | ||
358 | addAction(propertiesAction); | 373 | addAction(propertiesAction); | ||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | |||||
464 | KFileItem DolphinContextMenu::baseFileItem() | 479 | KFileItem DolphinContextMenu::baseFileItem() | ||
465 | { | 480 | { | ||
466 | if (!m_baseFileItem) { | 481 | if (!m_baseFileItem) { | ||
467 | m_baseFileItem = new KFileItem(m_baseUrl); | 482 | m_baseFileItem = new KFileItem(m_baseUrl); | ||
468 | } | 483 | } | ||
469 | return *m_baseFileItem; | 484 | return *m_baseFileItem; | ||
470 | } | 485 | } | ||
471 | 486 | | |||
472 | void DolphinContextMenu::addServiceActions(KFileItemActions& fileItemActions) | 487 | void DolphinContextMenu::addOpenWithActions(KFileItemActions& fileItemActions) | ||
473 | { | 488 | { | ||
474 | fileItemActions.setParentWidget(m_mainWindow); | | |||
475 | | ||||
476 | // insert 'Open With...' action or sub menu | 489 | // insert 'Open With...' action or sub menu | ||
477 | fileItemActions.addOpenWithActionsTo(this, QStringLiteral("DesktopEntryName != '%1'").arg(qApp->desktopFileName())); | 490 | fileItemActions.addOpenWithActionsTo(this, QStringLiteral("DesktopEntryName != '%1'").arg(qApp->desktopFileName())); | ||
This refactoring removes the "Open With" submenu from the viewport context menu. elvisangelaccio: This refactoring removes the "Open With" submenu from the viewport context menu. | |||||
478 | | ||||
479 | // insert 'Actions' sub menu | | |||
480 | fileItemActions.addServiceActionsTo(this); | | |||
481 | } | 491 | } | ||
482 | 492 | | |||
483 | void DolphinContextMenu::addVersionControlPluginActions() | 493 | void DolphinContextMenu::addVersionControlPluginActions() | ||
484 | { | 494 | { | ||
485 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | 495 | const DolphinView* view = m_mainWindow->activeViewContainer()->view(); | ||
486 | const QList<QAction*> versionControlActions = view->versionControlActions(m_selectedItems); | 496 | const QList<QAction*> versionControlActions = view->versionControlActions(m_selectedItems); | ||
487 | if (!versionControlActions.isEmpty()) { | 497 | if (!versionControlActions.isEmpty()) { | ||
488 | addActions(versionControlActions); | 498 | addActions(versionControlActions); | ||
489 | addSeparator(); | 499 | addSeparator(); | ||
The addServiceActions() function doesn't make sense anymore. We can move the fileItemActions.setParentWidget(m_mainWindow) call after we define the fileItemActions object, so we can even remove this line from the new addOpenWithActions() function. Then we can just call fileItemActions.addServiceActionsTo(this) instead of calling addServiceActions(). elvisangelaccio: The `addServiceActions()` function doesn't make sense anymore. We can move the `fileItemActions. | |||||
490 | } | 500 | } | ||
491 | } | 501 | } | ||
492 | 502 | | |||
493 | void DolphinContextMenu::addCustomActions() | 503 | void DolphinContextMenu::addCustomActions() | ||
494 | { | 504 | { | ||
495 | addActions(m_customActions); | 505 | addActions(m_customActions); | ||
496 | } | 506 | } | ||
497 | 507 | |
In the folder case I'd put "Open With" after these actions, without a separator.
On Windows "Open With" is always at the end of the first section, before the first separator.