Ticket #2642: 2642_2.diff

File 2642_2.diff, 8.1 KB (added by stilz_, 10 years ago)
  • source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp

     
    2020#include "ScenarioEditor.h"
    2121
    2222#include "wx/busyinfo.h"
     23#include "wx/clipbrd.h"
    2324#include "wx/config.h"
    2425#include "wx/dir.h"
    2526#include "wx/evtloop.h"
    enum  
    310311    ID_SaveAs,
    311312    ID_ImportHeightmap,
    312313
     314    ID_Copy,
     315    ID_Paste,
     316
    313317    ID_Wireframe,
    314318    ID_MessageTrace,
    315319    ID_Screenshot,
    BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame)  
    338342    EVT_MENU(ID_Quit, ScenarioEditor::OnQuit)
    339343    EVT_MENU(wxID_UNDO, ScenarioEditor::OnUndo)
    340344    EVT_MENU(wxID_REDO, ScenarioEditor::OnRedo)
     345    EVT_MENU(ID_Copy, ScenarioEditor::OnCopy)
     346    EVT_MENU(ID_Paste, ScenarioEditor::OnPaste)
    341347
    342348    EVT_MENU(ID_Wireframe, ScenarioEditor::OnWireframe)
    343349    EVT_MENU(ID_MessageTrace, ScenarioEditor::OnMessageTrace)
    BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame)  
    350356    EVT_MENU(ID_RenderPathFixed, ScenarioEditor::OnRenderPath)
    351357    EVT_MENU(ID_RenderPathShader, ScenarioEditor::OnRenderPath)
    352358
     359    EVT_MENU_OPEN(ScenarioEditor::OnMenuOpen)
     360
    353361    EVT_IDLE(ScenarioEditor::OnIdle)
    354362END_EVENT_TABLE()
    355363
    ScenarioEditor::ScenarioEditor(wxWindow* parent)  
    434442    {
    435443        menuEdit->Append(wxID_UNDO, _("&Undo"));
    436444        menuEdit->Append(wxID_REDO, _("&Redo"));
     445        menuEdit->AppendSeparator();
     446        menuEdit->Append(ID_Copy, _("&Copy"));
     447        menuEdit->Enable(ID_Copy, false);
     448        menuEdit->Append(ID_Paste, _("&Paste"));
    437449    }
    438450
     451    g_SelectedObjects.RegisterObserver(0, &ScenarioEditor::OnSelectedObjectsChange, this);
     452
    439453    GetCommandProc().SetEditMenu(menuEdit);
    440454    GetCommandProc().Initialize();
    441455
    void ScenarioEditor::OnRedo(wxCommandEvent&)  
    620634    GetCommandProc().Redo();
    621635}
    622636
     637void ScenarioEditor::OnCopy(wxCommandEvent&)
     638{
     639    if (GetToolManager().GetCurrentToolName() == _T("TransformObject"))
     640    {
     641        GetToolManager().GetCurrentTool()->OnCommand(_T("copy"), NULL);
     642    }
     643}
     644
     645void ScenarioEditor::OnPaste(wxCommandEvent&)
     646{
     647    if (GetToolManager().GetCurrentToolName() != _T("TransformObject"))
     648    {
     649        GetToolManager().SetCurrentTool(_T("TransformObject"), NULL);
     650    }
     651
     652    GetToolManager().GetCurrentTool()->OnCommand(_T("paste"), NULL);
     653}
     654
    623655//////////////////////////////////////////////////////////////////////////
    624656
    625657void ScenarioEditor::OnNew(wxCommandEvent& WXUNUSED(event))
    void ScenarioEditor::OnDumpState(wxCommandEvent& event)  
    865897    }
    866898}
    867899
     900void ScenarioEditor::OnSelectedObjectsChange(std::vector<ObjectID> const& selectedObjects)
     901{
     902    GetMenuBar()->Enable(ID_Copy, !selectedObjects.empty());
     903}
     904
     905void ScenarioEditor::OnMenuOpen(wxMenuEvent& event)
     906{
     907    // This could be done far more elegantly if wxMenuItem had changeable id.
     908    wxMenu* pasteMenuItem = NULL;
     909    event.GetMenu()->FindItem(ID_Paste, &pasteMenuItem);
     910
     911    if (pasteMenuItem)
     912    {
     913        bool hasContentToPaste = false;
     914        if (wxTheClipboard->Open())
     915        {
     916            if (wxTheClipboard->IsSupported(wxDF_TEXT))
     917            {
     918                wxTextDataObject data;
     919                wxTheClipboard->GetData(data);
     920                hasContentToPaste = !data.GetText().empty();
     921            }
     922
     923            wxTheClipboard->Close();
     924        }
     925
     926        GetMenuBar()->Enable(ID_Paste, hasContentToPaste);
     927    }
     928}
     929
    868930
    869931//////////////////////////////////////////////////////////////////////////
    870932
  • source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h

    public:  
    4646    void OnQuit(wxCommandEvent& event);
    4747    void OnUndo(wxCommandEvent& event);
    4848    void OnRedo(wxCommandEvent& event);
     49    void OnCopy(wxCommandEvent& event);
     50    void OnPaste(wxCommandEvent& event);
    4951
    5052    void OnWireframe(wxCommandEvent& event);
    5153    void OnMessageTrace(wxCommandEvent& event);
    public:  
    5557    void OnCameraReset(wxCommandEvent& event);
    5658    void OnRenderPath(wxCommandEvent& event);
    5759    void OnDumpState(wxCommandEvent& event);
     60    void OnSelectedObjectsChange(std::vector<AtlasMessage::ObjectID> const& selectedObjects);
     61
     62    void OnMenuOpen(wxMenuEvent& event);
    5863
    5964    bool OpenFile(const wxString& name, const wxString& filename);
    6065
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp

    class DummyTool : public ITool  
    2828    bool OnMouse(wxMouseEvent& WXUNUSED(evt)) { return false; }
    2929    bool OnKey(wxKeyEvent& WXUNUSED(evt), KeyEventType) { return false; }
    3030    void OnTick(float) {}
     31    void OnCommand(wxString const&, void*) {}
    3132} dummy;
    3233
    3334struct ToolManagerImpl
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h

    public:  
    3535    virtual bool OnMouse(wxMouseEvent& evt) = 0; // return true if handled
    3636    virtual bool OnKey(wxKeyEvent& evt, KeyEventType dir) = 0; // return true if handled
    3737    virtual void OnTick(float dt) = 0; // dt in seconds
     38    virtual void OnCommand(wxString const& command, void * userData) = 0;
    3839
    3940    virtual ~ITool() {};
    4041};
    private:  
    166167    {
    167168        m_CurrentState->OnTick(static_cast<T*>(this), dt);
    168169    }
     170
     171    virtual void OnCommand(wxString const&, void*)
     172    {
     173    }
    169174};
    170175
    171176
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp

    public:  
    5050        SetState(&Waiting);
    5151    }
    5252
     53    virtual void OnCommand(wxString const& command, void*)
     54    {
     55        if (command == _T("copy"))
     56        {
     57            OnCopy();
     58        }
     59        else if (command == _T("paste"))
     60        {
     61            OnPasteStart();
     62        }
     63    }
     64
    5365    void OnDisable()
    5466    {
    5567        g_SelectedObjects.clear();
    public:  
    5769        POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects));
    5870    }
    5971
     72    bool OnCopy() const
     73    {
     74        if (!g_SelectedObjects.empty())
     75        {
     76            // COPY current selections
     77            AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects);
     78            info.Post();
     79
     80            // In xmldata is the configuration
     81            // now send to clipboard
     82            if (wxTheClipboard->Open())
     83            {
     84                wxString text(info.xmldata.c_str());
     85                wxTheClipboard->SetData(new wxTextDataObject(text));
     86                wxTheClipboard->Close();
     87            }
     88            else
     89            {
     90                // TODO: Say something about couldnt open clipboard
     91            }
     92
     93            return true;
     94        }
     95
     96        return false;
     97    }
     98
    6099    void OnPasteStart()
    61100    {
    62101        //PASTE
    public:  
    321360            {
    322361                if (evt.GetKeyCode() == 'C')
    323362                {
    324                     if (!g_SelectedObjects.empty())
    325                     {
    326                         //COPY current selections
    327                         AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects);
    328                         info.Post();
    329 
    330                         //In xmldata is the configuration
    331                         //now send to clipboard
    332                         if (wxTheClipboard->Open())
    333                         {
    334                             wxString text(info.xmldata.c_str());
    335                             wxTheClipboard->SetData(new wxTextDataObject(text));
    336                             wxTheClipboard->Close();
    337                         }
    338                         else
    339                         {
    340                             //TODO: Say something about couldnt open clipboard
    341                         }
    342                         return true;
    343                     }
     363                    return obj->OnCopy();
    344364                }
    345365                else if (evt.GetKeyCode() == 'V')
    346366                {