ResourceEditor: Use ActionBuilder

Change-Id: Ibc6c114555d7b31f0a87a9727543313f50ab91d0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2024-01-17 18:08:39 +01:00
parent f2fb88df2e
commit 7ff6e555e3
2 changed files with 99 additions and 74 deletions

View File

@@ -396,27 +396,32 @@ void setupResourceEditor(QObject *guard)
// Register undo and redo // Register undo and redo
const Context context(Constants::C_RESOURCEEDITOR); const Context context(Constants::C_RESOURCEEDITOR);
s_undoAction = new QAction(Tr::tr("&Undo"), guard); ActionBuilder(guard, Core::Constants::UNDO)
s_redoAction = new QAction(Tr::tr("&Redo"), guard); .setText(Tr::tr("&Undo"))
s_refreshAction = new QAction(Tr::tr("Recheck Existence of Referenced Files"), guard); .bindContextAction(&s_undoAction)
ActionManager::registerAction(s_undoAction, Core::Constants::UNDO, context); .setContext(context)
ActionManager::registerAction(s_redoAction, Core::Constants::REDO, context); .addOnTriggered(guard, [] {
ActionManager::registerAction(s_refreshAction, Constants::REFRESH, context); if (ResourceEditorImpl *editor = ResourceEditorImpl::currentEditor())
editor->onUndo();
});
QObject::connect(s_undoAction, &QAction::triggered, guard, [] { ActionBuilder(guard, Core::Constants::REDO)
if (ResourceEditorImpl *editor = ResourceEditorImpl::currentEditor()) .bindContextAction(&s_redoAction)
editor->onUndo(); .setText(Tr::tr("&Redo"))
}); .setContext(context)
.addOnTriggered(guard, [] {
if (ResourceEditorImpl *editor = ResourceEditorImpl::currentEditor())
editor->onRedo();
});
QObject::connect(s_redoAction, &QAction::triggered, guard, [] { ActionBuilder(guard, Constants::REFRESH)
if (ResourceEditorImpl *editor = ResourceEditorImpl::currentEditor()) .setText(Tr::tr("Recheck Existence of Referenced Files"))
editor->onRedo(); .bindContextAction(&s_refreshAction)
}); .setContext(context)
.addOnTriggered(guard, [] {
QObject::connect(s_refreshAction, &QAction::triggered, guard, [] { if (ResourceEditorImpl *editor = ResourceEditorImpl::currentEditor())
if (ResourceEditorImpl *editor = ResourceEditorImpl::currentEditor()) editor->onRefresh();
editor->onRefresh(); });
});
} }
} // ResourceEditor::Internal } // ResourceEditor::Internal

View File

