[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.
//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);
}
}

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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);

View File

@ -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"