From: Markus R. <rol...@us...> - 2007-07-15 10:16:23
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv23210 Modified Files: sparkedit.cpp sparkedit.h Log Message: - made EditEntry::fn member protected, moved cleaning of filename and filename access to member functions - added member SaveFileAs, SetFile and GetTitle() - added support for unnamed files Index: sparkedit.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparkedit.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** sparkedit.cpp 10 Jul 2007 15:15:26 -0000 1.5 --- sparkedit.cpp 15 Jul 2007 10:16:18 -0000 1.6 *************** *** 20,24 **** #include "sparkedit.h" #include <wx/colour.h> - #include <wx/filename.h> #include <rsgedit/res/xpm_play.xpm> --- 20,23 ---- *************** *** 30,33 **** --- 29,50 ---- static wxColour COL_KEYWORD(0,0,255); + + // --- SparkEdit::EditEntry + + const wxFileName& SparkEdit::EditEntry::GetFileName() const + { + return fn; + } + + + void SparkEdit::EditEntry::SetFileName(const wxString& fname) + { + fn = wxFileName(fname); + fn.Normalize(); + } + + // --- SparkEdit + + SparkEdit::SparkEdit() : mStartScript(0) *************** *** 64,73 **** } ! wxString SparkEdit::GetTitle(wxScintilla* edit, const EditEntry& entry) { ! wxString title(wxFileName(entry.fname).GetFullName()); ! if (edit->GetModify()) { title += "*"; --- 81,107 ---- } ! wxString SparkEdit::GetTitle(wxScintilla* edit) { + TEditMap::iterator iter = mEditMap.find(edit); + if (iter == mEditMap.end()) + { + assert(false); + return wxString(); + } ! const EditEntry& entry = (*iter).second; ! bool markModified = false; ! return GetTitle(edit, entry, markModified); ! } ! wxString SparkEdit::GetTitle(wxScintilla* edit, const EditEntry& entry, bool markModified) ! { ! wxString fname = entry.GetFileName().GetFullName(); ! wxString title(fname.IsEmpty() ? "<unnamed>" : fname); ! ! if ( ! (markModified) && ! (edit->GetModify()) ! ) { title += "*"; *************** *** 85,107 **** } ! wxFileName fn(fname); ! fn.Normalize(); ! ! for ( ! TEditMap::iterator iter = mEditMap.begin(); ! iter != mEditMap.end(); ! ++iter ! ) { ! EditEntry& entry = (*iter).second; ! if (fn.GetFullPath() == entry.fname) { ! wxScintilla* edit = (*iter).first; ! if (select) ! { ! SelectEdit(notebook, edit); ! } ! return edit; } } --- 119,144 ---- } ! EditEntry newEntry; ! if (! fname.IsEmpty()) { ! newEntry.SetFileName(fname); ! ! for ( ! TEditMap::iterator iter = mEditMap.begin(); ! iter != mEditMap.end(); ! ++iter ! ) { ! EditEntry& entry = (*iter).second; ! if (newEntry.GetFileName() == entry.GetFileName()) ! { ! wxScintilla* edit = (*iter).first; ! if (select) ! { ! SelectEdit(notebook, edit); ! } ! return edit; ! } } } *************** *** 109,116 **** wxScintilla* edit = Create(notebook); ! EditEntry entry; ! entry.fname = fn.GetFullPath(); ! ! if (! LoadFile(edit, entry)) { edit->Destroy(); --- 146,153 ---- wxScintilla* edit = Create(notebook); ! if ( ! (! fname.IsEmpty()) && ! (! LoadFile(edit, newEntry)) ! ) { edit->Destroy(); *************** *** 118,122 **** } ! wxString title(GetTitle(edit, entry)); notebook->AddPage(edit,title,select); --- 155,160 ---- } ! bool markModified = true; ! wxString title(GetTitle(edit, newEntry, markModified)); notebook->AddPage(edit,title,select); *************** *** 126,132 **** } ! mEditMap[edit] = entry; ! UpdateIcon(notebook, edit, entry); return edit; } --- 164,170 ---- } ! mEditMap[edit] = newEntry; ! UpdateIcon(notebook, edit, newEntry); return edit; } *************** *** 140,148 **** } - wxFileName fn(entry.fname); - if ( ! (! fn.FileExists()) || ! (! edit->LoadFile(entry.fname)) ) { --- 178,184 ---- } if ( ! (! entry.GetFileName().FileExists()) || ! (! edit->LoadFile(entry.GetFileName().GetFullPath())) ) { *************** *** 151,156 **** } ! edit->SetLabel(entry.fname); ! wxString ext(fn.GetExt().Lower()); if (ext == "rsg") --- 187,205 ---- } ! PrepareEdit(edit, entry); ! return true; ! } ! ! void SparkEdit::PrepareEdit(wxScintilla* edit, EditEntry& entry) ! { ! if (edit == 0) ! { ! assert(false); ! return; ! } ! ! ! edit->SetLabel(entry.GetFileName().GetFullPath()); ! wxString ext(entry.GetFileName().GetExt().Lower()); if (ext == "rsg") *************** *** 174,190 **** } - PrepareEdit(edit, entry); - - return true; - } - - void SparkEdit::PrepareEdit(wxScintilla* edit, const EditEntry& entry) - { - if (edit == 0) - { - assert(false); - return; - } - switch (entry.type) { --- 223,226 ---- *************** *** 362,366 **** const EditEntry& entry = (*iter).second; ! notebook->SetPageText(page, GetTitle(edit, entry)); } --- 398,403 ---- const EditEntry& entry = (*iter).second; ! bool markModified = true; ! notebook->SetPageText(page, GetTitle(edit, entry, markModified)); } *************** *** 392,396 **** } ! edit->SaveFile(entry.fname); } --- 429,433 ---- } ! edit->SaveFile(entry.GetFileName().GetFullPath()); } *************** *** 407,410 **** --- 444,469 ---- } + void SparkEdit::SaveFileAs(wxFlatNotebook* notebook, wxScintilla* edit, const wxString& fname) + { + if (notebook == 0) + { + assert(false); + return; + } + + TEditMap::iterator iter = mEditMap.find(edit); + if (iter == mEditMap.end()) + { + return; + } + + EditEntry& entry = (*iter).second; + entry.SetFileName(fname); + + edit->SaveFile(entry.GetFileName().GetFullPath()); + PrepareEdit(edit, entry); + UpdateIcon(notebook, edit, entry); + } + void SparkEdit::SetStartScript(wxFlatNotebook* notebook, wxScintilla* edit) { *************** *** 444,448 **** const EditEntry& entry = (*iter).second; ! return entry.fname; } --- 503,528 ---- const EditEntry& entry = (*iter).second; ! return entry.GetFileName().GetFullPath(); ! } ! ! void SparkEdit::SetFile(wxScintilla* edit, wxFlatNotebook* notebook, const wxString& fname) ! { ! if (edit == 0) ! { ! assert(false); ! return; ! } ! ! TEditMap::iterator iter = mEditMap.find(edit); ! if (iter == mEditMap.end()) ! { ! return; ! } ! ! EditEntry& entry = (*iter).second; ! entry.SetFileName(fname); ! ! PrepareEdit(edit, entry); ! UpdateIcon(notebook, edit, entry); } Index: sparkedit.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparkedit.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** sparkedit.h 10 Jul 2007 15:15:26 -0000 1.6 --- sparkedit.h 15 Jul 2007 10:16:18 -0000 1.7 *************** *** 21,24 **** --- 21,25 ---- #define SPARKEDIT_H__ + #include <wx/filename.h> #include <wx/string.h> #include <wx/wxscintilla.h> *************** *** 52,57 **** public: EEditType type; - wxString fname; public: EditEntry() --- 53,59 ---- public: EEditType type; + protected: + wxFileName fn; public: EditEntry() *************** *** 59,62 **** --- 61,67 ---- { } + + const wxFileName& GetFileName() const; + void SetFileName(const wxString& fname); }; *************** *** 76,79 **** --- 81,85 ---- void UpdateIcons(wxFlatNotebook* notebook); void SaveFile(wxScintilla* edit); + void SaveFileAs(wxFlatNotebook* notebook, wxScintilla* edit, const wxString& fname); void SaveModified(); void SetStartScript(wxFlatNotebook* notebook, wxScintilla* edit); *************** *** 81,87 **** --- 87,95 ---- EEditType GetFileType(wxScintilla* edit); wxString GetFile(wxScintilla* edit); + void SetFile(wxScintilla* edit, wxFlatNotebook* notebook, const wxString& fname); wxString GetStartScriptFile(); void PrepareImageList(wxFlatNotebook* notebook); void SelectEdit(wxFlatNotebook* notebook, wxScintilla* edit); + wxString GetTitle(wxScintilla* edit); static wxScintilla* GetCurrentPage(wxFlatNotebook* notebook); *************** *** 90,95 **** wxScintilla* Create(wxWindow* parent); bool LoadFile(wxScintilla* edit, EditEntry& entry); ! void PrepareEdit(wxScintilla* edit, const EditEntry& entry); ! wxString GetTitle(wxScintilla* edit, const EditEntry& entry); void UpdateIcon(wxFlatNotebook* notebook, wxScintilla* edit, const EditEntry& entry); --- 98,103 ---- wxScintilla* Create(wxWindow* parent); bool LoadFile(wxScintilla* edit, EditEntry& entry); ! void PrepareEdit(wxScintilla* edit, EditEntry& entry); ! wxString GetTitle(wxScintilla* edit, const EditEntry& entry, bool markModified); void UpdateIcon(wxFlatNotebook* notebook, wxScintilla* edit, const EditEntry& entry); |