(actionCollection, parentWidget))
, mParent(parent)
{
QObject::connect(mGenericManager.get(), &StandardActionManager::actionStateUpdated,
mParent, &StandardNoteActionManager::actionStateUpdated);
mGenericManager->setMimeTypeFilter({ NoteUtils::noteMimeType() });
mGenericManager->setCapabilityFilter({ QStringLiteral("Resource") });
}
~Private() = default;
void updateGenericAllActions()
{
updateGenericAction(StandardActionManager::CreateCollection);
updateGenericAction(StandardActionManager::CopyCollections);
updateGenericAction(StandardActionManager::DeleteCollections);
updateGenericAction(StandardActionManager::SynchronizeCollections);
updateGenericAction(StandardActionManager::CollectionProperties);
updateGenericAction(StandardActionManager::CopyItems);
updateGenericAction(StandardActionManager::Paste);
updateGenericAction(StandardActionManager::DeleteItems);
updateGenericAction(StandardActionManager::ManageLocalSubscriptions);
updateGenericAction(StandardActionManager::AddToFavoriteCollections);
updateGenericAction(StandardActionManager::RemoveFromFavoriteCollections);
updateGenericAction(StandardActionManager::RenameFavoriteCollection);
updateGenericAction(StandardActionManager::CopyCollectionToMenu);
updateGenericAction(StandardActionManager::CopyItemToMenu);
updateGenericAction(StandardActionManager::MoveItemToMenu);
updateGenericAction(StandardActionManager::MoveCollectionToMenu);
updateGenericAction(StandardActionManager::CutItems);
updateGenericAction(StandardActionManager::CutCollections);
updateGenericAction(StandardActionManager::CreateResource);
updateGenericAction(StandardActionManager::DeleteResources);
updateGenericAction(StandardActionManager::ResourceProperties);
updateGenericAction(StandardActionManager::SynchronizeResources);
updateGenericAction(StandardActionManager::ToggleWorkOffline);
updateGenericAction(StandardActionManager::CopyCollectionToDialog);
updateGenericAction(StandardActionManager::MoveCollectionToDialog);
updateGenericAction(StandardActionManager::CopyItemToDialog);
updateGenericAction(StandardActionManager::MoveItemToDialog);
updateGenericAction(StandardActionManager::SynchronizeCollectionsRecursive);
updateGenericAction(StandardActionManager::MoveCollectionsToTrash);
updateGenericAction(StandardActionManager::MoveItemsToTrash);
updateGenericAction(StandardActionManager::RestoreCollectionsFromTrash);
updateGenericAction(StandardActionManager::RestoreItemsFromTrash);
updateGenericAction(StandardActionManager::MoveToTrashRestoreCollection);
updateGenericAction(StandardActionManager::MoveToTrashRestoreCollectionAlternative);
updateGenericAction(StandardActionManager::MoveToTrashRestoreItem);
updateGenericAction(StandardActionManager::MoveToTrashRestoreItemAlternative);
updateGenericAction(StandardActionManager::SynchronizeFavoriteCollections);
}
void updateGenericAction(StandardActionManager::Type type)
{
switch (type) {
case StandardActionManager::CreateCollection:
mGenericManager->action(StandardActionManager::CreateCollection)->setText(
i18n("New Note Book..."));
mGenericManager->action(StandardActionManager::CreateCollection)->setIcon(
QIcon::fromTheme(QStringLiteral("address-book-new")));
mGenericManager->action(StandardActionManager::CreateCollection)->setWhatsThis(
i18n("Add a new note book to the currently selected bookshelf."));
mGenericManager->setContextText(
StandardActionManager::CreateCollection, StandardActionManager::DialogTitle,
i18nc("@title:window", "New Note Book"));
mGenericManager->setContextText(
StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageText,
ki18n("Could not create note book: %1"));
mGenericManager->setContextText(
StandardActionManager::CreateCollection, StandardActionManager::ErrorMessageTitle,
i18n("Note book creation failed"));
mGenericManager->action(StandardActionManager::CreateCollection)->setProperty("ContentMimeTypes", { NoteUtils::noteMimeType() });
break;
case StandardActionManager::CopyCollections:
mGenericManager->setActionText(StandardActionManager::CopyCollections,
ki18np("Copy Note Book",
"Copy %1 Note Books"));
mGenericManager->action(StandardActionManager::CopyCollections)->setWhatsThis(
i18n("Copy the selected note books to the clipboard."));
break;
case StandardActionManager::DeleteCollections:
mGenericManager->setActionText(StandardActionManager::DeleteCollections,
ki18np("Delete Note Book",
"Delete %1 Note Books"));
mGenericManager->action(StandardActionManager::DeleteCollections)->setWhatsThis(
i18n("Delete the selected note books from the bookshelf."));
mGenericManager->setContextText(
StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxText,
ki18np("Do you really want to delete this note book and all its contents?",
"Do you really want to delete %1 note books and all their contents?"));
mGenericManager->setContextText(
StandardActionManager::DeleteCollections, StandardActionManager::MessageBoxTitle,
ki18ncp("@title:window", "Delete note book?", "Delete note books?"));
mGenericManager->setContextText(
StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageText,
ki18n("Could not delete note book: %1"));
mGenericManager->setContextText(
StandardActionManager::DeleteCollections, StandardActionManager::ErrorMessageTitle,
i18n("Note book deletion failed"));
break;
case StandardActionManager::SynchronizeCollections:
mGenericManager->setActionText(StandardActionManager::SynchronizeCollections,
ki18np("Update Note Book",
"Update %1 Note Books"));
mGenericManager->action(StandardActionManager::SynchronizeCollections)->setWhatsThis(
i18n("Update the content of the selected note books."));
break;
case StandardActionManager::CutCollections:
mGenericManager->setActionText(StandardActionManager::CutCollections,
ki18np("Cut Note Book",
"Cut %1 Note Books"));
mGenericManager->action(StandardActionManager::CutCollections)->setWhatsThis(
i18n("Cut the selected note books from the bookshelf."));
break;
case StandardActionManager::CollectionProperties:
mGenericManager->action(StandardActionManager::CollectionProperties)->setText(
i18n("Note Book Properties..."));
mGenericManager->action(StandardActionManager::CollectionProperties)->setWhatsThis(
i18n("Open a dialog to edit the properties of the selected note book."));
mGenericManager->setContextText(
StandardActionManager::CollectionProperties, StandardActionManager::DialogTitle,
ki18nc("@title:window", "Properties of Note Book %1"));
break;
case StandardActionManager::CopyItems:
mGenericManager->setActionText(StandardActionManager::CopyItems,
ki18np("Copy Note", "Copy %1 Notes"));
mGenericManager->action(StandardActionManager::CopyItems)->setWhatsThis(
i18n("Copy the selected notes to the clipboard."));
break;
case StandardActionManager::DeleteItems:
mGenericManager->setActionText(StandardActionManager::DeleteItems,
ki18np("Delete Note", "Delete %1 Notes"));
mGenericManager->action(StandardActionManager::DeleteItems)->setWhatsThis(
i18n("Delete the selected notes from the note book."));
mGenericManager->setContextText(
StandardActionManager::DeleteItems, StandardActionManager::MessageBoxText,
ki18np("Do you really want to delete the selected note?",
"Do you really want to delete %1 notes?"));
mGenericManager->setContextText(
StandardActionManager::DeleteItems, StandardActionManager::MessageBoxTitle,
ki18ncp("@title:window", "Delete Note?", "Delete Notes?"));
mGenericManager->setContextText(
StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageText,
ki18n("Could not delete note: %1"));
mGenericManager->setContextText(
StandardActionManager::DeleteItems, StandardActionManager::ErrorMessageTitle,
i18n("Note deletion failed"));
break;
case StandardActionManager::CutItems:
mGenericManager->setActionText(StandardActionManager::CutItems,
ki18np("Cut Note", "Cut %1 Notes"));
mGenericManager->action(StandardActionManager::CutItems)->setWhatsThis(
i18n("Cut the selected notes from the note book."));
break;
case StandardActionManager::CreateResource:
mGenericManager->action(StandardActionManager::CreateResource)->setText(
i18n("Add &Bookshelf..."));
mGenericManager->action(StandardActionManager::CreateResource)->setWhatsThis(
i18n("Add a new bookshelf"
"You will be presented with a dialog where you can select "
"the type of the bookshelf that shall be added.
"));
mGenericManager->setContextText(
StandardActionManager::CreateResource, StandardActionManager::DialogTitle,
i18nc("@title:window", "Add Bookshelf"));
mGenericManager->setContextText(
StandardActionManager::CreateResource, StandardActionManager::ErrorMessageText,
ki18n("Could not create bookshelf: %1"));
mGenericManager->setContextText(
StandardActionManager::CreateResource, StandardActionManager::ErrorMessageTitle,
i18n("Bookshelf creation failed"));
break;
case StandardActionManager::DeleteResources:
mGenericManager->setActionText(StandardActionManager::DeleteResources,
ki18np("&Delete Bookshelf",
"&Delete %1 Bookshelfs"));
mGenericManager->action(StandardActionManager::DeleteResources)->setWhatsThis(
i18n("Delete the selected bookshelfs"
"The currently selected bookshelfs will be deleted, "
"along with all the notes they contain.
"));
mGenericManager->setContextText(
StandardActionManager::DeleteResources, StandardActionManager::MessageBoxText,
ki18np("Do you really want to delete this bookshelf?",
"Do you really want to delete %1 bookshelfs?"));
mGenericManager->setContextText(
StandardActionManager::DeleteResources, StandardActionManager::MessageBoxTitle,
ki18ncp("@title:window", "Delete Bookshelf?", "Delete Bookshelfs?"));
break;
case StandardActionManager::ResourceProperties:
mGenericManager->action(StandardActionManager::ResourceProperties)->setText(
i18n("Bookshelf Properties..."));
mGenericManager->action(StandardActionManager::ResourceProperties)->setWhatsThis(
i18n("Open a dialog to edit properties of the selected bookshelf."));
break;
case StandardActionManager::SynchronizeResources:
mGenericManager->setActionText(StandardActionManager::SynchronizeResources,
ki18np("Update Bookshelf",
"Update %1 Bookshelfs"));
mGenericManager->action(StandardActionManager::SynchronizeResources)->setWhatsThis
(i18n("Updates the content of all note books of the selected bookshelfs."));
break;
case StandardActionManager::Paste:
mGenericManager->setContextText(
StandardActionManager::Paste, StandardActionManager::ErrorMessageText,
ki18n("Could not paste note: %1"));
mGenericManager->setContextText(
StandardActionManager::Paste, StandardActionManager::ErrorMessageTitle,
i18n("Paste failed"));
break;
default:
break;
}
}
void updateActions()
{
- if (mItemSelectionModel && mCollectionSelectionModel) {
- const Collection::List collections = mParent->selectedCollections();
+ if (mItemSelectionModel) {
const Item::List items = mParent->selectedItems();
- QAction *action = mActions.value(StandardNoteActionManager::Lock);
+ const int countUnlocked = std::count_if(items.cbegin(), items.cend(), [](const Item &item){
+ return item.isValid() && !item.hasAttribute();
+ });
+
+ QAction *action = mActions.value(StandardNoteActionManager::LockUnlockNote);
if (action) {
- bool canLock = std::any_of(collections.cbegin(), collections.cend(), [](const Collection &collection){
- return collection.isValid() && !collection.hasAttribute();
- });
- canLock = canLock || std::any_of(items.cbegin(), items.cend(), [](const Item &item){
- return item.isValid() && !item.hasAttribute();
- });
- action->setEnabled(canLock);
+ action->setEnabled(items.size() > 0);
+ if (countUnlocked > 0) {
+ action->setData(true);
+ action->setText(i18ncp("@action", "Lock Note", "Lock Notes", countUnlocked));
+ action->setIcon(QIcon::fromTheme(QStringLiteral("emblem-locked")));
+ action->setWhatsThis(i18n("Lock selected notes"));
+ } else if (items.size() > 0) {
+ action->setData(false);
+ action->setText(i18ncp("@action", "Unlock Note", "Unlock Notes", items.size()));
+ action->setIcon(QIcon::fromTheme(QStringLiteral("emblem-locked")));
+ action->setWhatsThis(i18n("Unlock selected notes"));
+ }
}
- action = mActions.value(StandardNoteActionManager::Unlock);
+ action = mGenericManager->action(StandardActionManager::DeleteItems);
if (action) {
- const bool hasLockedCollection = std::any_of(collections.cbegin(), collections.cend(), [](const Collection &collection){
- return collection.isValid() && collection.hasAttribute();
- });
- if (hasLockedCollection) {
- mGenericManager->action(StandardActionManager::DeleteCollections)->setEnabled(false);
- }
- const bool hasLockedItems = std::any_of(items.cbegin(), items.cend(), [](const Item &item){
- return item.isValid() && item.hasAttribute();
- });
- if (hasLockedItems) {
- mGenericManager->action(StandardActionManager::DeleteItems)->setEnabled(false);
+ action->setEnabled(countUnlocked == items.size());
+ }
+ } else {
+ QAction *action = mActions.value(StandardNoteActionManager::LockUnlockNote);
+ if (action) {
+ action->setEnabled(false);
+ }
+ }
+
+ if (mCollectionSelectionModel) {
+ const Collection::List collections = mParent->selectedCollections();
+ const int countUnlocked = std::count_if(collections.cbegin(), collections.cend(), [](const Collection &collection){
+ return collection.isValid() && !collection.hasAttribute();
+ });
+
+ QAction *action = mActions.value(StandardNoteActionManager::LockUnlockNoteBook);
+ if (action) {
+ action->setEnabled(collections.size() > 0);
+ if (countUnlocked > 0) {
+ action->setData(true);
+ action->setText(i18ncp("@action", "Lock Note Book", "Lock Note Books", countUnlocked));
+ action->setIcon(QIcon::fromTheme(QStringLiteral("emblem-locked")));
+ action->setWhatsThis(i18n("Lock selected note books"));
+ } else if (collections.size() > 0) {
+ action->setData(false);
+ action->setText(i18ncp("@action", "Unlock Note Book", "Unlock Note Books", collections.size()));
+ action->setIcon(QIcon::fromTheme(QStringLiteral("emblem-locked")));
+ action->setWhatsThis(i18n("Unlock selected note books"));
}
- action->setEnabled(hasLockedItems || hasLockedCollection);
}
- action = mActions.value(StandardNoteActionManager::CreateNote);
+ action = mGenericManager->action(StandardActionManager::DeleteCollections);
+ if (action) {
+ action->setEnabled(countUnlocked == collections.size());
+ }
+ } else {
+ QAction *action = mActions.value(StandardNoteActionManager::LockUnlockNoteBook);
+ if (action) {
+ action->setEnabled(false);
+ }
+ }
+
+
+ if (mItemSelectionModel && mCollectionSelectionModel) {
+ const Collection::List collections = mParent->selectedCollections();
+ const Item::List items = mParent->selectedItems();
+
+ QAction *action = mActions.value(StandardNoteActionManager::CreateNote);
if (action) {
Akonadi::Collection collection;
if (collections.count() == 1) {
collection = collections.first();
} else if (collections.count() == 0) {
if (items.count() > 0) {
collection = mItemSelectionModel->selectedRows().first().data(EntityTreeModel::ParentCollectionRole).value