Skip to content

Commit b5f03c2

Browse files
thedalbeedalbee
andauthored
Expose current file upload as a shortcut-mappable command (#404)
* Expose current-file upload as a shortcut command The bounty asks for a shortcut-driven upload path. NppFTP already had the correct current-file upload behavior behind the toolbar and context-menu handler, so this extracts that path into FTPWindow::UploadCurrentFile and exposes it through the Notepad++ plugin command list for Shortcut Mapper assignment. Constraint: Windows/Notepad++ plugin behavior cannot be runtime-tested from this macOS environment. Rejected: Add a hard-coded default shortcut | Notepad++ lets users map plugin commands, and default shortcuts risk colliding with editor or user mappings. Rejected: Implement arbitrary file-list upload | the issue discussion identifies active-current-file upload as the useful bounded shortcut path. Confidence: medium Scope-risk: narrow Directive: Preserve the existing toolbar upload behavior; shortcut command should call the same upload path. Tested: repo_vet.py static safety scan Tested: git -c core.whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol diff --check Not-tested: Windows Notepad++ build/runtime and actual FTP upload flow. * Preserve upload path lookup for current-file command The shared upload helper must not narrow the existing tree-menu behavior. The previous code resolved the current Notepad++ path at invocation time, so the extracted helper now does the same instead of depending on the cached toolbar-enabled state. Constraint: Follow-up came from code review before runtime validation was available. Confidence: medium Scope-risk: narrow Tested: git -c core.whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol diff --check Not-tested: Windows Notepad++ build/runtime and actual FTP upload flow. --------- Co-authored-by: dalbee <dalbee@dalbee.local>
1 parent 9dc437d commit b5f03c2

6 files changed

Lines changed: 55 additions & 21 deletions

File tree

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ The toolbar provides the following buttons:
7676
* _Settings_: Access settings dialogs.
7777
* _Show Message Window_: Hide or Show the messages window.
7878

79+
The same current-file upload action is also available from the Notepad++ **Plugins > NppFTP > Upload Current File** menu item. Assign a shortcut to that command with Notepad++'s Shortcut Mapper if you want to upload the active local file without clicking the NppFTP toolbar.
80+
7981
## Treeview
8082
If an FTP session is active, the treeview will show the files on the server. Some actions of the toolbar depend on the selected object in the treeview (see toolbar). Double-clicking on a directory will show its contents. Double-clicking on a file will download it to the cache and open it.
8183

src/NppFTP.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ int NppFTP::ShowAboutDialog() const {
158158
return 0;
159159
}
160160

161+
int NppFTP::UploadCurrentFile() {
162+
if (!m_ftpWindow) {
163+
return -1;
164+
}
165+
return m_ftpWindow->UploadCurrentFile();
166+
}
167+
161168
int NppFTP::OnSave(const TCHAR* path) {
162169
if (!path || !m_ftpSession)
163170
return -1;

src/NppFTP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class NppFTP {
3636
int ShowFTPWindow();
3737
int FocusFTPWindow();
3838
int ShowAboutDialog() const;
39+
int UploadCurrentFile();
3940

4041
int OnSave(const TCHAR* path);
4142
int OnActivateLocalFile(const TCHAR* path);

src/PluginInterface.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
typedef void* BufferID;
2828

29-
const int nrFuncItem = 3;
29+
const int nrFuncItem = 4;
3030
FuncItem funcItems[nrFuncItem];
3131
NppData nppData;
3232
NppFTP nppFTP;
@@ -38,6 +38,7 @@ bool isStarted = false;
3838

3939
void __cdecl ShowFTPWindow();
4040
void __cdecl FocusFTPWindow();
41+
void __cdecl UploadCurrentFile();
4142
void __cdecl ShowAboutDialog();
4243
void __cdecl FakeItem();
4344

@@ -91,6 +92,11 @@ FuncItem * getFuncsArray(int * arraysize) {
9192
funcItems[2]._pShKey = NULL;
9293
lstrcpyn(funcItems[2]._itemName, TEXT("About NppFTP"), menuItemSize);
9394

95+
funcItems[3]._pFunc = &UploadCurrentFile;
96+
funcItems[3]._init2Check = false;
97+
funcItems[3]._pShKey = NULL;
98+
lstrcpyn(funcItems[3]._itemName, TEXT("Upload Current File"), menuItemSize);
99+
94100
return &funcItems[0];
95101
}
96102

@@ -169,5 +175,10 @@ void __cdecl ShowAboutDialog() {
169175
nppFTP.ShowAboutDialog();
170176
}
171177

178+
void __cdecl UploadCurrentFile() {
179+
if (isStarted)
180+
nppFTP.UploadCurrentFile();
181+
}
182+
172183
void __cdecl FakeItem() {
173184
}

src/Windows/FTPWindow.cpp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,37 @@ int FTPWindow::OnActivateLocalFile(const TCHAR* filename) {
272272
return 0;
273273
}
274274

275+
int FTPWindow::UploadCurrentFile(bool promptForFile) {
276+
if (!m_ftpSession || !m_currentSelection) {
277+
return -1;
278+
}
279+
280+
TCHAR source[MAX_PATH]{};
281+
BOOL doUpload = FALSE;
282+
283+
if (promptForFile) {
284+
source[0] = 0;
285+
int res = PU::GetOpenFilename(source, MAX_PATH, m_hParent);
286+
if (res == 0) {
287+
doUpload = TRUE;
288+
}
289+
} else {
290+
doUpload = ::SendMessage(m_hNpp, NPPM_GETFULLCURRENTPATH, (WPARAM)MAX_PATH, (LPARAM)source);
291+
}
292+
293+
if (doUpload != TRUE) {
294+
return -1;
295+
}
296+
297+
if (m_currentSelection->isDir()) {
298+
m_ftpSession->UploadFile(source, m_currentSelection->GetPath(), true);
299+
} else {
300+
m_ftpSession->UploadFile(source, m_currentSelection->GetParent()->GetPath(), true);
301+
}
302+
303+
return 0;
304+
}
305+
275306
int FTPWindow::RegisterClass() {
276307
WNDCLASSEX FTPWindowClass{};
277308
FTPWindowClass.cbSize = sizeof(WNDCLASSEX);
@@ -469,26 +500,8 @@ LRESULT FTPWindow::MessageProc(UINT uMsg, WPARAM wParam, LPARAM lParam) {
469500
break; }
470501
case IDM_POPUP_UPLOADFILE:
471502
case IDB_BUTTON_TOOLBAR_UPLOAD: {
472-
//upload(TRUE, TRUE); //upload to cached folder is present, else upload to last selected folder
473-
//m_ftpSession->UploadFile();
474-
TCHAR source[MAX_PATH]{};
475-
BOOL doUpload = FALSE;
476503
SHORT state = GetKeyState(VK_CONTROL);
477-
if ((state & 0x8000) && LOWORD(wParam) == IDB_BUTTON_TOOLBAR_UPLOAD) {
478-
source[0] = 0;
479-
int res = PU::GetOpenFilename(source, MAX_PATH, m_hParent);
480-
if (res == 0)
481-
doUpload = TRUE;
482-
} else {
483-
doUpload = ::SendMessage(m_hNpp, NPPM_GETFULLCURRENTPATH, (WPARAM)MAX_PATH, (LPARAM)source);
484-
}
485-
if (doUpload == TRUE) {
486-
if (m_currentSelection->isDir()) {
487-
m_ftpSession->UploadFile(source, m_currentSelection->GetPath(), true);
488-
} else {
489-
m_ftpSession->UploadFile(source, m_currentSelection->GetParent()->GetPath(), true);
490-
}
491-
}
504+
UploadCurrentFile((state & 0x8000) && LOWORD(wParam) == IDB_BUTTON_TOOLBAR_UPLOAD);
492505
result = TRUE;
493506
break;}
494507
case IDM_POPUP_UPLOADOTHERFILE: {

src/Windows/FTPWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class FTPWindow : public DockableWindow, public DropTargetWindow, public DropDat
5757
virtual int OnSize(int newWidth, int newHeight);
5858
virtual int OnProfileChange();
5959
virtual int OnActivateLocalFile(const TCHAR* filename);
60+
virtual int UploadCurrentFile(bool promptForFile = false);
6061

6162
static int RegisterClass();
6263

@@ -104,7 +105,6 @@ class FTPWindow : public DockableWindow, public DropTargetWindow, public DropDat
104105
virtual int Copy(FileObject* fo, FileObject* _newParent);
105106
virtual int VScrollTreeView(LONG pos);
106107

107-
//virtual int UploadCurrentFile(FileObject * parent);
108108
//virtual int UploadOtherFile(FileObject * parent);
109109

110110
Toolbar m_toolbar;

0 commit comments

Comments
 (0)