forked from qt-creator/qt-creator
ModelEditor: Add action for inplace editing
Pressing "Return" activates inplace editing, Shift+Return activates properties. Change-Id: I67601a439d27f9d322a3a88f7706d26f75faaab8 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -144,15 +144,18 @@ void ActionHandler::createActions()
|
||||
registerCommand(Constants::ACTION_ADD_COMPONENT, nullptr, Core::Context());
|
||||
registerCommand(Constants::ACTION_ADD_CLASS, nullptr, Core::Context());
|
||||
registerCommand(Constants::ACTION_ADD_CANVAS_DIAGRAM, nullptr, Core::Context());
|
||||
}
|
||||
|
||||
void ActionHandler::createEditPropertiesShortcut(const Core::Id &shortcutId)
|
||||
{
|
||||
auto editAction = new QAction(tr("Edit Element Properties"), Core::ICore::mainWindow());
|
||||
Core::Command *editCommand = Core::ActionManager::registerAction(
|
||||
editAction, shortcutId, d->context);
|
||||
editCommand->setDefaultKeySequence(QKeySequence(tr("Return")));
|
||||
connect(editAction, &QAction::triggered, this, &ActionHandler::onEditProperties);
|
||||
auto editPropertiesAction = new QAction(tr("Edit Element Properties"), Core::ICore::mainWindow());
|
||||
Core::Command *editPropertiesCommand = Core::ActionManager::registerAction(
|
||||
editPropertiesAction, Constants::SHORTCUT_MODEL_EDITOR_EDIT_PROPERTIES, d->context);
|
||||
editPropertiesCommand->setDefaultKeySequence(QKeySequence(tr("Shift+Return")));
|
||||
connect(editPropertiesAction, &QAction::triggered, this, &ActionHandler::onEditProperties);
|
||||
|
||||
auto editItemAction = new QAction(tr("Edit Item on Diagram"), Core::ICore::mainWindow());
|
||||
Core::Command *editItemCommand = Core::ActionManager::registerAction(
|
||||
editItemAction, Constants::SHORTCUT_MODEL_EDITOR_EDIT_ITEM, d->context);
|
||||
editItemCommand->setDefaultKeySequence(QKeySequence(tr("Return")));
|
||||
connect(editItemAction, &QAction::triggered, this, &ActionHandler::onEditItem);
|
||||
}
|
||||
|
||||
void ActionHandler::undo()
|
||||
@@ -225,6 +228,13 @@ void ActionHandler::onEditProperties()
|
||||
editor->editProperties();
|
||||
}
|
||||
|
||||
void ActionHandler::onEditItem()
|
||||
{
|
||||
auto editor = qobject_cast<ModelEditor *>(Core::EditorManager::currentEditor());
|
||||
if (editor)
|
||||
editor->editSelectedItem();
|
||||
}
|
||||
|
||||
Core::Command *ActionHandler::registerCommand(const Core::Id &id, const std::function<void()> &slot,
|
||||
const Core::Context &context, bool scriptable, const QString &title,
|
||||
const QKeySequence &keySequence)
|
||||
|
||||
@@ -71,7 +71,6 @@ public:
|
||||
QAction *openParentDiagramAction() const;
|
||||
|
||||
void createActions();
|
||||
void createEditPropertiesShortcut(const Core::Id &shortcutId);
|
||||
|
||||
private slots:
|
||||
void undo();
|
||||
@@ -84,6 +83,7 @@ private slots:
|
||||
void selectAll();
|
||||
void openParentDiagram();
|
||||
void onEditProperties();
|
||||
void onEditItem();
|
||||
|
||||
private:
|
||||
Core::Command *registerCommand(const Core::Id &id, const std::function<void()> &slot,
|
||||
|
||||
@@ -508,6 +508,11 @@ void ModelEditor::editProperties()
|
||||
d->propertiesView->editSelectedElement();
|
||||
}
|
||||
|
||||
void ModelEditor::editSelectedItem()
|
||||
{
|
||||
onEditSelectedElement();
|
||||
}
|
||||
|
||||
qmt::MPackage *ModelEditor::guessSelectedPackage() const
|
||||
{
|
||||
qmt::MPackage *package = 0;
|
||||
@@ -1184,6 +1189,7 @@ void ModelEditor::onEditSelectedElement()
|
||||
if (element) {
|
||||
qmt::DiagramSceneModel *diagramSceneModel = d->document->documentController()->diagramsManager()->diagramSceneModel(diagram);
|
||||
if (diagramSceneModel->isElementEditable(element)) {
|
||||
d->diagramStack->currentWidget()->setFocus();
|
||||
diagramSceneModel->editElement(element);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ public:
|
||||
void selectAll();
|
||||
void openParentDiagram();
|
||||
void editProperties();
|
||||
void editSelectedItem();
|
||||
qmt::MPackage *guessSelectedPackage() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -50,6 +50,8 @@ const char ACTION_EXPLORER_OPEN_DIAGRAM[] = "ModelEditor.Action.Explorer.OpenDia
|
||||
|
||||
const char SHORTCUT_MODEL_EDITOR_EDIT_PROPERTIES[] =
|
||||
"ModelEditor.ModelEditor.Shortcut.EditProperties";
|
||||
const char SHORTCUT_MODEL_EDITOR_EDIT_ITEM[] =
|
||||
"ModelEditor.ModelEditor.Shortcut.EditItem";
|
||||
|
||||
const char WIZARD_CATEGORY[] = "O.Model";
|
||||
const char WIZARD_TR_CATEGORY[] = QT_TRANSLATE_NOOP("Modeling", "Modeling");
|
||||
|
||||
@@ -71,8 +71,6 @@ Core::IEditor *ModelEditorFactory::createEditor()
|
||||
void ModelEditorFactory::extensionsInitialized()
|
||||
{
|
||||
d->actionHandler->createActions();
|
||||
d->actionHandler->createEditPropertiesShortcut(
|
||||
Constants::SHORTCUT_MODEL_EDITOR_EDIT_PROPERTIES);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user