[NEW_FEATURE] (Author : Slurdge) Add system tray context menu and new command argument "-systemtray".

[NEW_FEATURE] Add new command argument "--help".

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@558 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2009-11-11 23:55:18 +00:00
parent 98fdb775f8
commit b8c8283a5d
7 changed files with 162 additions and 44 deletions

View File

@ -204,6 +204,8 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL
nppClass.lpszMenuName = MAKEINTRESOURCE(IDR_M30_MENU); nppClass.lpszMenuName = MAKEINTRESOURCE(IDR_M30_MENU);
nppClass.lpszClassName = _className; nppClass.lpszClassName = _className;
_isPrelaunch = cmdLineParams->_isPreLaunch;
if (!::RegisterClass(&nppClass)) if (!::RegisterClass(&nppClass))
{ {
systemMessage(TEXT("System Err")); systemMessage(TEXT("System Err"));
@ -260,6 +262,7 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL
if (newUpperLeft.y + nppGUI._appPos.bottom < ::GetSystemMetrics(SM_YVIRTUALSCREEN)+margin) if (newUpperLeft.y + nppGUI._appPos.bottom < ::GetSystemMetrics(SM_YVIRTUALSCREEN)+margin)
newUpperLeft.y = workAreaRect.top; newUpperLeft.y = workAreaRect.top;
} }
if (cmdLineParams->isPointValid()) if (cmdLineParams->isPointValid())
::MoveWindow(_hSelf, cmdLineParams->_point.x, cmdLineParams->_point.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); ::MoveWindow(_hSelf, cmdLineParams->_point.x, cmdLineParams->_point.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE);
else else
@ -282,10 +285,18 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL
loadLastSession(); loadLastSession();
} }
if (cmdLineParams->isPointValid()) if (!cmdLineParams->_isPreLaunch)
::ShowWindow(_hSelf, SW_SHOW); {
if (cmdLineParams->isPointValid())
::ShowWindow(_hSelf, SW_SHOW);
else
::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW);
}
else else
::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); {
_pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT(""));
_pTrayIco->doTrayIcon(ADD);
}
if (cmdLine) if (cmdLine)
{ {
@ -690,7 +701,8 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly)
if (_pTrayIco->isInTray()) if (_pTrayIco->isInTray())
{ {
::ShowWindow(_hSelf, SW_SHOW); ::ShowWindow(_hSelf, SW_SHOW);
_pTrayIco->doTrayIcon(REMOVE); if (!_isPrelaunch)
_pTrayIco->doTrayIcon(REMOVE);
::SendMessage(_hSelf, WM_SIZE, 0, 0); ::SendMessage(_hSelf, WM_SIZE, 0, 0);
} }
} }
@ -767,7 +779,8 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly)
if (_pTrayIco->isInTray()) if (_pTrayIco->isInTray())
{ {
::ShowWindow(_hSelf, SW_SHOW); ::ShowWindow(_hSelf, SW_SHOW);
_pTrayIco->doTrayIcon(REMOVE); if (!_isPrelaunch)
_pTrayIco->doTrayIcon(REMOVE);
::SendMessage(_hSelf, WM_SIZE, 0, 0); ::SendMessage(_hSelf, WM_SIZE, 0, 0);
} }
} }
@ -3405,11 +3418,9 @@ void Notepad_plus::command(int id)
switch (id) switch (id)
{ {
case IDM_FILE_NEW: case IDM_FILE_NEW:
{
fileNew(); fileNew();
} break;
break;
case IDM_FILE_OPEN: case IDM_FILE_OPEN:
fileOpen(); fileOpen();
break; break;
@ -4656,13 +4667,7 @@ void Notepad_plus::command(int id)
::ShellExecute(NULL, TEXT("open"), TEXT("http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Main_Page"), NULL, NULL, SW_SHOWNORMAL); ::ShellExecute(NULL, TEXT("open"), TEXT("http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Main_Page"), NULL, NULL, SW_SHOWNORMAL);
break; break;
} }
/*
case IDM_WIKIFAQ:
{
::ShellExecute(NULL, TEXT("open"), TEXT("http://notepad-plus.wiki.sourceforge.net/FAQ"), NULL, NULL, SW_SHOWNORMAL);
break;
}
*/
case IDM_FORUM: case IDM_FORUM:
{ {
::ShellExecute(NULL, TEXT("open"), TEXT("http://sourceforge.net/forum/?group_id=95717"), NULL, NULL, SW_SHOWNORMAL); ::ShellExecute(NULL, TEXT("open"), TEXT("http://sourceforge.net/forum/?group_id=95717"), NULL, NULL, SW_SHOWNORMAL);
@ -4841,6 +4846,53 @@ void Notepad_plus::command(int id)
} }
break; break;
case IDM_POPUP_FILE_NEW:
{
NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW);
fileNew();
}
break;
case IDM_POPUP_FILE_ACTIVATE_OR_NEW:
{
NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW);
}
break;
case IDM_POPUP_FILE_NEW_AND_PASTE:
{
NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW);
BufferID bufferID = _pEditView->getCurrentBufferID();
Buffer * buf = MainFileManager->getBufferByID(bufferID);
if (!buf->isUntitled() || buf->docLength() != 0)
{
fileNew();
}
command(IDM_EDIT_PASTE);
}
break;
case IDM_POPUP_FILE_OPEN:
{
NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW);
fileOpen();
}
break;
case IDM_POPUP_CLOSE:
{
_isPrelaunch = false;
_pTrayIco->doTrayIcon(REMOVE);
if (!::IsWindowVisible(_hSelf))
::SendMessage(_hSelf, WM_CLOSE, 0,0);
}
break;
default : default :
if (id > IDM_FILEMENU_LASTONE && id < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1)) if (id > IDM_FILEMENU_LASTONE && id < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1))
{ {
@ -7654,7 +7706,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_dockingManager.init(_hInst, hwnd, &_pMainWindow); _dockingManager.init(_hInst, hwnd, &_pMainWindow);
if (nppGUI._isMinimizedToTray) if (nppGUI._isMinimizedToTray && _pTrayIco == NULL)
_pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); _pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT(""));
checkSyncState(); checkSyncState();
@ -9152,6 +9204,11 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case WM_QUERYENDSESSION: case WM_QUERYENDSESSION:
case WM_CLOSE: case WM_CLOSE:
{ {
if (!_isPrelaunch)
{
_pTrayIco->doTrayIcon(REMOVE);
}
const NppGUI & nppgui = pNppParam->getNppGUI(); const NppGUI & nppgui = pNppParam->getNppGUI();
Session currentSession; Session currentSession;
if (nppgui._rememberLastSession) if (nppgui._rememberLastSession)
@ -9200,8 +9257,16 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
saveSession(currentSession); saveSession(currentSession);
//Sends WM_DESTROY, Notepad++ will end if (!_isPrelaunch)
::DestroyWindow(hwnd); {
//Sends WM_DESTROY, Notepad++ will end
::DestroyWindow(hwnd);
}
else
{
SendMessage(_hSelf, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
return TRUE; return TRUE;
} }
@ -9253,18 +9318,31 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case WM_LBUTTONUP : case WM_LBUTTONUP :
_pEditView->getFocus(); _pEditView->getFocus();
::ShowWindow(_hSelf, SW_SHOW); ::ShowWindow(_hSelf, SW_SHOW);
_pTrayIco->doTrayIcon(REMOVE); if (!_isPrelaunch)
_pTrayIco->doTrayIcon(REMOVE);
::SendMessage(_hSelf, WM_SIZE, 0, 0); ::SendMessage(_hSelf, WM_SIZE, 0, 0);
return TRUE; return TRUE;
/*
case WM_RBUTTONUP: case WM_MBUTTONUP:
{ command(IDM_POPUP_FILE_NEW_AND_PASTE);
POINT p; return TRUE;
GetCursorPos(&p);
TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, hwnd, NULL); case WM_RBUTTONUP:
return TRUE; {
} POINT p;
*/ GetCursorPos(&p);
HMENU hmenu; // menu template
HMENU hTrayIconMenu; // shortcut menu
hmenu = LoadMenu(_hInst, MAKEINTRESOURCE(IDR_POPUP_MENU));
hTrayIconMenu = GetSubMenu(hmenu, 0);
SetForegroundWindow(_hSelf);
TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL);
PostMessage(_hSelf, WM_NULL, 0, 0);
DestroyMenu(hmenu);
return TRUE;
}
} }
return TRUE; return TRUE;
} }

