Commit: [33ma767c6dc3829bda8c0d46881547807809a05bbce
Author: [32mSławomir Zborowski <slawomir.zborowski@nsn.com>
Date: ([31m4 months ago[m) 2014-07-09 18:27:23 +0200
Subject: #2642: Add Copy and Paste to the Edit menu in Atlas
diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
index 0065c13..d30eac3 100644
a
|
b
|
|
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& WXUNUSED(event)) |
| 642 | { |
| 643 | if (GetToolManager().GetCurrentToolName() == _T("TransformObject")) |
| 644 | GetToolManager().GetCurrentTool()->OnCommand(_T("copy"), NULL); |
| 645 | } |
| 646 | |
| 647 | void ScenarioEditor::OnPaste(wxCommandEvent& WXUNUSED(event)) |
| 648 | { |
| 649 | if (GetToolManager().GetCurrentToolName() != _T("TransformObject")) |
| 650 | GetToolManager().SetCurrentTool(_T("TransformObject"), NULL); |
| 651 | |
| 652 | GetToolManager().GetCurrentTool()->OnCommand(_T("paste"), NULL); |
| 653 | } |
| 654 | |
624 | 655 | ////////////////////////////////////////////////////////////////////////// |
625 | 656 | |
626 | 657 | void ScenarioEditor::OnNew(wxCommandEvent& WXUNUSED(event)) |
… |
… |
void ScenarioEditor::OnDumpState(wxCommandEvent& event)
|
866 | 897 | } |
867 | 898 | } |
868 | 899 | |
| 900 | void ScenarioEditor::OnSelectedObjectsChange(const std::vector<ObjectID>& 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 | GetMenuBar()->Enable(ID_Paste, false); |
| 912 | |
| 913 | if (!pasteMenuItem) |
| 914 | return; |
| 915 | |
| 916 | wxString content; |
| 917 | if (wxTheClipboard->Open()) |
| 918 | { |
| 919 | if (wxTheClipboard->IsSupported(wxDF_TEXT)) |
| 920 | { |
| 921 | wxTextDataObject data; |
| 922 | wxTheClipboard->GetData(data); |
| 923 | content = data.GetText(); |
| 924 | } |
| 925 | |
| 926 | wxTheClipboard->Close(); |
| 927 | } |
| 928 | |
| 929 | if (content.empty()) |
| 930 | return; |
| 931 | |
| 932 | wxInputStream* is = new wxStringInputStream(content); |
| 933 | wxXmlDocument doc; |
| 934 | { |
| 935 | wxLogNull stopComplaining; |
| 936 | static_cast<void>(stopComplaining); |
| 937 | if (!doc.Load(*is)) |
| 938 | return; |
| 939 | } |
| 940 | |
| 941 | wxXmlNode* root = doc.GetRoot(); |
| 942 | if (!root || root->GetName() != wxT("Entities")) |
| 943 | return; |
| 944 | |
| 945 | GetMenuBar()->Enable(ID_Paste, true); |
| 946 | } |
| 947 | |
869 | 948 | |
870 | 949 | ////////////////////////////////////////////////////////////////////////// |
871 | 950 | |
diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h
index e3c16ea..9eb95b8 100644
a
|
b
|
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(const std::vector<AtlasMessage::ObjectID>& selectedObjects); |
| 61 | |
| 62 | void OnMenuOpen(wxMenuEvent& event); |
58 | 63 | |
59 | 64 | bool OpenFile(const wxString& name, const wxString& filename); |
60 | 65 | |
diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp
index 7327362..767a357 100644
a
|
b
|
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(const wxString& WXUNUSED(comand), void* WXUNUSED(userData)) {} |
31 | 32 | } dummy; |
32 | 33 | |
33 | 34 | struct ToolManagerImpl |
diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h
index de338f4..181666d 100644
a
|
b
|
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(const wxString& 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(const wxString& WXUNUSED(command), void* WXUNUSED(userData)) |
| 172 | { |
| 173 | } |
169 | 174 | }; |
170 | 175 | |
171 | 176 | |
diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp
index 375e0c8..50f95b6 100644
a
|
b
|
public:
|
50 | 50 | SetState(&Waiting); |
51 | 51 | } |
52 | 52 | |
| 53 | virtual void OnCommand(const wxString& command, void* WXUNUSED(userData)) |
| 54 | { |
| 55 | if (command == _T("copy")) |
| 56 | OnCopy(); |
| 57 | else if (command == _T("paste")) |
| 58 | OnPasteStart(); |
| 59 | } |
| 60 | |
53 | 61 | void OnDisable() |
54 | 62 | { |
55 | 63 | g_SelectedObjects.clear(); |
… |
… |
public:
|
57 | 65 | POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); |
58 | 66 | } |
59 | 67 | |
| 68 | bool OnCopy() const |
| 69 | { |
| 70 | if (g_SelectedObjects.empty()) |
| 71 | return false; |
| 72 | |
| 73 | AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects); |
| 74 | info.Post(); |
| 75 | |
| 76 | if (wxTheClipboard->Open()) |
| 77 | { |
| 78 | wxString text(info.xmldata.c_str()); |
| 79 | wxTheClipboard->SetData(new wxTextDataObject(text)); |
| 80 | wxTheClipboard->Close(); |
| 81 | } |
| 82 | |
| 83 | return true; |
| 84 | } |
| 85 | |
60 | 86 | void OnPasteStart() |
61 | 87 | { |
62 | | //PASTE |
63 | 88 | wxString entities; |
64 | 89 | if (wxTheClipboard->Open()) |
65 | 90 | { |
… |
… |
public:
|
71 | 96 | } |
72 | 97 | wxTheClipboard->Close(); |
73 | 98 | } |
74 | | else |
75 | | { |
76 | | //TODO: Show something when the clipboard couldnt open |
77 | | } |
78 | 99 | |
79 | | //First do we need to check if it is a correct xml string |
| 100 | // First do we need to check if it is a correct xml string |
80 | 101 | wxInputStream* is = new wxStringInputStream(entities); |
81 | 102 | wxXmlDocument doc; |
82 | 103 | if (!doc.Load(*is)) |
… |
… |
public:
|
87 | 108 | if (root->GetName() != wxT("Entities")) |
88 | 109 | return; |
89 | 110 | |
90 | | // Template, position,orientation |
| 111 | // Template, position,orientation |
91 | 112 | const wxXmlNode* child = root->GetChildren(); |
92 | 113 | |
93 | 114 | while (child) |
… |
… |
public:
|
95 | 116 | if (child->GetName() != wxT("Entity")) |
96 | 117 | return; |
97 | 118 | |
98 | | //TODO Validate all attributes |
99 | 119 | child = child->GetNext(); |
100 | 120 | } |
101 | 121 | |
102 | | //Update selectedObjects?? |
103 | 122 | g_SelectedObjects.clear(); |
104 | 123 | POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); |
105 | 124 | |
… |
… |
public:
|
329 | 348 | { |
330 | 349 | if (evt.GetKeyCode() == 'C') |
331 | 350 | { |
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 | | } |
| 351 | return obj->OnCopy(); |
352 | 352 | } |
353 | 353 | else if (evt.GetKeyCode() == 'V') |
354 | 354 | { |