Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Correctly Set Working Directory in GUI #1829

Merged
merged 14 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class DissolveWindow : public QMainWindow
const int recentFileLimit_;

private:
// Set the input file path
void setInputFilename(const QString filename);
rhinoella marked this conversation as resolved.
Show resolved Hide resolved
// Check whether current input needs to be saved and, if so, if it saved successfully
bool checkSaveCurrentInput();
// Clear all data and start new simulation afresh
Expand Down
20 changes: 13 additions & 7 deletions src/gui/menu_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
#include <QMessageBox>
#include <QSettings>

// Set the input filename and the working directory of dissolve
void DissolveWindow::setInputFilename(const QString filename)
rhinoella marked this conversation as resolved.
Show resolved Hide resolved
{
QFileInfo inputFileInfo(filename);
QDir::setCurrent(inputFileInfo.absoluteDir().absolutePath());

dissolve_.setInputFilename(qPrintable(filename));
}

// Check whether current input needs to be saved and, if so, if it saved successfully
bool DissolveWindow::checkSaveCurrentInput()
{
Expand All @@ -32,7 +41,7 @@ bool DissolveWindow::checkSaveCurrentInput()
if (newFile.isEmpty())
return false;

dissolve_.setInputFilename(qPrintable(newFile));
setInputFilename(newFile);
}

// Save the file
Expand Down Expand Up @@ -243,7 +252,7 @@ void DissolveWindow::on_FileSaveAction_triggered(bool checked)
if (newFile.isEmpty())
return;

dissolve_.setInputFilename(qPrintable(newFile));
setInputFilename(newFile);

addRecentFile(newFile);
}
Expand All @@ -270,17 +279,14 @@ void DissolveWindow::on_FileSaveAsAction_triggered(bool checked)
if (newFile.isEmpty())
return;

dissolve_.setInputFilename(qPrintable(newFile));

// Attempt to save the file
if (!dissolve_.saveInput(dissolve_.inputFilename()))
if (!dissolve_.saveInput(qPrintable(newFile)))
return;

modified_ = false;

// Update the current working directory to be local to the new input file
QFileInfo inputFileInfo(newFile);
QDir::setCurrent(inputFileInfo.absoluteDir().absolutePath());
setInputFilename(newFile);

addRecentFile(newFile);

Expand Down