@@ -136,71 +136,91 @@ void ResourceEditorPlugin::initialize()
{ {
setupResourceEditor(this); setupResourceEditor(this);
Context projectTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE); const Context projectTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE);
ActionContainer *folderContextMenu = const Id folderContextMenu = ProjectExplorer::Constants::M_FOLDERCONTEXT;
ActionManager::actionContainer(ProjectExplorer::Constants::M_FOLDERCONTEXT); const Id folderFilesGroup = ProjectExplorer::Constants::G_FOLDER_FILES;
ActionContainer *fileContextMenu = const Id fileContextMenu = ProjectExplorer::Constants::M_FILECONTEXT;
ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT);
Command *command = nullptr;
m_addPrefix = new QAction(Tr::tr("Add Prefix..."), this); ActionBuilder(this, Constants::C_ADD_PREFIX)
command = ActionManager::registerAction(m_addPrefix, Constants::C_ADD_PREFIX, projectTreeContext); .setText(Tr::tr("Add Prefix..."))
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); .bindContextAction(&m_addPrefix)
connect(m_addPrefix, &QAction::triggered, this, &ResourceEditorPlugin::addPrefixContextMenu); .setContext(projectTreeContext)
.setEnabled(false)
.addToContainer(folderContextMenu, folderFilesGroup)
.addOnTriggered(this, &ResourceEditorPlugin::addPrefixContextMenu);
m_renamePrefix = new QAction(Tr::tr("Change Prefix..."), this); ActionBuilder(this, Constants::C_RENAME_PREFIX)
command = ActionManager::registerAction(m_renamePrefix, Constants::C_RENAME_PREFIX, projectTreeContext); .setText(Tr::tr("Change Prefix..."))
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); .bindContextAction(&m_renamePrefix)
connect(m_renamePrefix, &QAction::triggered, this, &ResourceEditorPlugin::renamePrefixContextMenu); .setContext(projectTreeContext)
.setEnabled(false)
.addToContainer(folderContextMenu, folderFilesGroup)
.addOnTriggered(this, &ResourceEditorPlugin::renamePrefixContextMenu);
m_removePrefix = new QAction(Tr::tr("Remove Prefix..."), this); ActionBuilder(this, Constants::C_REMOVE_PREFIX)
command = ActionManager::registerAction(m_removePrefix, Constants::C_REMOVE_PREFIX, projectTreeContext); .setText(Tr::tr("Remove Prefix..."))
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); .bindContextAction(&m_removePrefix)
connect(m_removePrefix, &QAction::triggered, this, &ResourceEditorPlugin::removePrefixContextMenu); .setContext(projectTreeContext)
.setEnabled(false)
.addToContainer(folderContextMenu, folderFilesGroup)
.addOnTriggered(this, &ResourceEditorPlugin::removePrefixContextMenu);
m_removeNonExisting = new QAction(Tr::tr("Remove Missing Files"), this); ActionBuilder(this, Constants::C_REMOVE_NON_EXISTING)
command = ActionManager::registerAction(m_removeNonExisting, Constants::C_REMOVE_NON_EXISTING, projectTreeContext); .setText(Tr::tr("Remove Missing Files"))
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); .bindContextAction(&m_removeNonExisting)
connect(m_removeNonExisting, &QAction::triggered, this, &ResourceEditorPlugin::removeNonExisting); .setContext(projectTreeContext)
.setEnabled(false)
.addToContainer(folderContextMenu, folderFilesGroup)
.addOnTriggered(this, &ResourceEditorPlugin::removeNonExisting);
m_renameResourceFile = new QAction(Tr::tr("Rename..."), this); ActionBuilder(this, Constants::C_RENAME_FILE)
command = ActionManager::registerAction(m_renameResourceFile, Constants::C_RENAME_FILE, projectTreeContext); .setText(Tr::tr("Rename..."))
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); .bindContextAction(&m_renameResourceFile)
connect(m_renameResourceFile, &QAction::triggered, this, &ResourceEditorPlugin::renameFileContextMenu); .setContext(projectTreeContext)
.setEnabled(false)
.addToContainer(folderContextMenu, folderFilesGroup)
.addOnTriggered(this, &ResourceEditorPlugin::renameFileContextMenu);
m_removeResourceFile = new QAction(Tr::tr("Remove File..."), this); ActionBuilder(this, Constants::C_REMOVE_FILE)
command = ActionManager::registerAction(m_removeResourceFile, Constants::C_REMOVE_FILE, projectTreeContext); .setText(Tr::tr("Remove File..."))
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); .bindContextAction(&m_removeResourceFile)
connect(m_removeResourceFile, &QAction::triggered, this, &ResourceEditorPlugin::removeFileContextMenu); .setContext(projectTreeContext)
.setEnabled(false)
.addToContainer(folderContextMenu, folderFilesGroup)
.addOnTriggered(this, &ResourceEditorPlugin::removeFileContextMenu);
m_openInEditor = new QAction(Tr::tr("Open in Editor"), this); ActionBuilder(this, Constants::C_OPEN_EDITOR)
command = ActionManager::registerAction(m_openInEditor, Constants::C_OPEN_EDITOR, projectTreeContext); .setText(Tr::tr("Open in Editor"))
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); .bindContextAction(&m_openInEditor)
connect(m_openInEditor, &QAction::triggered, this, &ResourceEditorPlugin::openEditorContextMenu); .setContext(projectTreeContext)
.addToContainer(folderContextMenu, folderFilesGroup)
.addOnTriggered(this, &ResourceEditorPlugin::openEditorContextMenu);
m_openWithMenu = new QMenu(Tr::tr("Open With"), folderContextMenu->menu()); ActionContainer *menu = ActionManager::actionContainer(folderContextMenu);
folderContextMenu->menu()->insertMenu( m_openWithMenu = new QMenu(Tr::tr("Open With"), menu->menu());
folderContextMenu->insertLocation(ProjectExplorer::Constants::G_FOLDER_FILES), menu->menu()->insertMenu(
m_openWithMenu); menu->insertLocation(ProjectExplorer::Constants::G_FOLDER_FILES),
m_openWithMenu);
m_copyPath = new ParameterAction(Tr::tr("Copy Path"), Tr::tr("Copy Path \"%1\""), ParameterAction::AlwaysEnabled, this); ActionBuilder(this, Constants::C_COPY_PATH)
command = ActionManager::registerAction(m_copyPath, Constants::C_COPY_PATH, projectTreeContext); .setParameterText(Tr::tr("Copy Path \"%1\""),
command->setAttribute(Command::CA_UpdateText); Tr::tr("Copy Path"),
fileContextMenu->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER); ActionBuilder::AlwaysEnabled)
connect(m_copyPath, &QAction::triggered, this, &ResourceEditorPlugin::copyPathContextMenu); .bindContextAction(&m_copyPath)
.setContext(projectTreeContext)
.setCommandAttribute(Command::CA_UpdateText)
.addToContainer(fileContextMenu, ProjectExplorer::Constants::G_FILE_OTHER)
.addOnTriggered(this, &ResourceEditorPlugin::copyPathContextMenu);
m_copyUrl = new ParameterAction(Tr::tr("Copy URL"), Tr::tr("Copy URL \"%1\""), ParameterAction::AlwaysEnabled, this); ActionBuilder(this, Constants::C_COPY_URL)
command = ActionManager::registerAction(m_copyUrl, Constants::C_COPY_URL, projectTreeContext); .setParameterText(Tr::tr("Copy URL \"%1\""),
command->setAttribute(Command::CA_UpdateText); Tr::tr("Copy URL"),
fileContextMenu->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER); ActionBuilder::AlwaysEnabled)
connect(m_copyUrl, &QAction::triggered, this, &ResourceEditorPlugin::copyUrlContextMenu); .bindContextAction(&m_copyUrl)
.setContext(projectTreeContext)
m_addPrefix->setEnabled(false); .setCommandAttribute(Command::CA_UpdateText)
m_removePrefix->setEnabled(false); .addToContainer(fileContextMenu, ProjectExplorer::Constants::G_FILE_OTHER)
m_renamePrefix->setEnabled(false); .addOnTriggered(this, &ResourceEditorPlugin::copyUrlContextMenu);
m_removeNonExisting->setEnabled(false);
m_renameResourceFile->setEnabled(false);
m_removeResourceFile->setEnabled(false);
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
this, &ResourceEditorPlugin::updateContextActions); this, &ResourceEditorPlugin::updateContextActions);