📄 parameters.cpp.svn-base
字号:
//this file is part of notepad++
//Copyright (C)2003 Don HO ( donho@altern.org )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "Parameters.h"
#include "ScintillaEditView.h"
#include <shlobj.h>
//#include <windows.h>
NppParameters * NppParameters::_pSelf = new NppParameters;
NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserStylerDoc(NULL),\
_pXmlUserLangDoc(NULL), _pXmlNativeLangDoc(NULL),\
_nbLang(0), _nbFile(0), _nbMaxFile(10), _pXmlToolIconsDoc(NULL),\
_pXmlShortcutDoc(NULL), _pXmlContextMenuDoc(NULL), _pXmlSessionDoc(NULL),\
_nbUserLang(0), _hUser32(NULL), _hUXTheme(NULL),\
_transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\
_isTaskListRBUTTONUP_Active(false)
{
_appdataNppDir[0] = '\0';
}
void cutString(const char *str2cut, vector<string> & patternVect)
{
char str2scan[MAX_PATH];
strcpy(str2scan, str2cut);
size_t len = strlen(str2scan);
bool isProcessing = false;
char *pBegin = NULL;
for (size_t i = 0 ; i <= len ; i++)
{
switch(str2scan[i])
{
case ' ':
case '\0':
{
if (isProcessing)
{
str2scan[i] = '\0';
patternVect.push_back(pBegin);
isProcessing = false;
}
break;
}
default :
if (!isProcessing)
{
isProcessing = true;
pBegin = str2scan+i;
}
}
}
}
bool NppParameters::load(/*bool noUserPath*/)
{
bool isAllLaoded = true;
for (int i = 0 ; i < NB_LANG ; _langList[i] = NULL, i++);
char nppPath[MAX_PATH];
char userPath[MAX_PATH];
// Prepare for default path
::GetModuleFileName(NULL, nppPath, sizeof(nppPath));
PathRemoveFileSpec(nppPath);
strcpy(_nppPath, nppPath);
// Make localConf.xml path
char localConfPath[MAX_PATH];
strcpy(localConfPath, _nppPath);
PathAppend(localConfPath, localConfFile);
// Test if localConf.xml exist
bool isLocal = (PathFileExists(localConfPath) == TRUE);
if (isLocal)
{
strcpy(userPath, _nppPath);
}
else
{
ITEMIDLIST *pidl;
SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl);
SHGetPathFromIDList(pidl, userPath);
PathAppend(userPath, "Notepad++");
strcpy(_appdataNppDir, userPath);
if (!PathFileExists(userPath))
{
::CreateDirectory(userPath, NULL);
}
}
//-------------------------------------//
// Transparent function for w2k and xp //
//-------------------------------------//
_hUser32 = ::GetModuleHandle("User32");
if (_hUser32)
_transparentFuncAddr = (WNDPROC)::GetProcAddress(_hUser32, "SetLayeredWindowAttributes");
//---------------------------------------------//
// Dlg theme texture function for xp and vista //
//---------------------------------------------//
_hUXTheme = ::LoadLibrary("uxtheme.dll");
if (_hUXTheme)
_enableThemeDialogTextureFuncAddr = (WNDPROC)::GetProcAddress(_hUXTheme, "EnableThemeDialogTexture");
//---------------------------------------//
// langs.xml : for every user statically //
//---------------------------------------//
char langs_xml_path[MAX_PATH];
strcpy(langs_xml_path, nppPath);
PathAppend(langs_xml_path, "langs.xml");
_pXmlDoc = new TiXmlDocument(langs_xml_path);
bool loadOkay = _pXmlDoc->LoadFile();
if (!loadOkay)
{
::MessageBox(NULL, "Load langs.xml failed!", "Configurator",MB_OK);
delete _pXmlDoc;
_pXmlDoc = NULL;
isAllLaoded = false;
}
else
getLangKeywordsFromXmlTree();
//---------------------------//
// config.xml : for per user //
//---------------------------//
char configPath[MAX_PATH];
strcpy(configPath, userPath);
PathAppend(configPath, "config.xml");
if (!PathFileExists(configPath))
{
char srcConfigPath[MAX_PATH];
strcpy(srcConfigPath, nppPath);
PathAppend(srcConfigPath, "config.xml");
::CopyFile(srcConfigPath, configPath, TRUE);
}
_pXmlUserDoc = new TiXmlDocument(configPath);
loadOkay = _pXmlUserDoc->LoadFile();
if (!loadOkay)
{
::MessageBox(NULL, "Load config.xml failed!", "Configurator",MB_OK);
delete _pXmlUserDoc;
_pXmlUserDoc = NULL;
isAllLaoded = false;
}
else
getUserParametersFromXmlTree();
//----------------------------//
// stylers.xml : for per user //
//----------------------------//
char stylerPath[MAX_PATH];
strcpy(stylerPath, userPath);
PathAppend(stylerPath, "stylers.xml");
if (!PathFileExists(stylerPath))
{
char srcStylersPath[MAX_PATH];
strcpy(srcStylersPath, nppPath);
PathAppend(srcStylersPath, "stylers.xml");
::CopyFile(srcStylersPath, stylerPath, TRUE);
}
_pXmlUserStylerDoc = new TiXmlDocument(stylerPath);
loadOkay = _pXmlUserStylerDoc->LoadFile();
if (!loadOkay)
{
::MessageBox(NULL, "Load stylers.xml failed!", "Configurator",MB_OK);
delete _pXmlUserStylerDoc;
_pXmlUserStylerDoc = NULL;
isAllLaoded = false;
}
else
getUserStylersFromXmlTree();
//-----------------------------------//
// userDefineLang.xml : for per user //
//-----------------------------------//
strcpy(_userDefineLangPath, userPath);
PathAppend(_userDefineLangPath, "userDefineLang.xml");
_pXmlUserLangDoc = new TiXmlDocument(_userDefineLangPath);
loadOkay = _pXmlUserLangDoc->LoadFile();
if (!loadOkay)
{
delete _pXmlUserLangDoc;
_pXmlUserLangDoc = NULL;
isAllLaoded = false;
}
else
getUserDefineLangsFromXmlTree();
//----------------------------------------------//
// nativeLang.xml : for per user //
// In case of absence of user's nativeLang.xml, //
// We'll look in the Notepad++ Dir. //
//----------------------------------------------//
char nativeLangPath[MAX_PATH];
strcpy(nativeLangPath, userPath);
PathAppend(nativeLangPath, "nativeLang.xml");
if (!PathFileExists(nativeLangPath))
{
strcpy(nativeLangPath, nppPath);
PathAppend(nativeLangPath, "nativeLang.xml");
}
_pXmlNativeLangDoc = new TiXmlDocument(nativeLangPath);
loadOkay = _pXmlNativeLangDoc->LoadFile();
if (!loadOkay)
{
delete _pXmlNativeLangDoc;
_pXmlNativeLangDoc = NULL;
isAllLaoded = false;
}
//---------------------------------//
// toolbarIcons.xml : for per user //
//---------------------------------//
char toolbarIconsPath[MAX_PATH];
strcpy(toolbarIconsPath, userPath);
PathAppend(toolbarIconsPath, "toolbarIcons.xml");
_pXmlToolIconsDoc = new TiXmlDocument(toolbarIconsPath);
loadOkay = _pXmlToolIconsDoc->LoadFile();
if (!loadOkay)
{
delete _pXmlToolIconsDoc;
_pXmlToolIconsDoc = NULL;
isAllLaoded = false;
}
//------------------------------//
// shortcuts.xml : for per user //
//------------------------------//
strcpy(_shortcutsPath, userPath);
PathAppend(_shortcutsPath, "shortcuts.xml");
if (!PathFileExists(_shortcutsPath))
{
char srcShortcutsPath[MAX_PATH];
strcpy(srcShortcutsPath, nppPath);
PathAppend(srcShortcutsPath, "shortcuts.xml");
::CopyFile(srcShortcutsPath, _shortcutsPath, TRUE);
}
_pXmlShortcutDoc = new TiXmlDocument(_shortcutsPath);
loadOkay = _pXmlShortcutDoc->LoadFile();
if (!loadOkay)
{
delete _pXmlShortcutDoc;
_pXmlShortcutDoc = NULL;
isAllLaoded = false;
}
else
{
getShortcutsFromXmlTree();
getMacrosFromXmlTree();
getUserCmdsFromXmlTree();
getPluginCmdsFromXmlTree();
// fill out _scintillaModifiedKeys :
// those user defined Scintilla key will be used remap Scintilla Key Array
getScintKeysFromXmlTree();
// initialize entire Scintilla Key Array
initScintillaKeys();
}
//---------------------------------//
// contextMenu.xml : for per user //
//---------------------------------//
strcpy(_contextMenuPath, userPath);
PathAppend(_contextMenuPath, "contextMenu.xml");
if (!PathFileExists(_contextMenuPath))
{
char srcContextMenuPath[MAX_PATH];
strcpy(srcContextMenuPath, nppPath);
PathAppend(srcContextMenuPath, "contextMenu.xml");
::CopyFile(srcContextMenuPath, _contextMenuPath, TRUE);
}
_pXmlContextMenuDoc = new TiXmlDocument(_contextMenuPath);
loadOkay = _pXmlContextMenuDoc->LoadFile();
if (!loadOkay)
{
delete _pXmlContextMenuDoc;
_pXmlContextMenuDoc = NULL;
isAllLaoded = false;
}
else
getContextMenuFromXmlTree();
//----------------------------//
// session.xml : for per user //
//----------------------------//
strcpy(_sessionPath, userPath);
PathAppend(_sessionPath, "session.xml");
_pXmlSessionDoc = new TiXmlDocument(_sessionPath);
loadOkay = _pXmlSessionDoc->LoadFile();
if (!loadOkay)
isAllLaoded = false;
else
getSessionFromXmlTree();
delete _pXmlSessionDoc;
_pXmlSessionDoc = NULL;
return isAllLaoded;
}
void NppParameters::destroyInstance()
{
if (_pXmlDoc != NULL)
{
delete _pXmlDoc;
}
if (_pXmlUserDoc != NULL)
{
_pXmlUserDoc->SaveFile();
delete _pXmlUserDoc;
}
if (_pXmlUserStylerDoc)
delete _pXmlUserStylerDoc;
if (_pXmlUserLangDoc)
delete _pXmlUserLangDoc;
if (_pXmlNativeLangDoc)
delete _pXmlNativeLangDoc;
if (_pXmlToolIconsDoc)
delete _pXmlToolIconsDoc;
if (_pXmlShortcutDoc)
delete _pXmlShortcutDoc;
if (_pXmlContextMenuDoc)
delete _pXmlContextMenuDoc;
if (_pXmlSessionDoc)
delete _pXmlSessionDoc;
delete _pSelf;
}
void NppParameters::setFontList(HWND hWnd)
{
::AddFontResource(LINEDRAW_FONT);
//---------------//
// Sys font list //
//---------------//
LOGFONT lf;
_fontlist.push_back("");
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfFaceName[0]='\0';
HDC hDC = ::GetDC(hWnd);
::EnumFontFamiliesEx(hDC,
&lf,
(FONTENUMPROC) EnumFontFamExProc,
(LPARAM) &_fontlist, 0);
}
void NppParameters::getLangKeywordsFromXmlTree()
{
TiXmlNode *root = _pXmlDoc->FirstChild("NotepadPlus");
if (!root) return;
feedKeyWordsParameters(root);
}
bool NppParameters::getUserStylersFromXmlTree()
{
TiXmlNode *root = _pXmlUserStylerDoc->FirstChild("NotepadPlus");
if (!root) return false;
return feedStylerArray(root);
}
bool NppParameters::getUserParametersFromXmlTree()
{
if (!_pXmlUserDoc)
return false;
TiXmlNode *root = _pXmlUserDoc->FirstChild("NotepadPlus");
if (!root) return false;
// GUI
feedGUIParameters(root);
//History
feedFileListParameters(root);
// Raser tout
TiXmlNode *node = root->FirstChildElement("History");
root->RemoveChild(node);
// Repartir de zero
TiXmlElement HistoryNode("History");
root->InsertEndChild(HistoryNode);
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -