[NEW_FEATURE] Add new -ro and -noSession command line parameters.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@57 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2007-10-21 00:23:07 +00:00
parent 681bb5943a
commit cce77550f2
7 changed files with 106 additions and 72 deletions

View File

@ -23,6 +23,9 @@ Remove this plugin from plugins directory if you don't want to see this message
bool PluginsManager::loadPlugins(const char *dir) bool PluginsManager::loadPlugins(const char *dir)
{ {
if (_isDisabled)
return false;
vector<string> dllNames; vector<string> dllNames;
const char *pNppPath = (NppParameters::getInstance())->getNppPath(); const char *pNppPath = (NppParameters::getInstance())->getNppPath();

View File

@ -59,7 +59,7 @@ struct PluginInfo {
class PluginsManager { class PluginsManager {
public: public:
PluginsManager() : _hPluginsMenu(NULL) {}; PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false) {};
~PluginsManager() { ~PluginsManager() {
for (size_t i = 0 ; i < _pluginInfos.size() ; i++) for (size_t i = 0 ; i < _pluginInfos.size() ; i++)
@ -143,6 +143,7 @@ public:
} }
} }
}; };
void disable() {_isDisabled = true;};
private: private:
NppData _nppData; NppData _nppData;
@ -151,6 +152,8 @@ private:
vector<PluginInfo *> _pluginInfos; vector<PluginInfo *> _pluginInfos;
vector<PluginCommand> _pluginsCommands; vector<PluginCommand> _pluginsCommands;
bool _isDisabled;
bool hasPlugins(){return (_pluginInfos.size()!= 0);}; bool hasPlugins(){return (_pluginInfos.size()!= 0);};
}; };

View File

@ -154,7 +154,7 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p
} }
void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine) void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine, CmdLineParams *cmdLineParams)
{ {
Window::init(hInst, parent); Window::init(hInst, parent);
@ -184,6 +184,9 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine)
const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI();
if (cmdLineParams->_isNoPlugin)
_pluginsManager.disable();
_hSelf = ::CreateWindowEx( _hSelf = ::CreateWindowEx(
WS_EX_ACCEPTFILES | (_isRTL?WS_EX_LAYOUTRTL:0),\ WS_EX_ACCEPTFILES | (_isRTL?WS_EX_LAYOUTRTL:0),\
_className,\ _className,\
@ -210,7 +213,7 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine)
::MoveWindow(_hSelf, nppGUI._appPos.left + workAreaRect.left, nppGUI._appPos.top + workAreaRect.top, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); ::MoveWindow(_hSelf, nppGUI._appPos.left + workAreaRect.left, nppGUI._appPos.top + workAreaRect.top, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE);
//::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); //::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW);
if (nppGUI._rememberLastSession) if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession)
{ {
//--LS: Session SubView restore: Code replaced to load session.xml with new loadSessionToEditView() function!! //--LS: Session SubView restore: Code replaced to load session.xml with new loadSessionToEditView() function!!
bool shouldBeResaved = loadSessionToEditView((NppParameters::getInstance())->getSession()); bool shouldBeResaved = loadSessionToEditView((NppParameters::getInstance())->getSession());
@ -218,12 +221,12 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine)
if (cmdLine) if (cmdLine)
{ {
LangType lt = (NppParameters::getInstance())->getDefLang(); LangType lt = cmdLineParams->_langType;
int ln = (NppParameters::getInstance())->getLineNumber2go(); int ln = cmdLineParams->_line2go;
if (PathFileExists(cmdLine)) if (PathFileExists(cmdLine))
{ {
doOpen(cmdLine); doOpen(cmdLine, cmdLineParams->_isReadOnly);
if (lt != L_TXT) if (lt != L_TXT)
_pEditView->setCurrentDocType(lt); _pEditView->setCurrentDocType(lt);
@ -238,7 +241,7 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine)
for (int i = 0 ; i < fnss.size() ; i++) for (int i = 0 ; i < fnss.size() ; i++)
{ {
pFn = (char *)fnss.getFileName(i); pFn = (char *)fnss.getFileName(i);
doOpen((const char *)pFn); doOpen((const char *)pFn, cmdLineParams->_isReadOnly);
if (lt != L_TXT) if (lt != L_TXT)
_pEditView->setCurrentDocType(lt); _pEditView->setCurrentDocType(lt);
@ -247,7 +250,7 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const char *cmdLine)
} }
} }
// restore the doc type to L_TXT // restore the doc type to L_TXT
(NppParameters::getInstance())->setDefLang(L_TXT); //(NppParameters::getInstance())->setDefLang(L_TXT);
} }
@ -5660,8 +5663,8 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_pluginsManager.init(nppData); _pluginsManager.init(nppData);
if (!pNppParam->isNoPlugin()) //if (!pNppParam->isNoPlugin())
_pluginsManager.loadPlugins(); _pluginsManager.loadPlugins();
const char *appDataNpp = pNppParam->getAppDataNppDir(); const char *appDataNpp = pNppParam->getAppDataNppDir();
if (appDataNpp[0]) if (appDataNpp[0])
@ -5962,26 +5965,42 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case WM_COPYDATA : case WM_COPYDATA :
{ {
const DWORD LASTBYTEMASK = 0x000000FF; //const DWORD LASTBYTEMASK = 0x000000FF;
COPYDATASTRUCT *pCopyData = (COPYDATASTRUCT *)lParam; COPYDATASTRUCT *pCopyData = (COPYDATASTRUCT *)lParam;
LangType lt = LangType(pCopyData->dwData & LASTBYTEMASK);
int ln = pCopyData->dwData >> 8; switch (pCopyData->dwData)
//::MessageBox(NULL, (const char *)pCopyData->lpData, "WM_COPYDATA", MB_OK); {
FileNameStringSplitter fnss((const char *)pCopyData->lpData); case COPYDATA_PARAMS :
char *pFn = NULL;
for (int i = 0 ; i < fnss.size() ; i++)
{
pFn = (char *)fnss.getFileName(i);
doOpen((const char *)pFn);
if (lt != L_TXT)
{ {
_pEditView->setCurrentDocType(lt); pNppParam->setCmdlineParam(*((CmdLineParams *)pCopyData->lpData));
setLangStatus(lt); break;
checkLangsMenu(-1);
} }
_pEditView->execute(SCI_GOTOLINE, ln-1);
} case COPYDATA_FILENAMES :
//setLangStatus(_pEditView->getCurrentDocType()); {
CmdLineParams & cmdLineParams = pNppParam->getCmdLineParams();
LangType lt = cmdLineParams._langType;//LangType(pCopyData->dwData & LASTBYTEMASK);
int ln = cmdLineParams._line2go;
FileNameStringSplitter fnss((char *)pCopyData->lpData);
char *pFn = NULL;
for (int i = 0 ; i < fnss.size() ; i++)
{
pFn = (char *)fnss.getFileName(i);
doOpen((const char *)pFn, cmdLineParams._isReadOnly);
if (lt != L_TXT)
{
_pEditView->setCurrentDocType(lt);
setLangStatus(lt);
checkLangsMenu(-1);
}
_pEditView->execute(SCI_GOTOLINE, ln-1);
}
//setLangStatus(_pEditView->getCurrentDocType());
break;
}
}
return TRUE; return TRUE;
} }

View File

