Changeset View
Changeset View
Standalone View
Standalone View
krusader/Panel/panelcontextmenu.cpp
Show All 21 Lines | |||||
22 | #include "panelcontextmenu.h" | 22 | #include "panelcontextmenu.h" | ||
23 | 23 | | |||
24 | // QtGui | 24 | // QtGui | ||
25 | #include <QPixmap> | 25 | #include <QPixmap> | ||
26 | 26 | | |||
27 | #include <KCoreAddons/KProcess> | 27 | #include <KCoreAddons/KProcess> | ||
28 | #include <KI18n/KLocalizedString> | 28 | #include <KI18n/KLocalizedString> | ||
29 | #include <KIOWidgets/KRun> | 29 | #include <KIOWidgets/KRun> | ||
30 | #include <KIconThemes/KIconLoader> | | |||
31 | #include <KWidgetsAddons/KMessageBox> | 30 | #include <KWidgetsAddons/KMessageBox> | ||
32 | #include <KService/KMimeTypeTrader> | 31 | #include <KService/KMimeTypeTrader> | ||
33 | #include <KService/KToolInvocation> | 32 | #include <KService/KToolInvocation> | ||
34 | #include <KXmlGui/KActionCollection> | 33 | #include <KXmlGui/KActionCollection> | ||
35 | #include <KIOCore/KFileItemListProperties> | 34 | #include <KIOCore/KFileItemListProperties> | ||
36 | #include <KIOWidgets/KAbstractFileItemActionPlugin> | 35 | #include <KIOWidgets/KAbstractFileItemActionPlugin> | ||
37 | #include <KCoreAddons/KPluginMetaData> | 36 | #include <KCoreAddons/KPluginMetaData> | ||
38 | 37 | | |||
39 | #include "krpreviewpopup.h" | 38 | #include "krpreviewpopup.h" | ||
40 | #include "listpanel.h" | 39 | #include "listpanel.h" | ||
41 | #include "listpanelactions.h" | 40 | #include "listpanelactions.h" | ||
42 | #include "panelfunc.h" | 41 | #include "panelfunc.h" | ||
43 | #include "PanelView/krview.h" | 42 | #include "PanelView/krview.h" | ||
44 | #include "PanelView/krviewitem.h" | 43 | #include "PanelView/krviewitem.h" | ||
45 | #include "../defaults.h" | 44 | #include "../defaults.h" | ||
45 | #include "../icon.h" | ||||
46 | #include "../krservices.h" | 46 | #include "../krservices.h" | ||
47 | #include "../krslots.h" | 47 | #include "../krslots.h" | ||
48 | #include "../krusader.h" | 48 | #include "../krusader.h" | ||
49 | #include "../krusaderview.h" | 49 | #include "../krusaderview.h" | ||
50 | #include "../panelmanager.h" | 50 | #include "../panelmanager.h" | ||
51 | #include "../Archive/krarchandler.h" | 51 | #include "../Archive/krarchandler.h" | ||
52 | #include "../FileSystem/fileitem.h" | 52 | #include "../FileSystem/fileitem.h" | ||
53 | #include "../FileSystem/filesystem.h" | 53 | #include "../FileSystem/filesystem.h" | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 129 | if (!multipleSelections) { // meaningful only if one file is selected | |||
131 | panel->view->getSelectedKrViewItems(&viewItems); | 131 | panel->view->getSelectedKrViewItems(&viewItems); | ||
132 | openAct->setIcon(viewItems.first()->icon()); | 132 | openAct->setIcon(viewItems.first()->icon()); | ||
133 | openAct->setText(file->isExecutable() && !file->isDir() ? | 133 | openAct->setText(file->isExecutable() && !file->isDir() ? | ||
134 | i18n("Run") : i18n("Open")); | 134 | i18n("Run") : i18n("Open")); | ||
135 | // open in a new tab (if folder) | 135 | // open in a new tab (if folder) | ||
136 | if (file->isDir()) { | 136 | if (file->isDir()) { | ||
137 | QAction * openTab = addAction(i18n("Open in New Tab")); | 137 | QAction * openTab = addAction(i18n("Open in New Tab")); | ||
138 | openTab->setData(QVariant(OPEN_TAB_ID)); | 138 | openTab->setData(QVariant(OPEN_TAB_ID)); | ||
139 | openTab->setIcon(krLoader->loadIcon("tab-new", KIconLoader::Panel)); | 139 | openTab->setIcon(Icon("tab-new")); | ||
140 | openTab->setText(i18n("Open in New Tab")); | 140 | openTab->setText(i18n("Open in New Tab")); | ||
141 | } | 141 | } | ||
142 | // if the file can be browsed as archive... | 142 | // if the file can be browsed as archive... | ||
143 | if (!panel->func->browsableArchivePath(file->getName()).isEmpty() | 143 | if (!panel->func->browsableArchivePath(file->getName()).isEmpty() | ||
144 | // ...but user disabled archive browsing... | 144 | // ...but user disabled archive browsing... | ||
145 | && (!KConfigGroup(krConfig, "Archives") | 145 | && (!KConfigGroup(krConfig, "Archives") | ||
146 | .readEntry("ArchivesAsDirectories", _ArchivesAsDirectories) | 146 | .readEntry("ArchivesAsDirectories", _ArchivesAsDirectories) | ||
147 | // ...or the file is not a standard archive (e.g. odt, docx, etc.)... | 147 | // ...or the file is not a standard archive (e.g. odt, docx, etc.)... | ||
148 | || !KRarcHandler::arcSupported(file->getMime()))) { | 148 | || !KRarcHandler::arcSupported(file->getMime()))) { | ||
149 | // ...it will not be browsed as a directory by default, but add an option for it | 149 | // ...it will not be browsed as a directory by default, but add an option for it | ||
150 | QAction *browseAct = addAction(i18n("Browse")); | 150 | QAction *browseAct = addAction(i18n("Browse")); | ||
151 | browseAct->setData(QVariant(BROWSE_ID)); | 151 | browseAct->setData(QVariant(BROWSE_ID)); | ||
152 | browseAct->setIcon(krLoader->loadIcon("", KIconLoader::Panel)); | 152 | browseAct->setIcon(Icon()); | ||
153 | browseAct->setText(i18n("Browse Archive")); | 153 | browseAct->setText(i18n("Browse Archive")); | ||
154 | } | 154 | } | ||
155 | addSeparator(); | 155 | addSeparator(); | ||
156 | } | 156 | } | ||
157 | 157 | | |||
158 | // ------------- Preview - local filesystem only ? | 158 | // ------------- Preview - local filesystem only ? | ||
159 | if (panel->func->files()->isLocal()) { | 159 | if (panel->func->files()->isLocal()) { | ||
160 | // create the preview popup | 160 | // create the preview popup | ||
161 | KrPreviewPopup preview; | 161 | KrPreviewPopup preview; | ||
162 | preview.setUrls(panel->func->files()->getUrls(fileNames)); | 162 | preview.setUrls(panel->func->files()->getUrls(fileNames)); | ||
163 | QAction *previewAction = addMenu(&preview); | 163 | QAction *previewAction = addMenu(&preview); | ||
164 | previewAction->setData(QVariant(PREVIEW_ID)); | 164 | previewAction->setData(QVariant(PREVIEW_ID)); | ||
165 | previewAction->setText(i18n("Preview")); | 165 | previewAction->setText(i18n("Preview")); | ||
166 | previewAction->setIcon(krLoader->loadIcon("document-print-preview", KIconLoader::Small)); | 166 | previewAction->setIcon(Icon("document-print-preview")); | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | // -------------- Open with: try to find-out which apps can open the file | 169 | // -------------- Open with: try to find-out which apps can open the file | ||
170 | QSet<QString> uniqueMimeTypes; | 170 | QSet<QString> uniqueMimeTypes; | ||
171 | for (FileItem *file : files) | 171 | for (FileItem *file : files) | ||
172 | uniqueMimeTypes.insert(file->getMime()); | 172 | uniqueMimeTypes.insert(file->getMime()); | ||
173 | const QStringList mimeTypes = uniqueMimeTypes.toList(); | 173 | const QStringList mimeTypes = uniqueMimeTypes.toList(); | ||
174 | 174 | | |||
175 | offers = mimeTypes.count() == 1 ? | 175 | offers = mimeTypes.count() == 1 ? | ||
176 | KMimeTypeTrader::self()->query(mimeTypes.first()) : | 176 | KMimeTypeTrader::self()->query(mimeTypes.first()) : | ||
177 | KFileItemActions::associatedApplications(mimeTypes, QString()); | 177 | KFileItemActions::associatedApplications(mimeTypes, QString()); | ||
178 | 178 | | |||
179 | if (!offers.isEmpty()) { | 179 | if (!offers.isEmpty()) { | ||
180 | QMenu *openWithMenu = new QMenu(this); | 180 | QMenu *openWithMenu = new QMenu(this); | ||
181 | for (int i = 0; i < offers.count(); ++i) { | 181 | for (int i = 0; i < offers.count(); ++i) { | ||
182 | QExplicitlySharedDataPointer<KService> service = offers[i]; | 182 | QExplicitlySharedDataPointer<KService> service = offers[i]; | ||
183 | if (service->isValid() && service->isApplication()) { | 183 | if (service->isValid() && service->isApplication()) { | ||
184 | openWithMenu->addAction(krLoader->loadIcon(service->icon(), KIconLoader::Small), | 184 | openWithMenu->addAction(Icon(service->icon()), | ||
185 | service->name())->setData(QVariant(SERVICE_LIST_ID + i)); | 185 | service->name())->setData(QVariant(SERVICE_LIST_ID + i)); | ||
186 | } | 186 | } | ||
187 | } | 187 | } | ||
188 | openWithMenu->addSeparator(); | 188 | openWithMenu->addSeparator(); | ||
189 | if (!multipleSelections && file->isDir()) | 189 | if (!multipleSelections && file->isDir()) | ||
190 | openWithMenu->addAction(krLoader->loadIcon("utilities-terminal", KIconLoader::Small), | 190 | openWithMenu->addAction(Icon("utilities-terminal"), | ||
191 | i18n("Terminal"))->setData(QVariant(OPEN_TERM_ID)); | 191 | i18n("Terminal"))->setData(QVariant(OPEN_TERM_ID)); | ||
192 | openWithMenu->addAction(i18n("Other..."))->setData(QVariant(CHOOSE_ID)); | 192 | openWithMenu->addAction(i18n("Other..."))->setData(QVariant(CHOOSE_ID)); | ||
193 | QAction *openWithAction = addMenu(openWithMenu); | 193 | QAction *openWithAction = addMenu(openWithMenu); | ||
194 | openWithAction->setText(i18n("Open With")); | 194 | openWithAction->setText(i18n("Open With")); | ||
195 | openWithAction->setIcon(krLoader->loadIcon("document-open", KIconLoader::Small)); | 195 | openWithAction->setIcon(Icon("document-open")); | ||
196 | addSeparator(); | 196 | addSeparator(); | ||
197 | } | 197 | } | ||
198 | 198 | | |||
199 | // --------------- user actions | 199 | // --------------- user actions | ||
200 | QAction *userAction = new UserActionPopupMenu(file->getUrl(), this); | 200 | QAction *userAction = new UserActionPopupMenu(file->getUrl(), this); | ||
201 | userAction->setText(i18n("User Actions")); | 201 | userAction->setText(i18n("User Actions")); | ||
202 | addAction(userAction); | 202 | addAction(userAction); | ||
203 | 203 | | |||
Show All 25 Lines | |||||
229 | // ------- RENAME - only one file | 229 | // ------- RENAME - only one file | ||
230 | if (!multipleSelections && !inTrash) { | 230 | if (!multipleSelections && !inTrash) { | ||
231 | addAction(panel->gui->actions()->actRenameF2); | 231 | addAction(panel->gui->actions()->actRenameF2); | ||
232 | } | 232 | } | ||
233 | 233 | | |||
234 | // -------- MOVE TO TRASH | 234 | // -------- MOVE TO TRASH | ||
235 | if (KConfigGroup(krConfig, "General").readEntry("Move To Trash", _MoveToTrash) | 235 | if (KConfigGroup(krConfig, "General").readEntry("Move To Trash", _MoveToTrash) | ||
236 | && panel->func->files()->canMoveToTrash(fileNames)) { | 236 | && panel->func->files()->canMoveToTrash(fileNames)) { | ||
237 | addAction(krLoader->loadIcon("user-trash", KIconLoader::Small), | 237 | addAction(Icon("user-trash"), | ||
238 | i18n("Move to Trash"))->setData(QVariant(TRASH_ID)); | 238 | i18n("Move to Trash"))->setData(QVariant(TRASH_ID)); | ||
239 | } | 239 | } | ||
240 | // -------- DELETE | 240 | // -------- DELETE | ||
241 | addAction(krLoader->loadIcon("edit-delete", KIconLoader::Small), | 241 | addAction(Icon("edit-delete"), | ||
242 | i18n("Delete"))->setData(QVariant(DELETE_ID)); | 242 | i18n("Delete"))->setData(QVariant(DELETE_ID)); | ||
243 | // -------- SHRED - only one file | 243 | // -------- SHRED - only one file | ||
244 | /* if ( panel->func->files() ->getType() == filesystem:fileSystemM_NORMAL && | 244 | /* if ( panel->func->files() ->getType() == filesystem:fileSystemM_NORMAL && | ||
245 | !fileitem->isDir() && !multipleSelections ) | 245 | !fileitem->isDir() && !multipleSelections ) | ||
246 | addAction( i18n( "Shred" ) )->setData( QVariant( SHRED_ID ) );*/ | 246 | addAction( i18n( "Shred" ) )->setData( QVariant( SHRED_ID ) );*/ | ||
247 | 247 | | |||
248 | // ---------- link handling | 248 | // ---------- link handling | ||
249 | // create new shortcut or redirect links - only on local directories: | 249 | // create new shortcut or redirect links - only on local directories: | ||
250 | if (panel->func->files()->isLocal()) { | 250 | if (panel->func->files()->isLocal()) { | ||
251 | addSeparator(); | 251 | addSeparator(); | ||
252 | QMenu *linkMenu = new QMenu(this); | 252 | QMenu *linkMenu = new QMenu(this); | ||
253 | linkMenu->addAction(i18n("New Symlink..."))->setData(QVariant(NEW_SYMLINK_ID)); | 253 | linkMenu->addAction(i18n("New Symlink..."))->setData(QVariant(NEW_SYMLINK_ID)); | ||
254 | linkMenu->addAction(i18n("New Hardlink..."))->setData(QVariant(NEW_LINK_ID)); | 254 | linkMenu->addAction(i18n("New Hardlink..."))->setData(QVariant(NEW_LINK_ID)); | ||
255 | if (file->isSymLink()) { | 255 | if (file->isSymLink()) { | ||
256 | linkMenu->addAction(i18n("Redirect Link..."))->setData(QVariant(REDIRECT_LINK_ID)); | 256 | linkMenu->addAction(i18n("Redirect Link..."))->setData(QVariant(REDIRECT_LINK_ID)); | ||
257 | } | 257 | } | ||
258 | QAction *linkAction = addMenu(linkMenu); | 258 | QAction *linkAction = addMenu(linkMenu); | ||
259 | linkAction->setText(i18n("Link Handling")); | 259 | linkAction->setText(i18n("Link Handling")); | ||
260 | linkAction->setIcon(krLoader->loadIcon("insert-link", KIconLoader::Small)); | 260 | linkAction->setIcon(Icon("insert-link")); | ||
261 | } | 261 | } | ||
262 | addSeparator(); | 262 | addSeparator(); | ||
263 | 263 | | |||
264 | // ---------- calculate space | 264 | // ---------- calculate space | ||
265 | if (panel->func->files()->isLocal() && (file->isDir() || multipleSelections)) | 265 | if (panel->func->files()->isLocal() && (file->isDir() || multipleSelections)) | ||
266 | addAction(panel->gui->actions()->actCalculate); | 266 | addAction(panel->gui->actions()->actCalculate); | ||
267 | 267 | | |||
268 | // ---------- mount/umount/eject | 268 | // ---------- mount/umount/eject | ||
269 | if (panel->func->files()->isLocal() && file->isDir() && !multipleSelections) { | 269 | if (panel->func->files()->isLocal() && file->isDir() && !multipleSelections) { | ||
270 | const QString selectedDirectoryPath = file->getUrl().path(); | 270 | const QString selectedDirectoryPath = file->getUrl().path(); | ||
271 | if (krMtMan.getStatus(selectedDirectoryPath) == KMountMan::MOUNTED) | 271 | if (krMtMan.getStatus(selectedDirectoryPath) == KMountMan::MOUNTED) | ||
272 | addAction(i18n("Unmount"))->setData(QVariant(UNMOUNT_ID)); | 272 | addAction(i18n("Unmount"))->setData(QVariant(UNMOUNT_ID)); | ||
273 | else if (krMtMan.getStatus(selectedDirectoryPath) == KMountMan::NOT_MOUNTED) | 273 | else if (krMtMan.getStatus(selectedDirectoryPath) == KMountMan::NOT_MOUNTED) | ||
274 | addAction(i18n("Mount"))->setData(QVariant(MOUNT_ID)); | 274 | addAction(i18n("Mount"))->setData(QVariant(MOUNT_ID)); | ||
275 | if (krMtMan.ejectable(selectedDirectoryPath)) | 275 | if (krMtMan.ejectable(selectedDirectoryPath)) | ||
276 | addAction(i18n("Eject"))->setData(QVariant(EJECT_ID)); | 276 | addAction(i18n("Eject"))->setData(QVariant(EJECT_ID)); | ||
277 | } | 277 | } | ||
278 | 278 | | |||
279 | // --------- send by mail | 279 | // --------- send by mail | ||
280 | if (KrServices::supportedTools().contains("MAIL") && !file->isDir()) { | 280 | if (KrServices::supportedTools().contains("MAIL") && !file->isDir()) { | ||
281 | addAction(krLoader->loadIcon("mail-send", KIconLoader::Small), | 281 | addAction(Icon("mail-send"), | ||
282 | i18n("Send by Email"))->setData(QVariant(SEND_BY_EMAIL_ID)); | 282 | i18n("Send by Email"))->setData(QVariant(SEND_BY_EMAIL_ID)); | ||
283 | } | 283 | } | ||
284 | 284 | | |||
285 | // --------- empty trash | 285 | // --------- empty trash | ||
286 | if (trashOnly) { | 286 | if (trashOnly) { | ||
287 | addAction(i18n("Restore"))->setData(QVariant(RESTORE_TRASHED_FILE_ID)); | 287 | addAction(i18n("Restore"))->setData(QVariant(RESTORE_TRASHED_FILE_ID)); | ||
288 | addAction(i18n("Empty Trash"))->setData(QVariant(EMPTY_TRASH_ID)); | 288 | addAction(i18n("Empty Trash"))->setData(QVariant(EMPTY_TRASH_ID)); | ||
289 | } | 289 | } | ||
Show All 20 Lines | |||||
310 | { | 310 | { | ||
311 | addAction(panel->gui->actions()->actPaste); | 311 | addAction(panel->gui->actions()->actPaste); | ||
312 | } | 312 | } | ||
313 | 313 | | |||
314 | void PanelContextMenu::addCreateNewMenu() | 314 | void PanelContextMenu::addCreateNewMenu() | ||
315 | { | 315 | { | ||
316 | QMenu *createNewMenu = new QMenu(this); | 316 | QMenu *createNewMenu = new QMenu(this); | ||
317 | 317 | | |||
318 | createNewMenu->addAction(krLoader->loadIcon("folder", KIconLoader::Small), | 318 | createNewMenu->addAction(Icon("folder"), | ||
319 | i18n("Folder..."))->setData(QVariant(MKDIR_ID)); | 319 | i18n("Folder..."))->setData(QVariant(MKDIR_ID)); | ||
320 | createNewMenu->addAction(krLoader->loadIcon("text-plain", KIconLoader::Small), | 320 | createNewMenu->addAction(Icon("text-plain"), | ||
321 | i18n("Text File..."))->setData(QVariant(NEW_TEXT_FILE_ID)); | 321 | i18n("Text File..."))->setData(QVariant(NEW_TEXT_FILE_ID)); | ||
322 | 322 | | |||
323 | QAction *newMenuAction = addMenu(createNewMenu); | 323 | QAction *newMenuAction = addMenu(createNewMenu); | ||
324 | newMenuAction->setText(i18n("Create New")); | 324 | newMenuAction->setText(i18n("Create New")); | ||
325 | newMenuAction->setIcon(krLoader->loadIcon("document-new", KIconLoader::Small)); | 325 | newMenuAction->setIcon(Icon("document-new")); | ||
326 | } | 326 | } | ||
327 | 327 | | |||
328 | void PanelContextMenu::performAction(int id) | 328 | void PanelContextMenu::performAction(int id) | ||
329 | { | 329 | { | ||
330 | const QUrl singleURL = _items.isEmpty() ? QUrl() : _items.first().url(); | 330 | const QUrl singleURL = _items.isEmpty() ? QUrl() : _items.first().url(); | ||
331 | 331 | | |||
332 | switch (id) { | 332 | switch (id) { | ||
333 | case - 1 : // the user clicked outside of the menu | 333 | case - 1 : // the user clicked outside of the menu | ||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |