Ticket #2642: 2642_3.diff
File 2642_3.diff, 9.6 KB (added by , 9 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" 26 27 #include "wx/ffile.h" 27 28 #include "wx/filename.h" 28 29 #include "wx/image.h" 30 #include "wx/sstream.h" 29 31 #include "wx/sysopt.h" 30 32 #include "wx/tooltip.h" 33 #include "wx/xml/xml.h" 31 34 32 35 #include "General/AtlasEventLoop.h" 33 36 #include "General/Datafile.h" … … enum 310 313 ID_SaveAs, 311 314 ID_ImportHeightmap, 312 315 316 ID_Copy, 317 ID_Paste, 318 313 319 ID_Wireframe, 314 320 ID_MessageTrace, 315 321 ID_Screenshot, … … BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) 338 344 EVT_MENU(ID_Quit, ScenarioEditor::OnQuit) 339 345 EVT_MENU(wxID_UNDO, ScenarioEditor::OnUndo) 340 346 EVT_MENU(wxID_REDO, ScenarioEditor::OnRedo) 347 EVT_MENU(ID_Copy, ScenarioEditor::OnCopy) 348 EVT_MENU(ID_Paste, ScenarioEditor::OnPaste) 341 349 342 350 EVT_MENU(ID_Wireframe, ScenarioEditor::OnWireframe) 343 351 EVT_MENU(ID_MessageTrace, ScenarioEditor::OnMessageTrace) … … BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) 350 358 EVT_MENU(ID_RenderPathFixed, ScenarioEditor::OnRenderPath) 351 359 EVT_MENU(ID_RenderPathShader, ScenarioEditor::OnRenderPath) 352 360 361 EVT_MENU_OPEN(ScenarioEditor::OnMenuOpen) 362 353 363 EVT_IDLE(ScenarioEditor::OnIdle) 354 364 END_EVENT_TABLE() 355 365 … … ScenarioEditor::ScenarioEditor(wxWindow* parent) 435 445 { 436 446 menuEdit->Append(wxID_UNDO, _("&Undo")); 437 447 menuEdit->Append(wxID_REDO, _("&Redo")); 448 menuEdit->AppendSeparator(); 449 menuEdit->Append(ID_Copy, _("&Copy")); 450 menuEdit->Enable(ID_Copy, false); 451 menuEdit->Append(ID_Paste, _("&Paste")); 452 menuEdit->Enable(ID_Paste, false); 438 453 } 439 454 455 g_SelectedObjects.RegisterObserver(0, &ScenarioEditor::OnSelectedObjectsChange, this); 456 440 457 GetCommandProc().SetEditMenu(menuEdit); 441 458 GetCommandProc().Initialize(); 442 459 … … void ScenarioEditor::OnRedo(wxCommandEvent&) 621 638 GetCommandProc().Redo(); 622 639 } 623 640 641 void ScenarioEditor::OnCopy(wxCommandEvent&) 642 { 643 if (GetToolManager().GetCurrentToolName() == _T("TransformObject")) 644 { 645 GetToolManager().GetCurrentTool()->OnCommand(_T("copy"), NULL); 646 } 647 } 648 649 void ScenarioEditor::OnPaste(wxCommandEvent&) 650 { 651 if (GetToolManager().GetCurrentToolName() != _T("TransformObject")) 652 { 653 GetToolManager().SetCurrentTool(_T("TransformObject"), NULL); 654 } 655 656 GetToolManager().GetCurrentTool()->OnCommand(_T("paste"), NULL); 657 } 658 624 659 ////////////////////////////////////////////////////////////////////////// 625 660 626 661 void ScenarioEditor::OnNew(wxCommandEvent& WXUNUSED(event)) … … void ScenarioEditor::OnDumpState(wxCommandEvent& event) 866 901 } 867 902 } 868 903 904 void ScenarioEditor::OnSelectedObjectsChange(std::vector<ObjectID> const& selectedObjects) 905 { 906 GetMenuBar()->Enable(ID_Copy, !selectedObjects.empty()); 907 } 908 909 void ScenarioEditor::OnMenuOpen(wxMenuEvent& event) 910 { 911 // This could be done far more elegantly if wxMenuItem had changeable id. 912 wxMenu* pasteMenuItem = NULL; 913 event.GetMenu()->FindItem(ID_Paste, &pasteMenuItem); 914 915 if (!pasteMenuItem) 916 { 917 GetMenuBar()->Enable(ID_Paste, false); 918 return; 919 } 920 921 wxString content; 922 if (wxTheClipboard->Open()) 923 { 924 if (wxTheClipboard->IsSupported(wxDF_TEXT)) 925 { 926 wxTextDataObject data; 927 wxTheClipboard->GetData(data); 928 content = data.GetText(); 929 } 930 931 wxTheClipboard->Close(); 932 } 933 else 934 { 935 GetMenuBar()->Enable(ID_Paste, false); 936 return; 937 } 938 939 if (content.empty()) 940 { 941 GetMenuBar()->Enable(ID_Paste, false); 942 return; 943 } 944 945 wxInputStream* is = new wxStringInputStream(content); 946 wxXmlDocument doc; 947 { 948 wxLogNull stopComplaining; 949 static_cast<void>(stopComplaining); 950 if (!doc.Load(*is)) 951 { 952 GetMenuBar()->Enable(ID_Paste, false); 953 return; 954 } 955 } 956 957 wxXmlNode* root = doc.GetRoot(); 958 if (root->GetName() != wxT("Entities")) 959 { 960 GetMenuBar()->Enable(ID_Paste, false); 961 return; 962 } 963 964 GetMenuBar()->Enable(ID_Paste, true); 965 } 966 869 967 870 968 ////////////////////////////////////////////////////////////////////////// 871 969 -
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 return false; 77 } 78 79 AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects); 80 info.Post(); 81 82 if (wxTheClipboard->Open()) 83 { 84 wxString text(info.xmldata.c_str()); 85 wxTheClipboard->SetData(new wxTextDataObject(text)); 86 wxTheClipboard->Close(); 87 } 88 89 return true; 90 } 91 60 92 void OnPasteStart() 61 93 { 62 //PASTE63 94 wxString entities; 64 95 if (wxTheClipboard->Open()) 65 96 { … … public: 71 102 } 72 103 wxTheClipboard->Close(); 73 104 } 74 else75 {76 //TODO: Show something when the clipboard couldnt open77 }78 105 79 // First do we need to check if it is a correct xml string106 // First do we need to check if it is a correct xml string 80 107 wxInputStream* is = new wxStringInputStream(entities); 81 108 wxXmlDocument doc; 82 109 if (!doc.Load(*is)) … … public: 87 114 if (root->GetName() != wxT("Entities")) 88 115 return; 89 116 90 // 117 // Template, position,orientation 91 118 const wxXmlNode* child = root->GetChildren(); 92 119 93 120 while (child) … … public: 95 122 if (child->GetName() != wxT("Entity")) 96 123 return; 97 124 98 //TODO Validate all attributes99 125 child = child->GetNext(); 100 126 } 101 127 102 //Update selectedObjects??103 128 g_SelectedObjects.clear(); 104 129 POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); 105 130 … … public: 329 354 { 330 355 if (evt.GetKeyCode() == 'C') 331 356 { 332 if (!g_SelectedObjects.empty()) 333 { 334 //COPY current selections 335 AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects); 336 info.Post(); 337 338 //In xmldata is the configuration 339 //now send to clipboard 340 if (wxTheClipboard->Open()) 341 { 342 wxString text(info.xmldata.c_str()); 343 wxTheClipboard->SetData(new wxTextDataObject(text)); 344 wxTheClipboard->Close(); 345 } 346 else 347 { 348 //TODO: Say something about couldnt open clipboard 349 } 350 return true; 351 } 357 return obj->OnCopy(); 352 358 } 353 359 else if (evt.GetKeyCode() == 'V') 354 360 {