Changeset 378

Show
Ignore:
Timestamp:
09/12/11 10:03:34 (8 months ago)
Author:
Carsten
Message:

Gui Editor:
Renamed and "templatized" class CommandSetStringsT to CommandSetWinPropT in order to make it reusable with ints and floats as well.

Location:
cafu/trunk/CaWE/GuiEditor
Files:
1 modified
2 moved

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/GuiEditor/Commands/SetWinProp.cpp

    r374 r378  
    2020*/ 
    2121 
    22 #include "SetStrings.hpp" 
     22#include "SetWinProp.hpp" 
    2323#include "../GuiDocument.hpp" 
    2424 
     
    2727 
    2828 
    29 CommandSetStringsT::CommandSetStringsT(GuiDocumentT* GuiDoc, const EditorWindowT* Win, const wxString& PropertyName, 
    30     ArrayT<std::string>& Strings, const ArrayT<std::string>& NewStrings) 
     29template<class T> 
     30CommandSetWinPropT<T>::CommandSetWinPropT(GuiDocumentT* GuiDoc, const EditorWindowT* Win, const wxString& PropName, T& Value, const T& NewValue) 
    3131    : m_GuiDoc(GuiDoc), 
    3232      m_Win(Win), 
    33       m_PropertyName(PropertyName), 
    34       m_Strings(Strings), 
    35       m_NewStrings(NewStrings), 
    36       m_OldStrings(Strings) 
     33      m_PropName(PropName), 
     34      m_Value(Value), 
     35      m_NewValue(NewValue), 
     36      m_OldValue(Value) 
    3737{ 
    3838} 
    3939 
    4040 
    41 bool CommandSetStringsT::Do() 
     41template<class T> 
     42bool CommandSetWinPropT<T>::Do() 
    4243{ 
    4344    wxASSERT(!m_Done); 
    4445    if (m_Done) return false; 
    4546 
    46     // If the next sequence didn't really change, don't put this command into the command history. 
    47     // if (m_NewNext==m_OldNext) return false; 
     47    // If the new value isn't different from the old, don't put this command into the command history. 
     48    // if (m_NewValue==m_OldValue) return false; 
    4849 
    49     m_Strings=m_NewStrings; 
     50    m_Value=m_NewValue; 
    5051 
    51     m_GuiDoc->UpdateAllObservers_Modified(m_Win, m_PropertyName); 
     52    m_GuiDoc->UpdateAllObservers_Modified(m_Win, m_PropName); 
    5253    m_Done=true; 
    5354    return true; 
     
    5556 
    5657 
    57 void CommandSetStringsT::Undo() 
     58template<class T> 
     59void CommandSetWinPropT<T>::Undo() 
    5860{ 
    5961    wxASSERT(m_Done); 
    6062    if (!m_Done) return; 
    6163 
    62     m_Strings=m_OldStrings; 
     64    m_Value=m_OldValue; 
    6365 
    64     m_GuiDoc->UpdateAllObservers_Modified(m_Win, m_PropertyName); 
     66    m_GuiDoc->UpdateAllObservers_Modified(m_Win, m_PropName); 
    6567    m_Done=false; 
    6668} 
    6769 
    6870 
    69 wxString CommandSetStringsT::GetName() const 
     71template<class T> 
     72wxString CommandSetWinPropT<T>::GetName() const 
    7073{ 
    71     return "Set strings for " + m_PropertyName; 
     74    return "Set " + m_PropName; 
    7275} 
     76 
     77 
     78template class CommandSetWinPropT< ArrayT<std::string> >; 
  • cafu/trunk/CaWE/GuiEditor/Commands/SetWinProp.hpp

    r374 r378  
    2020*/ 
    2121 
    22 #ifndef _GUIEDITOR_SET_STRINGS_HPP_ 
    23 #define _GUIEDITOR_SET_STRINGS_HPP_ 
     22#ifndef _GUIEDITOR_SET_WINDOW_PROPERTY_HPP_ 
     23#define _GUIEDITOR_SET_WINDOW_PROPERTY_HPP_ 
    2424 
    2525#include "../../CommandPattern.hpp" 
     
    3131    class EditorWindowT; 
    3232 
    33     class CommandSetStringsT : public CommandT 
     33    template<class T> 
     34    class CommandSetWinPropT : public CommandT 
    3435    { 
    3536        public: 
    3637 
    37         CommandSetStringsT(GuiDocumentT* GuiDoc, const EditorWindowT* Win, const wxString& PropertyName, 
    38             ArrayT<std::string>& Strings, const ArrayT<std::string>& NewStrings); 
     38        CommandSetWinPropT(GuiDocumentT* GuiDoc, const EditorWindowT* Win, const wxString& PropName, T& Value, const T& NewValue); 
    3939 
    4040        // CommandT implementation. 
     
    4646        private: 
    4747 
    48         GuiDocumentT*             m_GuiDoc; 
    49         const EditorWindowT*      m_Win; 
    50         const wxString            m_PropertyName; 
    51         ArrayT<std::string>&      m_Strings; 
    52         const ArrayT<std::string> m_NewStrings; 
    53         const ArrayT<std::string> m_OldStrings; 
     48        GuiDocumentT*        m_GuiDoc; 
     49        const EditorWindowT* m_Win; 
     50        const wxString       m_PropName; 
     51        T&                   m_Value; 
     52        const T              m_NewValue; 
     53        const T              m_OldValue; 
    5454    }; 
    5555} 
  • cafu/trunk/CaWE/GuiEditor/Windows/EditorChoiceWindow.cpp

    r374 r378  
    2424#include "../GuiDocument.hpp" 
    2525#include "../Commands/ModifyWindow.hpp" 
    26 #include "../Commands/SetStrings.hpp" 
     26#include "../Commands/SetWinProp.hpp" 
    2727 
    2828#include "GuiSys/WindowChoice.hpp" 
     
    104104            NewStrings.PushBack(std::string(Tokenizer.GetNextToken())); 
    105105 
    106         ChildFrame->SubmitCommand(new CommandSetStringsT(m_GuiDoc, this, PropName, m_Choice->m_Choices, NewStrings)); 
     106        ChildFrame->SubmitCommand(new CommandSetWinPropT< ArrayT<std::string> >(m_GuiDoc, this, PropName, m_Choice->m_Choices, NewStrings)); 
    107107        return true; 
    108108    }