//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 "PluginDefinition.h" #include "menuCmdID.h" #include "winuser.h" #include <sys/types.h> #include <sys/stat.h> //#include <tchar.h> //#include <stdio.h> #include <clientapi.h> #include <strtable.h> #include <enviro.h> #include "PerforceClient.h" // // The plugin data that Notepad++ needs // FuncItem * funcItem; unsigned int nbFunc; static bool withP4V = false; #define P4VFUNCS 4 // // The data of Notepad++ that you can use in your plugin commands // NppData nppData; HANDLE module; #define INFO_BUFFER_SIZE 32767 // // Initialize your plugin data here // It will be called while plugin loading void pluginInit(HANDLE hModule) { wchar_t path[INFO_BUFFER_SIZE]; GetEnvironmentVariable(TEXT("PATH"), path, INFO_BUFFER_SIZE); wchar_t *p = path; wchar_t *n; while ( (n = wcsstr(p, TEXT(";"))) != NULL) { *n = '\0'; wchar_t fullpath[MAX_PATH]; wcscpy(fullpath, p); wcscpy(fullpath + wcslen( p ), TEXT("\\p4vc.exe")); struct _stat buffer; int found = _wstat(fullpath, &buffer); if ( found >= 0 ) { withP4V = true; } p = n + 1; } nbFunc = 13 + (withP4V ? P4VFUNCS : 0); funcItem = new FuncItem[nbFunc]; module = hModule; } // // Here you can do the clean up, save the parameters (if any) for the next session // void pluginCleanUp() { delete [] funcItem; } // // Initialization of your plugin commands // You should fill your plugins commands here void commandMenuInit() { int offset = withP4V ? P4VFUNCS : 0; //--------------------------------------------// //-- STEP 3. CUSTOMIZE YOUR PLUGIN COMMANDS --// //--------------------------------------------// // with function : // setCommand(int index, // zero based number to indicate the order of command // TCHAR *commandName, // the command name that you want to see in plugin menu // PFUNCPLUGINCMD functionPointer, // the symbol of function (function pointer) associated with this command. The body should be defined below. See Step 4. // ShortcutKey *shortcut, // optional. Define a shortcut to trigger this command // bool check0nInit // optional. Make this menu item be checked visually // ); ShortcutKey *pAddKey = new ShortcutKey; pAddKey->_isAlt = true; pAddKey->_isCtrl = false; pAddKey->_isShift = true; pAddKey->_key = 'A'; //VK_A setCommand(0, TEXT("Add File"), addFile, pAddKey, false); ShortcutKey *pEditKey = new ShortcutKey; pEditKey->_isAlt = true; pEditKey->_isCtrl = false; pEditKey->_isShift = true; pEditKey->_key = 'E'; //VK_E setCommand(1, TEXT("Edit File"), editFile, pEditKey, false); ShortcutKey *pRevertKey = new ShortcutKey; pRevertKey->_isAlt = true; pRevertKey->_isCtrl = false; pRevertKey->_isShift = true; pRevertKey->_key = 'R'; //VK_R setCommand(2, TEXT("Revert File"), revertFile, pRevertKey, false); ShortcutKey *pDeleteKey = new ShortcutKey; pDeleteKey->_isAlt = true; pDeleteKey->_isCtrl = false; pDeleteKey->_isShift = true; pDeleteKey->_key = 'D'; //VK_S setCommand(3, TEXT("Delete File"), deleteFile, pDeleteKey, false); ShortcutKey *pSyncKey = new ShortcutKey; pSyncKey->_isAlt = true; pSyncKey->_isCtrl = false; pSyncKey->_isShift = true; pSyncKey->_key = 'X'; //VK_X -- ALT+SHIFT+S is taken already setCommand(4, TEXT("Sync File"), syncFile, pSyncKey, false); setCommand(5, TEXT("--------------------"), NULL, NULL, false); if (withP4V) { setCommand(6, TEXT("Revision Graph"), showRevisionGraph, NULL, false); setCommand(7, TEXT("Timelapse View"), showTimelapseView, NULL, false); setCommand(8, TEXT("Submit File ..."), submit, NULL, false); setCommand(9, TEXT("--------------------"), NULL, NULL, false); } ShortcutKey *pFileKey = new ShortcutKey; pFileKey->_isAlt = true; pFileKey->_isCtrl = false; pFileKey->_isShift = true; pFileKey->_key = 'F'; //VK_F setCommand(6 + offset, TEXT("Show file info"), showFileInfo, pFileKey, false); ShortcutKey *pConnectionKey = new ShortcutKey; pConnectionKey->_isAlt = true; pConnectionKey->_isCtrl = false; pConnectionKey->_isShift = true; pConnectionKey->_key = 'I'; //VK_I setCommand(7 + offset, TEXT("Show connection info"), showConnectionInfo, pConnectionKey, false); setCommand(8 + offset, TEXT("--------------------"), NULL, NULL, false); setCommand(9 + offset, TEXT("Login ..."), login, NULL, false); setCommand(10 + offset, TEXT("Logout"), logout, NULL, false); setCommand(11 + offset, TEXT("--------------------"), NULL, NULL, false); setCommand(12 + offset, TEXT("About"), about, NULL, false); } // // Here you can do the clean up (especially for the shortcut) // void commandMenuCleanUp() { int offset = withP4V ? P4VFUNCS : 0; // Don't forget to deallocate your shortcut here delete funcItem[0]._pShKey; delete funcItem[1]._pShKey; delete funcItem[2]._pShKey; delete funcItem[3]._pShKey; delete funcItem[4]._pShKey; delete funcItem[6 + offset]._pShKey; delete funcItem[7 + offset]._pShKey; } // // This function help you to initialize your plugin commands // bool setCommand(size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit) { if (index >= nbFunc) return false; // if (!pFunc) // return false; lstrcpy(funcItem[index]._itemName, cmdName); funcItem[index]._pFunc = pFunc; funcItem[index]._init2Check = check0nInit; funcItem[index]._pShKey = sk; return true; } //----------------------------------------------// //-- STEP 4. DEFINE YOUR ASSOCIATED FUNCTIONS --// //----------------------------------------------// void addFile() { PerforceClient client; client.addFile(); } void editFile() { PerforceClient client; client.editFile(); } void revertFile() { PerforceClient client; client.revertFile( ); } void deleteFile() { PerforceClient client; client.deleteFile(); } void syncFile() { PerforceClient client; client.syncFile(); } void showConnectionInfo() { PerforceClient client; client.showInfo(); } void showFileInfo() { PerforceClient client; client.showFileInfo(); } void show(const char * cmd) { PerforceClient client; client.callP4V(cmd); } void showRevisionGraph() { show("revgraph"); } void showTimelapseView() { show("tlv"); } void submit() { show("submit"); } void login() { PerforceClient client; client.login(); } void logout() { PerforceClient client; client.logout(); } void about() { ::MessageBox( nppData._nppHandle, TEXT("Perforce Plugin ver. 1.0.7\r\n") \ TEXT("(C) Sven Erik Knop, Perforce Software, Jan 2015\r\n") \ TEXT("(C) Sven Erik Knop, Perforce Software, 2009,2010"), TEXT("Perforce plugin for Notepad++"), MB_OK ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#9 | 11396 | Sven Erik Knop |
Fixed login issue from file command (endless loop). Bumped version to 1.0.7 Final version in this iteration (I hope). |
||
#8 | 11391 | Sven Erik Knop | Added login status to connection info output. | ||
#7 | 11384 | Sven Erik Knop | Added logout menu item (more for testing than practical use) | ||
#6 | 11381 | Sven Erik Knop |
Added login dialog (after many years of waiting) Currently needs to log on in a separate step, next change should prompt for password if ticket expired in any case. Also fixed a bug with showing file information for freshly added files. |
||
#5 | 11340 | Sven Erik Knop | Added an about box and menu item. | ||
#4 | 10986 | Sven Erik Knop |
Updated for new-style P4V. Now using P4VC (there is no more P4V -cmd). Currently only Revgraph, Timelapse View and Submit are supported. |
||
#3 | 7817 | Sven Erik Knop |
Updated NppPerforcePlugin: prevent crash for some people using newer versions of Notepad++. It seems that the existing sample code are wrong: adding a separator to the menu list does require a new entry in the function list. I also re-added my Visual Studio solution and project and added a compiled release version of the DLL. Let me know if there are any problems. |
||
#2 | 7482 | Sven Erik Knop |
Added P4V support to the plugin. If p4v.exe is in the path, additional menu items become available. |
||
#1 | 7440 | Sven Erik Knop |
Notepad++ Perforce Plugin. The provided DLL will only work for the Unicode version of Notepad++. The code currently contains no provision for ASCII builds. The plugin can : Add Edit Delete Revert Sync (to head) --- Show file info Show connection info |