Adjust lexing handling, restored performance in some cases,

temp. disable cloneview on updates.
Update lexer table to also contain lexerID.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@242 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
harrybharry 2008-06-18 13:12:54 +00:00
parent a06816432b
commit ed40c1f03b
6 changed files with 128 additions and 66 deletions

View File

@ -715,7 +715,26 @@ bool Notepad_plus::doReload(BufferID id, bool alert)
if (::MessageBox(_hSelf, "Do you want to reload the current file?", "Reload", MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL) != IDYES)
return false;
}
return MainFileManager->reloadBuffer(id);
//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.execute(SCI_SETDOCPOINTER, 0, 0);
}
if (subVisisble) {
_subEditView.execute(SCI_SETDOCPOINTER, 0, 0);
}
bool res = MainFileManager->reloadBuffer(id);
Buffer * pBuf = MainFileManager->getBufferByID(id);
if (mainVisisble) {
_mainEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
}
if (subVisisble) {
_subEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument());
}
return res;
}
bool Notepad_plus::doSave(BufferID id, const char * filename, bool isCopy)
@ -3993,6 +4012,29 @@ void Notepad_plus::command(int id)
}
void Notepad_plus::setLanguage(int id, LangType langType) {
//Add logic to prevent changing a language when a document is shared between two views
//If so, release one document
bool reset = false;
Document prev = 0;
if (bothActive()) {
if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID()) {
reset = true;
prev = _subEditView.execute(SCI_GETDOCPOINTER);
_subEditView.execute(SCI_SETDOCPOINTER, 0, 0);
}
}
if (reset) {
_mainEditView.getCurrentBuffer()->setLangType(langType);
} else {
_pEditView->getCurrentBuffer()->setLangType(langType);
}
if (reset) {
_subEditView.execute(SCI_SETDOCPOINTER, 0, prev);
}
};
enum LangType Notepad_plus::menuID2LangType(int cmdID)
{
switch (cmdID)

View File

@ -466,9 +466,7 @@ private:
void checkLangsMenu(int id) const ;
void setLanguage(int id, LangType langType) {
_pEditView->getCurrentBuffer()->setLangType(langType);
};
void setLanguage(int id, LangType langType);
enum LangType menuID2LangType(int cmdID);

View File

@ -376,7 +376,7 @@ BufferID FileManager::loadFile(const char * filename, Document doc) {
::GetFullPathName(filename, MAX_PATH, fullpath, NULL);
::GetLongPathName(fullpath, fullpath, MAX_PATH);
Utf8_16_Read UnicodeConvertor; //declare here so we can get information after loading is done
if (loadFileData(doc, fullpath, &UnicodeConvertor)) {
if (loadFileData(doc, fullpath, &UnicodeConvertor, L_TXT)) {
Buffer * newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath);
BufferID id = (BufferID) newBuf;
newBuf->_id = id;
@ -405,9 +405,16 @@ bool FileManager::reloadBuffer(BufferID id) {
Buffer * buf = getBufferByID(id);
Document doc = buf->getDocument();
Utf8_16_Read UnicodeConvertor;
bool res = loadFileData(doc, buf->getFilePath(), &UnicodeConvertor);
if (res)
buf->setNeedsLexing(true);
bool res = loadFileData(doc, buf->getFilePath(), &UnicodeConvertor, buf->getLangType());
if (res) {
if (UnicodeConvertor.getNewBuf()) {
buf->determinateFormat(UnicodeConvertor.getNewBuf());
} else {
buf->determinateFormat("");
}
buf->setUnicodeMode(UnicodeConvertor.getEncoding());
// buf->setNeedsLexing(true);
}
return res;
}
@ -516,7 +523,7 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d
return id;
}
bool FileManager::loadFileData(Document doc, const char * filename, Utf8_16_Read * UnicodeConvertor) {
bool FileManager::loadFileData(Document doc, const char * filename, Utf8_16_Read * UnicodeConvertor, LangType language) {
const int blockSize = 128 * 1024; //128 kB
char data[blockSize];
@ -527,13 +534,20 @@ bool FileManager::loadFileData(Document doc, const char * filename, Utf8_16_Read
//Setup scratchtilla for new filedata
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc);
_pscratchTilla->execute(SCI_CLEARALL);
if (language < L_EXTERNAL) {
_pscratchTilla->execute(SCI_SETLEXER, ScintillaEditView::langNames[language].lexerID);
} else {
int id = language - L_EXTERNAL;
char * name = NppParameters::getInstance()->getELCFromIndex(id)._name;
_pscratchTilla->execute(SCI_SETLEXERLANGUAGE, 0, (LPARAM)name);
}
size_t lenFile = 0;
size_t lenConvert = 0; //just in case conversion results in 0, but file not empty
do {
lenFile = fread(data, 1, blockSize, fp);
lenConvert = UnicodeConvertor->convert(data, lenFile);
_pscratchTilla->execute(SCI_ADDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf()));
_pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf()));
} while (lenFile > 0);
fclose(fp);

View File

@ -108,7 +108,7 @@ private:
BufferID _nextBufferID;
size_t _nrBufs;
bool loadFileData(Document doc, const char * filename, Utf8_16_Read * UnicodeConvertor);
bool loadFileData(Document doc, const char * filename, Utf8_16_Read * UnicodeConvertor, LangType language);
};
#define MainFileManager FileManager::getInstance()
@ -126,7 +126,7 @@ public :
//Destructor makes sure its purged
Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const char *fileName) //type must be either DOC_REGULAR or DOC_UNNAMED
: _pManager(pManager), _id(id), _isDirty(false), _doc(doc), _isFileReadOnly(false), _isUserReadOnly(false), _recentTag(-1), _references(0),
_canNotify(false), _timeStamp(0), _needLexer(true)
_canNotify(false), _timeStamp(0)
{
NppParameters *pNppParamInst = NppParameters::getInstance();
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings();
@ -141,9 +141,13 @@ public :
checkFileState();
_currentStatus = type;
_isDirty = false;
_needLexer = false; //new buffers do not need lexing, Scintilla takes care of that
/*
if (type == DOC_UNNAMED)
_needLexer = false; //empty document, no styling
*/
_canNotify = true;
};

