1 #include "filezilla.h"
2 #include "conditionaldialog.h"
3 #include "dialogex.h"
4 #include "filezillaapp.h"
5 #include "wrapengine.h"
6 #include "Options.h"
7
BEGIN_EVENT_TABLE(CConditionalDialog,wxDialog)8 BEGIN_EVENT_TABLE(CConditionalDialog, wxDialog)
9 EVT_BUTTON(wxID_ANY, CConditionalDialog::OnButton)
10 END_EVENT_TABLE()
11
12 CConditionalDialog::CConditionalDialog(wxWindow* parent, DialogType type, Modes mode, bool checked)
13 : wxDialog(parent, wxID_ANY, wxString(), wxDefaultPosition), m_type(type)
14 {
15 DialogLayout layout(this);
16
17 wxSizer* pVertSizer = new wxBoxSizer(wxVERTICAL);
18
19 wxSizer* pMainSizer = new wxBoxSizer(wxHORIZONTAL);
20 pVertSizer->Add(pMainSizer);
21
22 pMainSizer->AddSpacer(5);
23 wxSizer* pSizer = new wxBoxSizer(wxVERTICAL);
24 pMainSizer->Add(pSizer, 0, wxALL, 5);
25 m_pTextSizer = layout.createFlex(1);
26 pSizer->Add(m_pTextSizer, 0, wxTOP, 5);
27
28 wxCheckBox *pCheckBox = new wxCheckBox(this, wxID_HIGHEST + 1, _("&Don't show this dialog again."));
29 pCheckBox->SetValue(checked);
30 pSizer->Add(pCheckBox, 0, wxTOP | wxBOTTOM, 5);
31
32 wxStdDialogButtonSizer* buttons = new wxStdDialogButtonSizer();
33 pVertSizer->Add(buttons, 0, wxGROW | wxALL, 5);
34
35 if (mode == ok) {
36 pMainSizer->Prepend(new wxStaticBitmap(this, wxID_ANY, wxArtProvider::GetBitmap(wxART_INFORMATION)), 0, wxLEFT | wxBOTTOM | wxTOP, 10);
37
38 wxButton* ok_btn = new wxButton(this, wxID_OK);
39 ok_btn->SetDefault();
40 buttons->AddButton(ok_btn);
41 SetEscapeId(wxID_OK);
42 }
43 else {
44 pMainSizer->Prepend(new wxStaticBitmap(this, wxID_ANY, wxArtProvider::GetBitmap(wxART_QUESTION)), 0, wxLEFT | wxBOTTOM | wxTOP, 10);
45
46 wxButton* yes = new wxButton(this, wxID_YES);
47 yes->SetDefault();
48 buttons->AddButton(yes);
49
50 buttons->AddButton(new wxButton(this, wxID_NO));
51 SetEscapeId(wxID_NO);
52 }
53 buttons->Realize();
54
55 SetSizer(pVertSizer);
56 }
57
Run()58 bool CConditionalDialog::Run()
59 {
60 wxString dialogs = COptions::Get()->get_string(OPTION_ONETIME_DIALOGS);
61 if (dialogs.size() > static_cast<size_t>(m_type) && dialogs[m_type] == '1') {
62 return true;
63 }
64
65 Fit();
66 wxGetApp().GetWrapEngine()->WrapRecursive(this, 3);
67
68 CenterOnParent();
69
70 int id = ShowModal();
71
72 auto cb = dynamic_cast<wxCheckBox*>(FindWindow(wxID_HIGHEST + 1));
73 if (cb && cb->GetValue()) {
74 while (dialogs.size() <= static_cast<size_t>(m_type)) {
75 dialogs += _T("0");
76 }
77 dialogs[m_type] = '1';
78 COptions::Get()->set(OPTION_ONETIME_DIALOGS, dialogs.ToStdWstring());
79 }
80
81 if (id == wxID_OK || id == wxID_YES) {
82 return true;
83 }
84
85 return false;
86 }
87
AddText(const wxString & text)88 void CConditionalDialog::AddText(const wxString& text)
89 {
90 m_pTextSizer->Add(new wxStaticText(this, wxID_ANY, text));
91 }
92
OnButton(wxCommandEvent & event)93 void CConditionalDialog::OnButton(wxCommandEvent& event)
94 {
95 EndDialog(event.GetId());
96 }
97