From: <for...@us...> - 2009-04-23 17:05:21
|
Revision: 1102 http://colorer.svn.sourceforge.net/colorer/?rev=1102&view=rev Author: formirror Date: 2009-04-23 17:05:10 +0000 (Thu, 23 Apr 2009) Log Message: ----------- custom parameters for firstline Modified Paths: -------------- branches/EFREMOV-BASE2/colorer/hrc/proto.hrc branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.cpp branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.h Modified: branches/EFREMOV-BASE2/colorer/hrc/proto.hrc =================================================================== --- branches/EFREMOV-BASE2/colorer/hrc/proto.hrc 2009-04-23 15:25:45 UTC (rev 1101) +++ branches/EFREMOV-BASE2/colorer/hrc/proto.hrc 2009-04-23 17:05:10 UTC (rev 1102) @@ -258,6 +258,12 @@ <filename>/\.(xml|gi2|gpr|ui)$/i</filename> <firstline>/^<\?xml | <\!DOCTYPE | xmlns /x</firstline> <firstline>/^\s*<\w+>\s*/</firstline><!-- (\s+\w+\s*=\*(["']).+?\2)*\s* --> + <parameters> + <!-- firstline --> + <param name='firstlines' value='10' description="lines for 'firstline'"/> + <param name='firstlinebytes' value='2000' description="bytes for 'firstline'"/> + </parameters> + </prototype> <package name="xmlns" description="xml namespace" targetNamespace="http://www.w3.org/XML/1998/namespace"> <location link="xml/gen/xmlns.hrc"/> @@ -667,6 +673,9 @@ <param name="fullback" value="yes" description="If yes, draws background in inlined languages till end of the screen"/> <param name="default-fore" value="" description="User-defined foreground color for this particular type"/> <param name="default-back" value="" description="User-defined foreground color for this particular type"/> + <!-- firstline --> + <param name='firstlines' value='4' description="lines for 'firstline'"/> + <param name='firstlinebytes' value='500' description="bytes for 'firstline'"/> </parameters> </prototype> Modified: branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.cpp =================================================================== --- branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.cpp 2009-04-23 15:25:45 UTC (rev 1101) +++ branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.cpp 2009-04-23 17:05:10 UTC (rev 1102) @@ -1,10 +1,11 @@ #include<common/Logging.h> #include<colorer/editor/BaseEditor.h> +#include<unicode/UnicodeTools.h> #define IDLE_PARSE(time) (100+time*4) -const int CHOOSE_STR = 10; +const int CHOOSE_STR = 4; const int CHOOSE_LEN = 200 * CHOOSE_STR; ErrorHandler *eh; @@ -117,26 +118,54 @@ return currentFileType; } -FileType *BaseEditor::chooseFileType(const String *fileName){ - if (lineSource == null){ + +FileType *BaseEditor::chooseFileTypeCh(const String *fileName, int chooseStr, int chooseLen) +{ + StringBuffer textStart; + int totalLength = 0; + for(int i = 0; i < chooseStr; i++) + { + String *iLine = lineSource->getLine(i); + if (iLine == null) break; + textStart.append(iLine); + textStart.append(DString("\n")); + totalLength += iLine->length(); + if (totalLength > chooseLen) break; + } + currentFileType = hrcParser->chooseFileType(fileName, &textStart); + + int chooseStrNext=0, chooseLenNext=0; + UnicodeTools::getNumber(currentFileType->getParamValue(DString("firstlines")), &chooseStrNext); + UnicodeTools::getNumber(currentFileType->getParamValue(DString("firstlinebytes")), &chooseLenNext); + + if((chooseStrNext || chooseLenNext) && (chooseStrNext != chooseStr || chooseLenNext != chooseLen)) + { + currentFileType = chooseFileTypeCh(fileName, chooseStrNext, chooseLenNext); + } + return currentFileType; +} + +FileType *BaseEditor::chooseFileType(const String *fileName) +{ + if (lineSource == null) + { currentFileType = hrcParser->chooseFileType(fileName, null); - }else{ - StringBuffer textStart; - int totalLength = 0; - for(int i = 0; i < CHOOSE_STR; i++){ - String *iLine = lineSource->getLine(i); - if (iLine == null) break; - textStart.append(iLine); - textStart.append(DString("\n")); - totalLength += iLine->length(); - if (totalLength > CHOOSE_LEN) break; - } - currentFileType = hrcParser->chooseFileType(fileName, &textStart); } + else + { + int chooseStr=CHOOSE_STR, chooseLen=CHOOSE_LEN; + + FileType *def = hrcParser->getFileType(&DString("default")); + UnicodeTools::getNumber(def->getParamValue(DString("firstlines")), &chooseStr); + UnicodeTools::getNumber(def->getParamValue(DString("firstlinebytes")), &chooseLen); + + currentFileType = chooseFileTypeCh(fileName, chooseStr, chooseLen); + } setFileType(currentFileType); return currentFileType; } + FileType *BaseEditor::getFileType(){ return currentFileType; } Modified: branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.h =================================================================== --- branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.h 2009-04-23 15:25:45 UTC (rev 1101) +++ branches/EFREMOV-BASE2/colorer/src/shared/colorer/editor/BaseEditor.h 2009-04-23 17:05:10 UTC (rev 1102) @@ -241,6 +241,9 @@ void leaveScheme(int lno, String *line, int sx, int ex, const Region *region, const Scheme *scheme); private: + + FileType *chooseFileTypeCh(const String *fileName, int chooseStr, int chooseLen); + HRCParser *hrcParser; TextParser *textParser; ParserFactory *parserFactory; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |