From 5956fea2bde61f50f79eb4ee59aee2d1a9c7840d Mon Sep 17 00:00:00 2001 From: Vince Date: Thu, 7 Jan 2021 14:04:14 -0500 Subject: [PATCH] @mlehenb: Add getCurrentFileDirectory() and use it in launchGit() and gitPrompt --- PluginDefinition.cpp | 22 ++++++++++++++++------ resource.h | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/PluginDefinition.cpp b/PluginDefinition.cpp index 84e9bed..8dc33b8 100644 --- a/PluginDefinition.cpp +++ b/PluginDefinition.cpp @@ -221,6 +221,20 @@ std::wstring getCurrentFile() return std::wstring( path ); } +/// +/// Gets the path to the current file's directory. +/// +/// @return Current file's directory path. +/// +std::wstring getCurrentFileDirectory() +{ + TCHAR path[MAX_PATH]; + ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTDIRECTORY, MAX_PATH, + (LPARAM)path); + + return std::wstring(path); +} + /// /// Gets the path to the TortioseGit executable from the registry. /// @@ -291,7 +305,7 @@ bool launchGit( std::wstring &command ) FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, - NULL, + const_cast( getCurrentFileDirectory().c_str() ), &si, &pi ) != 0; } @@ -408,11 +422,7 @@ void gitPrompt() if ( _gitPanel.isVisible() ) updateLoc( pathName ); else - { - TCHAR tempPath[MAX_PATH] = {0}; - SendMessage( nppData._nppHandle, NPPM_GETCURRENTDIRECTORY, MAX_PATH, ( LPARAM )tempPath ); - pathName = tempPath; - } + pathName = getCurrentFileDirectory(); ShellExecute( nppData._nppHandle, TEXT("open"), g_GitPrompt, NULL, pathName.c_str(), SW_SHOW ); } diff --git a/resource.h b/resource.h index c5b0b52..67981a7 100644 --- a/resource.h +++ b/resource.h @@ -8,7 +8,7 @@ #define VER_MAJOR 1 #define VER_MINOR 4 #define VER_RELEASE 4 -#define VER_BUILD 2 +#define VER_BUILD 3 #define VER_STRING STR(VER_MAJOR) "." STR(VER_MINOR) "." STR(VER_RELEASE) "." STR(VER_BUILD) #define FILE_DESCRIPTION "Notepad++ Plugin for Git SCM."