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