diff --git a/bt_editor/mainwindow.cpp b/bt_editor/mainwindow.cpp index 3b135175..a37f5a14 100644 --- a/bt_editor/mainwindow.cpp +++ b/bt_editor/mainwindow.cpp @@ -148,6 +148,7 @@ MainWindow::MainWindow(GraphicMode initial_mode, connect( redo_shortcut, &QShortcut::activated, this, &MainWindow::onRedoInvoked ); QShortcut* save_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this); + QShortcut* save_as_shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S), this); connect( _editor_widget, &SidepanelEditor::nodeModelEdited, this, &MainWindow::onTreeNodeEdited); @@ -204,6 +205,11 @@ MainWindow::MainWindow(GraphicMode initial_mode, connect( save_shortcut, &QShortcut::activated, this, &MainWindow::on_actionSave_triggered ); + connect( ui->toolButtonSaveAsFile, &QToolButton::clicked, + this, &MainWindow::on_actionSaveAs_triggered ); + + connect( save_as_shortcut, &QShortcut::activated, this, &MainWindow::on_actionSaveAs_triggered ); + connect( _replay_widget, &SidepanelReplay::changeNodeStyle, this, &MainWindow::onChangeNodesStatus); @@ -433,23 +439,25 @@ void MainWindow::on_actionLoad_triggered() QString directory_path = settings.value("MainWindow.lastLoadDirectory", QDir::homePath() ).toString(); - QString fileName = QFileDialog::getOpenFileName(this, + QString filePath = QFileDialog::getOpenFileName(this, tr("Load BehaviorTree from file"), directory_path, tr("BehaviorTree files (*.xml)")); - if (!QFileInfo::exists(fileName)){ + if (!QFileInfo::exists(filePath)){ return; } - QFile file(fileName); + QFile file(filePath); if (!file.open(QIODevice::ReadOnly)){ return; } - directory_path = QFileInfo(fileName).absolutePath(); + directory_path = QFileInfo(filePath).absolutePath(); settings.setValue("MainWindow.lastLoadDirectory", directory_path); settings.sync(); + _loaded_tree_file_path = filePath; + QString xml_text; QTextStream in(&file); @@ -633,7 +641,7 @@ void MainWindow::recursivelySaveNodeCanonically(QXmlStreamWriter &stream, const } } -void MainWindow::on_actionSave_triggered() +void MainWindow::saveTree(QString loadedPath) { for (auto& it: _tab_info) { @@ -656,26 +664,46 @@ void MainWindow::on_actionSave_triggered() QString directory_path = settings.value("MainWindow.lastSaveDirectory", QDir::currentPath() ).toString(); - auto fileName = QFileDialog::getSaveFileName(this, "Save BehaviorTree to file", + auto filePath = loadedPath; + if(filePath.isEmpty()) + { + filePath = QFileDialog::getSaveFileName(this, "Save BehaviorTree to file", directory_path, "BehaviorTree files (*.xml)"); - if (fileName.isEmpty()){ + } + + if (filePath.isEmpty()) + { return; } - if (!fileName.endsWith(".xml")) + + if (!filePath.endsWith(".xml")) { - fileName += ".xml"; + filePath += ".xml"; } QString xml_text = saveToXML(); - QFile file(fileName); + QFile file(filePath); if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); stream << xml_text; } - directory_path = QFileInfo(fileName).absolutePath(); + directory_path = QFileInfo(filePath).absolutePath(); settings.setValue("MainWindow.lastSaveDirectory", directory_path); + _loaded_tree_file_path = filePath; + +} + +void MainWindow::on_actionSave_triggered() +{ + saveTree(_loaded_tree_file_path); +} + + +void MainWindow::on_actionSaveAs_triggered() +{ + saveTree(); } void MainWindow::onAutoArrange() diff --git a/bt_editor/mainwindow.h b/bt_editor/mainwindow.h index 56af8823..020a7393 100644 --- a/bt_editor/mainwindow.h +++ b/bt_editor/mainwindow.h @@ -98,6 +98,8 @@ public slots: void on_actionSave_triggered(); + void on_actionSaveAs_triggered(); + void onSubtreeSelected(const QString& subtreeName); void on_splitter_splitterMoved(int pos = 0, int index = 0); @@ -206,6 +208,8 @@ private slots: QString _main_tree; + QString _loaded_tree_file_path; + SidepanelEditor* _editor_widget; SidepanelReplay* _replay_widget; #ifdef ZMQ_FOUND @@ -219,6 +223,7 @@ private slots: MainWindow::SavedState saveCurrentState(); void clearUndoStacks(); + void saveTree(QString loadedPath = ""); }; diff --git a/bt_editor/mainwindow.ui b/bt_editor/mainwindow.ui index 8410449b..7fe662cc 100644 --- a/bt_editor/mainwindow.ui +++ b/bt_editor/mainwindow.ui @@ -366,6 +366,74 @@ QToolButton:disabled{ + + + + + 80 + 70 + + + + + 80 + 70 + + + + + 9 + + + + Qt::NoFocus + + + false + + + QToolButton { + color:white; +} + +QToolButton:hover{ + background-color: rgb(110, 110, 110); +} + +QToolButton:pressed{ + background-color: rgb(50, 150, 0) +} + +QToolButton:disabled{ + color:gray; + background-color: rgb(50, 50, 50) +} + + + + Save Tree As + + + + :/icons/svg/save_white.svg:/icons/svg/save_white.svg + + + + 34 + 34 + + + + false + + + Qt::ToolButtonTextUnderIcon + + + true + + + @@ -858,6 +926,14 @@ QToolButton:disabled{ Ctrl+S + + + Save + + + Ctrl+Shift+S + + Quit