[NEW_FEATURE] Add rename and delete current document features.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@263 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
84bd5081b0
commit
ad776f17fe
|
@ -793,7 +793,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne) {
|
|||
_lastRecentFileList.add(buf->getFilePath());
|
||||
}
|
||||
|
||||
int nrDocs = _pDocTab->nbItem();
|
||||
int nrDocs = whichOne==MAIN_VIEW?(_mainDocTab.nbItem()):(_subDocTab.nbItem());
|
||||
|
||||
//Do all the works
|
||||
removeBufferFromView(id, whichOne);
|
||||
|
@ -1117,6 +1117,73 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy)
|
|||
}
|
||||
}
|
||||
|
||||
bool Notepad_plus::fileRename(BufferID id, int curView)
|
||||
{
|
||||
BufferID bufferID = id;
|
||||
if (id == BUFFER_INVALID)
|
||||
bufferID = _pEditView->getCurrentBufferID();
|
||||
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
||||
|
||||
FileDialog fDlg(_hSelf, _hInst);
|
||||
|
||||
fDlg.setExtFilter("All types", ".*", NULL);
|
||||
setFileOpenSaveDlgFilters(fDlg);
|
||||
|
||||
fDlg.setDefFileName(buf->getFileName());
|
||||
char *pfn = fDlg.doSaveDlg();
|
||||
|
||||
if (pfn)
|
||||
{
|
||||
MainFileManager->moveFile(bufferID, pfn);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
bool Notepad_plus::fileDelete(BufferID id, int curView)
|
||||
{
|
||||
BufferID bufferID = id;
|
||||
if (id == BUFFER_INVALID)
|
||||
bufferID = _pEditView->getCurrentBufferID();
|
||||
|
||||
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
||||
const char *fileNamePath = buf->getFilePath();
|
||||
|
||||
if (PathFileExists(fileNamePath))
|
||||
return false;
|
||||
|
||||
int res = doDeleteOrNot(fileNamePath);
|
||||
if (res == IDYES && doDelete(fileNamePath))
|
||||
{
|
||||
doClose(bufferID, currentView());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
bool Notepad_plus::fileDelete(BufferID id, int curView)
|
||||
{
|
||||
BufferID bufferID = id;
|
||||
if (id == BUFFER_INVALID)
|
||||
bufferID = _pEditView->getCurrentBufferID();
|
||||
|
||||
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
||||
const char *fileNamePath = buf->getFilePath();
|
||||
|
||||
if (doDeleteOrNot(fileNamePath) == IDYES)
|
||||
{
|
||||
if (!MainFileManager->deleteFile(bufferID))
|
||||
{
|
||||
::MessageBox(_hSelf, "Delete File failed", "Delete File", MB_OK);
|
||||
return false;
|
||||
}
|
||||
doClose(bufferID, MAIN_VIEW);
|
||||
doClose(bufferID, SUB_VIEW);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Notepad_plus::fileClose(BufferID id, int curView)
|
||||
{
|
||||
BufferID bufferID = id;
|
||||
|
@ -1955,6 +2022,8 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||
char cilpFullPath[32] = "Full file path to Clipboard";
|
||||
char cilpFileName[32] = "File name to Clipboard";
|
||||
char cilpCurrentDir[32] = "Current dir path to Clipboard";
|
||||
char remove[32] = "Delete me";
|
||||
char rename[32] = "Rename me";
|
||||
|
||||
|
||||
const char *pClose = close;
|
||||
|
@ -1969,6 +2038,8 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||
const char *pCilpFullPath = cilpFullPath;
|
||||
const char *pCilpFileName = cilpFileName;
|
||||
const char *pCilpCurrentDir = cilpCurrentDir;
|
||||
const char *pRename = rename;
|
||||
const char *pRemove = remove;
|
||||
if (_nativeLang)
|
||||
{
|
||||
TiXmlNode *tabBarMenu = _nativeLang->FirstChild("Menu");
|
||||
|
@ -2000,6 +2071,16 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||
pGoToView = element->Attribute("name"); break;
|
||||
case 6 :
|
||||
pCloneToView = element->Attribute("name"); break;
|
||||
case 7 :
|
||||
pCilpFullPath = element->Attribute("name"); break;
|
||||
case 8 :
|
||||
pCilpFileName = element->Attribute("name"); break;
|
||||
case 9 :
|
||||
pCilpCurrentDir = element->Attribute("name"); break;
|
||||
case 10 :
|
||||
pRename = element->Attribute("name"); break;
|
||||
case 11 :
|
||||
pRemove = element->Attribute("name"); break;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2019,12 +2100,25 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||
pGoToView = goToView;
|
||||
if (!pCloneToView || !pCloneToView[0])
|
||||
pCloneToView = cloneToView;
|
||||
if (!pCilpFullPath || !pCilpFullPath[0])
|
||||
pCilpFullPath = cilpFullPath;
|
||||
if (!pCilpFileName || !pCilpFileName[0])
|
||||
pCilpFileName = cilpFileName;
|
||||
if (!pCilpCurrentDir || !pCilpCurrentDir[0])
|
||||
pCilpCurrentDir = cilpCurrentDir;
|
||||
if (!pRename || !pRename[0])
|
||||
pRename = rename;
|
||||
if (!pRemove || !pRemove[0])
|
||||
pRemove = remove;
|
||||
|
||||
}
|
||||
vector<MenuItemUnit> itemUnitArray;
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, pClose));
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, pCloseBut));
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVE, pSave));
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, pSaveAs));
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RENAME, pRename));
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_DELETE, pRemove));
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_PRINT, pPrint));
|
||||
itemUnitArray.push_back(MenuItemUnit(0, NULL));
|
||||
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_SETREADONLY, pReadOnly));
|
||||
|
@ -2810,6 +2904,14 @@ void Notepad_plus::command(int id)
|
|||
fileClose();
|
||||
break;
|
||||
|
||||
case IDM_FILE_DELETE:
|
||||
fileDelete();
|
||||
break;
|
||||
|
||||
case IDM_FILE_RENAME:
|
||||
fileRename();
|
||||
break;
|
||||
|
||||
case IDM_FILE_CLOSEALL:
|
||||
fileCloseAll();
|
||||
break;
|
||||
|
@ -6097,7 +6199,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
|||
//Add recent files
|
||||
HMENU hFileMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_FILE);
|
||||
int nbLRFile = pNppParam->getNbLRFile();
|
||||
int pos = 17;
|
||||
int pos = IDM_FILEMENU_LASTONE - IDM_FILE + 2;
|
||||
|
||||
_lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos);
|
||||
for (int i = 0 ; i < nbLRFile ; i++)
|
||||
|
|
|
@ -114,7 +114,6 @@ public:
|
|||
if (unicodeSupported?(::IsDialogMessageW(_hModelessDlgs[i], msg)):(::IsDialogMessageA(_hModelessDlgs[i], msg)))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
@ -124,6 +123,7 @@ public:
|
|||
bool doReload(BufferID id, bool alert = true);
|
||||
bool doSave(BufferID, const char * filename, bool isSaveCopy = false);
|
||||
void doClose(BufferID, int whichOne);
|
||||
//bool doDelete(const char *fileName) const {return ::DeleteFile(fileName) != 0;};
|
||||
|
||||
inline void fileNew();
|
||||
void fileOpen();
|
||||
|
@ -134,6 +134,8 @@ public:
|
|||
bool fileSave(BufferID id = BUFFER_INVALID);
|
||||
bool fileSaveAll();
|
||||
bool fileSaveAs(BufferID id = BUFFER_INVALID, bool isSaveCopy = false);
|
||||
bool fileDelete(BufferID id = BUFFER_INVALID, int curView = -1);
|
||||
bool fileRename(BufferID id = BUFFER_INVALID, int curView = -1);
|
||||
|
||||
bool addBufferToView(BufferID id, int whichOne);
|
||||
bool moveBuffer(BufferID id, int whereTo); //assumes whereFrom is otherView(whereTo)
|
||||
|
@ -391,23 +393,36 @@ private:
|
|||
//END: Document management
|
||||
|
||||
int doSaveOrNot(const char *fn) {
|
||||
char phrase[512] = "Save file \"";
|
||||
strcat(strcat(phrase, fn), "\" ?");
|
||||
return ::MessageBox(_hSelf, phrase, "Save", MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
|
||||
char pattern[64] = "Save file \"%s\" ?";
|
||||
char phrase[512];
|
||||
sprintf(phrase, pattern, fn);
|
||||
return doActionOrNot("Save", phrase, MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
|
||||
};
|
||||
|
||||
int doReloadOrNot(const char *fn) {
|
||||
char phrase[512] = "The file \"";
|
||||
strcat(strcat(phrase, fn), "\" is modified by another program. Reload this file?");
|
||||
return ::MessageBox(_hSelf, phrase, "Reload", MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL);
|
||||
char pattern[128] = "The file \"%s\" is modified by another program.\rReload this file?";
|
||||
char phrase[512];
|
||||
sprintf(phrase, pattern, fn);
|
||||
return doActionOrNot("Reload", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL);
|
||||
};
|
||||
|
||||
int doCloseOrNot(const char *fn) {
|
||||
char phrase[512] = "The file \"";
|
||||
strcat(strcat(phrase, fn), "\" doesn't exist anymore. Keep this file in editor ?");
|
||||
return ::MessageBox(_hSelf, phrase, "Keep non existing file", MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL);
|
||||
char pattern[128] = "The file \"%s\" doesn't exist anymore.\rKeep this file in editor?";
|
||||
char phrase[512];
|
||||
sprintf(phrase, pattern, fn);
|
||||
return doActionOrNot("Keep non existing file", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL);
|
||||
};
|
||||
|
||||
int doDeleteOrNot(const char *fn) {
|
||||
char pattern[128] = "The file \"%s\"\rwill be deleted from your disk and this document will be closed.\rContinue?";
|
||||
char phrase[512];
|
||||
sprintf(phrase, pattern, fn);
|
||||
return doActionOrNot("Delete file", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL);
|
||||
};
|
||||
|
||||
int doActionOrNot(const char *title, const char *displayText, int type) {
|
||||
return ::MessageBox(_hSelf, displayText, title, type);
|
||||
};
|
||||
void enableMenu(int cmdID, bool doEnable) const {
|
||||
int flag = doEnable?MF_ENABLED | MF_BYCOMMAND:MF_DISABLED | MF_GRAYED | MF_BYCOMMAND;
|
||||
::EnableMenuItem(_mainMenuHandle, cmdID, flag);
|
||||
|
|
|
@ -251,9 +251,11 @@ BEGIN
|
|||
MENUITEM "Save &As...", IDM_FILE_SAVEAS
|
||||
MENUITEM "Save a Copy As...", IDM_FILE_SAVECOPYAS
|
||||
MENUITEM "Sav&e All", IDM_FILE_SAVEALL
|
||||
MENUITEM "Rename...", IDM_FILE_RENAME
|
||||
MENUITEM "&Close", IDM_FILE_CLOSE
|
||||
MENUITEM "Cl&ose All", IDM_FILE_CLOSEALL
|
||||
MENUITEM "Close All but Active Document", IDM_FILE_CLOSEALL_BUT_CURRENT
|
||||
MENUITEM "Delete from Disk", IDM_FILE_DELETE
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Load Session...", IDM_FILE_LOADSESSION
|
||||
MENUITEM "Save Session...", IDM_FILE_SAVESESSION
|
||||
|
|
|
@ -54,6 +54,8 @@ WinMenuKeyDefinition winKeyDefs[] = { //array of accelerator keys for all std me
|
|||
{VK_W, IDM_FILE_CLOSE, true, false, false, NULL},
|
||||
{VK_NULL, IDM_FILE_CLOSEALL, false, false, false, NULL},
|
||||
{VK_NULL, IDM_FILE_CLOSEALL_BUT_CURRENT, false, false, false, NULL},
|
||||
{VK_NULL, IDM_FILE_DELETE, false, false, false, NULL},
|
||||
{VK_NULL, IDM_FILE_RENAME, false, false, false, NULL},
|
||||
{VK_NULL, IDM_FILE_LOADSESSION, false, false, false, NULL},
|
||||
{VK_NULL, IDM_FILE_SAVESESSION, false, false, false, NULL},
|
||||
{VK_P, IDM_FILE_PRINT, true, false, false, NULL},
|
||||
|
|
|
@ -437,7 +437,6 @@ bool FileManager::reloadBuffer(BufferID id) {
|
|||
buf->setUnicodeMode(UnicodeConvertor.getEncoding());
|
||||
// buf->setNeedsLexing(true);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -447,6 +446,29 @@ bool FileManager::reloadBufferDeferred(BufferID id) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileManager::deleteFile(BufferID id)
|
||||
{
|
||||
Buffer * buf = getBufferByID(id);
|
||||
const char *fileNamePath = buf->getFilePath();
|
||||
if (!PathFileExists(fileNamePath))
|
||||
return false;
|
||||
return ::DeleteFile(fileNamePath) != 0;
|
||||
}
|
||||
|
||||
bool FileManager::moveFile(BufferID id, const char * newFileName)
|
||||
{
|
||||
Buffer * buf = getBufferByID(id);
|
||||
const char *fileNamePath = buf->getFilePath();
|
||||
if (!PathFileExists(fileNamePath))
|
||||
return false;
|
||||
|
||||
if (::MoveFile(fileNamePath, newFileName) == 0)
|
||||
return false;
|
||||
|
||||
buf->setFileName(newFileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileManager::saveBuffer(BufferID id, const char * filename, bool isCopy) {
|
||||
Buffer * buffer = getBufferByID(id);
|
||||
bool isHidden = false;
|
||||
|
|
|
@ -89,6 +89,8 @@ public:
|
|||
bool reloadBuffer(BufferID id);
|
||||
bool reloadBufferDeferred(BufferID id);
|
||||
bool saveBuffer(BufferID id, const char * filename, bool isCopy = false);
|
||||
bool deleteFile(BufferID id);
|
||||
bool moveFile(BufferID id, const char * newFilename);
|
||||
|
||||
bool createEmptyFile(const char * path);
|
||||
|
||||
|
|
|
@ -37,9 +37,11 @@
|
|||
#define IDM_FILE_SAVESESSION (IDM_FILE + 13)
|
||||
#define IDM_FILE_RELOAD (IDM_FILE + 14)
|
||||
#define IDM_FILE_SAVECOPYAS (IDM_FILE + 15)
|
||||
#define IDM_FILE_DELETE (IDM_FILE + 16)
|
||||
#define IDM_FILE_RENAME (IDM_FILE + 17)
|
||||
|
||||
// A mettre à jour si on ajoute nouveau menu item dans le menu "File"
|
||||
#define IDM_FILEMENU_LASTONE IDM_FILE_SAVECOPYAS
|
||||
#define IDM_FILEMENU_LASTONE IDM_FILE_RENAME
|
||||
|
||||
#define IDM_EDIT (IDM + 2000)
|
||||
#define IDM_EDIT_CUT (IDM_EDIT + 1)
|
||||
|
|
Loading…
Reference in New Issue