19
19
private SearchRow? my_row = null;
21
public SearchRowContainer(SearchCondition.SearchType starting_type = 0) {
21
public SearchRowContainer() {
23
set_type(SearchCondition.SearchType.ANY_TEXT);
26
public SearchRowContainer.edit_existing(SearchCondition sc) {
28
set_type(sc.search_type);
29
type_combo.set_active(sc.search_type);
33
// Creates the GUI for this row.
34
private void setup_gui() {
22
35
// Ordering must correspond with SearchCondition.SearchType
23
36
type_combo = new Gtk.ComboBox.text();
24
37
type_combo.append_text(_("Any text"));
29
42
type_combo.append_text(_("Media type"));
30
43
type_combo.append_text(_("Flag state"));
31
44
type_combo.append_text(_("Rating"));
32
type_combo.set_active(starting_type); // Sets default.
45
type_combo.set_active(0); // Sets default.
33
46
type_combo.changed.connect(on_type_changed);
35
48
remove_button = new Gtk.Button();
36
remove_button.set_label(" - ");
49
remove_button.set_label(" – ");
37
50
remove_button.button_press_event.connect(on_removed);
39
52
align = new Gtk.Alignment(0,0,0,0);
44
57
box.pack_start(new Gtk.Alignment(0,0,0,0), true, true, 0); // Fill space.
45
58
box.pack_start(remove_button, false, false, 0);
48
set_type(SearchCondition.SearchType.ANY_TEXT);
51
62
private void on_type_changed() {
110
121
// Represents a row-type.
111
122
private abstract class SearchRow {
123
// Returns the GUI widget for this row.
112
124
public abstract Gtk.Widget get_widget();
126
// Returns the search condition for this row.
113
127
public abstract SearchCondition get_search_condition();
129
// Fills out the fields in this row based on an existing search condition (for edit mode.)
130
public abstract void populate(SearchCondition sc);
116
133
private class SearchRowText : SearchRow {
154
171
SearchConditionText c = new SearchConditionText(type, text, context);
175
public override void populate(SearchCondition sc) {
176
SearchConditionText? text = sc as SearchConditionText;
177
assert(text != null);
178
text_context.set_active(text.context);
179
entry.set_text(text.text);
159
183
private class SearchRowMediaType : SearchRow {
196
220
SearchConditionMediaType c = new SearchConditionMediaType(search_type, context, type);
224
public override void populate(SearchCondition sc) {
225
SearchConditionMediaType? media = sc as SearchConditionMediaType;
226
assert(media != null);
227
media_context.set_active(media.context);
228
media_type.set_active(media.media_type);
201
232
private class SearchRowFlagged : SearchRow {
229
260
SearchConditionFlagged c = new SearchConditionFlagged(search_type, state);
264
public override void populate(SearchCondition sc) {
265
SearchConditionFlagged? f = sc as SearchConditionFlagged;
267
flagged_state.set_active(f.state);
234
271
private class SearchRowRating : SearchRow {
276
313
SearchConditionRating c = new SearchConditionRating(search_type, search_rating, search_context);
317
public override void populate(SearchCondition sc) {
318
SearchConditionRating? r = sc as SearchConditionRating;
320
context.set_active(r.context);
321
rating.set_active(r.rating - Rating.REJECTED);
281
325
private Gtk.Builder builder;
285
329
private Gtk.VBox row_box;
286
330
private Gtk.Entry search_title;
287
331
private Gee.ArrayList<SearchRowContainer> row_list = new Gee.ArrayList<SearchRowContainer>();
332
private bool edit_mode = false;
333
private SavedSearch? previous_search = null;
289
335
public SavedSearchDialog() {
338
// Default is text search.
340
row_list.get(0).allow_removal(false);
342
// Add buttons for new search.
343
Gtk.Button ok_button = new Gtk.Button.from_stock(Gtk.Stock.OK);
344
ok_button.can_default = true;
345
dialog.add_action_widget(ok_button, Gtk.ResponseType.OK);
346
dialog.add_action_widget(new Gtk.Button.from_stock(Gtk.Stock.CANCEL), Gtk.ResponseType.CANCEL);
347
dialog.set_default_response(Gtk.ResponseType.OK);
352
public SavedSearchDialog.edit_existing(SavedSearch saved_search) {
353
previous_search = saved_search;
357
// Load existing search into dialog.
358
operator.set_active((SearchOperator) saved_search.get_operator());
359
search_title.set_text(saved_search.get_name());
360
foreach (SearchCondition sc in saved_search.get_conditions()) {
361
add_row(new SearchRowContainer.edit_existing(sc));
364
if (row_list.size == 1)
365
row_list.get(0).allow_removal(false);
368
Gtk.Button close_button = new Gtk.Button.from_stock(Gtk.Stock.CLOSE);
369
close_button.can_default = true;
370
dialog.add_action_widget(close_button, Gtk.ResponseType.OK);
371
dialog.set_default_response(Gtk.ResponseType.OK);
376
// Builds the dialog UI. Doesn't add buttons to the dialog or call dialog.show_all().
377
private void setup_dialog() {
290
378
builder = AppWindow.create_builder();
292
380
dialog = builder.get_object("Search criteria") as Gtk.Dialog;
303
391
row_box = builder.get_object("row_box") as Gtk.VBox;
306
row_list.get(0).allow_removal(false);
308
393
operator = builder.get_object("Type of search criteria") as Gtk.ComboBox;
309
394
gtk_combo_box_set_as_text(operator);
310
395
operator.append_text(_("any"));
311
396
operator.append_text(_("all"));
312
397
operator.append_text(_("none"));
313
398
operator.set_active(0);
315
// Add buttons for new search.
316
Gtk.Button ok_button = new Gtk.Button.from_stock(Gtk.Stock.OK);
317
ok_button.can_default = true;
318
dialog.add_action_widget(ok_button, Gtk.ResponseType.OK);
319
dialog.add_action_widget(new Gtk.Button.from_stock(Gtk.Stock.CANCEL), Gtk.ResponseType.CANCEL);
320
dialog.set_default_response(Gtk.ResponseType.OK);
325
public SavedSearchDialog.edit_existing(SavedSearch saved_search) {
329
401
// Displays the dialog.
364
436
private void on_response(int response_id) {
365
437
if (response_id == Gtk.ResponseType.OK) {
366
if (SavedSearchTable.get_instance().exists(search_title.get_text())) {
438
if (SavedSearchTable.get_instance().exists(search_title.get_text()) &&
439
!(edit_mode && previous_search.get_name() == search_title.get_text())) {
367
440
AppWindow.error_message(Resources.rename_search_exists_message(search_title.get_text()));
445
// Remove previous search.
446
SavedSearchTable.get_instance().remove(previous_search);
371
449
// Build the condition list from the search rows, and add our new saved search to the table.
372
450
Gee.ArrayList<SearchCondition> conditions = new Gee.ArrayList<SearchCondition>();
373
451
foreach (SearchRowContainer c in row_list) {