Add hidden capability of setting default directory (with envvars).
No more directory locks (can freely delete all directories). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@309 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
8c70585f27
commit
521c53918f
@ -6592,15 +6592,16 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
_findReplaceDlg.launchFindInFilesDlg();
|
||||
|
||||
const TCHAR *dir = NULL;
|
||||
TCHAR currentDir[MAX_PATH];
|
||||
//TCHAR currentDir[MAX_PATH];
|
||||
basic_string<TCHAR> fltr;
|
||||
|
||||
if (wParam)
|
||||
dir = (const TCHAR *)wParam;
|
||||
else
|
||||
{
|
||||
::GetCurrentDirectory(MAX_PATH, currentDir);
|
||||
dir = currentDir;
|
||||
//::GetCurrentDirectory(MAX_PATH, currentDir);
|
||||
//dir = currentDir;
|
||||
dir = NppParameters::getInstance()->getWorkingDir();
|
||||
}
|
||||
|
||||
if (lParam)
|
||||
|
@ -680,22 +680,29 @@ private:
|
||||
|
||||
void doSynScorll(HWND hW);
|
||||
void setWorkingDir(TCHAR *dir) {
|
||||
if (NppParameters::getInstance()->getNppGUI()._saveOpenKeepInSameDir)
|
||||
NppParameters * params = NppParameters::getInstance();
|
||||
if (params->getNppGUI()._saveOpenKeepInSameDir)
|
||||
return;
|
||||
|
||||
if (!dir || !PathIsDirectory(dir))
|
||||
{
|
||||
//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);
|
||||
{
|
||||
//::SetCurrentDirectory(dir);
|
||||
params->setWorkingDir(dir);
|
||||
}
|
||||
}
|
||||
bool str2Cliboard(const TCHAR *str2cpy);
|
||||
bool bin2Cliboard(const UCHAR *uchar2cpy, size_t length);
|
||||
|
@ -435,6 +435,11 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
|
||||
PathRemoveFileSpec(nppPath);
|
||||
lstrcpy(_nppPath, nppPath);
|
||||
|
||||
//Initialize current directory to startup directory
|
||||
::GetCurrentDirectory(MAX_PATH, _currentDirectory);
|
||||
//lstrcpy(_currentDirectory, nppPath);
|
||||
::SetCurrentDirectory(_nppPath); //force working directory to path of module, preventing lock
|
||||
|
||||
_appdataNppDir[0] = '\0';
|
||||
TCHAR notepadStylePath[MAX_PATH];
|
||||
lstrcpy(notepadStylePath, _nppPath);
|
||||
@ -1113,6 +1118,19 @@ bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle)
|
||||
return true;
|
||||
}
|
||||
|
||||
void NppParameters::setWorkingDir(const TCHAR * newPath)
|
||||
{
|
||||
if (newPath && newPath[0]) {
|
||||
lstrcpyn(_currentDirectory, newPath, MAX_PATH); //dont use sizeof
|
||||
} else {
|
||||
if (_nppGUI._defaultDirValid) {
|
||||
lstrcpyn(_currentDirectory, _nppGUI._defaultDirExp, MAX_PATH);
|
||||
} else {
|
||||
lstrcpyn(_currentDirectory, _nppPath, MAX_PATH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool NppParameters::loadSession(Session & session, const TCHAR *sessionFileName)
|
||||
{
|
||||
TiXmlDocument *pXmlSessionDocument = new TiXmlDocument(sessionFileName);
|
||||
@ -2903,6 +2921,23 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!lstrcmp(nm, TEXT("defaultDir")))
|
||||
{
|
||||
const TCHAR * path = element->Attribute(TEXT("path"));
|
||||
if (path && path[0])
|
||||
{
|
||||
lstrcpyn(_nppGUI._defaultDir, path, MAX_PATH);
|
||||
lstrcpyn(_nppGUI._defaultDirExp, path, MAX_PATH);
|
||||
DWORD res = DoEnvironmentSubst(_nppGUI._defaultDirExp, MAX_PATH);
|
||||
if (LOWORD(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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -3188,6 +3223,7 @@ bool NppParameters::writeGUIParams()
|
||||
bool smartHighLightExist = false;
|
||||
bool tagsMatchHighLightExist = false;
|
||||
bool caretExist = false;
|
||||
bool defaultDirExist = false;
|
||||
|
||||
TiXmlNode *dockingParamNode = NULL;
|
||||
|
||||
@ -3521,6 +3557,11 @@ bool NppParameters::writeGUIParams()
|
||||
else
|
||||
childNode->InsertEndChild(TiXmlText(pStr));
|
||||
}
|
||||
else if (!lstrcmp(nm, TEXT("defaultDir")))
|
||||
{
|
||||
defaultDirExist = true;
|
||||
element->SetAttribute(TEXT("path"), _nppGUI._defaultDir);
|
||||
}
|
||||
}
|
||||
|
||||
if (!noUpdateExist)
|
||||
@ -3691,6 +3732,13 @@ bool NppParameters::writeGUIParams()
|
||||
GUIConfigElement->SetAttribute(TEXT("blinkRate"), _nppGUI._caretBlinkRate);
|
||||
}
|
||||
|
||||
if (!defaultDirExist)
|
||||
{
|
||||
TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement();
|
||||
GUIConfigElement->SetAttribute(TEXT("name"), TEXT("defaultDir"));
|
||||
GUIConfigElement->SetAttribute(TEXT("path"), _nppGUI._defaultDir);
|
||||
}
|
||||
|
||||
insertDockingParamNode(GUIRoot);
|
||||
return true;
|
||||
}
|
||||
|
@ -538,13 +538,15 @@ 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){
|
||||
_doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _defaultDirValid(false) {
|
||||
_appPos.left = 0;
|
||||
_appPos.top = 0;
|
||||
_appPos.right = 700;
|
||||
_appPos.bottom = 500;
|
||||
|
||||
_backupDir[0] = '\0';
|
||||
_defaultDir[0] = 0;
|
||||
_defaultDirExp[0] = 0;
|
||||
};
|
||||
toolBarStatusType _toolBarStatus; // small, large ou standard
|
||||
bool _toolbarShow;
|
||||
@ -609,6 +611,10 @@ struct NppGUI
|
||||
bool _doesExistUpdater;
|
||||
int _caretBlinkRate;
|
||||
int _caretWidth;
|
||||
|
||||
TCHAR _defaultDir[MAX_PATH];
|
||||
TCHAR _defaultDirExp[MAX_PATH]; //expanded environment variables
|
||||
bool _defaultDirValid;
|
||||
};
|
||||
|
||||
struct ScintillaViewParams
|
||||
@ -1032,6 +1038,8 @@ public:
|
||||
|
||||
const TCHAR * getNppPath() const {return _nppPath;};
|
||||
const TCHAR * getAppDataNppDir() const {return _appdataNppDir;};
|
||||
const TCHAR * getWorkingDir() const {return _currentDirectory;};
|
||||
void setWorkingDir(const TCHAR * newPath);
|
||||
|
||||
bool loadSession(Session & session, const TCHAR *sessionFileName);
|
||||
int langTypeToCommandID(LangType lt) const;
|
||||
@ -1154,6 +1162,7 @@ private:
|
||||
TCHAR _sessionPath[MAX_PATH];
|
||||
TCHAR _nppPath[MAX_PATH];
|
||||
TCHAR _appdataNppDir[MAX_PATH]; // sentinel of the absence of "doLocalConf.xml" : (_appdataNppDir == TEXT(""))?"doLocalConf.xml present":"doLocalConf.xml absent"
|
||||
TCHAR _currentDirectory[MAX_PATH];
|
||||
|
||||
Accelerator *_pAccelerator;
|
||||
ScintillaAccelerator * _pScintAccelerator;
|
||||
|
@ -474,9 +474,10 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
|
||||
doDialog((DIALOG_TYPE)indexClicked);
|
||||
if ((DIALOG_TYPE)indexClicked == FINDINFILES_DLG)
|
||||
{
|
||||
TCHAR currentDir[MAX_PATH];
|
||||
::GetCurrentDirectory(MAX_PATH, currentDir);
|
||||
setFindInFilesDirFilter(currentDir, NULL);
|
||||
//TCHAR currentDir[MAX_PATH];
|
||||
//::GetCurrentDirectory(MAX_PATH, currentDir);
|
||||
//setFindInFilesDirFilter(currentDir, NULL);
|
||||
setFindInFilesDirFilter(NppParameters::getInstance()->getWorkingDir(), NULL);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -136,8 +136,10 @@ int FileDialog::setExtsFilter(const TCHAR *extText, const TCHAR *exts)
|
||||
TCHAR * FileDialog::doOpenSingleFileDlg()
|
||||
{
|
||||
TCHAR dir[MAX_PATH];
|
||||
::GetCurrentDirectory(sizeof(dir), dir);
|
||||
_ofn.lpstrInitialDir = dir;
|
||||
::GetCurrentDirectory(MAX_PATH, dir);
|
||||
//_ofn.lpstrInitialDir = dir;
|
||||
|
||||
_ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir();
|
||||
|
||||
_ofn.Flags |= OFN_FILEMUSTEXIST;
|
||||
|
||||
@ -148,18 +150,27 @@ TCHAR * FileDialog::doOpenSingleFileDlg()
|
||||
catch(...) {
|
||||
::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK);
|
||||
}
|
||||
|
||||
::SetCurrentDirectory(dir);
|
||||
|
||||
return (fn);
|
||||
}
|
||||
|
||||
stringVector * FileDialog::doOpenMultiFilesDlg()
|
||||
{
|
||||
TCHAR dir[MAX_PATH];
|
||||
::GetCurrentDirectory(sizeof(dir), dir);
|
||||
_ofn.lpstrInitialDir = dir;
|
||||
::GetCurrentDirectory(MAX_PATH, dir);
|
||||
//_ofn.lpstrInitialDir = dir;
|
||||
|
||||
_ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir();
|
||||
|
||||
_ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT;
|
||||
|
||||
if (::GetOpenFileName((OPENFILENAME*)&_ofn))
|
||||
BOOL res = ::GetOpenFileName((OPENFILENAME*)&_ofn);
|
||||
|
||||
::SetCurrentDirectory(dir);
|
||||
|
||||
if (res)
|
||||
{
|
||||
TCHAR fn[MAX_PATH];
|
||||
TCHAR *pFn = _fileName + lstrlen(_fileName) + 1;
|
||||
@ -190,9 +201,10 @@ stringVector * FileDialog::doOpenMultiFilesDlg()
|
||||
TCHAR * FileDialog::doSaveDlg()
|
||||
{
|
||||
TCHAR dir[MAX_PATH];
|
||||
::GetCurrentDirectory(sizeof(dir), dir);
|
||||
::GetCurrentDirectory(MAX_PATH, dir);
|
||||
//_ofn.lpstrInitialDir = dir;
|
||||
|
||||
_ofn.lpstrInitialDir = dir;
|
||||
_ofn.lpstrInitialDir = NppParameters::getInstance()->getWorkingDir();
|
||||
|
||||
_ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING;
|
||||
|
||||
@ -206,6 +218,9 @@ TCHAR * FileDialog::doSaveDlg()
|
||||
catch(...) {
|
||||
::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK);
|
||||
}
|
||||
|
||||
::SetCurrentDirectory(dir);
|
||||
|
||||
return (fn);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user