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.SourceLanguageManager; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gsv.SourceLanguage; 31 private import gsv.c.functions; 32 public import gsv.c.types; 33 public import gsvc.gsvtypes; 34 35 36 /** */ 37 public class SourceLanguageManager : ObjectG 38 { 39 /** the main Gtk struct */ 40 protected GtkSourceLanguageManager* gtkSourceLanguageManager; 41 42 /** Get the main Gtk struct */ 43 public GtkSourceLanguageManager* getSourceLanguageManagerStruct(bool transferOwnership = false) 44 { 45 if (transferOwnership) 46 ownedRef = false; 47 return gtkSourceLanguageManager; 48 } 49 50 /** the main Gtk struct as a void* */ 51 protected override void* getStruct() 52 { 53 return cast(void*)gtkSourceLanguageManager; 54 } 55 56 /** 57 * Sets our main struct and passes it to the parent class. 58 */ 59 public this (GtkSourceLanguageManager* gtkSourceLanguageManager, bool ownedRef = false) 60 { 61 this.gtkSourceLanguageManager = gtkSourceLanguageManager; 62 super(cast(GObject*)gtkSourceLanguageManager, ownedRef); 63 } 64 65 66 /** */ 67 public static GType getType() 68 { 69 return gtk_source_language_manager_get_type(); 70 } 71 72 /** 73 * Creates a new language manager. If you do not need more than one language 74 * manager or a private language manager instance then use 75 * gtk_source_language_manager_get_default() instead. 76 * 77 * Returns: a new #GtkSourceLanguageManager. 78 * 79 * Throws: ConstructionException GTK+ fails to create the object. 80 */ 81 public this() 82 { 83 auto p = gtk_source_language_manager_new(); 84 85 if(p is null) 86 { 87 throw new ConstructionException("null returned by new"); 88 } 89 90 this(cast(GtkSourceLanguageManager*) p, true); 91 } 92 93 /** 94 * Returns the default #GtkSourceLanguageManager instance. 95 * 96 * Returns: a #GtkSourceLanguageManager. 97 * Return value is owned by GtkSourceView library and must not be unref'ed. 98 */ 99 public static SourceLanguageManager getDefault() 100 { 101 auto p = gtk_source_language_manager_get_default(); 102 103 if(p is null) 104 { 105 return null; 106 } 107 108 return ObjectG.getDObject!(SourceLanguageManager)(cast(GtkSourceLanguageManager*) p); 109 } 110 111 /** 112 * Gets the #GtkSourceLanguage identified by the given @id in the language 113 * manager. 114 * 115 * Params: 116 * id = a language id. 117 * 118 * Returns: a #GtkSourceLanguage, or %NULL 119 * if there is no language identified by the given @id. Return value is 120 * owned by @lm and should not be freed. 121 */ 122 public SourceLanguage getLanguage(string id) 123 { 124 auto p = gtk_source_language_manager_get_language(gtkSourceLanguageManager, Str.toStringz(id)); 125 126 if(p is null) 127 { 128 return null; 129 } 130 131 return ObjectG.getDObject!(SourceLanguage)(cast(GtkSourceLanguage*) p); 132 } 133 134 /** 135 * Returns the ids of the available languages. 136 * 137 * Returns: a %NULL-terminated array of strings containing the ids of the available 138 * languages or %NULL if no language is available. 139 * The array is sorted alphabetically according to the language name. 140 * The array is owned by @lm and must not be modified. 141 */ 142 public string[] getLanguageIds() 143 { 144 return Str.toStringArray(gtk_source_language_manager_get_language_ids(gtkSourceLanguageManager)); 145 } 146 147 /** 148 * Gets the list directories where @lm looks for language files. 149 * 150 * Returns: %NULL-terminated array 151 * containg a list of language files directories. 152 * The array is owned by @lm and must not be modified. 153 */ 154 public string[] getSearchPath() 155 { 156 return Str.toStringArray(gtk_source_language_manager_get_search_path(gtkSourceLanguageManager)); 157 } 158 159 /** 160 * Picks a #GtkSourceLanguage for given file name and content type, 161 * according to the information in lang files. Either @filename or 162 * @content_type may be %NULL. This function can be used as follows: 163 * 164 * <informalexample><programlisting> 165 * GtkSourceLanguage *lang; 166 * lang = gtk_source_language_manager_guess_language (filename, NULL); 167 * gtk_source_buffer_set_language (buffer, lang); 168 * </programlisting></informalexample> 169 * 170 * or 171 * 172 * <informalexample><programlisting> 173 * GtkSourceLanguage *lang = NULL; 174 * gboolean result_uncertain; 175 * gchar *content_type; 176 * 177 * content_type = g_content_type_guess (filename, NULL, 0, &result_uncertain); 178 * if (result_uncertain) 179 * { 180 * g_free (content_type); 181 * content_type = NULL; 182 * } 183 * 184 * lang = gtk_source_language_manager_guess_language (manager, filename, content_type); 185 * gtk_source_buffer_set_language (buffer, lang); 186 * 187 * g_free (content_type); 188 * </programlisting></informalexample> 189 * 190 * etc. Use gtk_source_language_get_mime_types() and gtk_source_language_get_globs() 191 * if you need full control over file -> language mapping. 192 * 193 * Params: 194 * filename = a filename in Glib filename encoding, or %NULL. 195 * contentType = a content type (as in GIO API), or %NULL. 196 * 197 * Returns: a #GtkSourceLanguage, or %NULL if there 198 * is no suitable language for given @filename and/or @content_type. Return 199 * value is owned by @lm and should not be freed. 200 * 201 * Since: 2.4 202 */ 203 public SourceLanguage guessLanguage(string filename, string contentType) 204 { 205 auto p = gtk_source_language_manager_guess_language(gtkSourceLanguageManager, Str.toStringz(filename), Str.toStringz(contentType)); 206 207 if(p is null) 208 { 209 return null; 210 } 211 212 return ObjectG.getDObject!(SourceLanguage)(cast(GtkSourceLanguage*) p); 213 } 214 215 /** 216 * Sets the list of directories where the @lm looks for 217 * language files. 218 * If @dirs is %NULL, the search path is reset to default. 219 * 220 * <note> 221 * <para> 222 * At the moment this function can be called only before the 223 * language files are loaded for the first time. In practice 224 * to set a custom search path for a #GtkSourceLanguageManager, 225 * you have to call this function right after creating it. 226 * </para> 227 * </note> 228 * 229 * Params: 230 * dirs = a %NULL-terminated array of strings or %NULL. 231 */ 232 public void setSearchPath(string[] dirs) 233 { 234 gtk_source_language_manager_set_search_path(gtkSourceLanguageManager, Str.toStringzArray(dirs)); 235 } 236 }