[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
This commit is contained in:
donho 2008-09-16 18:08:42 +00:00
parent 5c6fb5e0f5
commit 836036890a
5 changed files with 35 additions and 56 deletions

View File

@ -690,18 +690,9 @@ private:
//Non existing path, usually occurs when a new 1 file is open. //Non existing path, usually occurs when a new 1 file is open.
//Set working dir to Notepad++' directory to prevent directory lock. //Set working dir to Notepad++' directory to prevent directory lock.
params->setWorkingDir(NULL); 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 else
{ {
//::SetCurrentDirectory(dir);
params->setWorkingDir(dir); params->setWorkingDir(dir);
} }
} }

View File

@ -1120,12 +1120,18 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle)
void NppParameters::setWorkingDir(const TCHAR * newPath) void NppParameters::setWorkingDir(const TCHAR * newPath)
{ {
if (newPath && newPath[0]) { if (newPath && newPath[0])
{
lstrcpyn(_currentDirectory, newPath, MAX_PATH); //dont use sizeof lstrcpyn(_currentDirectory, newPath, MAX_PATH); //dont use sizeof
} else { }
if (_nppGUI._defaultDirValid) { else
{
if (PathFileExists(_nppGUI._defaultDirExp))
{
lstrcpyn(_currentDirectory, _nppGUI._defaultDirExp, MAX_PATH); lstrcpyn(_currentDirectory, _nppGUI._defaultDirExp, MAX_PATH);
} else { }
else
{
lstrcpyn(_currentDirectory, _nppPath, MAX_PATH); lstrcpyn(_currentDirectory, _nppPath, MAX_PATH);
} }
} }
@ -2933,40 +2939,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
lstrcpyn(_nppGUI._defaultDir, path, MAX_PATH); lstrcpyn(_nppGUI._defaultDir, path, MAX_PATH);
lstrcpyn(_nppGUI._defaultDirExp, path, MAX_PATH); lstrcpyn(_nppGUI._defaultDirExp, path, MAX_PATH);
::ExpandEnvironmentStrings(_nppGUI._defaultDir, _nppGUI._defaultDirExp, 500);
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
}
} }
} }
} }

View File

@ -537,7 +537,7 @@ struct NppGUI
_isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _backup(bak_none), _useDir(false),\ _isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _backup(bak_none), _useDir(false),\
_doTaskList(true), _maitainIndent(true), _saveOpenKeepInSameDir(false), _styleMRU(true), _styleURL(0),\ _doTaskList(true), _maitainIndent(true), _saveOpenKeepInSameDir(false), _styleMRU(true), _styleURL(0),\
_autocStatus(autoc_none), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")), _neverUpdate(false),\ _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.left = 0;
_appPos.top = 0; _appPos.top = 0;
_appPos.right = 700; _appPos.right = 700;
@ -613,7 +613,6 @@ struct NppGUI
TCHAR _defaultDir[MAX_PATH]; TCHAR _defaultDir[MAX_PATH];
TCHAR _defaultDirExp[MAX_PATH]; //expanded environment variables TCHAR _defaultDirExp[MAX_PATH]; //expanded environment variables
bool _defaultDirValid;
}; };
struct ScintillaViewParams struct ScintillaViewParams

View File

@ -137,15 +137,20 @@ TCHAR * FileDialog::doOpenSingleFileDlg()
{ {
TCHAR dir[MAX_PATH]; TCHAR dir[MAX_PATH];
::GetCurrentDirectory(MAX_PATH, dir); ::GetCurrentDirectory(MAX_PATH, dir);
//_ofn.lpstrInitialDir = dir; NppParameters * params = NppParameters::getInstance();
_ofn.lpstrInitialDir = params->getWorkingDir();
_ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir();
_ofn.Flags |= OFN_FILEMUSTEXIST; _ofn.Flags |= OFN_FILEMUSTEXIST;
TCHAR *fn = NULL; TCHAR *fn = NULL;
try { try {
fn = ::GetOpenFileName((OPENFILENAME*)&_ofn)?_fileName:NULL; fn = ::GetOpenFileName((OPENFILENAME*)&_ofn)?_fileName:NULL;
if (params->getNppGUI()._saveOpenKeepInSameDir)
{
::GetCurrentDirectory(MAX_PATH, dir);
params->setWorkingDir(dir);
}
} }
catch(...) { catch(...) {
::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK);
@ -162,12 +167,17 @@ stringVector * FileDialog::doOpenMultiFilesDlg()
::GetCurrentDirectory(MAX_PATH, dir); ::GetCurrentDirectory(MAX_PATH, dir);
//_ofn.lpstrInitialDir = dir; //_ofn.lpstrInitialDir = dir;
_ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir(); NppParameters * params = NppParameters::getInstance();
_ofn.lpstrInitialDir = params->getWorkingDir();
_ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT; _ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT;
BOOL res = ::GetOpenFileName((OPENFILENAME*)&_ofn); BOOL res = ::GetOpenFileName((OPENFILENAME*)&_ofn);
if (params->getNppGUI()._saveOpenKeepInSameDir)
{
::GetCurrentDirectory(MAX_PATH, dir);
params->setWorkingDir(dir);
}
::SetCurrentDirectory(dir); ::SetCurrentDirectory(dir);
if (res) if (res)
@ -204,7 +214,8 @@ TCHAR * FileDialog::doSaveDlg()
::GetCurrentDirectory(MAX_PATH, dir); ::GetCurrentDirectory(MAX_PATH, dir);
//_ofn.lpstrInitialDir = 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; _ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING;
@ -214,6 +225,11 @@ TCHAR * FileDialog::doSaveDlg()
TCHAR *fn = NULL; TCHAR *fn = NULL;
try { try {
fn = ::GetSaveFileName((OPENFILENAME*)&_ofn)?_fileName:NULL; fn = ::GetSaveFileName((OPENFILENAME*)&_ofn)?_fileName:NULL;
if (params->getNppGUI()._saveOpenKeepInSameDir)
{
::GetCurrentDirectory(MAX_PATH, dir);
params->setWorkingDir(dir);
}
} }
catch(...) { catch(...) {
::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK);

View File

@ -42,7 +42,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
FavorSizeOrSpeed="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" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL"
MinimalRebuild="true" MinimalRebuild="true"
ExceptionHandling="2" ExceptionHandling="2"