Changeset 123

Show
Ignore:
Timestamp:
08/19/10 23:35:41 (18 months ago)
Author:
Carsten
Message:

CaWE GUI Editor: Rewrote/fixed broken "delete windows" command.

Location:
cafu/trunk/CaWE/GuiEditor
Files:
4 modified

Legend:

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

    r94 r123  
    497497{ 
    498498    SubmitCommand(new CommandDeleteT(m_GuiDocument, m_GuiDocument->GetSelection())); 
    499     SubmitCommand(CommandSelectT::Clear(m_GuiDocument)); 
    500499} 
    501500 
     
    519518void GuiEditor::ChildFrameT::OnUpdateEditCutCopyDelete(wxUpdateUIEvent& UE) 
    520519{ 
    521     if (m_GuiDocument->GetSelection().Size()>0) UE.Enable(true); 
    522     else                                        UE.Enable(false); 
     520    UE.Enable(m_GuiDocument->GetSelection().Size()>0); 
    523521} 
    524522 
     
    526524void GuiEditor::ChildFrameT::OnUpdateEditPaste(wxUpdateUIEvent& UE) 
    527525{ 
    528     if (ClipBoard.Size()>0 && m_GuiDocument->GetSelection().Size()==1) UE.Enable(true); 
    529     else                                                               UE.Enable(false); 
     526    UE.Enable(ClipBoard.Size()>0 && m_GuiDocument->GetSelection().Size()==1); 
    530527} 
    531528 
     
    702699        case ID_TOOLBAR_WINDOW_DELETE: 
    703700            SubmitCommand(new CommandDeleteT(m_GuiDocument, m_GuiDocument->GetSelection())); 
    704             SubmitCommand(CommandSelectT::Clear(m_GuiDocument)); 
    705701            break; 
    706702 
  • cafu/trunk/CaWE/GuiEditor/Commands/Delete.cpp

    r36 r123  
    2323 
    2424#include "Delete.hpp" 
    25  
     25#include "Select.hpp" 
    2626#include "../GuiDocument.hpp" 
    27  
    2827#include "GuiSys/Window.hpp" 
    2928 
     
    3332 
    3433CommandDeleteT::CommandDeleteT(GuiDocumentT* GuiDocument, cf::GuiSys::WindowT* Window) 
    35     : m_GuiDocument(GuiDocument) 
     34    : m_GuiDocument(GuiDocument), 
     35      m_CommandSelect(NULL) 
    3636{ 
    37     if (Window!=Window->GetRoot()) // Root window can never be deleted. 
     37    wxASSERT(Window->Parent->Children.Find(Window)>=0); 
     38 
     39    // The root window cannot be deleted. 
     40    if (Window!=Window->GetRoot()) 
    3841    { 
    39         m_DeleteWindows.PushBack(Window); 
    40         m_Parents.PushBack(Window->Parent); 
    41         m_Indexes.PushBack(Window->Parent->Children.Find(Window)); 
     42        m_Windows.PushBack(Window); 
     43        m_Indices.PushBack(-1); 
    4244    } 
     45 
     46    m_CommandSelect=CommandSelectT::Remove(m_GuiDocument, m_Windows); 
    4347} 
    4448 
     
    4650CommandDeleteT::CommandDeleteT(GuiDocumentT* GuiDocument, const ArrayT<cf::GuiSys::WindowT*>& Windows) 
    4751    : m_GuiDocument(GuiDocument), 
    48       m_DeleteWindows(Windows) 
     52      m_CommandSelect(NULL) 
    4953{ 
    50     for (unsigned long WinNr=0; WinNr<m_DeleteWindows.Size(); WinNr++) 
     54    for (unsigned long WinNr=0; WinNr<Windows.Size(); WinNr++) 
    5155    { 
    52         // Root window can never be deleted. 
    53         if (m_DeleteWindows[WinNr]==m_DeleteWindows[WinNr]->GetRoot()) 
     56        cf::GuiSys::WindowT* Window=Windows[WinNr]; 
     57 
     58        wxASSERT(Window->Parent->Children.Find(Window)>=0); 
     59 
     60        // The root window cannot be deleted. 
     61        if (Window!=Window->GetRoot()) 
    5462        { 
    55             m_DeleteWindows.RemoveAtAndKeepOrder(WinNr); 
    56             WinNr--; 
    57             continue; 
     63            m_Windows.PushBack(Window); 
     64            m_Indices.PushBack(-1); 
    5865        } 
     66    } 
    5967 
    60         m_Parents.PushBack(m_DeleteWindows[WinNr]->Parent); 
    61         m_Indexes.PushBack(m_DeleteWindows[WinNr]->Parent->Children.Find(m_DeleteWindows[WinNr])); 
    62     } 
     68    m_CommandSelect=CommandSelectT::Remove(m_GuiDocument, m_Windows); 
    6369} 
    6470 
     
    6672CommandDeleteT::~CommandDeleteT() 
    6773{ 
     74    delete m_CommandSelect; 
     75 
    6876    if (m_Done) 
    69         for (unsigned long WinNr=0; WinNr<m_DeleteWindows.Size(); WinNr++) 
    70             delete m_DeleteWindows[WinNr]; 
     77        for (unsigned long WinNr=0; WinNr<m_Windows.Size(); WinNr++) 
     78            delete m_Windows[WinNr]; 
    7179} 
    7280 
     
    7583{ 
    7684    wxASSERT(!m_Done); 
    77  
    7885    if (m_Done) return false; 
    7986 
    80     for (unsigned long WinNr=0; WinNr<m_DeleteWindows.Size(); WinNr++) 
    81         m_Parents[WinNr]->Children.RemoveAtAndKeepOrder(m_Indexes[WinNr]); 
     87    // Deselect any affected windows that are selected. 
     88    m_CommandSelect->Do(); 
    8289 
    83     m_GuiDocument->UpdateAllObservers_Deleted(m_DeleteWindows); 
     90    for (unsigned long WinNr=0; WinNr<m_Windows.Size(); WinNr++) 
     91    { 
     92        cf::GuiSys::WindowT* Window=m_Windows[WinNr]; 
     93 
     94        m_Indices[WinNr]=Window->Parent->Children.Find(Window); 
     95        Window->Parent->Children.RemoveAtAndKeepOrder(m_Indices[WinNr]); 
     96    } 
     97 
     98    m_GuiDocument->UpdateAllObservers_Deleted(m_Windows); 
    8499 
    85100    m_Done=true; 
    86  
    87101    return true; 
    88102} 
     
    92106{ 
    93107    wxASSERT(m_Done); 
    94  
    95108    if (!m_Done) return; 
    96109 
    97     for (unsigned long WinNr=0; WinNr<m_DeleteWindows.Size(); WinNr++) 
    98         m_Parents[WinNr]->Children.InsertAt(m_Indexes[WinNr], m_DeleteWindows[WinNr]); 
     110    for (unsigned long RevNr=0; RevNr<m_Windows.Size(); RevNr++) 
     111    { 
     112        const unsigned long  WinNr =m_Windows.Size()-RevNr-1; 
     113        cf::GuiSys::WindowT* Window=m_Windows[WinNr]; 
    99114 
    100     m_GuiDocument->UpdateAllObservers_Created(m_DeleteWindows); 
     115        Window->Parent->Children.InsertAt(m_Indices[WinNr], Window); 
     116    } 
     117 
     118    m_GuiDocument->UpdateAllObservers_Created(m_Windows); 
     119 
     120    // Select the previously selected windows again. 
     121    m_CommandSelect->Undo(); 
    101122 
    102123    m_Done=false; 
     
    106127wxString CommandDeleteT::GetName() const 
    107128{ 
    108     return "Delete windows"; 
     129    return (m_Windows.Size()==1) ? "Delete 1 window" : wxString::Format("Delete %lu windows", m_Windows.Size()); 
    109130} 
  • cafu/trunk/CaWE/GuiEditor/Commands/Delete.hpp

    r36 r123  
    3333namespace GuiEditor 
    3434{ 
     35    class CommandSelectT; 
    3536    class GuiDocumentT; 
     37 
    3638 
    3739    class CommandDeleteT : public CommandT 
     
    5355        GuiDocumentT* m_GuiDocument; 
    5456 
    55         ArrayT<cf::GuiSys::WindowT*> m_Parents; 
    56         ArrayT<unsigned long >       m_Indexes; 
    57         ArrayT<cf::GuiSys::WindowT*> m_DeleteWindows; 
     57        ArrayT<cf::GuiSys::WindowT*> m_Windows; 
     58        ArrayT<unsigned long>        m_Indices; 
     59        CommandSelectT*              m_CommandSelect;   ///< The command that unselects all windows before they are deleted. 
    5860    }; 
    5961} 
  • cafu/trunk/CaWE/GuiEditor/WindowTree.cpp

    r36 r123  
    281281        wxASSERT(Windows.Size()==1); // Can't set the name property for more windows since it must always be unique. 
    282282 
    283         wxTreeItemId TreeItem=FindTreeItem(GetRootItem(), Windows[0]); 
    284  
    285283        SetItemText(FindTreeItem(GetRootItem(), Windows[0]), Windows[0]->Name); 
    286284    } 
     
    290288        for (unsigned long WindowNr=0; WindowNr<Windows.Size(); WindowNr++) 
    291289        { 
    292             int ImageNr=0; 
    293  
    294             if (!Windows[WindowNr]->ShowWindow) ImageNr=1; 
    295  
    296             SetItemImage(FindTreeItem(GetRootItem(), Windows[WindowNr]), ImageNr); 
     290            SetItemImage(FindTreeItem(GetRootItem(), Windows[WindowNr]), Windows[WindowNr]->ShowWindow ? 0 : 1); 
    297291        } 
    298292    } 
     
    307301    ArrayT<wxTreeItemId>         TreeItems; 
    308302    ArrayT<cf::GuiSys::WindowT*> ExpandedWindows; 
     303 
     304    // Note that this may well produce TreeItems whose windows have been deleted from the document already. 
    309305    GetTreeItems(GetRootItem(), TreeItems); 
    310306 
     
    344340 
    345341            // Make sure parents are also expanded. 
    346             while(GetItemParent(Result).IsOk()) 
     342            while (GetItemParent(Result).IsOk()) 
    347343            { 
    348344                Result=GetItemParent(Result); 
     
    356352    // Expand all previously expanded items. 
    357353    for (unsigned long ExWinNr=0; ExWinNr<ExpandedWindows.Size(); ExWinNr++) 
    358         Expand(FindTreeItem(GetRootItem(), ExpandedWindows[ExWinNr])); 
     354    { 
     355        wxTreeItemId Result=FindTreeItem(GetRootItem(), ExpandedWindows[ExWinNr]); 
     356 
     357        if (Result.IsOk()) 
     358            Expand(Result); 
     359    } 
    359360 
    360361    Thaw();