View File

@ -329,6 +329,7 @@ private:
HMENU _mainMenuHandle; HMENU _mainMenuHandle;
bool _sysMenuEntering; bool _sysMenuEntering;
bool _isPrelaunch;
// For FullScreen/PostIt features // For FullScreen/PostIt features
VisibleGUIConf _beforeSpecialView; VisibleGUIConf _beforeSpecialView;

View File

@ -594,6 +594,21 @@ BEGIN
MENUITEM "X", IDM_FILE_CLOSE, HELP MENUITEM "X", IDM_FILE_CLOSE, HELP
END END
IDR_POPUP_MENU MENU
BEGIN
POPUP "Popup"
BEGIN
MENUITEM "Activate or New", IDM_POPUP_FILE_ACTIVATE_OR_NEW
MENUITEM SEPARATOR
MENUITEM "New", IDM_POPUP_FILE_NEW
MENUITEM "New and Paste", IDM_POPUP_FILE_NEW_AND_PASTE
MENUITEM "Open...", IDM_POPUP_FILE_OPEN
MENUITEM "Find in Files...", IDM_SEARCH_FINDINFILES
MENUITEM SEPARATOR
MENUITEM "Close Tray Icon", IDM_POPUP_CLOSE
END
END
IDD_ABOUTBOX DIALOGEX 0, 0, 271, 240 IDD_ABOUTBOX DIALOGEX 0, 0, 271, 240
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_BORDER | WS_SYSMENU STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_BORDER | WS_SYSMENU
FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1

