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 public class SourceLanguageManager : ObjectG
36 {
37 	/** the main Gtk struct */
38 	protected GtkSourceLanguageManager* gtkSourceLanguageManager;
39 
40 	/** Get the main Gtk struct */
41 	public GtkSourceLanguageManager* getSourceLanguageManagerStruct()
42 	{
43 		return gtkSourceLanguageManager;
44 	}
45 
46 	/** the main Gtk struct as a void* */
47 	protected override void* getStruct()
48 	{
49 		return cast(void*)gtkSourceLanguageManager;
50 	}
51 
52 	protected override void setStruct(GObject* obj)
53 	{
54 		gtkSourceLanguageManager = cast(GtkSourceLanguageManager*)obj;
55 		super.setStruct(obj);
56 	}
57 
58 	/**
59 	 * Sets our main struct and passes it to the parent class.
60 	 */
61 	public this (GtkSourceLanguageManager* gtkSourceLanguageManager, bool ownedRef = false)
62 	{
63 		this.gtkSourceLanguageManager = gtkSourceLanguageManager;
64 		super(cast(GObject*)gtkSourceLanguageManager, ownedRef);
65 	}
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
141 	 *     string containing the ids of the available languages or %NULL if no
142 	 *     language is available.  The array is sorted alphabetically
143 	 *     according to the language name.  The array is owned by @lm and must
144 	 *     not be modified.
145 	 */
146 	public string[] getLanguageIds()
147 	{
148 		return Str.toStringArray(gtk_source_language_manager_get_language_ids(gtkSourceLanguageManager));
149 	}
150 
151 	/**
152 	 * Gets the list directories where @lm looks for language files.
153 	 *
154 	 * Return: %NULL-terminated array
155 	 *     containg a list of language files directories.
156 	 *     The array is owned by @lm and must not be modified.
157 	 */
158 	public string[] getSearchPath()
159 	{
160 		return Str.toStringArray(gtk_source_language_manager_get_search_path(gtkSourceLanguageManager));
161 	}
162 
163 	/**
164 	 * Picks a #GtkSourceLanguage for given file name and content type,
165 	 * according to the information in lang files. Either @filename or
166 	 * @content_type may be %NULL. This function can be used as follows:
167 	 *
168 	 * <informalexample><programlisting>
169 	 * GtkSourceLanguage *lang;
170 	 * lang = gtk_source_language_manager_guess_language (filename, NULL);
171 	 * gtk_source_buffer_set_language (buffer, lang);
172 	 * </programlisting></informalexample>
173 	 *
174 	 * or
175 	 *
176 	 * <informalexample><programlisting>
177 	 * GtkSourceLanguage *lang = NULL;
178 	 * gboolean result_uncertain;
179 	 * gchar *content_type;
180 	 *
181 	 * content_type = g_content_type_guess (filename, NULL, 0, &result_uncertain);
182 	 * if (result_uncertain)
183 	 * {
184 	 * g_free (content_type);
185 	 * content_type = NULL;
186 	 * }
187 	 *
188 	 * lang = gtk_source_language_manager_guess_language (manager, filename, content_type);
189 	 * gtk_source_buffer_set_language (buffer, lang);
190 	 *
191 	 * g_free (content_type);
192 	 * </programlisting></informalexample>
193 	 *
194 	 * etc. Use gtk_source_language_get_mime_types() and gtk_source_language_get_globs()
195 	 * if you need full control over file -> language mapping.
196 	 *
197 	 * Params:
198 	 *     filename = a filename in Glib filename encoding, or %NULL.
199 	 *     contentType = a content type (as in GIO API), or %NULL.
200 	 *
201 	 * Return: a #GtkSourceLanguage, or %NULL if there
202 	 *     is no suitable language for given @filename and/or @content_type. Return
203 	 *     value is owned by @lm and should not be freed.
204 	 *
205 	 * Since: 2.4
206 	 */
207 	public SourceLanguage guessLanguage(string filename, string contentType)
208 	{
209 		auto p = gtk_source_language_manager_guess_language(gtkSourceLanguageManager, Str.toStringz(filename), Str.toStringz(contentType));
210 		
211 		if(p is null)
212 		{
213 			return null;
214 		}
215 		
216 		return ObjectG.getDObject!(SourceLanguage)(cast(GtkSourceLanguage*) p);
217 	}
218 
219 	/**
220 	 * Sets the list of directories where the @lm looks for
221 	 * language files.
222 	 * If @dirs is %NULL, the search path is reset to default.
223 	 *
224 	 * <note>
225 	 * <para>
226 	 * At the moment this function can be called only before the
227 	 * language files are loaded for the first time. In practice
228 	 * to set a custom search path for a #GtkSourceLanguageManager,
229 	 * you have to call this function right after creating it.
230 	 * </para>
231 	 * </note>
232 	 *
233 	 * Params:
234 	 *     dirs = a %NULL-terminated array of strings or %NULL.
235 	 */
236 	public void setSearchPath(string[] dirs)
237 	{
238 		gtk_source_language_manager_set_search_path(gtkSourceLanguageManager, Str.toStringzArray(dirs));
239 	}
240 }