Enhance 'Open File' command - open file without selecting whole path.
Closes #2878
This commit is contained in:
parent
389524d230
commit
7ad86ad688
@ -427,6 +427,7 @@ enum winVer{ WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, W
|
|||||||
#define NPPM_GETEXTPART (RUNCOMMAND_USER + EXT_PART)
|
#define NPPM_GETEXTPART (RUNCOMMAND_USER + EXT_PART)
|
||||||
#define NPPM_GETCURRENTWORD (RUNCOMMAND_USER + CURRENT_WORD)
|
#define NPPM_GETCURRENTWORD (RUNCOMMAND_USER + CURRENT_WORD)
|
||||||
#define NPPM_GETNPPDIRECTORY (RUNCOMMAND_USER + NPP_DIRECTORY)
|
#define NPPM_GETNPPDIRECTORY (RUNCOMMAND_USER + NPP_DIRECTORY)
|
||||||
|
#define NPPM_GETFILENAMEATCURSOR (RUNCOMMAND_USER + GETFILENAMEATCURSOR)
|
||||||
// BOOL NPPM_GETXXXXXXXXXXXXXXXX(size_t strLen, TCHAR *str)
|
// BOOL NPPM_GETXXXXXXXXXXXXXXXX(size_t strLen, TCHAR *str)
|
||||||
// where str is the allocated TCHAR array,
|
// where str is the allocated TCHAR array,
|
||||||
// strLen is the allocated array size
|
// strLen is the allocated array size
|
||||||
@ -453,6 +454,7 @@ enum winVer{ WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, W
|
|||||||
#define CURRENT_LINE 8
|
#define CURRENT_LINE 8
|
||||||
#define CURRENT_COLUMN 9
|
#define CURRENT_COLUMN 9
|
||||||
#define NPP_FULL_FILE_PATH 10
|
#define NPP_FULL_FILE_PATH 10
|
||||||
|
#define GETFILENAMEATCURSOR 11
|
||||||
|
|
||||||
|
|
||||||
// Notification code
|
// Notification code
|
||||||
|
@ -123,6 +123,16 @@ LRESULT Notepad_plus_Window::runProc(HWND hwnd, UINT message, WPARAM wParam, LPA
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used by NPPM_GETFILENAMEATCURSOR
|
||||||
|
int CharacterIs(TCHAR c, TCHAR *any)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; any[i] != 0; i++)
|
||||||
|
{
|
||||||
|
if (any[i] == c) return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
@ -699,6 +709,58 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case NPPM_GETFILENAMEATCURSOR: // wParam = buffer length, lParam = (TCHAR*)buffer
|
||||||
|
{
|
||||||
|
const int strSize = CURRENTWORD_MAXLENGTH;
|
||||||
|
TCHAR str[strSize];
|
||||||
|
TCHAR strLine[strSize];
|
||||||
|
size_t lineNumber;
|
||||||
|
int col;
|
||||||
|
int i;
|
||||||
|
int hasSlash;
|
||||||
|
TCHAR *pTchar = reinterpret_cast<TCHAR *>(lParam);
|
||||||
|
|
||||||
|
_pEditView->getGenericSelectedText(str, strSize); // this is either the selected text, or the word under the cursor if there is no selection
|
||||||
|
hasSlash = FALSE;
|
||||||
|
for (i = 0; str[i] != 0; i++) if (CharacterIs(str[i], TEXT("\\/"))) hasSlash = TRUE;
|
||||||
|
|
||||||
|
if (hasSlash == FALSE)
|
||||||
|
{
|
||||||
|
// it's not a full file name so try to find the beginning and ending of it
|
||||||
|
int start;
|
||||||
|
int end;
|
||||||
|
TCHAR *delimiters;
|
||||||
|
|
||||||
|
lineNumber = _pEditView->getCurrentLineNumber();
|
||||||
|
col = _pEditView->getCurrentColumnNumber();
|
||||||
|
_pEditView->getLine(lineNumber, strLine, strSize);
|
||||||
|
|
||||||
|
// find the start
|
||||||
|
start = col;
|
||||||
|
delimiters = TEXT(" \t[(\"<>");
|
||||||
|
while ((start > 0) && (CharacterIs(strLine[start], delimiters) == FALSE)) start--;
|
||||||
|
if (CharacterIs(strLine[start], delimiters)) start++;
|
||||||
|
|
||||||
|
// find the end
|
||||||
|
end = col;
|
||||||
|
delimiters = TEXT(" \t:()[]<>\"\r\n");
|
||||||
|
while ((strLine[end] != 0) && (CharacterIs(strLine[end], delimiters) == FALSE)) end++;
|
||||||
|
|
||||||
|
lstrcpyn(str, &strLine[start], end - start + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lstrlen(str) >= int(wParam)) //buffer too small
|
||||||
|
{
|
||||||
|
::MessageBox(hwnd, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETFILENAMEATCURSOR error"), MB_OK);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else //buffer large enough, perform safe copy
|
||||||
|
{
|
||||||
|
lstrcpyn(pTchar, str, static_cast<int32_t>(wParam));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case NPPM_GETNPPFULLFILEPATH:
|
case NPPM_GETNPPFULLFILEPATH:
|
||||||
case NPPM_GETNPPDIRECTORY:
|
case NPPM_GETNPPDIRECTORY:
|
||||||
{
|
{
|
||||||
|
@ -379,7 +379,7 @@ void Notepad_plus::command(int id)
|
|||||||
|
|
||||||
HWND hwnd = _pPublicInterface->getHSelf();
|
HWND hwnd = _pPublicInterface->getHSelf();
|
||||||
TCHAR curentWord[CURRENTWORD_MAXLENGTH];
|
TCHAR curentWord[CURRENTWORD_MAXLENGTH];
|
||||||
::SendMessage(hwnd, NPPM_GETCURRENTWORD, CURRENTWORD_MAXLENGTH, reinterpret_cast<LPARAM>(curentWord));
|
::SendMessage(hwnd, NPPM_GETFILENAMEATCURSOR, CURRENTWORD_MAXLENGTH, reinterpret_cast<LPARAM>(curentWord));
|
||||||
|
|
||||||
TCHAR cmd2Exec[CURRENTWORD_MAXLENGTH];
|
TCHAR cmd2Exec[CURRENTWORD_MAXLENGTH];
|
||||||
if (id == IDM_EDIT_OPENINFOLDER)
|
if (id == IDM_EDIT_OPENINFOLDER)
|
||||||
|
Loading…
Reference in New Issue
Block a user