[NEW_FEATURE] Add import/export User Defined Language features.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@632 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
0bb88d079b
commit
a82f2de60b
|
@ -1186,19 +1186,20 @@ bool NppParameters::getUserParametersFromXmlTree()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool NppParameters::getUserDefineLangsFromXmlTree()
|
||||
bool NppParameters::getUserDefineLangsFromXmlTree(TiXmlDocument *tixmldoc)
|
||||
{
|
||||
if (!_pXmlUserLangDoc)
|
||||
if (!tixmldoc)
|
||||
return false;
|
||||
|
||||
TiXmlNode *root = _pXmlUserLangDoc->FirstChild(TEXT("NotepadPlus"));
|
||||
TiXmlNode *root = tixmldoc->FirstChild(TEXT("NotepadPlus"));
|
||||
if (!root)
|
||||
return false;
|
||||
|
||||
feedUserLang(root);
|
||||
return true;
|
||||
return feedUserLang(root);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool NppParameters::getShortcutsFromXmlTree()
|
||||
{
|
||||
if (!_pXmlShortcutDoc)
|
||||
|
@ -2006,14 +2007,18 @@ bool NppParameters::getShortcuts(TiXmlNode *node, Shortcut & sc)
|
|||
|
||||
const int loadFailed = 100;
|
||||
const int missingName = 101;
|
||||
void NppParameters::feedUserLang(TiXmlNode *node)
|
||||
bool NppParameters::feedUserLang(TiXmlNode *node)
|
||||
{
|
||||
bool isEverythingOK = true;
|
||||
bool hasFoundElement = false;
|
||||
|
||||
for (TiXmlNode *childNode = node->FirstChildElement(TEXT("UserLang"));
|
||||
childNode && (_nbUserLang < NB_MAX_USER_LANG);
|
||||
childNode = childNode->NextSibling(TEXT("UserLang")) )
|
||||
{
|
||||
const TCHAR *name = (childNode->ToElement())->Attribute(TEXT("name"));
|
||||
const TCHAR *ext = (childNode->ToElement())->Attribute(TEXT("ext"));
|
||||
hasFoundElement = true;
|
||||
try {
|
||||
if (!name || !name[0] || !ext) throw int(missingName);
|
||||
|
||||
|
@ -2035,8 +2040,41 @@ void NppParameters::feedUserLang(TiXmlNode *node)
|
|||
} catch (int e) {
|
||||
if (e == loadFailed)
|
||||
delete _userLangArray[--_nbUserLang];
|
||||
isEverythingOK = false;
|
||||
}
|
||||
}
|
||||
if (isEverythingOK)
|
||||
isEverythingOK = hasFoundElement;
|
||||
return isEverythingOK;
|
||||
}
|
||||
|
||||
bool NppParameters::importUDLFromFile(generic_string sourceFile)
|
||||
{
|
||||
TiXmlDocument *pXmlUserLangDoc = new TiXmlDocument(sourceFile);
|
||||
bool loadOkay = pXmlUserLangDoc->LoadFile();
|
||||
if (loadOkay)
|
||||
{
|
||||
loadOkay = getUserDefineLangsFromXmlTree(pXmlUserLangDoc);
|
||||
}
|
||||
delete pXmlUserLangDoc;
|
||||
return loadOkay;
|
||||
}
|
||||
|
||||
bool NppParameters::exportUDLToFile(int langIndex2export, generic_string fileName2save)
|
||||
{
|
||||
if (langIndex2export != -1 && langIndex2export >= _nbUserLang)
|
||||
return false;
|
||||
|
||||
TiXmlDocument *pNewXmlUserLangDoc = new TiXmlDocument(fileName2save);
|
||||
TiXmlNode *newRoot2export = pNewXmlUserLangDoc->InsertEndChild(TiXmlElement(TEXT("NotepadPlus")));
|
||||
|
||||
bool b = false;
|
||||
|
||||
insertUserLang2Tree(newRoot2export, _userLangArray[langIndex2export]);
|
||||
b = pNewXmlUserLangDoc->SaveFile();
|
||||
|
||||
delete pNewXmlUserLangDoc;
|
||||
return b;
|
||||
}
|
||||
|
||||
LangType NppParameters::getLangFromExt(const TCHAR *ext)
|
||||
|
@ -2100,6 +2138,7 @@ void NppParameters::writeUserDefinedLang()
|
|||
stylerStrOp(FREE);
|
||||
}
|
||||
|
||||
|
||||
void NppParameters::insertCmd(TiXmlNode *shortcutsRoot, const CommandShortcut & cmd)
|
||||
{
|
||||
const KeyCombo & key = cmd.getKeyCombo();
|
||||
|
|
|
@ -1422,6 +1422,8 @@ public:
|
|||
};
|
||||
|
||||
PluginList & getPluginList() {return _pluginList;};
|
||||
bool importUDLFromFile(generic_string sourceFile);
|
||||
bool exportUDLToFile(int langIndex2export, generic_string fileName2save);
|
||||
|
||||
private:
|
||||
NppParameters();
|
||||
|
@ -1528,7 +1530,11 @@ private:
|
|||
void getLangKeywordsFromXmlTree();
|
||||
bool getUserParametersFromXmlTree();
|
||||
bool getUserStylersFromXmlTree();
|
||||
bool getUserDefineLangsFromXmlTree();
|
||||
bool getUserDefineLangsFromXmlTree(TiXmlDocument *tixmldoc);
|
||||
bool getUserDefineLangsFromXmlTree() {
|
||||
return getUserDefineLangsFromXmlTree(_pXmlUserLangDoc);
|
||||
};
|
||||
|
||||
bool getShortcutsFromXmlTree();
|
||||
|
||||
bool getMacrosFromXmlTree();
|
||||
|
@ -1548,7 +1554,8 @@ private:
|
|||
bool feedStylerArray(TiXmlNode *node);
|
||||
void getAllWordStyles(TCHAR *lexerName, TiXmlNode *lexerNode);
|
||||
|
||||
void feedUserLang(TiXmlNode *node);
|
||||
bool feedUserLang(TiXmlNode *node);
|
||||
|
||||
int getIndexFromKeywordListName(const TCHAR *name);
|
||||
void feedUserStyles(TiXmlNode *node);
|
||||
void feedUserKeywordList(TiXmlNode *node);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "Parameters.h"
|
||||
#include "resource.h"
|
||||
#include "Notepad_plus_msgs.h"
|
||||
#include "FileDialog.h"
|
||||
|
||||
UserLangContainer * SharedParametersDialog::_pUserLang = NULL;
|
||||
ScintillaEditView * SharedParametersDialog::_pScintilla = NULL;
|
||||
|
@ -1338,6 +1339,18 @@ UserDefineDialog::~UserDefineDialog()
|
|||
delete _pCurrentUserLang;
|
||||
}
|
||||
|
||||
void UserDefineDialog::reloadLangCombo()
|
||||
{
|
||||
NppParameters *pNppParam = NppParameters::getInstance();
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_RESETCONTENT, 0, 0);
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("User Define Language"));
|
||||
for (int i = 0 ; i < pNppParam->getNbUserLang() ; i++)
|
||||
{
|
||||
UserLangContainer & userLangContainer = pNppParam->getULCFromIndex(i);
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)userLangContainer.getName());
|
||||
}
|
||||
}
|
||||
|
||||
void UserDefineDialog::changeStyle()
|
||||
{
|
||||
display(false);
|
||||
|
@ -1427,7 +1440,7 @@ BOOL CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||
_ctrlTab.display();
|
||||
|
||||
RECT arc;
|
||||
::GetWindowRect(::GetDlgItem(_hSelf, IDC_ADDNEW_BUTTON), &arc);
|
||||
::GetWindowRect(::GetDlgItem(_hSelf, IDC_IMPORT_BUTTON), &arc);
|
||||
|
||||
POINT p;
|
||||
p.x = arc.left;
|
||||
|
@ -1445,13 +1458,9 @@ BOOL CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||
_commentStyleDlg.reSizeTo(rc);
|
||||
_symbolsStyleDlg.reSizeTo(rc);
|
||||
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("User Define Language"));
|
||||
for (int i = 0 ; i < pNppParam->getNbUserLang() ; i++)
|
||||
{
|
||||
UserLangContainer & userLangContainer = pNppParam->getULCFromIndex(i);
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)userLangContainer.getName());
|
||||
}
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, 0, 0);
|
||||
reloadLangCombo();
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, 0, 0);
|
||||
|
||||
enableLangAndControlsBy(0);
|
||||
|
||||
_pUserLang = _pCurrentUserLang;
|
||||
|
@ -1679,6 +1688,60 @@ BOOL CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
case IDC_IMPORT_BUTTON :
|
||||
{
|
||||
NppParameters *pNppParam = NppParameters::getInstance();
|
||||
|
||||
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
|
||||
fDlg.setExtFilter(TEXT("UDL"), TEXT(".xml"), NULL);
|
||||
TCHAR *fn = fDlg.doOpenSingleFileDlg();
|
||||
if (!fn) break;
|
||||
generic_string sourceFile = fn;
|
||||
|
||||
bool isSuccessful = pNppParam->importUDLFromFile(sourceFile);
|
||||
if (isSuccessful)
|
||||
{
|
||||
int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0);
|
||||
reloadLangCombo();
|
||||
::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, i, 0);
|
||||
_isDirty = true;
|
||||
printStr(TEXT("Import successful."));
|
||||
}
|
||||
else
|
||||
{
|
||||
printStr(TEXT("Fail to import."));
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case IDC_EXPORT_BUTTON :
|
||||
{
|
||||
NppParameters *pNppParam = NppParameters::getInstance();
|
||||
|
||||
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
|
||||
fDlg.setExtFilter(TEXT("UDL"), TEXT(".xml"), NULL);
|
||||
TCHAR *fn = fDlg.doSaveDlg();
|
||||
if (!fn) break;
|
||||
generic_string fileName2save = fn;
|
||||
|
||||
int i2Export = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0);
|
||||
|
||||
if (i2Export > 0)
|
||||
{
|
||||
bool isSuccessful = pNppParam->exportUDLToFile(i2Export - 1, fileName2save);
|
||||
if (isSuccessful)
|
||||
{
|
||||
printStr(TEXT("Export successful"));
|
||||
}
|
||||
else
|
||||
{
|
||||
printStr(TEXT("Fail to export."));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case IDC_UD_TRANSPARENT_CHECK :
|
||||
{
|
||||
|
|
|
@ -252,6 +252,7 @@ public :
|
|||
display();
|
||||
};
|
||||
|
||||
void reloadLangCombo();
|
||||
void changeStyle();
|
||||
bool isDocked() const {return _status == DOCK;};
|
||||
void setDockStatus(bool isDocked) {_status = isDocked;};
|
||||
|
|
|
@ -242,18 +242,22 @@ EXSTYLE WS_EX_TOOLWINDOW
|
|||
CAPTION "User-Defined"
|
||||
FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0
|
||||
BEGIN
|
||||
PUSHBUTTON "Rename",IDC_RENAME_BUTTON,174,40,62,14
|
||||
PUSHBUTTON "Create New...",IDC_ADDNEW_BUTTON,34,40,62,14
|
||||
PUSHBUTTON "Dock",IDC_DOCK_BUTTON,275,1,50,14,BS_FLAT
|
||||
COMBOBOX IDC_LANGNAME_COMBO,71,23,95,58,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
|
||||
PUSHBUTTON "Remove",IDC_REMOVELANG_BUTTON,243,40,62,14
|
||||
PUSHBUTTON "Save As...",IDC_SAVEAS_BUTTON,104,40,62,14
|
||||
LTEXT "User language : ",IDC_LANGNAME_STATIC,5,24,63,8,0,WS_EX_RIGHT
|
||||
EDITTEXT IDC_EXT_EDIT,291,23,33,14,ES_AUTOHSCROLL
|
||||
RTEXT "Ext. :",IDC_EXT_STATIC,257,25,33,8,0,WS_EX_RIGHT
|
||||
LTEXT "User language : ",IDC_LANGNAME_STATIC,0,3,63,8,0,WS_EX_RIGHT
|
||||
COMBOBOX IDC_LANGNAME_COMBO,64,1,90,58,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
|
||||
CONTROL "Transparency",IDC_UD_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,150,3,66,10
|
||||
CONTROL "",IDC_UD_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | NOT WS_VISIBLE | WS_TABSTOP,209,3,53,10
|
||||
PUSHBUTTON "Dock",IDC_DOCK_BUTTON,275,1,50,14,BS_FLAT
|
||||
|
||||
PUSHBUTTON "Create New...",IDC_ADDNEW_BUTTON,34,20,62,14
|
||||
PUSHBUTTON "Save As...",IDC_SAVEAS_BUTTON,104,20,62,14
|
||||
CONTROL "Ignore case",IDC_LANGNAME_IGNORECASE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,175,24,76,10
|
||||
RTEXT "Ext. :",IDC_EXT_STATIC,257,25,33,8,0,WS_EX_RIGHT
|
||||
EDITTEXT IDC_EXT_EDIT,291,23,33,14,ES_AUTOHSCROLL
|
||||
|
||||
PUSHBUTTON "Import...",IDC_IMPORT_BUTTON,34,40,62,14
|
||||
PUSHBUTTON "Export...",IDC_EXPORT_BUTTON,104,40,62,14
|
||||
PUSHBUTTON "Rename",IDC_RENAME_BUTTON,174,40,62,14
|
||||
PUSHBUTTON "Remove",IDC_REMOVELANG_BUTTON,243,40,62,14
|
||||
END
|
||||
|
||||
IDD_STRING_DLG DIALOGEX 0, 0, 151, 52
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
#define IDC_LANGNAME_IGNORECASE_CHECK (IDD_GLOBAL_USERDEFINE_DLG + 12)
|
||||
#define IDC_AUTOCOMPLET_EDIT (IDD_GLOBAL_USERDEFINE_DLG + 13)
|
||||
#define IDC_AUTOCOMPLET_STATIC (IDD_GLOBAL_USERDEFINE_DLG + 14)
|
||||
|
||||
#define IDC_IMPORT_BUTTON (IDD_GLOBAL_USERDEFINE_DLG + 15)
|
||||
#define IDC_EXPORT_BUTTON (IDD_GLOBAL_USERDEFINE_DLG + 16)
|
||||
#define IDD_FOLDER_STYLE_DLG 21000
|
||||
|
||||
#define IDC_DEFAULT (IDD_FOLDER_STYLE_DLG + 100)
|
||||
|
|
Loading…
Reference in New Issue