@ -80,7 +80,7 @@ class Notepad_plus : public Window {
public: public:
Notepad_plus(); Notepad_plus();
void init(HINSTANCE, HWND, const char *cmdLine); void init(HINSTANCE, HWND, const char *cmdLine, CmdLineParams *cmdLineParams);
// ATTENTION : the order of the destruction is very important // ATTENTION : the order of the destruction is very important
// because if the parent's window hadle is destroyed before // because if the parent's window hadle is destroyed before

View File

@ -21,9 +21,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "resource.h" #include "resource.h"
#include "menuCmdID.h" #include "menuCmdID.h"
#define NOTEPAD_PLUS_VERSION "Notepad++ v4.4" #define NOTEPAD_PLUS_VERSION "Notepad++ v4.4.1"
#define VERSION_VALUE "4.4\0" #define VERSION_VALUE "4.4.1\0"
#define VERSION_DIGITALVALUE 4, 4, 0, 0 #define VERSION_DIGITALVALUE 4, 4, 1, 0
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_DIGITALVALUE FILEVERSION VERSION_DIGITALVALUE

View File

@ -66,6 +66,9 @@ const int LANG_INDEX_TYPE3 = 4;
const int LANG_INDEX_TYPE4 = 5; const int LANG_INDEX_TYPE4 = 5;
const int LANG_INDEX_TYPE5 = 6; const int LANG_INDEX_TYPE5 = 6;
const int COPYDATA_PARAMS = 0;
const int COPYDATA_FILENAMES = 1;
const bool SCIV_PRIMARY = false; const bool SCIV_PRIMARY = false;
const bool SCIV_SECOND = true; const bool SCIV_SECOND = true;
@ -120,6 +123,15 @@ struct Session {
vector<sessionFileInfo> _files; vector<sessionFileInfo> _files;
}; };
struct CmdLineParams {
bool _isNoPlugin;
bool _isReadOnly;
bool _isNoSession;
int _line2go;
LangType _langType;
};
struct FloatingWindowInfo { struct FloatingWindowInfo {
int _cont; int _cont;
RECT _pos; RECT _pos;
@ -886,14 +898,16 @@ public:
::SetWindowLong(hwnd, GWL_EXSTYLE, ::GetWindowLong(hwnd, GWL_EXSTYLE) & ~/*WS_EX_LAYERED*/0x00080000); ::SetWindowLong(hwnd, GWL_EXSTYLE, ::GetWindowLong(hwnd, GWL_EXSTYLE) & ~/*WS_EX_LAYERED*/0x00080000);
}; };
void setDefLang(LangType langType) {_defLangType = langType;}; //void setDefLang(LangType langType) {_defLangType = langType;};
LangType getDefLang() const {return _defLangType;}; //LangType getDefLang() const {return _defLangType;};
void setLineNumber2go(int ln) {_lineNumber2Go = ln;}; //void setLineNumber2go(int ln) {_lineNumber2Go = ln;};
int getLineNumber2go() const {return _lineNumber2Go;}; //int getLineNumber2go() const {return _lineNumber2Go;};
void setIsNoPlugin(bool noPlugin) {_noPlugin = noPlugin;}; void setCmdlineParam(const CmdLineParams & cmdLineParams) {_cmdLineParams = cmdLineParams;
bool isNoPlugin() const {return _noPlugin;}; //::MessageBox(NULL, "", _cmdLineParams._isReadOnly?"Param:RO":"Param:RW", MB_OK);
};
CmdLineParams & getCmdLineParams() {return _cmdLineParams;};
void setFileSaveDlgFilterIndex(int ln) {_fileSaveDlgFilterIndex = ln;}; void setFileSaveDlgFilterIndex(int ln) {_fileSaveDlgFilterIndex = ln;};
int getFileSaveDlgFilterIndex() const {return _fileSaveDlgFilterIndex;}; int getFileSaveDlgFilterIndex() const {return _fileSaveDlgFilterIndex;};
@ -1003,9 +1017,7 @@ private:
int _nbUserLang; int _nbUserLang;
char _userDefineLangPath[MAX_PATH]; char _userDefineLangPath[MAX_PATH];
LangType _defLangType; CmdLineParams _cmdLineParams;
int _lineNumber2Go;
bool _noPlugin;
int _fileSaveDlgFilterIndex; int _fileSaveDlgFilterIndex;

View File

