Gsv::LanguageManager Class Reference

Class which provides access to SourceLanguages. More...

`#include <gtksourceviewmm/languagemanager.h>`

Inheritance diagram for Gsv::LanguageManager:
[legend]

## Public Member Functions

| LanguageManager (LanguageManager&& src) noexcept
LanguageManager& | operator= (LanguageManager&& src) noexcept
virtual | ~LanguageManager () noexcept
GtkSourceLanguageManager* | gobj ()
| Provides access to the underlying C GObject. More...
const GtkSourceLanguageManager* | gobj () const
| Provides access to the underlying C GObject. More...
GtkSourceLanguageManager* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
std::vector< std::string > | get_search_path () const
| Gets the list directories where language manager looks for language files. More...
void | set_search_path (const std::vector< std::string >& dirs)
| Sets the list of directories where the language manager looks for language files. More...
void | reset_search_path ()
| Resets the list of directories where the language manager looks for language files to default. More...
std::vector< std::string > | get_language_ids () const
| Returns the ids of the available languages. More...
Glib::RefPtr< Language > | get_language (const std::string& id)
| Gets the Language identified by the given id in the language manager. More...
Glib::RefPtr< const Language > | get_language (const std::string& id) const
| Gets the Language identified by the given id in the language manager. More...
Glib::RefPtr< Language > | guess_language (const std::string& filename, const std::string& content_type)
| Picks a Language for given file name and content type, according to the information in lang files. More...
Glib::RefPtr< const Language > | guess_language (const std::string& filename, const std::string& content_type) const
| Picks a Language for given file name and content type, according to the information in lang files. More...
Glib::PropertyProxy< std::vector< std::string > > | property_search_path ()
| List of directories where the language specification files (.lang) are located. More...
Glib::PropertyProxy_ReadOnly< std::vector< std::string > > | property_search_path () const
| List of directories where the language specification files (.lang) are located. More...
Glib::PropertyProxy_ReadOnly< std::vector< std::string > > | property_language_ids () const
| List of the ids of the available languages. More...
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
void | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void > &slot)
sigc::connection | connect_property_changed_with_return (const Glib::ustring &property_name, const sigc::slot< void > &slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const
Public Member Functions inherited from sigc::trackable
| trackable ()
| trackable (const trackable &src)
| trackable (trackable &&src) noexcept
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (void *data) const

## Static Public Member Functions

static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
static Glib::RefPtr< LanguageManager > | create ()
| Creates a new language manager. More...
static Glib::RefPtr< LanguageManager > | get_default ()
| Returns the default LanguageManager instance. More...

## Protected Member Functions

| LanguageManager ()
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
virtual | ~Object () noexcept
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## Related Functions

(Note that these are not member functions.)
Glib::RefPtr< Gsv::LanguageManager > | wrap (GtkSourceLanguageManager* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Additional Inherited Members

Public Types inherited from Glib::Object
typedef void(* | DestroyNotify) (gpointer data)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify

## Detailed Description

Class which provides access to SourceLanguages.

LanguageManager is a class which processes language description files and creates and stores Language objects, and provides API to access them.

Use get_default() to retrieve the default instance of LanguageManager, and guess_language() to get a Language for given file name and content type.

## Constructor & Destructor Documentation

Gsv::LanguageManager::LanguageManager | ( | LanguageManager&& | src | ) |

noexcept

virtual Gsv::LanguageManager::~LanguageManager | ( |  | ) |

virtual noexcept

Gsv::LanguageManager::LanguageManager | ( |  | ) |

protected

## Member Function Documentation

static Glib::RefPtr<LanguageManager> Gsv::LanguageManager::create | ( |  | ) |

static

Creates a new language manager.

If you do not need more than one language manager or a private language manager instance then use get_default() instead.

Returns
  A LanguageManager.

static Glib::RefPtr<LanguageManager> Gsv::LanguageManager::get_default | ( |  | ) |

static

Returns the default LanguageManager instance.

Returns
  A LanguageManager.

Glib::RefPtr<Language> Gsv::LanguageManager::get_language | ( | const std::string & | id | ) |

Gets the Language identified by the given id in the language manager.

Parameters

  id | A language id.

Returns
  A Language, or empty Glib::RefPtr if there is no language identified by the given id.

Glib::RefPtr<const Language> Gsv::LanguageManager::get_language | ( | const std::string & | id | ) | const

Gets the Language identified by the given id in the language manager.

Parameters

  id | A language id.

Returns
  A Language, or empty Glib::RefPtr if there is no language identified by the given id.

std::vector<std::string> Gsv::LanguageManager::get_language_ids | ( |  | ) | const

Returns the ids of the available languages.

Returns
  An array of string containing the ids of the available languages.

std::vector<std::string> Gsv::LanguageManager::get_search_path | ( |  | ) | const

Gets the list directories where language manager looks for language files.

Returns
  An array containg a list of language files directories.

static GType Gsv::LanguageManager::get_type | ( |  | ) |

static

Get the GType for this class, for use with the underlying GObject type system.

GtkSourceLanguageManager* Gsv::LanguageManager::gobj | ( |  | ) |

inline

Provides access to the underlying C GObject.

const GtkSourceLanguageManager* Gsv::LanguageManager::gobj | ( |  | ) | const

inline

Provides access to the underlying C GObject.

GtkSourceLanguageManager* Gsv::LanguageManager::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Glib::RefPtr<Language> Gsv::LanguageManager::guess_language | ( | const std::string & | filename,
|  | const std::string & | content_type
| ) |  |

Picks a Language for given file name and content type, according to the information in lang files.

Either filename or content_type may be an empty string. This function can be used as follows:

Glib::RefPtr<Language> lang;
lang = lm->guess_language(filename, Glib::ustring());
buffer->set_language(lang);

or

Glib::RefPtr<Language> lang;
bool result_uncertain = FALSE;
Glib::ustring content_type;
content_type = Gio::content_type_guess(filename, 0, 0, &result_uncertain);
if (result_uncertain)
{
content_type.clear();
}
lang = lm->guess_language(filename, content_type);
buffer->set_language(lang);

etc. Use get_mime_types() and get_globs() if you need full control over file -> language mapping.

Parameters

  filename | A filename, or empty string.
  content_type | A content type (as in GIO API), or empty string.

Returns
  A Language, or empty Glib::RefPtr if there is no suitable language for given filename and/or content_type.

Glib::RefPtr<const Language> Gsv::LanguageManager::guess_language | ( | const std::string & | filename,
|  | const std::string & | content_type
| ) |  | const

Picks a Language for given file name and content type, according to the information in lang files.

Either filename or content_type may be an empty string. This function can be used as follows:

Glib::RefPtr<LanguageManager> lm = LanguageManager::get_default();
Glib::RefPtr<Language> lang;
Glib::RefPtr<Buffer> buffer = Buffer::create();
lang = lm->guess_language(filename, Glib::ustring());
buffer->set_language(lang);
// or just:
// Glib::RefPtr<Buffer> buffer = Buffer::create(lang);

or

Glib::RefPtr<Language> lang;
Glib::RefPtr<LanguageManager> lm = LanguageManager::get_default();
Glib::RefPtr<Buffer> buffer = Buffer::create();
bool result_uncertain = FALSE;
Glib::ustring content_type;
content_type = Gio::content_type_guess(filename, 0, 0, &result_uncertain);
if (result_uncertain)
{
content_type.clear();
}
lang = lm->guess_language(filename, content_type);
buffer->set_language(lang);
// or just:
// Glib::RefPtr<Buffer> buffer = Buffer::create(lang);

etc. Use Language::get_mime_types() and Language::get_globs() if you need full control over file -> language mapping.

Parameters

  filename | A filename, or empty string.
  content_type | A content type (as in GIO API), or empty string.

Returns
  A Language, or empty Glib::RefPtr if there is no suitable language for given filename and/or content_type.

LanguageManager& Gsv::LanguageManager::operator= | ( | LanguageManager&& | src | ) |

noexcept

Glib::PropertyProxy_ReadOnly< std::vector<std::string> > Gsv::LanguageManager::property_language_ids | ( |  | ) | const

List of the ids of the available languages.

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

Glib::PropertyProxy< std::vector<std::string> > Gsv::LanguageManager::property_search_path | ( |  | ) |

List of directories where the language specification files (.lang) are located.

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly< std::vector<std::string> > Gsv::LanguageManager::property_search_path | ( |  | ) | const

List of directories where the language specification files (.lang) are located.

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

void Gsv::LanguageManager::reset_search_path | ( |  | ) |

Resets the list of directories where the language manager looks for language files to default.

Note
  At the moment this function can be called only before the language files are loaded for the first time. In practice to set a custom search path for a LanguageManager, you have to call this function right after creating it.

void Gsv::LanguageManager::set_search_path | ( | const std::vector< std::string > & | dirs | ) |

Sets the list of directories where the language manager looks for language files.

Note
  At the moment this function can be called only before the language files are loaded for the first time. In practice to set a custom search path for a LanguageManager, you have to call this function right after creating it.

Parameters

  dirs | An empty string terminated array of strings.

## Friends And Related Function Documentation

Glib::RefPtr< Gsv::LanguageManager > wrap | ( | GtkSourceLanguageManager * | object,
|  | bool | take_copy = `false`
| ) |  |

related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.