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