View File

@ -157,6 +157,7 @@ struct CmdLineParams {
bool _isReadOnly; bool _isReadOnly;
bool _isNoSession; bool _isNoSession;
bool _isNoTab; bool _isNoTab;
bool _isPreLaunch;
int _line2go; int _line2go;
int _column2go; int _column2go;

View File

@ -309,4 +309,11 @@
#define IDM_EXECUTE (IDM + 9000) #define IDM_EXECUTE (IDM + 9000)
#define IDM_POPUP (IDM + 3050)
#define IDM_POPUP_FILE_ACTIVATE_OR_NEW (IDM_POPUP + 1)
#define IDM_POPUP_FILE_NEW (IDM_POPUP + 2)
#define IDM_POPUP_FILE_NEW_AND_PASTE (IDM_POPUP + 3)
#define IDM_POPUP_FILE_OPEN (IDM_POPUP + 4)
#define IDM_POPUP_CLOSE (IDM_POPUP + 5)
#endif //MENUCMDID_H #endif //MENUCMDID_H

View File

@ -230,6 +230,8 @@
#define IDR_M30_MENU 1500 #define IDR_M30_MENU 1500
#define IDR_POPUP_MENU 1501
// #define IDD_FIND_REPLACE_DLG 1600 // #define IDD_FIND_REPLACE_DLG 1600
#define IDD_ABOUTBOX 1700 #define IDD_ABOUTBOX 1700

View File

@ -136,28 +136,34 @@ int getNumberFromParam(char paramName, ParamVector & params, bool & isParamePres
isParamePresent = true; isParamePresent = true;
return generic_atoi(numStr.c_str()); return generic_atoi(numStr.c_str());
}; };
/*
int getLn2GoFromParam(ParamVector & params) {
generic_string lineNumStr;
if (!getParamVal('n', params, lineNumStr))
return -1;
return generic_atoi(lineNumStr.c_str());
};
int getPointXFromParam(ParamVector & params) {
generic_string pointXStr;
if (!getParamVal('x', params, pointXStr))
return -1;
return generic_atoi(pointXStr.c_str());
};
*/
const TCHAR FLAG_MULTI_INSTANCE[] = TEXT("-multiInst"); const TCHAR FLAG_MULTI_INSTANCE[] = TEXT("-multiInst");
const TCHAR FLAG_NO_PLUGIN[] = TEXT("-noPlugin"); const TCHAR FLAG_NO_PLUGIN[] = TEXT("-noPlugin");
const TCHAR FLAG_READONLY[] = TEXT("-ro"); const TCHAR FLAG_READONLY[] = TEXT("-ro");
const TCHAR FLAG_NOSESSION[] = TEXT("-nosession"); const TCHAR FLAG_NOSESSION[] = TEXT("-nosession");
const TCHAR FLAG_NOTABBAR[] = TEXT("-notabbar"); const TCHAR FLAG_NOTABBAR[] = TEXT("-notabbar");
const TCHAR FLAG_SYSTRAY[] = TEXT("-systemtray");
const TCHAR FLAG_HELP[] = TEXT("--help");
const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\
\r\
notepad++ [--help] [-multiInst] [-noPlugins] [-lLanguage] [-nLineNumber] [-cColumnNumber] [-xPos] [-yPos] [-nosession] [-notabbar] [-ro] [-systemtray] [fullFilePathName]\r\
\r\
--help : This help message\r\
-multiInst : Launch another Notepad++ instance\r\
-noPlugins : Launch Notepad++ without loading any plugin\r\
-l : Launch Notepad++ by applying indicated language to the file to open\r\
-n : Launch Notepad++ by scrolling indicated line on the file to open\r\
-c : Launch Notepad++ on scrolling indicated column on the file to open\r\
-x : Launch Notepad++ by indicating its left side position on the screen\r\
-y : Launch Notepad++ by indicating its top position on the screen\r\
-nosession : Launch Notepad++ without any session\r\
-notabbar : Launch Notepad++ without tabbar\r\
-ro : Launch Notepad++ and make the file to open read only\r\
-systemtray : Launch Notepad++ directly in system tray\r\
fullFilePathName : file name to open (absolute or relative path name)\r\
");
void doException(Notepad_plus & notepad_plus_plus); void doException(Notepad_plus & notepad_plus_plus);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
@ -175,18 +181,26 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
TheFirstOne = false; TheFirstOne = false;
bool isParamePresent; bool isParamePresent;
CmdLineParams cmdLineParams; bool showHelp = isInList(FLAG_HELP, params);
bool isMultiInst = isInList(FLAG_MULTI_INSTANCE, params); bool isMultiInst = isInList(FLAG_MULTI_INSTANCE, params);
CmdLineParams cmdLineParams;
cmdLineParams._isNoTab = isInList(FLAG_NOTABBAR, params); cmdLineParams._isNoTab = isInList(FLAG_NOTABBAR, params);
cmdLineParams._isNoPlugin = isInList(FLAG_NO_PLUGIN, params); cmdLineParams._isNoPlugin = isInList(FLAG_NO_PLUGIN, params);
cmdLineParams._isReadOnly = isInList(FLAG_READONLY, params); cmdLineParams._isReadOnly = isInList(FLAG_READONLY, params);
cmdLineParams._isNoSession = isInList(FLAG_NOSESSION, params); cmdLineParams._isNoSession = isInList(FLAG_NOSESSION, params);
cmdLineParams._isPreLaunch = isInList(FLAG_SYSTRAY, params);
cmdLineParams._langType = getLangTypeFromParam(params); cmdLineParams._langType = getLangTypeFromParam(params);
cmdLineParams._line2go = getNumberFromParam('n', params, isParamePresent); cmdLineParams._line2go = getNumberFromParam('n', params, isParamePresent);
cmdLineParams._column2go = getNumberFromParam('c', params, isParamePresent); cmdLineParams._column2go = getNumberFromParam('c', params, isParamePresent);
cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid); cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid);
cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid); cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid);
if (showHelp)
{
::MessageBox(NULL, COMMAND_ARG_HELP, TEXT("Notepad++ Command Argument Help"), MB_OK);
}
NppParameters *pNppParameters = NppParameters::getInstance(); NppParameters *pNppParameters = NppParameters::getInstance();
// override the settings if notepad style is present // override the settings if notepad style is present
if (pNppParameters->asNotepadStyle()) if (pNppParameters->asNotepadStyle())