📄 notepad_plus.cpp.internaldockingdlg.svn-base
字号:
}
else
{
char msg[MAX_PATH + 100];
strcpy(msg, "Can not open file \"");
//strcat(msg, fullPath);
strcat(msg, longFileName);
strcat(msg, "\".");
::MessageBox(_hSelf, msg, "ERR", MB_OK);
_lastRecentFileList.remove(longFileName);
return false;
}
}
void Notepad_plus::fileOpen()
{
FileDialog fDlg(_hSelf, _hInst);
fDlg.setExtFilter("All types", ".*", NULL);
fDlg.setExtFilter("c/c++ src file", ".c", ".cpp", ".cxx", ".cc", ".h", NULL);
fDlg.setExtFilter("Window Resource File", ".rc", NULL);
fDlg.setExtFilter("Java src file", ".java", NULL);
fDlg.setExtFilter("HTML file", ".html", ".htm", NULL);
fDlg.setExtFilter("XML file", ".xml", NULL);
fDlg.setExtFilter("Makefile", "makefile", "GNUmakefile", ".makefile", NULL);
fDlg.setExtFilter("php file", ".php", ".php3", ".phtml", NULL);
fDlg.setExtFilter("asp file", ".asp", NULL);
fDlg.setExtFilter("ini file", ".ini", NULL);
fDlg.setExtFilter("nfo file", ".nfo", NULL);
fDlg.setExtFilter("VB/VBS file", ".vb", ".vbs", NULL);
fDlg.setExtFilter("SQL file", ".sql", NULL);
fDlg.setExtFilter("Objective C file", ".m", ".h", NULL);
if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())
{
int sz = int(pfns->size());
for (int i = 0 ; i < sz ; i++)
doOpen((pfns->at(i)).c_str(), fDlg.isReadOnly());
setLangStatus(_pEditView->getCurrentDocType());
}
}
bool Notepad_plus::doSave(const char *filename, UniMode mode)
{
bool isHidden = false;
bool isSys = false;
DWORD attrib;
if (PathFileExists(filename))
{
attrib = ::GetFileAttributes(filename);
if (attrib != INVALID_FILE_ATTRIBUTES)
{
isHidden = (attrib & FILE_ATTRIBUTE_HIDDEN) != 0;
if (isHidden)
::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_HIDDEN);
isSys = (attrib & FILE_ATTRIBUTE_SYSTEM) != 0;
if (isSys)
::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_SYSTEM);
}
}
if (mode == uniCookie)
mode = uni8Bit;
Utf8_16_Write UnicodeConvertor;
if (_pEditView->execute(SCI_GETCODEPAGE) != 0)
UnicodeConvertor.setEncoding(static_cast<UniMode>(mode));
FILE *fp = UnicodeConvertor.fopen(filename, "wb");
if (fp)
{
char data[blockSize + 1];
int lengthDoc = _pEditView->getCurrentDocLen();
for (int i = 0; i < lengthDoc; i += blockSize)
{
int grabSize = lengthDoc - i;
if (grabSize > blockSize)
grabSize = blockSize;
_pEditView->getText(data, i, i + grabSize);
UnicodeConvertor.fwrite(data, grabSize);
}
UnicodeConvertor.fclose();
_pEditView->updateCurrentBufTimeStamp();
_pEditView->execute(SCI_SETSAVEPOINT);
if (isHidden)
::SetFileAttributes(filename, attrib | FILE_ATTRIBUTE_HIDDEN);
if (isSys)
::SetFileAttributes(filename, attrib | FILE_ATTRIBUTE_SYSTEM);
return true;
}
return false;
}
bool Notepad_plus::fileSave()
{
if (_pEditView->isCurrentDocDirty())
{
const char *fn = _pEditView->getCurrentTitle();
if (Buffer::isUntitled(fn))
{
return fileSaveAs();
}
else
{
BackupFeature backup = ((NppParameters::getInstance())->getNppGUI())._backup;
if (backup == bak_simple)
{
//copy fn to fn.backup
string fn_bak(fn);
fn_bak += ".bak";
::CopyFile(fn, fn_bak.c_str(), FALSE);
}
else if (backup == bak_verbose)
{
//copy fn to fn.backup.dateTime
string fn_dateTime_bak(fn);
const int temBufLen = 32;
char tmpbuf[temBufLen];
time_t ltime = time(0);
struct tm *today;
today = localtime(<ime);
strftime(tmpbuf, temBufLen, "%Y-%m-%d_%H%M%S", today);
fn_dateTime_bak += ".";
fn_dateTime_bak += tmpbuf;
fn_dateTime_bak += ".bak";
::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE);
}
return doSave(fn, _pEditView->getCurrentBuffer().getUnicodeMode());
}
//return (Buffer::isUntitled(fn))?fileSaveAs():doSave(fn, _pEditView->getCurrentBuffer().getUnicodeMode());
}
return false;
}
bool Notepad_plus::fileSaveAll() {
int iCurrent = _pEditView->getCurrentDocIndex();
if (_mainWindowStatus & TWO_VIEWS_MASK)
{
switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW);
int iCur = _pEditView->getCurrentDocIndex();
for (size_t i = 0 ; i < _pEditView->getNbDoc() ; i++)
{
_pDocTab->activate(i);
if (!_pEditView->getCurrentBuffer().isReadOnly())
fileSave();
}
_pDocTab->activate(iCur);
switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW);
}
for (size_t i = 0 ; i < _pEditView->getNbDoc() ; i++)
{
_pDocTab->activate(i);
if (!_pEditView->getCurrentBuffer().isReadOnly())
fileSave();
}
_pDocTab->activate(iCurrent);
return true;
}
bool Notepad_plus::replaceAllFiles() {
int iCurrent = _pEditView->getCurrentDocIndex();
int nbTotal = 0;
const bool isEntireDoc = true;
if (_mainWindowStatus & TWO_VIEWS_MASK)
{
switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW);
int iCur = _pEditView->getCurrentDocIndex();
for (size_t i = 0 ; i < _pEditView->getNbDoc() ; i++)
{
_pDocTab->activate(i);
if (!_pEditView->getCurrentBuffer().isReadOnly())
{
_pEditView->execute(SCI_BEGINUNDOACTION);
nbTotal += _findReplaceDlg.processAll(REPLACE_ALL, isEntireDoc);
_pEditView->execute(SCI_ENDUNDOACTION);
}
}
_pDocTab->activate(iCur);
switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW);
}
for (size_t i = 0 ; i < _pEditView->getNbDoc() ; i++)
{
_pDocTab->activate(i);
if (!_pEditView->getCurrentBuffer().isReadOnly())
{
_pEditView->execute(SCI_BEGINUNDOACTION);
nbTotal += _findReplaceDlg.processAll(REPLACE_ALL, isEntireDoc);
_pEditView->execute(SCI_ENDUNDOACTION);
}
}
_pDocTab->activate(iCurrent);
char result[64];
if (nbTotal < 0)
strcpy(result, "The regular expression to search is formed badly");
else
{
itoa(nbTotal, result, 10);
strcat(result, " tokens are replaced.");
}
::MessageBox(_hSelf, result, "", MB_OK);
return true;
}
bool Notepad_plus::matchInList(const char *fileName, const vector<string> & patterns)
{
for (size_t i = 0 ; i < patterns.size() ; i++)
{
if (PathMatchSpec(fileName, patterns[i].c_str()))
return true;
}
return false;
}
void Notepad_plus::getMatchedFileNames(const char *dir, const vector<string> & patterns, vector<string> & fileNames)
{
string dirFilter(dir);
dirFilter += "*.*";
WIN32_FIND_DATA foundData;
HANDLE hFile = ::FindFirstFile(dirFilter.c_str(), &foundData);
if (hFile != INVALID_HANDLE_VALUE)
{
if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((strcmp(foundData.cFileName, ".")) && (strcmp(foundData.cFileName, "..")))
{
string pathDir(dir);
pathDir += foundData.cFileName;
pathDir += "\\";
getMatchedFileNames(pathDir.c_str(), patterns, fileNames);
}
}
else
{
if (matchInList(foundData.cFileName, patterns))
{
string pathFile(dir);
pathFile += foundData.cFileName;
fileNames.push_back(pathFile.c_str());
}
}
}
while (::FindNextFile(hFile, &foundData))
{
if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((strcmp(foundData.cFileName, ".")) && (strcmp(foundData.cFileName, "..")))
{
string pathDir(dir);
pathDir += foundData.cFileName;
pathDir += "\\";
getMatchedFileNames(pathDir.c_str(), patterns, fileNames);
}
}
else
{
if (matchInList(foundData.cFileName, patterns))
{
string pathFile(dir);
pathFile += foundData.cFileName;
fileNames.push_back(pathFile.c_str());
}
}
}
::FindClose(hFile);
}
bool Notepad_plus::findInFiles()
{
int nbTotal = 0;
ScintillaEditView *pOldView = _pEditView;
_pEditView = &_invisibleEditView;
_findReplaceDlg.setFinderReadOnly(false);
if (!_findReplaceDlg.isFinderEmpty())
_findReplaceDlg.clearFinder();
const char *dir2Search = _findReplaceDlg.getDir2Search();
vector<string> patterns2Match;
_findReplaceDlg.getPatterns(patterns2Match);
vector<string> fileNames;
getMatchedFileNames(dir2Search, patterns2Match, fileNames);
for (size_t i = 0 ; i < fileNames.size() ; i++)
{
doSimpleOpen(fileNames[i].c_str());
nbTotal += _findReplaceDlg.processAll(FIND_ALL, true, _findReplaceDlg.getDir2Search());
}
_findReplaceDlg.setFinderReadOnly();
_findReplaceDlg.putFindResult(nbTotal);
_pEditView = pOldView;
return true;
}
bool Notepad_plus::findInOpenedFiles() {
int iCurrent = _pEditView->getCurrentDocIndex();
int nbTotal = 0;
const bool isEntireDoc = true;
_findReplaceDlg.setFinderReadOnly(false);
//_findReplaceDlg.setFinderStyle();
//_pFinder->defineDocType(L_TXT);
//_pFinder->execute(SCI_STYLESETSIZE, STYLE_DEFAULT, 8);
if (!_findReplaceDlg.isFinderEmpty())
_findReplaceDlg.clearFinder();
if (_mainWindowStatus & TWO_VIEWS_MASK)
{
switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW);
int iCur = _pEditView->getCurrentDocIndex();
for (size_t i = 0 ; i < _pEditView->getNbDoc() ; i++)
{
_pDocTab->activate(i);
_pEditView->execute(SCI_BEGINUNDOACTION);
nbTotal += _findReplaceDlg.processAll(FIND_ALL, isEntireDoc);
_pEditView->execute(SCI_ENDUNDOACTION);
}
_pDocTab->activate(iCur);
switchEditViewTo((getCurrentView() == MAIN_VIEW)?SUB_VIEW:MAIN_VIEW);
}
for (size_t i = 0 ; i < _pEditView->getNbDoc() ; i++)
{
_pDocTab->activate(i);
_pEditView->execute(SCI_BEGINUNDOACTION);
nbTotal += _findReplaceDlg.processAll(FIND_ALL, isEntireDoc);
_pEditView->execute(SCI_ENDUNDOACTION);
}
_pDocTab->activate(iCurrent);
_findReplaceDlg.setFinderReadOnly();
_findReplaceDlg.putFindResult(nbTotal);
return true;
}
bool Notepad_plus::fileSaveAs()
{
FileDialog fDlg(_hSelf, _hInst);
fDlg.setExtFilter("All types", ".*", NULL);
fDlg.setExtFilter("c src file", ".c", NULL);
fDlg.setExtFilter("c++ src file", ".cpp", NULL);
fDlg.setExtFilter("Window Resource File", ".rc", NULL);
fDlg.setExtFilter("c/c++ header file", ".h", NULL);
fDlg.setExtFilter("Java src file", ".java", NULL);
fDlg.setExtFilter("HTML file", ".html", NULL);
fDlg.setExtFilter("XML file", ".xml", NULL);
fDlg.setExtFilter("php file", ".php",NULL);
fDlg.setExtFilter("ini file", ".ini", NULL);
fDlg.setExtFilter("bat file", ".bat", NULL);
fDlg.setExtFilter("Normal text file", ".txt", NULL);
char str[MAX_PATH];
strcpy(str, _pEditView->getCurrentTitle());
fDlg.setDefFileName(PathFindFileName(str));
if (char *pfn = fDlg.doSaveDlg())
{
int i = _pEditView->findDocIndexByName(pfn);
if ((i == -1) || (i == _pEditView->getCurrentDocIndex()))
{
doSave(pfn, _pEditView->getCurrentBuffer().getUnicodeMode());
_pEditView->setCurrentTitle(pfn);
_pEditView->setCurrentDocReadOnly(false);
_pDocTab->updateCurrentTabItem(PathFindFileName(pfn));
setTitleWith(pfn);
setLangStatus(_pEditView->getCurrentDocType());
checkLangsMenu(-1);
return true;
}
else
{
::MessageBox(_hSelf, "The file is already opened in the Notepad++.", "ERROR", MB_OK | MB_ICONSTOP);
_pDocTab->activate(i);
return false;
}
checkModifiedDocument();
}
else // cancel button is pressed
{
checkModifiedDocument();
return false;
}
}
void Notepad_plus::filePrint(bool showDialog)
{
Printer printer;
int startPos = int(_pEditView->execute(SCI_GETSELECTIONSTART));
int endPos = int(_pEditView->execute(SCI_GETSELECTIONEND));
printer.init(_hInst, _hSelf, _pEditView, showDialog, startPos, endPos);
printer.doPrint();
}
void Notepad_plus::enableCommand(int cmdID, bool doEnable, int which) const
{
if (which & MENU)
{
enableMenu(cmdID, doEnable);
}
if (which & TOOLBAR)
{
_toolBar.enable(cmdID, doEnable);
}
}
void Notepad_plus::checkClipboard()
{
bool hasSelection = _pEditView->execute(SCI_GETSELECTIONSTART) != _pEditView->execute(SCI_GETSELECTIONEND);
bool canPaste = (_pEditView->execute(SCI_CANPASTE) != 0);
enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR);
enableCommand(IDM_EDIT_COPY, hasSelection, MENU | TOOLBAR);
enableCommand(IDM_EDIT_PASTE, canPaste, MENU | TOOLBAR);
enableCommand(IDM_EDIT_DELETE, hasSelection, MENU | TOOLBAR);
enableCommand(IDM_EDIT_UPPERCASE, hasSelection, MENU);
enableCommand(IDM_EDIT_LOWERCASE, hasSelection, MENU);
enableCommand(IDM_EDIT_BLOCK_COMMENT, hasSelection, MENU);
enableCommand(IDM_EDIT_STREAM_COMMENT, hasSelection, MENU);
}
void Notepad_plus::checkDocState()
{
bool isCurrentDirty = _pEditView->isCurrentDocDirty();
bool isSeveralDirty = (!_pEditView->isAllDocsClean()) || (!getNonCurrentEditView()->isAllDocsClean());
enableCommand(IDM_FILE_SAVE, isCurrentDirty, MENU | TOOLBAR);
enableCommand(IDM_FILE_SAVEALL, isSeveralDirty, MENU | TOOLBAR);
bool isSysReadOnly = _pEditView->isCurrentBufSysReadOnly();
if (isSysReadOnly)
{
HMENU hMenu = ::GetMenu(_hSelf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -