Changeset 008d5c72452c9189b0f715046a34d75bb9acba88
- Timestamp:
- 22/12/10 20:19:42 (2 years ago)
- Children:
- c15395525506be7df1e1d05b82bfb04f27268ab7
- Parents:
- 15c36f68bf2989f4965aa740a6d7e33fb6fd0016
- git-committer:
- Matias De la Puente <mfpuente.ar@…> (22/12/10 20:19:42)
- Location:
- libi4uccore
- Files:
-
- 2 edited
-
addfiledialoglogic.vala (modified) (1 diff)
-
projectslogic.vala (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libi4uccore/addfiledialoglogic.vala
r78c0493 r008d5c7 43 43 } 44 44 45 public bool run ( out string file, out Gee.List<string> profiles)45 public bool run () 46 46 { 47 var response = _view.run (); 48 var is_new = _view.is_new; 49 var filename = _view.filename; 50 profiles = _view.activated_profiles; 51 _view.close_dialog (); 52 53 if (response != DialogResponse.OK) 47 if (_view.run () == DialogResponse.CANCEL) 54 48 return false; 55 56 if (is_new)57 {58 var new_file = File.new_for_uri (_project.get_file_uri (filename));59 var overwrite = true;60 if (new_file.query_exists (null))61 {62 var message = _("The file <<%s>> already exists, do you want to create a new one?").printf (new_file.get_path ());63 response = _view.show_yes_no_message (message, true);64 65 if (response == DialogResponse.CANCEL)66 return false;67 68 if (response == DialogResponse.NO)69 overwrite = false;70 }71 if (overwrite)72 new_file.replace_contents ("", 0, null, false, FileCreateFlags.NONE, null, null);73 file = filename;74 }75 else76 {77 var import_file = File.new_for_uri (filename);78 var file_info = import_file.query_info (FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, FileQueryInfoFlags.NONE, null);79 var import_filename = file_info.get_display_name ();80 if (_project.folder_uri != import_file.get_parent ().get_uri ())81 {82 var message = _("The file <<%s>> is outside the project's folder, do you want to copy the file?").printf (import_file.get_path ());83 response = _view.show_yes_no_message (message, false);84 85 if (response == DialogResponse.YES)86 {87 var dest_file = File.new_for_uri (_project.get_file_uri (import_filename));88 message = _("Do you want to overwrite the file <<%s>>?").printf (dest_file.get_path ());89 if (dest_file.query_exists (null) && _view.show_yes_no_message (message, false) == DialogResponse.NO)90 return false;91 import_file.copy (dest_file, FileCopyFlags.OVERWRITE, null, null);92 }93 }94 file = import_filename;95 }96 49 return true; 97 50 } 98 51 99 52 private void on_is_new_changed () 100 53 { -
libi4uccore/projectslogic.vala
r78c0493 r008d5c7 133 133 private void on_add_file_clicked () 134 134 { 135 var current_project = _page_logic.current_project; 136 var dialog_logic = new AddFileDialogLogic (_view.create_add_file_dialog_view (), current_project); 137 string file; 138 Gee.List<string> profiles; 139 if (dialog_logic.run (out file, out profiles)) 140 { 135 var dialog_view = _view.create_add_file_dialog_view (); 136 var current_project = _page_logic.current_project; 137 var dialog_logic = new AddFileDialogLogic (dialog_view, current_project); 138 139 if (dialog_logic.run ()) 140 { 141 string file; 142 if (dialog_view.is_new) 143 { 144 // Create a new empty file 145 var new_file = File.new_for_uri (current_project.get_file_uri (dialog_view.filename)); 146 var overwrite = true; 147 if (new_file.query_exists (null)) 148 { 149 // The file already exists, ask to create a new one 150 var message = _("The file <<%s>> already exists, do you want to create a new one?").printf (new_file.get_path ()); 151 var response = _view.show_yes_no_message (message, true); 152 153 if (response == DialogResponse.CANCEL) 154 return; 155 156 if (response == DialogResponse.NO) 157 overwrite = false; 158 } 159 if (overwrite) 160 new_file.replace_contents ("", 0, null, false, FileCreateFlags.NONE, null, null); 161 file = dialog_view.filename; 162 } 163 else 164 { 165 // Import a file 166 var import_file = File.new_for_uri (dialog_view.filename); 167 var file_info = import_file.query_info (FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, FileQueryInfoFlags.NONE, null); 168 var import_filename = file_info.get_display_name (); 169 if (current_project.folder_uri != import_file.get_parent ().get_uri ()) 170 { 171 // The file is in another folder, ask to copy the file 172 var message = _("The file <<%s>> is outside the project's folder, do you want to copy the file?").printf (import_file.get_path ()); 173 var response = _view.show_yes_no_message (message, false); 174 175 if (response == DialogResponse.YES) 176 { 177 // The file already exists, ask to ovewrite the file 178 var dest_file = File.new_for_uri (current_project.get_file_uri (import_filename)); 179 message = _("Do you want to overwrite the file <<%s>>?").printf (dest_file.get_path ()); 180 if (dest_file.query_exists (null) && _view.show_yes_no_message (message, false) == DialogResponse.NO) 181 return; 182 import_file.copy (dest_file, FileCopyFlags.OVERWRITE, null, null); 183 } 184 } 185 file = import_filename; 186 } 187 188 // Add the file to the project and to the selected profiles and open the file 141 189 if (!(file in current_project.files)) 142 190 current_project.files.add (file); 143 foreach (var profile in profiles)191 foreach (var profile in dialog_view.activated_profiles) 144 192 if (!(file in current_project.profiles[profile].files)) 145 193 current_project.profiles[profile].files.add (file); … … 148 196 _documents_logic.open_document (current_project.get_file_uri (file)); 149 197 } 198 dialog_view.close_dialog (); 150 199 } 151 200
Note: See TracChangeset
for help on using the changeset viewer.

