From: Leon W. <moo...@us...> - 2005-04-11 06:48:13
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29430 Modified Files: FileTypeManager.cpp Log Message: - Improved SetScintillaProperties to correctly colour a document (when switching languages). - Added Scinitlla VisibilityPolicy setting. - Cleaned up LoadSyntaxFiles code. - Small code cleanups. Index: FileTypeManager.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/FileTypeManager.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** FileTypeManager.cpp 31 Jan 2005 22:54:02 -0000 1.26 --- FileTypeManager.cpp 11 Apr 2005 06:47:47 -0000 1.27 *************** *** 87,91 **** szFileName += SYNTAX_DIR; szFileName += conf->GetLanguageSyntaxFileName( iCount ); ! pSyntaxFile = GetSyntaxFile( iCount ); if( NULL == pSyntaxFile || szFileName != pSyntaxFile->GetFilename() ) --- 87,91 ---- szFileName += SYNTAX_DIR; szFileName += conf->GetLanguageSyntaxFileName( iCount ); ! pSyntaxFile = GetSyntaxFile( iCount ); if( NULL == pSyntaxFile || szFileName != pSyntaxFile->GetFilename() ) *************** *** 95,99 **** // Create new file. pSyntaxFile = new CSyntaxFile(); ! if (NULL == pSyntaxFile) continue; // throw memory exception! } --- 95,99 ---- // Create new file. pSyntaxFile = new CSyntaxFile(); ! if (NULL == pSyntaxFile) continue; // throw memory exception! } *************** *** 109,116 **** if( !fp ) { - CFile file1; - CFile file2; - UINT bytesRead; - char filebuffer[1024]; // The username file doesn't exist read the default CString szDefaultFileName=theApp.GetAppPath(); --- 109,112 ---- *************** *** 120,140 **** szDefaultFileName += conf->GetLanguageSyntaxFileName( iCount ); ! if( !file1.Open( szDefaultFileName, CFile::modeRead | CFile::typeBinary ) ) { ! delete pSyntaxFile; ! continue; } ! ! if( !file2.Open( szFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary ) ) { delete pSyntaxFile; ! continue; ! } ! ! bytesRead = 1; ! while( bytesRead ) ! { ! bytesRead = file1.Read( filebuffer, 1024 ); ! if( bytesRead ) file2.Write( filebuffer, bytesRead ); } } --- 116,140 ---- szDefaultFileName += conf->GetLanguageSyntaxFileName( iCount ); ! fp = fopen( szDefaultFileName, "r" ); ! if( fp ) { ! fclose( fp ); ! pSyntaxFile->SetFilename( szDefaultFileName ); ! if( pSyntaxFile->Parse() ) ! { ! pSyntaxFile->SetFilename( szFileName ); ! pSyntaxFile->SetModified( true ); ! pSyntaxFile->Save(); ! } ! else ! { ! delete pSyntaxFile; ! pSyntaxFile = NULL; ! } } ! else { delete pSyntaxFile; ! pSyntaxFile = NULL; } } *************** *** 143,148 **** fclose( fp ); } ! // Add the parsed object to the Syntax file map. ! m_mapSyntaxFiles.SetAt( iCount, pSyntaxFile ); } } --- 143,156 ---- fclose( fp ); } ! if( NULL == pSyntaxFile ) ! { ! // Remove the language from the Syntax file map. ! m_mapSyntaxFiles.RemoveKey( iCount ); ! } ! else ! { ! // Add the parsed object to the Syntax file map. ! m_mapSyntaxFiles.SetAt( iCount, pSyntaxFile ); ! } } } *************** *** 275,284 **** pScintilla->StyleClearAll(); // Do some default AnyEdit settings pScintilla->StyleSetEOLFilled( STYLE_DEFAULT, true ); pScintilla->UsePopUp( false ); - pScintilla->SetCaretFore( pConfigFile->GetCaretColor() ); - pScintilla->SetSelFore( pConfigFile->UseSelectionForegroundColor(), pConfigFile->GetSelectionForegroundColor() ); pScintilla->SetSelBack( pConfigFile->UseSelectionBackgroundColor(), pConfigFile->GetSelectionBackgroundColor() ); --- 283,294 ---- pScintilla->StyleClearAll(); + // Clear stuff put by the lexer + pScintilla->SetLexer( SCLEX_NULL ); + pScintilla->ClearDocumentStyle(); + // Do some default AnyEdit settings pScintilla->StyleSetEOLFilled( STYLE_DEFAULT, true ); pScintilla->UsePopUp( false ); pScintilla->SetSelFore( pConfigFile->UseSelectionForegroundColor(), pConfigFile->GetSelectionForegroundColor() ); pScintilla->SetSelBack( pConfigFile->UseSelectionBackgroundColor(), pConfigFile->GetSelectionBackgroundColor() ); *************** *** 286,289 **** --- 296,300 ---- pScintilla->SetCaretLineVisible( pConfigFile->GetHighlightCurrentLine() ? 1 : 0 ); pScintilla->SetCaretWidth( 1 ); + pScintilla->SetCaretFore( pConfigFile->GetCaretColor() ); pScintilla->SetCaretLineBack( pConfigFile->GetHighlightCurrentLineColor() ); *************** *** 348,351 **** --- 359,363 ---- iTemp = pSyntaxFile->GetLexerNumber(); if( -1 != iTemp ) pScintilla->SetLexer( iTemp ); + else pScintilla->SetLexer( SCLEX_NULL ); // Set the lexer properties *************** *** 381,386 **** for( iCount = 0; iCount <= KEYWORDSET_MAX; ++ iCount ) { ! szTemp = pSyntaxFile->GetDelimitedKeywordSet( iCount, ' ' ); ! if( !szTemp.IsEmpty() ) pScintilla->SetKeyWords( iCount, szTemp ); } } --- 393,397 ---- for( iCount = 0; iCount <= KEYWORDSET_MAX; ++ iCount ) { ! pScintilla->SetKeyWords( iCount, pSyntaxFile->GetSpaceDelimitedKeywordSet( iCount ) ); } } *************** *** 388,392 **** { // At least set the scintilla default style if we don't use syntax highlighting. ! for( iCount = STYLE_DEFAULT + 1; iCount < STYLE_LASTPREDEFINED; ++ iCount ) { // Set the font properties of the style --- 399,403 ---- { // At least set the scintilla default style if we don't use syntax highlighting. ! for( iCount = 0; iCount < STYLE_LASTPREDEFINED; ++ iCount ) { // Set the font properties of the style *************** *** 402,408 **** pScintilla->StyleSetFore( iCount, pSyntaxFile->GetStyleColorForeground( iCount ) ); pScintilla->StyleSetBack( iCount, pSyntaxFile->GetStyleColorBackground( iCount ) ); } } ! pScintilla->SetVisibleLineNumber(pSyntaxFile->GetMarginLineNumber()); } --- 413,426 ---- pScintilla->StyleSetFore( iCount, pSyntaxFile->GetStyleColorForeground( iCount ) ); pScintilla->StyleSetBack( iCount, pSyntaxFile->GetStyleColorBackground( iCount ) ); + + // With no syntax highlighting we can skip 1 to STYLE_DEFAULT + // STYLE_DEFAULT has already been set when we cleared all. + // We will continue at STYLE_DEFAULT + 1. + if( iCount == 0 ) iCount = STYLE_DEFAULT; } } ! ! // Ok now restyle the document. ! pScintilla->Colourise(0,-1); } *************** *** 410,416 **** BOOL CFileTypeManager::GetBraceMatching(int iLanguage) { ! CSyntaxFile* pSyntaxFile; ! ! pSyntaxFile = GetSyntaxFile( iLanguage ); if( NULL == pSyntaxFile ) return FALSE; --- 428,432 ---- BOOL CFileTypeManager::GetBraceMatching(int iLanguage) { ! CSyntaxFile* pSyntaxFile = GetSyntaxFile( iLanguage ); if( NULL == pSyntaxFile ) return FALSE; *************** *** 423,429 **** BOOL CFileTypeManager::GetSyntaxHighlighting(int iLanguage) { ! CSyntaxFile* pSyntaxFile; ! ! pSyntaxFile = GetSyntaxFile( iLanguage ); if( NULL == pSyntaxFile ) return FALSE; --- 439,443 ---- BOOL CFileTypeManager::GetSyntaxHighlighting(int iLanguage) { ! CSyntaxFile* pSyntaxFile = GetSyntaxFile( iLanguage ); if( NULL == pSyntaxFile ) return FALSE; *************** *** 446,450 **** if( !pSyntaxFile->Parse() ) return; ! pScintilla->SetViewWS( pSyntaxFile->GetWhiteSpace() ? 1 : 0 ); pScintilla->SetViewEOL( pSyntaxFile->GetEOL() ? 1 : 0 ); --- 460,464 ---- if( !pSyntaxFile->Parse() ) return; ! pScintilla->SetViewWS( pSyntaxFile->GetWhiteSpace() ? 1 : 0 ); pScintilla->SetViewEOL( pSyntaxFile->GetEOL() ? 1 : 0 ); *************** *** 480,483 **** --- 494,502 ---- pScintilla->DefineMarker(SC_BOOKMARK, SC_MARK_ARROW, RGB(0,0,255), RGB(231,231,255)); pScintilla->DefineMarker(SC_MARK_SHORTARROW, SC_MARK_SHORTARROW, RGB(107,27,18), RGB(251,252,226)); + + // Set Caret and Visibility Policy + // pScintilla->SetXCaretPolicy( CARET_STRICT, 0 ); + pScintilla->SetYCaretPolicy( CARET_SLOP|CARET_EVEN, 3 ); + pScintilla->SetVisiblePolicy( VISIBLE_STRICT, 0 ); } *************** *** 487,499 **** CString CFileTypeManager::GetDelimitedKeywords(int iLanguage, char cSep) { ! CString strKeyWords; ! strKeyWords.Empty(); ! ! CSyntaxFile* pSyntaxFile; ! ! pSyntaxFile = GetSyntaxFile( iLanguage ); ! if( NULL == pSyntaxFile ) return strKeyWords; ! if( !pSyntaxFile->Parse() ) return strKeyWords; return pSyntaxFile->GetDelimitedKeywords(cSep); --- 506,513 ---- CString CFileTypeManager::GetDelimitedKeywords(int iLanguage, char cSep) { ! CSyntaxFile* pSyntaxFile = GetSyntaxFile( iLanguage ); ! if( NULL == pSyntaxFile ) return _T(""); ! if( !pSyntaxFile->Parse() ) return _T(""); return pSyntaxFile->GetDelimitedKeywords(cSep); *************** *** 517,521 **** m_arrLanguageNames.InsertAt(iCount, strLanguageName); } ! } /// Create filter string for file open dialog. --- 531,535 ---- m_arrLanguageNames.InsertAt(iCount, strLanguageName); } ! } /// Create filter string for file open dialog. *************** *** 549,553 **** CString CFileTypeManager::GetFileFilter( int iLanguage ) { ! return GetLanguageName( iLanguage ) + " (" + m_arrFilters.GetAt( iLanguage ) + ")|" + m_arrFilters.GetAt( iLanguage ); } --- 563,567 ---- CString CFileTypeManager::GetFileFilter( int iLanguage ) { ! return GetLanguageName( iLanguage ) + " (" + m_arrFilters.GetAt( iLanguage ) + ")|" + m_arrFilters.GetAt( iLanguage ); } |