1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD 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 Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gsv.SourceFileSaver; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.File; 30 private import gio.FileIF; 31 private import glib.ConstructionException; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import gobject.ObjectG; 35 private import gsv.SourceBuffer; 36 private import gsv.SourceEncoding; 37 private import gsv.SourceFile; 38 private import gsvc.gsv; 39 public import gsvc.gsvtypes; 40 41 42 /** */ 43 public class SourceFileSaver : ObjectG 44 { 45 /** the main Gtk struct */ 46 protected GtkSourceFileSaver* gtkSourceFileSaver; 47 48 /** Get the main Gtk struct */ 49 public GtkSourceFileSaver* getSourceFileSaverStruct() 50 { 51 return gtkSourceFileSaver; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected override void* getStruct() 56 { 57 return cast(void*)gtkSourceFileSaver; 58 } 59 60 protected override void setStruct(GObject* obj) 61 { 62 gtkSourceFileSaver = cast(GtkSourceFileSaver*)obj; 63 super.setStruct(obj); 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GtkSourceFileSaver* gtkSourceFileSaver, bool ownedRef = false) 70 { 71 this.gtkSourceFileSaver = gtkSourceFileSaver; 72 super(cast(GObject*)gtkSourceFileSaver, ownedRef); 73 } 74 75 76 /** */ 77 public static GType getType() 78 { 79 return gtk_source_file_saver_get_type(); 80 } 81 82 /** 83 * Creates a new #GtkSourceFileSaver object. The @buffer will be saved to the 84 * #GtkSourceFile's location. 85 * 86 * This constructor is suitable for a simple "save" operation, when the @file 87 * already contains a non-%NULL #GtkSourceFile:location. 88 * 89 * Params: 90 * buffer = the #GtkSourceBuffer to save. 91 * file = the #GtkSourceFile. 92 * 93 * Return: a new #GtkSourceFileSaver object. 94 * 95 * Since: 3.14 96 * 97 * Throws: ConstructionException GTK+ fails to create the object. 98 */ 99 public this(SourceBuffer buffer, SourceFile file) 100 { 101 auto p = gtk_source_file_saver_new((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct()); 102 103 if(p is null) 104 { 105 throw new ConstructionException("null returned by new"); 106 } 107 108 this(cast(GtkSourceFileSaver*) p, true); 109 } 110 111 /** 112 * Creates a new #GtkSourceFileSaver object with a target location. When the 113 * file saving is finished successfully, @target_location is set to the @file's 114 * #GtkSourceFile:location property. If an error occurs, the previous valid 115 * location is still available in #GtkSourceFile. 116 * 117 * This constructor is suitable for a "save as" operation, or for saving a new 118 * buffer for the first time. 119 * 120 * Params: 121 * buffer = the #GtkSourceBuffer to save. 122 * file = the #GtkSourceFile. 123 * targetLocation = the #GFile where to save the buffer to. 124 * 125 * Return: a new #GtkSourceFileSaver object. 126 * 127 * Since: 3.14 128 * 129 * Throws: ConstructionException GTK+ fails to create the object. 130 */ 131 public this(SourceBuffer buffer, SourceFile file, FileIF targetLocation) 132 { 133 auto p = gtk_source_file_saver_new_with_target((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct(), (targetLocation is null) ? null : targetLocation.getFileStruct()); 134 135 if(p is null) 136 { 137 throw new ConstructionException("null returned by new_with_target"); 138 } 139 140 this(cast(GtkSourceFileSaver*) p, true); 141 } 142 143 /** 144 * Return: the #GtkSourceBuffer to save. 145 * 146 * Since: 3.14 147 */ 148 public SourceBuffer getBuffer() 149 { 150 auto p = gtk_source_file_saver_get_buffer(gtkSourceFileSaver); 151 152 if(p is null) 153 { 154 return null; 155 } 156 157 return ObjectG.getDObject!(SourceBuffer)(cast(GtkSourceBuffer*) p); 158 } 159 160 /** 161 * Return: the compression type. 162 * 163 * Since: 3.14 164 */ 165 public GtkSourceCompressionType getCompressionType() 166 { 167 return gtk_source_file_saver_get_compression_type(gtkSourceFileSaver); 168 } 169 170 /** 171 * Return: the encoding. 172 * 173 * Since: 3.14 174 */ 175 public SourceEncoding getEncoding() 176 { 177 auto p = gtk_source_file_saver_get_encoding(gtkSourceFileSaver); 178 179 if(p is null) 180 { 181 return null; 182 } 183 184 return ObjectG.getDObject!(SourceEncoding)(cast(GtkSourceEncoding*) p); 185 } 186 187 /** 188 * Return: the #GtkSourceFile. 189 * 190 * Since: 3.14 191 */ 192 public SourceFile getFile() 193 { 194 auto p = gtk_source_file_saver_get_file(gtkSourceFileSaver); 195 196 if(p is null) 197 { 198 return null; 199 } 200 201 return ObjectG.getDObject!(SourceFile)(cast(GtkSourceFile*) p); 202 } 203 204 /** 205 * Return: the flags. 206 * 207 * Since: 3.14 208 */ 209 public GtkSourceFileSaverFlags getFlags() 210 { 211 return gtk_source_file_saver_get_flags(gtkSourceFileSaver); 212 } 213 214 /** 215 * Return: the #GFile where to save the buffer to. 216 * 217 * Since: 3.14 218 */ 219 public FileIF getLocation() 220 { 221 auto p = gtk_source_file_saver_get_location(gtkSourceFileSaver); 222 223 if(p is null) 224 { 225 return null; 226 } 227 228 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 229 } 230 231 /** 232 * Return: the newline type. 233 * 234 * Since: 3.14 235 */ 236 public GtkSourceNewlineType getNewlineType() 237 { 238 return gtk_source_file_saver_get_newline_type(gtkSourceFileSaver); 239 } 240 241 /** 242 * Saves asynchronously the buffer into the file. See the #GAsyncResult 243 * documentation to know how to use this function. 244 * 245 * Params: 246 * ioPriority = the I/O priority of the request. E.g. %G_PRIORITY_LOW, 247 * %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH. 248 * cancellable = optional #GCancellable object, %NULL to ignore. 249 * progressCallback = function to call back with 250 * progress information, or %NULL if progress information is not needed. 251 * progressCallbackData = user data to pass to @progress_callback. 252 * progressCallbackNotify = function to call on 253 * @progress_callback_data when the @progress_callback is no longer needed, or 254 * %NULL. 255 * callback = a #GAsyncReadyCallback to call when the request is 256 * satisfied. 257 * userData = user data to pass to @callback. 258 * 259 * Since: 3.14 260 */ 261 public void saveAsync(int ioPriority, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData, GDestroyNotify progressCallbackNotify, GAsyncReadyCallback callback, void* userData) 262 { 263 gtk_source_file_saver_save_async(gtkSourceFileSaver, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, progressCallbackNotify, callback, userData); 264 } 265 266 /** 267 * Finishes a file saving started with gtk_source_file_saver_save_async(). 268 * 269 * If the file has been saved successfully, the following #GtkSourceFile 270 * properties will be updated: the location, the encoding, the newline type and 271 * the compression type. 272 * 273 * Since the 3.20 version, gtk_text_buffer_set_modified() is called with %FALSE 274 * if the file has been saved successfully. 275 * 276 * Params: 277 * result = a #GAsyncResult. 278 * 279 * Return: whether the file was saved successfully. 280 * 281 * Since: 3.14 282 * 283 * Throws: GException on failure. 284 */ 285 public bool saveFinish(AsyncResultIF result) 286 { 287 GError* err = null; 288 289 auto p = gtk_source_file_saver_save_finish(gtkSourceFileSaver, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 290 291 if (err !is null) 292 { 293 throw new GException( new ErrorG(err) ); 294 } 295 296 return p; 297 } 298 299 /** 300 * Sets the compression type. By default the compression type is taken from the 301 * #GtkSourceFile. 302 * 303 * Params: 304 * compressionType = the new compression type. 305 * 306 * Since: 3.14 307 */ 308 public void setCompressionType(GtkSourceCompressionType compressionType) 309 { 310 gtk_source_file_saver_set_compression_type(gtkSourceFileSaver, compressionType); 311 } 312 313 /** 314 * Sets the encoding. If @encoding is %NULL, the UTF-8 encoding will be set. 315 * By default the encoding is taken from the #GtkSourceFile. 316 * 317 * Params: 318 * encoding = the new encoding, or %NULL for UTF-8. 319 * 320 * Since: 3.14 321 */ 322 public void setEncoding(SourceEncoding encoding) 323 { 324 gtk_source_file_saver_set_encoding(gtkSourceFileSaver, (encoding is null) ? null : encoding.getSourceEncodingStruct()); 325 } 326 327 /** */ 328 public void setFlags(GtkSourceFileSaverFlags flags) 329 { 330 gtk_source_file_saver_set_flags(gtkSourceFileSaver, flags); 331 } 332 333 /** 334 * Sets the newline type. By default the newline type is taken from the 335 * #GtkSourceFile. 336 * 337 * Params: 338 * newlineType = the new newline type. 339 * 340 * Since: 3.14 341 */ 342 public void setNewlineType(GtkSourceNewlineType newlineType) 343 { 344 gtk_source_file_saver_set_newline_type(gtkSourceFileSaver, newlineType); 345 } 346 }