| 1 | /* i4ucaddfiledialogview.vala |
|---|
| 2 | * |
|---|
| 3 | * Copyright (C) 2010 Matias De la Puente |
|---|
| 4 | * |
|---|
| 5 | * This program 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 | * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | * |
|---|
| 18 | * Author: |
|---|
| 19 | * Matias De la Puente <mfpuente.ar@gmail.com> |
|---|
| 20 | */ |
|---|
| 21 | using Gtk; |
|---|
| 22 | using Gee; |
|---|
| 23 | |
|---|
| 24 | public class I4uc.AddFileDialogView : Gtk.Dialog, AddFileDialogViewIface |
|---|
| 25 | { |
|---|
| 26 | private InfoBar _file_in_project_info_bar = new InfoBar (); |
|---|
| 27 | private RadioButton _new_file_radio = new RadioButton.with_label (null, _("New file:")); |
|---|
| 28 | private Entry _new_file_entry = new Entry (); |
|---|
| 29 | private RadioButton _import_file_radio; |
|---|
| 30 | private FileChooserButton _import_file_chooser = new FileChooserButton (_("Select file to import to current project"), FileChooserAction.OPEN); |
|---|
| 31 | private ProfilesCheckList _profiles_check_list = new ProfilesCheckList (); |
|---|
| 32 | private Button _accept_button; |
|---|
| 33 | |
|---|
| 34 | public bool is_new { get { return _new_file_radio.active; } } |
|---|
| 35 | |
|---|
| 36 | public string filename |
|---|
| 37 | { |
|---|
| 38 | owned get |
|---|
| 39 | { |
|---|
| 40 | if (this.is_new) |
|---|
| 41 | return _new_file_entry.text; |
|---|
| 42 | return _import_file_chooser.get_uri (); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public string folder_uri |
|---|
| 47 | { |
|---|
| 48 | set { _import_file_chooser.set_current_folder_uri (value); } |
|---|
| 49 | owned get { return _import_file_chooser.get_current_folder_uri (); } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | public Gee.List<string> activated_profiles { owned get { return _profiles_check_list.activated_profiles; } } |
|---|
| 53 | |
|---|
| 54 | public bool file_in_project_visible |
|---|
| 55 | { |
|---|
| 56 | set { _file_in_project_info_bar.visible = value; } |
|---|
| 57 | get { return _file_in_project_info_bar.visible; } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | public bool new_file_sensitive |
|---|
| 61 | { |
|---|
| 62 | set { _new_file_entry.sensitive = value; } |
|---|
| 63 | get { return _new_file_entry.sensitive; } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | public bool import_file_sensitive |
|---|
| 67 | { |
|---|
| 68 | set { _import_file_chooser.sensitive = value; } |
|---|
| 69 | get { return _import_file_chooser.sensitive; } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | public bool accept_sensitive |
|---|
| 73 | { |
|---|
| 74 | set { _accept_button.sensitive = value; } |
|---|
| 75 | get { return _accept_button.sensitive; } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | public AddFileDialogView () |
|---|
| 79 | { |
|---|
| 80 | this.title = _("Add file to project"); |
|---|
| 81 | |
|---|
| 82 | var info_bar_content = _file_in_project_info_bar.get_content_area () as Container; |
|---|
| 83 | info_bar_content.add (new Label (_("The file is already added to the project"))); |
|---|
| 84 | this.vbox.pack_start (_file_in_project_info_bar, false, false, 5); |
|---|
| 85 | |
|---|
| 86 | var hbox = new HBox (false, 0); |
|---|
| 87 | hbox.pack_start (_new_file_radio, false, false, 5); |
|---|
| 88 | hbox.pack_start (_new_file_entry, true, true, 5); |
|---|
| 89 | this.vbox.pack_start (hbox, true, true, 5); |
|---|
| 90 | |
|---|
| 91 | _import_file_radio = new RadioButton.with_label_from_widget (_new_file_radio, _("Import file:")); |
|---|
| 92 | _import_file_chooser.sensitive = false; |
|---|
| 93 | |
|---|
| 94 | hbox = new HBox (false, 0); |
|---|
| 95 | hbox.pack_start (_import_file_radio, false, false, 5); |
|---|
| 96 | hbox.pack_start (_import_file_chooser, true, true, 5); |
|---|
| 97 | this.vbox.pack_start (hbox, true, true, 5); |
|---|
| 98 | |
|---|
| 99 | this.vbox.pack_start (new Label (_("Add file to profile:")), false, false, 5); |
|---|
| 100 | this.vbox.pack_start (_profiles_check_list, true, true, 5); |
|---|
| 101 | |
|---|
| 102 | add_button (STOCK_CANCEL, ResponseType.CANCEL); |
|---|
| 103 | _accept_button = add_button (STOCK_OK, ResponseType.OK) as Button; |
|---|
| 104 | set_default_response (ResponseType.OK); |
|---|
| 105 | this.vbox.show_all (); |
|---|
| 106 | |
|---|
| 107 | _new_file_radio.toggled.connect (() => this.is_new_changed ()); |
|---|
| 108 | _new_file_entry.changed.connect (() => this.new_file_changed ()); |
|---|
| 109 | _import_file_chooser.file_set.connect (() => this.import_file_changed ()); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | public void add_profiles (Collection<string> profiles) |
|---|
| 113 | { |
|---|
| 114 | foreach (var profile in profiles) |
|---|
| 115 | _profiles_check_list.add_profile (profile, false); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | public int show_yes_no_message (string message, bool cancel) |
|---|
| 119 | { |
|---|
| 120 | var dialog = new MessageDialog (null, DialogFlags.MODAL, MessageType.WARNING, ButtonsType.NONE, message); |
|---|
| 121 | if (cancel) |
|---|
| 122 | dialog.add_button (STOCK_CANCEL, ResponseType.CANCEL); |
|---|
| 123 | dialog.add_button (STOCK_NO, ResponseType.NO); |
|---|
| 124 | dialog.add_button (STOCK_YES, ResponseType.YES); |
|---|
| 125 | dialog.set_default_response (ResponseType.YES); |
|---|
| 126 | var response = dialog.run (); |
|---|
| 127 | dialog.destroy (); |
|---|
| 128 | return response; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | public void close_dialog () |
|---|
| 132 | { |
|---|
| 133 | close (); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|