From: <moo...@us...> - 2003-12-12 11:00:08
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1:/tmp/cvs-serv25750 Modified Files: AnyEdit.cpp AnyEdit.dsp AnyEdit.h AnyEditDoc.cpp AnyEditDoc.h AnyEditView.cpp AnyEditView.h Language.cpp Added Files: ConfigFile.cpp ConfigFile.h SyntaxFile.cpp SyntaxFile.h Log Message: - The new Syntax File handling implemented. - Syntax files now XML. - New handling of Scintilla settings - New handling of the Language type of a document - New Config file with AnyEdit settings in XML format, will replace Registry settings. - Some multi used constants converted to defines. - Changed menu handling for all 3 margins. - Changed menu handling for bookmarks. More additions needed, will be implemented in the future. Cleanup is also still needed. --- NEW FILE: ConfigFile.cpp --- // ConfigFile.cpp: implementation of the CConfigFile class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" //#include "anyedit.h" #include "ConfigFile.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CConfigFile::CConfigFile() { szFileName = ""; } CConfigFile::~CConfigFile() { } // Set the Filename of the config file to parse. void CConfigFile::SetFilename( CString lszFileName ) { szFileName = lszFileName; } // Parse the config file. BOOL CConfigFile::Parse() { if( szFileName.IsEmpty() ) return false; if( !xparser.parse_file( szFileName ) ) return false; return true; } // Save the config file, including changes. BOOL CConfigFile::Save() { return TRUE; } // Get the number of languages int CConfigFile::GetLanguageCount() { xml_node xnode; xnode = xparser.document(); if( xnode.empty() && !xnode.children() ) return -1; xnode = xnode.child(0); if( xnode.empty() && !xnode.children() ) return -1; xnode = xnode.first_element_by_name( TAG_LANGUAGES ); if( xnode.empty() && !xnode.children() ) return -1; return atoi( xnode.child(0).value() ); } // Get the name of the language with number iNumber. CString CConfigFile::GetLanguageName( int iNumber ) { char szNumber[4]; xml_node xnode; sprintf( szNumber, "%i", iNumber ); xnode = xparser.document().first_element_by_attribute( TAG_LANGUAGE, ATT_LANGUAGE_NUMBER, szNumber ); if( xnode.empty() && !xnode.children() ) return ""; xnode = xnode.first_element_by_name( TAG_LANGUAGE_NAME ); if( xnode.empty() && !xnode.children() ) return ""; return xnode.child(0).value(); } // Get the syntaxfile name of the language with number iNumber. CString CConfigFile::GetLanguageSyntaxFileName( int iNumber ) { char szNumber[4]; xml_node xnode; sprintf( szNumber, "%i", iNumber ); xnode = xparser.document().first_element_by_attribute( TAG_LANGUAGE, ATT_LANGUAGE_NUMBER, szNumber ); if( xnode.empty() && !xnode.children() ) return ""; xnode = xnode.first_element_by_name( TAG_LANGUAGE_SYNTAXFILE ); if( xnode.empty() && !xnode.children() ) return ""; return xnode.child(0).value(); } // Get the auto completion filename of the language with number iNumber. CString CConfigFile::GetLanguageAutoCompFileName( int iNumber ) { char szNumber[4]; xml_node xnode; sprintf( szNumber, "%i", iNumber ); xnode = xparser.document().first_element_by_attribute( TAG_LANGUAGE, ATT_LANGUAGE_NUMBER, szNumber ); if( xnode.empty() && !xnode.children() ) return ""; xnode = xnode.first_element_by_name( TAG_LANGUAGE_AUTOCOMPFILE ); if( xnode.empty() && !xnode.children() ) return ""; return xnode.child(0).value(); } // Get the extensions string of languge with number iNumber. CString CConfigFile::GetLanguageExtensions( int iNumber ) { char szNumber[4]; xml_node xnode; sprintf( szNumber, "%i", iNumber ); xnode = xparser.document().first_element_by_attribute( TAG_LANGUAGE, ATT_LANGUAGE_NUMBER, szNumber ); if( xnode.empty() && !xnode.children() ) return ""; xnode = xnode.first_element_by_name( TAG_LANGUAGE_EXTENSIONS ); if( xnode.empty() && !xnode.children() ) return ""; return xnode.child(0).value(); } --- NEW FILE: ConfigFile.h --- // ConfigFile.h: interface for the CConfigFile class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_CONFIGFILE_H__F263D7F8_AAE8_424B_ACE1_05A20E187425__INCLUDED_) #define AFX_CONFIGFILE_H__F263D7F8_AAE8_424B_ACE1_05A20E187425__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "pugxml.h" using namespace std; using namespace pug; // Main config tag #define TAG_CONFIG "Config" // Config tags #define TAG_LANGUAGES "Languages" #define TAG_LANGUAGE "Language" // Language tags #define TAG_LANGUAGE_NAME "Name" #define TAG_LANGUAGE_SYNTAXFILE "SyntaxFile" #define TAG_LANGUAGE_AUTOCOMPFILE "AutoCompFile" #define TAG_LANGUAGE_EXTENSIONS "Extensions" // Language attributes #define ATT_LANGUAGE_NUMBER "number" // Defines for the Config paths and filename #define CONFIG_DIR "Config\\" #define DEFAULT_DIR "Default\\" #define SYNTAX_DIR "Syntax\\" // AnyEdit config file #define ANYEDIT_CONFIG_FILE "AnyEdit.cfg" class CConfigFile { protected: CString szFileName; xml_parser xparser; public: CConfigFile(); virtual ~CConfigFile(); // Set the Filename of the config file to parse. void SetFilename( CString lszFileName ); // Parse the config file. int Parse(); // Save the config file, including changes BOOL Save(); // Get the number of languages int GetLanguageCount(); // Get the name of the language with number iNumber. CString GetLanguageName( int iNumber ); // Get the syntaxfile name of the language with number iNumber. CString GetLanguageSyntaxFileName( int iNumber ); // Get the auto completion filename of the language with number iNumber. CString GetLanguageAutoCompFileName( int iNumber ); // Get the extensions string of languge with number iNumber. CString GetLanguageExtensions( int iNumber ); }; #endif // !defined(AFX_CONFIGFILE_H__F263D7F8_AAE8_424B_ACE1_05A20E187425__INCLUDED_) --- NEW FILE: SyntaxFile.cpp --- // SyntaxFile.cpp: implementation of the CSyntaxFile class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" //#include "anyedit.h" #include "SyntaxFile.h" #include <iostream> #include <fstream> #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif int CompareCString( CString s1, CString s2 ) { return s1.Compare( s2 ); } ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSyntaxFile::CSyntaxFile() { int iCount; szFileName = ""; // Set the string compare functions for the CSortedArray's with keywords. for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) { Keywords[iCount].SetCompareFunction( CompareCString ); } } CSyntaxFile::~CSyntaxFile() { } // Function to actually parse the synfile and the ability to check // if all goes well. BOOL CSyntaxFile::Parse() { int iCount; int iWordCount; char number[4]; xml_node tnode; if( szFileName.IsEmpty() ) return false; if( !xparser.parse_file( szFileName ) ) return false; // Read the keyword sets for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) { sprintf( number, "%i", iCount ); tnode = xparser.document().first_element_by_attribute( TAG_KEYWORDS, ATT_KEYWORDS_SET, number );//(LPCTSTR)CString().Format( "%i", iCount ) ); if( tnode.empty() ) continue; for( iWordCount = 0; iWordCount < tnode.children(); ++ iWordCount ) { if( CString( tnode.child( iWordCount ).name() ) == TAG_KEYWORDS_WORD && tnode.child( iWordCount ).children() ) { Keywords[iCount].Add( CString( tnode.child( iWordCount ).child(0).value() ) ); } } } return true; } void CSyntaxFile::SetFilename( CString lszFileName ) { szFileName = lszFileName; } // Gets a String with all keywords out of iSet separated by cSep CString CSyntaxFile::GetDelimitedKeywordSet( int iSet, char cSep ) { int iCount; CString szDelimited; if( iSet < 0 || iSet >= KEYWORDSET_MAX ) return ""; if( 0 == Keywords[iSet].GetSize() ) return ""; for( iCount = 0; iCount < Keywords[iSet].GetSize(); ++ iCount ) { if( 0 != iCount ) { szDelimited += cSep; szDelimited += Keywords[iSet][iCount]; } else { szDelimited = Keywords[iSet][iCount]; } } return szDelimited; } // Gets a String with all keywords out of all sets separated by cSep CString CSyntaxFile::GetDelimitedKeywords( char cSep ) { int iCount; CString szDelimited; CSortedArray<CString, CString> AllKeywords; AllKeywords.SetCompareFunction( CompareCString ); for( iCount = 0; iCount < KEYWORDSET_MAX; ++ iCount ) { if( Keywords[iCount].GetSize() ) { AllKeywords.Append( Keywords[iCount] ); } } AllKeywords.Sort(); for( iCount = 0; iCount < AllKeywords.GetSize(); ++ iCount ) { if( 0 != iCount ) { szDelimited += cSep; szDelimited += AllKeywords[iCount]; } else { szDelimited = AllKeywords[iCount]; } } return szDelimited; } void CSyntaxFile::Save() { filebuf fb; xml_node xnode; fb.open( szFileName, ios::out ); ostream os(&fb); xnode = xparser.document(); if( xnode.empty() ) return; xnode.outer_xml( os ); fb.close(); } int CSyntaxFile::GetLexerNumber() { CString name; xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_LEXER ); if( xnode.empty() ) return -1; xnode = xnode.first_element_by_name( TAG_LEXER_NAME ); if( xnode.empty() && !xnode.children() ) return -1; name = xnode.child(0).value(); if( name == "SCLEX_CONTAINER" ) return SCLEX_CONTAINER; if( name == "SCLEX_NULL" ) return SCLEX_NULL; if( name == "SCLEX_PYTHON" ) return SCLEX_PYTHON; if( name == "SCLEX_CPP" ) return SCLEX_CPP; if( name == "SCLEX_HTML" ) return SCLEX_HTML; if( name == "SCLEX_XML" ) return SCLEX_XML; if( name == "SCLEX_PERL" ) return SCLEX_PERL; if( name == "SCLEX_SQL" ) return SCLEX_SQL; if( name == "SCLEX_VB" ) return SCLEX_VB; if( name == "SCLEX_PROPERTIES" ) return SCLEX_PROPERTIES; if( name == "SCLEX_ERRORLIST" ) return SCLEX_ERRORLIST; if( name == "SCLEX_MAKEFILE" ) return SCLEX_MAKEFILE; if( name == "SCLEX_XCODE" ) return SCLEX_XCODE; if( name == "SCLEX_LATEX" ) return SCLEX_LATEX; if( name == "SCLEX_LUA" ) return SCLEX_LUA; if( name == "SCLEX_DIFF" ) return SCLEX_DIFF; if( name == "SCLEX_CONF" ) return SCLEX_CONF; if( name == "SCLEX_PASCAL" ) return SCLEX_PASCAL; if( name == "SCLEX_AVE" ) return SCLEX_AVE; if( name == "SCLEX_ADA" ) return SCLEX_ADA; if( name == "SCLEX_LISP" ) return SCLEX_LISP; if( name == "SCLEX_RUBY" ) return SCLEX_RUBY; if( name == "SCLEX_EIFFEL" ) return SCLEX_EIFFEL; if( name == "SCLEX_EIFFELKW" ) return SCLEX_EIFFELKW; if( name == "SCLEX_TCL" ) return SCLEX_TCL; if( name == "SCLEX_NNCRONTAB" ) return SCLEX_NNCRONTAB; if( name == "SCLEX_BULLANT" ) return SCLEX_BULLANT; if( name == "SCLEX_VBSCRIPT" ) return SCLEX_VBSCRIPT; if( name == "SCLEX_ASP" ) return SCLEX_ASP; if( name == "SCLEX_PHP" ) return SCLEX_PHP; if( name == "SCLEX_BAAN" ) return SCLEX_BAAN; if( name == "SCLEX_MATLAB" ) return SCLEX_MATLAB; if( name == "SCLEX_SCRIPTOL" ) return SCLEX_SCRIPTOL; if( name == "SCLEX_ASM" ) return SCLEX_ASM; if( name == "SCLEX_CPPNOCASE" ) return SCLEX_CPPNOCASE; if( name == "SCLEX_FORTRAN" ) return SCLEX_FORTRAN; if( name == "SCLEX_F77" ) return SCLEX_F77; if( name == "SCLEX_CSS" ) return SCLEX_CSS; if( name == "SCLEX_POV" ) return SCLEX_POV; if( name == "SCLEX_LOUT" ) return SCLEX_LOUT; if( name == "SCLEX_ESCRIPT" ) return SCLEX_ESCRIPT; if( name == "SCLEX_PS" ) return SCLEX_PS; if( name == "SCLEX_NSIS" ) return SCLEX_NSIS; if( name == "SCLEX_MMIXAL" ) return SCLEX_MMIXAL; if( name == "SCLEX_CLW" ) return SCLEX_CLW; if( name == "SCLEX_CLWNOCASE" ) return SCLEX_CLWNOCASE; if( name == "SCLEX_LOT" ) return SCLEX_LOT; if( name == "SCLEX_YAML" ) return SCLEX_YAML; if( name == "SCLEX_TEX" ) return SCLEX_TEX; if( name == "SCLEX_METAPOST" ) return SCLEX_METAPOST; if( name == "SCLEX_POWERBASIC" ) return SCLEX_POWERBASIC; if( name == "SCLEX_FORTH" ) return SCLEX_FORTH; return -1; } int CSyntaxFile::GetLexerProperties( CMapStringToString& msts ) { int iCount; int iNrOfProperties; CString node_name; CString property_name; CString property_value; xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_LEXER ); if( xnode.empty() ) return 0; iNrOfProperties = 0; for( iCount = 0; iCount < xnode.children(); ++ iCount ) { node_name = xnode.child( iCount ).name(); if( node_name == TAG_LEXER_PROPERTY ) { if( xnode.child( iCount ).attributes() && xnode.child( iCount ).children() ) { xml_node::xml_attribute_iterator xattit( xnode.child( iCount ) ); property_name = xattit->value(); property_value = xnode.child( iCount ).child( 0 ).value(); msts.SetAt( property_name, property_value ); ++ iNrOfProperties; } } } return iNrOfProperties; } // Returns if SyntaxHighlighting is on. BOOL CSyntaxFile::GetSyntaxHighlighting() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_SYNTAXHIGHLIGHTING ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } // Sets the SyntaxHighlighting to true or false. BOOL CSyntaxFile::SetSyntaxHighlighting( BOOL bSyntaxHighlighting ) { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_SYNTAXHIGHLIGHTING ); if( xnode.empty() && !xnode.children() ) return false; return xnode.child(0).value( bSyntaxHighlighting ? "1" : "0" ); } // Returns if WordWrap is on. BOOL CSyntaxFile::GetWordWrap() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_WORDWRAP ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } // Sets WordWrap to true or false. BOOL CSyntaxFile::SetWordWrap( BOOL bWordWrap ) { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_WORDWRAP ); if( xnode.empty() && !xnode.children() ) return false; return xnode.child(0).value( bWordWrap ? "1" : "0" ); } // Get the tab/indentation width int CSyntaxFile::GetTabWidth() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_TABWIDTH ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ); } // Sets the tab/indentation width to iTabWidth. BOOL CSyntaxFile::SetTabWidth( int iTabWidth ) { xml_node xnode; char szTabWidth[5]; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_TABWIDTH ); if( xnode.empty() && !xnode.children() ) return false; sprintf( szTabWidth, "%i", iTabWidth ); return xnode.child(0).value( szTabWidth ); } // Returns if we want to use tabs or space (true is tabs!) BOOL CSyntaxFile::GetUseTabs() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_USETABS ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } // Sets the UseTabs(OrSpaces) to true or false. BOOL CSyntaxFile::SetUseTabs( BOOL bUseTabs ) { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_USETABS ); if( xnode.empty() && !xnode.children() ) return false; return xnode.child(0).value( bUseTabs ? "1" : "0" ); } // Returns if the RightEdge is on. int CSyntaxFile::GetRightEdge() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_RIGHTEDGE ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ); } // Set the RightEdge to true or false. BOOL CSyntaxFile::SetRightEdge( BOOL bRightEdge ) { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_RIGHTEDGE ); if( xnode.empty() && !xnode.children() ) return false; return xnode.child(0).value( bRightEdge ? "1" : "0" ); } // Gets the RightEdgeColumn int CSyntaxFile::GetRightEdgeColumn() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_RIGHTEDGECOLUMN ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ); } // Sets the RightEdgeColumn to iREColumn. BOOL CSyntaxFile::SetRightEdgeColumn( int iREColumn ) { xml_node xnode; char szREColumn[5]; xnode = xparser.document().first_element_by_name( TAG_VIEW ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_VIEW_RIGHTEDGECOLUMN ); if( xnode.empty() && !xnode.children() ) return false; sprintf( szREColumn, "%i", iREColumn ); return xnode.child(0).value( szREColumn ); } // Returns if the LineNumber margin is on. BOOL CSyntaxFile::GetMarginLineNumber() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_MARGINS ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_MARGINS_LINENUMBERS ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } // Sets the LineNumber margin to true or false. BOOL CSyntaxFile::SetMarginLineNumber( BOOL bLineNumbers ) { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_MARGINS ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_MARGINS_LINENUMBERS ); if( xnode.empty() && !xnode.children() ) return false; return xnode.child(0).value( bLineNumbers ? "1" : "0" ); } // Returns if the Bookmark margin is on. BOOL CSyntaxFile::GetMarginBookmark() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_MARGINS ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_MARGINS_BOOKMARK ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } // Sets the Bookmark margin to true or false. BOOL CSyntaxFile::SetMarginBookmark( BOOL bBookmark ) { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_MARGINS ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_MARGINS_BOOKMARK ); if( xnode.empty() && !xnode.children() ) return false; return xnode.child(0).value( bBookmark? "1" : "0" ); } // Returns if the Fold margin is on. BOOL CSyntaxFile::GetMarginFold() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_MARGINS ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_MARGINS_FOLD ); if( xnode.empty() && !xnode.children() ) return false; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } // Sets the Fold margin to true of false. BOOL CSyntaxFile::SetMarginFold( BOOL bFold ) { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_MARGINS ); if( xnode.empty() && !xnode.children() ) return false; xnode = xnode.first_element_by_name( TAG_MARGINS_FOLD ); if( xnode.empty() && !xnode.children() ) return false; return xnode.child(0).value( bFold ? "1" : "0" ); } int CSyntaxFile::GetStyleBits() { xml_node xnode; xnode = xparser.document().first_element_by_name( TAG_STYLEBITS ); if( xnode.empty() && !xnode.children() ) return -1; return atoi( xnode.child(0).value() ); } CString CSyntaxFile::GetStyleName( int iStyle ) { char number[4]; xml_node xnode; sprintf( number, "%i", iStyle ); xnode = xparser.document().first_element_by_attribute( TAG_STYLE, ATT_STYLE_NUMBER, number ); if( xnode.empty() ) return ""; xnode = xnode.first_element_by_name( TAG_STYLE_NAME ); if( xnode.empty() && !xnode.children() ) return ""; return xnode.child(0).value(); } xml_node CSyntaxFile::GetStyleFontNode( int iStyle ) { char number[4]; xml_node xnode; sprintf( number, "%i", iStyle ); xnode = xparser.document().first_element_by_attribute( TAG_STYLE, ATT_STYLE_NUMBER, number ); if( !xnode.empty() ) { xnode = xnode.first_element_by_name( TAG_STYLE_FONT ); } return xnode; } CString CSyntaxFile::GetStyleFontName( int iStyle ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return ""; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_NAME ); if( xnode.empty() ) return ""; if( !xnode.children() ) return ""; return xnode.child(0).value(); } BOOL CSyntaxFile::SetStyleFontName( int iStyle, TCHAR* FontName ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_NAME ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; return xnode.child(0).value( FontName ); } int CSyntaxFile::GetStyleFontSize( int iStyle ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return -1; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_SIZE ); if( xnode.empty() ) return -1; if( !xnode.children() ) return -1; return atoi( xnode.child(0).value() ); } BOOL CSyntaxFile::SetStyleFontSize( int iStyle, int iValue ) { char szValue[4]; xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_SIZE ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; sprintf( szValue, "%i", iValue ); return xnode.child(0).value( szValue ); } BOOL CSyntaxFile::GetStyleFontBold( int iStyle ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_BOLD ); if( xnode.empty() && !xnode.children() ) return FALSE; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } BOOL CSyntaxFile::SetStyleFontBold( int iStyle, BOOL bValue ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_BOLD ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; return xnode.child(0).value( bValue ? "1" : "0"); } BOOL CSyntaxFile::GetStyleFontItalic( int iStyle ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_ITALIC ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } BOOL CSyntaxFile::SetStyleFontItalic( int iStyle, BOOL bValue ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_ITALIC ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; return xnode.child(0).value( bValue ? "1" : "0"); } BOOL CSyntaxFile::GetStyleFontUnderline( int iStyle ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_UNDERLINE ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; return atoi( xnode.child(0).value() ) ? TRUE : FALSE; } BOOL CSyntaxFile::SetStyleFontUnderline( int iStyle, BOOL bValue ) { xml_node xnode; xnode = GetStyleFontNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_FONT_UNDERLINE ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; return xnode.child(0).value( bValue ? "1" : "0"); } int CSyntaxFile::RGBHexValueToColorInt( const TCHAR* value ) { int iResult; int iCount; iResult = 0; for( iCount = 5; iCount >= 0; -- iCount ) { iResult <<= 4; switch( value[iCount % 2 ? iCount - 1 : iCount + 1] ) { case 'a': case 'A': iResult += 10; break; case 'b': case 'B': iResult += 11; break; case 'c': case 'C': iResult += 12; break; case 'd': case 'D': iResult += 13; break; case 'e': case 'E': iResult += 14; break; case 'f': case 'F': iResult += 15; break; case '9': ++ iResult; case '8': ++ iResult; case '7': ++ iResult; case '6': ++ iResult; case '5': ++ iResult; case '4': ++ iResult; case '3': ++ iResult; case '2': ++ iResult; case '1': ++ iResult; } } return( iResult ); } void CSyntaxFile::ColorIntValueToRGBHex( int iValue, char *szValue ) { int iCount; szValue[6] = '\0'; for( iCount = 0; iCount < 6; ++ iCount ) { switch( iValue & 0xf ) { case 0: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '0'; break; case 1: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '1'; break; case 2: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '2'; break; case 3: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '3'; break; case 4: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '4'; break; case 5: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '5'; break; case 6: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '6'; break; case 7: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '7'; break; case 8: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '8'; break; case 9: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = '9'; break; case 10: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = 'A'; break; case 11: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = 'B'; break; case 12: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = 'C'; break; case 13: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = 'D'; break; case 14: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = 'E'; break; case 15: szValue[iCount % 2 ? iCount - 1 : iCount + 1] = 'F'; break; } iValue >>= 4; } } xml_node CSyntaxFile::GetStyleColorNode( int iStyle ) { char numBer[4]; xml_node xnode; sprintf( numBer, "%i", iStyle ); xnode = xparser.document().first_element_by_attribute( "Style", ATT_STYLE_NUMBER, numBer ); if( !xnode.empty() ) { xnode = xnode.first_element_by_name( TAG_STYLE_COLOR ); } return xnode; } int CSyntaxFile::GetStyleColorForeground( int iStyle ) { xml_node xnode; xnode = GetStyleColorNode( iStyle ); if( xnode.empty() ) return -1; xnode = xnode.first_element_by_name( TAG_STYLE_COLOR_FOREGROUND ); if( xnode.empty() ) return -1; if( !xnode.children() ) return -1; return RGBHexValueToColorInt( xnode.child(0).value() ); } int CSyntaxFile::SetStyleColorForeground( int iStyle, int iColor ) { char szColor[9]; xml_node xnode; xnode = GetStyleColorNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_COLOR_FOREGROUND ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; ColorIntValueToRGBHex( iColor, szColor ); szColor[8] = '\0'; return xnode.child(0).value( &szColor[2] ); } int CSyntaxFile::GetStyleColorBackground( int iStyle ) { xml_node xnode; xnode = GetStyleColorNode( iStyle ); if( xnode.empty() ) return -1; xnode = xnode.first_element_by_name( TAG_STYLE_COLOR_BACKGROUND ); if( xnode.empty() ) return -1; if( !xnode.children() ) return -1; return RGBHexValueToColorInt( xnode.child(0).value() ); } int CSyntaxFile::SetStyleColorBackground( int iStyle, int iColor ) { char szColor[9]; xml_node xnode; xnode = GetStyleColorNode( iStyle ); if( xnode.empty() ) return FALSE; xnode = xnode.first_element_by_name( TAG_STYLE_COLOR_BACKGROUND ); if( xnode.empty() ) return FALSE; if( !xnode.children() ) return FALSE; ColorIntValueToRGBHex( iColor, szColor ); szColor[8] = '\0'; return xnode.child(0).value( &szColor[2] ); } --- NEW FILE: SyntaxFile.h --- // SyntaxFile.h: interface for the CSyntaxFile class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_SYNTAXFILE_H__E5CB9170_6EA5_4355_98E6_A883A9E8D79D__INCLUDED_) #define AFX_SYNTAXFILE_H__E5CB9170_6EA5_4355_98E6_A883A9E8D79D__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // STYLE_MAX #include "Scintilla.h" #include "SciLexer.h" #include "SortedArray.h" #include "pugxml.h" using namespace std; using namespace pug; // Main syntax tag #define TAG_SYNTAX "Syntax" // Syntax sub tags #define TAG_LEXER "Lexer" #define TAG_KEYWORDS "Keywords" #define TAG_VIEW "View" #define TAG_MARGINS "Margins" #define TAG_STYLE "Style" #define TAG_STYLEBITS "StyleBits" // Lexer sub tags #define TAG_LEXER_NAME "Name" #define TAG_LEXER_PROPERTY "Property" // Lexer sub attributes #define ATT_LEXER_PROPERTY_NAME "name" // Keywords sub tags #define TAG_KEYWORDS_WORD "Word" // Keywords attributes #define ATT_KEYWORDS_SET "set" // View sub tags #define TAG_VIEW_SYNTAXHIGHLIGHTING "SyntaxHighlighting" #define TAG_VIEW_WORDWRAP "WordWrap" #define TAG_VIEW_TABWIDTH "TabWidth" #define TAG_VIEW_USETABS "UseTabs" #define TAG_VIEW_RIGHTEDGE "RightEdge" #define TAG_VIEW_RIGHTEDGECOLUMN "RightEdgeColumn" // Margin sub tags #define TAG_MARGINS_LINENUMBERS "LineNumbers" #define TAG_MARGINS_BOOKMARK "BookMark" #define TAG_MARGINS_FOLD "Fold" // Style sub tags #define TAG_STYLE_NAME "Name" #define TAG_STYLE_FONT "Font" #define TAG_STYLE_COLOR "Color" // Style attributes #define ATT_STYLE_NUMBER "number" // Style Font sub tags #define TAG_STYLE_FONT_NAME "Name" #define TAG_STYLE_FONT_SIZE "Size" #define TAG_STYLE_FONT_BOLD "Bold" #define TAG_STYLE_FONT_ITALIC "Italic" #define TAG_STYLE_FONT_UNDERLINE "Underline" // Style Color sub tags #define TAG_STYLE_COLOR_FOREGROUND "Foreground" #define TAG_STYLE_COLOR_BACKGROUND "Background" class CSyntaxFile { protected: CString szFileName; xml_parser xparser; CSortedArray<CString, CString> Keywords[KEYWORDSET_MAX]; // Converts a char array with hex chars to an int. int RGBHexValueToColorInt( const TCHAR* value ); // Converts an int into hex chars and puts them in szValue. Don't forget to reserve memory! void ColorIntValueToRGBHex( int iValue, char* szValue ); // Get the Font node of Style iStyle. Function is used by GetStyleFont* and SetStyleColor* xml_node GetStyleFontNode( int iStyle ); // Get the Color node of Style iStyle. Function is used by GetStyleColor* and SetStyleColor* xml_node GetStyleColorNode( int iStyle ); public: CSyntaxFile(); virtual ~CSyntaxFile(); // Set the filename of the syntax file to parse or save. void SetFilename( CString szFileName ); // Function to actually parse the synfile and the ability to check // if all goes well. BOOL Parse(); // Save the current values back in the synfile. void Save(); // Get the lexer number from, it changes the name in the syn-file to a number int GetLexerNumber(); // Get the properties to set on the lexer int GetLexerProperties( CMapStringToString& msts ); // Gets a String with all keywords out of iSet separated by cSep CString GetDelimitedKeywordSet( int iSet, char cSep = ' ' ); // Gets a String with all keywords out of all sets separated by cSep CString GetDelimitedKeywords( char cSep = ' ' ); // Returns if SyntaxHighlighting is on. BOOL GetSyntaxHighlighting(); // Sets the SyntaxHighlighting to true or false. BOOL SetSyntaxHighlighting( BOOL bSyntaxHighlighting ); // Returns if WordWrap is on. BOOL GetWordWrap(); // Sets WordWrap to true or false. BOOL SetWordWrap( BOOL bWordWrap ); // Get the tab/indentation width int GetTabWidth(); // Sets the tab/indentation width to iTabWidth. BOOL SetTabWidth( int iTabWidth ); // Returns if we want to use tabs or space (true is tabs!) BOOL GetUseTabs(); // Sets the UseTabs(OrSpaces) to true or false. BOOL SetUseTabs( BOOL bUseTabs ); // Get the RightEdge type. int GetRightEdge(); // Set the RightEdge to true or false. BOOL SetRightEdge( BOOL bRightEdge ); // Gets the RightEdgeColumn int GetRightEdgeColumn(); // Sets the RightEdgeColumn to iREColumn. BOOL SetRightEdgeColumn( int iREColumn ); // Returns if the LineNumber margin is on. BOOL GetMarginLineNumber(); // Sets the LineNumber margin to true or false. BOOL SetMarginLineNumber( BOOL bLineNumbers ); // Returns if the Bookmark margin is on. BOOL GetMarginBookmark(); // Sets the Bookmark margin to true or false. BOOL SetMarginBookmark( BOOL bBookmark ); // Returns if the Fold margin is on. BOOL GetMarginFold(); // Sets the Fold margin to true of false. BOOL SetMarginFold( BOOL bFold ); // Gets the Number of Stylebits int GetStyleBits(); // Gets the Name of iStyle. CString GetStyleName( int iStyle ); // Gets the FontName of iStyle. CString GetStyleFontName( int iStyle ); // Sets the FontName of iStyle. BOOL SetStyleFontName( int iStyle, TCHAR* FontName ); // Gets the FontSize of iStyle font. int GetStyleFontSize( int iStyle ); // Sets the FontSize of iStyle font. BOOL SetStyleFontSize( int iStyle, int iValue ); // Get the FontBold attribute of iStyle font. BOOL GetStyleFontBold( int iStyle ); // Set the FontBold attribute of iStyle font. BOOL SetStyleFontBold( int iStyle, BOOL bValue ); // Get the FontItalic attribute of iStyle font. BOOL GetStyleFontItalic( int iStyle ); // Set the FontItalic attribute of iStyle font. BOOL SetStyleFontItalic( int iStyle, BOOL bValue ); // Get the FontUnderline attribute of iStyle font. BOOL GetStyleFontUnderline( int iStyle ); // Set the FontUnderline attribute of iStyle font. BOOL SetStyleFontUnderline( int iStyle, BOOL bValue ); // Get the Foreground Color of iStyle. int GetStyleColorForeground( int iStyle ); // Set the Foreground Color of iStyle. BOOL SetStyleColorForeground( int iStyle, int iColor ); // Get the Background Color of iStyle. int GetStyleColorBackground( int iStyle ); // Set the Background Color of iStyle. BOOL SetStyleColorBackground( int iStyle, int iColor ); }; #endif // !defined(AFX_SYNTAXFILE_H__E5CB9170_6EA5_4355_98E6_A883A9E8D79D__INCLUDED_) Index: AnyEdit.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** AnyEdit.cpp 11 Dec 2003 04:15:21 -0000 1.38 --- AnyEdit.cpp 12 Dec 2003 11:00:04 -0000 1.39 *************** *** 1,23 **** /********************************************************************* Copyright (C) 2002 DeepSoft - M.Deepak ! This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. ! Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: [...1328 lines suppressed...] ! { ! // Save the default to the users syntax file. ! pSyntaxFile->SetFilename( szFileName ); ! pSyntaxFile->Save(); ! } ! ! } ! // Add the parsed object to the Syntax file map. ! mapSyntaxFiles.SetAt( iCount, pSyntaxFile ); ! } ! } ! ! ! // Find the SyntaxFile object by it's language number ! CSyntaxFile* CAnyEditApp::GetSyntaxFile( int iLanguage ) ! { ! CSyntaxFile* pSyntaxFile; ! mapSyntaxFiles.Lookup( iLanguage, pSyntaxFile ); ! return pSyntaxFile; } Index: AnyEdit.dsp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.dsp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** AnyEdit.dsp 7 Dec 2003 17:06:10 -0000 1.28 --- AnyEdit.dsp 12 Dec 2003 11:00:04 -0000 1.29 *************** *** 372,375 **** --- 372,379 ---- # Begin Source File + SOURCE=.\ConfigFile.cpp + # End Source File + # Begin Source File + SOURCE=.\DumpDialog.cpp # End Source File *************** *** 414,417 **** --- 418,425 ---- SOURCE=.\SeException.cpp # End Source File + # Begin Source File + + SOURCE=.\SyntaxFile.cpp + # End Source File # End Group # Begin Group "Header Files" *************** *** 1124,1127 **** --- 1132,1139 ---- # Begin Source File + SOURCE=.\ConfigFile.h + # End Source File + # Begin Source File + SOURCE=.\DumpDialog.h # End Source File *************** *** 1145,1148 **** --- 1157,1164 ---- SOURCE=.\SeException.h + # End Source File + # Begin Source File + + SOURCE=.\SyntaxFile.h # End Source File # End Group Index: AnyEdit.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.h,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** AnyEdit.h 11 Dec 2003 04:15:21 -0000 1.32 --- AnyEdit.h 12 Dec 2003 11:00:04 -0000 1.33 *************** *** 18,22 **** #include "resource.h" // main symbols ! #define REGISTRY_ROOT _T("SOFTWARE\\DeepSoft\\AnyEdit\\"); ///////////////////////////////////////////////////////////////////////////// --- 18,22 ---- #include "resource.h" // main symbols ! #define REGISTRY_ROOT _T("SOFTWARE\\DeepSoft\\AnyEdit\\"); ///////////////////////////////////////////////////////////////////////////// *************** *** 34,45 **** #include "AEPlugin.h" #include "Plugin.h" //Save final position struct DocumentPosition { ! CString file_path; ! long initial_pos; ! long final_pos; ! int visible_line; }; --- 34,47 ---- #include "AEPlugin.h" #include "Plugin.h" + #include "ConfigFile.h" + #include "SyntaxFile.h" //Save final position struct DocumentPosition { ! CString file_path; ! long initial_pos; ! long final_pos; ! int visible_line; }; *************** *** 65,73 **** CObject * LoadLanguage(LPCSTR langpos); CString SetScintillaLanguage(LPCSTR ext, CScintilla *scintilla); ! CLanguage * GetLanguage(LPCSTR ext); void LoadLanguageExtensions(); ! void ApplyOtherDefaults(CScintilla * scintilla); void ResetAllProperties(); ! void SetDefaults(CScintilla * scintilla); CBCGToolbarComboBoxButton * GetFindCombo(); void ReturnItemsForCodeList(CStringArray &arr); --- 67,75 ---- CObject * LoadLanguage(LPCSTR langpos); CString SetScintillaLanguage(LPCSTR ext, CScintilla *scintilla); ! CLanguage * GetLanguage(LPCSTR ext); void LoadLanguageExtensions(); ! // void ApplyOtherDefaults(CScintilla * scintilla); void ResetAllProperties(); ! // void SetDefaults(CScintilla * scintilla); CBCGToolbarComboBoxButton * GetFindCombo(); void ReturnItemsForCodeList(CStringArray &arr); *************** *** 83,87 **** void SetAppPath(LPCSTR appPath); LPCSTR GetAppPath(); ! BOOL m_bTabFlatBorders; BOOL OnViewDoubleClick (int iViewId); BOOL ShowPopupMenu (UINT uiMenuResId, const CPoint& point, CWnd* pWnd); --- 85,89 ---- void SetAppPath(LPCSTR appPath); LPCSTR GetAppPath(); ! BOOL m_bTabFlatBorders; BOOL OnViewDoubleClick (int iViewId); BOOL ShowPopupMenu (UINT uiMenuResId, const CPoint& point, CWnd* pWnd); *************** *** 106,118 **** BOOL LockTagList(); void UnlockTagList(); ! void LoadPlugins(); ! void UnloadPlugins(); ! void PluginMenuClicked(UINT id); ! BOOL GetDocumentPosition(LPCSTR filepath,long &startpos,long &endpos,int &visline); ! void SetDocumentPosition(LPCSTR filepath, long startpos, long endpos, int visline); ! void SetModification(BOOL modval) ! { ! check_modification = modval; ! } BOOL CheckModification() { --- 108,120 ---- BOOL LockTagList(); void UnlockTagList(); ! void LoadPlugins(); ! void UnloadPlugins(); ! void PluginMenuClicked(UINT id); ! BOOL GetDocumentPosition(LPCSTR filepath,long &startpos,long &endpos,int &visline); ! void SetDocumentPosition(LPCSTR filepath, long startpos, long endpos, int visline); ! void SetModification(BOOL modval) ! { ! check_modification = modval; ! } BOOL CheckModification() { *************** *** 154,165 **** public: ! void ReloadACMP(); ! void ClearClassView(); ! CComboBox * findbox; CComboBox * funcbox; ! //For macro support ! MacroHolder * macroholder; ! BOOL isRecordingMacro; protected: --- 156,167 ---- public: ! void ReloadACMP(); ! void ClearClassView(); ! CComboBox * findbox; CComboBox * funcbox; ! //For macro support ! MacroHolder * macroholder; ! BOOL isRecordingMacro; protected: *************** *** 180,192 **** int lastsearchflags; BOOL lastsearchdirection; ! AEPlugin * pluginHead; ! CArray<DocumentPosition,DocumentPosition> m_docPos; ! CPlugin plugin; protected: ! void LoadDocumentPosition(); ! void SaveDocumentPosition(); void LoadGlobalSettings(); // Overrides // ClassWizard generated virtual function overrides --- 182,223 ---- int lastsearchflags; BOOL lastsearchdirection; ! AEPlugin * pluginHead; ! CArray<DocumentPosition,DocumentPosition> m_docPos; ! CPlugin plugin; ! ! // The main user config file for AnyEdit. ! CConfigFile ConfigFile; ! // Map of language number pointing to a CSytnaxFile object. ! CMap<int, int, CSyntaxFile*, CSyntaxFile*> mapSyntaxFiles; ! // Map of Extension strings pointing to a language number. ! CMapStringToString mapExtensions; ! // String with the name of the current user ! CString szUserName; protected: ! void LoadDocumentPosition(); ! void SaveDocumentPosition(); void LoadGlobalSettings(); + // Configuration functions + + // Read configuration information + BOOL ReadConfigFile(); + + // Get a reference to the config file. Used in the Preferences dialogs + CConfigFile* GetConfigFile(); + + // Fill the map with extensions and language numbers + void FillExtensionMap(); + public: + // Load all the configured syntax files. + void LoadSyntaxFiles(); + + // Get the SyntaxFile object by it's language number. + CSyntaxFile* GetSyntaxFile( int iLanguage ); + + // Get the LanguageNr of ext. + int GetLanguageNrFromExtension( CString szExtension ); + // Overrides // ClassWizard generated virtual function overrides *************** *** 207,224 **** afx_msg void OnFileNew(); afx_msg void OnFileOpenstartuppage(); ! afx_msg void OnToolsSavemacro(); ! afx_msg void OnUpdateToolsSavemacro(CCmdUI* pCmdUI); ! afx_msg void OnToolsLoadmacro(); ! afx_msg void OnUpdateToolsLoadmacro(CCmdUI* pCmdUI); ! //}}AFX_MSG DECLARE_MESSAGE_MAP() ! CBCGKeyboardManager m_KeyboardManager; ! CBCGMouseManager m_MouseManager; ! CBCGContextMenuManager m_ContextMenuManager; ! CScintillaDefaults m_sdefaults; ! ! //deepwashere ! } ; --- 238,252 ---- afx_msg void OnFileNew(); afx_msg void OnFileOpenstartuppage(); ! afx_msg void OnToolsSavemacro(); ! afx_msg void OnUpdateToolsSavemacro(CCmdUI* pCmdUI); ! afx_msg void OnToolsLoadmacro(); ! afx_msg void OnUpdateToolsLoadmacro(CCmdUI* pCmdUI); ! //}}AFX_MSG DECLARE_MESSAGE_MAP() ! CBCGKeyboardManager m_KeyboardManager; ! CBCGMouseManager m_MouseManager; ! CBCGContextMenuManager m_ContextMenuManager; ! CScintillaDefaults m_sdefaults; } ; Index: AnyEditDoc.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEditDoc.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AnyEditDoc.cpp 25 Nov 2003 15:05:56 -0000 1.13 --- AnyEditDoc.cpp 12 Dec 2003 11:00:04 -0000 1.14 *************** *** 32,42 **** CAnyEditDoc::CAnyEditDoc() { ! // TODO: add one-time construction code here ! m_pDocLang = NULL; ! } CAnyEditDoc::~CAnyEditDoc() ! {} BOOL CAnyEditDoc::OnNewDocument() --- 32,45 ---- CAnyEditDoc::CAnyEditDoc() { ! m_pDocLang = NULL; ! iLanguage = 0; // Use default if unknown ! bFirstTimeProperties = TRUE; ! bSyntaxHighlighting = TRUE; ! m_pScintilla = NULL; } CAnyEditDoc::~CAnyEditDoc() ! { ! } BOOL CAnyEditDoc::OnNewDocument() *************** *** 86,89 **** --- 89,111 ---- // CAnyEditDoc commands + CString CAnyEditDoc::GetFileNameExtension( LPCTSTR lpszPathName ) + { + int iStart; + int iEnd; + CString szFileName; + + // Extract extension + szFileName = lpszPathName; + iStart = 0; + iEnd = 0; + while( -1 != iEnd ) + { + iEnd = szFileName.Find( '.', iStart ); + if( -1 != iEnd ) iStart = iEnd + 1; + } + if( 0 == iStart ) return ""; + else return szFileName.Mid( iStart, szFileName.GetLength() - iStart ); + } + BOOL CAnyEditDoc::OnOpenDocument(LPCTSTR lpszPathName) { *************** *** 91,94 **** --- 113,122 ---- return FALSE; + // Set the language number from the extension + iLanguage = theApp.GetLanguageNrFromExtension( GetFileNameExtension( lpszPathName ) ); + + // Set the Scintilla properties + SetScintillaProperties(); + // Use scintilla to open the file [12/27/2001 13:51] m_pScintilla->OpenFile(lpszPathName); *************** *** 99,103 **** BOOL CAnyEditDoc::OnSaveDocument(LPCTSTR lpszPathName) { ! if(!this->IsModified()) return TRUE; BOOL saved = m_pScintilla->SaveFile(lpszPathName); if(saved) --- 127,131 ---- BOOL CAnyEditDoc::OnSaveDocument(LPCTSTR lpszPathName) { ! if(!this->IsModified()) return TRUE; BOOL saved = m_pScintilla->SaveFile(lpszPathName); if(saved) *************** *** 167,179 **** void CAnyEditDoc::ReloadDefaults() { ! theApp.SetDefaults(m_pScintilla); ! if(m_pScintilla) ! { ! if(m_pDocLang) ! { ! m_pDocLang->FillUpScintilla(m_pScintilla); ! } ! } ! theApp.ApplyOtherDefaults(m_pScintilla); } --- 195,209 ---- void CAnyEditDoc::ReloadDefaults() { ! /* theApp.SetDefaults(m_pScintilla); ! if(m_pScintilla) ! { ! if(m_pDocLang) ! { ! m_pDocLang->FillUpScintilla(m_pScintilla); ! } ! } ! theApp.ApplyOtherDefaults(m_pScintilla);*/ ! SetScintillaProperties(); ! m_pScintilla->Colourise( 0, -1 ); } *************** *** 219,245 **** void CAnyEditDoc::SetDocScintilla(CScintilla * m_pscin) { ! m_pScintilla = m_pscin; } void CAnyEditDoc::SetDocLanguage(CLanguage * m_plang) { ! m_pDocLang = m_plang; } void CAnyEditDoc::GetListWords(CString &result) { ! if(m_pDocLang==NULL) return; ! m_pDocLang->GetListWords(result); } BOOL CAnyEditDoc::GetAcmpValueToArray(LPCSTR val, CStringArray &arr) { ! if(m_pDocLang==NULL) return FALSE; ! return m_pDocLang->GetValueToArray(val,arr); } BOOL CAnyEditDoc::GetAcmpWordList(CStringArray &arr) { ! if(m_pDocLang==NULL) return FALSE; ! return m_pDocLang->GetAcmpWordList(arr); } --- 249,406 ---- void CAnyEditDoc::SetDocScintilla(CScintilla * m_pscin) { ! m_pScintilla = m_pscin; } void CAnyEditDoc::SetDocLanguage(CLanguage * m_plang) { ! m_pDocLang = m_plang; } void CAnyEditDoc::GetListWords(CString &result) { ! if(m_pDocLang==NULL) return; ! m_pDocLang->GetListWords(result); } BOOL CAnyEditDoc::GetAcmpValueToArray(LPCSTR val, CStringArray &arr) { ! if(m_pDocLang==NULL) return FALSE; ! return m_pDocLang->GetValueToArray(val,arr); } BOOL CAnyEditDoc::GetAcmpWordList(CStringArray &arr) { ! if(m_pDocLang==NULL) return FALSE; ! return m_pDocLang->GetAcmpWordList(arr); ! } ! ! void CAnyEditDoc::SetLanguageNr( int iLanguageNr ) ! { ! iLanguage = iLanguageNr; ! } ! ! void CAnyEditDoc::SetScintillaProperties() ! { ! int iCount; ! CSyntaxFile* pSyntaxFile; ! CString szTemp; ! int iTemp; ! CMapStringToString mapLexerProps; ! POSITION pos; ! ! pSyntaxFile = theApp.GetSyntaxFile( iLanguage ); ! if( NULL == pSyntaxFile ) return; ! ! // Clear the Scintilla object ! m_pScintilla->StyleClearAll(); ! ! // Do some default AnyEdit settings ! m_pScintilla->StyleSetEOLFilled( STYLE_DEFAULT, true ); ! m_pScintilla->UsePopUp( false ); ! ! if( bFirstTimeProperties ) ! { ! // We only want to do these settings the first time, on a change ! // of Preferences, we don't want the mess up the users menu ! // overridden settings. ! ! bSyntaxHighlighting = pSyntaxFile->GetSyntaxHighlighting(); ! m_pScintilla->SetWrapMode( pSyntaxFile->GetWordWrap() ? 1 : 0 ); ! m_pScintilla->SetUseTabs( pSyntaxFile->GetUseTabs() ); ! m_pScintilla->SetEdgeMode( pSyntaxFile->GetRightEdge() ); ! m_pScintilla->SetEdgeColour( RGB( 255, 255, 255 ) ); ! ! // These may need to be settable ! m_pScintilla->SetSelFore( true, RGB( 255, 255, 255 ) ); ! m_pScintilla->SetSelBack( true, RGB( 115, 113, 189 ) ); ! m_pScintilla->SetCaretLineBack( RGB( 255, 255, 238 ) ); ! m_pScintilla->SetCaretWidth( 1 ); ! ! // Set margins. ! // LineNumbers ! m_pScintilla->SetMarginWidthN( LINENUMBER_MARGIN_ID, pSyntaxFile->GetMarginLineNumber() ? LINENUMBER_MARGIN_SIZE : 0 ); ! m_pScintilla->SetMarginTypeN( LINENUMBER_MARGIN_ID, SC_MARGIN_NUMBER ); ! // Bookmark ! m_pScintilla->SetMarginWidthN( BOOKMARK_MARGIN_ID, pSyntaxFile->GetMarginBookmark() ? BOOKMARK_MARGIN_SIZE : 0 ); ! m_pScintilla->SetMarginTypeN( BOOKMARK_MARGIN_ID, SC_MARGIN_SYMBOL ); ! m_pScintilla->SetMarginMaskN( BOOKMARK_MARGIN_ID, ~SC_MASK_FOLDERS ); ! // Fold ! m_pScintilla->SetMarginWidthN( FOLD_MARGIN_ID, pSyntaxFile->GetMarginFold() ? FOLD_MARGIN_SIZE : 0 ); ! m_pScintilla->SetMarginTypeN( FOLD_MARGIN_ID, SC_MARGIN_SYMBOL ); ! m_pScintilla->SetMarginMaskN( FOLD_MARGIN_ID, SC_MASK_FOLDERS ); ! m_pScintilla->SetMarginSensitiveN( FOLD_MARGIN_ID, TRUE ); ! m_pScintilla->SetFoldingMargins( efsVSNet ); ! ! // Taken from AnyEditView::Init, need to be worked out. ! m_pScintilla->SetIndentationGuides(TRUE); ! m_pScintilla->IndicSetStyle(0,INDIC_SQUIGGLE); ! m_pScintilla->IndicSetStyle(1,INDIC_TT); ! m_pScintilla->IndicSetStyle(2,INDIC_DIAGONAL); ! m_pScintilla->autoindent = TRUE; ! m_pScintilla->DefineMarker(SC_MARK_ARROW,SC_MARK_ARROW,RGB(0,0,255),RGB(231,231,255)); ! m_pScintilla->DefineMarker(SC_MARK_SHORTARROW,SC_MARK_SHORTARROW,RGB(107,27,18),RGB(251,252,226)); ! ! } ! m_pScintilla->SetTabWidth( pSyntaxFile->GetTabWidth() ); ! m_pScintilla->SetEdgeColumn( pSyntaxFile->GetRightEdgeColumn() ); ! ! // Set the number of Stylebits ! iTemp = pSyntaxFile->GetStyleBits(); ! if( -1 != iTemp ) m_pScintilla->SetStyleBits( iTemp ); ! ! if( bSyntaxHighlighting ) ! { ! // Set the lexer ! iTemp = pSyntaxFile->GetLexerNumber(); ! if( -1 != iTemp ) m_pScintilla->SetLexer( iTemp ); ! ! // Set the lexer properties ! if( 0 < pSyntaxFile->GetLexerProperties( mapLexerProps ) ) ! { ! CString szTemp2; ! pos = mapLexerProps.GetStartPosition(); ! while( NULL != pos ) ! { ! mapLexerProps.GetNextAssoc( pos, szTemp, szTemp2 ); ! m_pScintilla->SetProperty( szTemp, szTemp2 ); ! } ! } ! ! // Set properties of each style if it is defined in the syntax ! for( iCount = 0; iCount <= STYLE_MAX; ++ iCount ) ! { ! // Set the font properties of the style ! szTemp = pSyntaxFile->GetStyleFontName( iCount ); ! if( !szTemp.IsEmpty() ) m_pScintilla->StyleSetFont( iCount, szTemp ); ! iTemp = pSyntaxFile->GetStyleFontSize( iCount ); ! if( -1 != iTemp ) m_pScintilla->StyleSetSize( iCount, iTemp ); ! m_pScintilla->StyleSetBold( iCount, pSyntaxFile->GetStyleFontBold( iCount ) ); ! m_pScintilla->StyleSetItalic( iCount, pSyntaxFile->GetStyleFontItalic( iCount ) ); ! m_pScintilla->StyleSetUnderline( iCount, pSyntaxFile->GetStyleFontUnderline( iCount ) ); ! ! // Set the color of the style ! m_pScintilla->StyleSetFore( iCount, pSyntaxFile->GetStyleColorForeground( iCount ) ); ! m_pScintilla->StyleSetBack( iCount, pSyntaxFile->GetStyleColorBackground( iCount ) ); ! ! } ! ! // Set the keywords for the lexer ! for( iCount = 0; iCount <= KEYWORDSET_MAX; ++ iCount ) ! { ! szTemp = pSyntaxFile->GetDelimitedKeywordSet( iCount, ' ' ); ! if( !szTemp.IsEmpty() ) m_pScintilla->SetKeyWords( iCount, szTemp ); ! } ! } ! ! bFirstTimeProperties = FALSE; // Done first round and keep is false every other round. ! } ! ! BOOL CAnyEditDoc::GetSyntaxHighlighting() ! { ! return bSyntaxHighlighting; ! } ! ! void CAnyEditDoc::ToggleSyntaxHighlighting() ! { ! bSyntaxHighlighting = bSyntaxHighlighting ? 0 : 1; } Index: AnyEditDoc.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEditDoc.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** AnyEditDoc.h 20 Nov 2003 15:47:49 -0000 1.7 --- AnyEditDoc.h 12 Dec 2003 11:00:04 -0000 1.8 *************** *** 11,14 **** --- 11,23 ---- #include "scintillaif.h" #include "Language.h" + #include "SyntaxFile.h" + + // Define the Margin ID's & Sizes + #define LINENUMBER_MARGIN_ID 0 + #define BOOKMARK_MARGIN_ID 1 + #define FOLD_MARGIN_ID 2 + #define LINENUMBER_MARGIN_SIZE 36 + #define BOOKMARK_MARGIN_SIZE 16 + #define FOLD_MARGIN_SIZE 14 class CAnyEditDoc : public CDocument *************** *** 20,23 **** --- 29,36 ---- // Attributes protected: + int iLanguage; // The Number of the Language + BOOL bFirstTimeProperties; // We want to know when we set the Scintilla properties for the first time. + BOOL bSyntaxHighlighting; // We want to keep track of the syntax highlighting setting. + CScintilla * m_pScintilla; CString doc_file_path; *************** *** 47,51 **** void SetDocScintilla(CScintilla * m_pscin); void SetDocLanguage(CLanguage * m_plang); ! virtual ~CAnyEditDoc(); #ifdef _DEBUG virtual void AssertValid() const; --- 60,70 ---- void SetDocScintilla(CScintilla * m_pscin); void SetDocLanguage(CLanguage * m_plang); ! ! void SetLanguageNr( int iLanguageNr ); ! void SetScintillaProperties(); ! BOOL GetSyntaxHighlighting(); ! void ToggleSyntaxHighlighting(); ! ! virtual ~CAnyEditDoc(); #ifdef _DEBUG virtual void AssertValid() const; *************** *** 54,59 **** protected: // Generated message map functions - protected: //{{AFX_MSG(CAnyEditDoc) // NOTE - the ClassWizard will add and remove member functions here. --- 73,79 ---- protected: + CString GetFileNameExtension( LPCTSTR lpszPathName ); + // Generated message map functions //{{AFX_MSG(CAnyEditDoc) // NOTE - the ClassWizard will add and remove member functions here. Index: AnyEditView.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEditView.cpp,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** AnyEditView.cpp 11 Dec 2003 04:15:21 -0000 1.40 --- AnyEditView.cpp 12 Dec 2003 11:00:04 -0000 1.41 *************** *** 12,15 **** --- 12,16 ---- #include "Goto.h" #include "Language.h" + #include "SyntaxFile.h" #ifdef _DEBUG *************** *** 19,25 **** #endif [...1190 lines suppressed...] ! pCmdUI->Enable(); ! return; ! } ! } ! pCmdUI->Enable(FALSE); } ! void CAnyEditView::OnUpdateToolsRepeatcommand(CCmdUI* pCmdUI) { ! if(theApp.macroholder) ! { ! if(!theApp.isRecordingMacro) ! { ! pCmdUI->Enable(); ! return; ! } ! } ! pCmdUI->Enable(FALSE); } + Index: AnyEditView.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEditView.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** AnyEditView.h 11 Dec 2003 04:15:21 -0000 1.22 --- AnyEditView.h 12 Dec 2003 11:00:04 -0000 1.23 *************** *** 15,19 **** #include "TagList.h" ! #define PARSER_TIMER (WM_USER + 5000) class CAnyEditView : public CView --- 15,19 ---- #include "TagList.h" ! #define PARSER_TIMER (WM_USER + 5000) class CAnyEditView : public CView *************** *** 27,43 **** BOOL EnableParsing; int ParseTimeLimit; ! BOOL isHighlightingOn; CString DocExt; CString CurDocPath; BOOL outoffocus; CTime last_access_time; ! BOOL fileclosed; ! CToolBar m_wndTool; // Attributes public: CAnyEditDoc* GetDocument(); ! void Init(); protected: --- 27,43 ---- BOOL EnableParsing; int ParseTimeLimit; ! BOOL isHighlightingOn; CString DocExt; CString CurDocPath; BOOL outoffocus; CTime last_access_time; ! BOOL fileclosed; ! CToolBar m_wndTool; // Attributes public: CAnyEditDoc* GetDocument(); ! // void Init(); protected: *************** *** 51,60 **** // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAnyEditView) ! public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo); virtual void OnInitialUpdate(); ! protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); --- 51,60 ---- // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAnyEditView) ! public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo); virtual void OnInitialUpdate(); ! protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); *************** *** 62,67 **** virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); ! virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo); ! //}}AFX_VIRTUAL // Implementation --- 62,67 ---- virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); ! virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo); ! //}}AFX_VIRTUAL // Implementation *************** *** 75,79 **** void InsertStringArray(CStringArray &arr); void JustOpenedFile(); ! void ReloadDefaults(); void SetSelectedLine(int lineno); void OnModified(); --- 75,79 ---- void InsertStringArray(CStringArray &arr); void JustOpenedFile(); ! // void ReloadDefaults(); ... [truncated message content] |