/* Copyright (C) Sven Erik Knop, Perforce Software, 2009 * */ #include <windows.h> #include <clientapi.h> #include <i18napi.h> #include <strtable.h> #include <enviro.h> #include "PerforceClient.h" #include "PluginInterface.h" extern NppData nppData; PerforceClient::PerforceClient( ) { TCHAR path[MAX_PATH]; ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTDIRECTORY, 0, (LPARAM) path); // Since this is a Unicode wchar, I need to convert it to ANSI first for Perforce char cwd[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, path, -1, cwd, MAX_PATH, NULL, NULL); enviro = new Enviro; enviro->Config( StrRef(cwd) ); client.SetCwd( cwd ); const char *lc; if( ( lc = enviro->Get( "P4CHARSET" )) ) { CharSetApi::CharSet cs = CharSetApi::NOCONV; cs = CharSetApi::Lookup( lc ); if( cs >= 0 ) { client.SetTrans( cs, cs, cs, cs ); } } Error e; client.Init( &e ); if ( e.Test() ) { except( "Connection failed.", &e ); } } PerforceClient::~PerforceClient() { Error e; client.Final( &e ); delete enviro; } void PerforceClient::except(const char *msg, Error *e) { StrBuf error; e->Fmt( &error ); StrBuf message; message << msg << "\n" << error; int length = MultiByteToWideChar(CP_ACP, 0, message.Text(), -1, NULL , 0); LPWSTR wmessage = new WCHAR[length]; (void) MultiByteToWideChar(CP_ACP, 0, message.Text(), -1, wmessage , length); ::MessageBox(nppData._nppHandle, wmessage, TEXT("Perforce error"), MB_OK); delete[] wmessage; } class OutputClient : public ClientUser { public: OutputClient() : error(false) { } virtual void OutputInfo( char level, const char *data ) { buf << data << "\n"; } virtual void OutputError( const char *errBuf ) { error = true; buf << errBuf << "\n"; } virtual void OutputStat( StrDict *varList ) { StrRef var, val; for( int i = 0; varList->GetVar( i, var, val ); i++ ) { if( var == "func" || var == P4Tag::v_specFormatted ) continue; buf << var << " ... " << val << "\n"; dict.VSetVar(var, val); } } bool errorExists() const { return error; } const StrBuf& getError() const { return err; } const StrBuf& getBuf() const { return buf; } StrDict& getDict() { return dict; } private: bool error; StrBuf err; StrBuf buf; StrBufDict dict; }; void PerforceClient::showInfo() { OutputClient cu; client.Run("info", &cu); displayMessage(TEXT("Perforce connection info"), cu.getBuf()); } void PerforceClient::showFileInfo() { TCHAR path[MAX_PATH]; ::SendMessage(nppData._nppHandle, NPPM_GETFULLCURRENTPATH, 0, (LPARAM)path); char file[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, path, -1, file, MAX_PATH, NULL, NULL); int argc = 1; char * argv[] = { file }; client.SetArgv( argc, argv ); OutputClient ui; // client.SetVar( P4Tag::v_tag ); client.Run("fstat", &ui); StrBuf buf; StrDict &dict = ui.getDict(); if( dict.GetVar("depotFile") ) { buf << "Depot File :\t" << dict.GetVar("depotFile") << "\n"; buf << "Client File :\t" << dict.GetVar("clientFile") << "\n"; if( dict.GetVar("haveRev") && dict.GetVar("headRev") ) { buf << "Revision : \t\t#" << dict.GetVar("haveRev") << "/" << dict.GetVar("headRev") << "\n"; } else { buf << "Revision : \t\t#0/0\n"; } buf << "Type : \t\t" << dict.GetVar("headType") << "\n"; if( dict.GetVar("action") ) { buf << "\nOpen for " << dict.GetVar("action") << " - change " << dict.GetVar("change") << " (" << dict.GetVar("type") << ")\n"; if( dict.GetVar("otherOpen") ) { int otherOpen = atoi(dict.GetVar("otherOpen")->Text()); for( int i = 0; i < otherOpen; i++) { StrBuf name("otherOpen"); name << i; buf << "\tAlso open by " << dict.GetVar(name) << "\n"; } } } } else { buf << "Not stored in Perforce"; } displayMessage(TEXT("Perforce file info"), buf /*ui.getBuf() */); } void PerforceClient::processFile(const char *cmd) { TCHAR path[MAX_PATH]; ::SendMessage(nppData._nppHandle, NPPM_GETFULLCURRENTPATH, 0, (LPARAM)path); char file[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, path, -1, file, MAX_PATH, NULL, NULL); int argc = 1; char * argv[] = { file }; client.SetArgv( argc, argv ); OutputClient ui; client.Run( cmd, &ui ); if( ui.errorExists() ) { displayMessage(TEXT("Perforce error"), ui.getError()); } //if( !strcmp(cmd, "sync") ) { // int currentBufferId = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0); // (void) ::SendMessage(nppData._nppHandle, NPPM_RELOADBUFFERID, currentBufferId, 0); //} //else { // refresh Notepad++ - currently a hack ::SendMessage(nppData._nppHandle, NPPMSG + 53, TRUE, 0); //} } void PerforceClient::displayMessage(LPWSTR title, const StrRef &buf) { int length = MultiByteToWideChar(CP_ACP, 0, buf.Text(), -1, NULL , 0); LPWSTR wmessage = new WCHAR[length]; (void) MultiByteToWideChar(CP_ACP, 0, buf.Text(), -1, wmessage , length); ::MessageBox(nppData._nppHandle, wmessage, title, MB_OK); delete[] wmessage; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#13 | 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). |
||
#12 | 11391 | Sven Erik Knop | Added login status to connection info output. | ||
#11 | 11384 | Sven Erik Knop | Added logout menu item (more for testing than practical use) | ||
#10 | 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. |
||
#9 | 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. |
||
#8 | 7822 | Sven Erik Knop |
Preparations for log-in dialog. The dialog is written, but not hooked up yet, but all the parts compile and link. Error dialog now displays a different error text if the ticket has expired, in preparation for the next step. |
||
#7 | 7821 | Sven Erik Knop |
Small change to Notepad++ plugin: improved error handling, in that errors are actually printed out as errors. Especially important if the user's session has expired and the user needs to log on again. Next up: Login dialog. |
||
#6 | 7482 | Sven Erik Knop |
Added P4V support to the plugin. If p4v.exe is in the path, additional menu items become available. |
||
#5 | 7469 | Sven Erik Knop | Solved a problem with Unicode enabled servers. | ||
#4 | 7468 | Sven Erik Knop | Show the otherAction as well. | ||
#3 | 7467 | Sven Erik Knop |
Updated the file info one more time. Now it shows the last change date, the last change number and the fact that files are open in other workspaces even if they are not open in the local workspace. |
||
#2 | 7465 | Sven Erik Knop |
Updated the fstat output for the plugin. Now the file type of the head revision is shown as well. |
||
#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 |