@ -120,7 +120,7 @@ static LangType getLangTypeFromParam(char *list2Clean) {
} }
} }
return L_TXT; return L_TXT;
}; };
static int getLn2GoFromParam(char *list2Clean) { static int getLn2GoFromParam(char *list2Clean) {
char word[16]; char word[16];
@ -183,6 +183,8 @@ static int getLn2GoFromParam(char *list2Clean) {
const char FLAG_MULTI_INSTANCE[] = "-multiInst"; const char FLAG_MULTI_INSTANCE[] = "-multiInst";
const char FLAG_NO_PLUGIN[] = "-noPlugin"; const char FLAG_NO_PLUGIN[] = "-noPlugin";
const char FLAG_READONLY[] = "-ro";
const char FLAG_NOSESSION[] = "-nosession";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdShow) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdShow)
{ {
@ -193,14 +195,18 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdSh
if (::GetLastError() == ERROR_ALREADY_EXISTS) if (::GetLastError() == ERROR_ALREADY_EXISTS)
TheFirstOne = false; TheFirstOne = false;
bool multiInstance = isInList(FLAG_MULTI_INSTANCE, lpszCmdLine); CmdLineParams cmdLineParams;
bool noPlugin = isInList(FLAG_NO_PLUGIN, lpszCmdLine); bool isMultiInst = isInList(FLAG_MULTI_INSTANCE, lpszCmdLine);
LangType langType = getLangTypeFromParam(lpszCmdLine); cmdLineParams._isNoPlugin = isInList(FLAG_NO_PLUGIN, lpszCmdLine);
int lineNumber = getLn2GoFromParam(lpszCmdLine); cmdLineParams._isReadOnly = isInList(FLAG_READONLY, lpszCmdLine);
cmdLineParams._isNoSession = isInList(FLAG_NOSESSION, lpszCmdLine);
//printStr(cmdLineParams._isReadOnly?"RO":"RW");
cmdLineParams._langType = getLangTypeFromParam(lpszCmdLine);
cmdLineParams._line2go = getLn2GoFromParam(lpszCmdLine);
NppParameters *pNppParameters = NppParameters::getInstance(); NppParameters *pNppParameters = NppParameters::getInstance();
if ((!multiInstance) && (!TheFirstOne)) if ((!isMultiInst) && (!TheFirstOne))
{ {
HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL);
for (;!(hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL));) for (;!(hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL));)
@ -225,18 +231,18 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdSh
if (lpszCmdLine[0]) if (lpszCmdLine[0])
{ {
COPYDATASTRUCT copyData; COPYDATASTRUCT paramData;
DWORD ln = 0; paramData.dwData = COPYDATA_PARAMS;
if (lineNumber != -1)
ln = lineNumber;
copyData.dwData = (ln << 8) | DWORD(langType);
COPYDATASTRUCT fileNamesData;
fileNamesData.dwData = COPYDATA_FILENAMES;
//pNppParameters->setCmdlineParam(cmdLineParams);
string quotFileName = "\""; string quotFileName = "\"";
// tell the other running instance the FULL path to the new file to load // tell the other running instance the FULL path to the new file to load
if (lpszCmdLine[0] == '"') if (lpszCmdLine[0] == '"')
{ {
copyData.cbData = long(strlen(lpszCmdLine) + 1); fileNamesData.lpData = (void *)lpszCmdLine;
copyData.lpData = lpszCmdLine; fileNamesData.cbData = long(strlen(lpszCmdLine) + 1);
} }
else else
{ {
@ -244,11 +250,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdSh
::GetFullPathName(lpszCmdLine, MAX_PATH, longFileName, NULL); ::GetFullPathName(lpszCmdLine, MAX_PATH, longFileName, NULL);
quotFileName += longFileName; quotFileName += longFileName;
quotFileName += "\""; quotFileName += "\"";
copyData.cbData = long(quotFileName.length() + 1);
copyData.lpData = (void *)quotFileName.c_str();
}
::SendMessage(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)&copyData); fileNamesData.lpData = (void *)quotFileName.c_str();
fileNamesData.cbData = long(quotFileName.length() + 1);
}
paramData.lpData = &cmdLineParams;
paramData.cbData = sizeof(cmdLineParams);
//printStr(((CmdLineParams *)copyData.dwData)->_isReadOnly?"DEBUT:RO":"DEBUT:RW");
::SendMessage(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)&paramData);
::SendMessage(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)&fileNamesData);
//printStr(((CmdLineParams *)copyData.dwData)->_isReadOnly?"FIN:RO":"FIN:RW");
} }
return 0; return 0;
} }
@ -257,18 +268,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdSh
Notepad_plus notepad_plus_plus; Notepad_plus notepad_plus_plus;
MSG msg; MSG msg;
msg.wParam = 0; msg.wParam = 0;
try { try {
char *pPathNames = NULL; char *pPathNames = NULL;
if (lpszCmdLine[0]) if (lpszCmdLine[0])
{ {
pPathNames = lpszCmdLine; pPathNames = lpszCmdLine;
} }
pNppParameters->setDefLang(langType); notepad_plus_plus.init(hInstance, NULL, pPathNames, &cmdLineParams);
pNppParameters->setLineNumber2go(lineNumber);
pNppParameters->setIsNoPlugin(noPlugin);
notepad_plus_plus.init(hInstance, NULL, pPathNames);
while (::GetMessage(&msg, NULL, 0, 0)) while (::GetMessage(&msg, NULL, 0, 0))
{ {
@ -288,7 +294,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdSh
} }
} }
} }
} catch(int i) { } catch(int i) {
if (i == 106901) if (i == 106901)
::MessageBox(NULL, "Scintilla.init is failed!", "106901", MB_OK); ::MessageBox(NULL, "Scintilla.init is failed!", "106901", MB_OK);
@ -299,14 +304,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdSh
::MessageBox(NULL, strcat(str, code), "int exception", MB_OK); ::MessageBox(NULL, strcat(str, code), "int exception", MB_OK);
} }
} }
/*
catch(std::exception ex) {
::MessageBox(NULL, ex.what(), "Exception", MB_OK);
}
catch(...) {
systemMessage("System Err");
}
*/
return (UINT)msg.wParam; return (UINT)msg.wParam;
} }