Ticket #2642: 2642_2.diff
File 2642_2.diff, 8.1 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" … … enum 310 311 ID_SaveAs, 311 312 ID_ImportHeightmap, 312 313 314 ID_Copy, 315 ID_Paste, 316 313 317 ID_Wireframe, 314 318 ID_MessageTrace, 315 319 ID_Screenshot, … … BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) 338 342 EVT_MENU(ID_Quit, ScenarioEditor::OnQuit) 339 343 EVT_MENU(wxID_UNDO, ScenarioEditor::OnUndo) 340 344 EVT_MENU(wxID_REDO, ScenarioEditor::OnRedo) 345 EVT_MENU(ID_Copy, ScenarioEditor::OnCopy) 346 EVT_MENU(ID_Paste, ScenarioEditor::OnPaste) 341 347 342 348 EVT_MENU(ID_Wireframe, ScenarioEditor::OnWireframe) 343 349 EVT_MENU(ID_MessageTrace, ScenarioEditor::OnMessageTrace) … … BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) 350 356 EVT_MENU(ID_RenderPathFixed, ScenarioEditor::OnRenderPath) 351 357 EVT_MENU(ID_RenderPathShader, ScenarioEditor::OnRenderPath) 352 358 359 EVT_MENU_OPEN(ScenarioEditor::OnMenuOpen) 360 353 361 EVT_IDLE(ScenarioEditor::OnIdle) 354 362 END_EVENT_TABLE() 355 363 … … ScenarioEditor::ScenarioEditor(wxWindow* parent) 434 442 { 435 443 menuEdit->Append(wxID_UNDO, _("&Undo")); 436 444 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")); 437 449 } 438 450 451 g_SelectedObjects.RegisterObserver(0, &ScenarioEditor::OnSelectedObjectsChange, this); 452 439 453 GetCommandProc().SetEditMenu(menuEdit); 440 454 GetCommandProc().Initialize(); 441 455 … … void ScenarioEditor::OnRedo(wxCommandEvent&) 620 634 GetCommandProc().Redo(); 621 635 } 622 636 637 void ScenarioEditor::OnCopy(wxCommandEvent&) 638 { 639 if (GetToolManager().GetCurrentToolName() == _T("TransformObject")) 640 { 641 GetToolManager().GetCurrentTool()->OnCommand(_T("copy"), NULL); 642 } 643 } 644 645 void 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 623 655 ////////////////////////////////////////////////////////////////////////// 624 656 625 657 void ScenarioEditor::OnNew(wxCommandEvent& WXUNUSED(event)) … … void ScenarioEditor::OnDumpState(wxCommandEvent& event) 865 897 } 866 898 } 867 899 900 void ScenarioEditor::OnSelectedObjectsChange(std::vector<ObjectID> const& selectedObjects) 901 { 902 GetMenuBar()->Enable(ID_Copy, !selectedObjects.empty()); 903 } 904 905 void 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 868 930 869 931 ////////////////////////////////////////////////////////////////////////// 870 932 -
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 (command == _T("copy")) 56 { 57 OnCopy(); 58 } 59 else if (command == _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 {