Ticket #2642: 2642.diff
File 2642.diff, 8.3 KB (added by , 10 years ago) |
---|
-
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
20 20 #include "ScenarioEditor.h" 21 21 22 22 #include "wx/busyinfo.h" 23 #include "wx/clipbrd.h" 23 24 #include "wx/config.h" 24 25 #include "wx/dir.h" 25 26 #include "wx/evtloop.h" … … 49 50 static HighResTimer g_Timer; 50 51 51 52 using namespace AtlasMessage; 53 using std::vector; 52 54 53 55 ////////////////////////////////////////////////////////////////////////// 54 56 … … enum 310 312 ID_SaveAs, 311 313 ID_ImportHeightmap, 312 314 315 ID_Copy, 316 ID_Paste, 317 313 318 ID_Wireframe, 314 319 ID_MessageTrace, 315 320 ID_Screenshot, … … BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) 338 343 EVT_MENU(ID_Quit, ScenarioEditor::OnQuit) 339 344 EVT_MENU(wxID_UNDO, ScenarioEditor::OnUndo) 340 345 EVT_MENU(wxID_REDO, ScenarioEditor::OnRedo) 346 EVT_MENU(ID_Copy, ScenarioEditor::OnCopy) 347 EVT_MENU(ID_Paste, ScenarioEditor::OnPaste) 341 348 342 349 EVT_MENU(ID_Wireframe, ScenarioEditor::OnWireframe) 343 350 EVT_MENU(ID_MessageTrace, ScenarioEditor::OnMessageTrace) … … BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) 350 357 EVT_MENU(ID_RenderPathFixed, ScenarioEditor::OnRenderPath) 351 358 EVT_MENU(ID_RenderPathShader, ScenarioEditor::OnRenderPath) 352 359 360 EVT_MENU_OPEN(ScenarioEditor::OnMenuOpen) 361 353 362 EVT_IDLE(ScenarioEditor::OnIdle) 354 363 END_EVENT_TABLE() 355 364 … … ScenarioEditor::ScenarioEditor(wxWindow* parent) 434 443 { 435 444 menuEdit->Append(wxID_UNDO, _("&Undo")); 436 445 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")); 437 450 } 438 451 452 g_SelectedObjects.RegisterObserver(0, &ScenarioEditor::OnSelectedObjectsChange, this); 453 439 454 GetCommandProc().SetEditMenu(menuEdit); 440 455 GetCommandProc().Initialize(); 441 456 … … void ScenarioEditor::OnRedo(wxCommandEvent&) 620 635 GetCommandProc().Redo(); 621 636 } 622 637 638 void ScenarioEditor::OnCopy(wxCommandEvent&) 639 { 640 if (0 == GetToolManager().GetCurrentToolName().Cmp(_T("TransformObject"))) 641 { 642 GetToolManager().GetCurrentTool()->OnCommand(_T("copy"), NULL); 643 } 644 } 645 646 void 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 623 656 ////////////////////////////////////////////////////////////////////////// 624 657 625 658 void ScenarioEditor::OnNew(wxCommandEvent& WXUNUSED(event)) … … void ScenarioEditor::OnDumpState(wxCommandEvent& event) 865 898 } 866 899 } 867 900 901 void ScenarioEditor::OnSelectedObjectsChange(vector<ObjectID> const& selectedObjects) 902 { 903 GetMenuBar()->Enable(ID_Copy, !selectedObjects.empty()); 904 } 905 906 void 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 868 931 869 932 ////////////////////////////////////////////////////////////////////////// 870 933 -
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h
public: 46 46 void OnQuit(wxCommandEvent& event); 47 47 void OnUndo(wxCommandEvent& event); 48 48 void OnRedo(wxCommandEvent& event); 49 void OnCopy(wxCommandEvent& event); 50 void OnPaste(wxCommandEvent& event); 49 51 50 52 void OnWireframe(wxCommandEvent& event); 51 53 void OnMessageTrace(wxCommandEvent& event); … … public: 55 57 void OnCameraReset(wxCommandEvent& event); 56 58 void OnRenderPath(wxCommandEvent& event); 57 59 void OnDumpState(wxCommandEvent& event); 60 void OnSelectedObjectsChange(std::vector<AtlasMessage::ObjectID> const& selectedObjects); 61 62 void OnMenuOpen(wxMenuEvent& event); 58 63 59 64 bool OpenFile(const wxString& name, const wxString& filename); 60 65 -
source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp
class DummyTool : public ITool 28 28 bool OnMouse(wxMouseEvent& WXUNUSED(evt)) { return false; } 29 29 bool OnKey(wxKeyEvent& WXUNUSED(evt), KeyEventType) { return false; } 30 30 void OnTick(float) {} 31 void OnCommand(wxString const&, void*) {} 31 32 } dummy; 32 33 33 34 struct ToolManagerImpl -
source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h
public: 35 35 virtual bool OnMouse(wxMouseEvent& evt) = 0; // return true if handled 36 36 virtual bool OnKey(wxKeyEvent& evt, KeyEventType dir) = 0; // return true if handled 37 37 virtual void OnTick(float dt) = 0; // dt in seconds 38 virtual void OnCommand(wxString const& command, void * userData) = 0; 38 39 39 40 virtual ~ITool() {}; 40 41 }; … … private: 166 167 { 167 168 m_CurrentState->OnTick(static_cast<T*>(this), dt); 168 169 } 170 171 virtual void OnCommand(wxString const&, void*) 172 { 173 } 169 174 }; 170 175 171 176 -
source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp
public: 50 50 SetState(&Waiting); 51 51 } 52 52 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 53 65 void OnDisable() 54 66 { 55 67 g_SelectedObjects.clear(); … … public: 57 69 POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); 58 70 } 59 71 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 60 99 void OnPasteStart() 61 100 { 62 101 //PASTE … … public: 321 360 { 322 361 if (evt.GetKeyCode() == 'C') 323 362 { 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(); 344 364 } 345 365 else if (evt.GetKeyCode() == 'V') 346 366 {