Changeset 122
- Timestamp:
- 08/19/10 19:21:08 (18 months ago)
- Location:
- cafu/trunk
- Files:
-
- 6 modified
-
CaWE/GuiEditor/Commands/Paste.cpp (modified) (5 diffs)
-
CaWE/GuiEditor/EditorData/Window.cpp (modified) (3 diffs)
-
CaWE/GuiEditor/EditorData/Window.hpp (modified) (2 diffs)
-
CaWE/GuiEditor/GuiDocument.cpp (modified) (4 diffs)
-
Libs/GuiSys/GuiImpl.cpp (modified) (2 diffs)
-
Libs/GuiSys/GuiImpl.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/CaWE/GuiEditor/Commands/Paste.cpp
r36 r122 23 23 24 24 #include "Paste.hpp" 25 26 25 #include "../GuiDocument.hpp" 27 28 26 #include "../EditorData/Window.hpp" 29 30 27 #include "GuiSys/Window.hpp" 31 28 … … 78 75 { 79 76 wxASSERT(!m_Done); 80 81 77 if (m_Done) return false; 82 78 … … 84 80 { 85 81 m_Windows[WinNr]->Parent=m_NewParent; 86 87 82 m_NewParent->Children.PushBack(m_Windows[WinNr]); 88 83 89 // If current window name is not unique within the window structure it was pasted into, 90 // create a new unique name. 91 wxString CurrentWindowName=m_Windows[WinNr]->Name; 92 unsigned long Counter=1; 93 94 while (!(((EditorDataWindowT*)m_Windows[WinNr]->EditorData)->CheckNameUniqueness(m_Windows[WinNr]->Name))) 95 { 96 std::ostringstream NameStream; 97 NameStream << CurrentWindowName << "_" << Counter; 98 Counter++; 99 100 m_Windows[WinNr]->Name=NameStream.str(); 101 } 84 // If the name of the window is not unique among its siblings, find a new unique name. 85 ((EditorDataWindowT*)m_Windows[WinNr]->EditorData)->RepairNameUniqueness(); 102 86 } 103 87 … … 105 89 106 90 m_Done=true; 107 108 91 return true; 109 92 } … … 113 96 { 114 97 wxASSERT(m_Done); 115 116 98 if (!m_Done) return; 117 99 -
cafu/trunk/CaWE/GuiEditor/EditorData/Window.cpp
r36 r122 34 34 35 35 36 static unsigned int Counter=1;37 38 39 36 EditorDataWindowT::EditorDataWindowT(cf::GuiSys::WindowT* Window, GuiDocumentT* GuiDocument) 40 37 : cf::GuiSys::EditorDataT(Window), 41 38 Selected(false), 42 m_GuiDocument(GuiDocument) 39 m_GuiDocument(GuiDocument), 40 m_Counter(1) 43 41 { 44 42 // If window has no name, create default name. 45 if (Window->Name=="") 46 { 47 std::ostringstream NameStream; 48 NameStream << "Window" << "_" << Counter; 49 Counter++; 50 Window->Name=NameStream.str(); 51 } 43 if (Window->Name=="") Window->Name="Window"; 52 44 53 45 // Check window name uniqueness and repair it. … … 80 72 81 73 82 void EditorDataWindowT::RepairNameUniqueness() 83 { 84 // Check if windows current name is unique. 85 std::string CurrentName=m_GuiWindow->Name; 86 std::string NewName =CurrentName; 87 88 // While current window name is not unique. 89 while (!CheckNameUniqueness(NewName)) 90 { 91 // Append continous number to name until the name is unique. 92 std::ostringstream NameStream; 93 NameStream << CurrentName << "_" << Counter; 94 NewName=NameStream.str(); 95 Counter++; 96 } 97 98 m_GuiWindow->Name=NewName; 99 } 100 101 102 bool EditorDataWindowT::CheckNameUniqueness(wxString Name) 74 bool EditorDataWindowT::CheckNameUniqueness(const wxString& Name) const 103 75 { 104 76 if (m_GuiWindow->GetRoot()==m_GuiWindow) return true; // Root window can have any name. … … 118 90 return true; 119 91 } 92 93 94 static wxString StripSuffix(const wxString& Str) 95 { 96 const size_t Pos=Str.rfind("_"); 97 98 if (Pos==std::string::npos) return Str; 99 100 for (size_t i=Pos+1; i<Str.length(); i++) 101 if (!wxIsdigit(Str[i])) return Str; 102 103 if (Pos==0) return "Window"; 104 105 return Str.Left(Pos); 106 } 107 108 109 void EditorDataWindowT::RepairNameUniqueness() 110 { 111 const wxString BaseName=StripSuffix(m_GuiWindow->Name); 112 wxString NewName =m_GuiWindow->Name; 113 114 while (!CheckNameUniqueness(NewName)) 115 { 116 NewName=BaseName+"_"+wxString::Format("%u", m_Counter); 117 m_Counter++; 118 } 119 120 m_GuiWindow->Name=NewName; 121 } -
cafu/trunk/CaWE/GuiEditor/EditorData/Window.hpp
r36 r122 50 50 51 51 /// Checks the name uniqueness of a new name string within the windows siblings. 52 /// @param Name Name to check for uniqueness.52 /// @param Name Name to check for uniqueness. 53 53 /// @return Whether this name is unique. 54 bool CheckNameUniqueness(wxString Name); 54 bool CheckNameUniqueness(const wxString& Name) const; 55 56 /// Helper method to check and auto-repair the uniqueness of the name of this window. 57 void RepairNameUniqueness(); 55 58 56 59 GuiDocumentT* GetGuiDoc() { return m_GuiDocument; } … … 62 65 63 66 GuiDocumentT* m_GuiDocument; 64 65 /// Helper method to check and repair the uniqueness of the name of this window. 66 void RepairNameUniqueness(); 67 unsigned int m_Counter; 67 68 }; 68 69 } -
cafu/trunk/CaWE/GuiEditor/GuiDocument.cpp
r36 r122 61 61 cf::GuiSys::GuiImplT Gui(gifn); 62 62 63 if (Gui.GetScriptInitResult()!="") 64 { 65 // GuiImplT::InitErrorT excecptions are caught in the caller code. 66 // Here we handle the case that initializing the GUI succeeded "halfway". 67 wxMessageBox("GUI file "+GuiInitFileName+" was loaded, but errors occurred:\n\n"+ 68 Gui.GetScriptInitResult()+"\n\n"+ 69 "You may choose to ignore this error and proceed,\n"+ 70 "but it is probably better to edit the file and manually fix the problem first.", 71 "GUI initialization warning", wxOK | wxICON_EXCLAMATION); 72 } 73 63 74 m_GuiProperties=GuiPropertiesT(Gui); 64 75 … … 159 170 160 171 172 // Recursively makes sure that the children of each window have unique names. 173 // Normally the other GUI editor code should make sure that that is always true, but right now it 174 // is possible to create violations of this constraint via drag-and-drop in the window hierarchy tree 175 // (can drop a window as a child of another window that already has a child with the same name). 176 static void CheckWindowNames(cf::GuiSys::WindowT* Window) 177 { 178 const std::string OldName=Window->Name; 179 180 ((EditorDataWindowT*)Window->EditorData)->RepairNameUniqueness(); 181 182 if (Window->Name!=OldName) 183 ((EditorDataWindowT*)Window->EditorData)->GetGuiDoc()->UpdateAllObservers_Modified(Window, WMD_PROPERTY_CHANGED, "Name"); 184 185 for (unsigned long ChildNr=0; ChildNr<Window->Children.Size(); ChildNr++) 186 CheckWindowNames(Window->Children[ChildNr]); 187 } 188 189 161 190 // Recursively saves the window instantiation of the passed window and all of its children. 162 191 static void SaveWindowInstantiation(std::ostream& OutFile, cf::GuiSys::WindowT* Window, const wxString& ParentName) … … 239 268 bool GuiDocumentT::SaveInit_cgui(std::ostream& OutFile) 240 269 { 270 CheckWindowNames(m_RootWindow); 271 241 272 OutFile << "-- This is a Cafu engine GUI script file, written by CaWE, the Cafu World Editor.\n"; 242 273 OutFile << "-- You CAN edit this file manually, but note that CaWE may overwrite your changes.\n"; … … 262 293 OutFile << "\n"; 263 294 264 SaveWindowHierarchy (OutFile, m_RootWindow, "");295 SaveWindowHierarchy(OutFile, m_RootWindow, ""); 265 296 266 297 OutFile << "\n"; -
cafu/trunk/Libs/GuiSys/GuiImpl.cpp
r102 r122 54 54 55 55 using namespace cf::GuiSys; 56 57 58 GuiImplT::InitErrorT::InitErrorT(const std::string& Message) 59 : std::runtime_error(Message) 60 { 61 } 56 62 57 63 … … 219 225 // problem. That is, there might still be a case left where we might want to throw. 220 226 lua_close(LuaState); 221 throw InitErrorT( /*"No root window set. Probable cause:\n"+ScriptInitResult*/);227 throw InitErrorT("No root window set. Probable cause:\n"+ScriptInitResult); 222 228 } 223 229 -
cafu/trunk/Libs/GuiSys/GuiImpl.hpp
r36 r122 49 49 public: 50 50 51 /// GUI initialization error. 52 class InitErrorT { }; 51 class InitErrorT; 53 52 54 53 … … 158 157 } 159 158 159 160 /// A class that is thrown on GUI initialization errors. 161 class cf::GuiSys::GuiImplT::InitErrorT : public std::runtime_error 162 { 163 public: 164 165 InitErrorT(const std::string& Message); 166 }; 167 160 168 #endif
