From 836036890a7597da79574db17259e4efbf8c12f6 Mon Sep 17 00:00:00 2001 From: donho Date: Tue, 16 Sep 2008 18:08:42 +0000 Subject: [PATCH] [BUG_FIXED] Fix "Remember the last operation Dir" bug. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@322 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.h | 9 ---- PowerEditor/src/Parameters.cpp | 49 +++++-------------- PowerEditor/src/Parameters.h | 3 +- .../OpenSaveFileDialog/FileDialog.cpp | 28 ++++++++--- PowerEditor/visual.net/notepadPlus.vcproj | 2 +- 5 files changed, 35 insertions(+), 56 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index daccdc8e..f48b38ae 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -690,18 +690,9 @@ private: //Non existing path, usually occurs when a new 1 file is open. //Set working dir to Notepad++' directory to prevent directory lock. params->setWorkingDir(NULL); - /* - TCHAR nppDir[MAX_PATH]; - - //wParam set to max_path in case boundary checks will ever be made. - SendMessage(_hSelf, NPPM_GETNPPDIRECTORY, (WPARAM)MAX_PATH, (LPARAM)nppDir); - ::SetCurrentDirectory(nppDir); - */ - return; } else { - //::SetCurrentDirectory(dir); params->setWorkingDir(dir); } } diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 400959e6..92fc4892 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1120,12 +1120,18 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle) void NppParameters::setWorkingDir(const TCHAR * newPath) { - if (newPath && newPath[0]) { + if (newPath && newPath[0]) + { lstrcpyn(_currentDirectory, newPath, MAX_PATH); //dont use sizeof - } else { - if (_nppGUI._defaultDirValid) { + } + else + { + if (PathFileExists(_nppGUI._defaultDirExp)) + { lstrcpyn(_currentDirectory, _nppGUI._defaultDirExp, MAX_PATH); - } else { + } + else + { lstrcpyn(_currentDirectory, _nppPath, MAX_PATH); } } @@ -2933,40 +2939,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) lstrcpyn(_nppGUI._defaultDir, path, MAX_PATH); lstrcpyn(_nppGUI._defaultDirExp, path, MAX_PATH); - - EESFUNC eesfunc = NULL; //MSDN doesnt list 98 as having this func, so load dynamically, fallback to DoEnvironmentSubst - - HMODULE hKernel = ::LoadLibrary(TEXT("Kernel32.dll")); - if (hKernel) { -#ifdef UNICODE - eesfunc = (EESFUNC)::GetProcAddress(hKernel, "ExpandEnvironmentStringsW"); -#else - eesfunc = (EESFUNC)::GetProcAddress(hKernel, "ExpandEnvironmentStringsA"); -#endif - } - - BOOL res = TRUE;//FALSE; - if (eesfunc) { - DWORD dres = eesfunc(_nppGUI._defaultDir, _nppGUI._defaultDirExp, 500); - if (dres >= MAX_PATH) { - res = FALSE; - } else { - res = TRUE; - } - } else { - //::MessageBox(0,TEXT("Fallback"), 0, 0); - DWORD dres = ::DoEnvironmentSubst(_nppGUI._defaultDirExp, MAX_PATH); - res = LOWORD(dres); - } - - - if (res == FALSE) { - _nppGUI._defaultDirValid = false; //unable to expand, cannot be used - } else if (!PathFileExists(_nppGUI._defaultDirExp)) { - _nppGUI._defaultDirValid = false; //invalid path, cannot be used - } else { - _nppGUI._defaultDirValid = true; //can use default path as override - } + ::ExpandEnvironmentStrings(_nppGUI._defaultDir, _nppGUI._defaultDirExp, 500); } } } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 335f2671..8fbda8df 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -537,7 +537,7 @@ struct NppGUI _isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _backup(bak_none), _useDir(false),\ _doTaskList(true), _maitainIndent(true), _saveOpenKeepInSameDir(false), _styleMRU(true), _styleURL(0),\ _autocStatus(autoc_none), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")), _neverUpdate(false),\ - _doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _defaultDirValid(false) { + _doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1) { _appPos.left = 0; _appPos.top = 0; _appPos.right = 700; @@ -613,7 +613,6 @@ struct NppGUI TCHAR _defaultDir[MAX_PATH]; TCHAR _defaultDirExp[MAX_PATH]; //expanded environment variables - bool _defaultDirValid; }; struct ScintillaViewParams diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp index eee66e12..b7b9600c 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -137,15 +137,20 @@ TCHAR * FileDialog::doOpenSingleFileDlg() { TCHAR dir[MAX_PATH]; ::GetCurrentDirectory(MAX_PATH, dir); - //_ofn.lpstrInitialDir = dir; - - _ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir(); + NppParameters * params = NppParameters::getInstance(); + _ofn.lpstrInitialDir = params->getWorkingDir(); _ofn.Flags |= OFN_FILEMUSTEXIST; TCHAR *fn = NULL; try { fn = ::GetOpenFileName((OPENFILENAME*)&_ofn)?_fileName:NULL; + + if (params->getNppGUI()._saveOpenKeepInSameDir) + { + ::GetCurrentDirectory(MAX_PATH, dir); + params->setWorkingDir(dir); + } } catch(...) { ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); @@ -162,12 +167,17 @@ stringVector * FileDialog::doOpenMultiFilesDlg() ::GetCurrentDirectory(MAX_PATH, dir); //_ofn.lpstrInitialDir = dir; - _ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir(); + NppParameters * params = NppParameters::getInstance(); + _ofn.lpstrInitialDir = params->getWorkingDir(); _ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT; BOOL res = ::GetOpenFileName((OPENFILENAME*)&_ofn); - + if (params->getNppGUI()._saveOpenKeepInSameDir) + { + ::GetCurrentDirectory(MAX_PATH, dir); + params->setWorkingDir(dir); + } ::SetCurrentDirectory(dir); if (res) @@ -204,7 +214,8 @@ TCHAR * FileDialog::doSaveDlg() ::GetCurrentDirectory(MAX_PATH, dir); //_ofn.lpstrInitialDir = dir; - _ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir(); + NppParameters * params = NppParameters::getInstance(); + _ofn.lpstrInitialDir = params->getWorkingDir(); _ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING; @@ -214,6 +225,11 @@ TCHAR * FileDialog::doSaveDlg() TCHAR *fn = NULL; try { fn = ::GetSaveFileName((OPENFILENAME*)&_ofn)?_fileName:NULL; + if (params->getNppGUI()._saveOpenKeepInSameDir) + { + ::GetCurrentDirectory(MAX_PATH, dir); + params->setWorkingDir(dir); + } } catch(...) { ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj index 9b811366..b61a9a4c 100644 --- a/PowerEditor/visual.net/notepadPlus.vcproj +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception" + AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL" MinimalRebuild="true" ExceptionHandling="2"