[NEW_FEATURE] Add the session file extension association feature (work copy).

Enhance the read/write config.xml to avoid crash.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@61 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2007-10-23 23:40:58 +00:00
parent 27d6d9b280
commit 0dd83435c9
4 changed files with 267 additions and 132 deletions

View File

@ -433,15 +433,24 @@ bool Notepad_plus::doOpen(const char *fileName, bool isReadOnly)
}
// if file2open matches the ext of user defined session file ext, then it'll be opened as a session
char fncp[MAX_PATH];
strcpy(fncp, longFileName);
char *pExt = PathFindExtension(fncp);
const char *definedSessionExt = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str();
if (strcmp(pExt, definedSessionExt))
if (*definedSessionExt != '\0')
{
return fileLoadSession(longFileName);
}
char fncp[MAX_PATH];
strcpy(fncp, longFileName);
char *pExt = PathFindExtension(fncp);
string usrSessionExt = "";
if (*definedSessionExt != '.')
{
usrSessionExt += ".";
}
usrSessionExt += definedSessionExt;
if (!strcmp(pExt, usrSessionExt.c_str()))
{
return fileLoadSession(longFileName);
}
}
Utf8_16_Read UnicodeConvertor;
bool isNewDoc2Close = false;

View File

@ -1624,33 +1624,43 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
{
TiXmlElement *element = childNode->ToElement();
const char *nm = element->Attribute("name");
if (!nm) return;
if (!nm) continue;
const char *val;
if (!strcmp(nm, "ToolBar"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "hide"))
_nppGUI._toolBarStatus = TB_HIDE;
else if (!strcmp(val, "small"))
_nppGUI._toolBarStatus = TB_SMALL;
else if (!strcmp(val, "large"))
_nppGUI._toolBarStatus = TB_LARGE;
else if (!strcmp(val, "standard"))
_nppGUI._toolBarStatus = TB_STANDARD;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "hide"))
_nppGUI._toolBarStatus = TB_HIDE;
else if (!strcmp(val, "small"))
_nppGUI._toolBarStatus = TB_SMALL;
else if (!strcmp(val, "large"))
_nppGUI._toolBarStatus = TB_LARGE;
else if (!strcmp(val, "standard"))
_nppGUI._toolBarStatus = TB_STANDARD;
}
}
}
else if (!strcmp(nm, "StatusBar"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "hide"))
_nppGUI._statusBarShow = false;
else if (!strcmp(val, "show"))
_nppGUI._statusBarShow = true;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "hide"))
_nppGUI._statusBarShow = false;
else if (!strcmp(val, "show"))
_nppGUI._statusBarShow = true;
}
}
}
else if (!strcmp(nm, "TabBar"))
{
@ -1718,111 +1728,170 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
}
else if (!strcmp(nm, "Auto-detection"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "no"))
_nppGUI._fileAutoDetection = cdDisabled;
else if (!strcmp(val, "auto"))
_nppGUI._fileAutoDetection = cdAutoUpdate;
else
_nppGUI._fileAutoDetection = cdEnabled;
if (!strcmp(val, "no"))
_nppGUI._fileAutoDetection = cdDisabled;
else if (!strcmp(val, "auto"))
_nppGUI._fileAutoDetection = cdAutoUpdate;
else
_nppGUI._fileAutoDetection = cdEnabled;
}
}
}
else if (!strcmp(nm, "TrayIcon"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "yes"))
_nppGUI._isMinimizedToTray = true;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "yes"))
_nppGUI._isMinimizedToTray = true;
}
}
}
else if (!strcmp(nm, "RememberLastSession"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "yes"))
_nppGUI._rememberLastSession = true;
else
_nppGUI._rememberLastSession = false;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "yes"))
_nppGUI._rememberLastSession = true;
else
_nppGUI._rememberLastSession = false;
}
}
}
else if (!strcmp(nm, "MaitainIndent"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "yes"))
_nppGUI._maitainIndent = true;
else
_nppGUI._maitainIndent = false;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "yes"))
_nppGUI._maitainIndent = true;
else
_nppGUI._maitainIndent = false;
}
}
}
else if (!strcmp(nm, "TaskList"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
_nppGUI._doTaskList = (!strcmp(val, "yes"))?true:false;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
_nppGUI._doTaskList = (!strcmp(val, "yes"))?true:false;
}
}
}
else if (!strcmp(nm, "SaveOpenFileInSameDir"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
_nppGUI._saveOpenKeepInSameDir = (!strcmp(val, "yes"))?true:false;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
_nppGUI._saveOpenKeepInSameDir = (!strcmp(val, "yes"))?true:false;
}
}
}
else if (!strcmp(nm, "MRU"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
_nppGUI._styleMRU = (!strcmp(val, "yes"))?true:false;
{
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
_nppGUI._styleMRU = (!strcmp(val, "yes"))?true:false;
}
}
}
else if (!strcmp(nm, "URL"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "1"))
_nppGUI._styleURL = 1;
else if (!strcmp(val, "2"))
_nppGUI._styleURL = 2;
else
_nppGUI._styleURL = 0;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "1"))
_nppGUI._styleURL = 1;
else if (!strcmp(val, "2"))
_nppGUI._styleURL = 2;
else
_nppGUI._styleURL = 0;
}
}
}
else if (!strcmp(nm, "CheckHistoryFiles"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "no"))
_nppGUI._checkHistoryFiles = false;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "no"))
_nppGUI._checkHistoryFiles = false;
}
}
}
else if (!strcmp(nm, "ScintillaViewsSplitter"))
{
val = (childNode->FirstChild())->Value();
if (!val) return;
if (!strcmp(val, "vertical"))
_nppGUI._splitterPos = POS_VERTICAL;
else if (!strcmp(val, "horizontal"))
_nppGUI._splitterPos = POS_HORIZOTAL;
TiXmlNode *n = childNode->FirstChild();
if (n)
{
val = n->Value();
if (val)
{
if (!strcmp(val, "vertical"))
_nppGUI._splitterPos = POS_VERTICAL;
else if (!strcmp(val, "horizontal"))
_nppGUI._splitterPos = POS_HORIZOTAL;
}
}
}
else if (!strcmp(nm, "UserDefineDlg"))
{
bool isFailed = false;
int oldValue = _nppGUI._userDefineDlgStatus;
val = (childNode->FirstChild())->Value();
if (val)
TiXmlNode *n = childNode->FirstChild();
if (n)
{
if (!strcmp(val, "hide"))
_nppGUI._userDefineDlgStatus = 0;
else if (!strcmp(val, "show"))
_nppGUI._userDefineDlgStatus = UDD_SHOW;
else
isFailed = true;
val = n->Value();
if (val)
{
if (!strcmp(val, "hide"))
_nppGUI._userDefineDlgStatus = 0;
else if (!strcmp(val, "show"))
_nppGUI._userDefineDlgStatus = UDD_SHOW;
else
isFailed = true;
}
}
val = element->Attribute("position");
if (val)
@ -1845,7 +1914,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
if ((_nppGUI._tabSize == -1) || (_nppGUI._tabSize == 0))
_nppGUI._tabSize = 8;
//bool isFailed = false;
val = element->Attribute("replaceBySpace");
if (val)
_nppGUI._tabReplacedBySpace = (!strcmp(val, "yes"));
@ -2450,12 +2519,20 @@ void NppParameters::writeGUIParams()
if (!strcmp(nm, "ToolBar"))
{
const char *pStr = _nppGUI._toolBarStatus == TB_HIDE?"hide":(_nppGUI._toolBarStatus == TB_SMALL?"small":(_nppGUI._toolBarStatus == TB_STANDARD?"standard":"large"));
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "StatusBar"))
{
const char *pStr = _nppGUI._statusBarShow?"show":"hide";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "TabBar"))
{
@ -2480,12 +2557,20 @@ void NppParameters::writeGUIParams()
else if (!strcmp(nm, "ScintillaViewsSplitter"))
{
const char *pStr = _nppGUI._splitterPos == POS_VERTICAL?"vertical":"horizontal";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "UserDefineDlg"))
{
const char *pStr = _nppGUI._userDefineDlgStatus & UDD_SHOW?"show":"hide";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
pStr = (_nppGUI._userDefineDlgStatus & UDD_DOCKED)?"docked":"undocked";
element->SetAttribute("position", pStr);
@ -2500,46 +2585,76 @@ void NppParameters::writeGUIParams()
{
autoDetectionExist = true;
const char *pStr = (cdEnabled == _nppGUI._fileAutoDetection)?"yes":((cdAutoUpdate == _nppGUI._fileAutoDetection)?"auto":"no");
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "TrayIcon"))
{
trayIconExist = true;
const char *pStr = _nppGUI._isMinimizedToTray?"yes":"no";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "RememberLastSession"))
{
rememberLastSessionExist = true;
const char *pStr = _nppGUI._rememberLastSession?"yes":"no";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "MaitainIndent"))
{
maitainIndentExist = true;
const char *pStr = _nppGUI._maitainIndent?"yes":"no";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "SaveOpenFileInSameDir"))
{
saveOpenFileInSameDirExist = true;
const char *pStr = _nppGUI._saveOpenKeepInSameDir?"yes":"no";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "TaskList"))
{
doTaskListExist = true;
const char *pStr = _nppGUI._doTaskList?"yes":"no";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "CheckHistoryFiles"))
{
checkHistoryFilesExist = true;
const char *pStr = _nppGUI._checkHistoryFiles?"yes":"no";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "AppPosition"))
{
@ -2577,7 +2692,12 @@ void NppParameters::writeGUIParams()
{
MRUExist = true;
const char *pStr = _nppGUI._styleMRU?"yes":"no";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "URL"))
{
@ -2588,7 +2708,11 @@ void NppParameters::writeGUIParams()
else if (_nppGUI._styleURL == 2)
pStr = "2";
(childNode->FirstChild())->SetValue(pStr);
TiXmlNode *n = childNode->FirstChild();
if (n)
n->SetValue(pStr);
else
childNode->InsertEndChild(TiXmlText(pStr));
}
else if (!strcmp(nm, "DockingManager"))
{

View File

@ -136,18 +136,15 @@ BEGIN
CONTROL "UCS2 small endian",IDC_RADIO_UCS2SMALL,"Button",
BS_AUTORADIOBUTTON,153,77,102,10
RTEXT "Default Language :",IDC_DEFAULTLANG_STATIC,16,110,80,8
COMBOBOX IDC_COMBO_DEFAULTLANG,100,108,72,140,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_COMBO_DEFAULTLANG,100,108,72,140,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END
IDD_PREFERENCE_LANG_BOX DIALOGEX 0, 0, 305, 147
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
LISTBOX IDC_LIST_ENABLEDLANG,54,21,78,117,LBS_NOINTEGRALHEIGHT |
WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_LIST_DISABLEDLANG,200,21,78,117,LBS_NOINTEGRALHEIGHT |
WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_LIST_ENABLEDLANG,54,21,78,117,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_LIST_DISABLEDLANG,200,21,78,117,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "->",IDC_BUTTON_REMOVE,141,53,50,14
PUSHBUTTON "<-",IDC_BUTTON_RESTORE,142,84,50,14
CTEXT "Available items",IDC_ENABLEDITEMS_STATIC,57,8,72,8
@ -158,18 +155,12 @@ IDD_PREFERENCE_PRINT_BOX DIALOGEX 0, 0, 305, 147
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CONTROL "WYSIWYG",IDC_RADIO_WYSIWYG,"Button",BS_AUTORADIOBUTTON,
16,52,123,10
CONTROL "Invert",IDC_RADIO_INVERT,"Button",BS_AUTORADIOBUTTON,16,
67,90,10
CONTROL "Black on white",IDC_RADIO_BW,"Button",
BS_AUTORADIOBUTTON,16,82,90,10
CONTROL "No background colour",IDC_RADIO_NOBG,"Button",
BS_AUTORADIOBUTTON,16,98,123,10
GROUPBOX "Colour Option",IDC_COLOUROPT_STATIC,11,32,133,96,
BS_CENTER
CONTROL "Print Line Number",IDC_CHECK_PRINTLINENUM,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,12,17,145,10
CONTROL "WYSIWYG",IDC_RADIO_WYSIWYG,"Button",BS_AUTORADIOBUTTON,16,52,123,10
CONTROL "Invert",IDC_RADIO_INVERT,"Button",BS_AUTORADIOBUTTON,16,67,90,10
CONTROL "Black on white",IDC_RADIO_BW,"Button",BS_AUTORADIOBUTTON,16,82,90,10
CONTROL "No background colour",IDC_RADIO_NOBG,"Button",BS_AUTORADIOBUTTON,16,98,123,10
GROUPBOX "Colour Option",IDC_COLOUROPT_STATIC,11,32,133,96,BS_CENTER
CONTROL "Print Line Number",IDC_CHECK_PRINTLINENUM,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,17,145,10
EDITTEXT IDC_EDIT_ML,194,75,17,14,ES_NUMBER
EDITTEXT IDC_EDIT_MT,215,56,17,14,ES_NUMBER
EDITTEXT IDC_EDIT_MR,235,75,17,14,ES_NUMBER
@ -178,8 +169,7 @@ BEGIN
CTEXT "Top",IDC_MT_STATIC,197,46,54,8
LTEXT "Right",IDC_MR_STATIC,257,78,29,8
CTEXT "Bottom",IDC_MB_STATIC,197,111,54,8
GROUPBOX "Margin Setting (Unit:mm)",IDC_MARGESETTINGS_STATIC,153,
32,144,96,BS_CENTER
GROUPBOX "Margin Setting (Unit:mm)",IDC_MARGESETTINGS_STATIC,153,32,144,96,BS_CENTER
END
IDD_PREFERENCE_PRINT2_BOX DIALOGEX 0, 0, 305, 147
@ -189,14 +179,10 @@ BEGIN
EDITTEXT IDC_EDIT_HLEFT,23,36,83,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDIT_HMIDDLE,113,36,83,14,ES_CENTER | ES_AUTOHSCROLL
EDITTEXT IDC_EDIT_HRIGHT,203,36,83,14,ES_RIGHT | ES_AUTOHSCROLL
COMBOBOX IDC_COMBO_HFONTNAME,23,54,84,104,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_COMBO_HFONTSIZE,113,54,31,72,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
CONTROL "Bold",IDC_CHECK_HBOLD,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,153,54,46,10
CONTROL "Italic",IDC_CHECK_HITALIC,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,213,54,43,10
COMBOBOX IDC_COMBO_HFONTNAME,23,54,84,104,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_COMBO_HFONTSIZE,113,54,31,72,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "Bold",IDC_CHECK_HBOLD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,153,54,46,10
CONTROL "Italic",IDC_CHECK_HITALIC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,213,54,43,10
GROUPBOX "Header",IDC_HGB_STATIC,15,17,279,56,BS_CENTER
CTEXT "Left part",IDC_HL_STATIC,25,27,79,8
CTEXT "Middle part",IDC_HM_STATIC,117,27,75,8

View File

@ -493,6 +493,8 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
::SendDlgItemMessage(_hSelf, IDC_CHECK_CLICKABLELINK_NOUNDERLINE, BM_SETCHECK, dontUnderline, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_CLICKABLELINK_NOUNDERLINE), dontUnderlineState);
::SendDlgItemMessage(_hSelf, IDC_EDIT_SESSIONFILEEXT, WM_SETTEXT, 0, (LPARAM)nppGUI._definedSessionExt.c_str());
ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture();
if (enableDlgTheme)
enableDlgTheme(_hSelf, ETDT_ENABLETAB);
@ -502,6 +504,20 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
case WM_COMMAND :
{
if (HIWORD(wParam) == EN_CHANGE)
{
switch (LOWORD(wParam))
{
case IDC_EDIT_SESSIONFILEEXT:
{
char sessionExt[MAX_PATH];
::SendDlgItemMessage(_hSelf, IDC_EDIT_SESSIONFILEEXT, WM_GETTEXT, sizeof(sessionExt), (LPARAM)sessionExt);
nppGUI._definedSessionExt = sessionExt;
return TRUE;
}
}
}
switch (wParam)
{
case IDC_CHECK_REPLACEBYSPACE: