📄 scintillaeditview.cpp
字号:
execute(SCI_COLOURISE, 0, -1);
int maxLine = execute(SCI_GETLINECOUNT);
for (int line = 0; line < maxLine; line++)
{
int level = execute(SCI_GETFOLDLEVEL, line);
if (level & SC_FOLDLEVELHEADERFLAG)
{
level -= SC_FOLDLEVELBASE;
if (level2Collapse == (level & SC_FOLDLEVELNUMBERMASK))
if ((execute(SCI_GETFOLDEXPANDED, line) != 0) != mode)
execute(SCI_TOGGLEFOLD, line);
}
}
}
void ScintillaEditView::foldCurrentPos(bool mode)
{
execute(SCI_COLOURISE, 0, -1);
int currentLine = this->getCurrentLineNumber();
int headerLine;
int level = execute(SCI_GETFOLDLEVEL, currentLine);
if (level & SC_FOLDLEVELHEADERFLAG)
headerLine = currentLine;
else
{
headerLine = execute(SCI_GETFOLDPARENT, currentLine);
if (headerLine == -1)
return;
}
if ((execute(SCI_GETFOLDEXPANDED, headerLine) != 0) != mode)
execute(SCI_TOGGLEFOLD, headerLine);
}
void ScintillaEditView::foldAll(bool mode)
{
execute(SCI_COLOURISE, 0, -1);
int maxLine = execute(SCI_GETLINECOUNT);
for (int line = 0; line < maxLine; line++)
{
int level = execute(SCI_GETFOLDLEVEL, line);
if (level & SC_FOLDLEVELHEADERFLAG)
if ((execute(SCI_GETFOLDEXPANDED, line) != 0) != mode)
execute(SCI_TOGGLEFOLD, line);
}
}
// return the index to close then (argument) the index to activate
int ScintillaEditView::closeCurrentDoc(int & i2Activate)
{
int oldCurrent = _currentIndex;
Position & prevDocPos = _buffers[_currentIndex]._pos;
// if the file 2 delete is the last one
if (_currentIndex == int(_buffers.size()) - 1)
{
// if current index is 0, ie. the current is the only one
if (!_currentIndex)
{
_currentIndex = 0;
}
// the current is NOT the only one and it is the last one,
// we set it to the index which precedes it
else
_currentIndex -= 1;
}
// else the next current index will be the same,
// we do nothing
// get the iterator and calculate its position with the old current index value
buf_vec_t::iterator posIt = _buffers.begin() + oldCurrent;
// erase the position given document from our list
_buffers.erase(posIt);
// set another document, so the ref count of old active document owned
// by Scintilla view will be decreased to 0 by SCI_SETDOCPOINTER message
// then increase the new current doc to 2
execute(SCI_SETDOCPOINTER, 0, _buffers[_currentIndex]._doc);
// Important : to avoid the leak of memory
// Now keep the ref counter of new current doc as 1
execute(SCI_RELEASEDOCUMENT, 0, _buffers[_currentIndex]._doc);
defineDocType(_buffers[_currentIndex]._lang);
restoreCurrentPos(prevDocPos);
// restore the collapsed info
int nbLineState = _buffers[_currentIndex]._foldState.size();
for (int i = 0 ; i < nbLineState ; i++)
{
HeaderLineState &hls = _buffers[_currentIndex]._foldState[i];
bool expanded = (execute(SCI_GETFOLDEXPANDED, hls._headerLineNumber) != 0);
// set line to state folded
if (hls._isCollapsed && !expanded)
execute(SCI_TOGGLEFOLD, hls._headerLineNumber);
if (!hls._isCollapsed && expanded)
execute(SCI_TOGGLEFOLD, hls._headerLineNumber);
}
i2Activate = _currentIndex;
return oldCurrent;
}
void ScintillaEditView::closeDocAt(int i2Close)
{
execute(SCI_RELEASEDOCUMENT, 0, _buffers[i2Close]._doc);
// get the iterator and calculate its position with the old current index value
buf_vec_t::iterator posIt = _buffers.begin() + i2Close;
// erase the position given document from our list
_buffers.erase(posIt);
_currentIndex -= (i2Close < _currentIndex)?1:0;
}
void ScintillaEditView::removeAllUnusedDocs()
{
// unreference all docs from list of Scintilla
// by sending SCI_RELEASEDOCUMENT message
for (int i = 0 ; i < int(_buffers.size()) ; i++)
if (i != _currentIndex)
execute(SCI_RELEASEDOCUMENT, 0, _buffers[i]._doc);
// remove all docs except the current doc from list
_buffers.clear();
}
void ScintillaEditView::getText(char *dest, int start, int end)
{
TextRange tr;
tr.chrg.cpMin = start;
tr.chrg.cpMax = end;
tr.lpstrText = dest;
execute(SCI_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
}
void ScintillaEditView::marginClick(int position, int modifiers){ int lineClick = int(execute(SCI_LINEFROMPOSITION, position, 0)); int levelClick = int(execute(SCI_GETFOLDLEVEL, lineClick, 0)); if (levelClick & SC_FOLDLEVELHEADERFLAG) { if (modifiers & SCMOD_SHIFT) { // Ensure all children visible execute(SCI_SETFOLDEXPANDED, lineClick, 1); expand(lineClick, true, true, 100, levelClick); } else if (modifiers & SCMOD_CTRL) { if (execute(SCI_GETFOLDEXPANDED, lineClick, 0)) { // Contract this line and all children execute(SCI_SETFOLDEXPANDED, lineClick, 0); expand(lineClick, false, true, 0, levelClick); } else { // Expand this line and all children execute(SCI_SETFOLDEXPANDED, lineClick, 1); expand(lineClick, true, true, 100, levelClick); } } else { // Toggle this line execute(SCI_TOGGLEFOLD, lineClick, 0); } }}void ScintillaEditView::expand(int &line, bool doExpand, bool force, int visLevels, int level){ int lineMaxSubord = int(execute(SCI_GETLASTCHILD, line, level & SC_FOLDLEVELNUMBERMASK)); line++; while (line <= lineMaxSubord) { if (force) { if (visLevels > 0) execute(SCI_SHOWLINES, line, line); else execute(SCI_HIDELINES, line, line); } else { if (doExpand) execute(SCI_SHOWLINES, line, line); } int levelLine = level; if (levelLine == -1) levelLine = int(execute(SCI_GETFOLDLEVEL, line, 0)); if (levelLine & SC_FOLDLEVELHEADERFLAG) { if (force) { if (visLevels > 1) execute(SCI_SETFOLDEXPANDED, line, 1); else execute(SCI_SETFOLDEXPANDED, line, 0); expand(line, doExpand, force, visLevels - 1); } else { if (doExpand) { if (!execute(SCI_GETFOLDEXPANDED, line, 0)) execute(SCI_SETFOLDEXPANDED, line, 1); expand(line, true, force, visLevels - 1); } else { expand(line, false, force, visLevels - 1); } } } else { line++; } }}
void ScintillaEditView::makeStyle(const char *lexerName, const char **keywordArray)
{
LexerStyler *pStyler = (_pParameter->getLStylerArray()).getLexerStylerByName(lexerName);
if (pStyler)
{
for (int i = 0 ; i < pStyler->getNbStyler() ; i++)
{
Style & style = pStyler->getStyler(i);
setStyle(style._styleID, style._fgColor, style._bgColor, style._fontName, style._fontStyle, style._fontSize);
if (keywordArray)
{
if ((style._keywordClass != -1) && (style._keywords))
keywordArray[style._keywordClass] = style._keywords->c_str();
}
}
}
}
void ScintillaEditView::performGlobalStyles()
{
StyleArray & stylers = _pParameter->getMiscStylerArray();
int i = stylers.getStylerIndexByName("Current line background colour");
if (i != -1)
{
Style & style = stylers.getStyler(i);
execute(SCI_SETCARETLINEBACK, style._bgColor);
}
i = stylers.getStylerIndexByName("Mark colour");
if (i != -1)
{
Style & style = stylers.getStyler(i);
execute(SCI_MARKERSETFORE, 1, style._fgColor);
execute(SCI_MARKERSETBACK, 1, style._bgColor);
}
COLORREF selectColorBack = grey;
i = stylers.getStylerIndexByName("Selected text colour");
if (i != -1)
{
Style & style = stylers.getStyler(i);
selectColorBack = style._bgColor;
execute(SCI_SETSELBACK, 1, selectColorBack);
}
COLORREF caretColor = black;
i = stylers.getStylerIndexByID(SCI_SETCARETFORE);
if (i != -1)
{
Style & style = stylers.getStyler(i);
caretColor = style._fgColor;
}
execute(SCI_SETCARETFORE, caretColor);
COLORREF edgeColor = liteGrey;
i = stylers.getStylerIndexByName("Edge colour");
if (i != -1)
{
Style & style = stylers.getStyler(i);
edgeColor = style._fgColor;
}
execute(SCI_SETEDGECOLOUR, edgeColor);
COLORREF foldMarginColor = grey;
COLORREF foldMarginHiColor = white;
i = stylers.getStylerIndexByName("Fold margin");
if (i != -1)
{
Style & style = stylers.getStyler(i);
foldMarginHiColor = style._fgColor;
foldMarginColor = style._bgColor;
}
execute(SCI_SETFOLDMARGINCOLOUR, true, foldMarginColor);
execute(SCI_SETFOLDMARGINHICOLOUR, true, foldMarginHiColor);
//StyleArray & stylers = _pParameter->getMiscStylerArray();
COLORREF foldfgColor = white;
COLORREF foldbgColor = grey;
i = stylers.getStylerIndexByName("Fold");
if (i != -1)
{
Style & style = stylers.getStyler(i);
foldfgColor = style._bgColor;
foldbgColor = style._fgColor;
}
for (int i = 0 ; i < NB_FOLDER_STATE ; i++)
defineMarker(_markersArray[FOLDER_TYPE][i], _markersArray[_folderStyle][i], foldfgColor, foldbgColor);
}
void ScintillaEditView::setLineIndent(int line, int indent) const {
if (indent < 0)
return;
CharacterRange crange = getSelection();
int posBefore = execute(SCI_GETLINEINDENTPOSITION, line);
execute(SCI_SETLINEINDENTATION, line, indent);
int posAfter = execute(SCI_GETLINEINDENTPOSITION, line);
int posDifference = posAfter - posBefore;
if (posAfter > posBefore) {
// Move selection on
if (crange.cpMin >= posBefore) {
crange.cpMin += posDifference;
}
if (crange.cpMax >= posBefore) {
crange.cpMax += posDifference;
}
} else if (posAfter < posBefore) {
// Move selection back
if (crange.cpMin >= posAfter) {
if (crange.cpMin >= posBefore)
crange.cpMin += posDifference;
else
crange.cpMin = posAfter;
}
if (crange.cpMax >= posAfter) {
if (crange.cpMax >= posBefore)
crange.cpMax += posDifference;
else
crange.cpMax = posAfter;
}
}
execute(SCI_SETSEL, crange.cpMin, crange.cpMax);
}
const char * ScintillaEditView::getCompleteKeywordList(std::string & kwl, LangType langType, int keywordIndex)
{
kwl += " ";
const char *defKwl = _pParameter->getWordList(langType, keywordIndex);
kwl += defKwl?defKwl:"";
return kwl.c_str();
}
void ScintillaEditView::convertSelectedTextTo(bool Case) {
size_t selectionStart = execute(SCI_GETSELECTIONSTART);
size_t selectionEnd = execute(SCI_GETSELECTIONEND);
int strSize = ((selectionEnd > selectionStart)?(selectionEnd - selectionStart):(selectionStart - selectionEnd))+1;
if (strSize)
{
char *selectedStr = new char[strSize];
int strWSize = strSize * 2;
WCHAR *selectedStrW = new WCHAR[strWSize];
execute(SCI_GETSELTEXT, 0, (LPARAM)selectedStr);
unsigned int codepage = _codepage;
UniMode um = getCurrentBuffer().getUnicodeMode();
if (um != uni8Bit)
codepage = CP_UTF8;
int nbChar = ::MultiByteToWideChar(codepage, 0, selectedStr, strSize, selectedStrW, strWSize);
for (int i = 0 ; i < nbChar ; i++)
{
if (Case == UPPERCASE)
selectedStrW[i] = (WCHAR)::CharUpperW((LPWSTR)selectedStrW[i]);
else
selectedStrW[i] = (WCHAR)::CharLowerW((LPWSTR)selectedStrW[i]);
}
::WideCharToMultiByte(codepage, 0, selectedStrW, strWSize, selectedStr, strSize, NULL, NULL);
execute(SCI_REPLACESEL, strSize, (LPARAM)selectedStr);
execute(SCI_SETSEL, selectionStart, selectionEnd);
delete [] selectedStr;
delete [] selectedStrW;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -