Show
Ignore:
Timestamp:
08/19/10 19:21:08 (21 months ago)
Author:
Carsten
Message:

CaWE GUI editor:

  • Lua errors on loading a GUI are now presented to the user.
  • Window names are checked for unique-ness now (and silently repaired, if necessary) when the GUI is saved.

Fixes #37.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/GuiEditor/GuiDocument.cpp

    r36 r122  
    6161        cf::GuiSys::GuiImplT Gui(gifn); 
    6262 
     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 
    6374        m_GuiProperties=GuiPropertiesT(Gui); 
    6475 
     
    159170 
    160171 
     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). 
     176static 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 
    161190// Recursively saves the window instantiation of the passed window and all of its children. 
    162191static void SaveWindowInstantiation(std::ostream& OutFile, cf::GuiSys::WindowT* Window, const wxString& ParentName) 
     
    239268bool GuiDocumentT::SaveInit_cgui(std::ostream& OutFile) 
    240269{ 
     270    CheckWindowNames(m_RootWindow); 
     271 
    241272    OutFile << "-- This is a Cafu engine GUI script file, written by CaWE, the Cafu World Editor.\n"; 
    242273    OutFile << "-- You CAN edit this file manually, but note that CaWE may overwrite your changes.\n"; 
     
    262293    OutFile << "\n"; 
    263294 
    264     SaveWindowHierarchy   (OutFile, m_RootWindow, ""); 
     295    SaveWindowHierarchy(OutFile, m_RootWindow, ""); 
    265296 
    266297    OutFile << "\n";