1 /*
2 * This file is part of wxSmith plugin for Code::Blocks Studio
3 * Copyright (C) 2006-2007 Bartlomiej Swiecki
4 *
5 * wxSmith is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * wxSmith is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * $Revision: 7109 $
19 * $Id: wxsguifactory.cpp 7109 2011-04-15 11:53:16Z mortenmacfly $
20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/wxSmith/wxsguifactory.cpp $
21 */
22
23 #include "wxsguifactory.h"
24 #include "wxsgui.h"
25
26 #include <logmanager.h>
27 #include <wx/choicdlg.h>
28
wxsGUIFactory(const wxString & Name)29 wxsGUIFactory::wxsGUIFactory(const wxString& Name): m_Name(Name)
30 {
31 // Registering this gui in new hash
32 GetHash()[m_Name] = this;
33 }
34
~wxsGUIFactory()35 wxsGUIFactory::~wxsGUIFactory()
36 {
37 // Assuming that factories are available
38 // during all wxSmith work time, it's not
39 // necessarry to remove any bindings
40 }
41
Build(const wxString & Name,wxsProject * Project)42 wxsGUI* wxsGUIFactory::Build(const wxString& Name,wxsProject* Project)
43 {
44 if ( GetHash().find(Name) == GetHash().end() ) return 0;
45 wxsGUIFactory* Factory = GetHash()[Name];
46 wxsGUI* NewGUI = Factory->OnCreate(Project);
47 if ( NewGUI->GetName() != Name )
48 {
49 // Some hack? Bug in factory?
50 Manager::Get()->GetLogManager()->DebugLog(_T("wxSmith: Error while creating wxsGUI object (name mismatch)."));
51 Manager::Get()->GetLogManager()->DebugLog(_T("wxSmith: Looks like bug in one wf wxsGUIFactory-derived classes or"));
52 Manager::Get()->GetLogManager()->DebugLog(_T("wxSmith: some hack attempt."));
53 delete NewGUI;
54 return 0;
55 }
56 return NewGUI;
57 }
58
SelectNew(const wxString & Message,wxsProject * Project)59 wxsGUI* wxsGUIFactory::SelectNew(const wxString& Message,wxsProject* Project)
60 {
61 if ( GetHash().empty() )
62 {
63 return 0;
64 }
65 if ( GetHash().size() == 1 )
66 {
67 return Build(GetHash().begin()->first,Project);
68 }
69
70 wxArrayString GUIList;
71 for ( GUIItemHashT::iterator i = GetHash().begin(); i!=GetHash().end(); ++i )
72 {
73 GUIList.Add(i->first);
74 }
75
76 wxString SelectedGUI = ::wxGetSingleChoice(Message,_("Select GUI"), GUIList);
77 if ( SelectedGUI.empty() )
78 {
79 return 0;
80 }
81
82 return Build(SelectedGUI,Project);
83 }
84
GetHash()85 inline wxsGUIFactory::GUIItemHashT& wxsGUIFactory::GetHash()
86 {
87 static GUIItemHashT Hash;
88 return Hash;
89 }
90