From 3546268c235780a6ba15266e7685aab7f6d6ce7f Mon Sep 17 00:00:00 2001 From: Rajendra Singh Date: Sun, 17 Feb 2019 08:10:59 +0530 Subject: [PATCH] Add the capacity to rename non-existing document's tab Close #5311 --- PowerEditor/src/Notepad_plus.cpp | 2 +- PowerEditor/src/NppIO.cpp | 55 +++++++++++++++---- PowerEditor/src/NppNotification.cpp | 2 +- .../ScitillaComponent/UserDefineDialog.cpp | 5 +- .../src/ScitillaComponent/UserDefineDialog.h | 16 +++--- 5 files changed, 60 insertions(+), 20 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 1615c689..e9060b47 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1995,7 +1995,7 @@ void Notepad_plus::checkDocState() } enableCommand(IDM_FILE_DELETE, isFileExisting, MENU); - enableCommand(IDM_FILE_RENAME, isFileExisting, MENU); + //enableCommand(IDM_FILE_RENAME, isFileExisting, MENU); enableCommand(IDM_FILE_OPEN_CMD, isFileExisting, MENU); enableCommand(IDM_FILE_OPEN_FOLDER, isFileExisting, MENU); enableCommand(IDM_FILE_RELOAD, isFileExisting, MENU); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 9d35890f..0c4fa933 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1404,17 +1404,52 @@ bool Notepad_plus::fileRename(BufferID id) scnN.nmhdr.idFrom = (uptr_t)bufferID; _pluginsManager.notify(&scnN); - FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); - - fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); - setFileOpenSaveDlgFilters(fDlg); - - fDlg.setDefFileName(buf->getFileName()); - TCHAR *pfn = fDlg.doSaveDlg(); - bool success = false; - if (pfn) - success = MainFileManager->moveFile(bufferID, pfn); + bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE; + if (isFileExisting) + { + FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); + + fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); + setFileOpenSaveDlgFilters(fDlg); + + fDlg.setDefFileName(buf->getFileName()); + TCHAR *pfn = fDlg.doSaveDlg(); + + if (pfn) + success = MainFileManager->moveFile(bufferID, pfn); + } + else + { + // We are just going to rename the tab nothing else + // So just rename the tab and rename the backup file too if applicable + + StringDlg strDlg; + strDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), TEXT("Rename Current Tab"), TEXT("New Name : "), buf->getFileName(), 0, true); + + TCHAR *tabNewName = reinterpret_cast(strDlg.doDialog()); + if (tabNewName) + { + success = true; + buf->setFileName(tabNewName); + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI().isSnapshotMode(); + if (isSnapshotMode) + { + generic_string oldBackUpFile = buf->getBackupFileName(); + + // Change the backup file name and let MainFileManager decide the new filename + buf->setBackupFileName(TEXT("")); + + // Create new backup + buf->setModifiedStatus(true); + bool bRes = MainFileManager->backupCurrentBuffer(); + + // Delete old backup + if (bRes) + ::DeleteFile(oldBackUpFile.c_str()); + } + } + } scnN.nmhdr.code = success ? NPPN_FILERENAMED : NPPN_FILERENAMECANCEL; _pluginsManager.notify(&scnN); diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 6342773f..caa55b15 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -564,7 +564,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE; _tabPopupMenu.enableItem(IDM_FILE_DELETE, isFileExisting); - _tabPopupMenu.enableItem(IDM_FILE_RENAME, isFileExisting); + //_tabPopupMenu.enableItem(IDM_FILE_RENAME, isFileExisting); _tabPopupMenu.enableItem(IDM_FILE_OPEN_FOLDER, isFileExisting); _tabPopupMenu.enableItem(IDM_FILE_OPEN_CMD, isFileExisting); diff --git a/PowerEditor/src/ScitillaComponent/UserDefineDialog.cpp b/PowerEditor/src/ScitillaComponent/UserDefineDialog.cpp index 717cbf5d..2a6e2ddf 100644 --- a/PowerEditor/src/ScitillaComponent/UserDefineDialog.cpp +++ b/PowerEditor/src/ScitillaComponent/UserDefineDialog.cpp @@ -1449,7 +1449,10 @@ INT_PTR CALLBACK StringDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) if (_txtLen) ::SendDlgItemMessage(_hSelf, IDC_STRING_EDIT, EM_SETLIMITTEXT, _txtLen, 0); - return TRUE; + if (_shouldGotoCenter) + goToCenter(); + + return TRUE; } case WM_COMMAND : diff --git a/PowerEditor/src/ScitillaComponent/UserDefineDialog.h b/PowerEditor/src/ScitillaComponent/UserDefineDialog.h index 2a83c4e6..4b61aaae 100644 --- a/PowerEditor/src/ScitillaComponent/UserDefineDialog.h +++ b/PowerEditor/src/ScitillaComponent/UserDefineDialog.h @@ -399,13 +399,14 @@ class StringDlg : public StaticDialog { public : StringDlg() : StaticDialog() {}; - void init(HINSTANCE hInst, HWND parent, const TCHAR *title, const TCHAR *staticName, const TCHAR *text2Set, int txtLen = 0) { - Window::init(hInst, parent); - _title = title; - _static = staticName; - _textValue = text2Set; - _txtLen = txtLen; - }; + void init(HINSTANCE hInst, HWND parent, const TCHAR *title, const TCHAR *staticName, const TCHAR *text2Set, int txtLen = 0, bool bGotoCenter = false) { + Window::init(hInst, parent); + _title = title; + _static = staticName; + _textValue = text2Set; + _txtLen = txtLen; + _shouldGotoCenter = bGotoCenter; + }; INT_PTR doDialog() { return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_STRING_DLG), _hParent, dlgProc, reinterpret_cast(this)); @@ -421,6 +422,7 @@ private : generic_string _textValue; generic_string _static; int _txtLen = 0; + bool _shouldGotoCenter = false; }; class StylerDlg