Ticket #2642: 2642.diff

File 2642.diff, 8.3 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"
     
    4950static HighResTimer g_Timer;
    5051
    5152using namespace AtlasMessage;
     53using std::vector;
    5254
    5355//////////////////////////////////////////////////////////////////////////
    5456
    enum  
    310312    ID_SaveAs,
    311313    ID_ImportHeightmap,
    312314
     315    ID_Copy,
     316    ID_Paste,
     317
    313318    ID_Wireframe,
    314319    ID_MessageTrace,
    315320    ID_Screenshot,
    BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame)  
    338343    EVT_MENU(ID_Quit, ScenarioEditor::OnQuit)
    339344    EVT_MENU(wxID_UNDO, ScenarioEditor::OnUndo)
    340345    EVT_MENU(wxID_REDO, ScenarioEditor::OnRedo)
     346    EVT_MENU(ID_Copy, ScenarioEditor::OnCopy)
     347    EVT_MENU(ID_Paste, ScenarioEditor::OnPaste)
    341348
    342349    EVT_MENU(ID_Wireframe, ScenarioEditor::OnWireframe)
    343350    EVT_MENU(ID_MessageTrace, ScenarioEditor::OnMessageTrace)
    BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame)  
    350357    EVT_MENU(ID_RenderPathFixed, ScenarioEditor::OnRenderPath)
    351358    EVT_MENU(ID_RenderPathShader, ScenarioEditor::OnRenderPath)
    352359
     360    EVT_MENU_OPEN(ScenarioEditor::OnMenuOpen)
     361
    353362    EVT_IDLE(ScenarioEditor::OnIdle)
    354363END_EVENT_TABLE()
    355364
    ScenarioEditor::ScenarioEditor(wxWindow* parent)  
    434443    {
    435444        menuEdit->Append(wxID_UNDO, _("&Undo"));
    436445        menuEdit->Append(wxID_REDO, _("&Redo"));
     446        menuEdit->AppendSeparator();
     447        menuEdit->Append(ID_Copy, _("&Copy"));
     448        menuEdit->Enable(ID_Copy, false);
     449        menuEdit->Append(ID_Paste, _("&Paste"));
    437450    }
    438451
     452    g_SelectedObjects.RegisterObserver(0, &ScenarioEditor::OnSelectedObjectsChange, this);
     453
    439454    GetCommandProc().SetEditMenu(menuEdit);
    440455    GetCommandProc().Initialize();
    441456
    void ScenarioEditor::OnRedo(wxCommandEvent&)  
    620635    GetCommandProc().Redo();
    621636}
    622637
     638void ScenarioEditor::OnCopy(wxCommandEvent&)
     639{
     640    if (0 == GetToolManager().GetCurrentToolName().Cmp(_T("TransformObject")))
     641    {
     642        GetToolManager().GetCurrentTool()->OnCommand(_T("copy"), NULL);
     643    }
     644}
     645
     646void ScenarioEditor::OnPaste(wxCommandEvent&)
     647{
     648    if (0 != GetToolManager().GetCurrentToolName().Cmp(_T("TransformObject")))
     649    {
     650        GetToolManager().SetCurrentTool(_T("TransformObject"), NULL);
     651    }
     652
     653    GetToolManager().GetCurrentTool()->OnCommand(_T("paste"), NULL);
     654}
     655
    623656//////////////////////////////////////////////////////////////////////////
    624657
    625658void ScenarioEditor::OnNew(wxCommandEvent& WXUNUSED(event))
    void ScenarioEditor::OnDumpState(wxCommandEvent& event)  
    865898    }
    866899}
    867900
     901void ScenarioEditor::OnSelectedObjectsChange(vector<ObjectID> const& selectedObjects)
     902{
     903    GetMenuBar()->Enable(ID_Copy, !selectedObjects.empty());
     904}
     905
     906void ScenarioEditor::OnMenuOpen(wxMenuEvent& event)
     907{
     908    // This could be done far more elegantly if wxMenuItem had changeable id.
     909    wxMenu* pasteMenuItem = NULL;
     910    event.GetMenu()->FindItem(ID_Paste, &pasteMenuItem);
     911
     912    if (pasteMenuItem)
     913    {
     914        bool hasContentToPaste = false;
     915        if (wxTheClipboard->Open())
     916        {
     917            if (wxTheClipboard->IsSupported(wxDF_TEXT))
     918            {
     919                wxTextDataObject data;
     920                wxTheClipboard->GetData(data);
     921                hasContentToPaste = !data.GetText().empty();
     922            }
     923
     924            wxTheClipboard->Close();
     925        }
     926
     927        GetMenuBar()->Enable(ID_Paste, hasContentToPaste);
     928    }
     929}
     930
    868931
    869932//////////////////////////////////////////////////////////////////////////
    870933
  • 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 (0 == command.Cmp(_T("copy")))
     56        {
     57            OnCopy();
     58        }
     59        else if (0 == command.Cmp(_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                {