1 // Copyright (c) 2006, Rodrigo Braz Monteiro
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 //   * Redistributions of source code must retain the above copyright notice,
8 //     this list of conditions and the following disclaimer.
9 //   * Redistributions in binary form must reproduce the above copyright notice,
10 //     this list of conditions and the following disclaimer in the documentation
11 //     and/or other materials provided with the distribution.
12 //   * Neither the name of the Aegisub Group nor the names of its contributors
13 //     may be used to endorse or promote products derived from this software
14 //     without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
27 //
28 // Aegisub Project http://www.aegisub.org/
29 
30 #include "help_button.h"
31 #include "options.h"
32 
33 #include <functional>
34 #include <wx/button.h>
35 #include <wx/dialog.h>
36 #include <wx/checklst.h>
37 #include <wx/sizer.h>
38 #include <wx/stattext.h>
39 
40 namespace {
41 struct DialogPasteOver {
42 	wxDialog d;
43 	wxCheckListBox *ListBox;
44 
45 	void CheckAll(bool check);
46 
47 	void OnOK(wxCommandEvent &);
48 	void OnTimes(wxCommandEvent &);
49 	void OnText(wxCommandEvent &);
50 
51 	DialogPasteOver(wxWindow *parent);
52 };
53 
DialogPasteOver(wxWindow * parent)54 DialogPasteOver::DialogPasteOver(wxWindow *parent)
55 : d(parent, -1, _("Select Fields to Paste Over"))
56 {
57 	// Label and list sizer
58 	wxSizer *ListSizer = new wxStaticBoxSizer(wxVERTICAL, &d, _("Fields"));
59 	ListSizer->Add(new wxStaticText(&d, -1, _("Please select the fields that you want to paste over:")), wxSizerFlags());
60 
61 	// List box
62 	wxArrayString choices;
63 	choices.Add(_("Comment"));
64 	choices.Add(_("Layer"));
65 	choices.Add(_("Start Time"));
66 	choices.Add(_("End Time"));
67 	choices.Add(_("Style"));
68 	choices.Add(_("Actor"));
69 	choices.Add(_("Margin Left"));
70 	choices.Add(_("Margin Right"));
71 	choices.Add(_("Margin Vertical"));
72 	choices.Add(_("Effect"));
73 	choices.Add(_("Text"));
74 	ListBox = new wxCheckListBox(&d, -1, wxDefaultPosition, wxDefaultSize, choices);
75 	ListSizer->Add(ListBox, wxSizerFlags(0).Expand().Border(wxTOP));
76 
77 	std::vector<bool> options = OPT_GET("Tool/Paste Lines Over/Fields")->GetListBool();
78 	if (options.size() != choices.size())
79 		options.resize(choices.size(), false);
80 
81 	for (size_t i = 0; i < choices.size(); ++i)
82 		ListBox->Check(i, options[i]);
83 
84 	// Top buttons
85 	wxButton *btn;
86 	wxSizer *TopButtonSizer = new wxBoxSizer(wxHORIZONTAL);
87 
88 	TopButtonSizer->Add(btn = new wxButton(&d, -1, _("&All")), wxSizerFlags(1));
89 	btn->Bind(wxEVT_BUTTON, std::bind(&DialogPasteOver::CheckAll, this, true));
90 	TopButtonSizer->Add(btn = new wxButton(&d, -1, _("&None")), wxSizerFlags(1));
91 	btn->Bind(wxEVT_BUTTON, std::bind(&DialogPasteOver::CheckAll, this, false));
92 	TopButtonSizer->Add(btn = new wxButton(&d, -1, _("&Times")), wxSizerFlags(1));
93 	btn->Bind(wxEVT_BUTTON, &DialogPasteOver::OnTimes, this);
94 	TopButtonSizer->Add(btn = new wxButton(&d, -1, _("T&ext")), wxSizerFlags(1));
95 	btn->Bind(wxEVT_BUTTON, &DialogPasteOver::OnText, this);
96 
97 	// Buttons
98 	auto ButtonSizer = d.CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
99 	d.Bind(wxEVT_BUTTON, &DialogPasteOver::OnOK, this, wxID_OK);
100 	d.Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Paste Over"), wxID_HELP);
101 
102 	// Main sizer
103 	wxSizer *MainSizer = new wxBoxSizer(wxVERTICAL);
104 	MainSizer->Add(ListSizer,0,wxEXPAND | wxLEFT | wxRIGHT,5);
105 	MainSizer->Add(TopButtonSizer,0,wxLEFT | wxRIGHT | wxEXPAND,5);
106 	MainSizer->Add(ButtonSizer,0,wxALL | wxEXPAND,5);
107 	d.SetSizerAndFit(MainSizer);
108 	d.CenterOnParent();
109 }
110 
OnOK(wxCommandEvent &)111 void DialogPasteOver::OnOK(wxCommandEvent &) {
112 	std::vector<bool> options;
113 	for (size_t i = 0; i < ListBox->GetCount(); ++i)
114 		options.push_back(ListBox->IsChecked(i));
115 	OPT_SET("Tool/Paste Lines Over/Fields")->SetListBool(std::move(options));
116 
117 	d.EndModal(wxID_OK);
118 }
119 
OnText(wxCommandEvent &)120 void DialogPasteOver::OnText(wxCommandEvent &) {
121 	CheckAll(false);
122 	ListBox->Check(10, true);
123 }
124 
OnTimes(wxCommandEvent &)125 void DialogPasteOver::OnTimes(wxCommandEvent &) {
126 	CheckAll(false);
127 	ListBox->Check(2, true);
128 	ListBox->Check(3, true);
129 }
130 
CheckAll(bool check)131 void DialogPasteOver::CheckAll(bool check) {
132 	for (size_t i = 0; i < ListBox->GetCount(); ++i)
133 		ListBox->Check(i, check);
134 }
135 }
136 
ShowPasteOverDialog(wxWindow * parent)137 bool ShowPasteOverDialog(wxWindow *parent) {
138 	return DialogPasteOver(parent).d.ShowModal() == wxID_OK;
139 }
140