Skip to content

Commit

Permalink
Save working directories from run to run for #360
Browse files Browse the repository at this point in the history
  • Loading branch information
markummitchell-tu committed Nov 29, 2019
1 parent a35cc8a commit 33fcb5f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const QString SETTINGS_HIGHLIGHT_OPACITY ("highlightOpacity");
const QString SETTINGS_IMAGE_REPLACE_RENAMES_DOCUMENT ("imageReplaceRenamesDocument");
const QString SETTINGS_LOCALE_COUNTRY ("country");
const QString SETTINGS_LOCALE_LANGUAGE ("language");
const QString SETTINGS_MAIN_DIRECTORY_EXPORT_SAVE ("exportSave");
const QString SETTINGS_MAIN_DIRECTORY_IMPORT_LOAD ("importLoad");
const QString SETTINGS_MAIN_TITLE_BAR_FORMAT ("titleBarFormat");
const QString SETTINGS_MAXIMUM_GRID_LINES ("maximumGridLines");
const QString SETTINGS_POS ("pos");
Expand Down
2 changes: 2 additions & 0 deletions src/Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ extern const QString SETTINGS_IMPORT_CROPPING_POS;
extern const QString SETTINGS_IMPORT_PDF_RESOLUTION;
extern const QString SETTINGS_LOCALE_COUNTRY;
extern const QString SETTINGS_LOCALE_LANGUAGE;
extern const QString SETTINGS_MAIN_DIRECTORY_EXPORT_SAVE;
extern const QString SETTINGS_MAIN_DIRECTORY_IMPORT_LOAD;
extern const QString SETTINGS_MAIN_TITLE_BAR_FORMAT;
extern const QString SETTINGS_MAXIMUM_GRID_LINES;
extern const QString SETTINGS_POS;
Expand Down
30 changes: 26 additions & 4 deletions src/main/MainDirectoryPersist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ QDir MainDirectoryPersist::getDirectoryImportOpen() const
void MainDirectoryPersist::setDirectoryExportSaveFromFilename(const QString &fileName)
{
m_setExportSave = true;
m_directoryExportSave = QFileInfo(fileName).dir();
setDirectoryExportSaveFromSavedPath (QFileInfo (fileName).dir ().absolutePath());
}

void MainDirectoryPersist::setDirectoryExportSaveFromSavedPath (const QString &path)
{
m_directoryExportSave = QDir(path);

if (!m_directoryExportSave.exists ()) {

// Directory has been (re)moved so fall back on a safe alternative
m_directoryExportSave = QDir::current ();

}

if (!m_setImportOpen) {

// Use the export directory for import since no better alternative is available
m_setImportOpen = true;
m_directoryImportOpen = m_directoryExportSave;

}
Expand All @@ -43,12 +54,23 @@ void MainDirectoryPersist::setDirectoryExportSaveFromFilename(const QString &fil
void MainDirectoryPersist::setDirectoryImportOpenFromFilename(const QString &fileName)
{
m_setImportOpen = true;
m_directoryImportOpen = QFileInfo(fileName).dir();
setDirectoryImportLoadFromSavedPath (QFileInfo (fileName).dir ().absolutePath());
}

void MainDirectoryPersist::setDirectoryImportLoadFromSavedPath (const QString &path)
{
m_directoryImportOpen = QDir (path);

if (!m_directoryImportOpen.exists ()) {

// Directory has been (re)moved so fall back on a safe alternative
m_directoryImportOpen = QDir::current ();

}

if (!m_setExportSave) {

// Use the import directory for export since no better alternative is available
m_setExportSave = true;
m_directoryExportSave = m_directoryImportOpen;

}
Expand Down
8 changes: 8 additions & 0 deletions src/main/MainDirectoryPersist.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ class MainDirectoryPersist
/// Save the current Export/Save directory, after user has accepted the Export/Save dialog
void setDirectoryExportSaveFromFilename (const QString &fileName);

/// Set the current Export/Save directory at startup to path from previous execution. When
/// called within this class the path is not saved from the previous execution
void setDirectoryExportSaveFromSavedPath (const QString &path);

/// Save the current Import/Open directory, after user has accepted the Import/Open dialog
void setDirectoryImportOpenFromFilename (const QString &fileName);

/// Set the current Import/Open directory at startup to path from previous execution. When
/// called within this class the path is not saved from the previous execution
void setDirectoryImportLoadFromSavedPath (const QString &path);

private:

// The directories are static so all instances of this class share the same values
Expand Down
15 changes: 14 additions & 1 deletion src/main/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ void MainWindow::settingsReadEnvironment (QSettings &settings)
}

void MainWindow::settingsReadMainWindow (QSettings &settings)
{
{
settings.beginGroup(SETTINGS_GROUP_MAIN_WINDOW);

// Main window geometry
Expand Down Expand Up @@ -1712,6 +1712,13 @@ void MainWindow::settingsReadMainWindow (QSettings &settings)
m_modelMainWindow.setImageReplaceRenamesDocument (settings.value (SETTINGS_IMAGE_REPLACE_RENAMES_DOCUMENT,
QVariant (DEFAULT_IMAGE_REPLACE_RENAMES_DOCUMENT)).toBool ());

// MainDirectoryPersist starts with directories from last execution
MainDirectoryPersist directoryPersist;
directoryPersist.setDirectoryExportSaveFromSavedPath (settings.value (SETTINGS_MAIN_DIRECTORY_EXPORT_SAVE,
QVariant (QDir::currentPath())).toString ());
directoryPersist.setDirectoryImportLoadFromSavedPath (settings.value (SETTINGS_MAIN_DIRECTORY_IMPORT_LOAD,
QVariant (QDir::currentPath())).toString ());

updateSettingsMainWindow();
updateSmallDialogs();

Expand All @@ -1720,6 +1727,8 @@ void MainWindow::settingsReadMainWindow (QSettings &settings)

void MainWindow::settingsWrite ()
{
MainDirectoryPersist directoryPersist;

QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);

settings.beginGroup (SETTINGS_GROUP_ENVIRONMENT);
Expand Down Expand Up @@ -1770,6 +1779,10 @@ void MainWindow::settingsWrite ()
settings.setValue (SETTINGS_IMPORT_PDF_RESOLUTION, m_modelMainWindow.pdfResolution ());
settings.setValue (SETTINGS_LOCALE_LANGUAGE, m_modelMainWindow.locale().language());
settings.setValue (SETTINGS_LOCALE_COUNTRY, m_modelMainWindow.locale().country());
settings.setValue (SETTINGS_MAIN_DIRECTORY_EXPORT_SAVE,
directoryPersist.getDirectoryExportSave().absolutePath());
settings.setValue (SETTINGS_MAIN_DIRECTORY_IMPORT_LOAD,
directoryPersist.getDirectoryImportOpen().absolutePath());
settings.setValue (SETTINGS_MAIN_TITLE_BAR_FORMAT, m_modelMainWindow.mainTitleBarFormat());
settings.setValue (SETTINGS_MAXIMUM_GRID_LINES, m_modelMainWindow.maximumGridLines());
settings.setValue (SETTINGS_SMALL_DIALOGS, m_modelMainWindow.smallDialogs());
Expand Down

0 comments on commit 33fcb5f

Please sign in to comment.