| 1 |
#include "wxcrafter_plugin.h" |
| 2 |
|
| 3 |
#include "AboutDlg.h" |
| 4 |
#include "ColoursAndFontsManager.h" |
| 5 |
#include "DefineCustomControlWizard.h" |
| 6 |
#include "DeleteCustomControlDlg.h" |
| 7 |
#include "EditCustomControlDlg.h" |
| 8 |
#include "EventsEditorDlg.h" |
| 9 |
#include "MessageDlg.h" |
| 10 |
#include "MyComboBoxXmlHandler.h" |
| 11 |
#include "MyRearrangeListXmlHandler.h" |
| 12 |
#include "NewFormWizard.h" |
| 13 |
#include "VirtualDirectorySelectorDlg.h" |
| 14 |
#include "allocator_mgr.h" |
| 15 |
#include "clKeyboardManager.h" |
| 16 |
#include "clStatusBar.h" |
| 17 |
#include "cl_command_event.h" |
| 18 |
#include "codelite_events.h" |
| 19 |
#include "ctags_manager.h" |
| 20 |
#include "editor_config.h" |
| 21 |
#include "entry.h" |
| 22 |
#include "event_notifier.h" |
| 23 |
#include "functions_parser.h" |
| 24 |
#include "globals.h" |
| 25 |
#include "gui.h" |
| 26 |
#include "import_from_wxFB.h" |
| 27 |
#include "import_from_wxSmith.h" |
| 28 |
#include "import_from_xrc.h" |
| 29 |
#include "myxh_auibook.h" |
| 30 |
#include "myxh_auimgr.h" |
| 31 |
#include "myxh_auitoolb.h" |
| 32 |
#include "myxh_cmdlinkbtn.h" |
| 33 |
#include "myxh_dataview.h" |
| 34 |
#include "myxh_dlg.h" |
| 35 |
#include "myxh_dvlistctrl.h" |
| 36 |
#include "myxh_dvtreectrl.h" |
| 37 |
#include "myxh_frame.h" |
| 38 |
#include "myxh_glcanvas.h" |
| 39 |
#include "myxh_grid.h" |
| 40 |
#include "myxh_infobar.h" |
| 41 |
#include "myxh_listc.h" |
| 42 |
#include "myxh_mediactrl.h" |
| 43 |
#include "myxh_panel.h" |
| 44 |
#include "myxh_propgrid.h" |
| 45 |
#include "myxh_ribbon.h" |
| 46 |
#include "myxh_richtext.h" |
| 47 |
#include "myxh_searchctrl.h" |
| 48 |
#include "myxh_simplebook.h" |
| 49 |
#include "myxh_stc.h" |
| 50 |
#include "myxh_textctrl.h" |
| 51 |
#include "myxh_toolbk.h" |
| 52 |
#include "myxh_treebk.h" |
| 53 |
#include "myxh_treelist.h" |
| 54 |
#include "myxh_webview.h" |
| 55 |
#include "plugin.h" |
| 56 |
#include "project.h" |
| 57 |
#include "workspace.h" |
| 58 |
#include "wxcSettingsDlg.h" |
| 59 |
#include "wxcTreeView.h" |
| 60 |
#include "wxc_bitmap_code_generator.h" |
| 61 |
#include "wxc_settings.h" |
| 62 |
#include "wxgui_bitmaploader.h" |
| 63 |
#include "wxgui_globals.h" |
| 64 |
#include "wxgui_helpers.h" |
| 65 |
#include "wxguicraft_main_view.h" |
| 66 |
|
| 67 |
#include <wx/choicdlg.h> |
| 68 |
#include <wx/dataview.h> |
| 69 |
#include <wx/module.h> |
| 70 |
#include <wx/msgdlg.h> |
| 71 |
#include <wx/propgrid/propgrid.h> |
| 72 |
#include <wx/stc/stc.h> |
| 73 |
#include <wx/xrc/xmlres.h> |
| 74 |
|
| 75 |
static wxCrafterPlugin* thePlugin = NULL; |
| 76 |
|
| 77 |
// Define the plugin entry point |
| 78 |
CL_PLUGIN_API IPlugin* CreatePlugin(IManager* manager) |
| 79 |
{ |
| 80 |
if(thePlugin == 0) { |
| 81 |
thePlugin = new wxCrafterPlugin(manager, false); |
| 82 |
} |
| 83 |
return thePlugin; |
| 84 |
} |
| 85 |
|
| 86 |
CL_PLUGIN_API PluginInfo* GetPluginInfo() |
| 87 |
{ |
| 88 |
static PluginInfo info; |
| 89 |
info.SetAuthor("Eran"); |
| 90 |
info.SetName("wxcrafter"); |
| 91 |
info.SetDescription(_("wxWidgets GUI Designer")); |
| 92 |
info.SetVersion("v2.4"); |
| 93 |
return &info; |
| 94 |
} |
| 95 |
|
| 96 |
CL_PLUGIN_API int GetPluginInterfaceVersion() { return PLUGIN_INTERFACE_VERSION; } |
| 97 |
|
| 98 |
wxCrafterPlugin::wxCrafterPlugin(IManager* manager, bool serverMode) |
| 99 |
: IPlugin(manager) |
| 100 |
, m_mainPanel(NULL) |
| 101 |
, m_allEditorsClosing(false) |
| 102 |
, m_addFileMenu(true) |
| 103 |
, m_useFrame(true) |
| 104 |
, m_mainFrame(NULL) |
| 105 |
, m_serverMode(serverMode) |
| 106 |
{ |
| 107 |
Allocator::Initialize(); |
| 108 |
Allocator::Instance()->SetPlugin(this); |
| 109 |
|
| 110 |
#if !STANDALONE_BUILD |
| 111 |
/// Initialize wxPG only in plugin mode |
| 112 |
wxPGInitResourceModule(); |
| 113 |
|
| 114 |
// Start the network thread |
| 115 |
#endif |
| 116 |
|
| 117 |
// Initialize all image handlers known to us (that aren't already loaded) |
| 118 |
if(wxImage::FindHandler(wxBITMAP_TYPE_PNG) == 0) { |
| 119 |
wxImage::AddHandler(new wxPNGHandler); |
| 120 |
} |
| 121 |
if(wxImage::FindHandler(wxBITMAP_TYPE_JPEG) == 0) { |
| 122 |
wxImage::AddHandler(new wxJPEGHandler); |
| 123 |
} |
| 124 |
if(wxImage::FindHandler(wxBITMAP_TYPE_GIF) == 0) { |
| 125 |
wxImage::AddHandler(new wxGIFHandler); |
| 126 |
} |
| 127 |
if(wxImage::FindHandler(wxBITMAP_TYPE_BMP) == 0) { |
| 128 |
wxImage::AddHandler(new wxBMPHandler); |
| 129 |
} |
| 130 |
if(wxImage::FindHandler(wxBITMAP_TYPE_ICO) == 0) { |
| 131 |
wxImage::AddHandler(new wxICOHandler); |
| 132 |
} |
| 133 |
if(wxImage::FindHandler(wxBITMAP_TYPE_ANI) == 0) { |
| 134 |
wxImage::AddHandler(new wxANIHandler); |
| 135 |
} |
| 136 |
if(wxImage::FindHandler(wxBITMAP_TYPE_CUR) == 0) { |
| 137 |
wxImage::AddHandler(new wxCURHandler); |
| 138 |
} |
| 139 |
|
| 140 |
wxXmlResource::Get()->ClearHandlers(); |
| 141 |
|
| 142 |
// +++++++++++--------------------------------------------- |
| 143 |
// Custom XML resource handlers |
| 144 |
// +++++++++++--------------------------------------------- |
| 145 |
|
| 146 |
wxXmlResource::Get()->AddHandler(new MYwxTreebookXmlHandler); |
| 147 |
wxXmlResource::Get()->AddHandler(new MyWxRichTextCtrlXmlHandler); |
| 148 |
wxXmlResource::Get()->AddHandler(new MyWxGridXmlHandler); |
| 149 |
wxXmlResource::Get()->AddHandler(new MyWxSearchCtrlXmlHandler); |
| 150 |
wxXmlResource::Get()->AddHandler(new MYwxToolbookXmlHandler); |
| 151 |
wxXmlResource::Get()->AddHandler(new MYwxListCtrlXmlHandler); |
| 152 |
wxXmlResource::Get()->AddHandler(new MyWxSimplebookXmlHandler); |
| 153 |
wxXmlResource::Get()->AddHandler(new MyWxAuiToolBarXmlHandler); |
| 154 |
wxXmlResource::Get()->AddHandler(new MyWxStcXmlHandler); |
| 155 |
wxXmlResource::Get()->AddHandler(new MyWxDataViewListCtrlHandler); |
| 156 |
wxXmlResource::Get()->AddHandler(new MyWxDataViewTreeCtrlHandler); |
| 157 |
wxXmlResource::Get()->AddHandler(new MyWxDataViewCtrlHandler); |
| 158 |
wxXmlResource::Get()->AddHandler(new MyWxInfoBarCtrlHandler); |
| 159 |
wxXmlResource::Get()->AddHandler(new MyWxWebViewXmlHandler); |
| 160 |
wxXmlResource::Get()->AddHandler(new MyWxGLCanvasXmlHandler); |
| 161 |
wxXmlResource::Get()->AddHandler(new MyWxMediaCtrlXmlHandler); |
| 162 |
wxXmlResource::Get()->AddHandler(new wxMyFrameXmlHandler); |
| 163 |
wxXmlResource::Get()->AddHandler(new MyWxPanelXmlHandler); |
| 164 |
wxXmlResource::Get()->AddHandler(new MyWxAuiManagerXmlHandler); |
| 165 |
wxXmlResource::Get()->AddHandler(new MyWxDialogXmlHandler); |
| 166 |
wxXmlResource::Get()->AddHandler(new MyWxPropGridXmlHandler); |
| 167 |
wxXmlResource::Get()->AddHandler(new MyWxRibbonXmlHandler); |
| 168 |
wxXmlResource::Get()->AddHandler(new MyWxCommandLinkButtonXmlHandler); |
| 169 |
wxXmlResource::Get()->AddHandler(new MyTreeListCtrl); |
| 170 |
wxXmlResource::Get()->AddHandler(new MyTextCtrlXrcHandler); |
| 171 |
wxXmlResource::Get()->AddHandler(new MyComboBoxXmlHandler); |
| 172 |
wxXmlResource::Get()->AddHandler(new MyRearrangeListXmlHandler); |
| 173 |
wxXmlResource::Get()->InitAllHandlers(); |
| 174 |
|
| 175 |
// wxCrafter::ResourceLoader bmps; |
| 176 |
m_longName = _("wxWidgets GUI Designer"); |
| 177 |
m_shortName = "wxCrafter"; |
| 178 |
|
| 179 |
// will be initialized in the OnInitDone() |
| 180 |
#if STANDALONE_BUILD |
| 181 |
DoInitDone(); |
| 182 |
#endif |
| 183 |
|
| 184 |
EventNotifier::Get()->Bind(wxEVT_SHOW_WORKSPACE_TAB, &wxCrafterPlugin::OnToggleView, this); |
| 185 |
EventNotifier::Get()->Connect(wxEVT_INIT_DONE, wxCommandEventHandler(wxCrafterPlugin::OnInitDone), NULL, this); |
| 186 |
EventNotifier::Get()->Connect(wxEVT_SHOW_WXCRAFTER_DESIGNER, wxCommandEventHandler(wxCrafterPlugin::OnShowDesigner), |
| 187 |
NULL, this); |
| 188 |
EventNotifier::Get()->Connect(wxEVT_DESIGNER_DELETED, wxCommandEventHandler(wxCrafterPlugin::OnDesignerDelete), |
| 189 |
NULL, this); |
| 190 |
EventNotifier::Get()->Connect(wxEVT_BITMAP_CODE_GENERATION_DONE, |
| 191 |
wxCommandEventHandler(wxCrafterPlugin::OnBitmapCodeGenerationCompleted), NULL, this); |
| 192 |
EventNotifier::Get()->Connect(wxEVT_TREE_ITEM_FILE_ACTIVATED, clCommandEventHandler(wxCrafterPlugin::OnOpenFile), |
| 193 |
NULL, this); |
| 194 |
EventNotifier::Get()->Connect(wxEVT_NOTIFY_PAGE_CLOSING, wxNotifyEventHandler(wxCrafterPlugin::OnPageClosing), NULL, |
| 195 |
this); |
| 196 |
EventNotifier::Get()->Connect(wxEVT_CMD_WXCRAFTER_PROJECT_MODIFIED, |
| 197 |
wxCommandEventHandler(wxCrafterPlugin::OnProjectModified), NULL, this); |
| 198 |
EventNotifier::Get()->Connect(wxEVT_CMD_WXCRAFTER_PROJECT_SYNCHED, |
| 199 |
wxCommandEventHandler(wxCrafterPlugin::OnProjectSynched), NULL, this); |
| 200 |
EventNotifier::Get()->Connect(wxEVT_CMD_PAGE_CHANGED, wxCommandEventHandler(wxCrafterPlugin::OnPageChanged), NULL, |
| 201 |
this); |
| 202 |
EventNotifier::Get()->Connect(wxEVT_PREVIEW_CTRL_SELECTED, |
| 203 |
wxCommandEventHandler(wxCrafterPlugin::OnDesignerItemSelected), NULL, this); |
| 204 |
EventNotifier::Get()->Bind(wxEVT_WORKSPACE_CLOSED, &wxCrafterPlugin::OnWorkspaceClosed, this); |
| 205 |
EventNotifier::Get()->Connect(wxEVT_BUILD_STARTING, wxCommandEventHandler(wxCrafterPlugin::OnBuildStarting), NULL, |
| 206 |
this); |
| 207 |
EventNotifier::Get()->Connect(wxEVT_ALL_EDITORS_CLOSING, |
| 208 |
wxCommandEventHandler(wxCrafterPlugin::OnAllEditorsClosing), NULL, this); |
| 209 |
EventNotifier::Get()->Connect(wxEVT_ALL_EDITORS_CLOSED, wxCommandEventHandler(wxCrafterPlugin::OnAllEditorsClosed), |
| 210 |
NULL, this); |
| 211 |
EventNotifier::Get()->Connect(XRCID("save_file"), wxCommandEventHandler(wxCrafterPlugin::OnSave), NULL, this); |
| 212 |
EventNotifier::Get()->Connect(wxEVT_SAVE_ALL_EDITORS, clCommandEventHandler(wxCrafterPlugin::OnSaveAll), NULL, |
| 213 |
this); |
| 214 |
EventNotifier::Get()->Connect(wxEVT_WXGUI_PROJECT_LOADED, wxCommandEventHandler(wxCrafterPlugin::OnProjectLoaded), |
| 215 |
NULL, this); |
| 216 |
|
| 217 |
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FILE, &wxCrafterPlugin::OnFileContextMenu, this); |
| 218 |
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_VIRTUAL_FOLDER, &wxCrafterPlugin::OnVirtualFolderContextMenu, this); |
| 219 |
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_PROJECT, &wxCrafterPlugin::OnProjectContextMenu, this); |
| 220 |
EventNotifier::Get()->Bind(wxEVT_PAGE_MODIFIED_UPDATE_UI, &wxCrafterPlugin::OnSaveUI, this); |
| 221 |
// Menu events |
| 222 |
wxTheApp->Connect(XRCID("wxc_settings"), wxEVT_COMMAND_MENU_SELECTED, |
| 223 |
wxCommandEventHandler(wxCrafterPlugin::OnSettings), NULL, this); |
| 224 |
wxTheApp->Connect(XRCID("open_wxcp_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 225 |
wxCommandEventHandler(wxCrafterPlugin::OnOpenProject), NULL, this); |
| 226 |
wxTheApp->Connect(XRCID("close_wxcp_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 227 |
wxCommandEventHandler(wxCrafterPlugin::OnCloseProject), NULL, this); |
| 228 |
wxTheApp->Connect(XRCID("save_wxcp_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 229 |
wxCommandEventHandler(wxCrafterPlugin::OnSaveProject), NULL, this); |
| 230 |
wxTheApp->Connect(XRCID("import_wxFB_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 231 |
wxCommandEventHandler(wxCrafterPlugin::OnImportwxFBProject), NULL, this); |
| 232 |
wxTheApp->Connect(XRCID("import_wxSmith_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 233 |
wxCommandEventHandler(wxCrafterPlugin::OnImportwxSmith), NULL, this); |
| 234 |
wxTheApp->Connect(XRCID("import_XRC_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 235 |
wxCommandEventHandler(wxCrafterPlugin::OnImportXRC), NULL, this); |
| 236 |
wxTheApp->Connect(XRCID("define_custom_controls"), wxEVT_COMMAND_MENU_SELECTED, |
| 237 |
wxCommandEventHandler(wxCrafterPlugin::OnDefineCustomControls), NULL, this); |
| 238 |
wxTheApp->Connect(XRCID("edit_custom_controls"), wxEVT_COMMAND_MENU_SELECTED, |
| 239 |
wxCommandEventHandler(wxCrafterPlugin::OnEditCustomControls), NULL, this); |
| 240 |
wxTheApp->Connect(XRCID("delete_custom_controls"), wxEVT_COMMAND_MENU_SELECTED, |
| 241 |
wxCommandEventHandler(wxCrafterPlugin::OnDeleteCustomControls), NULL, this); |
| 242 |
wxTheApp->Connect(XRCID("wxcp_about"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxCrafterPlugin::OnAbout), |
| 243 |
NULL, this); |
| 244 |
wxTheApp->Connect(XRCID("open_wxcp_project"), wxEVT_UPDATE_UI, |
| 245 |
wxUpdateUIEventHandler(wxCrafterPlugin::OnOpenProjectUI), NULL, this); |
| 246 |
wxTheApp->Connect(XRCID("close_wxcp_project"), wxEVT_UPDATE_UI, |
| 247 |
wxUpdateUIEventHandler(wxCrafterPlugin::OnCloseProjectUI), NULL, this); |
| 248 |
wxTheApp->Connect(XRCID("save_wxcp_project"), wxEVT_UPDATE_UI, |
| 249 |
wxUpdateUIEventHandler(wxCrafterPlugin::OnSaveProjectUI), NULL, this); |
| 250 |
wxTheApp->Connect(XRCID("wxcp_new_form"), wxEVT_COMMAND_MENU_SELECTED, |
| 251 |
wxCommandEventHandler(wxCrafterPlugin::OnNewForm), NULL, this); |
| 252 |
wxTheApp->Bind(wxEVT_MENU, &wxCrafterPlugin::OnReGenerateForProject, this, XRCID("wxcp_generate_all_project")); |
| 253 |
wxTheApp->Connect(XRCID("ID_SHOW_DESIGNER"), wxEVT_COMMAND_MENU_SELECTED, |
| 254 |
wxCommandEventHandler(wxCrafterPlugin::OnShowDesigner), NULL, (wxEvtHandler*)this); |
| 255 |
|
| 256 |
#if !STANDALONE_BUILD |
| 257 |
m_mgr->GetWorkspacePaneNotebook()->Bind(wxEVT_BOOK_PAGE_CHANGED, &wxCrafterPlugin::OnWorkspaceTabSelected, this); |
| 258 |
clKeyboardManager::Get()->AddAccelerator("ID_SHOW_DESIGNER", _("wxCrafter"), _("Show the designer"), |
| 259 |
"Ctrl-Shift-F12"); |
| 260 |
#endif |
| 261 |
} |
| 262 |
|
| 263 |
wxCrafterPlugin::~wxCrafterPlugin() |
| 264 |
{ |
| 265 |
Allocator::Release(); |
| 266 |
wxcSettings::Get().Save(); |
| 267 |
} |
| 268 |
|
| 269 |
void wxCrafterPlugin::UnPlug() |
| 270 |
{ |
| 271 |
EventNotifier::Get()->Unbind(wxEVT_PAGE_MODIFIED_UPDATE_UI, &wxCrafterPlugin::OnSaveUI, this); |
| 272 |
EventNotifier::Get()->Unbind(wxEVT_SHOW_WORKSPACE_TAB, &wxCrafterPlugin::OnToggleView, this); |
| 273 |
EventNotifier::Get()->Disconnect(wxEVT_DESIGNER_DELETED, wxCommandEventHandler(wxCrafterPlugin::OnDesignerDelete), |
| 274 |
NULL, this); |
| 275 |
EventNotifier::Get()->Disconnect(wxEVT_SHOW_WXCRAFTER_DESIGNER, |
| 276 |
wxCommandEventHandler(wxCrafterPlugin::OnShowDesigner), NULL, this); |
| 277 |
EventNotifier::Get()->Disconnect(wxEVT_INIT_DONE, wxCommandEventHandler(wxCrafterPlugin::OnInitDone), NULL, this); |
| 278 |
EventNotifier::Get()->Disconnect(wxEVT_BITMAP_CODE_GENERATION_DONE, |
| 279 |
wxCommandEventHandler(wxCrafterPlugin::OnBitmapCodeGenerationCompleted), NULL, |
| 280 |
this); |
| 281 |
EventNotifier::Get()->Disconnect(wxEVT_TREE_ITEM_FILE_ACTIVATED, clCommandEventHandler(wxCrafterPlugin::OnOpenFile), |
| 282 |
NULL, this); |
| 283 |
EventNotifier::Get()->Disconnect(wxEVT_NOTIFY_PAGE_CLOSING, wxNotifyEventHandler(wxCrafterPlugin::OnPageClosing), |
| 284 |
NULL, this); |
| 285 |
EventNotifier::Get()->Disconnect(wxEVT_CMD_WXCRAFTER_PROJECT_MODIFIED, |
| 286 |
wxCommandEventHandler(wxCrafterPlugin::OnProjectModified), NULL, this); |
| 287 |
EventNotifier::Get()->Disconnect(wxEVT_CMD_WXCRAFTER_PROJECT_SYNCHED, |
| 288 |
wxCommandEventHandler(wxCrafterPlugin::OnProjectSynched), NULL, this); |
| 289 |
EventNotifier::Get()->Disconnect(wxEVT_CMD_PAGE_CHANGED, wxCommandEventHandler(wxCrafterPlugin::OnPageChanged), |
| 290 |
NULL, this); |
| 291 |
EventNotifier::Get()->Disconnect(wxEVT_PREVIEW_CTRL_SELECTED, |
| 292 |
wxCommandEventHandler(wxCrafterPlugin::OnDesignerItemSelected), NULL, this); |
| 293 |
EventNotifier::Get()->Unbind(wxEVT_WORKSPACE_CLOSED, &wxCrafterPlugin::OnWorkspaceClosed, this); |
| 294 |
EventNotifier::Get()->Disconnect(wxEVT_BUILD_STARTING, wxCommandEventHandler(wxCrafterPlugin::OnBuildStarting), |
| 295 |
NULL, this); |
| 296 |
EventNotifier::Get()->Disconnect(wxEVT_ALL_EDITORS_CLOSING, |
| 297 |
wxCommandEventHandler(wxCrafterPlugin::OnAllEditorsClosing), NULL, this); |
| 298 |
EventNotifier::Get()->Disconnect(wxEVT_ALL_EDITORS_CLOSED, |
| 299 |
wxCommandEventHandler(wxCrafterPlugin::OnAllEditorsClosed), NULL, this); |
| 300 |
EventNotifier::Get()->Disconnect(XRCID("save_file"), wxCommandEventHandler(wxCrafterPlugin::OnSave), NULL, this); |
| 301 |
EventNotifier::Get()->Disconnect(wxEVT_SAVE_ALL_EDITORS, clCommandEventHandler(wxCrafterPlugin::OnSaveAll), NULL, |
| 302 |
this); |
| 303 |
EventNotifier::Get()->Disconnect(wxEVT_WXGUI_PROJECT_LOADED, |
| 304 |
wxCommandEventHandler(wxCrafterPlugin::OnProjectLoaded), NULL, this); |
| 305 |
|
| 306 |
EventNotifier::Get()->Unbind(wxEVT_CONTEXT_MENU_FILE, &wxCrafterPlugin::OnFileContextMenu, this); |
| 307 |
EventNotifier::Get()->Unbind(wxEVT_CONTEXT_MENU_VIRTUAL_FOLDER, &wxCrafterPlugin::OnVirtualFolderContextMenu, this); |
| 308 |
EventNotifier::Get()->Unbind(wxEVT_CONTEXT_MENU_PROJECT, &wxCrafterPlugin::OnProjectContextMenu, this); |
| 309 |
|
| 310 |
// Menu events |
| 311 |
wxTheApp->Disconnect(XRCID("open_wxcp_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 312 |
wxCommandEventHandler(wxCrafterPlugin::OnOpenProject), NULL, this); |
| 313 |
wxTheApp->Disconnect(XRCID("close_wxcp_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 314 |
wxCommandEventHandler(wxCrafterPlugin::OnCloseProject), NULL, this); |
| 315 |
wxTheApp->Disconnect(XRCID("save_wxcp_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 316 |
wxCommandEventHandler(wxCrafterPlugin::OnSaveProject), NULL, this); |
| 317 |
wxTheApp->Disconnect(XRCID("import_wxFB_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 318 |
wxCommandEventHandler(wxCrafterPlugin::OnImportwxFBProject), NULL, this); |
| 319 |
wxTheApp->Disconnect(XRCID("import_wxSmith_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 320 |
wxCommandEventHandler(wxCrafterPlugin::OnImportwxSmith), NULL, this); |
| 321 |
wxTheApp->Disconnect(XRCID("import_XRC_project"), wxEVT_COMMAND_MENU_SELECTED, |
| 322 |
wxCommandEventHandler(wxCrafterPlugin::OnImportXRC), NULL, this); |
| 323 |
wxTheApp->Disconnect(XRCID("define_custom_controls"), wxEVT_COMMAND_MENU_SELECTED, |
| 324 |
wxCommandEventHandler(wxCrafterPlugin::OnDefineCustomControls), NULL, this); |
| 325 |
wxTheApp->Disconnect(XRCID("edit_custom_controls"), wxEVT_COMMAND_MENU_SELECTED, |
| 326 |
wxCommandEventHandler(wxCrafterPlugin::OnEditCustomControls), NULL, this); |
| 327 |
wxTheApp->Disconnect(XRCID("delete_custom_controls"), wxEVT_COMMAND_MENU_SELECTED, |
| 328 |
wxCommandEventHandler(wxCrafterPlugin::OnDeleteCustomControls), NULL, this); |
| 329 |
// Connect the events to us |
| 330 |
wxTheApp->Disconnect(XRCID("ID_SHOW_DESIGNER"), wxEVT_COMMAND_MENU_SELECTED, |
| 331 |
wxCommandEventHandler(wxCrafterPlugin::OnShowDesigner), NULL, (wxEvtHandler*)this); |
| 332 |
|
| 333 |
wxTheApp->Disconnect(XRCID("open_wxcp_project"), wxEVT_UPDATE_UI, |
| 334 |
wxUpdateUIEventHandler(wxCrafterPlugin::OnOpenProjectUI), NULL, this); |
| 335 |
wxTheApp->Disconnect(XRCID("close_wxcp_project"), wxEVT_UPDATE_UI, |
| 336 |
wxUpdateUIEventHandler(wxCrafterPlugin::OnCloseProjectUI), NULL, this); |
| 337 |
wxTheApp->Disconnect(XRCID("save_wxcp_project"), wxEVT_UPDATE_UI, |
| 338 |
wxUpdateUIEventHandler(wxCrafterPlugin::OnSaveProjectUI), NULL, this); |
| 339 |
#if !STANDALONE_BUILD |
| 340 |
m_mgr->GetWorkspacePaneNotebook()->Unbind(wxEVT_BOOK_PAGE_CHANGED, &wxCrafterPlugin::OnWorkspaceTabSelected, this); |
| 341 |
#endif |
| 342 |
wxTheApp->Disconnect(XRCID("wxcp_new_form"), wxEVT_COMMAND_MENU_SELECTED, |
| 343 |
wxCommandEventHandler(wxCrafterPlugin::OnNewForm), NULL, this); |
| 344 |
|
| 345 |
// before this plugin is un-plugged we must remove the tab we added |
| 346 |
if(IsTabMode()) { |
| 347 |
|
| 348 |
#if !STANDALONE_BUILD |
| 349 |
for(size_t i = 0; i < m_mgr->GetWorkspacePaneNotebook()->GetPageCount(); i++) { |
| 350 |
if(m_treeView == m_mgr->GetWorkspacePaneNotebook()->GetPage(i)) { |
| 351 |
m_mgr->GetWorkspacePaneNotebook()->RemovePage(i); |
| 352 |
break; |
| 353 |
} |
| 354 |
} |
| 355 |
m_treeView->Destroy(); |
| 356 |
#endif |
| 357 |
|
| 358 |
} else { |
| 359 |
m_mainFrame->Destroy(); |
| 360 |
m_treeView = NULL; |
| 361 |
} |
| 362 |
|
| 363 |
wxXmlResource::Get()->ClearHandlers(); |
| 364 |
// Why is wxModule::CleanUpModules(); commented out? |
| 365 |
// We comment this or m_mainFrame->Destroy(); will crash (it destroys wxPG class which relies on a |
| 366 |
// wxModule::Register) |
| 367 |
// We can: |
| 368 |
// 1. use wxDELETE(m_mainFrame) and uncomment the line below |
| 369 |
// 2. use m_mainFrame->Destroy() and comment the line below |
| 370 |
// we choose the second option |
| 371 |
// wxModule::CleanUpModules(); |
| 372 |
} |
| 373 |
|
| 374 |
void wxCrafterPlugin::CreateToolBar(clToolBarGeneric* toolbar) { wxUnusedVar(toolbar); } |
| 375 |
|
| 376 |
void wxCrafterPlugin::CreatePluginMenu(wxMenu* pluginsMenu) |
| 377 |
{ |
| 378 |
wxUnusedVar(pluginsMenu); |
| 379 |
wxMenu* menu = new wxMenu(); |
| 380 |
menu->Append(XRCID("open_wxcp_project"), _("Open wxCrafter project...")); |
| 381 |
menu->Append(XRCID("close_wxcp_project"), _("Close wxCrafter project")); |
| 382 |
menu->Append(XRCID("save_wxcp_project"), _("Save project")); |
| 383 |
menu->AppendSeparator(); |
| 384 |
menu->Append(XRCID("import_wxFB_project"), _("Import a wxFormBuilder project")); |
| 385 |
menu->Append(XRCID("import_wxSmith_project"), _("Import a wxSmith file")); |
| 386 |
menu->Append(XRCID("import_XRC_project"), _("Import from XRC")); |
| 387 |
menu->AppendSeparator(); |
| 388 |
menu->Append(XRCID("define_custom_controls"), _("Define custom control...")); |
| 389 |
menu->Append(XRCID("edit_custom_controls"), _("Edit custom controls...")); |
| 390 |
menu->Append(XRCID("delete_custom_controls"), _("Delete custom control...")); |
| 391 |
menu->AppendSeparator(); |
| 392 |
menu->Append(XRCID("ID_SHOW_DESIGNER"), _("Show the designer"), _("Show the designer")); |
| 393 |
menu->AppendSeparator(); |
| 394 |
#if STANDALONE_BUILD |
| 395 |
menu->Append(XRCID("wxcp_about"), _("About...")); |
| 396 |
#endif |
| 397 |
menu->Append(XRCID("wxc_settings"), _("Settings...")); |
| 398 |
pluginsMenu->Append(wxID_ANY, _("wxCrafter"), menu); |
| 399 |
} |
| 400 |
|
| 401 |
void wxCrafterPlugin::OnInitDone(wxCommandEvent& e) |
| 402 |
{ |
| 403 |
e.Skip(); |
| 404 |
DoInitDone(NULL); |
| 405 |
} |
| 406 |
|
| 407 |
void wxCrafterPlugin::OnShowDesigner(wxCommandEvent& e) { DoShowDesigner(); } |
| 408 |
|
| 409 |
void wxCrafterPlugin::OnDesignerDelete(wxCommandEvent& e) |
| 410 |
{ |
| 411 |
e.Skip(); |
| 412 |
m_mainPanel = NULL; |
| 413 |
} |
| 414 |
|
| 415 |
void wxCrafterPlugin::OnPageClosing(wxNotifyEvent& e) |
| 416 |
{ |
| 417 |
if(!IsTabMode()) { |
| 418 |
e.Skip(); |
| 419 |
return; |
| 420 |
} |
| 421 |
|
| 422 |
wxWindow* win = reinterpret_cast<wxWindow*>(e.GetClientData()); |
| 423 |
if(win && win == m_mainPanel) { |
| 424 |
if(wxcEditManager::Get().IsDirty()) { |
| 425 |
|
| 426 |
wxString msg; |
| 427 |
msg << _("wxCrafter project is modified\nDo you want to save your changes?"); |
| 428 |
|
| 429 |
int rc = ::wxMessageBox(msg, _("wxCrafter"), wxYES_NO | wxCANCEL | wxCENTER); |
| 430 |
switch(rc) { |
| 431 |
case wxYES: { |
| 432 |
m_treeView->CloseProject(true); |
| 433 |
e.Skip(); |
| 434 |
break; |
| 435 |
} |
| 436 |
case wxNO: |
| 437 |
m_treeView->CloseProject(false); |
| 438 |
e.Skip(); |
| 439 |
break; |
| 440 |
|
| 441 |
case wxCANCEL: |
| 442 |
e.Veto(); |
| 443 |
break; |
| 444 |
} |
| 445 |
} else { |
| 446 |
m_treeView->CloseProject(false); |
| 447 |
} |
| 448 |
|
| 449 |
} else { |
| 450 |
e.Skip(); |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
void wxCrafterPlugin::OnBitmapCodeGenerationCompleted(wxCommandEvent& e) |
| 455 |
{ |
| 456 |
if(wxcProjectMetadata::Get().GetGenerateCPPCode()) { |
| 457 |
// First, notify codelite to reload all modified files that are opened (so codelite will not prompt us about |
| 458 |
// them) |
| 459 |
wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, wxEVT_CMD_RELOAD_EXTERNALLY_MODIFIED_NOPROMPT); |
| 460 |
EventNotifier::Get()->TopFrame()->GetEventHandler()->AddPendingEvent(evt); |
| 461 |
|
| 462 |
// Next, compile a list of all generated files and add them to codelite |
| 463 |
wxFileName bitmapSourceFile(e.GetString()); |
| 464 |
wxCrafter::MakeAbsToProject(bitmapSourceFile); |
| 465 |
|
| 466 |
// Base header/cpp |
| 467 |
wxFileName headerFile = wxcProjectMetadata::Get().BaseHeaderFile(); |
| 468 |
wxCrafter::MakeAbsToProject(headerFile); |
| 469 |
|
| 470 |
wxFileName sourceFile = wxcProjectMetadata::Get().BaseCppFile(); |
| 471 |
wxCrafter::MakeAbsToProject(sourceFile); |
| 472 |
|
| 473 |
// And the derived classes |
| 474 |
wxFileName derivedHeader = wxcProjectMetadata::Get().GetGeneratedHeader(); |
| 475 |
wxCrafter::MakeAbsToProject(derivedHeader); |
| 476 |
|
| 477 |
wxFileName derivedSource = wxcProjectMetadata::Get().GetGeneratedSource(); |
| 478 |
wxCrafter::MakeAbsToProject(derivedSource); |
| 479 |
|
| 480 |
// XRC file |
| 481 |
wxFileName xrcFile; |
| 482 |
if(wxcProjectMetadata::Get().GetGenerateXRC()) { |
| 483 |
xrcFile = wxcProjectMetadata::Get().GetXrcFileName(); |
| 484 |
wxCrafter::MakeAbsToProject(xrcFile); |
| 485 |
} |
| 486 |
|
| 487 |
// Notify codelite to retagg the workspace |
| 488 |
std::vector<wxFileName> filesToRetag; |
| 489 |
filesToRetag.push_back(headerFile); |
| 490 |
filesToRetag.push_back(sourceFile); |
| 491 |
filesToRetag.push_back(derivedHeader); |
| 492 |
filesToRetag.push_back(derivedSource); |
| 493 |
filesToRetag.push_back(bitmapSourceFile); |
| 494 |
|
| 495 |
// Prepare a list of additional files generated by wxC (this can happen for custom model for wxDataViewCtrl) |
| 496 |
wxArrayString additionalFiles; |
| 497 |
const wxStringMap_t& af = wxcProjectMetadata::Get().GetAdditionalFiles(); |
| 498 |
wxStringMap_t::const_iterator itr = af.begin(); |
| 499 |
for(; itr != af.end(); ++itr) { |
| 500 |
wxFileName f(wxcProjectMetadata::Get().GetGeneratedHeader()); |
| 501 |
f.SetFullName(itr->first); |
| 502 |
wxCrafter::MakeAbsToProject(f); |
| 503 |
additionalFiles.Add(f.GetFullPath()); |
| 504 |
filesToRetag.push_back(f); |
| 505 |
} |
| 506 |
|
| 507 |
m_generatedClassInfo.Clear(); |
| 508 |
m_generatedClassInfo.classname = wxcProjectMetadata::Get().GetGeneratedClassName(); |
| 509 |
m_generatedClassInfo.derivedHeader = derivedHeader; |
| 510 |
m_generatedClassInfo.derivedSource = derivedSource; |
| 511 |
|
| 512 |
#if !STANDALONE_BUILD |
| 513 |
wxArrayString filesToAdd; |
| 514 |
std::set<wxString> uniqueFiles; |
| 515 |
wxString sourceFilesVD; |
| 516 |
if(clCxxWorkspaceST::Get()->IsOpen()) { |
| 517 |
wxString vd = wxcProjectMetadata::Get().GetVirtualFolder(); |
| 518 |
|
| 519 |
wxString projectName; |
| 520 |
vd.Trim().Trim(false); |
| 521 |
if(vd.IsEmpty()) { |
| 522 |
// We got no Virtual Folder to place the files to |
| 523 |
// Search for resource file |
| 524 |
wxFileName projectFile(wxcProjectMetadata::Get().GetProjectFile()); |
| 525 |
projectName = m_mgr->GetProjectNameByFile(projectFile.GetFullPath()); |
| 526 |
|
| 527 |
} else { |
| 528 |
projectName = vd.BeforeFirst(':'); |
| 529 |
} |
| 530 |
|
| 531 |
projectName.Trim().Trim(false); |
| 532 |
if(projectName.IsEmpty()) { |
| 533 |
return; |
| 534 |
} |
| 535 |
|
| 536 |
wxString errMsg; |
| 537 |
ProjectPtr project = clCxxWorkspaceST::Get()->FindProjectByName(projectName, errMsg); |
| 538 |
|
| 539 |
if(!project) { |
| 540 |
wxString msg; |
| 541 |
msg << _("Could not find target project: '") << projectName << _("'\n"); |
| 542 |
msg << _("Make sure that the virtual folder entry is valid (it must exist)\n"); |
| 543 |
msg << _("Virtual Folder provided was: '") << vd << _("'"); |
| 544 |
::wxMessageBox(msg, _("wxCrafter"), wxOK | wxICON_ERROR); |
| 545 |
return; |
| 546 |
} |
| 547 |
|
| 548 |
std::vector<wxFileName> projectFiles; |
| 549 |
project->GetFilesAsVectorOfFileName(projectFiles); |
| 550 |
uniqueFiles = wxCrafter::VectorToSet(projectFiles); |
| 551 |
|
| 552 |
wxString baseFilesVD, bitmapFilesVD, xrcVD; |
| 553 |
sourceFilesVD << wxcProjectMetadata::Get().GetVirtualFolder(); |
| 554 |
sourceFilesVD.Trim().Trim(false); |
| 555 |
|
| 556 |
if(sourceFilesVD.IsEmpty()) { |
| 557 |
sourceFilesVD << projectName << ":src"; |
| 558 |
} |
| 559 |
|
| 560 |
baseFilesVD << projectName << ":wxcrafter:base"; |
| 561 |
bitmapFilesVD << projectName << ":wxcrafter:resources"; |
| 562 |
xrcVD << projectName << ":wxcrafter:XRC"; |
| 563 |
|
| 564 |
////////////////////////////////////////////////////////////// |
| 565 |
// Add the bitmap resource files |
| 566 |
////////////////////////////////////////////////////////////// |
| 567 |
if(uniqueFiles.find(bitmapSourceFile.GetFullPath()) == uniqueFiles.end()) { |
| 568 |
filesToAdd.Add(bitmapSourceFile.GetFullPath()); |
| 569 |
} |
| 570 |
|
| 571 |
if(filesToAdd.IsEmpty() == false) { |
| 572 |
DoCreateVirtualFolder(bitmapFilesVD); |
| 573 |
m_mgr->AddFilesToVirtualFolder(bitmapFilesVD, filesToAdd); |
| 574 |
} |
| 575 |
|
| 576 |
////////////////////////////////////////////////////////////// |
| 577 |
// Add the XRC files |
| 578 |
////////////////////////////////////////////////////////////// |
| 579 |
filesToAdd.Clear(); |
| 580 |
if(xrcFile.IsOk() && uniqueFiles.find(xrcFile.GetFullPath()) == uniqueFiles.end()) { |
| 581 |
filesToAdd.Add(xrcFile.GetFullPath()); |
| 582 |
} |
| 583 |
|
| 584 |
if(filesToAdd.IsEmpty() == false) { |
| 585 |
DoCreateVirtualFolder(xrcVD); |
| 586 |
m_mgr->AddFilesToVirtualFolder(xrcVD, filesToAdd); |
| 587 |
} |
| 588 |
|
| 589 |
////////////////////////////////////////////////////////////// |
| 590 |
// Add the base classes files |
| 591 |
////////////////////////////////////////////////////////////// |
| 592 |
filesToAdd.Clear(); |
| 593 |
if(uniqueFiles.find(headerFile.GetFullPath()) == uniqueFiles.end()) { |
| 594 |
filesToAdd.Add(headerFile.GetFullPath()); |
| 595 |
} |
| 596 |
if(uniqueFiles.find(sourceFile.GetFullPath()) == uniqueFiles.end()) { |
| 597 |
filesToAdd.Add(sourceFile.GetFullPath()); |
| 598 |
} |
| 599 |
|
| 600 |
// The additional files are added to the 'base' |
| 601 |
for(size_t i = 0; i < additionalFiles.GetCount(); ++i) { |
| 602 |
if(uniqueFiles.find(additionalFiles.Item(i)) == uniqueFiles.end()) { |
| 603 |
filesToAdd.Add(additionalFiles.Item(i)); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
if(filesToAdd.IsEmpty() == false) { |
| 608 |
DoCreateVirtualFolder(baseFilesVD); |
| 609 |
m_mgr->AddFilesToVirtualFolder(baseFilesVD, filesToAdd); |
| 610 |
} |
| 611 |
} |
| 612 |
#endif |
| 613 |
|
| 614 |
////////////////////////////////////////////////////////////// |
| 615 |
// Add the derived classes files |
| 616 |
////////////////////////////////////////////////////////////// |
| 617 |
|
| 618 |
// Not all top level windows wants subclassing.. |
| 619 |
if(derivedHeader.IsOk() && !derivedHeader.GetName().IsEmpty()) { |
| 620 |
#if !STANDALONE_BUILD |
| 621 |
if(clCxxWorkspaceST::Get()->IsOpen()) { |
| 622 |
filesToAdd.Clear(); |
| 623 |
if(uniqueFiles.find(derivedHeader.GetFullPath()) == uniqueFiles.end()) { |
| 624 |
filesToAdd.Add(derivedHeader.GetFullPath()); |
| 625 |
} |
| 626 |
|
| 627 |
if(uniqueFiles.find(derivedSource.GetFullPath()) == uniqueFiles.end()) { |
| 628 |
filesToAdd.Add(derivedSource.GetFullPath()); |
| 629 |
} |
| 630 |
|
| 631 |
if(filesToAdd.IsEmpty() == false) { |
| 632 |
DoCreateVirtualFolder(sourceFilesVD); |
| 633 |
m_mgr->AddFilesToVirtualFolder(sourceFilesVD, filesToAdd); |
| 634 |
} |
| 635 |
} |
| 636 |
#endif |
| 637 |
DoUpdateDerivedClassEventHandlers(); |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
wxString msg; |
| 642 |
msg << _("wxCrafter: code generation completed successfully!"); |
| 643 |
wxCrafter::SetStatusMessage(msg); |
| 644 |
|
| 645 |
// Restart ctagsd |
| 646 |
clLanguageServerEvent restart_event{ wxEVT_LSP_RESTART }; |
| 647 |
restart_event.SetLspName("ctagsd"); |
| 648 |
EventNotifier::Get()->ProcessEvent(restart_event); |
| 649 |
} |
| 650 |
|
| 651 |
wxMenu* wxCrafterPlugin::DoCreateFolderMenu() |
| 652 |
{ |
| 653 |
// Create the popup menu for the file explorer |
| 654 |
// The only menu that we are interseted is the file explorer menu |
| 655 |
wxMenu* menu = new wxMenu(); |
| 656 |
wxMenuItem* item(NULL); |
| 657 |
|
| 658 |
wxCrafter::ResourceLoader bmps; |
| 659 |
item = new wxMenuItem(menu, XRCID("wxcp_new_form"), _("Add wxWidgets UI Form..."), wxEmptyString, wxITEM_NORMAL); |
| 660 |
item->SetBitmap(bmps.Bitmap("new-form")); |
| 661 |
menu->Append(item); |
| 662 |
|
| 663 |
return menu; |
| 664 |
} |
| 665 |
|
| 666 |
void wxCrafterPlugin::OnNewForm(wxCommandEvent& e) |
| 667 |
{ |
| 668 |
int type = e.GetInt(); |
| 669 |
|
| 670 |
#if STANDALONE_BUILD |
| 671 |
if(!wxcProjectMetadata::Get().IsLoaded()) { |
| 672 |
::wxMessageBox(_("You must create a project before you can add new forms"), _("wxCrafter"), |
| 673 |
wxOK | wxCENTER | wxICON_WARNING); |
| 674 |
return; |
| 675 |
} |
| 676 |
#endif |
| 677 |
|
| 678 |
// Check to see if we already got a wxCrafter.wxcp file |
| 679 |
NewFormWizard wizard(wxCrafter::TopFrame(), m_mgr, type); |
| 680 |
if(wizard.RunWizard(wizard.GetFirstPage())) { |
| 681 |
NewFormDetails details = wizard.GetFormDetails(); |
| 682 |
DoGenerateCode(details); |
| 683 |
|
| 684 |
wxString label("new "); |
| 685 |
switch(type) { |
| 686 |
case ID_WXDIALOG: |
| 687 |
label << "dialog"; |
| 688 |
break; |
| 689 |
case ID_WXFRAME: |
| 690 |
label << "frame"; |
| 691 |
break; |
| 692 |
case ID_WXWIZARD: |
| 693 |
label << "wizard"; |
| 694 |
break; |
| 695 |
case ID_WXPANEL_TOPLEVEL: |
| 696 |
label << "panel"; |
| 697 |
break; |
| 698 |
case ID_WXPOPUPWINDOW: |
| 699 |
label << "popup window"; |
| 700 |
break; |
| 701 |
case ID_WXIMAGELIST: |
| 702 |
label << "image list"; |
| 703 |
break; |
| 704 |
default: |
| 705 |
label << "top-level item"; |
| 706 |
} |
| 707 |
wxcEditManager::Get().PushState(label); |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
void wxCrafterPlugin::DoGenerateCode(const NewFormDetails& fd) |
| 712 |
{ |
| 713 |
wxCrafter::ResourceLoader rl; |
| 714 |
wxString errMsg; |
| 715 |
|
| 716 |
wxFileName wxcpFile = wxFileName(fd.wxcpFile); |
| 717 |
if(!wxcpFile.FileExists()) { |
| 718 |
wxFFile fp(wxcpFile.GetFullPath(), "w+b"); |
| 719 |
if(fp.IsOpened()) { |
| 720 |
fp.Close(); |
| 721 |
|
| 722 |
} else { |
| 723 |
wxString msg; |
| 724 |
msg << _("Could not create resource file '") << wxcpFile.GetFullPath() << "'"; |
| 725 |
::wxMessageBox(msg, _("wxCrafter"), wxOK | wxICON_WARNING | wxCENTRE); |
| 726 |
return; |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
#if !STANDALONE_BUILD |
| 731 |
// If we have a workspace opened, handle the virtual folder thing here |
| 732 |
if(clCxxWorkspaceST::Get()->IsOpen()) { |
| 733 |
// Step 1: |
| 734 |
// Check if we already got a virtual folder named 'wxcrafter' |
| 735 |
wxString projectName = fd.virtualFolder.BeforeFirst(':'); |
| 736 |
ProjectPtr project = clCxxWorkspaceST::Get()->FindProjectByName(projectName, errMsg); |
| 737 |
if(!project) { |
| 738 |
::wxMessageBox(errMsg, _("wxCrafter"), wxOK | wxICON_WARNING | wxCENTRE); |
| 739 |
return; |
| 740 |
} |
| 741 |
|
| 742 |
wxString vdFullPath; |
| 743 |
vdFullPath << projectName; |
| 744 |
|
| 745 |
// Check if already got a file with this name in the project |
| 746 |
wxStringSet_t files; |
| 747 |
wxCrafter::GetProjectFiles(project->GetName(), files); |
| 748 |
|
| 749 |
if(!files.count(wxcpFile.GetFullPath())) { |
| 750 |
|
| 751 |
if(!m_mgr->CreateVirtualDirectory(vdFullPath, "wxcrafter")) { |
| 752 |
::wxMessageBox(_("Could not create virtual folder 'wxcrafter'"), _("wxCrafter"), |
| 753 |
wxOK | wxICON_WARNING | wxCENTRE); |
| 754 |
return; |
| 755 |
} |
| 756 |
|
| 757 |
// Add the resource file to the newly created virtual folder |
| 758 |
wxArrayString f; |
| 759 |
f.Add(wxcpFile.GetFullPath()); |
| 760 |
vdFullPath << ":" |
| 761 |
<< "wxcrafter"; |
| 762 |
m_mgr->AddFilesToVirtualFolder(vdFullPath, f); |
| 763 |
} |
| 764 |
} |
| 765 |
#endif |
| 766 |
|
| 767 |
// At this point, wxcpFile contains the fullpath the |
| 768 |
// wxCrafter project, load it |
| 769 |
DoShowDesigner(); |
| 770 |
m_treeView->LoadProject(wxcpFile.GetFullPath()); |
| 771 |
m_treeView->AddForm(fd); |
| 772 |
|
| 773 |
// Notify about file system changes here |
| 774 |
clFileSystemEvent eventFilesGenerate(wxEVT_FILE_CREATED); |
| 775 |
eventFilesGenerate.GetPaths().Add(wxcpFile.GetFullPath()); |
| 776 |
EventNotifier::Get()->QueueEvent(eventFilesGenerate.Clone()); |
| 777 |
|
| 778 |
// And finally, select the wxCrafter tab in the 'Workspace' view |
| 779 |
if(IsTabMode()) { |
| 780 |
DoSelectWorkspaceTab(); |
| 781 |
|
| 782 |
} else { |
| 783 |
wxCommandEvent evtShowDesigner(wxEVT_SHOW_WXCRAFTER_DESIGNER); |
| 784 |
EventNotifier::Get()->ProcessEvent(evtShowDesigner); |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
bool wxCrafterPlugin::DoShowDesigner(bool createIfNotExist) |
| 789 |
{ |
| 790 |
if(!m_mgr) { |
| 791 |
return false; |
| 792 |
} |
| 793 |
|
| 794 |
m_mainFrame->DisplayDesigner(); |
| 795 |
return false; |
| 796 |
} |
| 797 |
|
| 798 |
bool wxCrafterPlugin::DoCreateVirtualFolder(const wxString& vdFullPath) |
| 799 |
{ |
| 800 |
CHECK_POINTER_RET_FALSE(m_mgr); |
| 801 |
wxString name = vdFullPath.AfterLast(':'); |
| 802 |
wxString parent = vdFullPath.BeforeLast(':'); |
| 803 |
return m_mgr->CreateVirtualDirectory(parent, name); |
| 804 |
} |
| 805 |
|
| 806 |
void wxCrafterPlugin::OnOpenFile(clCommandEvent& e) |
| 807 |
{ |
| 808 |
e.Skip(); |
| 809 |
wxFileName fullpath(e.GetFileName()); |
| 810 |
if(fullpath.GetExt() == "wxcp") { |
| 811 |
e.Skip(false); |
| 812 |
DoLoadWxcProject(fullpath); |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
void wxCrafterPlugin::DoSelectWorkspaceTab() |
| 817 |
{ |
| 818 |
|
| 819 |
CHECK_POINTER(m_mgr); |
| 820 |
if(IsTabMode()) { |
| 821 |
// And finally, select the wxCrafter tab in the 'Workspace' view |
| 822 |
Notebook* book = m_mgr->GetWorkspacePaneNotebook(); |
| 823 |
for(size_t i = 0; i < book->GetPageCount(); i++) { |
| 824 |
if(book->GetPage(i) == m_treeView) { |
| 825 |
book->SetSelection(i); |
| 826 |
break; |
| 827 |
} |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
void wxCrafterPlugin::OnProjectModified(wxCommandEvent& e) |
| 833 |
{ |
| 834 |
e.Skip(); |
| 835 |
CHECK_POINTER(m_mainPanel); |
| 836 |
CHECK_POINTER(m_mgr); |
| 837 |
|
| 838 |
wxString title = m_mgr->GetPageTitle(m_mainPanel); |
| 839 |
if(!title.StartsWith("*")) { |
| 840 |
title.Prepend("*"); |
| 841 |
m_mgr->SetPageTitle(m_mainPanel, title); |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
void wxCrafterPlugin::OnProjectSynched(wxCommandEvent& e) |
| 846 |
{ |
| 847 |
e.Skip(); |
| 848 |
CHECK_POINTER(m_mainPanel); |
| 849 |
CHECK_POINTER(m_mgr); |
| 850 |
|
| 851 |
wxString title = m_mgr->GetPageTitle(m_mainPanel); |
| 852 |
if(title.StartsWith("*")) { |
| 853 |
title.Remove(0, 1); |
| 854 |
m_mgr->SetPageTitle(m_mainPanel, title); |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
void wxCrafterPlugin::OnPageChanged(wxCommandEvent& e) |
| 859 |
{ |
| 860 |
e.Skip(); |
| 861 |
if(!m_allEditorsClosing) { |
| 862 |
wxWindow* win = reinterpret_cast<wxWindow*>(e.GetClientData()); |
| 863 |
if(win && (win == m_mainPanel)) { |
| 864 |
DoSelectWorkspaceTab(); |
| 865 |
if(wxcProjectMetadata::Get().IsLoaded()) { |
| 866 |
CallAfter(&wxCrafterPlugin::UpdateFileNameInStatusBar); |
| 867 |
} |
| 868 |
} |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
void wxCrafterPlugin::UpdateFileNameInStatusBar() {} |
| 873 |
|
| 874 |
void wxCrafterPlugin::OnWorkspaceTabSelected(wxBookCtrlEvent& e) |
| 875 |
{ |
| 876 |
e.Skip(); |
| 877 |
CHECK_POINTER(m_mgr); |
| 878 |
wxWindow* page = m_mgr->GetWorkspacePaneNotebook()->GetPage(e.GetSelection()); |
| 879 |
if(page == m_treeView) { |
| 880 |
DoShowDesigner(false); |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
void wxCrafterPlugin::OnDesignerItemSelected(wxCommandEvent& e) |
| 885 |
{ |
| 886 |
e.Skip(); |
| 887 |
DoSelectWorkspaceTab(); |
| 888 |
} |
| 889 |
|
| 890 |
void wxCrafterPlugin::OnWorkspaceClosed(clWorkspaceEvent& e) |
| 891 |
{ |
| 892 |
e.Skip(); |
| 893 |
m_treeView->CloseProject(false); |
| 894 |
} |
| 895 |
|
| 896 |
void wxCrafterPlugin::DoUpdateDerivedClassEventHandlers() |
| 897 |
{ |
| 898 |
wxString headerContent, sourceContent; |
| 899 |
IEditor *headerEditor(NULL), *sourceEditor(NULL); |
| 900 |
|
| 901 |
if(!DoReadFileContentAndPrompt(m_generatedClassInfo.derivedHeader, headerContent, &headerEditor)) { |
| 902 |
return; |
| 903 |
} |
| 904 |
|
| 905 |
if(!DoReadFileContentAndPrompt(m_generatedClassInfo.derivedSource, sourceContent, &sourceEditor)) { |
| 906 |
return; |
| 907 |
} |
| 908 |
|
| 909 |
CHECK_POINTER(m_mainPanel); |
| 910 |
|
| 911 |
// Parse and collect all functions declared in the header file |
| 912 |
wxcWidget* topLevelWin = m_mainPanel->GetActiveTopLevelWin(); |
| 913 |
CHECK_POINTER(topLevelWin); |
| 914 |
|
| 915 |
wxcWidget::Map_t connectedEvents = topLevelWin->GetConnectedEventsRecrusively(); |
| 916 |
FunctionsParser parser(connectedEvents, m_generatedClassInfo.classname, headerContent); |
| 917 |
parser.Parse(); |
| 918 |
|
| 919 |
wxString decl, impl; |
| 920 |
const wxcWidget::Map_t& newEvents = parser.GetAllEvents(); |
| 921 |
if(newEvents.empty()) { |
| 922 |
return; |
| 923 |
} |
| 924 |
|
| 925 |
wxcWidget::Map_t::const_iterator iter = newEvents.begin(); |
| 926 |
for(; iter != newEvents.end(); ++iter) { |
| 927 |
impl << iter->second.GetFunctionImpl(m_generatedClassInfo.classname); |
| 928 |
decl << iter->second.GetFunctionDecl(); |
| 929 |
} |
| 930 |
|
| 931 |
// Insert the functions declarations |
| 932 |
if(TagsManagerST::Get()->InsertFunctionDecl(m_generatedClassInfo.classname, decl, headerContent, 1)) { |
| 933 |
if(wxcSettings::Get().HasFlag(wxcSettings::FORMAT_INHERITED_FILES)) { |
| 934 |
// Format the string |
| 935 |
wxCrafter::FormatString(headerContent, m_generatedClassInfo.derivedHeader); |
| 936 |
} |
| 937 |
|
| 938 |
// Write the resulting string |
| 939 |
DoWriteFileContent(m_generatedClassInfo.derivedHeader, headerContent, headerEditor); |
| 940 |
wxCrafter::NotifyFileSaved(m_generatedClassInfo.derivedHeader); |
| 941 |
} |
| 942 |
|
| 943 |
// Insert the functions definitions at the end of the file buffer |
| 944 |
if(!sourceContent.EndsWith("\n")) { |
| 945 |
sourceContent << "\n"; |
| 946 |
} |
| 947 |
sourceContent << impl; |
| 948 |
|
| 949 |
// Format the source file |
| 950 |
if(wxcSettings::Get().HasFlag(wxcSettings::FORMAT_INHERITED_FILES)) { |
| 951 |
wxCrafter::FormatString(headerContent, m_generatedClassInfo.derivedSource); |
| 952 |
} |
| 953 |
|
| 954 |
DoWriteFileContent(m_generatedClassInfo.derivedSource, sourceContent, sourceEditor); |
| 955 |
wxCrafter::NotifyFileSaved(m_generatedClassInfo.derivedSource); |
| 956 |
} |
| 957 |
|
| 958 |
bool wxCrafterPlugin::DoReadFileContentAndPrompt(const wxFileName& fn, wxString& content, IEditor** editor) |
| 959 |
{ |
| 960 |
*editor = NULL; |
| 961 |
|
| 962 |
// Check to see if we got the file opened in the editor |
| 963 |
if(m_mgr) { |
| 964 |
*editor = m_mgr->FindEditor(fn.GetFullPath()); |
| 965 |
if(*editor) { |
| 966 |
content = (*editor)->GetTextRange(0, (*editor)->GetLength()); |
| 967 |
return true; |
| 968 |
} |
| 969 |
} |
| 970 |
|
| 971 |
// Read the header file content from the disk |
| 972 |
if(!wxCrafter::ReadFileContent(fn.GetFullPath(), content)) { |
| 973 |
wxString msg; |
| 974 |
msg << _("Error while reading file content: '") << fn.GetFullPath() << _("'.\n") |
| 975 |
<< _("Could not read file content"); |
| 976 |
::wxMessageBox(msg, _("wxCrafter"), wxICON_WARNING | wxOK | wxCENTER, EventNotifier::Get()->TopFrame()); |
| 977 |
return false; |
| 978 |
} |
| 979 |
return true; |
| 980 |
} |
| 981 |
|
| 982 |
void wxCrafterPlugin::OnBuildStarting(wxCommandEvent& e) |
| 983 |
{ |
| 984 |
e.Skip(); // Important... |
| 985 |
} |
| 986 |
|
| 987 |
void wxCrafterPlugin::OnAllEditorsClosing(wxCommandEvent& e) |
| 988 |
{ |
| 989 |
e.Skip(); |
| 990 |
if(IsTabMode()) { |
| 991 |
m_allEditorsClosing = true; |
| 992 |
m_treeView->CloseProject(true); |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
void wxCrafterPlugin::OnAllEditorsClosed(wxCommandEvent& e) |
| 997 |
{ |
| 998 |
e.Skip(); |
| 999 |
if(IsTabMode()) { |
| 1000 |
m_allEditorsClosing = false; |
| 1001 |
} |
| 1002 |
} |
| 1003 |
|
| 1004 |
void wxCrafterPlugin::OnDebugStarting(clDebugEvent& e) |
| 1005 |
{ |
| 1006 |
if(!m_mainPanel) { |
| 1007 |
e.Skip(); |
| 1008 |
return; |
| 1009 |
} |
| 1010 |
|
| 1011 |
if(!m_mgr) { |
| 1012 |
e.Skip(); |
| 1013 |
return; |
| 1014 |
} |
| 1015 |
|
| 1016 |
if(IsTabMode() && m_mgr->GetActivePage() == m_mainPanel) { |
| 1017 |
|
| 1018 |
// Show the preview instead |
| 1019 |
wxCommandEvent showPreviewEvent(wxEVT_COMMAND_MENU_SELECTED, ID_SHOW_PREVIEW); |
| 1020 |
m_mainPanel->GetEventHandler()->ProcessEvent(showPreviewEvent); |
| 1021 |
|
| 1022 |
} else { |
| 1023 |
e.Skip(); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
|
| 1027 |
void wxCrafterPlugin::DoWriteFileContent(const wxFileName& fn, const wxString& content, IEditor* editor) |
| 1028 |
{ |
| 1029 |
if(editor) { |
| 1030 |
editor->GetCtrl()->SetText(content); |
| 1031 |
|
| 1032 |
} else { |
| 1033 |
|
| 1034 |
// Write the file content from the disk |
| 1035 |
wxCrafter::WriteFile(fn, content, true); |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
void wxCrafterPlugin::OnSave(wxCommandEvent& e) |
| 1040 |
{ |
| 1041 |
CHECK_POINTER(m_mgr); |
| 1042 |
if(IsTabMode() && m_mainPanel && m_mgr->GetActivePage() == m_mainPanel) { |
| 1043 |
m_treeView->SaveProject(); |
| 1044 |
|
| 1045 |
} else { |
| 1046 |
e.Skip(); |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
bool wxCrafterPlugin::IsMainViewActive() |
| 1051 |
{ |
| 1052 |
return true; // IIUC this function was protecting against outside events being caught when in Tabbed mode and a |
| 1053 |
// different tab was active |
| 1054 |
if(!m_mgr) { |
| 1055 |
return true; |
| 1056 |
} else { |
| 1057 |
return IsTabMode() && m_mainPanel && m_mgr->GetActivePage() == m_mainPanel; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
// plugin menu |
| 1062 |
void wxCrafterPlugin::OnCloseProject(wxCommandEvent& e) |
| 1063 |
{ |
| 1064 |
CHECK_POINTER(m_mgr); |
| 1065 |
wxUnusedVar(e); |
| 1066 |
if(IsTabMode()) { |
| 1067 |
m_mgr->ClosePage(_("[wxCrafter]")); |
| 1068 |
} |
| 1069 |
// m_treeView->CloseProject(true); |
| 1070 |
} |
| 1071 |
|
| 1072 |
void wxCrafterPlugin::OnCloseProjectUI(wxUpdateUIEvent& e) { e.Enable(wxcProjectMetadata::Get().IsLoaded()); } |
| 1073 |
|
| 1074 |
void wxCrafterPlugin::OnOpenProject(wxCommandEvent& e) |
| 1075 |
{ |
| 1076 |
wxUnusedVar(e); |
| 1077 |
m_treeView->LoadProject(wxFileName()); |
| 1078 |
} |
| 1079 |
|
| 1080 |
void wxCrafterPlugin::OnOpenProjectUI(wxUpdateUIEvent& e) { e.Enable(wxcProjectMetadata::Get().IsLoaded() == false); } |
| 1081 |
|
| 1082 |
void wxCrafterPlugin::OnSaveProject(wxCommandEvent& e) |
| 1083 |
{ |
| 1084 |
wxUnusedVar(e); |
| 1085 |
m_treeView->SaveProject(); |
| 1086 |
} |
| 1087 |
|
| 1088 |
void wxCrafterPlugin::OnSaveProjectUI(wxUpdateUIEvent& e) { e.Enable(wxcEditManager::Get().IsDirty()); } |
| 1089 |
|
| 1090 |
void wxCrafterPlugin::DoLoadAfterImport(ImportDlg::ImportFileData& data) |
| 1091 |
{ |
| 1092 |
if(m_mgr && data.addToProject && !data.virtualFolder.IsEmpty()) { |
| 1093 |
wxArrayString filesToAdd; |
| 1094 |
filesToAdd.Add(data.wxcpFilename.GetFullPath()); |
| 1095 |
if(DoCreateVirtualFolder(data.virtualFolder)) { |
| 1096 |
m_mgr->AddFilesToVirtualFolder(data.virtualFolder, filesToAdd); |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
if(data.loadWhenDone) { |
| 1101 |
m_treeView->LoadProject(data.wxcpFilename); |
| 1102 |
} |
| 1103 |
|
| 1104 |
// do it using event, orelse the main framw will steal the focus |
| 1105 |
wxCommandEvent evtShowDesigner(wxEVT_SHOW_WXCRAFTER_DESIGNER); |
| 1106 |
EventNotifier::Get()->AddPendingEvent(evtShowDesigner); |
| 1107 |
} |
| 1108 |
|
| 1109 |
void wxCrafterPlugin::OnImportwxFBProject(wxCommandEvent& e) |
| 1110 |
{ |
| 1111 |
wxUnusedVar(e); |
| 1112 |
DoImportFB(); |
| 1113 |
} |
| 1114 |
|
| 1115 |
void wxCrafterPlugin::OnImportXRC(wxCommandEvent& e) |
| 1116 |
{ |
| 1117 |
ImportDlg::ImportFileData data; |
| 1118 |
ImportFromXrc import(wxCrafter::TopFrame()); |
| 1119 |
if(import.ImportProject(data)) { |
| 1120 |
DoLoadAfterImport(data); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
void wxCrafterPlugin::OnImportwxSmith(wxCommandEvent& e) |
| 1125 |
{ |
| 1126 |
ImportDlg::ImportFileData data; |
| 1127 |
ImportFromwxSmith import(wxCrafter::TopFrame()); |
| 1128 |
if(import.ImportProject(data)) { |
| 1129 |
DoLoadAfterImport(data); |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
void wxCrafterPlugin::OnDefineCustomControls(wxCommandEvent& e) |
| 1134 |
{ |
| 1135 |
DefineCustomControlWizard wiz(NULL); |
| 1136 |
if(wiz.RunWizard(wiz.GetFirstPage())) { |
| 1137 |
CustomControlTemplate controlData = wiz.GetControl(); |
| 1138 |
wxcSettings::Get().RegisterCustomControl(controlData); |
| 1139 |
wxcSettings::Get().Save(); |
| 1140 |
} |
| 1141 |
} |
| 1142 |
void wxCrafterPlugin::OnEditCustomControls(wxCommandEvent& e) |
| 1143 |
{ |
| 1144 |
EditCustomControlDlg dlg(NULL); |
| 1145 |
dlg.ShowModal(); |
| 1146 |
|
| 1147 |
// Once this dialog is saved, we should: |
| 1148 |
// 1) Refresh the view |
| 1149 |
wxCommandEvent evt(wxEVT_PROPERTIES_MODIFIED); |
| 1150 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 1151 |
} |
| 1152 |
|
| 1153 |
void wxCrafterPlugin::OnDeleteCustomControls(wxCommandEvent& e) |
| 1154 |
{ |
| 1155 |
DeleteCustomControlDlg dlg(NULL); |
| 1156 |
dlg.ShowModal(); |
| 1157 |
|
| 1158 |
// Once this dialog is saved, we should: |
| 1159 |
// 1) Refresh the view |
| 1160 |
wxCommandEvent evt(wxEVT_PROPERTIES_MODIFIED); |
| 1161 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 1162 |
} |
| 1163 |
|
| 1164 |
void wxCrafterPlugin::OnAbout(wxCommandEvent& e) |
| 1165 |
{ |
| 1166 |
wxcAboutDlg dlg(NULL); |
| 1167 |
dlg.ShowModal(); |
| 1168 |
} |
| 1169 |
|
| 1170 |
void wxCrafterPlugin::DoImportFB(const wxString& filename) |
| 1171 |
{ |
| 1172 |
ImportDlg::ImportFileData data; |
| 1173 |
ImportFromwxFB import(wxCrafter::TopFrame()); |
| 1174 |
if(import.ImportProject(data, filename)) { |
| 1175 |
DoLoadAfterImport(data); |
| 1176 |
} |
| 1177 |
} |
| 1178 |
void wxCrafterPlugin::OnSettings(wxCommandEvent& e) |
| 1179 |
{ |
| 1180 |
wxcSettingsDlg dlg(NULL); |
| 1181 |
dlg.ShowModal(); |
| 1182 |
|
| 1183 |
if(dlg.IsRestartRequired()) { |
| 1184 |
::wxMessageBox(_("In order for the change to take place, you need to restart codelite"), _("wxCrafter")); |
| 1185 |
} |
| 1186 |
} |
| 1187 |
|
| 1188 |
void wxCrafterPlugin::DoInitDone(wxObject* obj) |
| 1189 |
{ |
| 1190 |
wxUnusedVar(obj); |
| 1191 |
#if !STANDALONE_BUILD |
| 1192 |
wxToolBar* mainToolbar = EventNotifier::Get()->TopFrame()->GetToolBar(); |
| 1193 |
if(mainToolbar) { |
| 1194 |
int toolHeight = mainToolbar->GetToolBitmapSize().GetHeight(); |
| 1195 |
|
| 1196 |
wxCrafter::ResourceLoader rl; |
| 1197 |
wxBitmap bmp = rl.Bitmap(toolHeight == 24 ? "wxc-logo-24" : "wxc-logo-16"); |
| 1198 |
wxTheApp->Connect(XRCID("ID_SHOW_DESIGNER"), wxEVT_COMMAND_MENU_SELECTED, |
| 1199 |
wxCommandEventHandler(wxCrafterPlugin::OnShowDesigner), NULL, (wxEvtHandler*)this); |
| 1200 |
} |
| 1201 |
|
| 1202 |
#endif |
| 1203 |
|
| 1204 |
#if STANDALONE_BUILD |
| 1205 |
/// explicitly load the lexers |
| 1206 |
ColoursAndFontsManager::Get().Load(); |
| 1207 |
#endif |
| 1208 |
|
| 1209 |
m_mainFrame = new MainFrame(nullptr, m_serverMode); |
| 1210 |
|
| 1211 |
m_treeView = new wxcTreeView(m_mainFrame->GetTreeParent(), this); |
| 1212 |
m_mainFrame->Add(m_treeView); |
| 1213 |
|
| 1214 |
m_mainPanel = new GUICraftMainPanel(m_mainFrame->GetDesignerParent(), this, m_treeView->GetTree()); |
| 1215 |
m_mainFrame->Add(m_mainPanel); |
| 1216 |
m_mainFrame->Layout(); |
| 1217 |
wxCrafter::SetTopFrame(m_mainFrame); |
| 1218 |
} |
| 1219 |
|
| 1220 |
void wxCrafterPlugin::OnProjectLoaded(wxCommandEvent& e) { e.Skip(); } |
| 1221 |
|
| 1222 |
void wxCrafterPlugin::OnSaveAll(clCommandEvent& e) |
| 1223 |
{ |
| 1224 |
e.Skip(); |
| 1225 |
if(wxcProjectMetadata::Get().IsLoaded()) { |
| 1226 |
m_treeView->SaveProject(); |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
void wxCrafterPlugin::OnFileContextMenu(clContextMenuEvent& event) |
| 1231 |
{ |
| 1232 |
event.Skip(); |
| 1233 |
const wxArrayString& files = event.GetStrings(); |
| 1234 |
if(files.GetCount() == 1) { |
| 1235 |
m_selectedFile = files.Item(0); |
| 1236 |
if(m_selectedFile.GetExt() == "wxcp") { |
| 1237 |
// a wxCrafter file |
| 1238 |
event.GetMenu()->PrependSeparator(); |
| 1239 |
event.GetMenu()->Prepend(new wxMenuItem(event.GetMenu(), XRCID("open_wxC_project_from_context_menu"), |
| 1240 |
_("Open with wxCrafter..."), wxEmptyString, wxITEM_NORMAL)); |
| 1241 |
event.GetMenu()->Bind(wxEVT_COMMAND_MENU_SELECTED, &wxCrafterPlugin::OnOpenWxcpProject, this, |
| 1242 |
XRCID("open_wxC_project_from_context_menu")); |
| 1243 |
} else if(m_selectedFile.GetExt() == "fbp") { |
| 1244 |
// form builder file |
| 1245 |
event.GetMenu()->PrependSeparator(); |
| 1246 |
event.GetMenu()->Prepend(new wxMenuItem(event.GetMenu(), XRCID("import_wxFB_project_from_context_menu"), |
| 1247 |
_("Import with wxCrafter..."), wxEmptyString, wxITEM_NORMAL)); |
| 1248 |
event.GetMenu()->Bind(wxEVT_COMMAND_MENU_SELECTED, &wxCrafterPlugin::OnImportFBProject, this, |
| 1249 |
XRCID("import_wxFB_project_from_context_menu")); |
| 1250 |
} else if(m_selectedFile.GetExt() == "wxs") { |
| 1251 |
event.GetMenu()->PrependSeparator(); |
| 1252 |
event.GetMenu()->Prepend(new wxMenuItem(event.GetMenu(), XRCID("import_wxSmith_project"), |
| 1253 |
_("Import with wxCrafter..."), wxEmptyString, wxITEM_NORMAL)); |
| 1254 |
event.GetMenu()->Bind(wxEVT_COMMAND_MENU_SELECTED, &wxCrafterPlugin::OnImportwxSmithProject, this, |
| 1255 |
XRCID("import_wxSmith_project")); |
| 1256 |
} |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
void wxCrafterPlugin::OnImportFBProject(wxCommandEvent& event) { DoImportFB(m_selectedFile.GetFullPath()); } |
| 1261 |
void wxCrafterPlugin::OnOpenWxcpProject(wxCommandEvent& event) { DoLoadWxcProject(m_selectedFile); } |
| 1262 |
|
| 1263 |
void wxCrafterPlugin::DoLoadWxcProject(const wxFileName& filename) |
| 1264 |
{ |
| 1265 |
DoShowDesigner(); |
| 1266 |
m_treeView->LoadProject(filename); |
| 1267 |
DoSelectWorkspaceTab(); |
| 1268 |
|
| 1269 |
if(!IsTabMode()) { |
| 1270 |
wxCommandEvent evtShowDesigner(wxEVT_COMMAND_MENU_SELECTED, XRCID("ID_SHOW_DESIGNER")); |
| 1271 |
m_mainFrame->GetEventHandler()->AddPendingEvent(evtShowDesigner); |
| 1272 |
} |
| 1273 |
} |
| 1274 |
|
| 1275 |
void wxCrafterPlugin::OnImportwxSmithProject(wxCommandEvent& event) |
| 1276 |
{ |
| 1277 |
ImportDlg::ImportFileData data; |
| 1278 |
ImportFromwxSmith import(wxCrafter::TopFrame()); |
| 1279 |
if(import.ImportProject(data, m_selectedFile.GetFullPath())) { |
| 1280 |
DoLoadAfterImport(data); |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
void wxCrafterPlugin::OnVirtualFolderContextMenu(clContextMenuEvent& event) |
| 1285 |
{ |
| 1286 |
event.Skip(); |
| 1287 |
event.GetMenu()->AppendSeparator(); |
| 1288 |
event.GetMenu()->Append(wxID_ANY, "wxCrafter", DoCreateFolderMenu()); |
| 1289 |
} |
| 1290 |
|
| 1291 |
wxMenu* wxCrafterPlugin::DoProjectMenu() |
| 1292 |
{ |
| 1293 |
wxMenu* menu = new wxMenu(); |
| 1294 |
menu->Append(XRCID("wxcp_generate_all_project"), _("Re-generate code for project")); |
| 1295 |
return menu; |
| 1296 |
} |
| 1297 |
|
| 1298 |
void wxCrafterPlugin::OnProjectContextMenu(clContextMenuEvent& event) |
| 1299 |
{ |
| 1300 |
event.Skip(); |
| 1301 |
event.GetMenu()->Append(wxID_ANY, "wxCrafter", DoProjectMenu()); |
| 1302 |
} |
| 1303 |
|
| 1304 |
void wxCrafterPlugin::OnReGenerateForProject(wxCommandEvent& e) |
| 1305 |
{ |
| 1306 |
wxArrayString wxcpFiles; |
| 1307 |
if(clGetManager()->GetWorkspace() && clGetManager()->GetWorkspace()->IsOpen()) { |
| 1308 |
wxStringSet_t all_files; |
| 1309 |
wxArrayString projects; |
| 1310 |
ProjectPtr activeProject = clGetManager()->GetSelectedProject(); |
| 1311 |
if(!activeProject) { |
| 1312 |
return; |
| 1313 |
} |
| 1314 |
wxCrafter::GetProjectFiles(activeProject->GetName(), all_files); |
| 1315 |
|
| 1316 |
// Filter out and keep only wxcp files |
| 1317 |
std::for_each(all_files.begin(), all_files.end(), [&](const wxString& file) { |
| 1318 |
if(FileExtManager::GetType(file) == FileExtManager::TypeWxCrafter) { |
| 1319 |
wxcpFiles.Add(file); |
| 1320 |
} |
| 1321 |
}); |
| 1322 |
|
| 1323 |
if(wxcpFiles.IsEmpty()) { |
| 1324 |
::wxMessageBox(_("This project does not contain any wxCrafter files"), "wxCrafter"); |
| 1325 |
return; |
| 1326 |
} |
| 1327 |
|
| 1328 |
// Ensure that we have a designer |
| 1329 |
if(DoShowDesigner()) {} |
| 1330 |
|
| 1331 |
// Now generate the code |
| 1332 |
m_mainPanel->BatchGenerate(wxcpFiles); |
| 1333 |
} |
| 1334 |
} |
| 1335 |
|
| 1336 |
void wxCrafterPlugin::OnToggleView(clCommandEvent& event) |
| 1337 |
{ |
| 1338 |
if(event.GetString() != _("wxCrafter")) { |
| 1339 |
event.Skip(); |
| 1340 |
return; |
| 1341 |
} |
| 1342 |
#if 0 |
| 1343 |
if(event.IsSelected()) { |
| 1344 |
// show it |
| 1345 |
wxcImages images; |
| 1346 |
m_mgr->GetWorkspacePaneNotebook()->AddPage(m_treeView, _("wxCrafter"), false, images.Bitmap("wxc_icon")); |
| 1347 |
} else { |
| 1348 |
int where = m_mgr->GetWorkspacePaneNotebook()->GetPageIndex(_("wxCrafter")); |
| 1349 |
if(where != wxNOT_FOUND) { |
| 1350 |
m_mgr->GetWorkspacePaneNotebook()->RemovePage(where); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
#endif |
| 1354 |
} |
| 1355 |
|
| 1356 |
void wxCrafterPlugin::OnSaveUI(clCommandEvent& event) |
| 1357 |
{ |
| 1358 |
event.Skip(); |
| 1359 |
wxWindow* win = (wxWindow*)event.GetClientData(); |
| 1360 |
if(win == m_mainPanel) { |
| 1361 |
event.Skip(false); |
| 1362 |
event.SetAnswer(wxcEditManager::Get().IsDirty()); |
| 1363 |
} |
| 1364 |
} |