Add the capacity to rename non-existing document's tab

Close #5311
This commit is contained in:
Rajendra Singh 2019-02-17 08:10:59 +05:30 committed by Don HO
parent c4ff9f76a3
commit 3546268c23
5 changed files with 60 additions and 20 deletions

View File

@ -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);

View File

@ -1404,6 +1404,10 @@ bool Notepad_plus::fileRename(BufferID id)
scnN.nmhdr.idFrom = (uptr_t)bufferID;
_pluginsManager.notify(&scnN);
bool success = false;
bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE;
if (isFileExisting)
{
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
@ -1412,9 +1416,40 @@ bool Notepad_plus::fileRename(BufferID id)
fDlg.setDefFileName(buf->getFileName());
TCHAR *pfn = fDlg.doSaveDlg();
bool success = false;
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<TCHAR *>(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);

View File

@ -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);

View File

@ -1449,6 +1449,9 @@ INT_PTR CALLBACK StringDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
if (_txtLen)
::SendDlgItemMessage(_hSelf, IDC_STRING_EDIT, EM_SETLIMITTEXT, _txtLen, 0);
if (_shouldGotoCenter)
goToCenter();
return TRUE;
}

View File

@ -399,12 +399,13 @@ 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) {
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() {
@ -421,6 +422,7 @@ private :
generic_string _textValue;
generic_string _static;
int _txtLen = 0;
bool _shouldGotoCenter = false;
};
class StylerDlg