diff --git a/docs/guide/images/context_menu.png b/docs/guide/images/context_menu.png index f704ba10439..fbf7c5f16f1 100644 Binary files a/docs/guide/images/context_menu.png and b/docs/guide/images/context_menu.png differ diff --git a/docs/guide/images/scene_tree.png b/docs/guide/images/scene_tree.png index d93cb55e144..8928ec5d32e 100644 Binary files a/docs/guide/images/scene_tree.png and b/docs/guide/images/scene_tree.png differ diff --git a/docs/reference/changelog-r2022.md b/docs/reference/changelog-r2022.md index accf4c4063b..8e5a608117a 100644 --- a/docs/reference/changelog-r2022.md +++ b/docs/reference/changelog-r2022.md @@ -43,6 +43,7 @@ Released on September, 13th, 2022. - Changed the layout and behavior of the loading screen and progress bar for the [Web Interface](../guide/web-interface.md) ([#4593](https://github.com/cyberbotics/webots/pull/4593)). - Improved display of generated PROTO sources in Text Editor that are now opened in read-only mode ([#5023](https://github.com/cyberbotics/webots/pull/5023)). - Improved terminology and keyboard shortcuts of [Viewpoint](viewpoint.md) standard views related to the world ([#5149](https://github.com/cyberbotics/webots/pull/5149)). + - Added shortcuts to open the Field Editor from the Context Menu and double clicking on the Scene Tree node or field item ([#5211](https://github.com/cyberbotics/webots/pull/5211)). - Bug Fixes - Fixed execution of Webots on Windows in a UTF-8 path with non-ASCII characters ([#5103](https://github.com/cyberbotics/webots/pull/5103)). - Fixed bug in `wb_supervisor_node_get_field_by_index` and `wb_supervisor_node_get_proto_field_by_index` API functions ([#4366](https://github.com/cyberbotics/webots/pull/4366)). diff --git a/resources/icons/dark/edit_field_button.png b/resources/icons/dark/edit_field_button.png new file mode 100644 index 00000000000..2e17cab6771 Binary files /dev/null and b/resources/icons/dark/edit_field_button.png differ diff --git a/resources/icons/light/edit_field_button.png b/resources/icons/light/edit_field_button.png new file mode 100644 index 00000000000..34f84456be8 Binary files /dev/null and b/resources/icons/light/edit_field_button.png differ diff --git a/src/webots/core/WbAction.hpp b/src/webots/core/WbAction.hpp index 4b4c5b58ac9..1dda2efb916 100644 --- a/src/webots/core/WbAction.hpp +++ b/src/webots/core/WbAction.hpp @@ -137,6 +137,7 @@ namespace WbAction { // node/field actions OPEN_HELP, RESET_VALUE, + EDIT_FIELD, EXPORT_URDF, // PROTO actions EDIT_PROTO_SOURCE, diff --git a/src/webots/scene_tree/WbSceneTree.cpp b/src/webots/scene_tree/WbSceneTree.cpp index 91504555f36..58a65e7f9d7 100644 --- a/src/webots/scene_tree/WbSceneTree.cpp +++ b/src/webots/scene_tree/WbSceneTree.cpp @@ -125,6 +125,7 @@ WbSceneTree::WbSceneTree(QWidget *parent) : connect(mActionManager->action(WbAction::MOVE_VIEWPOINT_TO_OBJECT), &QAction::triggered, this, &WbSceneTree::moveViewpointToObject); connect(mActionManager->action(WbAction::RESET_VALUE), &QAction::triggered, this, &WbSceneTree::reset); + connect(mActionManager->action(WbAction::EDIT_FIELD), &QAction::triggered, this, &WbSceneTree::showFieldEditor); connect(mActionManager->action(WbAction::CONVERT_TO_BASE_NODES), &QAction::triggered, this, &WbSceneTree::convertToBaseNode); connect(mActionManager->action(WbAction::CONVERT_ROOT_TO_BASE_NODES), &QAction::triggered, this, &WbSceneTree::convertRootToBaseNode); @@ -268,7 +269,7 @@ void WbSceneTree::setWorld(WbWorld *world) { void WbSceneTree::showExternProtoPanel() { clearSelection(); // uncollapse the field editor - handleFieldEditorVisibility(true); + showFieldEditor(true); emit nodeSelected(NULL); mFieldEditor->editExternProto(); } @@ -1091,9 +1092,6 @@ void WbSceneTree::clearSelection() { mFieldEditor->setTitle(""); mFieldEditor->editField(NULL, NULL); - - // collapse the field editor - handleFieldEditorVisibility(false); } void WbSceneTree::enableObjectViewActions(bool enabled) { @@ -1125,6 +1123,7 @@ void WbSceneTree::updateSelection() { mSelectedItem = NULL; enableObjectViewActions(false); mActionManager->action(WbAction::OPEN_HELP)->setEnabled(false); + mActionManager->action(WbAction::EDIT_FIELD)->setEnabled(false); updateToolbar(); // no item selected return; @@ -1134,6 +1133,7 @@ void WbSceneTree::updateSelection() { mSelectedItem = NULL; enableObjectViewActions(false); mActionManager->action(WbAction::OPEN_HELP)->setEnabled(false); + mActionManager->action(WbAction::EDIT_FIELD)->setEnabled(false); updateToolbar(); return; } @@ -1155,6 +1155,7 @@ void WbSceneTree::updateSelection() { mFieldEditor->editField(node, mSelectedItem->parent()->field(), mSelectedItem->row()); } + mActionManager->action(WbAction::EDIT_FIELD)->setEnabled(mSplitter->sizes()[2] == 0); WbContextMenuGenerator::enableNodeActions(mSelectedItem->isNode()); WbContextMenuGenerator::enableRobotActions(mSelectedItem->node() && WbNodeUtilities::isRobotTypeName(mSelectedItem->node()->nodeModelName())); @@ -1194,7 +1195,7 @@ void WbSceneTree::updateSelection() { } // uncollapse the field editor - handleFieldEditorVisibility(true); + showFieldEditor(); } void WbSceneTree::startWatching(const QModelIndex &index) { @@ -1504,10 +1505,14 @@ void WbSceneTree::handleDoubleClickOrEnterPress() { (mSelectedItem->isField() && !mSelectedItem->isSFNode() && !mSelectedItem->field()->isMultiple())) mFieldEditor->currentEditor()->takeKeyboardFocus(); // default behavior, collapse/expand tree item - else if (mTreeView->isExpanded(mTreeView->currentIndex())) - mTreeView->collapse(mTreeView->currentIndex()); - else + else if (!mTreeView->isExpanded(mTreeView->currentIndex())) mTreeView->expand(mTreeView->currentIndex()); + else { + mTreeView->collapse(mTreeView->currentIndex()); + return; // do not show field editor when collasping tree item + } + + showFieldEditor(true); } void WbSceneTree::refreshTreeView() { @@ -1597,17 +1602,19 @@ void WbSceneTree::openTemplateInstanceInTextEditor() { emit editRequested(file.fileName()); } -void WbSceneTree::handleFieldEditorVisibility(bool isVisible) { +void WbSceneTree::showFieldEditor(bool force) { + if (dynamic_cast(sender()) != NULL) + force = true; + static bool hiddenByUser = false; const QList currentSize = mSplitter->sizes(); - QList sizes; - int newSize; - if (isVisible && currentSize[2] == 0) - newSize = 1; - else if (!isVisible && currentSize[2] != 0) - newSize = 0; - else + if (currentSize[2] != 0) { + hiddenByUser = true; return; - sizes << currentSize[0] << (mSplitter->height() - newSize) << newSize; + } + if (!force && hiddenByUser) + return; + QList sizes; + sizes << currentSize[0] << (mSplitter->height() - 1) << 1; mSplitter->setSizes(sizes); mSplitter->setHandleWidth(mHandleWidth); return; diff --git a/src/webots/scene_tree/WbSceneTree.hpp b/src/webots/scene_tree/WbSceneTree.hpp index f1a63ca0ebd..605ffbbe817 100644 --- a/src/webots/scene_tree/WbSceneTree.hpp +++ b/src/webots/scene_tree/WbSceneTree.hpp @@ -104,7 +104,7 @@ private slots: void openProtoInTextEditor(); void editProtoInTextEditor(); void openTemplateInstanceInTextEditor(); - void handleFieldEditorVisibility(bool isVisible); + void showFieldEditor(bool force = false); void del(WbNode *nodeToDel = NULL); diff --git a/src/webots/user_commands/WbActionManager.cpp b/src/webots/user_commands/WbActionManager.cpp index af49a774d54..788e28b1dde 100644 --- a/src/webots/user_commands/WbActionManager.cpp +++ b/src/webots/user_commands/WbActionManager.cpp @@ -1081,6 +1081,17 @@ void WbActionManager::populateActions() { newAction->setEnabled(false); mActions[RESET_VALUE] = newAction; + icon = QIcon(); + icon.addFile("enabledIcons:edit_field_button.png", QSize(), QIcon::Normal); + icon.addFile("disabledIcons:edit_field_button.png", QSize(), QIcon::Disabled); + newAction = new QAction(this); + newAction->setText(tr("&Edit...")); + newAction->setStatusTip(tr("Open field/node editor.")); + newAction->setToolTip(newAction->statusTip()); + newAction->setIcon(icon); + newAction->setEnabled(false); + mActions[EDIT_FIELD] = newAction; + newAction = new QAction(this); newAction->setText(tr("&Export URDF")); newAction->setStatusTip(tr("Export this robot model to URDF.")); diff --git a/src/webots/user_commands/WbContextMenuGenerator.cpp b/src/webots/user_commands/WbContextMenuGenerator.cpp index b9d5809e404..1d60b4ea551 100644 --- a/src/webots/user_commands/WbContextMenuGenerator.cpp +++ b/src/webots/user_commands/WbContextMenuGenerator.cpp @@ -70,6 +70,7 @@ namespace WbContextMenuGenerator { contextMenu.addAction(WbActionManager::instance()->action(WbAction::COPY)); contextMenu.addAction(WbActionManager::instance()->action(WbAction::PASTE)); contextMenu.addAction(WbActionManager::instance()->action(WbAction::RESET_VALUE)); + contextMenu.addAction(WbActionManager::instance()->action(WbAction::EDIT_FIELD)); contextMenu.addSeparator(); contextMenu.addAction(WbActionManager::instance()->action(WbAction::ADD_NEW)); contextMenu.addAction(WbActionManager::instance()->action(WbAction::DEL));