mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Cleanup Places Panel context menus
Differential Revision: https://phabricator.kde.org/D4498
This commit is contained in:
parent
db54c9b6ce
commit
429427767b
|
@ -249,7 +249,7 @@ QAction* PlacesItemModel::ejectAction(int index) const
|
|||
{
|
||||
const PlacesItem* item = placesItem(index);
|
||||
if (item && item->device().is<Solid::OpticalDisc>()) {
|
||||
return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject '%1'", item->text()), 0);
|
||||
return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject"), 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -283,14 +283,13 @@ QAction* PlacesItemModel::teardownAction(int index) const
|
|||
|
||||
QString iconName;
|
||||
QString text;
|
||||
const QString label = item->text();
|
||||
if (device.is<Solid::OpticalDisc>()) {
|
||||
text = i18nc("@item", "Release '%1'", label);
|
||||
text = i18nc("@item", "Release");
|
||||
} else if (removable || hotPluggable) {
|
||||
text = i18nc("@item", "Safely Remove '%1'", label);
|
||||
text = i18nc("@item", "Safely Remove");
|
||||
iconName = QStringLiteral("media-eject");
|
||||
} else {
|
||||
text = i18nc("@item", "Unmount '%1'", label);
|
||||
text = i18nc("@item", "Unmount");
|
||||
iconName = QStringLiteral("media-eject");
|
||||
}
|
||||
|
||||
|
|
|
@ -160,8 +160,6 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
|
|||
QMenu menu(this);
|
||||
|
||||
QAction* emptyTrashAction = 0;
|
||||
QAction* addAction = 0;
|
||||
QAction* mainSeparator = 0;
|
||||
QAction* editAction = 0;
|
||||
QAction* teardownAction = 0;
|
||||
QAction* ejectAction = 0;
|
||||
|
@ -169,6 +167,7 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
|
|||
const QString label = item->text();
|
||||
|
||||
const bool isDevice = !item->udi().isEmpty();
|
||||
const bool isTrash = (item->url().scheme() == QLatin1String("trash"));
|
||||
if (isDevice) {
|
||||
ejectAction = m_model->ejectAction(index);
|
||||
if (ejectAction) {
|
||||
|
@ -183,95 +182,36 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
|
|||
}
|
||||
|
||||
if (teardownAction || ejectAction) {
|
||||
mainSeparator = menu.addSeparator();
|
||||
menu.addSeparator();
|
||||
}
|
||||
} else {
|
||||
if (item->url() == QUrl(QStringLiteral("trash:/"))) {
|
||||
if (isTrash) {
|
||||
emptyTrashAction = menu.addAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"));
|
||||
emptyTrashAction->setEnabled(item->icon() == QLatin1String("user-trash-full"));
|
||||
menu.addSeparator();
|
||||
}
|
||||
addAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18nc("@item:inmenu", "Add Entry..."));
|
||||
mainSeparator = menu.addSeparator();
|
||||
editAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18nc("@item:inmenu", "Edit '%1'...", label));
|
||||
}
|
||||
|
||||
if (!addAction) {
|
||||
addAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-new")), i18nc("@item:inmenu", "Add Entry..."));
|
||||
QAction* openInNewTabAction = menu.addAction(QIcon::fromTheme("tab-new"), i18nc("@item:inmenu", "Open in New Tab"));
|
||||
if (!isDevice && !isTrash) {
|
||||
menu.addSeparator();
|
||||
}
|
||||
|
||||
QAction* openInNewTabAction = menu.addAction(i18nc("@item:inmenu", "Open '%1' in New Tab", label));
|
||||
openInNewTabAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
|
||||
editAction = menu.addAction(QIcon::fromTheme("document-properties"), i18nc("@item:inmenu", "Edit..."));
|
||||
|
||||
QAction* removeAction = 0;
|
||||
if (!isDevice && !item->isSystemItem()) {
|
||||
removeAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@item:inmenu", "Remove '%1'", label));
|
||||
removeAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@item:inmenu", "Remove"));
|
||||
}
|
||||
|
||||
QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide '%1'", label));
|
||||
QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide"));
|
||||
hideAction->setCheckable(true);
|
||||
hideAction->setChecked(item->isHidden());
|
||||
|
||||
QAction* showAllAction = 0;
|
||||
if (m_model->hiddenCount() > 0) {
|
||||
if (!mainSeparator) {
|
||||
mainSeparator = menu.addSeparator();
|
||||
}
|
||||
showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries"));
|
||||
showAllAction->setCheckable(true);
|
||||
showAllAction->setChecked(m_model->hiddenItemsShown());
|
||||
}
|
||||
|
||||
menu.addSeparator();
|
||||
QMenu* iconSizeSubMenu = new QMenu(i18nc("@item:inmenu", "Icon Size"), &menu);
|
||||
|
||||
struct IconSizeInfo
|
||||
{
|
||||
int size;
|
||||
const char* context;
|
||||
const char* text;
|
||||
};
|
||||
|
||||
const int iconSizeCount = 4;
|
||||
static const IconSizeInfo iconSizes[iconSizeCount] = {
|
||||
{KIconLoader::SizeSmall, I18N_NOOP2_NOSTRIP("Small icon size", "Small (%1x%2)")},
|
||||
{KIconLoader::SizeSmallMedium, I18N_NOOP2_NOSTRIP("Medium icon size", "Medium (%1x%2)")},
|
||||
{KIconLoader::SizeMedium, I18N_NOOP2_NOSTRIP("Large icon size", "Large (%1x%2)")},
|
||||
{KIconLoader::SizeLarge, I18N_NOOP2_NOSTRIP("Huge icon size", "Huge (%1x%2)")}
|
||||
};
|
||||
|
||||
QHash<QAction*, int> iconSizeActionMap;
|
||||
QActionGroup* iconSizeGroup = new QActionGroup(iconSizeSubMenu);
|
||||
|
||||
for (int i = 0; i < iconSizeCount; ++i) {
|
||||
const int size = iconSizes[i].size;
|
||||
const QString text = i18nc(iconSizes[i].context, iconSizes[i].text,
|
||||
size, size);
|
||||
|
||||
QAction* action = iconSizeSubMenu->addAction(text);
|
||||
iconSizeActionMap.insert(action, size);
|
||||
action->setActionGroup(iconSizeGroup);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(m_view->iconSize() == size);
|
||||
}
|
||||
|
||||
menu.addMenu(iconSizeSubMenu);
|
||||
|
||||
menu.addSeparator();
|
||||
foreach (QAction* action, customContextMenuActions()) {
|
||||
menu.addAction(action);
|
||||
}
|
||||
|
||||
QAction* action = menu.exec(pos.toPoint());
|
||||
if (action) {
|
||||
if (action == emptyTrashAction) {
|
||||
emptyTrash();
|
||||
} else if (action == addAction) {
|
||||
addEntry();
|
||||
} else if (action == showAllAction) {
|
||||
m_model->setHiddenItemsShown(showAllAction->isChecked());
|
||||
} else if (iconSizeActionMap.contains(action)) {
|
||||
m_view->setIconSize(iconSizeActionMap.value(action));
|
||||
} else {
|
||||
// The index might have changed if devices were added/removed while
|
||||
// the context menu was open.
|
||||
|
@ -318,6 +258,40 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
|
|||
showAllAction->setChecked(m_model->hiddenItemsShown());
|
||||
}
|
||||
|
||||
QMenu* iconSizeSubMenu = new QMenu(i18nc("@item:inmenu", "Icon Size"), &menu);
|
||||
|
||||
struct IconSizeInfo
|
||||
{
|
||||
int size;
|
||||
const char* context;
|
||||
const char* text;
|
||||
};
|
||||
|
||||
const int iconSizeCount = 4;
|
||||
static const IconSizeInfo iconSizes[iconSizeCount] = {
|
||||
{KIconLoader::SizeSmall, I18N_NOOP2_NOSTRIP("Small icon size", "Small (%1x%2)")},
|
||||
{KIconLoader::SizeSmallMedium, I18N_NOOP2_NOSTRIP("Medium icon size", "Medium (%1x%2)")},
|
||||
{KIconLoader::SizeMedium, I18N_NOOP2_NOSTRIP("Large icon size", "Large (%1x%2)")},
|
||||
{KIconLoader::SizeLarge, I18N_NOOP2_NOSTRIP("Huge icon size", "Huge (%1x%2)")}
|
||||
};
|
||||
|
||||
QMap<QAction*, int> iconSizeActionMap;
|
||||
QActionGroup* iconSizeGroup = new QActionGroup(iconSizeSubMenu);
|
||||
|
||||
for (int i = 0; i < iconSizeCount; ++i) {
|
||||
const int size = iconSizes[i].size;
|
||||
const QString text = i18nc(iconSizes[i].context, iconSizes[i].text,
|
||||
size, size);
|
||||
|
||||
QAction* action = iconSizeSubMenu->addAction(text);
|
||||
iconSizeActionMap.insert(action, size);
|
||||
action->setActionGroup(iconSizeGroup);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(m_view->iconSize() == size);
|
||||
}
|
||||
|
||||
menu.addMenu(iconSizeSubMenu);
|
||||
|
||||
menu.addSeparator();
|
||||
foreach (QAction* action, customContextMenuActions()) {
|
||||
menu.addAction(action);
|
||||
|
@ -329,6 +303,8 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
|
|||
addEntry();
|
||||
} else if (action == showAllAction) {
|
||||
m_model->setHiddenItemsShown(showAllAction->isChecked());
|
||||
} else if (iconSizeActionMap.contains(action)) {
|
||||
m_view->setIconSize(iconSizeActionMap.value(action));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue