From 955094331d42cdd80bb50c0272dfcdbc2b1c0f27 Mon Sep 17 00:00:00 2001 From: Dennis Syrovatsky Date: Wed, 14 Dec 2005 16:42:33 +0000 Subject: Added code for local and remote renaming files and folders. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@449 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- rfb_win32/FolderManager.cxx | 12 ++++++ rfb_win32/FolderManager.h | 1 + vncviewer/FTDialog.cxx | 92 ++++++++++++++++++++++++++++++++++++++++++++- vncviewer/FTDialog.h | 20 +++++++++- vncviewer/FileTransfer.cxx | 15 ++++++++ vncviewer/FileTransfer.h | 1 + vncviewer/resource.h | 3 +- vncviewer/vncviewer.rc | 2 +- 8 files changed, 141 insertions(+), 5 deletions(-) diff --git a/rfb_win32/FolderManager.cxx b/rfb_win32/FolderManager.cxx index 06daf311..349e0f75 100644 --- a/rfb_win32/FolderManager.cxx +++ b/rfb_win32/FolderManager.cxx @@ -44,6 +44,18 @@ FolderManager::createDir(char *pFullPath) return true; } +bool +FolderManager::renameIt(char *pPath, char *pOldName, char *pNewName) +{ + char fullOldName[FT_FILENAME_SIZE]; + char fullNewName[FT_FILENAME_SIZE]; + + sprintf(fullOldName, "%s\\%s", pPath, pOldName); + sprintf(fullNewName, "%s\\%s", pPath, pNewName); + + return renameIt(fullOldName, fullNewName); +} + bool FolderManager::renameIt(char *pOldName, char *pNewName) { diff --git a/rfb_win32/FolderManager.h b/rfb_win32/FolderManager.h index 55f352d1..97a6538d 100644 --- a/rfb_win32/FolderManager.h +++ b/rfb_win32/FolderManager.h @@ -39,6 +39,7 @@ namespace rfb { bool createDir(char *pFullPath); bool renameIt(char *pOldName, char *pNewName); + bool renameIt(char *pPath, char *pOldName, char *pNewName); bool deleteIt(char *pPrefix, FileInfo *pFI); bool deleteIt(char *pFullPath); diff --git a/vncviewer/FTDialog.cxx b/vncviewer/FTDialog.cxx index 64c8f3ab..a02ae756 100644 --- a/vncviewer/FTDialog.cxx +++ b/vncviewer/FTDialog.cxx @@ -43,6 +43,7 @@ FTDialog::FTDialog(HINSTANCE hInst, FileTransfer *pFT) m_pProgress = NULL; m_pCancelingDlg = NULL; m_pCreateFolderDlg = NULL; + m_pRenameDlg = NULL; m_hwndFTDialog = NULL; m_hwndLocalPath = NULL; @@ -170,6 +171,21 @@ FTDialog::destroyFTDialog() m_pProgress = NULL; } + if(m_pCancelingDlg != NULL) { + delete m_pCancelingDlg; + m_pCancelingDlg = NULL; + } + + if (m_pCreateFolderDlg != NULL) { + delete m_pCreateFolderDlg; + m_pCreateFolderDlg = NULL; + } + + if(m_pRenameDlg != NULL) { + delete m_pRenameDlg; + m_pRenameDlg = NULL; + } + if (DestroyWindow(m_hwndFTDialog)) m_hwndFTDialog = NULL; } @@ -442,15 +458,53 @@ FTDialog::onDownload() void FTDialog::onLocalRename() { - MessageBox(NULL, "onLocalRename", "FTDialog", MB_OK); + if (m_pRenameDlg != NULL) return; + FileInfo fi; + if (m_pLocalLV->getSelectedItems(&fi) == 1) { + unsigned int flags = fi.getFlagsAt(0); + m_pRenameDlg = new FTDialog::RenameDlg(this); + if (m_pRenameDlg != NULL) { + if (flags & FT_ATTR_DIR) { + m_pRenameDlg->create(fi.getNameAt(0), true); + } else { + m_pRenameDlg->create(fi.getNameAt(0), false); + } + if (strlen(m_pRenameDlg->getFolderName()) > 0) { + FolderManager fm; + fm.renameIt(m_szLocalPath, fi.getNameAt(0), m_pRenameDlg->getFolderName()); + showLocalLVItems(); + } + delete m_pRenameDlg; + m_pRenameDlg = NULL; + } + } + setButtonsState(); } void FTDialog::onRemoteRename() { - MessageBox(NULL, "onRemoteRename", "FTDialog", MB_OK); + if (m_pRenameDlg != NULL) return; + FileInfo fi; + if (m_pRemoteLV->getSelectedItems(&fi) == 1) { + unsigned int flags = fi.getFlagsAt(0); + m_pRenameDlg = new FTDialog::RenameDlg(this); + if (m_pRenameDlg != NULL) { + if (flags & FT_ATTR_DIR) { + m_pRenameDlg->create(fi.getNameAt(0), true); + } else { + m_pRenameDlg->create(fi.getNameAt(0), false); + } + if (strlen(m_pRenameDlg->getFolderName()) > 0) { + m_pFileTransfer->renameRemote(m_szRemotePath, fi.getNameAt(0), m_pRenameDlg->getFolderName()); + } + delete m_pRenameDlg; + m_pRenameDlg = NULL; + } + } + setButtonsState(); } void @@ -938,3 +992,37 @@ FTDialog::CreateFolderDlg::onOk() strcpy(m_szFolderName, getItemString(IDC_FTFOLDERNAME)); return true; } + +FTDialog::RenameDlg::RenameDlg(FTDialog *pFTDlg) : CreateFolderDlg(pFTDlg) +{ + m_bFolder = false; +} + +FTDialog::RenameDlg::~RenameDlg() +{ +} + +bool +FTDialog::RenameDlg::create(char *pFilename, bool bFolder) +{ + m_bFolder = bFolder; + strcpy(m_szFilename, pFilename); + return showDialog(MAKEINTRESOURCE(IDD_FTCREATEFOLDER), m_pFTDlg->getWndHandle()); +} + +void +FTDialog::RenameDlg::initDialog() +{ + char buf[2*FT_FILENAME_SIZE]; + if (m_bFolder) { + SetWindowText(handle, "Rename Folder"); + sprintf(buf, "Rename Folder '%s'", m_szFilename); + } else { + SetWindowText(handle, "Rename File"); + sprintf(buf, "Rename File '%s'", m_szFilename); + } + + setItemString(IDC_FTTEXT, buf); + setItemString(IDC_FTFOLDERNAME, m_szFilename); + SendDlgItemMessage(handle, IDC_FTFOLDERNAME, EM_SETSEL, (WPARAM) 0, (LPARAM) -1); +} \ No newline at end of file diff --git a/vncviewer/FTDialog.h b/vncviewer/FTDialog.h index e362f95d..04b1c9bb 100644 --- a/vncviewer/FTDialog.h +++ b/vncviewer/FTDialog.h @@ -198,13 +198,31 @@ namespace rfb { bool create(); char *getFolderName() { return m_szFolderName; } - private: + protected: FTDialog *m_pFTDlg; char m_szFolderName[FT_FILENAME_SIZE]; }; private: CreateFolderDlg *m_pCreateFolderDlg; + + public: + class RenameDlg : public CreateFolderDlg + { + public: + RenameDlg(FTDialog *pFTDlg); + ~RenameDlg(); + + bool create(char *pFilename, bool bFolder); + void initDialog(); + + private: + bool m_bFolder; + char m_szFilename[FT_FILENAME_SIZE]; + }; + + private: + RenameDlg *m_pRenameDlg; }; } } diff --git a/vncviewer/FileTransfer.cxx b/vncviewer/FileTransfer.cxx index 37475060..b324901e 100644 --- a/vncviewer/FileTransfer.cxx +++ b/vncviewer/FileTransfer.cxx @@ -372,6 +372,21 @@ FileTransfer::createRemoteFolder(char *pPath, char *pName) m_pWriter->writeFileListRqst(strlen(pPath), pPath, false); } +void +FileTransfer::renameRemote(char *pPath, char *pOldName, char *pNewName) +{ + char fullOldName[FT_FILENAME_SIZE]; + char fullNewName[FT_FILENAME_SIZE]; + + sprintf(fullOldName, "%s\\%s", pPath, pOldName); + sprintf(fullNewName, "%s\\%s", pPath, pNewName); + + m_pWriter->writeFileRenameRqst(strlen(fullOldName), strlen(fullNewName), + fullOldName, fullNewName); + m_queueFileListRqst.add(pPath, 0, 0, FT_FLR_DEST_MAIN); + m_pWriter->writeFileListRqst(strlen(pPath), pPath, false); +} + bool FileTransfer::procFileListDataMsg() { diff --git a/vncviewer/FileTransfer.h b/vncviewer/FileTransfer.h index eccdcd6e..2c5d8027 100644 --- a/vncviewer/FileTransfer.h +++ b/vncviewer/FileTransfer.h @@ -65,6 +65,7 @@ namespace rfb { void uploadFilePortion(); void createRemoteFolder(char *pPath, char *pName); + void renameRemote(char *pPath, char *pOldName, char *pNewName); bool m_bCancel; diff --git a/vncviewer/resource.h b/vncviewer/resource.h index adff6511..4967ab9f 100644 --- a/vncviewer/resource.h +++ b/vncviewer/resource.h @@ -111,6 +111,7 @@ #define IDC_CONFIRM_TEXT 1080 #define IDC_EDIT2 1082 #define IDC_FTFOLDERNAME 1083 +#define IDC_FTTEXT 1084 #define ID_TOOLBAR 40002 #define ID_CLOSE 40003 #define ID_OPTIONS 40004 @@ -139,7 +140,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 133 #define _APS_NEXT_COMMAND_VALUE 40028 -#define _APS_NEXT_CONTROL_VALUE 1084 +#define _APS_NEXT_CONTROL_VALUE 1085 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/vncviewer/vncviewer.rc b/vncviewer/vncviewer.rc index 90171bad..d0e01f78 100644 --- a/vncviewer/vncviewer.rc +++ b/vncviewer/vncviewer.rc @@ -369,7 +369,7 @@ BEGIN EDITTEXT IDC_FTFOLDERNAME,7,19,179,14,ES_AUTOHSCROLL DEFPUSHBUTTON "OK",IDOK,80,42,50,14 PUSHBUTTON "Cancel",IDCANCEL,136,42,50,14 - LTEXT "New Folder Name",IDC_STATIC,7,7,179,8 + LTEXT "New Folder Name",IDC_FTTEXT,7,7,179,8 END -- cgit v1.2.3