2012-04-15 16:54:38 +00:00
|
|
|
// This file is part of Notepad++ project
|
|
|
|
// Copyright (C)2003 Don HO <don.h@free.fr>
|
2010-01-31 17:45:32 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
2010-01-31 17:45:32 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// Note that the GPL places important restrictions on "derived works", yet
|
|
|
|
// it does not provide a detailed definition of that term. To avoid
|
|
|
|
// misunderstandings, we consider an application to constitute a
|
|
|
|
// "derivative work" for the purpose of this license if it does any of the
|
|
|
|
// following:
|
|
|
|
// 1. Integrates source code from Notepad++.
|
|
|
|
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
|
|
|
|
// installer, such as those produced by InstallShield.
|
|
|
|
// 3. Links to a library or executes a program that does any of the above.
|
2010-01-31 17:45:32 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
|
|
|
|
#include "precompiledHeaders.h"
|
2010-03-26 00:22:14 +00:00
|
|
|
#include "Notepad_plus_Window.h"
|
2010-01-31 17:45:32 +00:00
|
|
|
#include "FileDialog.h"
|
2010-11-13 11:15:06 +00:00
|
|
|
#include "EncodingMapper.h"
|
2011-06-11 14:40:44 +00:00
|
|
|
#include "VerticalFileSwitcher.h"
|
2014-02-24 22:38:56 +00:00
|
|
|
#include "functionListPanel.h"
|
2012-09-08 12:50:55 +00:00
|
|
|
#include <TCHAR.h>
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2010-11-01 16:08:43 +00:00
|
|
|
|
2014-03-05 21:18:05 +00:00
|
|
|
BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isReadOnly, int encoding)
|
2010-02-21 18:17:54 +00:00
|
|
|
{
|
2014-03-04 18:56:53 +00:00
|
|
|
NppParameters *pNppParam = NppParameters::getInstance();
|
|
|
|
TCHAR longFileName[MAX_PATH];
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
::GetFullPathName(fileName, MAX_PATH, longFileName, NULL);
|
|
|
|
::GetLongPathName(longFileName, longFileName, MAX_PATH);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
_lastRecentFileList.remove(longFileName);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
const TCHAR * fileName2Find;
|
|
|
|
generic_string gs_fileName = fileName;
|
|
|
|
size_t res = gs_fileName.find_first_of(UNTITLED_STR);
|
|
|
|
|
|
|
|
if (res != string::npos && res == 0)
|
|
|
|
{
|
|
|
|
fileName2Find = fileName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fileName2Find = longFileName;
|
|
|
|
}
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
BufferID test = MainFileManager->getBufferFromName(fileName2Find);
|
|
|
|
if (test != BUFFER_INVALID)
|
|
|
|
{
|
|
|
|
//switchToFile(test);
|
|
|
|
//Dont switch, not responsibility of doOpen, but of caller
|
|
|
|
if (_pTrayIco)
|
|
|
|
{
|
|
|
|
if (_pTrayIco->isInTray())
|
|
|
|
{
|
|
|
|
::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW);
|
|
|
|
if (!_pPublicInterface->isPrelaunch())
|
|
|
|
_pTrayIco->doTrayIcon(REMOVE);
|
|
|
|
::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return test;
|
|
|
|
}
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (isFileSession(longFileName) && PathFileExists(longFileName))
|
|
|
|
{
|
|
|
|
fileLoadSession(longFileName);
|
|
|
|
return BUFFER_INVALID;
|
|
|
|
}
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
bool isWow64Off = false;
|
|
|
|
if (!PathFileExists(longFileName))
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
|
|
|
|
isWow64Off = true;
|
|
|
|
}
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
bool globbing = wcsrchr(longFileName, TCHAR('*')) || wcsrchr(longFileName, TCHAR('?'));
|
|
|
|
if (!PathFileExists(longFileName) && !globbing)
|
|
|
|
{
|
|
|
|
TCHAR str2display[MAX_PATH*2];
|
|
|
|
generic_string longFileDir(longFileName);
|
|
|
|
PathRemoveFileSpec(longFileDir);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
bool isCreateFileSuccessful = false;
|
|
|
|
if (PathFileExists(longFileDir.c_str()))
|
|
|
|
{
|
|
|
|
wsprintf(str2display, TEXT("%s doesn't exist. Create it?"), longFileName);
|
|
|
|
if (::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_YESNO) == IDYES)
|
|
|
|
{
|
|
|
|
bool res = MainFileManager->createEmptyFile(longFileName);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
isCreateFileSuccessful = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wsprintf(str2display, TEXT("Cannot create the file \"%s\""), longFileName);
|
|
|
|
::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-01 16:08:43 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (!isCreateFileSuccessful)
|
|
|
|
{
|
|
|
|
if (isWow64Off)
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
|
|
|
|
isWow64Off = false;
|
|
|
|
}
|
|
|
|
return BUFFER_INVALID;
|
|
|
|
}
|
|
|
|
}
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
// Notify plugins that current file is about to load
|
|
|
|
// Plugins can should use this notification to filter SCN_MODIFIED
|
|
|
|
SCNotification scnN;
|
|
|
|
scnN.nmhdr.code = NPPN_FILEBEFORELOAD;
|
|
|
|
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
|
|
|
|
scnN.nmhdr.idFrom = NULL;
|
|
|
|
_pluginsManager.notify(&scnN);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (encoding == -1)
|
|
|
|
{
|
|
|
|
encoding = getHtmlXmlEncoding(longFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferID buffer = MainFileManager->loadFile(longFileName, NULL, encoding);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (buffer != BUFFER_INVALID)
|
|
|
|
{
|
|
|
|
_isFileOpening = true;
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
Buffer * buf = MainFileManager->getBufferByID(buffer);
|
|
|
|
// if file is read only, we set the view read only
|
|
|
|
if (isReadOnly)
|
|
|
|
buf->setUserReadOnly(true);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
// Notify plugins that current file is about to open
|
|
|
|
scnN.nmhdr.code = NPPN_FILEBEFOREOPEN;
|
|
|
|
scnN.nmhdr.idFrom = (uptr_t)buffer;
|
|
|
|
_pluginsManager.notify(&scnN);
|
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
loadBufferIntoView(buffer, currentView());
|
2013-02-18 23:13:18 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (_pTrayIco)
|
|
|
|
{
|
|
|
|
if (_pTrayIco->isInTray())
|
|
|
|
{
|
|
|
|
::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW);
|
|
|
|
if (!_pPublicInterface->isPrelaunch())
|
|
|
|
_pTrayIco->doTrayIcon(REMOVE);
|
|
|
|
::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PathRemoveFileSpec(longFileName);
|
|
|
|
_linkTriggered = true;
|
|
|
|
_isFileOpening = false;
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
// Notify plugins that current file is just opened
|
|
|
|
scnN.nmhdr.code = NPPN_FILEOPENED;
|
|
|
|
_pluginsManager.notify(&scnN);
|
|
|
|
if (_pFileSwitcherPanel)
|
|
|
|
_pFileSwitcherPanel->newItem((int)buf, currentView());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (globbing || ::PathIsDirectory(fileName))
|
|
|
|
{
|
|
|
|
vector<generic_string> fileNames;
|
|
|
|
vector<generic_string> patterns;
|
|
|
|
if (globbing)
|
|
|
|
{
|
|
|
|
const TCHAR * substring = wcsrchr(fileName, TCHAR('\\'));
|
|
|
|
size_t pos = substring - fileName;
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
patterns.push_back(substring + 1);
|
|
|
|
generic_string dir(fileName, pos + 1);
|
2014-03-05 21:18:05 +00:00
|
|
|
getMatchedFileNames(dir.c_str(), patterns, fileNames, isRecursive, false);
|
2014-03-04 18:56:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
generic_string fileNameStr = fileName;
|
|
|
|
if (fileName[lstrlen(fileName) - 1] != '\\')
|
|
|
|
fileNameStr += TEXT("\\");
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
patterns.push_back(TEXT("*"));
|
|
|
|
getMatchedFileNames(fileNameStr.c_str(), patterns, fileNames, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok2Open = true;
|
|
|
|
size_t nbFiles2Open = fileNames.size();
|
2012-05-01 12:20:18 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (nbFiles2Open > 200)
|
|
|
|
{
|
|
|
|
ok2Open = IDYES == _nativeLangSpeaker.messageBox("NbFileToOpenImportantWarning",
|
|
|
|
_pPublicInterface->getHSelf(),
|
|
|
|
TEXT("$INT_REPLACE$ files are about to be opened.\rAre you sure to open them?"),
|
|
|
|
TEXT("Amount of files to open is too large"),
|
|
|
|
MB_YESNO|MB_APPLMODAL,
|
|
|
|
nbFiles2Open);
|
|
|
|
}
|
2012-05-01 12:20:18 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (ok2Open)
|
|
|
|
{
|
|
|
|
for (size_t i = 0 ; i < nbFiles2Open ; ++i)
|
|
|
|
{
|
|
|
|
doOpen(fileNames[i].c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
generic_string msg = TEXT("Can not open file \"");
|
|
|
|
msg += longFileName;
|
|
|
|
msg += TEXT("\".");
|
|
|
|
::MessageBox(_pPublicInterface->getHSelf(), msg.c_str(), TEXT("ERROR"), MB_OK);
|
|
|
|
_isFileOpening = false;
|
2010-01-31 17:45:32 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
scnN.nmhdr.code = NPPN_FILELOADFAILED;
|
|
|
|
_pluginsManager.notify(&scnN);
|
|
|
|
}
|
|
|
|
}
|
2010-11-01 16:08:43 +00:00
|
|
|
|
2014-03-04 18:56:53 +00:00
|
|
|
if (isWow64Off)
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
|
|
|
|
isWow64Off = false;
|
|
|
|
}
|
|
|
|
return buffer;
|
2010-01-31 17:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::doReload(BufferID id, bool alert)
|
|
|
|
{
|
|
|
|
if (alert)
|
|
|
|
{
|
2011-01-19 21:05:40 +00:00
|
|
|
int answer = _nativeLangSpeaker.messageBox("DocReloadWarning",
|
|
|
|
_pPublicInterface->getHSelf(),
|
|
|
|
TEXT("Are you sure you want to reload the current file and lose the changes made in Notepad++?"),
|
|
|
|
TEXT("Reload"),
|
|
|
|
MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL);
|
|
|
|
if (answer != IDYES)
|
2010-01-31 17:45:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//In order to prevent Scintilla from restyling the entire document,
|
|
|
|
//an empty Document is inserted during reload if needed.
|
|
|
|
bool mainVisisble = (_mainEditView.getCurrentBufferID() == id);
|
|
|
|
bool subVisisble = (_subEditView.getCurrentBufferID() == id);
|
|
|
|
if (mainVisisble) {
|
|
|
|
_mainEditView.saveCurrentPos();
|
|
|
|
_mainEditView.execute(SCI_SETDOCPOINTER, 0, 0);
|
|
|
|
}
|
|
|
|
if (subVisisble) {
|
|
|
|
_subEditView.saveCurrentPos();
|
|
|
|
_subEditView.execute(SCI_SETDOCPOINTER, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mainVisisble && !subVisisble) {
|
|
|
|
return MainFileManager->reloadBufferDeferred(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = MainFileManager->reloadBuffer(id);
|
|
|
|
Buffer * pBuf = MainFileManager->getBufferByID(id);
|
|
|
|
if (mainVisisble) {
|
|
|
|
_mainEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
|
|
|
|
_mainEditView.restoreCurrentPos();
|
|
|
|
}
|
|
|
|
if (subVisisble) {
|
|
|
|
_subEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
|
|
|
|
_subEditView.restoreCurrentPos();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
|
|
|
|
{
|
|
|
|
SCNotification scnN;
|
|
|
|
// Notify plugins that current file is about to be saved
|
|
|
|
if (!isCopy)
|
|
|
|
{
|
|
|
|
|
|
|
|
scnN.nmhdr.code = NPPN_FILEBEFORESAVE;
|
2010-03-26 00:22:14 +00:00
|
|
|
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
|
2010-01-31 17:45:32 +00:00
|
|
|
scnN.nmhdr.idFrom = (uptr_t)id;
|
|
|
|
_pluginsManager.notify(&scnN);
|
|
|
|
}
|
|
|
|
|
2012-09-08 12:50:55 +00:00
|
|
|
generic_string error_msg;
|
|
|
|
bool res = MainFileManager->saveBuffer(id, filename, isCopy, &error_msg);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
|
|
|
if (!isCopy)
|
|
|
|
{
|
|
|
|
scnN.nmhdr.code = NPPN_FILESAVED;
|
|
|
|
_pluginsManager.notify(&scnN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res)
|
2012-09-08 12:50:55 +00:00
|
|
|
{
|
|
|
|
if(error_msg.empty())
|
|
|
|
{
|
|
|
|
_nativeLangSpeaker.messageBox("FileLockedWarning",
|
|
|
|
_pPublicInterface->getHSelf(),
|
|
|
|
TEXT("Please check if this file is opened in another program."),
|
|
|
|
TEXT("Save failed"),
|
|
|
|
MB_OK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
::MessageBox(_pPublicInterface->getHSelf(), error_msg.c_str(), TEXT("Save failed"), MB_OK);
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 22:38:56 +00:00
|
|
|
|
|
|
|
if (_pFuncList && (!_pFuncList->isClosed()) && _pFuncList->isVisible())
|
|
|
|
{
|
|
|
|
_pFuncList->reload();
|
|
|
|
}
|
2010-01-31 17:45:32 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-12-08 12:28:52 +00:00
|
|
|
void Notepad_plus::doClose(BufferID id, int whichOne)
|
|
|
|
{
|
|
|
|
DocTabView *tabToClose = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab;
|
|
|
|
int i = tabToClose->getIndexByBuffer(id);
|
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
|
|
|
|
|
|
|
// Notify plugins that current file is about to be closed
|
|
|
|
SCNotification scnN;
|
|
|
|
scnN.nmhdr.code = NPPN_FILEBEFORECLOSE;
|
2010-03-26 00:22:14 +00:00
|
|
|
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
|
2010-01-31 17:45:32 +00:00
|
|
|
scnN.nmhdr.idFrom = (uptr_t)id;
|
|
|
|
_pluginsManager.notify(&scnN);
|
|
|
|
|
|
|
|
//add to recent files if its an existing file
|
2010-11-21 01:44:40 +00:00
|
|
|
if (!buf->isUntitled())
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
2010-11-21 01:44:40 +00:00
|
|
|
// if the file doesn't exist, it could be redirected
|
|
|
|
// So we turn Wow64 off
|
|
|
|
bool isWow64Off = false;
|
|
|
|
NppParameters *pNppParam = NppParameters::getInstance();
|
2011-09-25 01:33:34 +00:00
|
|
|
const TCHAR *fn = buf->getFullPathName();
|
|
|
|
if (!PathFileExists(fn))
|
2010-11-21 01:44:40 +00:00
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
|
|
|
|
isWow64Off = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PathFileExists(buf->getFullPathName()))
|
|
|
|
_lastRecentFileList.add(buf->getFullPathName());
|
|
|
|
|
|
|
|
// We enable Wow64 system, if it was disabled
|
|
|
|
if (isWow64Off)
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
|
|
|
|
isWow64Off = false;
|
|
|
|
}
|
2010-01-31 17:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int nrDocs = whichOne==MAIN_VIEW?(_mainDocTab.nbItem()):(_subDocTab.nbItem());
|
|
|
|
|
|
|
|
//Do all the works
|
2011-06-13 01:24:00 +00:00
|
|
|
bool isBufRemoved = removeBufferFromView(id, whichOne);
|
2011-06-30 21:37:43 +00:00
|
|
|
int hiddenBufferID = -1;
|
2010-01-31 17:45:32 +00:00
|
|
|
if (nrDocs == 1 && canHideView(whichOne))
|
|
|
|
{ //close the view if both visible
|
|
|
|
hideView(whichOne);
|
2011-06-30 21:37:43 +00:00
|
|
|
|
|
|
|
// if the current activated buffer is in this view,
|
|
|
|
// then get buffer ID to remove the entry from File Switcher Pannel
|
|
|
|
hiddenBufferID = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETBUFFERIDFROMPOS, 0, whichOne);
|
2010-01-31 17:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notify plugins that current file is closed
|
2011-06-13 01:24:00 +00:00
|
|
|
if (isBufRemoved)
|
|
|
|
{
|
|
|
|
scnN.nmhdr.code = NPPN_FILECLOSED;
|
|
|
|
_pluginsManager.notify(&scnN);
|
2011-06-30 21:37:43 +00:00
|
|
|
|
|
|
|
// The document could be clonned.
|
|
|
|
// if the same buffer ID is not found then remove the entry from File Switcher Pannel
|
2011-06-13 01:24:00 +00:00
|
|
|
if (_pFileSwitcherPanel)
|
2011-06-30 21:37:43 +00:00
|
|
|
{
|
2011-07-09 10:14:54 +00:00
|
|
|
//int posInfo = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_GETPOSFROMBUFFERID, (WPARAM)id ,0);
|
|
|
|
|
|
|
|
_pFileSwitcherPanel->closeItem((int)id, whichOne);
|
2011-06-30 21:37:43 +00:00
|
|
|
|
|
|
|
if (hiddenBufferID != -1)
|
2011-07-09 10:14:54 +00:00
|
|
|
_pFileSwitcherPanel->closeItem((int)hiddenBufferID, whichOne);
|
2011-06-30 21:37:43 +00:00
|
|
|
}
|
2011-06-13 01:24:00 +00:00
|
|
|
}
|
2013-01-01 21:02:17 +00:00
|
|
|
command(IDM_VIEW_REFRESHTABAR);
|
2010-01-31 17:45:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
generic_string Notepad_plus::exts2Filters(generic_string exts) const
|
|
|
|
{
|
|
|
|
const TCHAR *extStr = exts.c_str();
|
|
|
|
TCHAR aExt[MAX_PATH];
|
|
|
|
generic_string filters(TEXT(""));
|
|
|
|
|
|
|
|
int j = 0;
|
|
|
|
bool stop = false;
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t i = 0, len = exts.length(); i < len ; ++i)
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
|
|
|
if (extStr[i] == ' ')
|
|
|
|
{
|
|
|
|
if (!stop)
|
|
|
|
{
|
|
|
|
aExt[j] = '\0';
|
|
|
|
stop = true;
|
|
|
|
|
|
|
|
if (aExt[0])
|
|
|
|
{
|
|
|
|
filters += TEXT("*.");
|
|
|
|
filters += aExt;
|
|
|
|
filters += TEXT(";");
|
|
|
|
}
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aExt[j] = extStr[i];
|
|
|
|
stop = false;
|
2013-07-08 00:12:50 +00:00
|
|
|
++j;
|
2010-01-31 17:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j > 0)
|
|
|
|
{
|
|
|
|
aExt[j] = '\0';
|
|
|
|
if (aExt[0])
|
|
|
|
{
|
|
|
|
filters += TEXT("*.");
|
|
|
|
filters += aExt;
|
|
|
|
filters += TEXT(";");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the last ';'
|
|
|
|
filters = filters.substr(0, filters.length()-1);
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType)
|
|
|
|
{
|
|
|
|
NppParameters *pNppParam = NppParameters::getInstance();
|
|
|
|
NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
Lang *l = NppParameters::getInstance()->getLangFromIndex(i++);
|
|
|
|
|
|
|
|
int ltIndex = 0;
|
|
|
|
bool ltFound = false;
|
|
|
|
while (l)
|
|
|
|
{
|
|
|
|
LangType lid = l->getLangID();
|
|
|
|
|
|
|
|
bool inExcludedList = false;
|
|
|
|
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t j = 0, len = nppGUI._excludedLangList.size() ; j < len ; ++j)
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
|
|
|
if (lid == nppGUI._excludedLangList[j]._langType)
|
|
|
|
{
|
|
|
|
inExcludedList = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inExcludedList)
|
|
|
|
{
|
|
|
|
const TCHAR *defList = l->getDefaultExtList();
|
|
|
|
const TCHAR *userList = NULL;
|
|
|
|
|
|
|
|
LexerStylerArray &lsa = (NppParameters::getInstance())->getLStylerArray();
|
|
|
|
const TCHAR *lName = l->getLangName();
|
|
|
|
LexerStyler *pLS = lsa.getLexerStylerByName(lName);
|
|
|
|
|
|
|
|
if (pLS)
|
|
|
|
userList = pLS->getLexerUserExt();
|
|
|
|
|
|
|
|
generic_string list(TEXT(""));
|
|
|
|
if (defList)
|
|
|
|
list += defList;
|
|
|
|
if (userList)
|
|
|
|
{
|
|
|
|
list += TEXT(" ");
|
|
|
|
list += userList;
|
|
|
|
}
|
|
|
|
|
|
|
|
generic_string stringFilters = exts2Filters(list);
|
|
|
|
const TCHAR *filters = stringFilters.c_str();
|
|
|
|
if (filters[0])
|
|
|
|
{
|
2011-06-18 21:53:14 +00:00
|
|
|
fDlg.setExtsFilter(getLangDesc(lid, false).c_str(), filters);
|
2010-01-31 17:45:32 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get index of lang type to find
|
|
|
|
//
|
|
|
|
if (langType != -1 && !ltFound)
|
|
|
|
{
|
|
|
|
ltFound = langType == lid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (langType != -1 && !ltFound)
|
|
|
|
{
|
2013-07-08 00:12:50 +00:00
|
|
|
++ltIndex;
|
2010-01-31 17:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l = (NppParameters::getInstance())->getLangFromIndex(i++);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ltFound)
|
|
|
|
return -1;
|
|
|
|
return ltIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Notepad_plus::fileClose(BufferID id, int curView)
|
|
|
|
{
|
|
|
|
BufferID bufferID = id;
|
|
|
|
if (id == BUFFER_INVALID)
|
|
|
|
bufferID = _pEditView->getCurrentBufferID();
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
|
|
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
//process the fileNamePath into LRF
|
|
|
|
const TCHAR *fileNamePath = buf->getFullPathName();
|
|
|
|
|
|
|
|
if (buf->isUntitled() && buf->docLength() == 0)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else if (buf->isDirty())
|
|
|
|
{
|
|
|
|
|
|
|
|
res = doSaveOrNot(fileNamePath);
|
|
|
|
if (res == IDYES)
|
|
|
|
{
|
|
|
|
if (!fileSave(id)) // the cancel button of savedialog is pressed, aborts closing
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (res == IDCANCEL)
|
|
|
|
{
|
|
|
|
return false; //cancel aborts closing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// else IDNO we continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int viewToClose = currentView();
|
|
|
|
if (curView != -1)
|
|
|
|
viewToClose = curView;
|
|
|
|
//first check amount of documents, we dont want the view to hide if we closed a secondary doc with primary being empty
|
|
|
|
//int nrDocs = _pDocTab->nbItem();
|
|
|
|
doClose(bufferID, viewToClose);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::fileCloseAll()
|
|
|
|
{
|
|
|
|
//closes all documents, makes the current view the only one visible
|
|
|
|
|
|
|
|
//first check if we need to save any file
|
2013-07-08 00:12:50 +00:00
|
|
|
for(int i = 0; i < _mainDocTab.nbItem(); ++i)
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
|
|
|
BufferID id = _mainDocTab.getBufferByIndex(i);
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
|
|
|
if (buf->isUntitled() && buf->docLength() == 0)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else if (buf->isDirty())
|
|
|
|
{
|
2013-01-08 01:00:19 +00:00
|
|
|
activateBuffer(id, MAIN_VIEW);
|
|
|
|
if(!activateBuffer(id, SUB_VIEW))
|
|
|
|
switchEditViewTo(MAIN_VIEW);
|
2010-02-11 23:53:06 +00:00
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
int res = doSaveOrNot(buf->getFullPathName());
|
|
|
|
if (res == IDYES)
|
|
|
|
{
|
|
|
|
if (!fileSave(id))
|
|
|
|
return false; //abort entire procedure
|
|
|
|
}
|
|
|
|
else if (res == IDCANCEL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-08 00:12:50 +00:00
|
|
|
for(int i = 0; i < _subDocTab.nbItem(); ++i)
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
|
|
|
BufferID id = _subDocTab.getBufferByIndex(i);
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
|
|
|
if (buf->isUntitled() && buf->docLength() == 0)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else if (buf->isDirty())
|
|
|
|
{
|
2013-01-08 01:00:19 +00:00
|
|
|
activateBuffer(id, SUB_VIEW);
|
|
|
|
switchEditViewTo(SUB_VIEW);
|
2010-02-11 23:53:06 +00:00
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
int res = doSaveOrNot(buf->getFullPathName());
|
|
|
|
if (res == IDYES)
|
|
|
|
{
|
|
|
|
if (!fileSave(id))
|
|
|
|
return false; //abort entire procedure
|
|
|
|
}
|
|
|
|
else if (res == IDCANCEL)
|
|
|
|
{
|
2013-01-08 01:00:19 +00:00
|
|
|
return false;
|
2010-01-31 17:45:32 +00:00
|
|
|
//otherwise continue (IDNO)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Then start closing, inactive view first so the active is left open
|
|
|
|
if (bothActive())
|
|
|
|
{ //first close all docs in non-current view, which gets closed automatically
|
|
|
|
//Set active tab to the last one closed.
|
|
|
|
activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView());
|
|
|
|
for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
|
|
|
|
doClose(_pNonDocTab->getBufferByIndex(i), otherView());
|
|
|
|
}
|
|
|
|
//hideView(otherView());
|
|
|
|
}
|
|
|
|
|
|
|
|
activateBuffer(_pDocTab->getBufferByIndex(0), currentView());
|
|
|
|
for(int i = _pDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
|
|
|
|
doClose(_pDocTab->getBufferByIndex(i), currentView());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-03 23:40:07 +00:00
|
|
|
bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
|
|
|
|
{
|
|
|
|
// First check if we need to save any file.
|
|
|
|
|
|
|
|
std::vector<int>::const_iterator itIndexesEnd = krvecBufferIndexes.end();
|
|
|
|
|
|
|
|
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
|
|
|
|
BufferID id = _pDocTab->getBufferByIndex(*itIndex);
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
|
|
|
if (buf->isUntitled() && buf->docLength() == 0)
|
|
|
|
{
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
else if (buf->isDirty())
|
|
|
|
{
|
|
|
|
if(_activeView == MAIN_VIEW)
|
|
|
|
{
|
|
|
|
activateBuffer(id, MAIN_VIEW);
|
|
|
|
if(!activateBuffer(id, SUB_VIEW))
|
|
|
|
switchEditViewTo(MAIN_VIEW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
activateBuffer(id, SUB_VIEW);
|
|
|
|
switchEditViewTo(SUB_VIEW);
|
|
|
|
}
|
|
|
|
|
|
|
|
int res = doSaveOrNot(buf->getFullPathName());
|
|
|
|
if (res == IDYES)
|
|
|
|
{
|
|
|
|
if (!fileSave(id))
|
|
|
|
return false; // Abort entire procedure.
|
|
|
|
}
|
|
|
|
else if (res == IDCANCEL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we close.
|
|
|
|
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
|
|
|
|
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::fileCloseAllToLeft()
|
|
|
|
{
|
|
|
|
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
|
|
|
|
// indexes (smaller than the one just closed) will point to the wrong tab.
|
|
|
|
std::vector<int> vecIndexesToClose;
|
|
|
|
for(int i = _pDocTab->getCurrentTabIndex() - 1; i >= 0; i--) {
|
|
|
|
vecIndexesToClose.push_back(i);
|
|
|
|
}
|
|
|
|
return fileCloseAllGiven(vecIndexesToClose);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::fileCloseAllToRight()
|
|
|
|
{
|
|
|
|
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
|
|
|
|
// indexes (smaller than the one just closed) will point to the wrong tab.
|
|
|
|
const int kiActive = _pDocTab->getCurrentTabIndex();
|
|
|
|
std::vector<int> vecIndexesToClose;
|
|
|
|
for(int i = _pDocTab->nbItem() - 1; i > kiActive; i--) {
|
|
|
|
vecIndexesToClose.push_back(i);
|
|
|
|
}
|
|
|
|
return fileCloseAllGiven(vecIndexesToClose);
|
|
|
|
}
|
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
bool Notepad_plus::fileCloseAllButCurrent()
|
|
|
|
{
|
|
|
|
BufferID current = _pEditView->getCurrentBufferID();
|
|
|
|
int active = _pDocTab->getCurrentTabIndex();
|
|
|
|
//closes all documents, makes the current view the only one visible
|
|
|
|
|
|
|
|
//first check if we need to save any file
|
2013-07-08 00:12:50 +00:00
|
|
|
for(int i = 0; i < _mainDocTab.nbItem(); ++i) {
|
2010-01-31 17:45:32 +00:00
|
|
|
BufferID id = _mainDocTab.getBufferByIndex(i);
|
|
|
|
if (id == current)
|
|
|
|
continue;
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
|
|
|
if (buf->isUntitled() && buf->docLength() == 0)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else if (buf->isDirty())
|
|
|
|
{
|
2013-01-08 01:00:19 +00:00
|
|
|
activateBuffer(id, MAIN_VIEW);
|
|
|
|
if(!activateBuffer(id, SUB_VIEW))
|
|
|
|
switchEditViewTo(MAIN_VIEW);
|
2010-02-11 23:53:06 +00:00
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
int res = doSaveOrNot(buf->getFullPathName());
|
|
|
|
if (res == IDYES)
|
|
|
|
{
|
|
|
|
if (!fileSave(id))
|
|
|
|
return false; //abort entire procedure
|
|
|
|
}
|
|
|
|
else if (res == IDCANCEL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-08 00:12:50 +00:00
|
|
|
for(int i = 0; i < _subDocTab.nbItem(); ++i)
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
|
|
|
BufferID id = _subDocTab.getBufferByIndex(i);
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
|
|
|
if (id == current)
|
|
|
|
continue;
|
|
|
|
if (buf->isUntitled() && buf->docLength() == 0)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
else if (buf->isDirty())
|
|
|
|
{
|
2013-01-08 01:00:19 +00:00
|
|
|
activateBuffer(id, SUB_VIEW);
|
|
|
|
switchEditViewTo(SUB_VIEW);
|
2010-02-11 23:53:06 +00:00
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
int res = doSaveOrNot(buf->getFullPathName());
|
|
|
|
if (res == IDYES)
|
|
|
|
{
|
|
|
|
if (!fileSave(id))
|
|
|
|
return false; //abort entire procedure
|
|
|
|
}
|
|
|
|
else if (res == IDCANCEL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Then start closing, inactive view first so the active is left open
|
|
|
|
if (bothActive())
|
|
|
|
{ //first close all docs in non-current view, which gets closed automatically
|
|
|
|
//Set active tab to the last one closed.
|
|
|
|
activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView());
|
|
|
|
for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
|
|
|
|
doClose(_pNonDocTab->getBufferByIndex(i), otherView());
|
|
|
|
}
|
|
|
|
//hideView(otherView());
|
|
|
|
}
|
|
|
|
|
|
|
|
activateBuffer(_pDocTab->getBufferByIndex(0), currentView());
|
|
|
|
for(int i = _pDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
|
|
|
|
if (i == active) { //dont close active index
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
doClose(_pDocTab->getBufferByIndex(i), currentView());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::fileSave(BufferID id)
|
|
|
|
{
|
|
|
|
BufferID bufferID = id;
|
|
|
|
if (id == BUFFER_INVALID)
|
|
|
|
bufferID = _pEditView->getCurrentBufferID();
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
|
|
|
|
|
|
|
if (!buf->getFileReadOnly() && buf->isDirty()) //cannot save if readonly
|
|
|
|
{
|
|
|
|
const TCHAR *fn = buf->getFullPathName();
|
|
|
|
if (buf->isUntitled())
|
|
|
|
{
|
2010-08-15 15:27:46 +00:00
|
|
|
return fileSaveAs(bufferID);
|
2010-01-31 17:45:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const NppGUI & nppgui = (NppParameters::getInstance())->getNppGUI();
|
|
|
|
BackupFeature backup = nppgui._backup;
|
|
|
|
TCHAR *name = ::PathFindFileName(fn);
|
|
|
|
|
|
|
|
if (backup == bak_simple)
|
|
|
|
{
|
|
|
|
//copy fn to fn.backup
|
|
|
|
generic_string fn_bak(fn);
|
|
|
|
if ((nppgui._useDir) && (nppgui._backupDir != TEXT("")))
|
|
|
|
{
|
|
|
|
fn_bak = nppgui._backupDir;
|
|
|
|
fn_bak += TEXT("\\");
|
|
|
|
fn_bak += name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fn_bak = fn;
|
|
|
|
}
|
|
|
|
fn_bak += TEXT(".bak");
|
|
|
|
::CopyFile(fn, fn_bak.c_str(), FALSE);
|
|
|
|
}
|
|
|
|
else if (backup == bak_verbose)
|
|
|
|
{
|
|
|
|
generic_string fn_dateTime_bak(TEXT(""));
|
|
|
|
|
|
|
|
if ((nppgui._useDir) && (nppgui._backupDir != TEXT("")))
|
|
|
|
{
|
|
|
|
fn_dateTime_bak = nppgui._backupDir;
|
|
|
|
fn_dateTime_bak += TEXT("\\");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const TCHAR *bakDir = TEXT("nppBackup");
|
|
|
|
|
|
|
|
// std::string path should be a temp throwable variable
|
|
|
|
generic_string path = fn;
|
|
|
|
::PathRemoveFileSpec(path);
|
|
|
|
fn_dateTime_bak = path.c_str();
|
|
|
|
|
|
|
|
|
|
|
|
fn_dateTime_bak += TEXT("\\");
|
|
|
|
fn_dateTime_bak += bakDir;
|
|
|
|
fn_dateTime_bak += TEXT("\\");
|
|
|
|
|
|
|
|
if (!::PathFileExists(fn_dateTime_bak.c_str()))
|
|
|
|
{
|
|
|
|
::CreateDirectory(fn_dateTime_bak.c_str(), NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn_dateTime_bak += name;
|
|
|
|
|
|
|
|
const int temBufLen = 32;
|
|
|
|
TCHAR tmpbuf[temBufLen];
|
|
|
|
time_t ltime = time(0);
|
|
|
|
struct tm *today;
|
|
|
|
|
|
|
|
today = localtime(<ime);
|
|
|
|
generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today);
|
|
|
|
|
|
|
|
fn_dateTime_bak += TEXT(".");
|
|
|
|
fn_dateTime_bak += tmpbuf;
|
|
|
|
fn_dateTime_bak += TEXT(".bak");
|
|
|
|
|
|
|
|
::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE);
|
|
|
|
}
|
|
|
|
return doSave(bufferID, buf->getFullPathName(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::fileSaveAll() {
|
|
|
|
if (viewVisible(MAIN_VIEW)) {
|
2013-07-08 00:12:50 +00:00
|
|
|
for(int i = 0; i < _mainDocTab.nbItem(); ++i) {
|
2010-01-31 17:45:32 +00:00
|
|
|
BufferID idToSave = _mainDocTab.getBufferByIndex(i);
|
|
|
|
fileSave(idToSave);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewVisible(SUB_VIEW)) {
|
2013-07-08 00:12:50 +00:00
|
|
|
for(int i = 0; i < _subDocTab.nbItem(); ++i) {
|
2010-01-31 17:45:32 +00:00
|
|
|
BufferID idToSave = _subDocTab.getBufferByIndex(i);
|
|
|
|
fileSave(idToSave);
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 22:04:50 +00:00
|
|
|
checkDocState();
|
2010-01-31 17:45:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy)
|
|
|
|
{
|
|
|
|
BufferID bufferID = id;
|
|
|
|
if (id == BUFFER_INVALID)
|
|
|
|
bufferID = _pEditView->getCurrentBufferID();
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
|
2010-01-31 17:45:32 +00:00
|
|
|
|
|
|
|
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
|
|
|
int langTypeIndex = setFileOpenSaveDlgFilters(fDlg, buf->getLangType());
|
|
|
|
fDlg.setDefFileName(buf->getFileName());
|
|
|
|
|
|
|
|
fDlg.setExtIndex(langTypeIndex+1); // +1 for "All types"
|
2012-09-08 13:26:55 +00:00
|
|
|
|
|
|
|
// Disable file autodetection before opening save dialog to prevent use-after-delete bug.
|
|
|
|
NppParameters *pNppParam = NppParameters::getInstance();
|
|
|
|
ChangeDetect cdBefore = ((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetection;
|
|
|
|
((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetection = cdDisabled;
|
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
TCHAR *pfn = fDlg.doSaveDlg();
|
|
|
|
|
2012-09-08 13:26:55 +00:00
|
|
|
// Enable file autodetection again.
|
|
|
|
((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetection = cdBefore;
|
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
if (pfn)
|
|
|
|
{
|
|
|
|
BufferID other = _pNonDocTab->findBufferByName(pfn);
|
|
|
|
if (other == BUFFER_INVALID) //can save, other view doesnt contain buffer
|
|
|
|
{
|
|
|
|
bool res = doSave(bufferID, pfn, isSaveCopy);
|
|
|
|
//buf->setNeedsLexing(true); //commented to fix wrapping being removed after save as (due to SCI_CLEARSTYLE or something, seems to be Scintilla bug)
|
|
|
|
//Changing lexer after save seems to work properly
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else //cannot save, other view has buffer already open, activate it
|
|
|
|
{
|
2011-01-19 21:05:40 +00:00
|
|
|
_nativeLangSpeaker.messageBox("FileAlreadyOpenedInNpp",
|
|
|
|
_pPublicInterface->getHSelf(),
|
|
|
|
TEXT("The file is already opened in the Notepad++."),
|
|
|
|
TEXT("ERROR"),
|
|
|
|
MB_OK | MB_ICONSTOP);
|
2010-01-31 17:45:32 +00:00
|
|
|
switchToFile(other);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // cancel button is pressed
|
|
|
|
{
|
|
|
|
checkModifiedDocument();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notepad_plus::fileRename(BufferID id)
|
|
|
|
{
|
|
|
|
BufferID bufferID = id;
|
|
|
|
if (id == BUFFER_INVALID)
|
|
|
|
bufferID = _pEditView->getCurrentBufferID();
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
|
2010-01-31 17:45:32 +00:00
|
|
|
|
|
|
|
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
|
|
|
setFileOpenSaveDlgFilters(fDlg);
|
|
|
|
|
|
|
|
fDlg.setDefFileName(buf->getFileName());
|
|
|
|
TCHAR *pfn = fDlg.doSaveDlg();
|
|
|
|
|
|
|
|
if (pfn)
|
|
|
|
{
|
|
|
|
MainFileManager->moveFile(bufferID, pfn);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Notepad_plus::fileDelete(BufferID id)
|
|
|
|
{
|
|
|
|
BufferID bufferID = id;
|
|
|
|
if (id == BUFFER_INVALID)
|
|
|
|
bufferID = _pEditView->getCurrentBufferID();
|
|
|
|
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(bufferID);
|
|
|
|
const TCHAR *fileNamePath = buf->getFullPathName();
|
|
|
|
|
2013-01-05 20:05:02 +00:00
|
|
|
winVer winVersion = (NppParameters::getInstance())->getWinVersion();
|
|
|
|
bool goAhead = true;
|
|
|
|
if (winVersion >= WV_WIN8)
|
|
|
|
{
|
|
|
|
// Windows 8 (and version afer?) has no system alert, so we ask user's confirmation
|
|
|
|
goAhead = (doDeleteOrNot(fileNamePath) == IDYES);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (goAhead)
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
|
|
|
if (!MainFileManager->deleteFile(bufferID))
|
|
|
|
{
|
2011-01-19 21:05:40 +00:00
|
|
|
_nativeLangSpeaker.messageBox("DeleteFileFailed",
|
|
|
|
_pPublicInterface->getHSelf(),
|
|
|
|
TEXT("Delete File failed"),
|
|
|
|
TEXT("Delete File"),
|
|
|
|
MB_OK);
|
2010-01-31 17:45:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
doClose(bufferID, MAIN_VIEW);
|
|
|
|
doClose(bufferID, SUB_VIEW);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notepad_plus::fileOpen()
|
|
|
|
{
|
2010-03-26 00:22:14 +00:00
|
|
|
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
|
2010-01-31 17:45:32 +00:00
|
|
|
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
|
|
|
|
|
|
|
setFileOpenSaveDlgFilters(fDlg);
|
|
|
|
|
|
|
|
BufferID lastOpened = BUFFER_INVALID;
|
|
|
|
if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())
|
|
|
|
{
|
|
|
|
size_t sz = pfns->size();
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t i = 0 ; i < sz ; ++i) {
|
2010-01-31 17:45:32 +00:00
|
|
|
BufferID test = doOpen(pfns->at(i).c_str(), fDlg.isReadOnly());
|
|
|
|
if (test != BUFFER_INVALID)
|
|
|
|
lastOpened = test;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lastOpened != BUFFER_INVALID) {
|
|
|
|
switchToFile(lastOpened);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 11:15:06 +00:00
|
|
|
void Notepad_plus::fileNew()
|
|
|
|
{
|
|
|
|
BufferID newBufID = MainFileManager->newEmptyDocument();
|
2011-06-13 01:24:00 +00:00
|
|
|
|
2010-11-13 11:15:06 +00:00
|
|
|
loadBufferIntoView(newBufID, currentView(), true); //true, because we want multiple new files if possible
|
|
|
|
activateBuffer(newBufID, currentView());
|
|
|
|
}
|
2010-02-04 01:22:41 +00:00
|
|
|
|
|
|
|
bool Notepad_plus::isFileSession(const TCHAR * filename) {
|
|
|
|
// if file2open matches the ext of user defined session file ext, then it'll be opened as a session
|
|
|
|
const TCHAR *definedSessionExt = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str();
|
|
|
|
if (*definedSessionExt != '\0')
|
|
|
|
{
|
|
|
|
generic_string fncp = filename;
|
|
|
|
TCHAR *pExt = PathFindExtension(fncp.c_str());
|
|
|
|
|
|
|
|
generic_string usrSessionExt = TEXT("");
|
|
|
|
if (*definedSessionExt != '.')
|
|
|
|
{
|
|
|
|
usrSessionExt += TEXT(".");
|
|
|
|
}
|
|
|
|
usrSessionExt += definedSessionExt;
|
|
|
|
|
|
|
|
if (!generic_stricmp(pExt, usrSessionExt.c_str()))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return true if all the session files are loaded
|
|
|
|
// return false if one or more sessions files fail to load (and session is modify to remove invalid files)
|
|
|
|
bool Notepad_plus::loadSession(Session & session)
|
|
|
|
{
|
2010-11-21 01:44:40 +00:00
|
|
|
NppParameters *pNppParam = NppParameters::getInstance();
|
2010-02-04 01:22:41 +00:00
|
|
|
bool allSessionFilesLoaded = true;
|
|
|
|
BufferID lastOpened = BUFFER_INVALID;
|
|
|
|
size_t i = 0;
|
|
|
|
showView(MAIN_VIEW);
|
|
|
|
switchEditViewTo(MAIN_VIEW); //open files in main
|
2013-04-20 23:10:07 +00:00
|
|
|
|
|
|
|
int mainIndex2Update = -1;
|
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
for ( ; i < session.nbMainFiles() ; )
|
|
|
|
{
|
|
|
|
const TCHAR *pFn = session._mainViewFiles[i]._fileName.c_str();
|
2010-11-21 01:44:40 +00:00
|
|
|
if (isFileSession(pFn))
|
|
|
|
{
|
2010-02-04 01:22:41 +00:00
|
|
|
vector<sessionFileInfo>::iterator posIt = session._mainViewFiles.begin() + i;
|
|
|
|
session._mainViewFiles.erase(posIt);
|
|
|
|
continue; //skip session files, not supporting recursive sessions
|
|
|
|
}
|
2010-11-21 01:44:40 +00:00
|
|
|
|
|
|
|
bool isWow64Off = false;
|
|
|
|
if (!PathFileExists(pFn))
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
|
|
|
|
isWow64Off = true;
|
|
|
|
}
|
|
|
|
if (PathFileExists(pFn))
|
|
|
|
{
|
2014-03-05 21:18:05 +00:00
|
|
|
lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding);
|
2010-11-21 01:44:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-04 01:22:41 +00:00
|
|
|
lastOpened = BUFFER_INVALID;
|
|
|
|
}
|
2010-11-21 01:44:40 +00:00
|
|
|
if (isWow64Off)
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
|
|
|
|
isWow64Off = false;
|
|
|
|
}
|
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
if (lastOpened != BUFFER_INVALID)
|
|
|
|
{
|
|
|
|
showView(MAIN_VIEW);
|
|
|
|
const TCHAR *pLn = session._mainViewFiles[i]._langName.c_str();
|
|
|
|
int id = getLangFromMenuName(pLn);
|
|
|
|
LangType typeToSet = L_TEXT;
|
2011-10-07 22:02:18 +00:00
|
|
|
if (id != 0 && id != IDM_LANG_USER)
|
2010-02-04 01:22:41 +00:00
|
|
|
typeToSet = menuID2LangType(id);
|
|
|
|
if (typeToSet == L_EXTERNAL )
|
|
|
|
typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
|
|
|
|
|
2013-04-20 23:10:07 +00:00
|
|
|
Buffer *buf = MainFileManager->getBufferByID(lastOpened);
|
|
|
|
|
|
|
|
if (session._mainViewFiles[i]._foldStates.size() > 0)
|
|
|
|
{
|
|
|
|
if (buf == _mainEditView.getCurrentBuffer()) // current document
|
|
|
|
// Set floding state in the current doccument
|
|
|
|
mainIndex2Update = i;
|
|
|
|
else
|
|
|
|
// Set fold states in the buffer
|
|
|
|
buf->setHeaderLineState(session._mainViewFiles[i]._foldStates, &_mainEditView);
|
|
|
|
}
|
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
buf->setPosition(session._mainViewFiles[i], &_mainEditView);
|
|
|
|
buf->setLangType(typeToSet, pLn);
|
|
|
|
if (session._mainViewFiles[i]._encoding != -1)
|
|
|
|
buf->setEncoding(session._mainViewFiles[i]._encoding);
|
|
|
|
|
|
|
|
//Force in the document so we can add the markers
|
|
|
|
//Dont use default methods because of performance
|
2013-04-02 16:25:04 +00:00
|
|
|
Document prevDoc = _mainEditView.execute(SCI_GETDOCPOINTER);
|
|
|
|
_mainEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t j = 0, len = session._mainViewFiles[i].marks.size(); j < len ; ++j)
|
2010-02-04 01:22:41 +00:00
|
|
|
{
|
|
|
|
_mainEditView.execute(SCI_MARKERADD, session._mainViewFiles[i].marks[j], MARK_BOOKMARK);
|
|
|
|
}
|
2013-04-02 16:25:04 +00:00
|
|
|
_mainEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
2013-07-08 00:12:50 +00:00
|
|
|
++i;
|
2010-02-04 01:22:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vector<sessionFileInfo>::iterator posIt = session._mainViewFiles.begin() + i;
|
|
|
|
session._mainViewFiles.erase(posIt);
|
|
|
|
allSessionFilesLoaded = false;
|
|
|
|
}
|
|
|
|
}
|
2013-04-20 23:10:07 +00:00
|
|
|
if (mainIndex2Update != -1)
|
|
|
|
_mainEditView.syncFoldStateWith(session._mainViewFiles[mainIndex2Update]._foldStates);
|
2010-02-04 01:22:41 +00:00
|
|
|
|
|
|
|
size_t k = 0;
|
|
|
|
showView(SUB_VIEW);
|
|
|
|
switchEditViewTo(SUB_VIEW); //open files in sub
|
2013-04-20 23:10:07 +00:00
|
|
|
int subIndex2Update = -1;
|
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
for ( ; k < session.nbSubFiles() ; )
|
|
|
|
{
|
|
|
|
const TCHAR *pFn = session._subViewFiles[k]._fileName.c_str();
|
|
|
|
if (isFileSession(pFn)) {
|
|
|
|
vector<sessionFileInfo>::iterator posIt = session._subViewFiles.begin() + k;
|
|
|
|
session._subViewFiles.erase(posIt);
|
|
|
|
continue; //skip session files, not supporting recursive sessions
|
|
|
|
}
|
2010-11-21 01:44:40 +00:00
|
|
|
|
|
|
|
bool isWow64Off = false;
|
|
|
|
if (!PathFileExists(pFn))
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
|
|
|
|
isWow64Off = true;
|
|
|
|
}
|
|
|
|
if (PathFileExists(pFn))
|
|
|
|
{
|
2014-03-05 21:18:05 +00:00
|
|
|
lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding);
|
2013-04-20 23:10:07 +00:00
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
//check if already open in main. If so, clone
|
|
|
|
if (_mainDocTab.getIndexByBuffer(lastOpened) != -1) {
|
|
|
|
loadBufferIntoView(lastOpened, SUB_VIEW);
|
|
|
|
}
|
2010-11-21 01:44:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-04 01:22:41 +00:00
|
|
|
lastOpened = BUFFER_INVALID;
|
|
|
|
}
|
2010-11-21 01:44:40 +00:00
|
|
|
if (isWow64Off)
|
|
|
|
{
|
|
|
|
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
|
|
|
|
isWow64Off = false;
|
|
|
|
}
|
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
if (lastOpened != BUFFER_INVALID)
|
|
|
|
{
|
|
|
|
showView(SUB_VIEW);
|
|
|
|
if (canHideView(MAIN_VIEW))
|
|
|
|
hideView(MAIN_VIEW);
|
|
|
|
const TCHAR *pLn = session._subViewFiles[k]._langName.c_str();
|
|
|
|
int id = getLangFromMenuName(pLn);
|
|
|
|
LangType typeToSet = L_TEXT;
|
2013-04-02 16:25:04 +00:00
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
if (id != 0)
|
|
|
|
typeToSet = menuID2LangType(id);
|
|
|
|
if (typeToSet == L_EXTERNAL )
|
|
|
|
typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL);
|
|
|
|
|
|
|
|
Buffer * buf = MainFileManager->getBufferByID(lastOpened);
|
2013-04-20 23:10:07 +00:00
|
|
|
|
|
|
|
// Set fold states
|
|
|
|
if (session._subViewFiles[k]._foldStates.size() > 0)
|
|
|
|
{
|
|
|
|
if (buf == _subEditView.getCurrentBuffer()) // current document
|
|
|
|
// Set floding state in the current doccument
|
|
|
|
subIndex2Update = k;
|
|
|
|
else
|
|
|
|
// Set fold states in the buffer
|
|
|
|
buf->setHeaderLineState(session._subViewFiles[k]._foldStates, &_subEditView);
|
|
|
|
}
|
|
|
|
|
2010-02-04 01:22:41 +00:00
|
|
|
buf->setPosition(session._subViewFiles[k], &_subEditView);
|
|
|
|
if (typeToSet == L_USER) {
|
|
|
|
if (!lstrcmp(pLn, TEXT("User Defined"))) {
|
|
|
|
pLn = TEXT(""); //default user defined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf->setLangType(typeToSet, pLn);
|
|
|
|
buf->setEncoding(session._subViewFiles[k]._encoding);
|
|
|
|
|
|
|
|
//Force in the document so we can add the markers
|
|
|
|
//Dont use default methods because of performance
|
2013-04-02 16:25:04 +00:00
|
|
|
Document prevDoc = _subEditView.execute(SCI_GETDOCPOINTER);
|
|
|
|
_subEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t j = 0, len = session._subViewFiles[k].marks.size(); j < len ; ++j)
|
2010-02-04 01:22:41 +00:00
|
|
|
{
|
|
|
|
_subEditView.execute(SCI_MARKERADD, session._subViewFiles[k].marks[j], MARK_BOOKMARK);
|
|
|
|
}
|
2013-04-02 16:25:04 +00:00
|
|
|
_subEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc);
|
2010-02-04 01:22:41 +00:00
|
|
|
|
2013-07-08 00:12:50 +00:00
|
|
|
++k;
|
2010-02-04 01:22:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vector<sessionFileInfo>::iterator posIt = session._subViewFiles.begin() + k;
|
|
|
|
session._subViewFiles.erase(posIt);
|
|
|
|
allSessionFilesLoaded = false;
|
|
|
|
}
|
|
|
|
}
|
2013-04-20 23:10:07 +00:00
|
|
|
if (subIndex2Update != -1)
|
|
|
|
_subEditView.syncFoldStateWith(session._subViewFiles[subIndex2Update]._foldStates);
|
|
|
|
|
2013-04-02 16:25:04 +00:00
|
|
|
_mainEditView.restoreCurrentPos();
|
|
|
|
_subEditView.restoreCurrentPos();
|
2010-02-04 01:22:41 +00:00
|
|
|
|
|
|
|
if (session._activeMainIndex < (size_t)_mainDocTab.nbItem())//session.nbMainFiles())
|
|
|
|
activateBuffer(_mainDocTab.getBufferByIndex(session._activeMainIndex), MAIN_VIEW);
|
|
|
|
|
|
|
|
if (session._activeSubIndex < (size_t)_subDocTab.nbItem())//session.nbSubFiles())
|
|
|
|
activateBuffer(_subDocTab.getBufferByIndex(session._activeSubIndex), SUB_VIEW);
|
|
|
|
|
|
|
|
if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW))
|
|
|
|
switchEditViewTo(session._activeView);
|
|
|
|
else
|
|
|
|
switchEditViewTo(MAIN_VIEW);
|
|
|
|
|
|
|
|
if (canHideView(otherView()))
|
|
|
|
hideView(otherView());
|
|
|
|
else if (canHideView(currentView()))
|
|
|
|
hideView(currentView());
|
|
|
|
return allSessionFilesLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-31 17:45:32 +00:00
|
|
|
bool Notepad_plus::fileLoadSession(const TCHAR *fn)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
const TCHAR *sessionFileName = NULL;
|
|
|
|
if (fn == NULL)
|
|
|
|
{
|
2010-03-26 00:22:14 +00:00
|
|
|
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
|
2010-01-31 17:45:32 +00:00
|
|
|
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
|
|
|
const TCHAR *ext = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str();
|
|
|
|
generic_string sessionExt = TEXT("");
|
|
|
|
if (*ext != '\0')
|
|
|
|
{
|
|
|
|
if (*ext != '.')
|
|
|
|
sessionExt += TEXT(".");
|
|
|
|
sessionExt += ext;
|
|
|
|
fDlg.setExtFilter(TEXT("Session file"), sessionExt.c_str(), NULL);
|
|
|
|
}
|
|
|
|
sessionFileName = fDlg.doOpenSingleFileDlg();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PathFileExists(fn))
|
|
|
|
sessionFileName = fn;
|
|
|
|
}
|
|
|
|
|
2013-07-27 17:30:55 +00:00
|
|
|
|
2013-07-17 22:35:34 +00:00
|
|
|
NppParameters *pNppParam = NppParameters::getInstance();
|
|
|
|
const NppGUI & nppGUI = pNppParam->getNppGUI();
|
2010-01-31 17:45:32 +00:00
|
|
|
if (sessionFileName)
|
|
|
|
{
|
2013-07-27 17:30:55 +00:00
|
|
|
bool isEmptyNpp = false;
|
|
|
|
if (_mainDocTab.nbItem() == 1 && _subDocTab.nbItem() == 1)
|
|
|
|
{
|
|
|
|
Buffer * buf1 = MainFileManager->getBufferByID(_mainDocTab.getBufferByIndex(0));
|
|
|
|
Buffer * buf2 = MainFileManager->getBufferByID(_subDocTab.getBufferByIndex(0));
|
|
|
|
isEmptyNpp = (!buf1->isDirty() && buf1->isUntitled() && !buf2->isDirty() && buf2->isUntitled());
|
|
|
|
}
|
|
|
|
if (!isEmptyNpp && (nppGUI._multiInstSetting == multiInstOnSession || nppGUI._multiInstSetting == multiInst))
|
2013-07-17 22:35:34 +00:00
|
|
|
{
|
|
|
|
TCHAR nppFullPath[MAX_PATH];
|
|
|
|
::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
|
2013-07-27 17:30:55 +00:00
|
|
|
|
|
|
|
|
2013-07-17 22:35:34 +00:00
|
|
|
generic_string args = TEXT("-multiInst -nosession -openSession ");
|
2013-07-27 17:30:55 +00:00
|
|
|
args += TEXT("\"");
|
2013-07-17 22:35:34 +00:00
|
|
|
args += sessionFileName;
|
2013-07-27 17:30:55 +00:00
|
|
|
args += TEXT("\"");
|
2013-07-17 22:35:34 +00:00
|
|
|
::ShellExecute(_pPublicInterface->getHSelf(), TEXT("open"), nppFullPath, args.c_str(), TEXT("."), SW_SHOW);
|
|
|
|
}
|
|
|
|
else
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
2013-07-17 22:35:34 +00:00
|
|
|
bool isAllSuccessful = true;
|
|
|
|
Session session2Load;
|
|
|
|
|
|
|
|
if ((NppParameters::getInstance())->loadSession(session2Load, sessionFileName))
|
|
|
|
{
|
|
|
|
isAllSuccessful = loadSession(session2Load);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
if (!isAllSuccessful)
|
|
|
|
(NppParameters::getInstance())->writeSession(session2Load, sessionFileName);
|
2010-01-31 17:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save)
|
|
|
|
{
|
|
|
|
if (sessionFile2save)
|
|
|
|
{
|
|
|
|
Session currentSession;
|
2010-08-15 15:27:46 +00:00
|
|
|
if ((nbFile) && (fileNames))
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t i = 0 ; i < nbFile ; ++i)
|
2010-01-31 17:45:32 +00:00
|
|
|
{
|
|
|
|
if (PathFileExists(fileNames[i]))
|
|
|
|
currentSession._mainViewFiles.push_back(generic_string(fileNames[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
getCurrentOpenedFiles(currentSession);
|
|
|
|
|
|
|
|
(NppParameters::getInstance())->writeSession(currentSession, sessionFile2save);
|
|
|
|
return sessionFile2save;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames)
|
|
|
|
{
|
|
|
|
const TCHAR *sessionFileName = NULL;
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
|
2010-01-31 17:45:32 +00:00
|
|
|
const TCHAR *ext = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str();
|
|
|
|
|
|
|
|
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
|
|
|
generic_string sessionExt = TEXT("");
|
|
|
|
if (*ext != '\0')
|
|
|
|
{
|
|
|
|
if (*ext != '.')
|
|
|
|
sessionExt += TEXT(".");
|
|
|
|
sessionExt += ext;
|
|
|
|
fDlg.setExtFilter(TEXT("Session file"), sessionExt.c_str(), NULL);
|
|
|
|
}
|
|
|
|
sessionFileName = fDlg.doSaveDlg();
|
|
|
|
|
|
|
|
return fileSaveSession(nbFile, fileNames, sessionFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-10 23:54:44 +00:00
|
|
|
void Notepad_plus::saveSession(const Session & session)
|
|
|
|
{
|
|
|
|
(NppParameters::getInstance())->writeSession(session);
|
|
|
|
}
|