1 /////////////////////////////////////////////////////////////////////////////
2 // Name: NewProjectDlg.cpp
3 // Purpose: New project dialog
4 // Author: Alex Thuering
5 // Created: 23.03.2009
6 // RCS-ID: $Id: WelcomeDlg.cpp,v 1.6 2012/09/02 14:49:25 ntalex Exp $
7 // Copyright: (c) Alex Thuering
8 // Licence: GPL
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "WelcomeDlg.h"
12 #include "Config.h"
13 #include <wxVillaLib/utils.h>
14 #include <wx/artprov.h>
15 #include <wx/statbmp.h>
16 #include <wx/statline.h>
17 #include <wx/docview.h>
18
19 #ifdef __WXMSW__
20 #include "rc/new.png.h"
21 #include "rc/open.png.h"
22 #define ICON_NEW wxBITMAP_FROM_MEMORY(new)
23 #define ICON_OPEN wxBITMAP_FROM_MEMORY(open)
24 #else
25 #define ICON_NEW wxArtProvider::GetBitmap(wxART_NEW, wxART_TOOLBAR)
26 #define ICON_OPEN wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_TOOLBAR)
27 #endif
28
29 enum {
30 NEW_PROJECT_BT_ID = 2000,
31 OPEN_PROJECT_BT_ID
32 };
33
BEGIN_EVENT_TABLE(WelcomeDlg,NewProjectDlg)34 BEGIN_EVENT_TABLE(WelcomeDlg, NewProjectDlg)
35 EVT_RADIOBUTTON(NEW_PROJECT_BT_ID, WelcomeDlg::OnChooseNew)
36 EVT_RADIOBUTTON(OPEN_PROJECT_BT_ID, WelcomeDlg::OnChooseOpen)
37 EVT_CHILD_FOCUS(WelcomeDlg::OnSetFocus)
38 EVT_LISTBOX_DCLICK(wxID_ANY, WelcomeDlg::OnListBoxDClick)
39 END_EVENT_TABLE()
40
41 WelcomeDlg::WelcomeDlg(wxWindow *parent) : NewProjectDlg(parent, false) {
42 m_newProjectBt = NULL;
43 m_openProjectBt = NULL;
44 m_listBox = NULL;
45 Create(false, true);
46 SetTitle(_("Welcome"));
47 SetSize(500, -1);
48 }
49
CreatePropPanel(wxSizer * sizer)50 void WelcomeDlg::CreatePropPanel(wxSizer* sizer) {
51 // new project radio
52 AddStaticLine(sizer, _("New project"));
53 wxSizer* mainSizer = new wxBoxSizer(wxHORIZONTAL);
54 mainSizer->Add(new wxStaticBitmap(this, wxID_ANY, ICON_NEW), 0, wxLEFT|wxRIGHT|wxTOP, 8);
55 wxSizer* newPrjSizer = new wxBoxSizer(wxVERTICAL);
56 newPrjSizer->Add(8, 8);
57 AddRadioProp(newPrjSizer, _("Create a new project"), true, wxRB_GROUP, false, NEW_PROJECT_BT_ID);
58 m_newProjectBt = (wxRadioButton*) GetLastControl();
59 newPrjSizer->GetItem(newPrjSizer->GetChildren().GetCount()-1)->SetProportion(0);
60 mainSizer->Add(newPrjSizer, 1, wxEXPAND);
61 sizer->Add(mainSizer, 0, wxEXPAND);
62
63 // open project radio
64 AddStaticLine(sizer, _("Open project"));
65 mainSizer = new wxBoxSizer(wxHORIZONTAL);
66 mainSizer->Add(new wxStaticBitmap(this, wxID_ANY, ICON_OPEN), 0, wxLEFT|wxRIGHT|wxTOP, 8);
67 wxSizer* openPrjSizer = new wxBoxSizer(wxVERTICAL);
68 openPrjSizer->Add(8, 8);
69 AddRadioProp(openPrjSizer, _("Open an existing project file"), false, 0, false, OPEN_PROJECT_BT_ID);
70 m_openProjectBt = (wxRadioButton*) GetLastControl();
71 openPrjSizer->GetItem(openPrjSizer->GetChildren().GetCount()-1)->SetProportion(0);
72 mainSizer->Add(openPrjSizer, 1, wxEXPAND);
73 sizer->Add(mainSizer, 1, wxEXPAND);
74
75 // new project content
76 propIndex = GetLastControlIndex() + 1;
77 CreateDVDPropPanel(newPrjSizer, NULL);
78
79 // open project content
80 m_listBox = new wxListBox(this, wxID_ANY);
81 m_listBox->SetMinSize(wxSize(-1, 200));
82 m_listBox->Append(_("Browse files..."));
83 m_listBox->SetSelection(-1);
84 wxFileHistory history;
85 history.Load(*s_config.GetConfigBase());
86 for (int i=0; i<(int)history.GetCount(); i++)
87 if (wxFileExists(history.GetHistoryFile(i)))
88 m_listBox->Append(history.GetHistoryFile(i));
89 openPrjSizer->Add(m_listBox, 1, wxEXPAND|wxTOP, 4);
90
91 sizer->Add(new wxStaticLine(this, wxID_ANY), 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxTOP, 8);
92 }
93
SetValues()94 bool WelcomeDlg::SetValues() {
95 if (!Validate())
96 return false;
97 if (GetBool(GetLastControlIndex()))
98 s_config.SetShowWelcomeDlg(false);
99 return true;
100 }
101
OnChooseNew(wxCommandEvent & event)102 void WelcomeDlg::OnChooseNew(wxCommandEvent& event) {
103 m_listBox->SetSelection(-1);
104 }
105
OnChooseOpen(wxCommandEvent & event)106 void WelcomeDlg::OnChooseOpen(wxCommandEvent& event) {
107 if (m_listBox->GetSelection() < 0)
108 m_listBox->SetSelection(0);
109 }
110
OnSetFocus(wxChildFocusEvent & event)111 void WelcomeDlg::OnSetFocus(wxChildFocusEvent& event) {
112 if (event.GetWindow()->IsKindOf(CLASSINFO(wxListBox))) {
113 m_openProjectBt->SetValue(true);
114 } else if (event.GetWindow()->GetId() != OPEN_PROJECT_BT_ID
115 && !event.GetWindow()->IsKindOf(CLASSINFO(wxButton))
116 && !event.GetWindow()->IsKindOf(CLASSINFO(wxCheckBox))) {
117 m_newProjectBt->SetValue(true);
118 m_listBox->SetSelection(-1);
119 }
120 }
121
OnListBoxDClick(wxCommandEvent & event)122 void WelcomeDlg::OnListBoxDClick(wxCommandEvent& event) {
123 EndModal(wxID_OK);
124 }
125
IsNewProject()126 bool WelcomeDlg::IsNewProject() {
127 return GetBool(0);
128 }
129
GetOpenFilename()130 wxString WelcomeDlg::GetOpenFilename() {
131 return m_listBox->GetSelection() > 0 ? m_listBox->GetStringSelection() : wxT("");
132 }
133