View File

@ -57,57 +57,57 @@ const int ScintillaEditView::_markersArray[][NB_FOLDER_STATE] = {
//Array with all the names of all languages
LanguageName ScintillaEditView::langNames[L_EXTERNAL+1] = {
{"normal", "Normal text", "Normal text file", L_TXT},
{"php", "PHP", "PHP Hypertext Preprocessor file", L_PHP},
{"c", "C", "C source file", L_C},
{"cpp", "C++", "C++ source file", L_CPP},
{"cs", "C#", "C# source file", L_CS},
{"objc", "Objective-C", "Objective-C source file", L_OBJC},
{"java", "Java", "Java source file", L_JAVA},
{"rc", "RC", "Windows Resource file", L_RC},
{"html", "HTML", "Hyper Text Markup Language file", L_HTML},
{"xml", "XML", "eXtensible Markup Language file", L_XML},
{"makefile", "Makefile", "Makefile", L_MAKEFILE},
{"pascal", "Pascal", "Pascal source file", L_PASCAL},
{"batch", "Batch", "Batch file", L_BATCH},
{"ini", "ini", "MS ini file", L_INI},
{"nfo", "NFO", "MSDOS Style/ASCII Art", L_NFO},
{"udf", "udf", "User Define File", L_USER},
{"asp", "ASP", "Active Server Pages script file", L_ASP},
{"sql", "SQL", "Structured Query Language file", L_SQL},
{"vb", "VB", "Visual Basic file", L_VB},
{"javascript", "JavaScript", "JavaScript file", L_JS},
{"css", "CSS", "Cascade Style Sheets File", L_CSS},
{"perl", "Perl", "Perl source file", L_PERL},
{"python", "Python", "Python file", L_PYTHON},
{"lua", "Lua", "Lua source File", L_LUA},
{"tex", "TeX", "TeX file", L_TEX},
{"fortran", "Fortran", "Fortran source file", L_FORTRAN},
{"bash", "Shell", "Unix script file", L_BASH},
{"actionscript","Flash Action", "Flash Action script file", L_FLASH}, //WARNING, was "flash"
{"nsis", "NSIS", "Nullsoft Scriptable Install System script file", L_NSIS},
{"tcl", "TCL", "Tool Command Language file", L_TCL},
{"lisp", "Lisp", "List Processing language file", L_LISP},
{"scheme", "Scheme", "Scheme file", L_SCHEME},
{"asm", "Assembly", "Assembly language source file", L_ASM},
{"diff", "Diff", "Diff file", L_DIFF},
{"props", "Properties file", "Properties file", L_PROPS},
{"postscript", "Postscript", "Postscript file", L_PS},
{"ruby", "Ruby", "Ruby file", L_RUBY},
{"smalltalk", "Smalltalk", "Smalltalk file", L_SMALLTALK},
{"vhdl", "VHDL", "VHSIC Hardware Description Language file", L_VHDL},
{"kix", "KiXtart", "KiXtart file", L_KIX},
{"autoit", "AutoIt", "AutoIt", L_AU3},
{"caml", "CAML", "Categorical Abstract Machine Language", L_CAML},
{"ada", "Ada", "Ada file", L_ADA},
{"verilog", "Verilog", "Verilog file", L_VERILOG},
{"matlab", "MATLAB", "MATrix LABoratory", L_MATLAB},
{"haskell", "Haskell", "Haskell", L_HASKELL},
{"inno", "Inno", "Inno Setup script", L_INNO},
{"searchResult","Internal Search", "Internal Search", L_SEARCHRESULT},
{"cmake", "CMAKEFILE", "CMAKEFILE", L_CMAKE},
{"yaml", "YAML", "YAML Ain't Markup Language", L_YAML},
{"ext", "External", "External", L_EXTERNAL}
{"normal", "Normal text", "Normal text file", L_TXT, SCLEX_NULL},
{"php", "PHP", "PHP Hypertext Preprocessor file", L_PHP, SCLEX_HTML},
{"c", "C", "C source file", L_C, SCLEX_CPP},
{"cpp", "C++", "C++ source file", L_CPP, SCLEX_CPP},
{"cs", "C#", "C# source file", L_CS, },
{"objc", "Objective-C", "Objective-C source file", L_OBJC, },
{"java", "Java", "Java source file", L_JAVA, SCLEX_CPP},
{"rc", "RC", "Windows Resource file", L_RC, SCLEX_CPP},
{"html", "HTML", "Hyper Text Markup Language file", L_HTML, SCLEX_HTML},
{"xml", "XML", "eXtensible Markup Language file", L_XML, SCLEX_XML},
{"makefile", "Makefile", "Makefile", L_MAKEFILE, SCLEX_MAKEFILE},
{"pascal", "Pascal", "Pascal source file", L_PASCAL, SCLEX_PASCAL},
{"batch", "Batch", "Batch file", L_BATCH, SCLEX_BATCH},
{"ini", "ini", "MS ini file", L_INI, SCLEX_PROPERTIES},
{"nfo", "NFO", "MSDOS Style/ASCII Art", L_NFO, SCLEX_NULL},
{"udf", "udf", "User Define File", L_USER, SCLEX_USER},
{"asp", "ASP", "Active Server Pages script file", L_ASP, SCLEX_HTML},
{"sql", "SQL", "Structured Query Language file", L_SQL, SCLEX_SQL},
{"vb", "VB", "Visual Basic file", L_VB, SCLEX_VB},
{"javascript", "JavaScript", "JavaScript file", L_JS, SCLEX_CPP},
{"css", "CSS", "Cascade Style Sheets File", L_CSS, SCLEX_CSS},
{"perl", "Perl", "Perl source file", L_PERL, SCLEX_PERL},
{"python", "Python", "Python file", L_PYTHON, SCLEX_PYTHON},
{"lua", "Lua", "Lua source File", L_LUA, SCLEX_LUA},
{"tex", "TeX", "TeX file", L_TEX, SCLEX_TEX},
{"fortran", "Fortran", "Fortran source file", L_FORTRAN, SCLEX_FORTRAN},
{"bash", "Shell", "Unix script file", L_BASH, SCLEX_BASH},
{"actionscript","Flash Action", "Flash Action script file", L_FLASH, SCLEX_OBJC}, //WARNING, was "flash"
{"nsis", "NSIS", "Nullsoft Scriptable Install System script file", L_NSIS, SCLEX_NSIS},
{"tcl", "TCL", "Tool Command Language file", L_TCL, SCLEX_TCL},
{"lisp", "Lisp", "List Processing language file", L_LISP, SCLEX_LISP},
{"scheme", "Scheme", "Scheme file", L_SCHEME, SCLEX_LISP},
{"asm", "Assembly", "Assembly language source file", L_ASM, SCLEX_ASM},
{"diff", "Diff", "Diff file", L_DIFF, SCLEX_DIFF},
{"props", "Properties file", "Properties file", L_PROPS, SCLEX_PROPERTIES},
{"postscript", "Postscript", "Postscript file", L_PS, SCLEX_PS},
{"ruby", "Ruby", "Ruby file", L_RUBY, SCLEX_RUBY},
{"smalltalk", "Smalltalk", "Smalltalk file", L_SMALLTALK, SCLEX_SMALLTALK},
{"vhdl", "VHDL", "VHSIC Hardware Description Language file", L_VHDL, SCLEX_VHDL},
{"kix", "KiXtart", "KiXtart file", L_KIX, SCLEX_KIX},
{"autoit", "AutoIt", "AutoIt", L_AU3, SCLEX_AU3},
{"caml", "CAML", "Categorical Abstract Machine Language", L_CAML, SCLEX_CAML},
{"ada", "Ada", "Ada file", L_ADA, SCLEX_ADA},
{"verilog", "Verilog", "Verilog file", L_VERILOG, SCLEX_VERILOG},
{"matlab", "MATLAB", "MATrix LABoratory", L_MATLAB, SCLEX_MATLAB},
{"haskell", "Haskell", "Haskell", L_HASKELL, SCLEX_HASKELL},
{"inno", "Inno", "Inno Setup script", L_INNO, SCLEX_INNOSETUP},
{"searchResult","Internal Search", "Internal Search", L_SEARCHRESULT, SCLEX_SEARCHRESULT},
{"cmake", "CMAKEFILE", "CMAKEFILE", L_CMAKE, SCLEX_CMAKE},
{"yaml", "YAML", "YAML Ain't Markup Language", L_YAML, SCLEX_YAML},
{"ext", "External", "External", L_EXTERNAL, SCLEX_NULL}
};
//const int MASK_RED = 0xFF0000;
@ -698,6 +698,7 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
}
execute(SCI_STYLECLEARALL);
int oldBits = execute(SCI_GETSTYLEBITSNEEDED);
int iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE);
if (iFind != -1)
@ -938,7 +939,8 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
execute(SCI_SETUSETABS, !((NppParameters::getInstance())->getNppGUI())._tabReplacedBySpace);
int bitsNeeded = execute(SCI_GETSTYLEBITSNEEDED);
execute(SCI_SETSTYLEBITS, bitsNeeded);
if (oldBits != bitsNeeded)
execute(SCI_SETSTYLEBITS, bitsNeeded);
}
BufferID ScintillaEditView::attachDefaultDoc()
@ -1001,8 +1003,9 @@ void ScintillaEditView::restoreCurrentPos()
//! \brief this method activates the doc and the corresponding sub tab
//! \brief return the index of previeus current doc
void ScintillaEditView::restyleBuffer() {
int end = execute(SCI_GETENDSTYLED); //style up to the last styled byte.
execute(SCI_CLEARDOCUMENTSTYLE);
execute(SCI_COLOURISE, 0, -1);
execute(SCI_COLOURISE, 0, end);
_currentBuffer->setNeedsLexing(false);
}

View File

@ -130,6 +130,7 @@ struct LanguageName {
const char * shortName;
const char * longName;
LangType LangID;
int lexerID;
};
class ScintillaEditView : public Window