Skip to content

Commit

Permalink
Remember the directory of "Remember last used directory" through sess…
Browse files Browse the repository at this point in the history
…ions

Fix #11326, fix #10901, fix #4961, fix #4119, close #13887
  • Loading branch information
molsonkiko authored and donho committed Jul 21, 2023
1 parent eef91b0 commit ff2179a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5743,6 +5743,12 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
lstrcpyn(_nppGUI._defaultDir, path, MAX_PATH);
::ExpandEnvironmentStrings(_nppGUI._defaultDir, _nppGUI._defaultDirExp, MAX_PATH);
}

const TCHAR* path2 = element->Attribute(TEXT("lastUsedDirPath"));
if (path2 && path2[0])
{
lstrcpyn(_nppGUI._lastUsedDir, path2, MAX_PATH);
}
}

else if (!lstrcmp(nm, TEXT("titleBar")))
Expand Down Expand Up @@ -7171,6 +7177,7 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->SetAttribute(TEXT("name"), TEXT("openSaveDir"));
GUIConfigElement->SetAttribute(TEXT("value"), _nppGUI._openSaveDir);
GUIConfigElement->SetAttribute(TEXT("defaultDirPath"), _nppGUI._defaultDir);
GUIConfigElement->SetAttribute(TEXT("lastUsedDirPath"), _nppGUI._lastUsedDir);
}

// <GUIConfig name="titleBar" short="no" />
Expand Down
3 changes: 3 additions & 0 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ struct NppGUI final

_defaultDir[0] = 0;
_defaultDirExp[0] = 0;
_lastUsedDir[0] = 0;
}

toolBarStatusType _toolBarStatus = TB_STANDARD;
Expand Down Expand Up @@ -887,6 +888,8 @@ struct NppGUI final

TCHAR _defaultDir[MAX_PATH];
TCHAR _defaultDirExp[MAX_PATH]; //expanded environment variables
TCHAR _lastUsedDir[MAX_PATH];

generic_string _themeName;
MultiInstSetting _multiInstSetting = monoInst;
bool _clipboardHistoryPanelKeepState = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,12 @@ class CustomFileDialog::Impl
okPressed = SUCCEEDED(hr);

NppParameters& params = NppParameters::getInstance();
if (okPressed && params.getNppGUI()._openSaveDir == dir_last)
NppGUI& nppGUI = params.getNppGUI();
if (okPressed && nppGUI._openSaveDir == dir_last)
{
// Note: IFileDialog doesn't modify the current directory.
// At least, after it is hidden, the current directory is the same as before it was shown.
lstrcpyn(nppGUI._lastUsedDir, _events->getLastUsedFolder().c_str(), MAX_PATH);
params.setWorkingDir(_events->getLastUsedFolder().c_str());
}
}
Expand Down Expand Up @@ -986,7 +988,8 @@ CustomFileDialog::CustomFileDialog(HWND hwnd) : _impl{ std::make_unique<Impl>()
_impl->_hwndOwner = hwnd;

NppParameters& params = NppParameters::getInstance();
const TCHAR* workDir = params.getWorkingDir();
NppGUI& nppGUI = params.getNppGUI();
const TCHAR* workDir = nppGUI._openSaveDir == dir_last ? nppGUI._lastUsedDir : params.getWorkingDir();
if (workDir)
_impl->_fallbackFolder = workDir;
}
Expand Down

0 comments on commit ff2179a

Please sign in to comment.