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