GSList *
cedit_language_manager_list_languages_sorted (GtkSourceLanguageManager *lm,
					      gboolean                  include_hidden)
{
	GSList *languages = NULL;
	const gchar * const *ids;

	ids = gtk_source_language_manager_get_language_ids (lm);
	if (ids == NULL)
		return NULL;

	while (*ids != NULL)
	{
		GtkSourceLanguage *lang;

		lang = gtk_source_language_manager_get_language (lm, *ids);
#if GTK_CHECK_VERSION (3, 0, 0)
		g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), NULL);
#else
		g_return_val_if_fail (GTK_IS_SOURCE_LANGUAGE (lang), NULL);
#endif
		++ids;

		if (include_hidden || !gtk_source_language_get_hidden (lang))
		{
			languages = g_slist_prepend (languages, lang);
		}
	}

	return g_slist_sort (languages, (GCompareFunc)language_compare);
}
Exemple #2
0
Gobby::MenuManager::MenuManager(GtkSourceLanguageManager* language_manager)
{
	Glib::RefPtr<Gtk::Builder> builder =
		Gtk::Builder::create_from_resource(
			"/de/0x539/gobby/ui/menu.ui");

	m_app_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(
		builder->get_object("appmenu"));
	m_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(
		builder->get_object("winmenu"));

	Glib::RefPtr<Gio::Menu> highlight_mode_menu = get_highlight_mode_menu();

	const gchar* const* language_ids =
		gtk_source_language_manager_get_language_ids(
			language_manager);
	if(language_ids != NULL)
	{
		typedef std::list<GtkSourceLanguage*> LanguageList;
		typedef std::map<std::string, LanguageList> LanguageMap;
		LanguageMap languages;

		for(const gchar* const* id = language_ids; *id != NULL; ++id)
		{
			GtkSourceLanguage* language =
				gtk_source_language_manager_get_language(
					language_manager, *id);
			if(gtk_source_language_get_hidden(language)) continue;

			const std::string section =
				gtk_source_language_get_section(language);

			languages[section].push_back(language);
		}

		for(LanguageMap::iterator iter = languages.begin();
		    iter != languages.end(); ++iter)
		{
			Glib::RefPtr<Gio::Menu> submenu(Gio::Menu::create());

			LanguageList& list = iter->second;
			list.sort(language_sort_func);

			for(LanguageList::const_iterator liter = list.begin();
			    liter != list.end(); ++liter)
			{
				GtkSourceLanguage* language = *liter;

				const std::string id =
					gtk_source_language_get_id(language);
				const std::string name =
					gtk_source_language_get_name(language);

				Glib::RefPtr<Gio::MenuItem> item(
					Gio::MenuItem::create(
						name, Glib::ustring::compose(
							"win.highlight-mode"
							"('%1')", id)));
				submenu->append_item(item);
			}

			highlight_mode_menu->append_submenu(
				iter->first, submenu);
		}
	}
}