| 1 |
#include "wxguicraft_main_view.h" |
| 2 |
|
| 3 |
#include "AuiToolBarTopLevel.h" |
| 4 |
#include "EventsEditorDlg.h" |
| 5 |
#include "ToolBoxPanel.h" |
| 6 |
#include "allocator_mgr.h" |
| 7 |
#include "attribute_style.h" |
| 8 |
#include "button_wrapper.h" |
| 9 |
#include "cl_command_event.h" |
| 10 |
#include "ctags_manager.h" |
| 11 |
#include "custom_control_wrapper.h" |
| 12 |
#include "designer_panel.h" |
| 13 |
#include "dialog_wrapper.h" |
| 14 |
#include "duplicateTLWdlg.h" |
| 15 |
#include "editor_config.h" |
| 16 |
#include "event_notifier.h" |
| 17 |
#include "file_logger.h" |
| 18 |
#include "fileextmanager.h" |
| 19 |
#include "fileutils.h" |
| 20 |
#include "flexgridsizer_wrapper.h" |
| 21 |
#include "frame_wrapper.h" |
| 22 |
#include "globals.h" |
| 23 |
#include "myxh_grid.h" |
| 24 |
#include "myxh_listc.h" |
| 25 |
#include "myxh_richtext.h" |
| 26 |
#include "myxh_searchctrl.h" |
| 27 |
#include "myxh_toolbk.h" |
| 28 |
#include "myxh_treebk.h" |
| 29 |
#include "notebook_base_wrapper.h" |
| 30 |
#include "notebook_page_wrapper.h" |
| 31 |
#include "panel_wrapper_top_level.h" |
| 32 |
#include "plugin.h" |
| 33 |
#include "popup_window_preview.h" |
| 34 |
#include "popup_window_wrapper.h" |
| 35 |
#include "preview_dialog.h" |
| 36 |
#include "preview_frame.h" |
| 37 |
#include "preview_panel.h" |
| 38 |
#include "preview_wizard.h" |
| 39 |
#include "ribbon_bar_wrapper.h" |
| 40 |
#include "ribbon_page_wrapper.h" |
| 41 |
#include "tool_bar_item_wrapper.h" |
| 42 |
#include "wizard_wrapper.h" |
| 43 |
#include "wxcTreeView.h" |
| 44 |
#include "wxc_bitmap_code_generator.h" |
| 45 |
#include "wxc_edit_manager.h" |
| 46 |
#include "wxc_settings.h" |
| 47 |
#include "wxcrafter_plugin.h" |
| 48 |
#include "wxgui_bitmaploader.h" |
| 49 |
#include "wxgui_helpers.h" |
| 50 |
#include "xy_pair.h" |
| 51 |
|
| 52 |
#include <algorithm> |
| 53 |
#include <set> |
| 54 |
#include <wx/app.h> |
| 55 |
#include <wx/busyinfo.h> |
| 56 |
#include <wx/ffile.h> |
| 57 |
#include <wx/filedlg.h> |
| 58 |
#include <wx/imaggif.h> |
| 59 |
#include <wx/imaglist.h> |
| 60 |
#include <wx/infobar.h> |
| 61 |
#include <wx/log.h> |
| 62 |
#include <wx/menu.h> |
| 63 |
#include <wx/msgdlg.h> |
| 64 |
#include <wx/sstream.h> |
| 65 |
#include <wx/textdlg.h> |
| 66 |
#include <wx/utils.h> |
| 67 |
#include <wx/wupdlock.h> |
| 68 |
#include <wx/xrc/xmlres.h> |
| 69 |
#if defined(__WXOSX__) |
| 70 |
#include <wx/osx/tooltip.h> |
| 71 |
#endif |
| 72 |
|
| 73 |
GUICraftMainPanel* GUICraftMainPanel::m_MainPanel = NULL; |
| 74 |
|
| 75 |
const wxString SIMPLE_BORDER_CODE = R"( |
| 76 |
namespace { |
| 77 |
// return the wxBORDER_SIMPLE that matches the current application theme |
| 78 |
wxBorder get_border_simple_theme_aware_bit() { |
| 79 |
#if wxVERSION_NUMBER >= 3300 && defined(__WXMSW__) |
| 80 |
return wxSystemSettings::GetAppearance().IsDark() ? wxBORDER_SIMPLE : wxBORDER_STATIC; |
| 81 |
#else |
| 82 |
return wxBORDER_DEFAULT; |
| 83 |
#endif |
| 84 |
} // DoGetBorderSimpleBit |
| 85 |
bool bBitmapLoaded = false; |
| 86 |
} // namespace |
| 87 |
|
| 88 |
)"; |
| 89 |
|
| 90 |
static bool bManualSelection = false; |
| 91 |
|
| 92 |
#define MENU_ENTRY(id, label, bmpname) \ |
| 93 |
menuItem = new wxMenuItem(&menu, id, label); \ |
| 94 |
menuItem->SetBitmap(bmpLoader.Bitmap(bmpname)); \ |
| 95 |
menu.Append(menuItem); |
| 96 |
|
| 97 |
#define MENU_SEPARATOR() menu.AppendSeparator(); |
| 98 |
|
| 99 |
BEGIN_EVENT_TABLE(GUICraftMainPanel, GUICraftMainPanelBase) |
| 100 |
|
| 101 |
EVT_MENU(ID_GENERATE_CODE, GUICraftMainPanel::OnGenerateCode) |
| 102 |
EVT_COMMAND_RANGE(ID_FIRST_CONTROL, ID_LAST_CONTROL - 1, wxEVT_COMMAND_BUTTON_CLICKED, GUICraftMainPanel::OnNewControl) |
| 103 |
EVT_COMMAND_RANGE(ID_CHANGE_SIZER_FIRST, ID_CHANGE_SIZER_LAST - 1, wxEVT_COMMAND_MENU_SELECTED, |
| 104 |
GUICraftMainPanel::OnChangeSizerType) |
| 105 |
EVT_COMMAND_RANGE(ID_INSERT_INTO_SIZER_FIRST, ID_INSERT_INTO_SIZER_LAST - 1, wxEVT_COMMAND_MENU_SELECTED, |
| 106 |
GUICraftMainPanel::OnInsertIntoSizer) |
| 107 |
EVT_COMMAND(ID_WXCUSTOMCONTROL, wxEVT_COMMAND_BUTTON_CLICKED, GUICraftMainPanel::OnNewCustomControlMenu) |
| 108 |
EVT_MENU_RANGE(ID_FIRST_CONTROL, ID_LAST_CONTROL - 1, GUICraftMainPanel::OnNewControl) |
| 109 |
EVT_MENU(ID_DELETE_NODE, GUICraftMainPanel::OnDelete) |
| 110 |
EVT_MENU_RANGE(ID_MOVE_NODE_UP, ID_MOVE_NODE_INTO_SIBLING, GUICraftMainPanel::OnMoveItem) |
| 111 |
EVT_MENU(ID_SHOW_PREVIEW, GUICraftMainPanel::OnShowPreview) |
| 112 |
EVT_MENU(ID_CANCEL_PREVIEW, GUICraftMainPanel::OnCancelPreview) |
| 113 |
EVT_TOOL(ID_SAVE_WXGUI_PROJECT, GUICraftMainPanel::OnSaveProject) |
| 114 |
EVT_AUITOOLBAR_TOOL_DROPDOWN(ID_GENERATE_CODE, GUICraftMainPanel::OnGenerateCodeMenu) |
| 115 |
EVT_MENU(XRCID("GenerateCPP"), GUICraftMainPanel::OnCodeGenerationTypeChanged) |
| 116 |
EVT_MENU(XRCID("GenerateXRC"), GUICraftMainPanel::OnCodeGenerationTypeChanged) |
| 117 |
EVT_TOOL_RANGE(ID_TOOL_ALIGN_LEFT, ID_TOOL_WXEXPAND, GUICraftMainPanel::OnSizerTool) |
| 118 |
EVT_TOOL(ID_TOOL_PROP1, GUICraftMainPanel::OnSetSizerProp1) |
| 119 |
|
| 120 |
EVT_MENU(ID_EVENT_EDITOR, GUICraftMainPanel::OnEventEditor) |
| 121 |
#if STANDALONE_BUILD |
| 122 |
EVT_UPDATE_UI(ID_EVENT_EDITOR, GUICraftMainPanel::OnEventEditorUI) |
| 123 |
#endif |
| 124 |
EVT_MENU(ID_EVENT_EDITOR_COMMON, GUICraftMainPanel::OnEventEditorCommon) |
| 125 |
|
| 126 |
// IMPORTANT: this entry MUST be last! |
| 127 |
EVT_MENU(wxID_ANY, GUICraftMainPanel::OnMenuItemClicked) |
| 128 |
|
| 129 |
// ----------------------------------------------------------- |
| 130 |
// UpdateUI events |
| 131 |
// ----------------------------------------------------------- |
| 132 |
EVT_UPDATE_UI(ID_SAVE_WXGUI_PROJECT, GUICraftMainPanel::OnSaveProjectUI) |
| 133 |
EVT_UPDATE_UI(ID_GENERATE_CODE, GUICraftMainPanel::OnGenerateCodeUI) |
| 134 |
EVT_UPDATE_UI_RANGE(ID_MOVE_NODE_UP, ID_MOVE_NODE_INTO_SIBLING, GUICraftMainPanel::OnMoveItemUI) |
| 135 |
EVT_UPDATE_UI(ID_DELETE_NODE, GUICraftMainPanel::OnDeleteUI) |
| 136 |
EVT_UPDATE_UI(ID_CANCEL_PREVIEW, GUICraftMainPanel::OnCancelPreviewUI) |
| 137 |
EVT_UPDATE_UI(ID_TOOL_PROP1, GUICraftMainPanel::OnSetSizerProp1UI) |
| 138 |
EVT_UPDATE_UI_RANGE(ID_TOOL_ALIGN_LEFT, ID_TOOL_WXEXPAND, GUICraftMainPanel::OnSizerToolUI) |
| 139 |
EVT_UPDATE_UI(ID_SHOW_PREVIEW, GUICraftMainPanel::OnShowPreviewUI) |
| 140 |
EVT_UPDATE_UI(wxID_ANY, GUICraftMainPanel::OnMenuItemUI) |
| 141 |
|
| 142 |
EVT_MENU(ID_CUT, GUICraftMainPanel::OnCut) |
| 143 |
EVT_MENU(ID_PASTE, GUICraftMainPanel::OnPaste) |
| 144 |
EVT_MENU(ID_DUPLICATE, GUICraftMainPanel::OnDuplicate) |
| 145 |
EVT_MENU(ID_COPY, GUICraftMainPanel::OnCopy) |
| 146 |
EVT_MENU(ID_RENAME, GUICraftMainPanel::OnRename) |
| 147 |
END_EVENT_TABLE() |
| 148 |
|
| 149 |
const wxEventType wxEVT_UPDATE_PREVIEW = wxNewEventType(); |
| 150 |
const wxEventType wxEVT_UPDATE_EVENTSEDITORPANE = wxNewEventType(); |
| 151 |
wxDEFINE_EVENT(wxEVT_EVENTS_PROPERTIES_UPDATED, wxCommandEvent); // Must do it this way as it's used in a Bind() |
| 152 |
const wxEventType wxEVT_PROPERTIES_MODIFIED = wxNewEventType(); |
| 153 |
const wxEventType wxEVT_PROJECT_METADATA_MODIFIED = wxNewEventType(); |
| 154 |
const wxEventType wxEVT_WXGUI_PROJECT_CLOSED = wxNewEventType(); |
| 155 |
const wxEventType wxEVT_WXGUI_PROJECT_SAVED = wxNewEventType(); |
| 156 |
const wxEventType wxEVT_WXGUI_PROJECT_LOADED = wxNewEventType(); |
| 157 |
const wxEventType wxEVT_CLOSE_PREVIEW = wxNewEventType(); |
| 158 |
const wxEventType wxEVT_PREVIEW_CLOSED = wxNewEventType(); |
| 159 |
const wxEventType wxEVT_DESIGNER_DELETED = wxNewEventType(); |
| 160 |
const wxEventType wxEVT_WXC_CMD_GENERATE_CODE = wxNewEventType(); |
| 161 |
wxDEFINE_EVENT(wxEVT_WXC_CMD_BATCH_GENERATE_CODE, wxCommandEvent); |
| 162 |
const wxEventType wxEVT_WXC_OPEN_PROJECT = wxNewEventType(); |
| 163 |
const wxEventType wxEVT_WXC_SAVE_PROJECT = XRCID("wxEVT_WXC_SAVE_PROJECT"); |
| 164 |
const wxEventType wxEVT_WXC_CLOSE_PROJECT = wxNewEventType(); |
| 165 |
const wxEventType wxEVT_REFRESH_DESIGNER = wxNewEventType(); |
| 166 |
const wxEventType wxEVT_TREE_ITEM_SELECTED = wxNewEventType(); |
| 167 |
const wxEventType wxEVT_SHOW_CONTEXT_MENU = wxNewEventType(); |
| 168 |
const wxEventType wxEVT_DELETE_CONTROL = wxNewEventType(); |
| 169 |
const wxEventType wxEVT_REFRESH_PROPERTIES_VIEW = wxNewEventType(); |
| 170 |
const wxEventType wxEVT_WXC_PROJECT_LOADED = wxNewEventType(); |
| 171 |
const wxEventType wxEVT_WXC_SELECT_TREE_TLW = wxNewEventType(); |
| 172 |
const wxEventType wxEVT_WXC_CODE_PREVIEW_PAGE_CHANGED = wxNewEventType(); |
| 173 |
|
| 174 |
GUICraftMainPanel::GUICraftMainPanel(wxWindow* parent, wxCrafterPlugin* plugin, clTreeCtrl* treeView) |
| 175 |
: GUICraftMainPanelBase(parent) |
| 176 |
, m_clipboardItem(NULL) |
| 177 |
, m_previewAlive(false) |
| 178 |
, m_treeControls(treeView) |
| 179 |
, m_plugin(plugin) |
| 180 |
{ |
| 181 |
#if defined(__WXMSW__) || defined(__WXOSX__) |
| 182 |
wxToolTip::SetDelay(100); |
| 183 |
#endif |
| 184 |
|
| 185 |
#if STANDALONE_BUILD |
| 186 |
FileLogger::OpenLog("wxcrafter.log", FileLogger::Dbg); |
| 187 |
#endif |
| 188 |
|
| 189 |
wxcSettings::Get().Load(); |
| 190 |
wxCrafter::ResourceLoader bmps; |
| 191 |
wxLog::EnableLogging(false); |
| 192 |
|
| 193 |
m_panelToolBox->GetSizer()->Add(new ToolBoxPanel(m_panelToolBox, this), 0, wxEXPAND); |
| 194 |
|
| 195 |
m_toolbar->AddTool(ID_GENERATE_CODE, _("Generate Code"), bmps.Bitmap("generate-code"), _("Generate Code")); |
| 196 |
m_toolbar->AddSeparator(); |
| 197 |
m_toolbar->AddTool(ID_SHOW_PREVIEW, _("Show Preview..."), bmps.Bitmap("preview"), _("Show Preview")); |
| 198 |
m_toolbar->AddTool(ID_CANCEL_PREVIEW, _("Close Preview..."), bmps.Bitmap("cancel"), _("Close Preview")); |
| 199 |
m_toolbar->AddSeparator(); |
| 200 |
|
| 201 |
m_toolbar->AddTool(ID_DELETE_NODE, _("Delete Item"), bmps.Bitmap("delete"), _("Delete Item")); |
| 202 |
m_toolbar->AddSeparator(); |
| 203 |
m_toolbar->AddTool(ID_TOOL_ALIGN_LEFT, _("Align Left"), bmps.Bitmap("align-left"), _("Align Left"), wxITEM_CHECK); |
| 204 |
m_toolbar->AddTool(ID_TOOL_ALIGN_HCENTER, _("Align Center"), bmps.Bitmap("align-center-horizontal"), |
| 205 |
_("Align Center Horizontally"), wxITEM_CHECK); |
| 206 |
m_toolbar->AddTool(ID_TOOL_ALIGN_RIGHT, _("Align Right"), bmps.Bitmap("align-right"), _("Align Right"), |
| 207 |
wxITEM_CHECK); |
| 208 |
m_toolbar->AddSeparator(); |
| 209 |
|
| 210 |
m_toolbar->AddTool(ID_TOOL_ALIGN_TOP, _("Align Top"), bmps.Bitmap("align-top"), _("Align Top"), wxITEM_CHECK); |
| 211 |
m_toolbar->AddTool(ID_TOOL_ALIGN_VCENTER, _("Align Middle"), bmps.Bitmap("align-center-vertical"), |
| 212 |
_("Align Center Vertically"), wxITEM_CHECK); |
| 213 |
m_toolbar->AddTool(ID_TOOL_ALIGN_BOTTOM, _("Align Bottom"), bmps.Bitmap("align-bottom"), _("Align Bottom"), |
| 214 |
wxITEM_CHECK); |
| 215 |
m_toolbar->AddSeparator(); |
| 216 |
|
| 217 |
m_toolbar->AddTool(ID_TOOL_BORDER_ALL, _("All Borders"), bmps.Bitmap("wxall"), _("All Borders"), wxITEM_CHECK); |
| 218 |
m_toolbar->AddTool(ID_TOOL_BORDER_LEFT, _("Left Border"), bmps.Bitmap("border-left"), _("Left Border"), |
| 219 |
wxITEM_CHECK); |
| 220 |
m_toolbar->AddTool(ID_TOOL_BORDER_TOP, _("Top Border"), bmps.Bitmap("border-top"), _("Top Border"), wxITEM_CHECK); |
| 221 |
m_toolbar->AddTool(ID_TOOL_BORDER_RIGHT, _("Right Border"), bmps.Bitmap("border-right"), _("Right Border"), |
| 222 |
wxITEM_CHECK); |
| 223 |
m_toolbar->AddTool(ID_TOOL_BORDER_BOTTOM, _("Bottom Border"), bmps.Bitmap("border-bottom"), _("Bottom Border"), |
| 224 |
wxITEM_CHECK); |
| 225 |
|
| 226 |
m_toolbar->AddSeparator(); |
| 227 |
m_toolbar->AddTool(ID_TOOL_PROP1, _("Set Sizer Proportion to 1"), bmps.Bitmap("proportion-1"), |
| 228 |
_("Set Sizer Proportion to 1"), wxITEM_CHECK); |
| 229 |
m_toolbar->AddTool(ID_TOOL_WXEXPAND, _("Expand Item"), bmps.Bitmap("expand"), _("Expand Item"), wxITEM_CHECK); |
| 230 |
m_toolbar->AddSeparator(); |
| 231 |
|
| 232 |
m_toolbar->AddTool(ID_MOVE_NODE_UP, _("Move Up"), bmps.Bitmap("move-up"), _("Move Up")); |
| 233 |
m_toolbar->AddTool(ID_MOVE_NODE_DOWN, _("Move Down"), bmps.Bitmap("move-down"), _("Move Down")); |
| 234 |
m_toolbar->AddTool(ID_MOVE_NODE_INTO_SIZER, _("Move Left"), bmps.Bitmap("move-left"), |
| 235 |
_("Move Left into parent sizer")); |
| 236 |
m_toolbar->AddTool(ID_MOVE_NODE_INTO_SIBLING, _("Move Right"), bmps.Bitmap("move-upper-right"), |
| 237 |
_("Move Right into a sibling sizer")); |
| 238 |
|
| 239 |
wxAuiToolBarItem* item = m_toolbar->FindTool(ID_GENERATE_CODE); |
| 240 |
item->SetHasDropDown(true); |
| 241 |
|
| 242 |
m_toolbar->Realize(); |
| 243 |
|
| 244 |
m_propertiesPage = new PropertiesSheet(m_panelProperties); |
| 245 |
m_panelProperties->GetSizer()->Add(m_propertiesPage, 1, wxEXPAND); |
| 246 |
m_panelProperties->GetSizer()->Layout(); |
| 247 |
EventNotifier::Get()->Bind(wxEVT_WXC_CMD_BATCH_GENERATE_CODE, &GUICraftMainPanel::OnBatchGenerateCode, this); |
| 248 |
EventNotifier::Get()->Connect(wxEVT_PROPERTIES_MODIFIED, |
| 249 |
wxCommandEventHandler(GUICraftMainPanel::OnPropertyChanged), NULL, this); |
| 250 |
EventNotifier::Get()->Connect(wxEVT_PREVIEW_CTRL_SELECTED, |
| 251 |
wxCommandEventHandler(GUICraftMainPanel::OnPreviewItemSelected), NULL, this); |
| 252 |
EventNotifier::Get()->Connect(wxEVT_WXC_SELECT_TREE_TLW, |
| 253 |
wxCommandEventHandler(GUICraftMainPanel::OnSelectToplevelItem), NULL, this); |
| 254 |
EventNotifier::Get()->Connect(wxEVT_PREVIEW_BOOKPAGE_SELECTED, |
| 255 |
wxCommandEventHandler(GUICraftMainPanel::OnBookPageSelected), NULL, this); |
| 256 |
EventNotifier::Get()->Connect(wxEVT_PREVIEW_RIBBON_PAGE_SELECTED, |
| 257 |
wxCommandEventHandler(GUICraftMainPanel::OnRibbonPageSelected), NULL, this); |
| 258 |
EventNotifier::Get()->Connect(wxEVT_PREVIEW_CLOSED, wxCommandEventHandler(GUICraftMainPanel::OnPreviewClosed), NULL, |
| 259 |
this); |
| 260 |
EventNotifier::Get()->Connect(wxEVT_WXC_OPEN_PROJECT, wxCommandEventHandler(GUICraftMainPanel::OnOpenProject), NULL, |
| 261 |
this); |
| 262 |
EventNotifier::Get()->Connect(wxEVT_WXC_SAVE_PROJECT, wxCommandEventHandler(GUICraftMainPanel::OnSaveProject), NULL, |
| 263 |
this); |
| 264 |
EventNotifier::Get()->Connect(wxEVT_WXC_CLOSE_PROJECT, wxCommandEventHandler(GUICraftMainPanel::OnCloseProject), |
| 265 |
NULL, this); |
| 266 |
EventNotifier::Get()->Connect(wxEVT_WXC_CMD_GENERATE_CODE, wxCommandEventHandler(GUICraftMainPanel::OnGenerateCode), |
| 267 |
NULL, this); |
| 268 |
EventNotifier::Get()->Connect(wxEVT_REFRESH_DESIGNER, wxCommandEventHandler(GUICraftMainPanel::OnRefreshView), NULL, |
| 269 |
this); |
| 270 |
EventNotifier::Get()->Connect(wxEVT_PREVIEW_BAR_SELECTED, |
| 271 |
wxCommandEventHandler(GUICraftMainPanel::OnBarItemSelected), NULL, this); |
| 272 |
EventNotifier::Get()->Connect(wxEVT_SHOW_CONTEXT_MENU, wxCommandEventHandler(GUICraftMainPanel::OnShowContextMenu), |
| 273 |
NULL, this); |
| 274 |
EventNotifier::Get()->Connect(wxEVT_DELETE_CONTROL, wxCommandEventHandler(GUICraftMainPanel::OnDelete), NULL, this); |
| 275 |
EventNotifier::Get()->Connect(wxEVT_UPDATE_PREVIEW, wxCommandEventHandler(GUICraftMainPanel::OnUpdatePreview), NULL, |
| 276 |
this); |
| 277 |
EventNotifier::Get()->Bind(wxEVT_FINDBAR_ABOUT_TO_SHOW, &GUICraftMainPanel::OnFindBar, this); |
| 278 |
EventNotifier::Get()->Connect(wxEVT_REFRESH_PROPERTIES_VIEW, |
| 279 |
wxCommandEventHandler(GUICraftMainPanel::OnRefreshPropertiesView), NULL, this); |
| 280 |
m_MainPanel = this; |
| 281 |
|
| 282 |
m_treeControls->Connect(wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEventHandler(GUICraftMainPanel::OnBeginDrag), NULL, |
| 283 |
this); |
| 284 |
m_treeControls->Connect(wxEVT_COMMAND_TREE_END_DRAG, wxTreeEventHandler(GUICraftMainPanel::OnEndDrag), NULL, this); |
| 285 |
m_treeControls->Connect(wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler(GUICraftMainPanel::OnMenu), NULL, this); |
| 286 |
m_treeControls->Connect(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, |
| 287 |
wxTreeEventHandler(GUICraftMainPanel::OnItemRightClick), NULL, this); |
| 288 |
m_treeControls->Connect(wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler(GUICraftMainPanel::OnItemSelected), NULL, |
| 289 |
this); |
| 290 |
m_treeControls->Connect(ID_DELETE_NODE, wxEVT_COMMAND_MENU_SELECTED, |
| 291 |
wxCommandEventHandler(GUICraftMainPanel::OnDelete), NULL, |
| 292 |
this); // Translated from a DEL keypress |
| 293 |
|
| 294 |
wxTheApp->Connect(wxID_UNDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(GUICraftMainPanel::OnUndo), NULL, |
| 295 |
this); |
| 296 |
wxTheApp->Connect(wxID_REDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(GUICraftMainPanel::OnRedo), NULL, |
| 297 |
this); |
| 298 |
wxTheApp->Connect(wxID_UNDO, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(GUICraftMainPanel::OnUndoUI), NULL, this); |
| 299 |
wxTheApp->Connect(wxID_REDO, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(GUICraftMainPanel::OnRedoUI), NULL, this); |
| 300 |
wxTheApp->Connect(XRCID("label_current_state"), wxEVT_COMMAND_MENU_SELECTED, |
| 301 |
wxCommandEventHandler(GUICraftMainPanel::OnLabelCurrentState), NULL, this); |
| 302 |
wxTheApp->Connect(wxEVT_MULTIPLE_UNREDO, wxCommandEventHandler(GUICraftMainPanel::OnLoadCurrentState), NULL, this); |
| 303 |
this->Connect(ID_FORM_TYPE, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(GUICraftMainPanel::OnNewFormUI), NULL, this); |
| 304 |
|
| 305 |
int sashPos = wxcSettings::Get().GetSashPosition(); |
| 306 |
if(sashPos != wxNOT_FOUND) { |
| 307 |
m_mainSplitter->SetSashPosition(sashPos); |
| 308 |
} |
| 309 |
|
| 310 |
// Use codelite's coloring settings |
| 311 |
LexerConf::Ptr_t cppLexer = EditorConfigST::Get()->GetLexer("C++"); |
| 312 |
if(cppLexer) { |
| 313 |
cppLexer->Apply(m_textCtrlCppSource); |
| 314 |
cppLexer->Apply(m_textCtrlHeaderSource); |
| 315 |
m_textCtrlCppSource->SetProperty("lexer.cpp.track.preprocessor", "0"); |
| 316 |
m_textCtrlCppSource->SetProperty("lexer.cpp.update.preprocessor", "0"); |
| 317 |
|
| 318 |
m_textCtrlHeaderSource->SetProperty("lexer.cpp.track.preprocessor", "0"); |
| 319 |
m_textCtrlHeaderSource->SetProperty("lexer.cpp.update.preprocessor", "0"); |
| 320 |
} |
| 321 |
|
| 322 |
LexerConf::Ptr_t xmlLexer = EditorConfigST::Get()->GetLexer("XML"); |
| 323 |
if(xmlLexer) { |
| 324 |
xmlLexer->Apply(m_textCtrlXrc); |
| 325 |
} |
| 326 |
|
| 327 |
wxTheApp->Connect(XRCID("save_file"), wxEVT_UPDATE_UI, wxUpdateUIEventHandler(GUICraftMainPanel::OnSaveProjectUI), |
| 328 |
NULL, this); |
| 329 |
|
| 330 |
::wxPGPropertyBooleanUseCheckbox(m_pgMgrAuiProperties->GetGrid()); |
| 331 |
::wxPGPropertyBooleanUseCheckbox(m_pgMgrSizerFlags->GetGrid()); |
| 332 |
} |
| 333 |
|
| 334 |
GUICraftMainPanel::~GUICraftMainPanel() |
| 335 |
{ |
| 336 |
// Notify the find-bar to clear any pointer referenced by it |
| 337 |
// that is belonged to this view |
| 338 |
DoDismissFindBar(); |
| 339 |
|
| 340 |
wxDELETE(m_clipboardItem); |
| 341 |
|
| 342 |
wxcSettings::Get().SetSashPosition(m_mainSplitter->GetSashPosition()); |
| 343 |
wxcSettings::Get().Save(); |
| 344 |
|
| 345 |
EventNotifier::Get()->Disconnect(wxEVT_PROPERTIES_MODIFIED, |
| 346 |
wxCommandEventHandler(GUICraftMainPanel::OnPropertyChanged), NULL, this); |
| 347 |
EventNotifier::Get()->Disconnect(wxEVT_PREVIEW_CTRL_SELECTED, |
| 348 |
wxCommandEventHandler(GUICraftMainPanel::OnPreviewItemSelected), NULL, this); |
| 349 |
EventNotifier::Get()->Disconnect(wxEVT_PREVIEW_BOOKPAGE_SELECTED, |
| 350 |
wxCommandEventHandler(GUICraftMainPanel::OnBookPageSelected), NULL, this); |
| 351 |
EventNotifier::Get()->Disconnect(wxEVT_PREVIEW_RIBBON_PAGE_SELECTED, |
| 352 |
wxCommandEventHandler(GUICraftMainPanel::OnRibbonPageSelected), NULL, this); |
| 353 |
EventNotifier::Get()->Disconnect(wxEVT_PREVIEW_CLOSED, wxCommandEventHandler(GUICraftMainPanel::OnPreviewClosed), |
| 354 |
NULL, this); |
| 355 |
EventNotifier::Get()->Disconnect(wxEVT_WXC_OPEN_PROJECT, wxCommandEventHandler(GUICraftMainPanel::OnOpenProject), |
| 356 |
NULL, this); |
| 357 |
EventNotifier::Get()->Disconnect(wxEVT_WXC_SAVE_PROJECT, wxCommandEventHandler(GUICraftMainPanel::OnSaveProject), |
| 358 |
NULL, this); |
| 359 |
EventNotifier::Get()->Disconnect(wxEVT_WXC_CMD_GENERATE_CODE, |
| 360 |
wxCommandEventHandler(GUICraftMainPanel::OnGenerateCode), NULL, this); |
| 361 |
EventNotifier::Get()->Unbind(wxEVT_WXC_CMD_BATCH_GENERATE_CODE, &GUICraftMainPanel::OnBatchGenerateCode, this); |
| 362 |
EventNotifier::Get()->Disconnect(wxEVT_REFRESH_DESIGNER, wxCommandEventHandler(GUICraftMainPanel::OnRefreshView), |
| 363 |
NULL, this); |
| 364 |
EventNotifier::Get()->Disconnect(wxEVT_WXC_CLOSE_PROJECT, wxCommandEventHandler(GUICraftMainPanel::OnCloseProject), |
| 365 |
NULL, this); |
| 366 |
EventNotifier::Get()->Disconnect(wxEVT_PREVIEW_BAR_SELECTED, |
| 367 |
wxCommandEventHandler(GUICraftMainPanel::OnBarItemSelected), NULL, this); |
| 368 |
EventNotifier::Get()->Disconnect(wxEVT_SHOW_CONTEXT_MENU, |
| 369 |
wxCommandEventHandler(GUICraftMainPanel::OnShowContextMenu), NULL, this); |
| 370 |
EventNotifier::Get()->Disconnect(wxEVT_DELETE_CONTROL, wxCommandEventHandler(GUICraftMainPanel::OnDelete), NULL, |
| 371 |
this); |
| 372 |
EventNotifier::Get()->Disconnect(wxEVT_UPDATE_PREVIEW, wxCommandEventHandler(GUICraftMainPanel::OnUpdatePreview), |
| 373 |
NULL, this); |
| 374 |
EventNotifier::Get()->Unbind(wxEVT_FINDBAR_ABOUT_TO_SHOW, &GUICraftMainPanel::OnFindBar, this); |
| 375 |
EventNotifier::Get()->Disconnect(wxEVT_REFRESH_PROPERTIES_VIEW, |
| 376 |
wxCommandEventHandler(GUICraftMainPanel::OnRefreshPropertiesView), NULL, this); |
| 377 |
|
| 378 |
// Only disconnect the events in Tabbed mode, |
| 379 |
// in the "frame" mode, the main panel and the tree view have the same |
| 380 |
// parent |
| 381 |
if(false) { |
| 382 |
m_treeControls->Disconnect(wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEventHandler(GUICraftMainPanel::OnBeginDrag), |
| 383 |
NULL, this); |
| 384 |
m_treeControls->Disconnect(wxEVT_COMMAND_TREE_END_DRAG, wxTreeEventHandler(GUICraftMainPanel::OnEndDrag), NULL, |
| 385 |
this); |
| 386 |
m_treeControls->Disconnect(wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler(GUICraftMainPanel::OnMenu), NULL, |
| 387 |
this); |
| 388 |
m_treeControls->Disconnect(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, |
| 389 |
wxTreeEventHandler(GUICraftMainPanel::OnItemRightClick), NULL, this); |
| 390 |
m_treeControls->Disconnect(wxEVT_COMMAND_TREE_SEL_CHANGED, |
| 391 |
wxTreeEventHandler(GUICraftMainPanel::OnItemSelected), NULL, this); |
| 392 |
m_treeControls->Disconnect(ID_DELETE_NODE, wxEVT_COMMAND_MENU_SELECTED, |
| 393 |
wxCommandEventHandler(GUICraftMainPanel::OnDelete), NULL, this); |
| 394 |
wxTheApp->Disconnect(ID_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(GUICraftMainPanel::OnCopy), |
| 395 |
NULL, this); |
| 396 |
wxTheApp->Disconnect(ID_CUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(GUICraftMainPanel::OnCut), NULL, |
| 397 |
this); |
| 398 |
wxTheApp->Disconnect(ID_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(GUICraftMainPanel::OnPaste), |
| 399 |
NULL, this); |
| 400 |
} |
| 401 |
|
| 402 |
wxTheApp->Disconnect(wxID_UNDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(GUICraftMainPanel::OnUndo), NULL, |
| 403 |
this); |
| 404 |
wxTheApp->Disconnect(wxID_REDO, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(GUICraftMainPanel::OnRedo), NULL, |
| 405 |
this); |
| 406 |
wxTheApp->Disconnect(wxID_UNDO, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(GUICraftMainPanel::OnUndoUI), NULL, this); |
| 407 |
wxTheApp->Disconnect(wxID_REDO, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(GUICraftMainPanel::OnRedoUI), NULL, this); |
| 408 |
wxTheApp->Disconnect(XRCID("label_current_state"), wxEVT_COMMAND_MENU_SELECTED, |
| 409 |
wxCommandEventHandler(GUICraftMainPanel::OnLabelCurrentState), NULL, this); |
| 410 |
wxTheApp->Disconnect(wxEVT_MULTIPLE_UNREDO, wxCommandEventHandler(GUICraftMainPanel::OnLoadCurrentState), NULL, |
| 411 |
this); |
| 412 |
wxTheApp->Disconnect(XRCID("save_file"), wxEVT_UPDATE_UI, |
| 413 |
wxUpdateUIEventHandler(GUICraftMainPanel::OnSaveProjectUI), NULL, this); |
| 414 |
|
| 415 |
m_treeControls = NULL; |
| 416 |
m_MainPanel = NULL; |
| 417 |
|
| 418 |
wxCommandEvent deleteEvent(wxEVT_DESIGNER_DELETED); |
| 419 |
EventNotifier::Get()->AddPendingEvent(deleteEvent); |
| 420 |
} |
| 421 |
|
| 422 |
void GUICraftMainPanel::Clear() |
| 423 |
{ |
| 424 |
#ifdef __WXMSW__ |
| 425 |
wxWindowUpdateLocker locker(this); |
| 426 |
#endif |
| 427 |
// Clear all the data |
| 428 |
m_propertiesPage->Construct(NULL); |
| 429 |
m_sizerFlags.Construct(m_pgMgrSizerFlags->GetGrid(), NULL); |
| 430 |
m_styles.Clear(m_pgMgrStyles->GetGrid()); |
| 431 |
|
| 432 |
m_treeControls->DeleteAllItems(); |
| 433 |
m_treeControls->AddRoot(_("wxCrafter Project"), 0, 0); |
| 434 |
wxcProjectMetadata::Get().Reset(); |
| 435 |
|
| 436 |
// Notify all controls to perform cleanup |
| 437 |
wxCommandEvent evt(wxEVT_WXGUI_PROJECT_CLOSED); |
| 438 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 439 |
|
| 440 |
// Close any opened preview |
| 441 |
wxCommandEvent closePreviewEvt(wxEVT_CLOSE_PREVIEW); |
| 442 |
EventNotifier::Get()->AddPendingEvent(closePreviewEvt); |
| 443 |
} |
| 444 |
|
| 445 |
void GUICraftMainPanel::OnNewFormUI(wxUpdateUIEvent& event) { event.Enable(wxcProjectMetadata::Get().IsLoaded()); } |
| 446 |
|
| 447 |
void GUICraftMainPanel::OnMenu(wxTreeEvent& event) |
| 448 |
{ |
| 449 |
wxMenu menu; |
| 450 |
GUICraftItemData* data = GetSelItemData(); |
| 451 |
Allocator::Instance()->PrepareMenu(menu, data ? data->m_wxcWidget : NULL); |
| 452 |
PopupMenu(&menu); |
| 453 |
} |
| 454 |
|
| 455 |
void GUICraftMainPanel::OnShowContextMenu(wxCommandEvent& e) |
| 456 |
{ |
| 457 |
GUICraftItemData* data = GetSelItemData(); |
| 458 |
|
| 459 |
wxString title; |
| 460 |
if(data && data->m_wxcWidget) { |
| 461 |
title = data->m_wxcWidget->GetName(); |
| 462 |
} |
| 463 |
wxMenu menu(title.IsEmpty() ? "" : title); |
| 464 |
Allocator::Instance()->PrepareMenu(menu, data ? data->m_wxcWidget : NULL); |
| 465 |
PopupMenu(&menu); |
| 466 |
} |
| 467 |
|
| 468 |
void GUICraftMainPanel::OnItemSelected(wxTreeEvent& event) |
| 469 |
{ |
| 470 |
event.Skip(); |
| 471 |
wxUnusedVar(event); |
| 472 |
GUICraftItemData* data = GetSelItemData(); |
| 473 |
|
| 474 |
if(!data) { |
| 475 |
// Clear all properties |
| 476 |
DoUpdatPropertiesFlags(NULL); |
| 477 |
m_propertiesPage->Construct(NULL); |
| 478 |
m_auiPaneInfo.Construct(m_pgMgrAuiProperties->GetGrid(), NULL); |
| 479 |
|
| 480 |
m_propertiesPage->ConstructProjectSettings(); |
| 481 |
} |
| 482 |
|
| 483 |
CHECK_POINTER(data); |
| 484 |
CHECK_POINTER(data->m_wxcWidget); |
| 485 |
|
| 486 |
DoUpdateNotebookSelection(m_treeControls->GetSelection()); |
| 487 |
if(!bManualSelection) { |
| 488 |
NotifyPreviewChanged(); |
| 489 |
} |
| 490 |
DoUpdatePropertiesView(); |
| 491 |
|
| 492 |
wxCommandEvent eventTreeItemSeleted(wxEVT_TREE_ITEM_SELECTED); |
| 493 |
eventTreeItemSeleted.SetString(data->m_wxcWidget->GetName()); |
| 494 |
EventNotifier::Get()->AddPendingEvent(eventTreeItemSeleted); |
| 495 |
} |
| 496 |
|
| 497 |
void GUICraftMainPanel::DoUpdatePropertiesView() |
| 498 |
{ |
| 499 |
GUICraftItemData* data = GetSelItemData(); |
| 500 |
if(!data) { |
| 501 |
// Clear all properties |
| 502 |
DoUpdatPropertiesFlags(NULL); |
| 503 |
m_propertiesPage->Construct(NULL); |
| 504 |
m_auiPaneInfo.Construct(m_pgMgrAuiProperties->GetGrid(), NULL); |
| 505 |
m_propertiesPage->ConstructProjectSettings(); |
| 506 |
} |
| 507 |
|
| 508 |
CHECK_POINTER(data); |
| 509 |
CHECK_POINTER(data->m_wxcWidget); |
| 510 |
DoUpdatPropertiesFlags(data->m_wxcWidget); |
| 511 |
m_propertiesPage->Construct(data->m_wxcWidget); |
| 512 |
} |
| 513 |
|
| 514 |
GUICraftItemData* GUICraftMainPanel::GetSelItemData() |
| 515 |
{ |
| 516 |
wxTreeItemId itemId = m_treeControls->GetSelection(); |
| 517 |
if(itemId.IsOk() == false) { |
| 518 |
return NULL; |
| 519 |
} |
| 520 |
|
| 521 |
GUICraftItemData* data = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(itemId)); |
| 522 |
return data; |
| 523 |
} |
| 524 |
|
| 525 |
void GUICraftMainPanel::OnSizerForTopLevelWinUI(wxUpdateUIEvent& e) |
| 526 |
{ |
| 527 |
GUICraftItemData* data = GetSelItemData(); |
| 528 |
CHECK_POINTER(data); |
| 529 |
|
| 530 |
e.Enable((data->m_wxcWidget->IsSizer()) || (!data->m_wxcWidget->IsSizer() && !data->m_wxcWidget->HasMainSizer())); |
| 531 |
} |
| 532 |
|
| 533 |
void GUICraftMainPanel::OnShowPreview(wxCommandEvent& e) |
| 534 |
{ |
| 535 |
wxTreeItemId topLevelItem = DoGetTopLevelTreeItem(); |
| 536 |
CHECK_TREEITEM(topLevelItem); |
| 537 |
|
| 538 |
GUICraftItemData* data = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(topLevelItem)); |
| 539 |
CHECK_POINTER(data); |
| 540 |
|
| 541 |
wxWindow* parent = GetTopFrame(); |
| 542 |
FrameWrapper* fw = dynamic_cast<FrameWrapper*>(data->m_wxcWidget); |
| 543 |
if(fw) { |
| 544 |
PreviewFrame* frame = new PreviewFrame(parent, *fw); |
| 545 |
m_previewAlive = true; |
| 546 |
frame->Show(); |
| 547 |
} |
| 548 |
|
| 549 |
PanelWrapperTopLevel* pw = dynamic_cast<PanelWrapperTopLevel*>(data->m_wxcWidget); |
| 550 |
if(pw) { |
| 551 |
PreviewPanel* frame = new PreviewPanel(parent, *pw); |
| 552 |
m_previewAlive = true; |
| 553 |
frame->Show(); |
| 554 |
} |
| 555 |
|
| 556 |
AuiToolBarTopLevelWrapper* aui = dynamic_cast<AuiToolBarTopLevelWrapper*>(data->m_wxcWidget); |
| 557 |
if(aui) { |
| 558 |
PreviewPanel* frame = new PreviewPanel(parent, *aui); |
| 559 |
m_previewAlive = true; |
| 560 |
frame->Show(); |
| 561 |
} |
| 562 |
|
| 563 |
DialogWrapper* dw = dynamic_cast<DialogWrapper*>(data->m_wxcWidget); |
| 564 |
if(dw) { |
| 565 |
// Show the dialog |
| 566 |
PreviewDialog* dlg = new PreviewDialog(parent, *dw); |
| 567 |
m_previewAlive = true; |
| 568 |
dlg->Show(); |
| 569 |
} |
| 570 |
|
| 571 |
WizardWrapper* ww = dynamic_cast<WizardWrapper*>(data->m_wxcWidget); |
| 572 |
if(ww) { |
| 573 |
// Show the dialog |
| 574 |
PreviewWizard dlg(parent, *ww); |
| 575 |
m_previewAlive = true; |
| 576 |
dlg.Run(); |
| 577 |
} |
| 578 |
|
| 579 |
PopupWindowWrapper* pop = dynamic_cast<PopupWindowWrapper*>(data->m_wxcWidget); |
| 580 |
if(pop) { |
| 581 |
PopupWindowPreview* frame = new PopupWindowPreview(parent, *pop); |
| 582 |
m_previewAlive = true; |
| 583 |
frame->Show(); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
void GUICraftMainPanel::OnItemRightClick(wxTreeEvent& event) |
| 588 |
{ |
| 589 |
event.Skip(); |
| 590 |
m_treeControls->SelectItem(event.GetItem()); |
| 591 |
} |
| 592 |
|
| 593 |
void GUICraftMainPanel::DoUpdatPropertiesFlags(wxcWidget* data) |
| 594 |
{ |
| 595 |
DoUpdateSizerFlags(data); |
| 596 |
DoUpdateStyleFlags(data); |
| 597 |
} |
| 598 |
|
| 599 |
void GUICraftMainPanel::DoUpdateStyleFlags(wxcWidget* data) { m_styles.Construct(m_pgMgrStyles->GetGrid(), data); } |
| 600 |
|
| 601 |
void GUICraftMainPanel::DoUpdateSizerFlags(wxcWidget* data) |
| 602 |
{ |
| 603 |
m_auiPaneInfo.Construct(m_pgMgrAuiProperties->GetGrid(), data); |
| 604 |
m_sizerFlags.Construct(m_pgMgrSizerFlags->GetGrid(), data); |
| 605 |
|
| 606 |
if(!data) { |
| 607 |
DoShowPropertiesPage(m_panelAuiPaneInfo, "wxAuiPaneInfo", false); |
| 608 |
DoShowPropertiesPage(m_panelSizerFlags, _("Sizer Flags"), false); |
| 609 |
|
| 610 |
} else { |
| 611 |
int cursel = m_notebook2->GetSelection(); |
| 612 |
if(data->IsAuiPane()) { |
| 613 |
DoShowPropertiesPage(m_panelAuiPaneInfo, "wxAuiPaneInfo", true); |
| 614 |
DoShowPropertiesPage(m_panelSizerFlags, _("Sizer Flags"), false); |
| 615 |
|
| 616 |
} else { |
| 617 |
DoShowPropertiesPage(m_panelAuiPaneInfo, "wxAuiPaneInfo", false); |
| 618 |
DoShowPropertiesPage(m_panelSizerFlags, _("Sizer Flags"), true); |
| 619 |
} |
| 620 |
#ifndef __WXGTK__ |
| 621 |
m_notebook2->SetSelection(cursel); |
| 622 |
#endif |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
void GUICraftMainPanel::NotifyPreviewChanged(int eventType) |
| 627 |
{ |
| 628 |
|
| 629 |
GUICraftItemData* data = GetSelItemData(); |
| 630 |
CHECK_POINTER(data); |
| 631 |
CHECK_POINTER(data->m_wxcWidget); |
| 632 |
|
| 633 |
// If the selected item is notebook page, make sure we select this page again after the update |
| 634 |
NotebookPageWrapper* bookPage = dynamic_cast<NotebookPageWrapper*>(data->m_wxcWidget); |
| 635 |
if(bookPage) { |
| 636 |
NotebookBaseWrapper* book = dynamic_cast<NotebookBaseWrapper*>(bookPage->GetParent()); |
| 637 |
if(book) { |
| 638 |
book->SetSelection(bookPage); |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
wxcWidget* parent = data->m_wxcWidget; |
| 643 |
while(parent && !parent->IsTopWindow()) { |
| 644 |
parent = parent->GetParent(); |
| 645 |
} |
| 646 |
|
| 647 |
CHECK_POINTER(parent); |
| 648 |
|
| 649 |
wxCommandEvent evt(eventType); |
| 650 |
TopLevelWinWrapper* topWin = dynamic_cast<TopLevelWinWrapper*>(parent); |
| 651 |
if(topWin) { |
| 652 |
evt.SetString(topWin->DesignerXRC(false)); |
| 653 |
evt.SetInt(topWin->GetType()); |
| 654 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 655 |
} |
| 656 |
|
| 657 |
// Also, notify the deisgner to mark the new selection |
| 658 |
wxCommandEvent eventTreeItemSeleted(wxEVT_TREE_ITEM_SELECTED); |
| 659 |
eventTreeItemSeleted.SetString(data->m_wxcWidget->GetName()); |
| 660 |
EventNotifier::Get()->AddPendingEvent(eventTreeItemSeleted); |
| 661 |
} |
| 662 |
|
| 663 |
void GUICraftMainPanel::OnPropertyChanged(wxCommandEvent& e) |
| 664 |
{ |
| 665 |
e.Skip(); |
| 666 |
// Special case, before we test for valid pointers: a metadata alteration |
| 667 |
GUICraftItemData* itemData = GetSelItemData(); |
| 668 |
CHECK_POINTER(itemData); |
| 669 |
CHECK_POINTER(itemData->m_wxcWidget); |
| 670 |
wxTreeItemId item; |
| 671 |
wxcWidget* modifiedWidget = reinterpret_cast<wxcWidget*>(e.GetClientData()); |
| 672 |
if(modifiedWidget && modifiedWidget != itemData->m_wxcWidget) { |
| 673 |
// Locate the proper wxTreeItemId to update |
| 674 |
item = DoFindItemByWxcWidget(modifiedWidget, m_treeControls->GetRootItem()); |
| 675 |
|
| 676 |
} else { |
| 677 |
item = m_treeControls->GetSelection(); |
| 678 |
if(item.IsOk()) { |
| 679 |
GUICraftItemData* data = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 680 |
if(data) { |
| 681 |
modifiedWidget = dynamic_cast<wxcWidget*>(data->m_wxcWidget); |
| 682 |
} |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
wxString newname = e.GetString(); |
| 687 |
if(item.IsOk() && !newname.IsEmpty() && (newname != m_treeControls->GetItemText(item))) { |
| 688 |
m_treeControls->SetItemText(item, newname); |
| 689 |
} |
| 690 |
|
| 691 |
// Special case: An auitoolbar item changing kind |
| 692 |
if(modifiedWidget && modifiedWidget->IsParentAuiToolbar()) { |
| 693 |
ToolBarItemWrapper* auiItem = dynamic_cast<ToolBarItemWrapper*>(modifiedWidget); |
| 694 |
if(auiItem) { |
| 695 |
auiItem->UpdateRegisteredEventsIfNeeded(); // Switch the event between wxEVT_COMMAND_MENU_SELECTED and |
| 696 |
// wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN |
| 697 |
auiItem->OnPropertiesUpdated(); |
| 698 |
DoUpdatePropertiesView(); |
| 699 |
|
| 700 |
wxCrafter::TOOL_TYPE toolType = wxCrafter::GetToolType(auiItem->PropertyString(PROP_KIND)); |
| 701 |
if(toolType == wxCrafter::TOOL_TYPE_DROPDOWN && auiItem->PropertyString(PROP_DROPDOWN_MENU) == "1") { |
| 702 |
// We're a dropdown item, and the user wants to construct its menu inside wxC |
| 703 |
if(auiItem->GetChildren().empty()) { |
| 704 |
wxcWidget* menu = Allocator::Instance()->Create(ID_WXMENU); |
| 705 |
menu->SetParent(auiItem); |
| 706 |
DoInsertControl(menu, auiItem, Allocator::INSERT_CHILD, |
| 707 |
Allocator::Instance()->GetImageId(ID_WXMENU)); |
| 708 |
} |
| 709 |
} else if(!auiItem->GetChildren().empty()) { |
| 710 |
// There's a redundant menu, either because user switched to DIY, or because it's no longer a dropdown |
| 711 |
wxTreeItemIdValue cookie; |
| 712 |
wxTreeItemId menuitem = m_treeControls->GetFirstChild(item, cookie); |
| 713 |
if(menuitem.IsOk()) { |
| 714 |
DoUnsetItemData(menuitem); |
| 715 |
delete auiItem->GetChildren().front(); |
| 716 |
m_treeControls->DeleteChildren(menuitem); |
| 717 |
m_treeControls->Delete(menuitem); |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
// I'm not certain this is still needed, but it, and its associated code, seems like a good idea anyway |
| 722 |
wxCommandEvent evt(wxEVT_UPDATE_EVENTSEDITORPANE); |
| 723 |
EventNotifier::Get()->AddPendingEvent(evt); // Keep the events view in sync |
| 724 |
} |
| 725 |
} |
| 726 |
NotifyPreviewChanged(); |
| 727 |
} |
| 728 |
|
| 729 |
void GUICraftMainPanel::OnNewControl(wxCommandEvent& e) |
| 730 |
{ |
| 731 |
if(e.GetId() == ID_WXCUSTOMCONTROL) { |
| 732 |
// Custom Controls are handled differently |
| 733 |
e.Skip(); |
| 734 |
return; |
| 735 |
} |
| 736 |
|
| 737 |
GUICraftItemData* data = GetSelItemData(); |
| 738 |
int imgId = Allocator::Instance()->GetImageId(e.GetId()); |
| 739 |
|
| 740 |
bool isTopLevel = (e.GetId() == ID_WXDIALOG || e.GetId() == ID_WXFRAME || e.GetId() == ID_WXWIZARD || |
| 741 |
e.GetId() == ID_WXPANEL_TOPLEVEL || e.GetId() == ID_WXPOPUPWINDOW || |
| 742 |
e.GetId() == ID_WXIMAGELIST || e.GetId() == ID_WXAUITOOLBARTOPLEVEL); |
| 743 |
if(isTopLevel) { |
| 744 |
|
| 745 |
// Use the Wizard instead of adding the form directly |
| 746 |
wxCommandEvent createFormEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("wxcp_new_form")); |
| 747 |
createFormEvent.SetInt(e.GetId()); |
| 748 |
wxTheApp->AddPendingEvent(createFormEvent); |
| 749 |
|
| 750 |
} else if(data && data->m_wxcWidget) { |
| 751 |
// Non toplevel window |
| 752 |
wxcWidget* control = Allocator::Instance()->Create(e.GetId()); |
| 753 |
CHECK_POINTER(control); |
| 754 |
|
| 755 |
int insertType; |
| 756 |
|
| 757 |
// Special handling for treebook |
| 758 |
if(e.GetId() == ID_WXTREEBOOK_SUB_PAGE) { |
| 759 |
insertType = Allocator::INSERT_CHILD; |
| 760 |
|
| 761 |
} else if(e.GetId() == ID_WXPGPROPERTY_SUB) { |
| 762 |
insertType = Allocator::INSERT_CHILD; |
| 763 |
|
| 764 |
} else if(e.GetId() == ID_WXSPACER) { |
| 765 |
// A spacer has no proportion by default, but this one's supposed to stretch |
| 766 |
control->SizerItem().SetProportion(1); |
| 767 |
insertType = |
| 768 |
Allocator::Instance()->GetInsertionType(control->GetType(), data->m_wxcWidget->GetType(), false); |
| 769 |
|
| 770 |
} else { |
| 771 |
insertType = |
| 772 |
Allocator::Instance()->GetInsertionType(control->GetType(), data->m_wxcWidget->GetType(), true); |
| 773 |
} |
| 774 |
DoInsertControl(control, data->m_wxcWidget, insertType, imgId); |
| 775 |
} |
| 776 |
} |
| 777 |
|
| 778 |
void GUICraftMainPanel::OnStyleChanged(wxPropertyGridEvent& event) |
| 779 |
{ |
| 780 |
GUICraftItemData* itemData = GetSelItemData(); |
| 781 |
CHECK_POINTER(itemData); |
| 782 |
|
| 783 |
wxVariant v = event.GetPropertyValue(); |
| 784 |
wxString asString = v.GetString(); |
| 785 |
// WrapperBase::MapStyles_t flags = DoGetStylesFromCheckList(m_checkListStyles); |
| 786 |
// itemData->m_wxcWidget->SetStyles(flags); |
| 787 |
// wxcProjectMetadata::Get().SetIsModified(true); |
| 788 |
NotifyPreviewChanged(); |
| 789 |
} |
| 790 |
|
| 791 |
void GUICraftMainPanel::OnGenerateCode(wxCommandEvent& e) |
| 792 |
{ |
| 793 |
wxUnusedVar(e); |
| 794 |
DoGenerateCode(false); |
| 795 |
} |
| 796 |
|
| 797 |
bool GUICraftMainPanel::GenerateCppOutput(wxString& cpp, wxString& header, wxArrayString& headers, |
| 798 |
wxStringMap_t& additionalFiles, size_t flags) const |
| 799 |
{ |
| 800 |
// If onlySelection, just produce output for the currently selected tree branch. By default do everything |
| 801 |
wxTreeItemId start, item; |
| 802 |
wxTreeItemId selectedItem = DoGetTopLevelTreeItem(); |
| 803 |
if((flags & kGenCodeSelectionOnly) && selectedItem.IsOk()) { |
| 804 |
start = selectedItem; |
| 805 |
} else { |
| 806 |
start = m_treeControls->GetRootItem(); |
| 807 |
} |
| 808 |
wxCHECK(start.IsOk(), "Invalid tree root"); |
| 809 |
|
| 810 |
wxTreeItemIdValue cookie; |
| 811 |
if(start == m_treeControls->GetRootItem()) { |
| 812 |
item = m_treeControls->GetFirstChild(start, cookie); |
| 813 |
flags &= ~kGenCodeSelectionOnly; // in case onlySelection was asked for, but selectedItem wasn't Ok |
| 814 |
|
| 815 |
} else { |
| 816 |
item = start; |
| 817 |
} |
| 818 |
|
| 819 |
while(item.IsOk()) { |
| 820 |
GUICraftItemData* data = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 821 |
if(data) { |
| 822 |
wxcWidget* wb = dynamic_cast<wxcWidget*>(data->m_wxcWidget); |
| 823 |
if(wb) { |
| 824 |
TopLevelWinWrapper* tl = dynamic_cast<TopLevelWinWrapper*>(wb); |
| 825 |
if(tl) { |
| 826 |
tl->GenerateCode(wxcProjectMetadata::Get(), !(flags & kGenCodeForPreview), |
| 827 |
(flags & kGenCodeSelectionOnly) || (item != selectedItem), // output base only |
| 828 |
cpp, header, headers, additionalFiles); |
| 829 |
if(flags & kGenCodeSelectionOnly) { |
| 830 |
break; // We only want a single tlw, so don't loop |
| 831 |
} |
| 832 |
} |
| 833 |
} |
| 834 |
} |
| 835 |
item = m_treeControls->GetNextChild(m_treeControls->GetRootItem(), cookie); |
| 836 |
} |
| 837 |
return true; |
| 838 |
} |
| 839 |
|
| 840 |
void GUICraftMainPanel::GenerateXrcOutput(wxString& output, size_t flags) const |
| 841 |
{ |
| 842 |
// If onlySelection, just produce output for the currently selected tree branch. By default do everything |
| 843 |
wxTreeItemId start, item; |
| 844 |
wxTreeItemId sel = DoGetTopLevelTreeItem(); |
| 845 |
if((flags & kGenCodeSelectionOnly) && sel.IsOk()) { |
| 846 |
start = sel; |
| 847 |
} else { |
| 848 |
start = m_treeControls->GetRootItem(); |
| 849 |
} |
| 850 |
wxCHECK_RET(start.IsOk(), "Invalid tree root"); |
| 851 |
|
| 852 |
wxTreeItemIdValue cookie; |
| 853 |
if(start == m_treeControls->GetRootItem()) { |
| 854 |
item = m_treeControls->GetFirstChild(start, cookie); |
| 855 |
flags &= ~kGenCodeSelectionOnly; // in case onlySelection was asked for, but sel wasn't Ok |
| 856 |
|
| 857 |
} else { |
| 858 |
item = start; |
| 859 |
} |
| 860 |
|
| 861 |
while(item.IsOk()) { |
| 862 |
GUICraftItemData* data = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 863 |
if(data) { |
| 864 |
wxcWidget* wb = dynamic_cast<wxcWidget*>(data->m_wxcWidget); |
| 865 |
if(wb) { |
| 866 |
TopLevelWinWrapper* tl = dynamic_cast<TopLevelWinWrapper*>(wb); |
| 867 |
if(tl) { |
| 868 |
wxString text; |
| 869 |
tl->ToXRC(text, wxcWidget::XRC_LIVE); |
| 870 |
output << text; |
| 871 |
if(flags & kGenCodeSelectionOnly) { |
| 872 |
break; // We only want a single tlw, so don't loop |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
item = m_treeControls->GetNextChild(m_treeControls->GetRootItem(), cookie); |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
void GUICraftMainPanel::OnSizerTool(wxCommandEvent& e) |
| 882 |
{ |
| 883 |
GUICraftItemData* itemData = GetSelItemData(); |
| 884 |
CHECK_POINTER(itemData); |
| 885 |
CHECK_POINTER(itemData->m_wxcWidget); |
| 886 |
|
| 887 |
wxString bitname = GetStyleFromGuiID(e.GetId()); |
| 888 |
if(bitname.IsEmpty()) { |
| 889 |
return; |
| 890 |
} |
| 891 |
|
| 892 |
itemData->m_wxcWidget->EnableSizerFlag(bitname, e.IsChecked()); |
| 893 |
|
| 894 |
if(bitname == "wxALL") { |
| 895 |
itemData->m_wxcWidget->EnableSizerFlag("wxLEFT", e.IsChecked()); |
| 896 |
itemData->m_wxcWidget->EnableSizerFlag("wxRIGHT", e.IsChecked()); |
| 897 |
itemData->m_wxcWidget->EnableSizerFlag("wxTOP", e.IsChecked()); |
| 898 |
itemData->m_wxcWidget->EnableSizerFlag("wxBOTTOM", e.IsChecked()); |
| 899 |
} |
| 900 |
|
| 901 |
wxcEditManager::Get().PushState("sizer flags change"); |
| 902 |
DoUpdatPropertiesFlags(itemData->m_wxcWidget); |
| 903 |
NotifyPreviewChanged(); |
| 904 |
} |
| 905 |
|
| 906 |
void GUICraftMainPanel::OnSizerToolUI(wxUpdateUIEvent& e) |
| 907 |
{ |
| 908 |
if(!wxcProjectMetadata::Get().IsLoaded()) { |
| 909 |
e.Enable(false); |
| 910 |
return; |
| 911 |
} |
| 912 |
|
| 913 |
GUICraftItemData* itemData = GetSelItemData(); |
| 914 |
if(!itemData || !itemData->m_wxcWidget || !itemData->m_wxcWidget->IsSizerItem()) { |
| 915 |
e.Enable(false); |
| 916 |
e.Check(false); |
| 917 |
return; |
| 918 |
} |
| 919 |
|
| 920 |
e.Enable(true); |
| 921 |
wxString bitname = GetStyleFromGuiID(e.GetId()); |
| 922 |
if(bitname.IsEmpty()) { |
| 923 |
e.Enable(false); |
| 924 |
return; |
| 925 |
} |
| 926 |
|
| 927 |
if(bitname == "wxALL") { |
| 928 |
bool previous = itemData->m_wxcWidget->GetSizerFlags().Item("wxALL").is_set; |
| 929 |
bool current = itemData->m_wxcWidget->GetSizerFlags().Item("wxLEFT").is_set && |
| 930 |
itemData->m_wxcWidget->GetSizerFlags().Item("wxRIGHT").is_set && |
| 931 |
itemData->m_wxcWidget->GetSizerFlags().Item("wxTOP").is_set && |
| 932 |
itemData->m_wxcWidget->GetSizerFlags().Item("wxBOTTOM").is_set; |
| 933 |
|
| 934 |
e.Check(current); |
| 935 |
if(current != previous) { |
| 936 |
itemData->m_wxcWidget->EnableSizerFlag("wxALL", current); |
| 937 |
DoUpdatPropertiesFlags(itemData->m_wxcWidget); |
| 938 |
NotifyPreviewChanged(); |
| 939 |
} |
| 940 |
return; |
| 941 |
} |
| 942 |
|
| 943 |
if(itemData->m_wxcWidget->GetSizerFlags().Contains(bitname) && |
| 944 |
itemData->m_wxcWidget->GetSizerFlags().Item(bitname).is_set) { |
| 945 |
e.Check(true); |
| 946 |
|
| 947 |
} else { |
| 948 |
e.Check(false); |
| 949 |
} |
| 950 |
|
| 951 |
m_sizerFlags.DoUpdateUI(m_pgMgrSizerFlags->GetGrid(), e); // This will do updateui for the alignment tools |
| 952 |
} |
| 953 |
|
| 954 |
wxString GUICraftMainPanel::GetStyleFromGuiID(int guiId) const |
| 955 |
{ |
| 956 |
switch(guiId) { |
| 957 |
case ID_TOOL_ALIGN_LEFT: |
| 958 |
return STRINGFY(wxALIGN_LEFT); |
| 959 |
|
| 960 |
case ID_TOOL_ALIGN_HCENTER: |
| 961 |
return STRINGFY(wxALIGN_CENTER_HORIZONTAL); |
| 962 |
|
| 963 |
case ID_TOOL_ALIGN_RIGHT: |
| 964 |
return STRINGFY(wxALIGN_RIGHT); |
| 965 |
|
| 966 |
case ID_TOOL_ALIGN_TOP: |
| 967 |
return STRINGFY(wxALIGN_TOP); |
| 968 |
|
| 969 |
case ID_TOOL_ALIGN_VCENTER: |
| 970 |
return STRINGFY(wxALIGN_CENTER_VERTICAL); |
| 971 |
|
| 972 |
case ID_TOOL_ALIGN_BOTTOM: |
| 973 |
return STRINGFY(wxALIGN_BOTTOM); |
| 974 |
|
| 975 |
case ID_TOOL_BORDER_ALL: |
| 976 |
return STRINGFY(wxALL); |
| 977 |
|
| 978 |
case ID_TOOL_BORDER_LEFT: |
| 979 |
return STRINGFY(wxLEFT); |
| 980 |
|
| 981 |
case ID_TOOL_BORDER_TOP: |
| 982 |
return STRINGFY(wxTOP); |
| 983 |
|
| 984 |
case ID_TOOL_BORDER_RIGHT: |
| 985 |
return STRINGFY(wxRIGHT); |
| 986 |
|
| 987 |
case ID_TOOL_BORDER_BOTTOM: |
| 988 |
return STRINGFY(wxBOTTOM); |
| 989 |
|
| 990 |
case ID_TOOL_WXEXPAND: |
| 991 |
return STRINGFY(wxEXPAND); |
| 992 |
|
| 993 |
default: |
| 994 |
return ""; |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
JSONElement GUICraftMainPanel::ToJSON(const wxTreeItemId& fromItem) |
| 999 |
{ |
| 1000 |
JSONElement json = JSONElement::createArray("windows"); |
| 1001 |
wxTreeItemIdValue cookie; |
| 1002 |
wxTreeItemId rootItem = fromItem.IsOk() ? fromItem : m_treeControls->GetRootItem(); |
| 1003 |
wxTreeItemId child = m_treeControls->GetFirstChild(rootItem, cookie); |
| 1004 |
while(child.IsOk()) { |
| 1005 |
|
| 1006 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(child)); |
| 1007 |
if(itemData && itemData->m_wxcWidget) { |
| 1008 |
JSONElement obj = JSONElement::createObject(); |
| 1009 |
itemData->m_wxcWidget->FixPaths( |
| 1010 |
wxcProjectMetadata::Get().GetProjectPath()); // Fix abs paths to fit the new project file |
| 1011 |
itemData->m_wxcWidget->Serialize(obj); |
| 1012 |
json.arrayAppend(obj); |
| 1013 |
} |
| 1014 |
|
| 1015 |
child = m_treeControls->GetNextChild(rootItem, cookie); |
| 1016 |
} |
| 1017 |
DoUpdatePropertiesView(); |
| 1018 |
return json; |
| 1019 |
} |
| 1020 |
|
| 1021 |
void GUICraftMainPanel::OnSaveProject(wxCommandEvent& e) |
| 1022 |
{ |
| 1023 |
wxArrayString customControls = GetCustomControlsUsed(); |
| 1024 |
if(wxcProjectMetadata::Get().GetProjectFile().IsEmpty()) { |
| 1025 |
wxString path = |
| 1026 |
wxFileSelector(_("Save as"), wxEmptyString, _("my_gui.wxcp"), "wxCrafter Project File(*.wxcp)|*.wxcp", |
| 1027 |
wxFileSelectorDefaultWildcardStr, wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT); |
| 1028 |
if(path.IsEmpty()) { |
| 1029 |
return; |
| 1030 |
} |
| 1031 |
|
| 1032 |
wxcProjectMetadata::Get().SetProjectFile(path); |
| 1033 |
} |
| 1034 |
wxcProjectMetadata::Get().SetObjCounter(wxcWidget::GetObjCounter()); |
| 1035 |
|
| 1036 |
JSONRoot root(cJSON_Object); |
| 1037 |
|
| 1038 |
// If we dont have bitmap function assigned to this project, create new one |
| 1039 |
if(wxcProjectMetadata::Get().GetBitmapFunction().IsEmpty()) { |
| 1040 |
wxcProjectMetadata::Get().GenerateBitmapFunctionName(); |
| 1041 |
} |
| 1042 |
|
| 1043 |
JSONElement metadata = wxcProjectMetadata::Get().ToJSON(); |
| 1044 |
wxcProjectMetadata::Get().AppendCustomControlsJSON(customControls, metadata); |
| 1045 |
root.toElement().append(metadata); |
| 1046 |
|
| 1047 |
wxFFile fp(wxcProjectMetadata::Get().GetProjectFile(), "w+b"); |
| 1048 |
if(fp.IsOpened()) { |
| 1049 |
root.toElement().append(ToJSON()); |
| 1050 |
|
| 1051 |
fp.Write(root.toElement().format(), wxConvUTF8); |
| 1052 |
fp.Close(); |
| 1053 |
|
| 1054 |
// Notify that this project was saved |
| 1055 |
wxCommandEvent eventSave(wxEVT_WXGUI_PROJECT_SAVED); |
| 1056 |
EventNotifier::Get()->AddPendingEvent(eventSave); |
| 1057 |
|
| 1058 |
} else { |
| 1059 |
|
| 1060 |
wxString msg; |
| 1061 |
msg << _("Error occurred while opening file '") << wxcProjectMetadata::Get().GetProjectFile() |
| 1062 |
<< _("' for writing"); |
| 1063 |
wxMessageBox(msg, "wxCrafter", wxICON_ERROR | wxOK | wxCENTER); |
| 1064 |
} |
| 1065 |
} |
| 1066 |
|
| 1067 |
void GUICraftMainPanel::OnOpenProject(wxCommandEvent& e) |
| 1068 |
{ |
| 1069 |
wxcSettings::Get().SetInitCompleted(true); |
| 1070 |
if(!e.GetString().IsEmpty() && wxcProjectMetadata::Get().IsLoaded() && |
| 1071 |
e.GetString() == wxcProjectMetadata::Get().GetProjectFile()) { |
| 1072 |
// the currently loaded file is the same as this one |
| 1073 |
// do nothing |
| 1074 |
if(!IsShown()) { |
| 1075 |
Show(); |
| 1076 |
} |
| 1077 |
Raise(); |
| 1078 |
return; |
| 1079 |
} |
| 1080 |
|
| 1081 |
if(wxcProjectMetadata::Get().IsLoaded() && wxcEditManager::Get().IsDirty()) { |
| 1082 |
if(::wxMessageBox(_("Current file has been modified\nContinue?"), "wxCrafter", wxYES_NO | wxCANCEL | wxCENTER, |
| 1083 |
wxCrafter::TopFrame()) != wxYES) { |
| 1084 |
return; |
| 1085 |
} |
| 1086 |
} |
| 1087 |
|
| 1088 |
wxString path = e.GetString(); |
| 1089 |
if(path.IsEmpty()) { |
| 1090 |
// User request |
| 1091 |
path = wxFileSelector(_("Open wxCrafter project"), wxEmptyString, wxEmptyString, wxEmptyString, |
| 1092 |
"wxCrafter Project File(*.wxcp)|*.wxcp", wxFD_OPEN); |
| 1093 |
|
| 1094 |
} else { |
| 1095 |
// Progrematically |
| 1096 |
wxFileName curfile = wxcProjectMetadata::Get().GetProjectFile(); |
| 1097 |
wxFileName newfile = path; |
| 1098 |
|
| 1099 |
wxString p1, p2; |
| 1100 |
p1 = curfile.GetFullPath(); |
| 1101 |
p2 = path; |
| 1102 |
if(curfile == path) { |
| 1103 |
return; |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
if(path.IsEmpty() == false) { |
| 1108 |
|
| 1109 |
/// update the history list |
| 1110 |
wxArrayString history = wxcSettings::Get().GetHistory(); |
| 1111 |
if(history.Index(path) == wxNOT_FOUND) { |
| 1112 |
history.Add(path); |
| 1113 |
wxcSettings::Get().SetHistory(history); |
| 1114 |
wxcSettings::Get().Save(); |
| 1115 |
} |
| 1116 |
|
| 1117 |
wxFileName fn(path); |
| 1118 |
wxFFile fp(fn.GetFullPath(), "r+b"); |
| 1119 |
if(fp.IsOpened()) { |
| 1120 |
wxString content; |
| 1121 |
fp.ReadAll(&content, wxConvUTF8); |
| 1122 |
fp.Close(); |
| 1123 |
|
| 1124 |
// Update the root item |
| 1125 |
wxString rootText; |
| 1126 |
rootText << fn.GetFullPath(); |
| 1127 |
m_treeControls->SetItemText(m_treeControls->GetRootItem(), rootText); |
| 1128 |
LoadProject(fn, content); |
| 1129 |
|
| 1130 |
// The next line shouldn't be necessary, as it's done when the wxEVT_WXC_PROJECT_LOADED event is handled in |
| 1131 |
// wxcEditManager |
| 1132 |
// However, for unknown reasons, a heisenbug sometimes makes that event not arrive, which means the initial |
| 1133 |
// state is |
| 1134 |
// never initialised; this prevents the first Undo from being undoable. So, until the bug is squashed: |
| 1135 |
wxcEditManager::Get().SaveInitialState(CurrentState()); |
| 1136 |
|
| 1137 |
// notify about project load |
| 1138 |
wxCommandEvent evtProjectLoaded(wxEVT_WXC_PROJECT_LOADED); |
| 1139 |
evtProjectLoaded.SetString(fn.GetFullPath()); |
| 1140 |
EventNotifier::Get()->AddPendingEvent(evtProjectLoaded); |
| 1141 |
} |
| 1142 |
} |
| 1143 |
} |
| 1144 |
|
| 1145 |
void GUICraftMainPanel::LoadProject(const wxFileName& fn, const wxString& fileContent, bool lightLoad) |
| 1146 |
{ |
| 1147 |
bool deleteAllItems = false; |
| 1148 |
wxFileName project_file = fn; |
| 1149 |
JSONRoot json(fileContent); |
| 1150 |
if(!lightLoad) { |
| 1151 |
Clear(); |
| 1152 |
|
| 1153 |
// Read the metadata first |
| 1154 |
wxcProjectMetadata::Get().SetProjectFile(fn.GetFullPath()); |
| 1155 |
wxcProjectMetadata::Get().FromJSON(json.toElement().namedObject("metadata")); |
| 1156 |
wxcProjectMetadata::Get().UpdatePaths(); |
| 1157 |
|
| 1158 |
} else { |
| 1159 |
deleteAllItems = true; |
| 1160 |
} |
| 1161 |
|
| 1162 |
// Read the top-level windows |
| 1163 |
JSONElement windows = json.toElement().namedObject("windows"); |
| 1164 |
int nCount = windows.arraySize(); |
| 1165 |
|
| 1166 |
#ifdef __WXMSW__ |
| 1167 |
wxWindowUpdateLocker locker(m_treeControls); |
| 1168 |
#endif |
| 1169 |
if(deleteAllItems) { |
| 1170 |
m_treeControls->DeleteAllItems(); |
| 1171 |
m_treeControls->AddRoot(_("wxCrafter Project"), 0, 0); |
| 1172 |
project_file = wxcProjectMetadata::Get().GetProjectFile(); |
| 1173 |
wxcProjectMetadata::Get().FromJSON( |
| 1174 |
json.toElement().namedObject("metadata")); // Needed for Redo() to work correctly |
| 1175 |
wxcProjectMetadata::Get().UpdatePaths(); |
| 1176 |
} |
| 1177 |
|
| 1178 |
wxTreeItemId dummy; |
| 1179 |
for(int i = 0; i < nCount; i++) { |
| 1180 |
wxcWidget* wrapper = Allocator::Instance()->CreateWrapperFromJSON(windows.arrayItem(i)); |
| 1181 |
DoBuildTree(dummy, wrapper, m_treeControls->GetRootItem()); |
| 1182 |
} |
| 1183 |
|
| 1184 |
wxTreeItemIdValue cookie; |
| 1185 |
wxTreeItemId rootItem = m_treeControls->GetRootItem(); |
| 1186 |
wxTreeItemId firstChild = m_treeControls->GetFirstChild(rootItem, cookie); |
| 1187 |
if(firstChild.IsOk()) { |
| 1188 |
m_treeControls->SelectItem(firstChild); |
| 1189 |
} |
| 1190 |
NotifyPreviewChanged(wxEVT_WXGUI_PROJECT_LOADED); |
| 1191 |
|
| 1192 |
wxString rootText = project_file.IsOk() ? project_file.GetFullPath() : _("wxCrafter Project"); |
| 1193 |
|
| 1194 |
m_treeControls->SetItemText(m_treeControls->GetRootItem(), rootText); |
| 1195 |
wxcWidget::SetObjCounter(wxcProjectMetadata::Get().GetObjCounter()); |
| 1196 |
|
| 1197 |
// Expand the top level root item |
| 1198 |
if(rootItem.IsOk() && m_treeControls->ItemHasChildren(rootItem)) { |
| 1199 |
m_treeControls->Expand(rootItem); |
| 1200 |
} |
| 1201 |
} |
| 1202 |
|
| 1203 |
void GUICraftMainPanel::DoBuildTree(wxTreeItemId& itemToSelect, wxcWidget* wrapper, const wxTreeItemId& parent, |
| 1204 |
const wxTreeItemId& beforeItem, bool insertBefore) |
| 1205 |
{ |
| 1206 |
CHECK_PTR_RET(wrapper); |
| 1207 |
int imgId = Allocator::Instance()->GetImageId(wrapper->GetType()); |
| 1208 |
wxTreeItemId item; |
| 1209 |
|
| 1210 |
if(beforeItem.IsOk()) { |
| 1211 |
|
| 1212 |
wxTreeItemId insertionItem = beforeItem; |
| 1213 |
if(insertBefore) { |
| 1214 |
insertionItem = m_treeControls->GetPrevSibling(beforeItem); |
| 1215 |
if(insertionItem.IsOk() == false) { |
| 1216 |
insertionItem = parent; |
| 1217 |
} |
| 1218 |
} |
| 1219 |
|
| 1220 |
item = m_treeControls->InsertItem(parent, insertionItem, wrapper->GetName(), imgId, imgId, |
| 1221 |
new GUICraftItemData(wrapper)); |
| 1222 |
if(itemToSelect.IsOk() == false) { |
| 1223 |
itemToSelect = item; |
| 1224 |
} |
| 1225 |
|
| 1226 |
} else { |
| 1227 |
|
| 1228 |
item = m_treeControls->AppendItem(parent, wrapper->GetName(), imgId, imgId, new GUICraftItemData(wrapper)); |
| 1229 |
if(itemToSelect.IsOk() == false) { |
| 1230 |
itemToSelect = item; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
wxcWidget::List_t::const_iterator iter = wrapper->GetChildren().begin(); |
| 1235 |
for(; iter != wrapper->GetChildren().end(); ++iter) { |
| 1236 |
DoBuildTree(itemToSelect, (*iter), item); |
| 1237 |
} |
| 1238 |
} |
| 1239 |
|
| 1240 |
void GUICraftMainPanel::DoUnsetItemData(const wxTreeItemId& item) |
| 1241 |
{ |
| 1242 |
if(item.IsOk()) { |
| 1243 |
|
| 1244 |
// Remove the WrapperBase item associated with this item-data |
| 1245 |
// by setting it to NULL |
| 1246 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 1247 |
if(itemData) { |
| 1248 |
itemData->m_wxcWidget = NULL; |
| 1249 |
} |
| 1250 |
|
| 1251 |
if(m_treeControls->ItemHasChildren(item)) { |
| 1252 |
wxTreeItemIdValue cookie; |
| 1253 |
wxTreeItemId child = m_treeControls->GetFirstChild(item, cookie); |
| 1254 |
while(child.IsOk()) { |
| 1255 |
DoUnsetItemData(child); |
| 1256 |
child = m_treeControls->GetNextChild(item, cookie); |
| 1257 |
} |
| 1258 |
} |
| 1259 |
} |
| 1260 |
} |
| 1261 |
|
| 1262 |
void GUICraftMainPanel::DoMoveToplevelWindow(wxcWidget* tlw, int direction) |
| 1263 |
{ |
| 1264 |
CHECK_POINTER(tlw); |
| 1265 |
wxTreeItemId treeItem = m_treeControls->GetSelection(); |
| 1266 |
CHECK_TREEITEM(treeItem); |
| 1267 |
wxTreeItemId root = m_treeControls->GetRootItem(); |
| 1268 |
CHECK_TREEITEM(root); |
| 1269 |
wxTreeItemId target; |
| 1270 |
bool doPrepend(false); |
| 1271 |
|
| 1272 |
if(direction == ID_MOVE_NODE_DOWN) { |
| 1273 |
target = m_treeControls->GetNextSibling(treeItem); |
| 1274 |
CHECK_TREEITEM(target); |
| 1275 |
|
| 1276 |
} else { |
| 1277 |
// There's no InsertBefore(), so we need to go up 2, then InsertAfter() |
| 1278 |
target = m_treeControls->GetPrevSibling(treeItem); |
| 1279 |
CHECK_TREEITEM(target); |
| 1280 |
wxTreeItemId previous = m_treeControls->GetPrevSibling(target); |
| 1281 |
if(previous.IsOk()) { |
| 1282 |
target = previous; |
| 1283 |
} else { |
| 1284 |
// The exception: we can't go up by 2 if the second item is moving above the first. So: |
| 1285 |
doPrepend = true; |
| 1286 |
} |
| 1287 |
} |
| 1288 |
int image = m_treeControls->GetItemImage(treeItem); |
| 1289 |
wxString text = m_treeControls->GetItemText(treeItem); |
| 1290 |
|
| 1291 |
#ifdef __WXMSW__ |
| 1292 |
wxWindowUpdateLocker locker(m_treeControls); |
| 1293 |
#endif |
| 1294 |
|
| 1295 |
DoUnsetItemData(treeItem); |
| 1296 |
m_treeControls->Delete(treeItem); |
| 1297 |
|
| 1298 |
wxTreeItemId insertedItem; |
| 1299 |
if(!doPrepend) { |
| 1300 |
insertedItem = m_treeControls->InsertItem(root, target, text, image, image, new GUICraftItemData(tlw)); |
| 1301 |
} else { |
| 1302 |
insertedItem = m_treeControls->AppendItem(root, text, image, image, new GUICraftItemData(tlw)); |
| 1303 |
} |
| 1304 |
|
| 1305 |
CHECK_TREEITEM(insertedItem); |
| 1306 |
|
| 1307 |
// Restore the parent tree item data |
| 1308 |
wxTreeItemId dummy; |
| 1309 |
const wxcWidget::List_t& list = tlw->GetChildren(); |
| 1310 |
wxcWidget::List_t::const_iterator iter = list.begin(); |
| 1311 |
for(; iter != list.end(); ++iter) { |
| 1312 |
DoBuildTree(dummy, *iter, insertedItem); |
| 1313 |
} |
| 1314 |
|
| 1315 |
m_treeControls->EnsureVisible(insertedItem); |
| 1316 |
m_treeControls->SelectItem(insertedItem); |
| 1317 |
|
| 1318 |
wxcEditManager::Get().PushState("top-level window move"); |
| 1319 |
DoRefresh(wxEVT_UPDATE_PREVIEW); |
| 1320 |
} |
| 1321 |
|
| 1322 |
void GUICraftMainPanel::OnMoveItem(wxCommandEvent& e) |
| 1323 |
{ |
| 1324 |
GUICraftItemData* itemData = GetSelItemData(); |
| 1325 |
if(!itemData || !itemData->m_wxcWidget) { |
| 1326 |
return; |
| 1327 |
} else if(!itemData->m_wxcWidget->GetParent()) { |
| 1328 |
return DoMoveToplevelWindow(itemData->m_wxcWidget, e.GetId()); |
| 1329 |
} |
| 1330 |
|
| 1331 |
wxTreeItemId treeItem, treeItemParent; |
| 1332 |
treeItem = m_treeControls->GetSelection(); |
| 1333 |
CHECK_TREEITEM(treeItem); |
| 1334 |
|
| 1335 |
treeItemParent = m_treeControls->GetItemParent(treeItem); |
| 1336 |
CHECK_TREEITEM(treeItemParent); |
| 1337 |
|
| 1338 |
wxString itemName = itemData->m_wxcWidget->GetName(); |
| 1339 |
wxcWidget* nodeToMove = itemData->m_wxcWidget; |
| 1340 |
CHECK_POINTER(nodeToMove->GetParent()); |
| 1341 |
wxcWidget* subTree(NULL); |
| 1342 |
|
| 1343 |
switch(e.GetId()) { |
| 1344 |
case ID_MOVE_NODE_DOWN: |
| 1345 |
nodeToMove->MoveDown(); |
| 1346 |
subTree = nodeToMove->GetParent(); |
| 1347 |
break; |
| 1348 |
case ID_MOVE_NODE_UP: |
| 1349 |
nodeToMove->MoveUp(); |
| 1350 |
subTree = nodeToMove->GetParent(); |
| 1351 |
break; |
| 1352 |
case ID_MOVE_NODE_INTO_SIZER: |
| 1353 |
treeItemParent = m_treeControls->GetItemParent(treeItemParent); // We need to go back a generation this time |
| 1354 |
CHECK_TREEITEM(treeItemParent); |
| 1355 |
{ |
| 1356 |
wxcWidget* grandparent = nodeToMove->GetParent()->GetParent(); |
| 1357 |
wxCHECK_RET(grandparent && grandparent->IsSizer(), "UpdateUI failure: No grandparent sizer"); |
| 1358 |
nodeToMove->Reparent(grandparent); |
| 1359 |
subTree = grandparent; |
| 1360 |
} |
| 1361 |
break; |
| 1362 |
case ID_MOVE_NODE_INTO_SIBLING: |
| 1363 |
wxcWidget* siblingSizer = nodeToMove->GetAdjacentSiblingSizer(); |
| 1364 |
wxCHECK_RET(siblingSizer, "UpdateUI failure: No adjacent sibling sizer"); |
| 1365 |
nodeToMove->Reparent(siblingSizer); |
| 1366 |
subTree = siblingSizer->GetParent(); |
| 1367 |
} |
| 1368 |
CHECK_POINTER(subTree); |
| 1369 |
|
| 1370 |
#ifdef __WXMSW__ |
| 1371 |
wxWindowUpdateLocker locker(m_treeControls); |
| 1372 |
#endif |
| 1373 |
|
| 1374 |
DoUnsetItemData(treeItemParent); |
| 1375 |
m_treeControls->DeleteChildren(treeItemParent); |
| 1376 |
|
| 1377 |
// Restore the parent tree item data |
| 1378 |
wxTreeItemId dummy; |
| 1379 |
m_treeControls->SetItemData(treeItemParent, new GUICraftItemData(subTree)); |
| 1380 |
const wxcWidget::List_t& list = subTree->GetChildren(); |
| 1381 |
wxcWidget::List_t::const_iterator iter = list.begin(); |
| 1382 |
for(; iter != list.end(); ++iter) { |
| 1383 |
DoBuildTree(dummy, *iter, treeItemParent); |
| 1384 |
} |
| 1385 |
|
| 1386 |
wxTreeItemId where; |
| 1387 |
DoFindName(treeItemParent, itemName, where); |
| 1388 |
if(where.IsOk()) { |
| 1389 |
m_treeControls->EnsureVisible(where); |
| 1390 |
m_treeControls->SelectItem(where); |
| 1391 |
} |
| 1392 |
|
| 1393 |
wxcEditManager::Get().PushState("move"); |
| 1394 |
DoRefresh(wxEVT_UPDATE_PREVIEW); |
| 1395 |
} |
| 1396 |
|
| 1397 |
void GUICraftMainPanel::OnDelete(wxCommandEvent& e) |
| 1398 |
{ |
| 1399 |
GUICraftItemData* data = GetSelItemData(); |
| 1400 |
if(data) { |
| 1401 |
int eventType = wxEVT_UPDATE_PREVIEW; |
| 1402 |
if(data->m_wxcWidget->IsTopWindow()) { |
| 1403 |
// Notify the preview that we are about to delete the entire preview page |
| 1404 |
NotifyPreviewChanged(wxEVT_WXGUI_PROJECT_CLOSED); |
| 1405 |
eventType = wxEVT_WXGUI_PROJECT_LOADED; |
| 1406 |
} |
| 1407 |
|
| 1408 |
wxTreeItemId newSel = DoFindBestSelection(m_treeControls->GetSelection()); |
| 1409 |
|
| 1410 |
m_treeControls->DeleteChildren(m_treeControls->GetSelection()); |
| 1411 |
m_treeControls->Delete(m_treeControls->GetSelection()); |
| 1412 |
if(newSel.IsOk()) { |
| 1413 |
m_treeControls->SelectItem(newSel); |
| 1414 |
} |
| 1415 |
CallAfter(&GUICraftMainPanel::DoRefresh, eventType); |
| 1416 |
m_treeControls->CallAfter(&clTreeCtrl::SetFocus); // Without this, focus will unexpectedly appear elsewhere, |
| 1417 |
// e.g. on a propertygrid style |
| 1418 |
wxcEditManager::Get().PushState("deletion"); |
| 1419 |
} |
| 1420 |
} |
| 1421 |
|
| 1422 |
void GUICraftMainPanel::DoRefresh(int eventType) |
| 1423 |
{ |
| 1424 |
DoUpdatePropertiesView(); |
| 1425 |
NotifyPreviewChanged(eventType); |
| 1426 |
} |
| 1427 |
|
| 1428 |
void GUICraftMainPanel::ExpandToItem(const wxString& name, wxTreeItemId& searchFromItem) |
| 1429 |
{ |
| 1430 |
if(!searchFromItem.IsOk()) { |
| 1431 |
searchFromItem = m_treeControls->GetRootItem(); |
| 1432 |
} |
| 1433 |
|
| 1434 |
wxTreeItemId item; |
| 1435 |
DoFindName(searchFromItem, name, item); |
| 1436 |
if(item.IsOk()) { |
| 1437 |
m_treeControls->Expand(item); |
| 1438 |
m_treeControls->EnsureVisible(item); |
| 1439 |
m_treeControls->SelectItem(item); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
void GUICraftMainPanel::DoFindName(const wxTreeItemId& parent, const wxString& name, wxTreeItemId& item) |
| 1444 |
{ |
| 1445 |
if(item.IsOk()) { |
| 1446 |
return; |
| 1447 |
} |
| 1448 |
|
| 1449 |
if(parent.IsOk() == false) { |
| 1450 |
return; |
| 1451 |
} |
| 1452 |
|
| 1453 |
if(m_treeControls->GetItemText(parent) == name) { |
| 1454 |
item = parent; |
| 1455 |
return; |
| 1456 |
} |
| 1457 |
|
| 1458 |
if(m_treeControls->ItemHasChildren(parent)) { |
| 1459 |
wxTreeItemIdValue cookie; |
| 1460 |
wxTreeItemId child = m_treeControls->GetFirstChild(parent, cookie); |
| 1461 |
while(child.IsOk()) { |
| 1462 |
DoFindName(child, name, item); |
| 1463 |
if(item.IsOk()) { |
| 1464 |
return; |
| 1465 |
} |
| 1466 |
child = m_treeControls->GetNextChild(parent, cookie); |
| 1467 |
} |
| 1468 |
} |
| 1469 |
} |
| 1470 |
|
| 1471 |
void GUICraftMainPanel::OnMoveItemUI(wxUpdateUIEvent& e) |
| 1472 |
{ |
| 1473 |
e.Enable(false); // Disable by default here; it simplifies all the 'if' statements |
| 1474 |
|
| 1475 |
GUICraftItemData* d = GetSelItemData(); |
| 1476 |
CHECK_POINTER(d); |
| 1477 |
wxcWidget* control = d->m_wxcWidget; |
| 1478 |
CHECK_POINTER(control); |
| 1479 |
|
| 1480 |
if(e.GetId() == ID_MOVE_NODE_DOWN) { |
| 1481 |
if(control->GetParent()) { |
| 1482 |
e.Enable(control->CanMoveDown()); |
| 1483 |
} else if(control->IsTopWindow()) { |
| 1484 |
wxTreeItemId item; |
| 1485 |
DoFindName(m_treeControls->GetRootItem(), control->GetName(), item); |
| 1486 |
if(item.IsOk()) { |
| 1487 |
e.Enable(m_treeControls->GetNextSibling(item).IsOk()); |
| 1488 |
} |
| 1489 |
} |
| 1490 |
|
| 1491 |
} else if(e.GetId() == ID_MOVE_NODE_UP) { |
| 1492 |
if(control->GetParent()) { |
| 1493 |
e.Enable(control->CanMoveUp()); |
| 1494 |
} else if(control->IsTopWindow()) { |
| 1495 |
wxTreeItemId item; |
| 1496 |
DoFindName(m_treeControls->GetRootItem(), control->GetName(), item); |
| 1497 |
if(item.IsOk()) { |
| 1498 |
e.Enable(m_treeControls->GetPrevSibling(item).IsOk()); |
| 1499 |
} |
| 1500 |
} |
| 1501 |
} else if(e.GetId() == ID_MOVE_NODE_INTO_SIZER) { |
| 1502 |
if(!control->IsSizerItem()) { |
| 1503 |
return; |
| 1504 |
} |
| 1505 |
wxcWidget* parent = control->GetParent(); |
| 1506 |
CHECK_POINTER(parent); |
| 1507 |
if(parent->IsSizer()) { |
| 1508 |
wxcWidget* grandparent = parent->GetParent(); |
| 1509 |
e.Enable(grandparent && grandparent->IsSizer()); |
| 1510 |
} |
| 1511 |
} else if(e.GetId() == ID_MOVE_NODE_INTO_SIBLING) { |
| 1512 |
if(!control->IsSizerItem()) { |
| 1513 |
return; |
| 1514 |
} |
| 1515 |
if(control->CanMoveRight()) { |
| 1516 |
bool isAbove; |
| 1517 |
control->GetAdjacentSiblingSizer(&isAbove); // Which icon should we use? upper-right or lower-right? |
| 1518 |
wxCrafter::ResourceLoader bmps; |
| 1519 |
if(isAbove) { |
| 1520 |
m_toolbar->SetToolBitmap(ID_MOVE_NODE_INTO_SIBLING, bmps.Bitmap("move-upper-right")); |
| 1521 |
} else { |
| 1522 |
m_toolbar->SetToolBitmap(ID_MOVE_NODE_INTO_SIBLING, bmps.Bitmap("move-lower-right")); |
| 1523 |
} |
| 1524 |
|
| 1525 |
e.Enable(true); |
| 1526 |
} |
| 1527 |
} |
| 1528 |
} |
| 1529 |
|
| 1530 |
void GUICraftMainPanel::OnSetSizerProp1(wxCommandEvent& e) |
| 1531 |
{ |
| 1532 |
GUICraftItemData* d = GetSelItemData(); |
| 1533 |
CHECK_POINTER(d); |
| 1534 |
CHECK_POINTER(d->m_wxcWidget); |
| 1535 |
|
| 1536 |
if(e.IsChecked()) { |
| 1537 |
d->m_wxcWidget->SizerItem().SetProportion(1); |
| 1538 |
m_sizerFlags.Construct(m_pgMgrSizerFlags->GetGrid(), d->m_wxcWidget); |
| 1539 |
|
| 1540 |
} else { |
| 1541 |
d->m_wxcWidget->SizerItem().SetProportion(0); |
| 1542 |
m_sizerFlags.Construct(m_pgMgrSizerFlags->GetGrid(), d->m_wxcWidget); |
| 1543 |
} |
| 1544 |
|
| 1545 |
wxcEditManager::Get().PushState("sizer proportion change"); |
| 1546 |
NotifyPreviewChanged(); |
| 1547 |
} |
| 1548 |
|
| 1549 |
void GUICraftMainPanel::OnSetSizerProp1UI(wxUpdateUIEvent& e) |
| 1550 |
{ |
| 1551 |
GUICraftItemData* d = GetSelItemData(); |
| 1552 |
if(!d || !d->m_wxcWidget || !d->m_wxcWidget->IsSizerItem()) { |
| 1553 |
e.Check(false); |
| 1554 |
e.Enable(false); |
| 1555 |
return; |
| 1556 |
|
| 1557 |
} else { |
| 1558 |
e.Enable(wxcProjectMetadata::Get().IsLoaded()); |
| 1559 |
e.Check(d->m_wxcWidget->SizerItem().GetProportion() == 1); |
| 1560 |
} |
| 1561 |
} |
| 1562 |
|
| 1563 |
wxTreeItemId GUICraftMainPanel::DoGetTopLevelTreeItem() const |
| 1564 |
{ |
| 1565 |
wxTreeItemId item = m_treeControls->GetSelection(); |
| 1566 |
if(!item.IsOk()) { |
| 1567 |
return wxTreeItemId(); |
| 1568 |
} |
| 1569 |
|
| 1570 |
wxTreeItemId parent = item; |
| 1571 |
|
| 1572 |
while(true) { |
| 1573 |
|
| 1574 |
wxTreeItemId tmpParent = m_treeControls->GetItemParent(parent); |
| 1575 |
if(tmpParent.IsOk() && tmpParent != m_treeControls->GetRootItem()) { |
| 1576 |
parent = tmpParent; |
| 1577 |
|
| 1578 |
} else { |
| 1579 |
break; |
| 1580 |
} |
| 1581 |
} |
| 1582 |
return parent; |
| 1583 |
} |
| 1584 |
|
| 1585 |
void GUICraftMainPanel::OnMenuItemClicked(wxCommandEvent& e) |
| 1586 |
{ |
| 1587 |
GUICraftItemData* itemData = GetSelItemData(); |
| 1588 |
if(!itemData || !itemData->m_wxcWidget) { |
| 1589 |
e.Skip(); |
| 1590 |
return; |
| 1591 |
} |
| 1592 |
|
| 1593 |
if(Allocator::GetCommonEvents().Exists(e.GetId())) { |
| 1594 |
ConnectDetails eventDetails = Allocator::GetCommonEvents().Item(e.GetId()); |
| 1595 |
itemData->m_wxcWidget->AddEvent(eventDetails); |
| 1596 |
|
| 1597 |
} else if(itemData->m_wxcWidget->GetControlEvents().Exists(e.GetId())) { |
| 1598 |
ConnectDetails eventDetails = itemData->m_wxcWidget->GetControlEvents().Item(e.GetId()); |
| 1599 |
itemData->m_wxcWidget->AddEvent(eventDetails); |
| 1600 |
|
| 1601 |
} else { |
| 1602 |
e.Skip(); |
| 1603 |
} |
| 1604 |
} |
| 1605 |
|
| 1606 |
void GUICraftMainPanel::OnMenuItemUI(wxUpdateUIEvent& e) |
| 1607 |
{ |
| 1608 |
GUICraftItemData* itemData = GetSelItemData(); |
| 1609 |
CHECK_POINTER(itemData); |
| 1610 |
CHECK_POINTER(itemData->m_wxcWidget); |
| 1611 |
|
| 1612 |
if(Allocator::GetCommonEvents().Exists(e.GetId())) { |
| 1613 |
ConnectDetails eventDetails = Allocator::GetCommonEvents().Item(e.GetId()); |
| 1614 |
e.Check(itemData->m_wxcWidget->HasEvent(eventDetails.GetEventName())); |
| 1615 |
|
| 1616 |
} else if(itemData->m_wxcWidget->GetControlEvents().Exists(e.GetId())) { |
| 1617 |
ConnectDetails eventDetails = itemData->m_wxcWidget->GetControlEvents().Item(e.GetId()); |
| 1618 |
e.Check(itemData->m_wxcWidget->HasEvent(eventDetails.GetEventName())); |
| 1619 |
|
| 1620 |
} else { |
| 1621 |
e.Skip(); |
| 1622 |
} |
| 1623 |
} |
| 1624 |
|
| 1625 |
void GUICraftMainPanel::OnDeleteUI(wxUpdateUIEvent& e) |
| 1626 |
{ |
| 1627 |
GUICraftItemData* itemData = GetSelItemData(); |
| 1628 |
e.Enable(itemData); |
| 1629 |
} |
| 1630 |
|
| 1631 |
void GUICraftMainPanel::OnEventEditor(wxCommandEvent& e) { wxUnusedVar(e); } |
| 1632 |
|
| 1633 |
void GUICraftMainPanel::OnEventEditorCommon(wxCommandEvent& e) { wxUnusedVar(e); } |
| 1634 |
|
| 1635 |
wxTreeItemId GUICraftMainPanel::DoFindBestSelection(const wxTreeItemId& item) |
| 1636 |
{ |
| 1637 |
if(item.IsOk() == false) { |
| 1638 |
return wxTreeItemId(); |
| 1639 |
} |
| 1640 |
|
| 1641 |
wxTreeItemId newSel = m_treeControls->GetPrevSibling(item); |
| 1642 |
if(newSel.IsOk() == false) { |
| 1643 |
newSel = m_treeControls->GetNextSibling(item); |
| 1644 |
if(newSel.IsOk() == false && m_treeControls->GetItemParent(item)) { |
| 1645 |
newSel = m_treeControls->GetItemParent(item); |
| 1646 |
} |
| 1647 |
} |
| 1648 |
return newSel; |
| 1649 |
} |
| 1650 |
|
| 1651 |
bool GUICraftMainPanel::DoUpdateNotebookSelection(const wxTreeItemId& item) |
| 1652 |
{ |
| 1653 |
if(!item.IsOk()) { |
| 1654 |
return false; |
| 1655 |
} |
| 1656 |
|
| 1657 |
bool dirty = false; |
| 1658 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 1659 |
CHECK_POINTER_RET_FALSE(itemData); |
| 1660 |
CHECK_POINTER_RET_FALSE(itemData->m_wxcWidget); |
| 1661 |
|
| 1662 |
wxcWidget* wrapper = itemData->m_wxcWidget; |
| 1663 |
NotebookPageWrapper* page = NULL; |
| 1664 |
RibbonPageWrapper* ribbonPage = NULL; |
| 1665 |
while(wrapper) { |
| 1666 |
page = dynamic_cast<NotebookPageWrapper*>(wrapper); |
| 1667 |
if(page) { |
| 1668 |
break; |
| 1669 |
} |
| 1670 |
wrapper = wrapper->GetParent(); |
| 1671 |
} |
| 1672 |
|
| 1673 |
if(!page) { |
| 1674 |
wrapper = itemData->m_wxcWidget; |
| 1675 |
while(wrapper) { |
| 1676 |
ribbonPage = dynamic_cast<RibbonPageWrapper*>(wrapper); |
| 1677 |
if(ribbonPage) { |
| 1678 |
break; |
| 1679 |
} |
| 1680 |
wrapper = wrapper->GetParent(); |
| 1681 |
} |
| 1682 |
} |
| 1683 |
|
| 1684 |
if(!page && !ribbonPage) { |
| 1685 |
return false; |
| 1686 |
} |
| 1687 |
|
| 1688 |
if(page) { |
| 1689 |
// Page is an actual notebook page, get the notebook that it represents |
| 1690 |
NotebookBaseWrapper* book = page->GetNotebook(); |
| 1691 |
CHECK_POINTER_RET_FALSE(book); |
| 1692 |
|
| 1693 |
// Get the selection |
| 1694 |
dirty = (book->GetSelection() != page); |
| 1695 |
|
| 1696 |
// Mark the page as selected (it will unselect all other pages) |
| 1697 |
book->SetSelection(page); |
| 1698 |
} else { |
| 1699 |
// Page is an actual notebook page, get the notebook that it represents |
| 1700 |
RibbonBarWrapper* book = dynamic_cast<RibbonBarWrapper*>(ribbonPage->GetParent()); |
| 1701 |
CHECK_POINTER_RET_FALSE(book); |
| 1702 |
|
| 1703 |
// Get the selection |
| 1704 |
dirty = (book->GetSelection() != ribbonPage); |
| 1705 |
|
| 1706 |
// Mark the page as selected (it will unselect all other pages) |
| 1707 |
book->SetSelection(ribbonPage); |
| 1708 |
} |
| 1709 |
return dirty; |
| 1710 |
} |
| 1711 |
|
| 1712 |
void GUICraftMainPanel::OnPreviewItemSelected(wxCommandEvent& e) |
| 1713 |
{ |
| 1714 |
e.Skip(); |
| 1715 |
wxString controlName = e.GetString(); |
| 1716 |
wxTreeItemId item = DoGetTopLevelTreeItem(); |
| 1717 |
if(item.IsOk()) { |
| 1718 |
wxTreeItemId sel; |
| 1719 |
DoFindName(item, controlName, sel); |
| 1720 |
if(sel.IsOk()) { |
| 1721 |
m_treeControls->EnsureVisible(sel); |
| 1722 |
bManualSelection = true; |
| 1723 |
m_treeControls->SelectItem(sel); |
| 1724 |
bManualSelection = false; |
| 1725 |
DoUpdatePropertiesView(); |
| 1726 |
} |
| 1727 |
} |
| 1728 |
} |
| 1729 |
|
| 1730 |
void GUICraftMainPanel::OnSelectToplevelItem(wxCommandEvent& e) |
| 1731 |
{ |
| 1732 |
wxTreeItemId item = DoGetTopLevelTreeItem(); |
| 1733 |
if(item.IsOk()) { |
| 1734 |
bManualSelection = true; |
| 1735 |
m_treeControls->EnsureVisible(item); |
| 1736 |
m_treeControls->SelectItem(item); |
| 1737 |
bManualSelection = false; |
| 1738 |
DoUpdatePropertiesView(); |
| 1739 |
} |
| 1740 |
} |
| 1741 |
|
| 1742 |
void GUICraftMainPanel::OnBookPageSelected(wxCommandEvent& e) |
| 1743 |
{ |
| 1744 |
wxTreeItemId item; |
| 1745 |
DoFindName(DoGetTopLevelTreeItem(), e.GetString(), item); |
| 1746 |
if(item.IsOk()) { |
| 1747 |
GUICraftItemData* d = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 1748 |
CHECK_POINTER(d); |
| 1749 |
CHECK_POINTER(d->m_wxcWidget); |
| 1750 |
|
| 1751 |
NotebookPageWrapper* page = dynamic_cast<NotebookPageWrapper*>(d->m_wxcWidget); |
| 1752 |
CHECK_POINTER(page); |
| 1753 |
|
| 1754 |
NotebookBaseWrapper* book = page->GetNotebook(); |
| 1755 |
CHECK_POINTER(book); |
| 1756 |
|
| 1757 |
book->SetSelection(page); |
| 1758 |
bManualSelection = true; |
| 1759 |
m_treeControls->SelectItem(item); |
| 1760 |
bManualSelection = false; |
| 1761 |
m_treeControls->EnsureVisible(item); |
| 1762 |
} |
| 1763 |
} |
| 1764 |
|
| 1765 |
void GUICraftMainPanel::OnRibbonPageSelected(wxCommandEvent& e) |
| 1766 |
{ |
| 1767 |
wxTreeItemId item; |
| 1768 |
DoFindName(DoGetTopLevelTreeItem(), e.GetString(), item); |
| 1769 |
if(item.IsOk()) { |
| 1770 |
GUICraftItemData* d = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 1771 |
CHECK_POINTER(d); |
| 1772 |
CHECK_POINTER(d->m_wxcWidget); |
| 1773 |
|
| 1774 |
RibbonPageWrapper* page = dynamic_cast<RibbonPageWrapper*>(d->m_wxcWidget); |
| 1775 |
CHECK_POINTER(page); |
| 1776 |
|
| 1777 |
RibbonBarWrapper* ribbonbar = dynamic_cast<RibbonBarWrapper*>(page->GetParent()); |
| 1778 |
CHECK_POINTER(ribbonbar); |
| 1779 |
|
| 1780 |
ribbonbar->SetSelection(page); |
| 1781 |
bManualSelection = true; |
| 1782 |
m_treeControls->SelectItem(item); |
| 1783 |
bManualSelection = false; |
| 1784 |
m_treeControls->EnsureVisible(item); |
| 1785 |
} |
| 1786 |
} |
| 1787 |
|
| 1788 |
void GUICraftMainPanel::OnCut(wxCommandEvent& e) |
| 1789 |
{ |
| 1790 |
if(!m_plugin->IsMainViewActive()) { |
| 1791 |
e.Skip(); // This event is nothing to do with us |
| 1792 |
return; |
| 1793 |
} |
| 1794 |
|
| 1795 |
if(!IsTreeViewSelected()) { |
| 1796 |
e.Skip(); // The treeview isn't selected, so don't cut its selection! |
| 1797 |
return; |
| 1798 |
} |
| 1799 |
|
| 1800 |
GUICraftItemData* itemData = GetSelItemData(); |
| 1801 |
CHECK_POINTER(itemData); |
| 1802 |
CHECK_POINTER(itemData->m_wxcWidget); |
| 1803 |
|
| 1804 |
wxDELETE(m_clipboardItem); |
| 1805 |
|
| 1806 |
m_clipboardItem = itemData->m_wxcWidget; |
| 1807 |
m_clipboardItem->SetCopyReason(wxcWidget::CR_Cut); |
| 1808 |
|
| 1809 |
wxWindowUpdateLocker locker(m_treeControls); |
| 1810 |
|
| 1811 |
// This step is needed so when we delete the GUI subtree, the |
| 1812 |
// metadata kept on each node is not deleted |
| 1813 |
wxTreeItemId item = m_treeControls->GetSelection(); |
| 1814 |
DoUnsetItemData(item); |
| 1815 |
|
| 1816 |
// disconnect this item from the its parent |
| 1817 |
m_clipboardItem->RemoveFromParent(); |
| 1818 |
|
| 1819 |
if(m_treeControls->ItemHasChildren(item)) { |
| 1820 |
m_treeControls->DeleteChildren(item); |
| 1821 |
} |
| 1822 |
m_treeControls->Delete(item); |
| 1823 |
|
| 1824 |
NotifyPreviewChanged(); |
| 1825 |
|
| 1826 |
// Without this, focus will unexpectedly appear elsewhere, e.g. on a propertygrid style. And for Cut, it still does; |
| 1827 |
// Copy/Paste/Del work OK though :/ |
| 1828 |
m_treeControls->SetFocus(); |
| 1829 |
wxcEditManager::Get().PushState("cut"); |
| 1830 |
} |
| 1831 |
|
| 1832 |
void GUICraftMainPanel::OnCopy(wxCommandEvent& e) |
| 1833 |
{ |
| 1834 |
if(!m_plugin->IsMainViewActive()) { |
| 1835 |
e.Skip(); // This event is nothing to do with us |
| 1836 |
return; |
| 1837 |
} |
| 1838 |
|
| 1839 |
if(!IsTreeViewSelected()) { |
| 1840 |
e.Skip(); // The treeview isn't selected, so don't copy its selection unnecessarily |
| 1841 |
return; |
| 1842 |
} |
| 1843 |
|
| 1844 |
GUICraftItemData* itemData = GetSelItemData(); |
| 1845 |
CHECK_POINTER(itemData); |
| 1846 |
CHECK_POINTER(itemData->m_wxcWidget); |
| 1847 |
|
| 1848 |
// Delete any old instance |
| 1849 |
wxDELETE(m_clipboardItem); |
| 1850 |
std::set<wxString> unused; |
| 1851 |
m_clipboardItem = itemData->m_wxcWidget->Copy((DuplicatingOptions)(DO_renameNone | DO_copyEventsToo), unused); |
| 1852 |
m_clipboardItem->SetCopyReason(wxcWidget::CR_Copy); |
| 1853 |
|
| 1854 |
m_treeControls->SetFocus(); // Without this, focus will unexpectedly appear elsewhere, e.g. on a propertygrid style |
| 1855 |
} |
| 1856 |
|
| 1857 |
void GUICraftMainPanel::OnPaste(wxCommandEvent& e) |
| 1858 |
{ |
| 1859 |
if(!m_plugin->IsMainViewActive()) { |
| 1860 |
e.Skip(); // This event is nothing to do with us |
| 1861 |
return; |
| 1862 |
} |
| 1863 |
|
| 1864 |
if(!IsTreeViewSelected()) { |
| 1865 |
e.Skip(); // The treeview isn't selected, so don't make an unintented paste into it |
| 1866 |
return; |
| 1867 |
} |
| 1868 |
|
| 1869 |
CHECK_POINTER(m_clipboardItem); |
| 1870 |
|
| 1871 |
wxcWidget *source, *target; |
| 1872 |
wxcWidget* destinationItem = NULL; |
| 1873 |
wxcWidget* destTLW = NULL; |
| 1874 |
GUICraftItemData* sel = GetSelItemData(); |
| 1875 |
|
| 1876 |
if(!sel) { |
| 1877 |
// pasting on the root item |
| 1878 |
target = NULL; |
| 1879 |
|
| 1880 |
} else { |
| 1881 |
CHECK_POINTER(sel->m_wxcWidget); |
| 1882 |
|
| 1883 |
destinationItem = sel->m_wxcWidget; |
| 1884 |
|
| 1885 |
// Check if we can paste it here |
| 1886 |
if(!Allocator::Instance()->CanPaste(m_clipboardItem, destinationItem)) { |
| 1887 |
wxMessageBox(_("Can't paste it here")); |
| 1888 |
return; |
| 1889 |
} |
| 1890 |
target = destinationItem; |
| 1891 |
} |
| 1892 |
|
| 1893 |
bool differentTLW(false); |
| 1894 |
wxString newname, newinheritedname, newfilename; |
| 1895 |
int options(DO_renameAllChildren); |
| 1896 |
|
| 1897 |
DuplicateTLWDlg dlg(this); |
| 1898 |
if(m_clipboardItem->IsTopWindow()) { |
| 1899 |
while(true) { |
| 1900 |
if(dlg.ShowModal() != wxID_OK) { |
| 1901 |
return; // Presumably the user meant cancel the whole process |
| 1902 |
} |
| 1903 |
newname = dlg.GetBaseName(); |
| 1904 |
wxTreeItemId match; |
| 1905 |
DoFindName(m_treeControls->GetRootItem(), newname, match); |
| 1906 |
if(match.IsOk()) { |
| 1907 |
if(wxMessageBox(_("This name is already in use. Try again?"), _("wxCrafter"), |
| 1908 |
wxYES_NO | wxICON_QUESTION, this) == wxYES) { |
| 1909 |
continue; |
| 1910 |
} else { |
| 1911 |
return; |
| 1912 |
} |
| 1913 |
} |
| 1914 |
break; |
| 1915 |
} |
| 1916 |
newinheritedname = dlg.GetInheritedName(); |
| 1917 |
newfilename = dlg.GetFilename(); |
| 1918 |
} else if(target) { |
| 1919 |
// try to locate an item with this name inside the destination TLW |
| 1920 |
// If we got a match - force a rename |
| 1921 |
destTLW = target->GetTopLevel(); |
| 1922 |
CHECK_POINTER(destTLW); |
| 1923 |
// FindChildByName() can't tell if an idiot user is trying to paste m_foo into a different TLW that already |
| 1924 |
// contains an m_foo. |
| 1925 |
// So compare not only the names, but also the addresses |
| 1926 |
const wxcWidget* sameNameChild = destTLW->FindChildByName(m_clipboardItem->GetName()); |
| 1927 |
differentTLW = (sameNameChild == NULL) || (sameNameChild != m_clipboardItem); |
| 1928 |
} |
| 1929 |
|
| 1930 |
if(m_clipboardItem->IsTopWindow() || differentTLW) { |
| 1931 |
if(wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_KEEPS_ALL_NAMES)) { |
| 1932 |
options = DO_renameNone; |
| 1933 |
} else if(wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_KEEPS_USERSET_NAMES)) { |
| 1934 |
options = DO_renameAllChildrenExceptUsernamed; |
| 1935 |
} |
| 1936 |
options |= (wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_EVENTHANDLERS_TOO) ? DO_copyEventsToo : 0); |
| 1937 |
} |
| 1938 |
|
| 1939 |
std::set<wxString> existingNames; |
| 1940 |
if(destTLW) { |
| 1941 |
destTLW->StoreNames(existingNames); |
| 1942 |
} |
| 1943 |
// Don't place the actual item, but rather a copy of it |
| 1944 |
source = m_clipboardItem->Copy((DuplicatingOptions)options, existingNames, newname, newinheritedname, newfilename); |
| 1945 |
|
| 1946 |
DoPasteOrDuplicate(source, target, false); |
| 1947 |
} |
| 1948 |
|
| 1949 |
void GUICraftMainPanel::OnDuplicate(wxCommandEvent& e) |
| 1950 |
{ |
| 1951 |
wxcWidget *source, *target; |
| 1952 |
wxcWidget* destinationItem = NULL; |
| 1953 |
GUICraftItemData* sel = GetSelItemData(); |
| 1954 |
|
| 1955 |
if(!sel) { |
| 1956 |
// pasting on the root item |
| 1957 |
target = NULL; |
| 1958 |
|
| 1959 |
} else { |
| 1960 |
CHECK_POINTER(sel->m_wxcWidget); |
| 1961 |
|
| 1962 |
destinationItem = sel->m_wxcWidget; |
| 1963 |
|
| 1964 |
// Check if we can paste it here |
| 1965 |
if(!Allocator::Instance()->CanPaste(destinationItem, destinationItem)) { |
| 1966 |
wxMessageBox(_("Can't paste it here")); |
| 1967 |
return; |
| 1968 |
} |
| 1969 |
target = destinationItem; |
| 1970 |
} |
| 1971 |
|
| 1972 |
wxString newname, newinheritedname, newfilename; |
| 1973 |
int options(DO_renameAllChildren); |
| 1974 |
|
| 1975 |
// We're duplicating, not pasting, so only TLWs can possibly retain old names for child-controls |
| 1976 |
if(destinationItem->IsTopWindow()) { |
| 1977 |
|
| 1978 |
DuplicateTLWDlg dlg(this); |
| 1979 |
while(true) { |
| 1980 |
if(dlg.ShowModal() != wxID_OK) { |
| 1981 |
return; // Presumably the user meant cancel the whole process |
| 1982 |
} |
| 1983 |
newname = dlg.GetBaseName(); |
| 1984 |
wxTreeItemId match; |
| 1985 |
DoFindName(m_treeControls->GetRootItem(), newname, match); |
| 1986 |
if(match.IsOk()) { |
| 1987 |
if(wxMessageBox(_("This name is already in use. Try again?"), _("wxCrafter"), |
| 1988 |
wxYES_NO | wxICON_QUESTION, this) == wxYES) { |
| 1989 |
continue; |
| 1990 |
} else { |
| 1991 |
return; |
| 1992 |
} |
| 1993 |
} |
| 1994 |
break; |
| 1995 |
} |
| 1996 |
newinheritedname = dlg.GetInheritedName(); |
| 1997 |
newfilename = dlg.GetFilename(); |
| 1998 |
|
| 1999 |
if(wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_KEEPS_ALL_NAMES)) { |
| 2000 |
options = DO_renameNone; |
| 2001 |
} else if(wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_KEEPS_USERSET_NAMES)) { |
| 2002 |
options = DO_renameAllChildrenExceptUsernamed; |
| 2003 |
} |
| 2004 |
} |
| 2005 |
|
| 2006 |
// There's nothing to stop us honouring the user's event-copying preference, even if it's _not_ a TLW |
| 2007 |
options |= (wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_EVENTHANDLERS_TOO) ? DO_copyEventsToo : 0); |
| 2008 |
|
| 2009 |
std::set<wxString> unused; |
| 2010 |
source = destinationItem->Copy((DuplicatingOptions)options, unused, newname, newinheritedname, newfilename); |
| 2011 |
|
| 2012 |
DoPasteOrDuplicate(source, target, true); |
| 2013 |
} |
| 2014 |
|
| 2015 |
void GUICraftMainPanel::DoPasteOrDuplicate(wxcWidget* source, wxcWidget* target, bool duplicating) |
| 2016 |
{ |
| 2017 |
wxWindowUpdateLocker locker(m_treeControls); |
| 2018 |
|
| 2019 |
if((!target && source->IsTopWindow()) || // pasting on the root item a top level window |
| 2020 |
(source->IsTopWindow() && target->IsTopWindow())) { |
| 2021 |
// top level window copy/paste |
| 2022 |
DoAppendItem(wxTreeItemId(), m_treeControls->GetRootItem(), source); |
| 2023 |
|
| 2024 |
} else { |
| 2025 |
|
| 2026 |
int insertType = Allocator::Instance()->GetInsertionType(source->GetType(), target->GetType(), true); |
| 2027 |
if(duplicating && (insertType == Allocator::INSERT_CHILD) && |
| 2028 |
(wxcWidget::GetWidgetType(target->GetType()) == TYPE_SIZER) && target->IsSizerItem()) { |
| 2029 |
// If we're duplicating a (child) sizer, don't insert the dup into the original; make it a sibling |
| 2030 |
insertType = Allocator::INSERT_SIBLING; |
| 2031 |
} |
| 2032 |
|
| 2033 |
if(insertType == Allocator::INSERT_SIBLING) { |
| 2034 |
DoInsertBefore(wxTreeItemId(), m_treeControls->GetSelection(), source); |
| 2035 |
|
| 2036 |
} else if(insertType == Allocator::INSERT_CHILD) { |
| 2037 |
|
| 2038 |
// trying to paste a wxAUI manager on a control with wxAUI manager? |
| 2039 |
if(target->IsAuiManaged() && source->GetType() == ID_WXAUIMANAGER) { |
| 2040 |
wxMessageBox(_("Only one wxAui Manager is allowed"), "wxCrafter", wxOK | wxICON_WARNING | wxCENTER); |
| 2041 |
wxDELETE(source); |
| 2042 |
return; |
| 2043 |
} |
| 2044 |
|
| 2045 |
DoAppendItem(wxTreeItemId(), m_treeControls->GetSelection(), source); |
| 2046 |
|
| 2047 |
} else if(insertType == Allocator::INSERT_MAIN_SIZER) { |
| 2048 |
if(target->HasMainSizer()) { |
| 2049 |
wxDELETE(source); |
| 2050 |
wxMessageBox(_("Can't insert this item here\nThere is already a main sizer")); |
| 2051 |
return; |
| 2052 |
|
| 2053 |
} else if(target->IsAuiManaged()) { |
| 2054 |
wxDELETE(source); |
| 2055 |
wxMessageBox(_("Can't insert this item here\nThis item is managed by wxAUI")); |
| 2056 |
return; |
| 2057 |
} |
| 2058 |
DoAppendItem(wxTreeItemId(), m_treeControls->GetSelection(), source); |
| 2059 |
} |
| 2060 |
} |
| 2061 |
NotifyPreviewChanged(); |
| 2062 |
|
| 2063 |
m_treeControls->SetFocus(); // Without this, focus will unexpectedly appear elsewhere, e.g. on a propertygrid style |
| 2064 |
|
| 2065 |
wxcEditManager::Get().PushState(duplicating ? "duplication" : "paste"); |
| 2066 |
} |
| 2067 |
|
| 2068 |
void GUICraftMainPanel::OnBeginDrag(wxTreeEvent& event) |
| 2069 |
{ |
| 2070 |
// event.Skip(); |
| 2071 |
m_draggedItem = m_treeControls->GetSelection(); |
| 2072 |
if(m_draggedItem.IsOk()) { |
| 2073 |
event.Allow(); |
| 2074 |
} |
| 2075 |
} |
| 2076 |
|
| 2077 |
void GUICraftMainPanel::OnEndDrag(wxTreeEvent& event) |
| 2078 |
{ |
| 2079 |
wxTreeItemId itemDst = event.GetItem(); |
| 2080 |
if(!itemDst.IsOk() || !m_draggedItem.IsOk()) { |
| 2081 |
return; |
| 2082 |
} |
| 2083 |
|
| 2084 |
wxcWidget *source, *target; |
| 2085 |
GUICraftItemData* guiTargetItem = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(itemDst)); |
| 2086 |
CHECK_POINTER(guiTargetItem); |
| 2087 |
CHECK_POINTER(guiTargetItem->m_wxcWidget); |
| 2088 |
target = guiTargetItem->m_wxcWidget; |
| 2089 |
|
| 2090 |
GUICraftItemData* guiSourceItem = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(m_draggedItem)); |
| 2091 |
CHECK_POINTER(guiSourceItem); |
| 2092 |
CHECK_POINTER(guiSourceItem->m_wxcWidget); |
| 2093 |
source = guiSourceItem->m_wxcWidget; |
| 2094 |
|
| 2095 |
// source and targets are the same? |
| 2096 |
if(source == target) { |
| 2097 |
return; |
| 2098 |
} |
| 2099 |
|
| 2100 |
// target is child of source? |
| 2101 |
if(target->IsDirectOrIndirectChildOf(source)) { |
| 2102 |
return; |
| 2103 |
} |
| 2104 |
|
| 2105 |
// Can we paste the item to the new location? |
| 2106 |
if(!Allocator::Instance()->CanPaste(source, target)) { |
| 2107 |
return; |
| 2108 |
} |
| 2109 |
|
| 2110 |
// We need to check for potential name-clashes. This is most likely with Paste, but may happen with Move between |
| 2111 |
// TLWs |
| 2112 |
wxcWidget* destTLW = target->GetTopLevel(); |
| 2113 |
CHECK_POINTER(destTLW); |
| 2114 |
std::set<wxString> existingNames; |
| 2115 |
destTLW->StoreNames(existingNames); |
| 2116 |
|
| 2117 |
bool Pasting = wxGetKeyState(WXK_CONTROL); |
| 2118 |
|
| 2119 |
int options(DO_renameAllChildren); |
| 2120 |
|
| 2121 |
// FindChildByName() can't tell if an idiot user is trying to paste m_foo into a different TLW that already contains |
| 2122 |
// an m_foo. |
| 2123 |
// So compare not only the names, but also the addresses |
| 2124 |
const wxcWidget* sameNameChild = destTLW->FindChildByName(source->GetName()); |
| 2125 |
bool differentTLW = (sameNameChild == NULL) || (sameNameChild != source); |
| 2126 |
|
| 2127 |
if(Pasting) { |
| 2128 |
if(source->IsTopWindow() || differentTLW) { |
| 2129 |
if(wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_KEEPS_ALL_NAMES)) { |
| 2130 |
options = DO_renameNone; |
| 2131 |
} else if(wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_KEEPS_USERSET_NAMES)) { |
| 2132 |
options = DO_renameAllChildrenExceptUsernamed; |
| 2133 |
} |
| 2134 |
} |
| 2135 |
} else { |
| 2136 |
options = DO_renameNone; |
| 2137 |
} |
| 2138 |
|
| 2139 |
if(Pasting) { |
| 2140 |
options |= (wxcSettings::Get().HasFlag(wxcSettings::DUPLICATE_EVENTHANDLERS_TOO) ? DO_copyEventsToo : 0); |
| 2141 |
} else { |
| 2142 |
// If we're moving, always retain any eventhandlers |
| 2143 |
options |= DO_copyEventsToo; |
| 2144 |
} |
| 2145 |
|
| 2146 |
wxTreeItemId itemSrc; |
| 2147 |
if(Pasting) { |
| 2148 |
// If this is a Paste rather than a Move, we need to copy the source |
| 2149 |
source = source->Copy((DuplicatingOptions)options, existingNames); |
| 2150 |
|
| 2151 |
} else { |
| 2152 |
if(!source->IsTopWindow() && differentTLW) { |
| 2153 |
// Even if it's a Move, we still may need rename to avoid a name-clash |
| 2154 |
// So, though it's a bit clunky, Copy() the source, then steal any new name from the copy |
| 2155 |
wxcWidget* clone = source->Copy((DuplicatingOptions)options, existingNames); |
| 2156 |
if(source->GetName() != clone->GetName()) { |
| 2157 |
source->SetName(clone->GetName()); |
| 2158 |
} |
| 2159 |
|
| 2160 |
wxDELETE(clone); |
| 2161 |
} |
| 2162 |
|
| 2163 |
itemSrc = m_draggedItem; |
| 2164 |
} |
| 2165 |
|
| 2166 |
wxWindowUpdateLocker locker(m_treeControls); |
| 2167 |
|
| 2168 |
int insertType = Allocator::Instance()->GetInsertionType(source->GetType(), target->GetType(), true); |
| 2169 |
if(insertType == Allocator::INSERT_SIBLING) { |
| 2170 |
// We want to insert where the marker is, so pass 'false' for insert-after |
| 2171 |
// (That means we can't insert above the top item: there's no place for the marker to go except onto the |
| 2172 |
// containing sizer, |
| 2173 |
// so the item gets appended to the that instead. However the top item can always be moved down...) |
| 2174 |
DoInsertBefore(itemSrc, itemDst, source, false); |
| 2175 |
|
| 2176 |
} else if(insertType == Allocator::INSERT_CHILD || insertType == Allocator::INSERT_MAIN_SIZER) { |
| 2177 |
DoAppendItem(itemSrc, itemDst, source); |
| 2178 |
} |
| 2179 |
|
| 2180 |
NotifyPreviewChanged(); |
| 2181 |
wxcEditManager::Get().PushState(Pasting ? "paste" : "move"); |
| 2182 |
} |
| 2183 |
|
| 2184 |
void GUICraftMainPanel::DoAppendItem(const wxTreeItemId& sourceItem, const wxTreeItemId& targetItem, |
| 2185 |
wxcWidget* sourceItemData) |
| 2186 |
{ |
| 2187 |
wxcWidget *source, *target = NULL; |
| 2188 |
GUICraftItemData* guiTargetItem = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(targetItem)); |
| 2189 |
|
| 2190 |
if(guiTargetItem && guiTargetItem->m_wxcWidget) { |
| 2191 |
target = guiTargetItem->m_wxcWidget; |
| 2192 |
} |
| 2193 |
|
| 2194 |
if(sourceItem.IsOk()) { |
| 2195 |
GUICraftItemData* guiSourceItem = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(sourceItem)); |
| 2196 |
CHECK_POINTER(guiSourceItem); |
| 2197 |
CHECK_POINTER(guiSourceItem->m_wxcWidget); |
| 2198 |
source = guiSourceItem->m_wxcWidget; |
| 2199 |
source->RemoveFromParent(); |
| 2200 |
|
| 2201 |
// Disconnect the dragged item from its parent |
| 2202 |
DoUnsetItemData(sourceItem); |
| 2203 |
|
| 2204 |
// Delete the UI of the dragged item |
| 2205 |
if(m_treeControls->ItemHasChildren(sourceItem)) { |
| 2206 |
m_treeControls->DeleteChildren(sourceItem); |
| 2207 |
} |
| 2208 |
m_treeControls->Delete(sourceItem); |
| 2209 |
|
| 2210 |
} else { |
| 2211 |
source = sourceItemData; |
| 2212 |
CHECK_POINTER(source); |
| 2213 |
} |
| 2214 |
|
| 2215 |
// Paste it as a child of the target item |
| 2216 |
if(target) { |
| 2217 |
// the only case where "target" is NULL is when a top level item is being appended |
| 2218 |
// in this case it has no one to be added to as a child |
| 2219 |
target->AddChild(source); |
| 2220 |
} |
| 2221 |
|
| 2222 |
wxTreeItemId selection; |
| 2223 |
DoBuildTree(selection, source, targetItem); |
| 2224 |
if(selection.IsOk()) { |
| 2225 |
m_treeControls->SelectItem(selection); |
| 2226 |
m_treeControls->EnsureVisible(selection); |
| 2227 |
} |
| 2228 |
} |
| 2229 |
|
| 2230 |
void GUICraftMainPanel::DoInsertBefore(const wxTreeItemId& sourceItem, const wxTreeItemId& targetItem, |
| 2231 |
wxcWidget* sourceItemData, bool insertBefore) |
| 2232 |
{ |
| 2233 |
wxcWidget *source, *target; |
| 2234 |
GUICraftItemData* guiTargetItem = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(targetItem)); |
| 2235 |
CHECK_POINTER(guiTargetItem); |
| 2236 |
CHECK_POINTER(guiTargetItem->m_wxcWidget); |
| 2237 |
target = guiTargetItem->m_wxcWidget; |
| 2238 |
|
| 2239 |
CHECK_POINTER(target->GetParent()); |
| 2240 |
|
| 2241 |
if(sourceItem.IsOk()) { |
| 2242 |
GUICraftItemData* guiSourceItem = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(sourceItem)); |
| 2243 |
CHECK_POINTER(guiSourceItem); |
| 2244 |
CHECK_POINTER(guiSourceItem->m_wxcWidget); |
| 2245 |
source = guiSourceItem->m_wxcWidget; |
| 2246 |
|
| 2247 |
// Check if we can perform the insert action |
| 2248 |
if(!DoCheckInsert(source, target)) { |
| 2249 |
return; |
| 2250 |
} |
| 2251 |
|
| 2252 |
// Disconnect the dragged item from its parent |
| 2253 |
source->RemoveFromParent(); |
| 2254 |
DoUnsetItemData(sourceItem); |
| 2255 |
|
| 2256 |
// Delete the UI of the dragged item |
| 2257 |
if(m_treeControls->ItemHasChildren(sourceItem)) { |
| 2258 |
m_treeControls->DeleteChildren(sourceItem); |
| 2259 |
} |
| 2260 |
m_treeControls->Delete(sourceItem); |
| 2261 |
|
| 2262 |
} else { |
| 2263 |
source = sourceItemData; |
| 2264 |
CHECK_POINTER(source); |
| 2265 |
|
| 2266 |
// Check if we can perform the insert action |
| 2267 |
if(!DoCheckInsert(source, target)) { |
| 2268 |
return; |
| 2269 |
} |
| 2270 |
} |
| 2271 |
|
| 2272 |
// Paste it as a child of the target item |
| 2273 |
if(insertBefore) { |
| 2274 |
target->GetParent()->InsertBefore(source, target); |
| 2275 |
|
| 2276 |
} else { |
| 2277 |
target->GetParent()->InsertAfter(source, target); |
| 2278 |
} |
| 2279 |
|
| 2280 |
wxTreeItemId selection; |
| 2281 |
DoBuildTree(selection, source, m_treeControls->GetItemParent(targetItem), targetItem, insertBefore); |
| 2282 |
|
| 2283 |
if(selection.IsOk()) { |
| 2284 |
m_treeControls->SelectItem(selection); |
| 2285 |
m_treeControls->EnsureVisible(selection); |
| 2286 |
} |
| 2287 |
} |
| 2288 |
|
| 2289 |
void GUICraftMainPanel::OnCancelPreview(wxCommandEvent& e) |
| 2290 |
{ |
| 2291 |
wxCommandEvent closePreviewEvt(wxEVT_CLOSE_PREVIEW); |
| 2292 |
EventNotifier::Get()->ProcessEvent(closePreviewEvt); |
| 2293 |
} |
| 2294 |
|
| 2295 |
void GUICraftMainPanel::OnCancelPreviewUI(wxUpdateUIEvent& e) |
| 2296 |
{ |
| 2297 |
e.Enable(wxcProjectMetadata::Get().IsLoaded() && m_previewAlive); |
| 2298 |
} |
| 2299 |
|
| 2300 |
void GUICraftMainPanel::OnPreviewClosed(wxCommandEvent& e) |
| 2301 |
{ |
| 2302 |
e.Skip(); |
| 2303 |
m_previewAlive = false; |
| 2304 |
} |
| 2305 |
|
| 2306 |
void GUICraftMainPanel::OnShowPreviewUI(wxUpdateUIEvent& e) |
| 2307 |
{ |
| 2308 |
wxcWidget* tlw = GetActiveTopLevelWin(); |
| 2309 |
e.Enable(wxcProjectMetadata::Get().IsLoaded() && !m_previewAlive && tlw && tlw->GetType() != ID_WXIMAGELIST); |
| 2310 |
} |
| 2311 |
|
| 2312 |
wxcWidget* GUICraftMainPanel::GetActiveWizardPage() const |
| 2313 |
{ |
| 2314 |
wxTreeItemId topLevel = DoGetTopLevelTreeItem(); |
| 2315 |
if(topLevel.IsOk() == false) { |
| 2316 |
return NULL; |
| 2317 |
} |
| 2318 |
|
| 2319 |
wxTreeItemId sel = m_treeControls->GetSelection(); |
| 2320 |
if(sel.IsOk() == false) { |
| 2321 |
return NULL; |
| 2322 |
} |
| 2323 |
|
| 2324 |
// Check that this top level is indeed a wxWizard... |
| 2325 |
GUICraftItemData* topLevelItemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(topLevel)); |
| 2326 |
CHECK_POINTER_RET_NULL(topLevelItemData); |
| 2327 |
CHECK_POINTER_RET_NULL(topLevelItemData->m_wxcWidget); |
| 2328 |
if(topLevelItemData->m_wxcWidget->GetType() != ID_WXWIZARD) { |
| 2329 |
return NULL; |
| 2330 |
} |
| 2331 |
|
| 2332 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(sel)); |
| 2333 |
CHECK_POINTER_RET_NULL(itemData); |
| 2334 |
CHECK_POINTER_RET_NULL(itemData->m_wxcWidget); |
| 2335 |
|
| 2336 |
wxcWidget* p = itemData->m_wxcWidget; |
| 2337 |
while(p && p->GetType() != ID_WXWIZARDPAGE) { |
| 2338 |
p = p->GetParent(); |
| 2339 |
} |
| 2340 |
|
| 2341 |
if(p && p->GetType() == ID_WXWIZARDPAGE) { |
| 2342 |
return p; |
| 2343 |
|
| 2344 |
} else if(!p && m_treeControls->ItemHasChildren(topLevel)) { |
| 2345 |
wxTreeItemIdValue cookie; |
| 2346 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>( |
| 2347 |
m_treeControls->GetItemData(m_treeControls->GetFirstChild(topLevel, cookie))); |
| 2348 |
CHECK_POINTER_RET_NULL(itemData); |
| 2349 |
return itemData->m_wxcWidget; |
| 2350 |
} |
| 2351 |
return NULL; |
| 2352 |
} |
| 2353 |
|
| 2354 |
void GUICraftMainPanel::OnRefreshView(wxCommandEvent& e) |
| 2355 |
{ |
| 2356 |
e.Skip(); |
| 2357 |
DoRefresh(wxEVT_UPDATE_PREVIEW); |
| 2358 |
} |
| 2359 |
|
| 2360 |
void GUICraftMainPanel::OnCloseProject(wxCommandEvent& e) |
| 2361 |
{ |
| 2362 |
e.Skip(); |
| 2363 |
if(wxcEditManager::Get().IsDirty()) { |
| 2364 |
if(::wxMessageBox(_("Current file has been modified\nClose anyway?"), "wxCrafter", |
| 2365 |
wxYES_NO | wxCANCEL | wxCENTER, wxCrafter::TopFrame()) != wxYES) { |
| 2366 |
return; |
| 2367 |
} |
| 2368 |
} |
| 2369 |
Clear(); |
| 2370 |
|
| 2371 |
wxCommandEvent refreshView(wxEVT_UPDATE_PREVIEW); |
| 2372 |
EventNotifier::Get()->AddPendingEvent(refreshView); |
| 2373 |
} |
| 2374 |
|
| 2375 |
void GUICraftMainPanel::OnGenerateCodeUI(wxUpdateUIEvent& e) { e.Enable(wxcProjectMetadata::Get().IsLoaded()); } |
| 2376 |
|
| 2377 |
void GUICraftMainPanel::OnSaveProjectUI(wxUpdateUIEvent& e) |
| 2378 |
{ |
| 2379 |
e.Enable(wxcProjectMetadata::Get().IsLoaded() && wxcEditManager::Get().IsDirty()); |
| 2380 |
} |
| 2381 |
|
| 2382 |
void GUICraftMainPanel::OnBarItemSelected(wxCommandEvent& e) |
| 2383 |
{ |
| 2384 |
wxTreeItemId topLevel = DoGetTopLevelTreeItem(); |
| 2385 |
|
| 2386 |
wxcWidget* tlid = DoGetItemData(topLevel); |
| 2387 |
CHECK_POINTER(tlid); |
| 2388 |
|
| 2389 |
wxString parentname = e.GetString().BeforeFirst(wxT(':')); |
| 2390 |
|
| 2391 |
const wxcWidget* parnt = NULL; |
| 2392 |
if(parentname == "TOOL_BAR_ID") { |
| 2393 |
// direct toolbar child of the main frame |
| 2394 |
parnt = tlid->FindFirstDirectChildOfType(ID_WXTOOLBAR); |
| 2395 |
|
| 2396 |
} else if(parentname == "MENU_BAR_ID") { |
| 2397 |
// direct toolbar child of the main frame |
| 2398 |
parnt = tlid->FindFirstDirectChildOfType(ID_WXMENUBAR); |
| 2399 |
|
| 2400 |
} else { |
| 2401 |
parnt = tlid->FindChildByName(parentname); |
| 2402 |
} |
| 2403 |
CHECK_POINTER(parnt); |
| 2404 |
|
| 2405 |
wxString toolname = e.GetString().AfterFirst(wxT(':')); |
| 2406 |
const wxcWidget::List_t& tools = parnt->GetChildren(); |
| 2407 |
wxcWidget::List_t::const_iterator menuIter = tools.begin(); |
| 2408 |
for(; menuIter != tools.end(); ++menuIter) { |
| 2409 |
if((*menuIter)->PropertyString(PROP_LABEL) == toolname) { |
| 2410 |
|
| 2411 |
// Select this item |
| 2412 |
wxCommandEvent evt(wxEVT_PREVIEW_CTRL_SELECTED); |
| 2413 |
evt.SetString((*menuIter)->GetName()); |
| 2414 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 2415 |
|
| 2416 |
break; |
| 2417 |
} |
| 2418 |
} |
| 2419 |
} |
| 2420 |
|
| 2421 |
wxcWidget* GUICraftMainPanel::DoGetItemData(const wxTreeItemId& item) const |
| 2422 |
{ |
| 2423 |
if(!item.IsOk()) { |
| 2424 |
return NULL; |
| 2425 |
} |
| 2426 |
|
| 2427 |
GUICraftItemData* id = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 2428 |
CHECK_POINTER_RET_NULL(id); |
| 2429 |
return id->m_wxcWidget; |
| 2430 |
} |
| 2431 |
|
| 2432 |
/////////////////////////////////////////////////////////// |
| 2433 |
// Edit |
| 2434 |
/////////////////////////////////////////////////////////// |
| 2435 |
|
| 2436 |
void GUICraftMainPanel::OnRedo(wxCommandEvent& e) |
| 2437 |
{ |
| 2438 |
if(!m_plugin->IsTabMode() && !(m_plugin->GetMainFrame() && m_plugin->GetMainFrame()->IsShown())) { |
| 2439 |
e.Skip(); |
| 2440 |
return; // Otherwise, in non-tabbed mode, there'll be contamination between us and clMainFrame |
| 2441 |
} |
| 2442 |
|
| 2443 |
if(IsPropertyGridPropertySelected()) { |
| 2444 |
e.Skip(); |
| 2445 |
return; // Otherwise Ctrl-Y in the EventsTableListView may do unwanted things to the tree |
| 2446 |
} |
| 2447 |
|
| 2448 |
if(wxcEditManager::Get().CanRedo()) { |
| 2449 |
|
| 2450 |
State::Ptr_t state = wxcEditManager::Get().Redo(); |
| 2451 |
if(state) { |
| 2452 |
LoadProject(wxFileName(), state->project_json, true); |
| 2453 |
DoSelectItemByName(state->selection, state->parentTLW); |
| 2454 |
} |
| 2455 |
|
| 2456 |
} else { |
| 2457 |
e.Skip(); |
| 2458 |
} |
| 2459 |
} |
| 2460 |
|
| 2461 |
void GUICraftMainPanel::OnRedoUI(wxUpdateUIEvent& e) { e.Enable(wxcEditManager::Get().CanRedo()); } |
| 2462 |
|
| 2463 |
void GUICraftMainPanel::OnUndo(wxCommandEvent& e) |
| 2464 |
{ |
| 2465 |
if(!m_plugin->IsTabMode() && !(m_plugin->GetMainFrame() && m_plugin->GetMainFrame()->IsShown())) { |
| 2466 |
e.Skip(); |
| 2467 |
return; // Otherwise, in non-tabbed mode, there'll be contamination between us and clMainFrame |
| 2468 |
} |
| 2469 |
|
| 2470 |
if(IsPropertyGridPropertySelected()) { |
| 2471 |
e.Skip(); |
| 2472 |
return; // Otherwise Ctrl-Z in the EventsTableListView may do unwanted things to the tree |
| 2473 |
} |
| 2474 |
|
| 2475 |
if(wxcEditManager::Get().CanUndo()) { |
| 2476 |
|
| 2477 |
State::Ptr_t state = wxcEditManager::Get().Undo(); |
| 2478 |
if(state) { |
| 2479 |
LoadProject(wxFileName(), state->project_json, true); |
| 2480 |
DoSelectItemByName(state->selection, state->parentTLW); |
| 2481 |
} |
| 2482 |
|
| 2483 |
} else { |
| 2484 |
e.Skip(); |
| 2485 |
} |
| 2486 |
} |
| 2487 |
|
| 2488 |
void GUICraftMainPanel::OnUndoUI(wxUpdateUIEvent& e) { e.Enable(wxcEditManager::Get().CanUndo()); } |
| 2489 |
|
| 2490 |
void GUICraftMainPanel::OnLabelCurrentState(wxCommandEvent& event) |
| 2491 |
{ |
| 2492 |
if(!m_plugin->IsTabMode() && !(m_plugin->GetMainFrame() && m_plugin->GetMainFrame()->IsShown())) { |
| 2493 |
event.Skip(); |
| 2494 |
return; // Otherwise, in non-tabbed mode, there'll be contamination between us and clMainFrame |
| 2495 |
} |
| 2496 |
|
| 2497 |
// wxString label = wxGetTextFromUser("What would you like to call the current state?", "Label current state", "", |
| 2498 |
// this); |
| 2499 |
// if (!label.empty()) { |
| 2500 |
// wxcEditManager::Get().SetUserLabel(label); |
| 2501 |
//} |
| 2502 |
} |
| 2503 |
|
| 2504 |
void GUICraftMainPanel::OnEditMenuOpened(wxMenuEvent& event) |
| 2505 |
{ |
| 2506 |
if(m_plugin->IsTabMode() && !m_plugin->IsMainViewActive()) { |
| 2507 |
event.Skip(); // This event is nothing to do with us |
| 2508 |
return; |
| 2509 |
} |
| 2510 |
// wxcEditManager::Get().PrepareLabelledStatesMenu(event.GetMenu()); |
| 2511 |
} |
| 2512 |
|
| 2513 |
void GUICraftMainPanel::OnLoadCurrentState( |
| 2514 |
wxCommandEvent& WXUNUSED(event)) // Called after a multiple unredo has changed the GetCurrentState() value |
| 2515 |
{ |
| 2516 |
State::Ptr_t state = wxcEditManager::Get().GetCurrentState(); |
| 2517 |
if(!state) { |
| 2518 |
return; |
| 2519 |
} |
| 2520 |
LoadProject(wxFileName(), state->project_json, true); |
| 2521 |
DoSelectItemByName(state->selection, state->parentTLW); |
| 2522 |
} |
| 2523 |
|
| 2524 |
State::Ptr_t GUICraftMainPanel::CurrentState() |
| 2525 |
{ |
| 2526 |
JSONRoot root(cJSON_Object); |
| 2527 |
|
| 2528 |
// If we dont have bitmap function assigned to this project, create new one |
| 2529 |
if(wxcProjectMetadata::Get().GetBitmapFunction().IsEmpty()) { |
| 2530 |
wxcProjectMetadata::Get().GenerateBitmapFunctionName(); |
| 2531 |
} |
| 2532 |
|
| 2533 |
// Update the counter info; this will otherwise be wrong after e.g. a duplication |
| 2534 |
wxcProjectMetadata::Get().SetObjCounter(wxcWidget::GetObjCounter()); |
| 2535 |
|
| 2536 |
JSONElement metadata = wxcProjectMetadata::Get().ToJSON(); |
| 2537 |
wxcProjectMetadata::Get().AppendCustomControlsJSON(GetCustomControlsUsed(), metadata); |
| 2538 |
root.toElement().append(metadata); |
| 2539 |
root.toElement().append(ToJSON(wxTreeItemId())); |
| 2540 |
|
| 2541 |
State::Ptr_t state(new State); |
| 2542 |
state->project_json = root.toElement().format(); |
| 2543 |
|
| 2544 |
wxTreeItemId item = m_treeControls->GetSelection(); |
| 2545 |
if(item.IsOk()) { |
| 2546 |
state->selection = m_treeControls->GetItemText(item); |
| 2547 |
GUICraftItemData* control = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 2548 |
if(control && control->m_wxcWidget) { |
| 2549 |
state->parentTLW = control->m_wxcWidget->GetTopLevel()->GetName(); |
| 2550 |
} |
| 2551 |
} |
| 2552 |
return state; |
| 2553 |
} |
| 2554 |
|
| 2555 |
void GUICraftMainPanel::DoSelectItemByName(const wxString& name, const wxString& parentTLW) |
| 2556 |
{ |
| 2557 |
if(name.IsEmpty()) { |
| 2558 |
return; |
| 2559 |
} |
| 2560 |
|
| 2561 |
wxTreeItemId startpoint = m_treeControls->GetRootItem(); |
| 2562 |
if(!parentTLW.IsEmpty()) { |
| 2563 |
wxTreeItemId sp; |
| 2564 |
DoFindName(startpoint, parentTLW, sp); |
| 2565 |
if(sp.IsOk()) { |
| 2566 |
startpoint = sp; |
| 2567 |
} |
| 2568 |
} |
| 2569 |
|
| 2570 |
wxTreeItemId where; |
| 2571 |
DoFindName(startpoint, name, where); |
| 2572 |
if(where.IsOk()) { |
| 2573 |
m_treeControls->SelectItem(where); |
| 2574 |
m_treeControls->EnsureVisible(where); |
| 2575 |
|
| 2576 |
wxCommandEvent eventTreeItemSeleted(wxEVT_TREE_ITEM_SELECTED); |
| 2577 |
eventTreeItemSeleted.SetString(name); |
| 2578 |
EventNotifier::Get()->AddPendingEvent(eventTreeItemSeleted); |
| 2579 |
} |
| 2580 |
} |
| 2581 |
|
| 2582 |
bool GUICraftMainPanel::IsTreeViewSelected() const { return wxWindow::FindFocus() == m_treeControls; } |
| 2583 |
|
| 2584 |
bool GUICraftMainPanel::IsPropertyGridPropertySelected() const |
| 2585 |
{ |
| 2586 |
// This function tests if the parent of an item is a propertygrid. The idea is to avoid |
| 2587 |
// e.g. Ctrl-Z affecting the tree when the user was actually trying to edit a property |
| 2588 |
wxWindow* win = wxWindow::FindFocus(); |
| 2589 |
if(!win) { |
| 2590 |
return false; |
| 2591 |
} |
| 2592 |
|
| 2593 |
return dynamic_cast<wxPropertyGrid*>(win->GetParent()) != NULL; |
| 2594 |
} |
| 2595 |
|
| 2596 |
wxcWidget* GUICraftMainPanel::GetActiveTopLevelWin() const |
| 2597 |
{ |
| 2598 |
wxTreeItemId topLevel = DoGetTopLevelTreeItem(); |
| 2599 |
if(topLevel.IsOk() == false) { |
| 2600 |
return NULL; |
| 2601 |
} |
| 2602 |
|
| 2603 |
GUICraftItemData* topLevelItemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(topLevel)); |
| 2604 |
CHECK_POINTER_RET_NULL(topLevelItemData); |
| 2605 |
return topLevelItemData->m_wxcWidget; |
| 2606 |
} |
| 2607 |
|
| 2608 |
void GUICraftMainPanel::OnGenerateCodeMenu(wxAuiToolBarEvent& e) |
| 2609 |
{ |
| 2610 |
if(e.IsDropDownClicked()) { |
| 2611 |
wxMenu menu(_("Code Generation")); |
| 2612 |
wxMenuItem* item = menu.AppendCheckItem(XRCID("GenerateCPP"), _("Generate C++ code")); |
| 2613 |
item->Check(wxcProjectMetadata::Get().GetGenerateCPPCode()); |
| 2614 |
item = menu.AppendCheckItem(XRCID("GenerateXRC"), _("Generate XRC")); |
| 2615 |
item->Check(wxcProjectMetadata::Get().GetGenerateXRC()); |
| 2616 |
|
| 2617 |
wxPoint pt = e.GetItemRect().GetBottomLeft(); |
| 2618 |
pt.y++; |
| 2619 |
m_toolbar->PopupMenu(&menu, pt); |
| 2620 |
|
| 2621 |
} else { |
| 2622 |
wxCommandEvent dummy; |
| 2623 |
OnGenerateCode(dummy); |
| 2624 |
} |
| 2625 |
} |
| 2626 |
|
| 2627 |
void GUICraftMainPanel::OnCodeGenerationTypeChanged(wxCommandEvent& event) |
| 2628 |
{ |
| 2629 |
if(event.GetId() == XRCID("GenerateCPP")) { |
| 2630 |
wxcProjectMetadata::Get().SetGenerateCPPCode(event.IsChecked()); |
| 2631 |
} |
| 2632 |
if(event.GetId() == XRCID("GenerateXRC")) { |
| 2633 |
wxcProjectMetadata::Get().SetGenerateXRC(event.IsChecked()); |
| 2634 |
} |
| 2635 |
} |
| 2636 |
|
| 2637 |
void GUICraftMainPanel::OnNewCustomControlMenu(wxCommandEvent& e) |
| 2638 |
{ |
| 2639 |
wxMenu menu(_("Choose a control")); |
| 2640 |
const CustomControlTemplateMap_t& controls = wxcSettings::Get().GetTemplateClasses(); |
| 2641 |
CustomControlTemplateMap_t::const_iterator iter = controls.begin(); |
| 2642 |
|
| 2643 |
if(controls.empty() == false) { |
| 2644 |
for(; iter != controls.end(); ++iter) { |
| 2645 |
menu.Append(iter->second.GetControlId(), iter->first); |
| 2646 |
menu.Connect(iter->second.GetControlId(), wxEVT_COMMAND_MENU_SELECTED, |
| 2647 |
wxCommandEventHandler(GUICraftMainPanel::OnNewCustomControl), NULL, this); |
| 2648 |
} |
| 2649 |
menu.AppendSeparator(); |
| 2650 |
} |
| 2651 |
menu.Append(XRCID("define_custom_controls"), _("Define custom control...")); |
| 2652 |
|
| 2653 |
wxButton* button = dynamic_cast<wxButton*>(e.GetEventObject()); |
| 2654 |
if(button) { |
| 2655 |
wxPoint pt = button->GetScreenPosition(); |
| 2656 |
pt.y += button->GetSize().GetHeight(); |
| 2657 |
pt = ScreenToClient(pt); |
| 2658 |
PopupMenu(&menu, pt); |
| 2659 |
} |
| 2660 |
} |
| 2661 |
|
| 2662 |
void GUICraftMainPanel::OnNewCustomControl(wxCommandEvent& e) |
| 2663 |
{ |
| 2664 |
int ctrlId = e.GetId(); |
| 2665 |
AddCustomControl(ctrlId); |
| 2666 |
} |
| 2667 |
|
| 2668 |
void GUICraftMainPanel::DoInsertControl(wxcWidget* control, wxcWidget* parent, int insertType, int imgId) |
| 2669 |
{ |
| 2670 |
if(control->GetType() == ID_WXAUIMANAGER && parent->IsAuiManaged()) { |
| 2671 |
wxDELETE(control); |
| 2672 |
wxMessageBox(_("Only one wxAui Manager is allowed"), "wxCrafter", wxOK | wxICON_WARNING | wxCENTER); |
| 2673 |
return; |
| 2674 |
} |
| 2675 |
|
| 2676 |
if(control->GetType() == ID_WXAUIMANAGER && parent->HasMainSizer()) { |
| 2677 |
wxDELETE(control); |
| 2678 |
wxMessageBox(_("wxAui Manager can not be placed onto a control with a main sizer"), "wxCrafter", |
| 2679 |
wxOK | wxICON_WARNING | wxCENTER); |
| 2680 |
return; |
| 2681 |
} |
| 2682 |
|
| 2683 |
if(parent->GetType() == ID_WXRIBBONPANEL && !parent->GetChildren().empty() && |
| 2684 |
insertType == Allocator::INSERT_CHILD) { |
| 2685 |
wxDELETE(control); |
| 2686 |
wxMessageBox(_("wxRibbonPanel can only have one direct child"), "wxCrafter", wxOK | wxICON_WARNING | wxCENTER); |
| 2687 |
return; |
| 2688 |
} |
| 2689 |
|
| 2690 |
if(insertType == Allocator::INSERT_SIBLING) { |
| 2691 |
DoInsertBefore(wxTreeItemId(), m_treeControls->GetSelection(), control, false); |
| 2692 |
|
| 2693 |
} else if(insertType == Allocator::INSERT_CHILD || insertType == Allocator::INSERT_MAIN_SIZER) { |
| 2694 |
|
| 2695 |
// We need to place a main sizer, check that we dont have one already... |
| 2696 |
if(parent->HasMainSizer() && insertType == Allocator::INSERT_MAIN_SIZER) { |
| 2697 |
wxDELETE(control); |
| 2698 |
wxMessageBox(_("Can't insert this item here\nThere is already a main sizer")); |
| 2699 |
return; |
| 2700 |
|
| 2701 |
} else if(parent->IsAuiManaged() && insertType == Allocator::INSERT_MAIN_SIZER) { |
| 2702 |
wxDELETE(control); |
| 2703 |
wxMessageBox(_("A Main Sizer can not be placed into a wxAui managed window"), "wxCrafter", |
| 2704 |
wxOK | wxICON_WARNING | wxCENTER); |
| 2705 |
return; |
| 2706 |
} |
| 2707 |
|
| 2708 |
parent->AddChild(control); |
| 2709 |
wxTreeItemId item = m_treeControls->AppendItem(m_treeControls->GetSelection(), control->GetName(), imgId, imgId, |
| 2710 |
new GUICraftItemData(control)); |
| 2711 |
m_treeControls->SelectItem(item); |
| 2712 |
} else { |
| 2713 |
wxDELETE(control); |
| 2714 |
wxMessageBox(_("Can't insert this item here")); |
| 2715 |
return; |
| 2716 |
} |
| 2717 |
|
| 2718 |
DoRefresh(wxEVT_UPDATE_PREVIEW); |
| 2719 |
wxcEditManager::Get().PushState("insertion"); |
| 2720 |
} |
| 2721 |
|
| 2722 |
size_t GUICraftMainPanel::DoFindPropertiesPage(wxWindow* win) |
| 2723 |
{ |
| 2724 |
// locate the page index |
| 2725 |
size_t pageIdx = wxString::npos; |
| 2726 |
for(size_t i = 0; i < m_notebook2->GetPageCount(); ++i) { |
| 2727 |
if(win == m_notebook2->GetPage(i)) { |
| 2728 |
pageIdx = i; |
| 2729 |
break; |
| 2730 |
} |
| 2731 |
} |
| 2732 |
return pageIdx; |
| 2733 |
} |
| 2734 |
|
| 2735 |
void GUICraftMainPanel::DoShowPropertiesPage(wxWindow* win, const wxString& text, bool show) |
| 2736 |
{ |
| 2737 |
size_t where = DoFindPropertiesPage(win); |
| 2738 |
if(show && where == wxString::npos) { |
| 2739 |
m_notebook2->AddPage(win, text); |
| 2740 |
|
| 2741 |
} else if(!show && where != wxString::npos) { |
| 2742 |
m_notebook2->RemovePage(where); |
| 2743 |
} |
| 2744 |
} |
| 2745 |
|
| 2746 |
bool GUICraftMainPanel::DoCheckInsert(wxcWidget* source, wxcWidget* target) const |
| 2747 |
{ |
| 2748 |
return Allocator::Instance()->CanPaste(source, target); |
| 2749 |
} |
| 2750 |
|
| 2751 |
wxArrayString GUICraftMainPanel::GetCustomControlsUsed() const |
| 2752 |
{ |
| 2753 |
wxArrayString customControls; |
| 2754 |
wxTreeItemIdValue cookie; |
| 2755 |
wxTreeItemId rootItem = m_treeControls->GetRootItem(); |
| 2756 |
wxTreeItemId child = m_treeControls->GetFirstChild(rootItem, cookie); |
| 2757 |
while(child.IsOk()) { |
| 2758 |
|
| 2759 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(child)); |
| 2760 |
if(itemData && itemData->m_wxcWidget) { |
| 2761 |
itemData->m_wxcWidget->GetCustomControlsName(customControls); |
| 2762 |
} |
| 2763 |
child = m_treeControls->GetNextChild(rootItem, cookie); |
| 2764 |
} |
| 2765 |
return customControls; |
| 2766 |
} |
| 2767 |
|
| 2768 |
void GUICraftMainPanel::OnPageChanged(wxBookCtrlEvent& event) |
| 2769 |
{ |
| 2770 |
event.Skip(); |
| 2771 |
DoUpdateCppPreview(); |
| 2772 |
DoDismissFindBar(); |
| 2773 |
} |
| 2774 |
|
| 2775 |
void GUICraftMainPanel::OnUpdatePreview(wxCommandEvent& e) |
| 2776 |
{ |
| 2777 |
e.Skip(); |
| 2778 |
DoUpdateCppPreview(); |
| 2779 |
} |
| 2780 |
|
| 2781 |
void GUICraftMainPanel::DoUpdateCppPreview() |
| 2782 |
{ |
| 2783 |
// Notify about code editor {de}selected |
| 2784 |
wxCommandEvent event(wxEVT_WXC_CODE_PREVIEW_PAGE_CHANGED); |
| 2785 |
int sel = m_mainBook->GetSelection(); |
| 2786 |
if(sel == 1) { // C++ |
| 2787 |
event.SetClientData(m_notebookCpp->GetSelection() == 0 ? m_textCtrlCppSource : m_textCtrlHeaderSource); |
| 2788 |
m_mainBook->CppPageSelected(m_textCtrlCppSource, m_textCtrlHeaderSource); |
| 2789 |
|
| 2790 |
} else if(sel == 2) { // XRC |
| 2791 |
m_mainBook->XrcPageSelected(m_textCtrlXrc); |
| 2792 |
event.SetClientData(m_textCtrlXrc); |
| 2793 |
|
| 2794 |
} else { |
| 2795 |
event.SetClientData(NULL); |
| 2796 |
} |
| 2797 |
EventNotifier::Get()->AddPendingEvent(event); |
| 2798 |
} |
| 2799 |
|
| 2800 |
void GUICraftMainPanel::OnFindBar(clFindEvent& e) |
| 2801 |
{ |
| 2802 |
e.Skip(); |
| 2803 |
if(IsShown()) { |
| 2804 |
int sel = m_mainBook->GetSelection(); |
| 2805 |
if(sel == 1) { // C++ |
| 2806 |
e.Skip(false); |
| 2807 |
sel = m_notebookCpp->GetSelection(); |
| 2808 |
e.SetCtrl(sel == 0 ? m_textCtrlCppSource : m_textCtrlHeaderSource); |
| 2809 |
|
| 2810 |
} else if(sel == 2) { // XRC |
| 2811 |
e.Skip(false); |
| 2812 |
e.SetCtrl(m_textCtrlXrc); |
| 2813 |
} |
| 2814 |
} |
| 2815 |
} |
| 2816 |
|
| 2817 |
void GUICraftMainPanel::OnCppBookPageChanged(wxBookCtrlEvent& event) |
| 2818 |
{ |
| 2819 |
event.Skip(); |
| 2820 |
// Force the user to re-open the 'find-bar' |
| 2821 |
DoDismissFindBar(); |
| 2822 |
} |
| 2823 |
|
| 2824 |
void GUICraftMainPanel::DoDismissFindBar() |
| 2825 |
{ |
| 2826 |
// Notify the find-bar to clear any pointer referenced by it |
| 2827 |
// that is belonged to this view |
| 2828 |
clFindEvent evtFindBar(wxEVT_FINDBAR_RELEASE_EDITOR); |
| 2829 |
evtFindBar.SetCtrl(m_textCtrlCppSource); |
| 2830 |
EventNotifier::Get()->ProcessEvent(evtFindBar); |
| 2831 |
|
| 2832 |
evtFindBar.SetCtrl(m_textCtrlHeaderSource); |
| 2833 |
EventNotifier::Get()->ProcessEvent(evtFindBar); |
| 2834 |
|
| 2835 |
evtFindBar.SetCtrl(m_textCtrlXrc); |
| 2836 |
EventNotifier::Get()->ProcessEvent(evtFindBar); |
| 2837 |
} |
| 2838 |
|
| 2839 |
void GUICraftMainPanel::OnRename(wxCommandEvent& event) |
| 2840 |
{ |
| 2841 |
if(m_treeControls->GetSelection().IsOk()) { |
| 2842 |
GUICraftItemData* itemData = |
| 2843 |
dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(m_treeControls->GetSelection())); |
| 2844 |
CHECK_POINTER(itemData); |
| 2845 |
CHECK_POINTER(itemData->m_wxcWidget); |
| 2846 |
|
| 2847 |
wxString msg; |
| 2848 |
msg << _("Rename '") << itemData->m_wxcWidget->GetName() << _("'"); |
| 2849 |
wxString new_name = ::wxGetTextFromUser(_("Enter the new name:"), msg, itemData->m_wxcWidget->GetName(), this); |
| 2850 |
if(new_name.empty()) { |
| 2851 |
return; |
| 2852 |
} |
| 2853 |
|
| 2854 |
itemData->m_wxcWidget->SetName(new_name); |
| 2855 |
m_treeControls->SetItemText(m_treeControls->GetSelection(), new_name); |
| 2856 |
DoUpdatePropertiesView(); |
| 2857 |
wxcEditManager::Get().PushState("rename"); |
| 2858 |
} |
| 2859 |
} |
| 2860 |
|
| 2861 |
void GUICraftMainPanel::OnRefreshPropertiesView(wxCommandEvent& e) |
| 2862 |
{ |
| 2863 |
e.Skip(); |
| 2864 |
DoUpdatePropertiesView(); |
| 2865 |
} |
| 2866 |
|
| 2867 |
wxTreeItemId GUICraftMainPanel::DoFindItemByWxcWidget(wxcWidget* widget, const wxTreeItemId& item) const |
| 2868 |
{ |
| 2869 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(item)); |
| 2870 |
if(itemData && itemData->m_wxcWidget == widget) { |
| 2871 |
return item; |
| 2872 |
} |
| 2873 |
|
| 2874 |
if(!m_treeControls->HasChildren(item)) { |
| 2875 |
return wxTreeItemId(); |
| 2876 |
} |
| 2877 |
|
| 2878 |
wxTreeItemIdValue cookie; |
| 2879 |
wxTreeItemId child = m_treeControls->GetFirstChild(item, cookie); |
| 2880 |
while(child.IsOk()) { |
| 2881 |
|
| 2882 |
GUICraftItemData* itemData = dynamic_cast<GUICraftItemData*>(m_treeControls->GetItemData(child)); |
| 2883 |
if(itemData && itemData->m_wxcWidget) { |
| 2884 |
wxTreeItemId matchedItem = DoFindItemByWxcWidget(widget, child); |
| 2885 |
if(matchedItem.IsOk()) { |
| 2886 |
return matchedItem; |
| 2887 |
} |
| 2888 |
} |
| 2889 |
child = m_treeControls->GetNextChild(item, cookie); |
| 2890 |
} |
| 2891 |
return wxTreeItemId(); |
| 2892 |
} |
| 2893 |
|
| 2894 |
void GUICraftMainPanel::AddCustomControl(int controlId) |
| 2895 |
{ |
| 2896 |
CustomControlTemplate templateInfo = wxcSettings::Get().FindByControlId(controlId); |
| 2897 |
if(templateInfo.IsValid() == false) { |
| 2898 |
return; |
| 2899 |
} |
| 2900 |
|
| 2901 |
GUICraftItemData* data = GetSelItemData(); |
| 2902 |
CHECK_POINTER(data); |
| 2903 |
CHECK_POINTER(data->m_wxcWidget); |
| 2904 |
|
| 2905 |
// Allocate the new control |
| 2906 |
CustomControlWrapper* control = |
| 2907 |
dynamic_cast<CustomControlWrapper*>(Allocator::Instance()->Create(ID_WXCUSTOMCONTROL)); |
| 2908 |
CHECK_POINTER(control); |
| 2909 |
control->SetTemplInfoName(templateInfo.GetClassName()); |
| 2910 |
|
| 2911 |
int insertType = Allocator::Instance()->GetInsertionType(control->GetType(), data->m_wxcWidget->GetType(), false); |
| 2912 |
int imgId = Allocator::Instance()->GetImageId(ID_WXCUSTOMCONTROL); |
| 2913 |
DoInsertControl(control, data->m_wxcWidget, insertType, imgId); |
| 2914 |
} |
| 2915 |
|
| 2916 |
wxWindow* GUICraftMainPanel::GetTopFrame() const |
| 2917 |
{ |
| 2918 |
wxWindow* top = wxCrafter::TopFrame(); |
| 2919 |
if(!m_plugin->IsTabMode() && m_plugin->GetMainFrame() && m_plugin->GetMainFrame()->IsShown()) { |
| 2920 |
top = m_plugin->GetMainFrame(); |
| 2921 |
} else if(m_plugin->IsTabMode()) { |
| 2922 |
top = wxDynamicCast(top, wxFrame); |
| 2923 |
} |
| 2924 |
|
| 2925 |
return top; |
| 2926 |
} |
| 2927 |
|
| 2928 |
void GUICraftMainPanel::OnChangeSizerType(wxCommandEvent& e) { DoChangeOrInsertIntoSizer(e.GetId()); } |
| 2929 |
|
| 2930 |
void GUICraftMainPanel::OnInsertIntoSizer(wxCommandEvent& e) { DoChangeOrInsertIntoSizer(e.GetId()); } |
| 2931 |
|
| 2932 |
void GUICraftMainPanel::DoChangeOrInsertIntoSizer(int id) |
| 2933 |
{ |
| 2934 |
GUICraftItemData* data = GetSelItemData(); |
| 2935 |
wxTreeItemId itemId = m_treeControls->GetSelection(); |
| 2936 |
CHECK_POINTER(data); |
| 2937 |
CHECK_POINTER(data->m_wxcWidget); |
| 2938 |
CHECK_TREEITEM(itemId); |
| 2939 |
|
| 2940 |
int widgetType = wxNOT_FOUND; |
| 2941 |
switch(id) { |
| 2942 |
case ID_CHANGE_SIZER_BOXSIZER: |
| 2943 |
case ID_INSERT_INTO_SIZER_BOXSIZER: |
| 2944 |
widgetType = ID_WXBOXSIZER; |
| 2945 |
break; |
| 2946 |
case ID_CHANGE_SIZER_FLEXGRIDSIZER: |
| 2947 |
case ID_INSERT_INTO_SIZER_FLEXGRIDSIZER: |
| 2948 |
widgetType = ID_WXFLEXGRIDSIZER; |
| 2949 |
break; |
| 2950 |
case ID_CHANGE_SIZER_GRIDSIZER: |
| 2951 |
case ID_INSERT_INTO_SIZER_GRIDSIZER: |
| 2952 |
widgetType = ID_WXGRIDSIZER; |
| 2953 |
break; |
| 2954 |
case ID_CHANGE_SIZER_GRIDBAGSIZER: |
| 2955 |
case ID_INSERT_INTO_SIZER_GRIDBAGSIZER: |
| 2956 |
widgetType = ID_WXGRIDBAGSIZER; |
| 2957 |
break; |
| 2958 |
case ID_CHANGE_SIZER_STATICBOXSIZER: |
| 2959 |
case ID_INSERT_INTO_SIZER_STATICBOXSIZER: |
| 2960 |
widgetType = ID_WXSTATICBOXSIZER; |
| 2961 |
break; |
| 2962 |
} |
| 2963 |
|
| 2964 |
if(widgetType == wxNOT_FOUND) { |
| 2965 |
return; |
| 2966 |
} |
| 2967 |
|
| 2968 |
wxString label; |
| 2969 |
wxcWidget* newWidget = Allocator::Instance()->Create(widgetType); |
| 2970 |
|
| 2971 |
if(id < ID_CHANGE_SIZER_LAST) { // Changing the sizer type |
| 2972 |
wxcWidget::ReplaceWidget(data->m_wxcWidget, newWidget); |
| 2973 |
// delete the old widget |
| 2974 |
wxDELETE(data->m_wxcWidget); |
| 2975 |
|
| 2976 |
// replace the pointers |
| 2977 |
data->m_wxcWidget = newWidget; |
| 2978 |
|
| 2979 |
// Visual fixes: |
| 2980 |
// - Update the name on the tree view |
| 2981 |
// - Update the icon |
| 2982 |
m_treeControls->SetItemText(itemId, data->m_wxcWidget->GetName()); |
| 2983 |
int imgId = Allocator::Instance()->GetImageId(data->m_wxcWidget->GetType()); |
| 2984 |
m_treeControls->SetItemImage(itemId, imgId, wxTreeItemIcon_Expanded); |
| 2985 |
m_treeControls->SetItemImage(itemId, imgId, wxTreeItemIcon_Selected); |
| 2986 |
m_treeControls->SetItemImage(itemId, imgId, wxTreeItemIcon_Normal); |
| 2987 |
|
| 2988 |
label = "sizer type change"; |
| 2989 |
|
| 2990 |
} else if(id < ID_INSERT_INTO_SIZER_LAST) { // Inserting into a new sizer |
| 2991 |
wxString widgetName = m_treeControls->GetItemText(itemId); |
| 2992 |
wxcWidget* parentWidget = data->m_wxcWidget->GetParent(); |
| 2993 |
CHECK_POINTER(parentWidget); |
| 2994 |
|
| 2995 |
wxcWidget::InsertWidgetInto(data->m_wxcWidget, newWidget); |
| 2996 |
|
| 2997 |
#ifdef __WXMSW__ |
| 2998 |
wxWindowUpdateLocker locker(m_treeControls); |
| 2999 |
#endif |
| 3000 |
wxTreeItemId treeItemParent = m_treeControls->GetItemParent(itemId); |
| 3001 |
CHECK_TREEITEM(itemId); |
| 3002 |
DoUnsetItemData(treeItemParent); |
| 3003 |
m_treeControls->DeleteChildren(treeItemParent); |
| 3004 |
|
| 3005 |
wxTreeItemId dummy; |
| 3006 |
m_treeControls->SetItemData(treeItemParent, new GUICraftItemData(parentWidget)); |
| 3007 |
const wxcWidget::List_t& list = parentWidget->GetChildren(); |
| 3008 |
wxcWidget::List_t::const_iterator iter = list.begin(); |
| 3009 |
for(; iter != list.end(); ++iter) { |
| 3010 |
DoBuildTree(dummy, *iter, treeItemParent); |
| 3011 |
} |
| 3012 |
|
| 3013 |
ExpandToItem(widgetName, treeItemParent); |
| 3014 |
|
| 3015 |
label = "insertion into sizer"; |
| 3016 |
} |
| 3017 |
|
| 3018 |
m_treeControls->Refresh(); |
| 3019 |
|
| 3020 |
DoRefresh(wxEVT_UPDATE_PREVIEW); |
| 3021 |
wxcEditManager::Get().PushState(label); |
| 3022 |
} |
| 3023 |
|
| 3024 |
wxStyledTextCtrl* GUICraftMainPanel::GetPreviewEditor() const |
| 3025 |
{ |
| 3026 |
if(m_mainBook->GetSelection() == 1) { |
| 3027 |
// C++ tab is selected |
| 3028 |
wxStyledTextCtrl* stc = m_notebookCpp->GetSelection() == 0 ? m_textCtrlCppSource : m_textCtrlHeaderSource; |
| 3029 |
return stc; |
| 3030 |
} |
| 3031 |
return NULL; |
| 3032 |
} |
| 3033 |
|
| 3034 |
void GUICraftMainPanel::OnEventEditorUI(wxUpdateUIEvent& e) { e.Enable(true); } |
| 3035 |
|
| 3036 |
void GUICraftMainPanel::OnStylesChanged(wxPropertyGridEvent& event) |
| 3037 |
{ |
| 3038 |
m_styles.Changed(m_pgMgrStyles->GetGrid(), event); |
| 3039 |
} |
| 3040 |
void GUICraftMainPanel::OnSizerFlagsChanged(wxPropertyGridEvent& event) |
| 3041 |
{ |
| 3042 |
m_sizerFlags.Changed(m_pgMgrSizerFlags->GetGrid(), event); |
| 3043 |
} |
| 3044 |
void GUICraftMainPanel::OnSizerFlagsUpdateUI(wxUpdateUIEvent& event) |
| 3045 |
{ |
| 3046 |
m_sizerFlags.DoUpdateUI(m_pgMgrSizerFlags->GetGrid(), event); |
| 3047 |
} |
| 3048 |
|
| 3049 |
void GUICraftMainPanel::OnAuiPaneInfoChanged(wxPropertyGridEvent& event) |
| 3050 |
{ |
| 3051 |
m_auiPaneInfo.Changed(m_pgMgrAuiProperties->GetGrid(), event); |
| 3052 |
} |
| 3053 |
|
| 3054 |
void GUICraftMainPanel::DoGenerateCode(bool silent) |
| 3055 |
{ |
| 3056 |
// Show the nag dialog if needed |
| 3057 |
if(!silent) { |
| 3058 |
wxcSettings::Get().ShowNagDialogIfNeeded(); |
| 3059 |
} |
| 3060 |
|
| 3061 |
if(!wxcProjectMetadata::Get().GetGenerateCPPCode() && !wxcProjectMetadata::Get().GetGenerateXRC()) { |
| 3062 |
if(silent) { |
| 3063 |
return; |
| 3064 |
} |
| 3065 |
wxString msg; |
| 3066 |
msg << _("You need to enable at least one of 'Generate C++ code' and 'Generate XRC'"); |
| 3067 |
::wxMessageBox(msg, "wxCrafter", wxOK | wxCENTER | wxICON_WARNING, wxCrafter::TopFrame()); |
| 3068 |
return; |
| 3069 |
} |
| 3070 |
|
| 3071 |
wxFileName outputDir(wxcProjectMetadata::Get().GetGeneratedFilesDir(), ""); |
| 3072 |
wxCrafter::MakeAbsToProject(outputDir); |
| 3073 |
if(!outputDir.DirExists()) { |
| 3074 |
if(silent) { |
| 3075 |
return; |
| 3076 |
} |
| 3077 |
wxString msg; |
| 3078 |
msg << _("Please set the base classes generated files output directory\nThis can be done by selecting the root " |
| 3079 |
"item of the tree and edit the properties"); |
| 3080 |
::wxMessageBox(msg, "wxCrafter", wxOK | wxCENTER | wxICON_WARNING, wxCrafter::TopFrame()); |
| 3081 |
return; |
| 3082 |
} |
| 3083 |
|
| 3084 |
if(wxcProjectMetadata::Get().GetProjectFile().IsEmpty()) { |
| 3085 |
if(silent) { |
| 3086 |
return; |
| 3087 |
} |
| 3088 |
wxString msg; |
| 3089 |
msg << _("You must save the project before generating code"); |
| 3090 |
::wxMessageBox(msg, "wxCrafter", wxOK | wxCENTER | wxICON_WARNING, wxCrafter::TopFrame()); |
| 3091 |
return; |
| 3092 |
} |
| 3093 |
|
| 3094 |
// Always save the project when generating code |
| 3095 |
// even if its not modified |
| 3096 |
wxCommandEvent dummy; |
| 3097 |
OnSaveProject(dummy); |
| 3098 |
|
| 3099 |
// Loop over the top level windows and generate their base classes |
| 3100 |
wxArrayString headers; |
| 3101 |
wxString baseCpp; |
| 3102 |
wxString baseHeader; |
| 3103 |
wxString blockGuard; |
| 3104 |
|
| 3105 |
wxString autoGenComment; |
| 3106 |
autoGenComment << "//////////////////////////////////////////////////////////////////////" |
| 3107 |
<< "\n"; |
| 3108 |
autoGenComment << "// This file was auto-generated by codelite's wxCrafter Plugin\n"; |
| 3109 |
autoGenComment << "// wxCrafter project file: " << wxcProjectMetadata::Get().GetProjectFileName().GetFullName() |
| 3110 |
<< "\n"; |
| 3111 |
autoGenComment << "// Do not modify this file by hand!\n"; |
| 3112 |
autoGenComment << "//////////////////////////////////////////////////////////////////////" |
| 3113 |
<< "\n\n"; |
| 3114 |
|
| 3115 |
wxFileName projectFile(wxcProjectMetadata::Get().GetProjectFile()); |
| 3116 |
wxCrafter::MakeAbsToProject(projectFile); |
| 3117 |
|
| 3118 |
wxFileName headerFile = wxcProjectMetadata::Get().BaseHeaderFile(); |
| 3119 |
wxCrafter::MakeAbsToProject(headerFile); |
| 3120 |
|
| 3121 |
wxFileName sourceFile = wxcProjectMetadata::Get().BaseCppFile(); |
| 3122 |
wxCrafter::MakeAbsToProject(sourceFile); |
| 3123 |
|
| 3124 |
blockGuard = "_"; // Ensure that the blockguard does not start with a number |
| 3125 |
wxArrayString dirs = projectFile.GetDirs(); |
| 3126 |
if(!dirs.IsEmpty()) { |
| 3127 |
if(dirs.size() > 2) { |
| 3128 |
blockGuard << dirs.Item(dirs.size() - 2) << "_"; |
| 3129 |
} |
| 3130 |
blockGuard << dirs.Last() << "_"; |
| 3131 |
} |
| 3132 |
blockGuard << projectFile.GetName(); |
| 3133 |
blockGuard.Replace("-", "_"); |
| 3134 |
blockGuard.Replace(".", "_"); |
| 3135 |
blockGuard.Replace("+", "_"); |
| 3136 |
blockGuard.Replace(":", "_"); |
| 3137 |
blockGuard << "_BASE_CLASSES"; |
| 3138 |
blockGuard << "_" << wxcProjectMetadata::Get().GetHeaderFileExt(); |
| 3139 |
blockGuard.MakeUpper(); |
| 3140 |
|
| 3141 |
// Before we start traversing the tree, clear the bitmap code generator content |
| 3142 |
wxcCodeGeneratorHelper::Get().Clear(); |
| 3143 |
wxcProjectMetadata::Get().ClearAggregatedData(); |
| 3144 |
wxStringMap_t additionalFiles; |
| 3145 |
|
| 3146 |
GenerateCppOutput(baseCpp, baseHeader, headers, additionalFiles); |
| 3147 |
|
| 3148 |
wxcProjectMetadata::Get().SetAdditionalFiles(additionalFiles); |
| 3149 |
if(wxcProjectMetadata::Get().GetGenerateCPPCode() && (baseCpp.IsEmpty() == false)) { |
| 3150 |
|
| 3151 |
// Write the base cpp/header |
| 3152 |
headers = wxCrafter::MakeUnique(headers); |
| 3153 |
|
| 3154 |
wxString prefix; |
| 3155 |
prefix << autoGenComment; |
| 3156 |
prefix << "#ifndef " << blockGuard << "\n"; |
| 3157 |
prefix << "#define " << blockGuard << "\n\n"; |
| 3158 |
prefix << "// clang-format off\n"; |
| 3159 |
prefix << wxCrafter::Join(headers, "\n") << "\n"; |
| 3160 |
|
| 3161 |
// wxPersistence support |
| 3162 |
prefix << wxCrafter::WX29_BLOCK_START(); |
| 3163 |
prefix << "#include <wx/persist.h>\n"; |
| 3164 |
prefix << "#include <wx/persist/toplevel.h>\n"; |
| 3165 |
prefix << "#include <wx/persist/bookctrl.h>\n"; |
| 3166 |
prefix << "#include <wx/persist/treebook.h>\n"; |
| 3167 |
prefix << "#endif\n"; |
| 3168 |
|
| 3169 |
prefix << "\n"; |
| 3170 |
prefix << "#ifdef WXC_FROM_DIP\n"; |
| 3171 |
prefix << "#undef WXC_FROM_DIP\n"; |
| 3172 |
prefix << "#endif\n"; |
| 3173 |
prefix << wxCrafter::WX31_BLOCK_START(); |
| 3174 |
prefix << "#define WXC_FROM_DIP(x) wxWindow::FromDIP(x, NULL)\n"; |
| 3175 |
prefix << "#else\n"; |
| 3176 |
prefix << "#define WXC_FROM_DIP(x) x\n"; |
| 3177 |
prefix << "#endif\n\n"; |
| 3178 |
|
| 3179 |
// Prepare the project additional include files |
| 3180 |
wxString projectIncludes; |
| 3181 |
const wxArrayString& includes = wxcProjectMetadata::Get().GetIncludeFiles(); |
| 3182 |
for(size_t i = 0; i < includes.GetCount(); i++) { |
| 3183 |
projectIncludes << "#include " << wxCrafter::AddQuotes(includes.Item(i)) << "\n"; |
| 3184 |
} |
| 3185 |
prefix << projectIncludes; |
| 3186 |
prefix << "// clang-format on\n"; |
| 3187 |
|
| 3188 |
baseHeader.Prepend(prefix); |
| 3189 |
baseHeader.Append("#endif\n"); |
| 3190 |
|
| 3191 |
if(wxCrafter::IsTheSame(baseHeader, headerFile) == false) { |
| 3192 |
wxCrafter::WriteFile(headerFile, baseHeader, true); |
| 3193 |
wxCrafter::FormatFile(headerFile); |
| 3194 |
wxCrafter::NotifyFileSaved(headerFile); |
| 3195 |
} |
| 3196 |
|
| 3197 |
wxString cppPrefix; |
| 3198 |
cppPrefix << autoGenComment; |
| 3199 |
cppPrefix << "#include \"" << headerFile.GetFullName() << "\"\n"; |
| 3200 |
cppPrefix << projectIncludes << "\n\n"; |
| 3201 |
|
| 3202 |
cppPrefix << "// Declare the bitmap loading function\n"; |
| 3203 |
cppPrefix << wxcCodeGeneratorHelper::Get().GenerateExternCode() << "\n"; // Add the bitmap extern code |
| 3204 |
cppPrefix << SIMPLE_BORDER_CODE; |
| 3205 |
|
| 3206 |
baseCpp.Prepend(cppPrefix); |
| 3207 |
if(wxCrafter::IsTheSame(baseCpp, sourceFile) == false) { |
| 3208 |
wxCrafter::WriteFile(sourceFile, baseCpp, true); |
| 3209 |
wxCrafter::FormatFile(sourceFile); |
| 3210 |
wxCrafter::NotifyFileSaved(sourceFile); |
| 3211 |
} |
| 3212 |
} |
| 3213 |
|
| 3214 |
if(wxcProjectMetadata::Get().GetGenerateCPPCode() && !additionalFiles.empty()) { |
| 3215 |
wxStringMap_t::const_iterator itr = additionalFiles.begin(); |
| 3216 |
for(; itr != additionalFiles.end(); ++itr) { |
| 3217 |
wxFileName additionalFile = wxcProjectMetadata::Get().BaseHeaderFile(); |
| 3218 |
additionalFile.SetFullName(itr->first); |
| 3219 |
wxCrafter::MakeAbsToProject(additionalFile); |
| 3220 |
|
| 3221 |
if(wxCrafter::IsTheSame(itr->second, additionalFile) == false) { |
| 3222 |
wxCrafter::WriteFile(additionalFile, itr->second, true); |
| 3223 |
wxCrafter::FormatFile(additionalFile); |
| 3224 |
wxCrafter::NotifyFileSaved(additionalFile); |
| 3225 |
} |
| 3226 |
} |
| 3227 |
} |
| 3228 |
|
| 3229 |
// Export the XRC output if required |
| 3230 |
if(wxcProjectMetadata::Get().GetGenerateXRC()) { |
| 3231 |
wxString xrcFilePath = wxcProjectMetadata::Get().GetXrcFileName(); |
| 3232 |
if(!xrcFilePath.empty()) { |
| 3233 |
wxString XrcOutput; |
| 3234 |
GenerateXrcOutput(XrcOutput); |
| 3235 |
if(!XrcOutput.empty()) { |
| 3236 |
TopLevelWinWrapper::WrapXRC(XrcOutput); |
| 3237 |
// Format the output and make it human readable |
| 3238 |
wxStringInputStream str(XrcOutput); |
| 3239 |
wxStringOutputStream out; |
| 3240 |
wxXmlDocument doc(str); |
| 3241 |
if(!doc.Save(out)) { |
| 3242 |
wxMessageBox(XrcOutput); |
| 3243 |
} |
| 3244 |
|
| 3245 |
wxFileName fnXrcFilePath(xrcFilePath); |
| 3246 |
wxCrafter::MakeAbsToProject(fnXrcFilePath); |
| 3247 |
wxCrafter::WriteFile(fnXrcFilePath.GetFullPath(), out.GetString(), true); |
| 3248 |
wxCrafter::NotifyFileSaved(fnXrcFilePath); |
| 3249 |
} |
| 3250 |
} |
| 3251 |
} |
| 3252 |
|
| 3253 |
// And finally, generate the Bitmap resource file |
| 3254 |
wxcCodeGeneratorHelper::Get().CreateXRC(); |
| 3255 |
} |
| 3256 |
|
| 3257 |
void GUICraftMainPanel::BatchGenerate(const wxArrayString& files) |
| 3258 |
{ |
| 3259 |
// SHow the nag dialog if needed |
| 3260 |
wxcSettings::Get().ShowNagDialogIfNeeded(); |
| 3261 |
|
| 3262 |
wxArrayString projectsGenerated; |
| 3263 |
wxArrayString wxcpFiles; |
| 3264 |
|
| 3265 |
#ifdef STANDALONE_BUILD |
| 3266 |
wxUnusedVar(files); |
| 3267 |
wxFileDialog openFileDialog(this, _("Select wxCrafter files:"), "", "", "wxCrafter Project Files (*.wxcp)|*.wxcp", |
| 3268 |
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE); |
| 3269 |
if(openFileDialog.ShowModal() != wxID_OK) { |
| 3270 |
return; |
| 3271 |
} |
| 3272 |
openFileDialog.GetPaths(wxcpFiles); |
| 3273 |
#else |
| 3274 |
wxcpFiles = files; |
| 3275 |
#endif |
| 3276 |
|
| 3277 |
if(wxcpFiles.IsEmpty()) { |
| 3278 |
return; |
| 3279 |
} |
| 3280 |
if(wxcProjectMetadata::Get().IsLoaded()) { |
| 3281 |
::wxMessageBox(_("Please close the current wxCrafter project before batch generating code"), "wxCrafter", |
| 3282 |
wxOK | wxCENTER | wxICON_ERROR); |
| 3283 |
return; |
| 3284 |
} |
| 3285 |
|
| 3286 |
{ |
| 3287 |
wxBusyCursor bc; |
| 3288 |
wxBusyInfo bi(_("Generating Code...")); |
| 3289 |
|
| 3290 |
// Lock the UI |
| 3291 |
wxWindowUpdateLocker locker(EventNotifier::Get()->TopFrame()); |
| 3292 |
|
| 3293 |
for(size_t i = 0; i < wxcpFiles.size(); ++i) { |
| 3294 |
wxString fileContent; |
| 3295 |
if(FileUtils::ReadFileContent(wxcpFiles.Item(i), fileContent)) { |
| 3296 |
LoadProject(wxcpFiles.Item(i), fileContent); |
| 3297 |
DoGenerateCode(true); |
| 3298 |
projectsGenerated.Add(wxcpFiles.Item(i)); |
| 3299 |
} |
| 3300 |
} |
| 3301 |
|
| 3302 |
// Close any project |
| 3303 |
if(wxcProjectMetadata::Get().IsLoaded()) { |
| 3304 |
wxCommandEvent e; |
| 3305 |
OnCloseProject(e); |
| 3306 |
} |
| 3307 |
} |
| 3308 |
if(!projectsGenerated.IsEmpty()) { |
| 3309 |
wxString message; |
| 3310 |
message << _("Generated Code For the following projects:\n") << wxImplode(projectsGenerated, "\n"); |
| 3311 |
::wxMessageBox(message, "wxCrafter"); |
| 3312 |
} |
| 3313 |
} |
| 3314 |
|
| 3315 |
void GUICraftMainPanel::OnBatchGenerateCode(wxCommandEvent& e) |
| 3316 |
{ |
| 3317 |
wxUnusedVar(e); |
| 3318 |
#ifdef STANDALONE_BUILD |
| 3319 |
BatchGenerate(wxArrayString()); |
| 3320 |
#endif |
| 3321 |
} |