From: Markus R. <rol...@us...> - 2007-06-21 17:56:44
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24132 Added Files: Tag: RSGEDIT_SCINTILLA sparkedit.cpp sparkedit.h Log Message: - added SparkEdit, a class to manage wxScintilla instances --- NEW FILE: sparkedit.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: sparkedit.cpp,v 1.1.2.1 2007/06/21 17:56:39 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "sparkedit.h" #include <wx/colour.h> #include <wx/filename.h> static wxColour COL_COMMENT(0,128,0); static wxColour COL_KEYWORD(0,0,255); SparkEdit::TEditMap SparkEdit::mEditMap; wxScintilla* SparkEdit::Create(wxWindow* parent) { wxScintilla* edit = new wxScintilla(parent, wxID_ANY); // setup basic styles edit->SetMarginWidth(0, 24); edit->SetMarginWidth(1, 0); edit->SetMarginWidth(2, 0); edit->SetMarginType(0, wxSCI_MARGIN_NUMBER); edit->StyleSetVisible(wxSCI_STYLE_LINENUMBER, true); edit->SetCaretLineBackground(wxColour(255,255,0)); edit->SetCaretLineVisible(true); return edit; } wxScintilla* SparkEdit::GetEdit(const wxString& fname, wxFlatNotebook* notebook) { if (notebook == 0) { assert(false); return 0; } wxFileName fn(fname); fn.Normalize(); for ( TEditMap::iterator iter = mEditMap.begin(); iter != mEditMap.end(); ++iter ) { EditEntry& entry = (*iter).second; if (fn.GetFullPath() == entry.fname) { notebook->SetSelection(entry.page); wxScintilla* edit = (*iter).first; edit->SetFocus(); return edit; } } wxScintilla* edit = Create(notebook); EditEntry entry; entry.fname = fn.GetFullPath(); if (! LoadFile(edit, entry)) { edit->Destroy(); return 0; } bool select = true; notebook->AddPage(edit,wxFileName(fname).GetFullName(), select); edit->SetFocus(); entry.page = static_cast<int>(notebook->GetPageCount() - 1); mEditMap[edit] = entry; return edit; } bool SparkEdit::LoadFile(wxScintilla* edit, EditEntry& entry) { if (edit == 0) { assert(false); return false; } wxFileName fn(entry.fname); if ( (! fn.FileExists()) || (! edit->LoadFile(entry.fname)) ) { edit->ClearAll(); return false; } wxString ext(fn.GetExt().Lower()); if (ext == "rsg") { entry.type = ET_RSG; } else if (ext == "rb") { entry.type = ET_RB; } else if ( (ext == "c") || (ext == "cpp") || (ext == "cxx") || (ext == "h") || (ext == "hpp") ) { entry.type = ET_C; } else { entry.type = ET_TEXT; } PrepareEdit(edit, entry); return true; } void SparkEdit::PrepareEdit(wxScintilla* edit, const EditEntry& entry) { if (edit == 0) { assert(false); return; } switch (entry.type) { default: assert(false); // fall through case ET_TEXT: { edit->SetLexer(wxSCI_LEX_NULL); break; } case ET_RSG: { edit->SetLexer(wxSCI_LEX_LISP); edit->SetKeyWords(0, "node select pwd template define attach RubyDeltaScene RubySceneGraph " "nd sel pwd templ def attach RDS RSG" ); edit->StyleSetForeground(wxSCI_LISP_KEYWORD, COL_KEYWORD); edit->StyleSetForeground(wxSCI_LISP_COMMENT, COL_COMMENT); edit->StyleSetForeground(wxSCI_LISP_MULTI_COMMENT, COL_COMMENT); break; } case ET_RB: { edit->SetLexer(wxSCI_LEX_RUBY); // todo: set ruby color styles break; } case ET_C: { edit->SetLexer(wxSCI_LEX_CPP); // todo: set c color styles break; } } edit->Colourise(0,-1); } void SparkEdit::PutEdit(wxScintilla* edit) { TEditMap::iterator iter = mEditMap.find(edit); if (iter == mEditMap.end()) { assert(false); return; } mEditMap.erase(iter); } --- NEW FILE: sparkedit.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: sparkedit.h,v 1.1.2.1 2007/06/21 17:56:39 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef SPARKEDIT_H__ #define SPARKEDIT_H__ #include <wx/string.h> #include <wx/wxscintilla.h> #include <wx/wxflatnotebook/wxflatnotebook.h> #include <map> class SparkEdit { public: enum EEditType { ET_RSG, ET_RB, ET_C, ET_TEXT }; struct EditEntry { EEditType type; wxString fname; int page; }; typedef std::map<wxScintilla*, EditEntry > TEditMap; public: static wxScintilla* GetEdit(const wxString& fname, wxFlatNotebook* notebook); static void PutEdit(wxScintilla* edit); protected: static wxScintilla* Create(wxWindow* parent); static bool LoadFile(wxScintilla* edit, EditEntry& entry); static void PrepareEdit(wxScintilla* edit, const EditEntry& entry); protected: static TEditMap mEditMap; }; #endif // SPARKEDIT_H__ |