📄 notepad_plus.cpp.internaldockingdlg.svn-base
字号:
if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf())
{
strcpy(fullPath, _mainDocTab.clickedUpdate());
switchEditViewTo(MAIN_VIEW);
}
else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf())
{
strcpy(fullPath, _subDocTab.clickedUpdate());
switchEditViewTo(SUB_VIEW);
}
PathRemoveFileSpec(fullPath);
setWorkingDir(fullPath);
break;
}
case NM_CLICK :
{
if (notification->nmhdr.hwndFrom == _statusBar.getHSelf())
{
LPNMMOUSE lpnm = (LPNMMOUSE)notification;
if (lpnm->dwItemSpec == DWORD(STATUSBAR_TYPING_MODE))
{
bool isOverTypeMode = (_pEditView->execute(SCI_GETOVERTYPE) != 0);
_pEditView->execute(SCI_SETOVERTYPE, !isOverTypeMode);
_statusBar.setText((_pEditView->execute(SCI_GETOVERTYPE))?"OVR":"INS", STATUSBAR_TYPING_MODE);
}
}
break;
}
case NM_DBLCLK :
{
if (notification->nmhdr.hwndFrom == _statusBar.getHSelf())
{
LPNMMOUSE lpnm = (LPNMMOUSE)notification;
if (lpnm->dwItemSpec == DWORD(STATUSBAR_CUR_POS))
{
bool isFirstTime = !_goToLineDlg.isCreated();
if (isFirstTime)
{
tTbData data = {0};
_goToLineDlg.create(&data, _isRTL);
_dockingManager.createDockableDlg(data);
changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
}
else
{
_goToLineDlg.display();
}
}
}
break;
}
case NM_RCLICK :
{
if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf())
{
switchEditViewTo(MAIN_VIEW);
}
else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf())
{
switchEditViewTo(SUB_VIEW);
}
else // From tool bar or Status Bar
return TRUE;
//break;
POINT p, clientPoint;
::GetCursorPos(&p);
clientPoint.x = p.x;
clientPoint.y = p.y;
if (!_tabPopupMenu.isCreated())
{
char close[32] = "Close me";
char closeBut[32] = "Close all but me";
char save[32] = "Save me";
char saveAs[32] = "Save me As...";
char print[32] = "Print me";
char readOnly[32] = "Read only";
char clearReadOnly[32] = "Clear read only flag";
char goToView[32] = "Go to another View";
char cloneToView[32] = "Clone to another View";
char cilpFullPath[32] = "Full file path to Clipboard";
char cilpFileName[32] = "File name to Clipboard";
char cilpCurrentDir[32] = "Current dir path to Clipboard";
const char *pClose = close;
const char *pCloseBut = closeBut;
const char *pSave = save;
const char *pSaveAs = saveAs;
const char *pPrint = print;
const char *pReadOnly = readOnly;
const char *pClearReadOnly = clearReadOnly;
const char *pGoToView = goToView;
const char *pCloneToView = cloneToView;
const char *pCilpFullPath = cilpFullPath;
const char *pCilpFileName = cilpFileName;
const char *pCilpCurrentDir = cilpCurrentDir;
if (_nativeLang)
{
TiXmlNode *tabBarMenu = _nativeLang->FirstChild("Menu");
if (tabBarMenu)
{
tabBarMenu = tabBarMenu->FirstChild("TabBar");
if (tabBarMenu)
{
for (TiXmlNode *childNode = tabBarMenu->FirstChildElement("Item");
childNode ;
childNode = childNode->NextSibling("Item") )
{
TiXmlElement *element = childNode->ToElement();
int ordre;
element->Attribute("order", &ordre);
switch (ordre)
{
case 0 :
pClose = element->Attribute("name"); break;
case 1 :
pCloseBut = element->Attribute("name"); break;
case 2 :
pSave = element->Attribute("name"); break;
case 3 :
pSaveAs = element->Attribute("name"); break;
case 4 :
pPrint = element->Attribute("name"); break;
case 5 :
pGoToView = element->Attribute("name"); break;
case 6 :
pCloneToView = element->Attribute("name"); break;
}
}
}
}
if (!pClose || !pClose[0])
pClose = close;
if (!pCloseBut || !pCloseBut[0])
pCloseBut = cloneToView;
if (!pSave || !pSave[0])
pSave = save;
if (!pSaveAs || !pSaveAs[0])
pSaveAs = saveAs;
if (!pPrint || !pPrint[0])
pPrint = print;
if (!pGoToView || !pGoToView[0])
pGoToView = goToView;
if (!pCloneToView || !pCloneToView[0])
pCloneToView = cloneToView;
}
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_PRINT, pPrint));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_SETREADONLY, pReadOnly));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CLEARREADONLY, pClearReadOnly));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FULLPATHTOCLIP, pCilpFullPath));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FILENAMETOCLIP, pCilpFileName));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CURRENTDIRTOCLIP, pCilpCurrentDir));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDC_DOC_GOTO_ANOTHER_VIEW, pGoToView));
itemUnitArray.push_back(MenuItemUnit(IDC_DOC_CLONE_TO_ANOTHER_VIEW, pCloneToView));
_tabPopupMenu.create(_hSelf, itemUnitArray);
}
::ScreenToClient(_pDocTab->getHSelf(), &clientPoint);
::SendMessage(_pDocTab->getHSelf(), WM_LBUTTONDOWN, 2, MAKELONG(clientPoint.x, clientPoint.y));
bool isEnable = ((::GetMenuState(::GetMenu(_hSelf), IDM_FILE_SAVE, MF_BYCOMMAND)&MF_DISABLED) == 0);
_tabPopupMenu.enableItem(IDM_FILE_SAVE, isEnable);
bool isUserReadOnly = _pEditView->isCurrentBufUserReadOnly();
_tabPopupMenu.checkItem(IDM_EDIT_SETREADONLY, isUserReadOnly);
bool isSysReadOnly = _pEditView->isCurrentBufSysReadOnly();
_tabPopupMenu.enableItem(IDM_EDIT_SETREADONLY, !isSysReadOnly);
_tabPopupMenu.enableItem(IDM_EDIT_CLEARREADONLY, isSysReadOnly);
_tabPopupMenu.display(p);
return TRUE;
}
case SCN_MARGINCLICK:
{
if (notification->nmhdr.hwndFrom == _mainEditView.getHSelf())
switchEditViewTo(MAIN_VIEW);
else if (notification->nmhdr.hwndFrom == _subEditView.getHSelf())
switchEditViewTo(SUB_VIEW);
if (notification->margin == ScintillaEditView::_SC_MARGE_FOLDER)
{
_pEditView->marginClick(notification->position, notification->modifiers);
}
else if (notification->margin == ScintillaEditView::_SC_MARGE_SYBOLE)
{
int lineClick = int(_pEditView->execute(SCI_LINEFROMPOSITION, notification->position));
bookmarkToggle(lineClick);
}
break;
}
case SCN_CHARADDED:
charAdded(static_cast<char>(notification->ch));
break;
case SCN_UPDATEUI:
braceMatch();
updateStatusBar();
break;
case TTN_GETDISPINFO:
{
LPTOOLTIPTEXT lpttt;
lpttt = (LPTOOLTIPTEXT)notification;
lpttt->hinst = _hInst;
// Specify the resource identifier of the descriptive
// text for the given button.
int idButton = int(lpttt->hdr.idFrom);
static string tip;
getNameStrFromCmd(idButton, tip);
lpttt->lpszText = (LPSTR)tip.c_str();
}
break;
case SCN_ZOOM:
_pEditView->setLineNumberWidth(_pEditView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER));
break;
case SCN_MACRORECORD:
_macro.push_back(recordedMacroStep(notification->message, notification->wParam, notification->lParam));
break;
case SCN_PAINTED:
if (_syncInfo.doSync())
doSynScorll(HWND(notification->nmhdr.hwndFrom));
break;
default :
break;
}
return FALSE;
}
void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite)
{
int caretPos = int(_pEditView->execute(SCI_GETCURRENTPOS, 0, 0));
braceAtCaret = -1;
braceOpposite = -1;
char charBefore = '\0';
//char styleBefore = '\0';
int lengthDoc = int(_pEditView->execute(SCI_GETLENGTH, 0, 0));
if ((lengthDoc > 0) && (caretPos > 0))
{
charBefore = char(_pEditView->execute(SCI_GETCHARAT, caretPos - 1, 0));
}
// Priority goes to character before caret
if (charBefore && strchr("[](){}", charBefore))
{
braceAtCaret = caretPos - 1;
}
if (lengthDoc > 0 && (braceAtCaret < 0))
{
// No brace found so check other side
char charAfter = char(_pEditView->execute(SCI_GETCHARAT, caretPos, 0));
if (charAfter && strchr("[](){}", charAfter))
{
braceAtCaret = caretPos;
}
}
if (braceAtCaret >= 0)
braceOpposite = int(_pEditView->execute(SCI_BRACEMATCH, braceAtCaret, 0));
}
void Notepad_plus::braceMatch()
{
int braceAtCaret = -1;
int braceOpposite = -1;
findMatchingBracePos(braceAtCaret, braceOpposite);
if ((braceAtCaret != -1) && (braceOpposite == -1))
{
_pEditView->execute(SCI_BRACEBADLIGHT, braceAtCaret);
_pEditView->execute(SCI_SETHIGHLIGHTGUIDE);
}
else
{
_pEditView->execute(SCI_BRACEHIGHLIGHT, braceAtCaret, braceOpposite);
if (_pEditView->isShownIndentGuide())
{
int columnAtCaret = int(_pEditView->execute(SCI_GETCOLUMN, braceAtCaret));
int columnOpposite = int(_pEditView->execute(SCI_GETCOLUMN, braceOpposite));
_pEditView->execute(SCI_SETHIGHLIGHTGUIDE, (columnAtCaret < columnOpposite)?columnAtCaret:columnOpposite);
}
}
enableCommand(IDM_SEARCH_GOTOMATCHINGBRACE, (braceAtCaret != -1) && (braceOpposite != -1), MENU | TOOLBAR);
}
void Notepad_plus::charAdded(char chAdded)
{
bool indentMaintain = NppParameters::getInstance()->getNppGUI()._maitainIndent;
if (indentMaintain)
MaintainIndentation(chAdded);
hotSpot(chAdded);
}
void Notepad_plus::hotSpot(char chAdded)
{
}
void Notepad_plus::MaintainIndentation(char ch)
{
int eolMode = int(_pEditView->execute(SCI_GETEOLMODE));
int curLine = int(_pEditView->getCurrentLineNumber());
int lastLine = curLine - 1;
int indentAmount = 0;
if (((eolMode == SC_EOL_CRLF || eolMode == SC_EOL_LF) && ch == '\n') ||
(eolMode == SC_EOL_CR && ch == '\r'))
{
while (lastLine >= 0 && _pEditView->getLineLength(lastLine) == 0)
lastLine--;
if (lastLine >= 0) {
indentAmount = _pEditView->getLineIndent(lastLine);
}
if (indentAmount > 0) {
_pEditView->setLineIndent(curLine, indentAmount);
}
}
}
void Notepad_plus::specialCmd(int id, int param)
{
if ((param != 1) && (param != 2)) return;
NppParameters *pNppParam = NppParameters::getInstance();
ScintillaEditView *pEditView = (param == 1)?&_mainEditView:&_subEditView;
switch (id)
{
case IDM_VIEW_LINENUMBER:
case IDM_VIEW_SYMBOLMARGIN:
case IDM_VIEW_FOLDERMAGIN:
{
int margin;
if (id == IDM_VIEW_LINENUMBER)
margin = ScintillaEditView::_SC_MARGE_LINENUMBER;
else if (id == IDM_VIEW_SYMBOLMARGIN)
margin = ScintillaEditView::_SC_MARGE_SYBOLE;
else
margin = ScintillaEditView::_SC_MARGE_FOLDER;
if (pEditView->hasMarginShowed(margin))
pEditView->showMargin(margin, false);
else
pEditView->showMargin(margin);
break;
}
case IDM_VIEW_FOLDERMAGIN_SIMPLE:
case IDM_VIEW_FOLDERMAGIN_ARROW:
case IDM_VIEW_FOLDERMAGIN_CIRCLE:
case IDM_VIEW_FOLDERMAGIN_BOX:
{
int checkedID = getFolderMarginStyle();
if (checkedID == id) return;
folderStyle fStyle = (id == IDM_VIEW_FOLDERMAGIN_SIMPLE)?FOLDER_STYLE_SIMPLE:\
((id == IDM_VIEW_FOLDERMAGIN_ARROW)?FOLDER_STYLE_ARROW:\
((id == IDM_VIEW_FOLDERMAGIN_CIRCLE)?FOLDER_STYLE_CIRCLE:FOLDER_STYLE_BOX));
pEditView->setMakerStyle(fStyle);
break;
}
case IDM_VIEW_CURLINE_HILITING:
{
COLORREF colour = pNppParam->getCurLineHilitingColour();
pEditView->setCurrentLineHiLiting(!_pEditView->isCurrentLineHiLiting(), colour);
break;
}
case IDM_VIEW_EDGEBACKGROUND:
case IDM_VIEW_EDGELINE:
case IDM_VIEW_EDGENONE:
{
int mode;
switch (id)
{
case IDM_VIEW_EDGELINE:
{
mode = EDGE_LINE;
break;
}
case IDM_VIEW_EDGEBACKGROUND:
{
mode = EDGE_BACKGROUND;
break;
}
default :
mode = EDGE_NONE;
}
pEditView->execute(SCI_SETEDGEMODE, mode);
break;
}
case IDM_SETTING_EDGE_SIZE :
{
ValueDlg nbColumnEdgeDlg;
ScintillaViewParams & svp = (ScintillaViewParams &)pNppParam->getSVP(param == 1?SCIV_PRIMARY:SCIV_SECOND);
nbColumnEdgeDlg.init(_hInst, _hSelf, svp._edgeNbColumn, "Nb of column:");
nbColumnEdgeDlg.setNBNumber(3);
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_hParent, &p);
int size = nbColumnEdgeDlg.doDialog(p, _isRTL);
if (size != -1)
{
svp._edgeNbColumn = size;
pEditView->execute(SCI_SETEDGECOLUMN, size);
}
break;
}
}
}
void Notepad_plus::command(int id)
{
NppParameters *pNppParam = NppParameters::getInstance();
switch (id)
{
case IDM_FILE_NEW:
fileNew();
break;
case IDM_FILE_OPEN:
fileOpen();
break;
case IDM_FILE_CLOSE:
fileClose();
checkSyncState();
break;
case IDM_FILE_CLOSEALL:
fileCloseAll();
checkSyncState();
break;
case IDM_FILE_CLOSEALL_BUT_CURRENT :
fileCloseAllButCurrent();
checkSyncState();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -