Commit 3cabaf3e authored by Christian Hergert's avatar Christian Hergert
Browse files

template: add priority to templates to sort

parent d0a12aea
......@@ -133,3 +133,46 @@ ide_project_template_expand_finish (IdeProjectTemplate *self,
return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->expand_finish (self, result, error);
}
/**
* ide_project_template_get_priority:
* @self: a #IdeProjectTemplate
*
* Gets the priority of the template. This can be used to sort the templates
* in the "new project" view.
*
* Returns: the priority of the template
*
* Since: 3.28
*/
gint
ide_project_template_get_priority (IdeProjectTemplate *self)
{
g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), 0);
if (IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_priority)
return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_priority (self);
return 0;
}
gint
ide_project_template_compare (IdeProjectTemplate *a,
IdeProjectTemplate *b)
{
gint ret;
g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (a), 0);
g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (b), 0);
ret = ide_project_template_get_priority (a) - ide_project_template_get_priority (b);
if (ret == 0)
{
g_autofree gchar *a_name = ide_project_template_get_name (a);
g_autofree gchar *b_name = ide_project_template_get_name (b);
ret = g_utf8_collate (a_name, b_name);
}
return ret;
}
......@@ -46,10 +46,13 @@ struct _IdeProjectTemplateInterface
gboolean (*expand_finish) (IdeProjectTemplate *self,
GAsyncResult *result,
GError **error);
gint (*get_priority) (IdeProjectTemplate *self);
};
IDE_AVAILABLE_IN_ALL
gchar *ide_project_template_get_id (IdeProjectTemplate *self);
IDE_AVAILABLE_IN_3_28
gint ide_project_template_get_priority (IdeProjectTemplate *self);
IDE_AVAILABLE_IN_ALL
gchar *ide_project_template_get_name (IdeProjectTemplate *self);
IDE_AVAILABLE_IN_ALL
......@@ -70,5 +73,8 @@ IDE_AVAILABLE_IN_ALL
gboolean ide_project_template_expand_finish (IdeProjectTemplate *self,
GAsyncResult *result,
GError **error);
IDE_AVAILABLE_IN_3_28
gint ide_project_template_compare (IdeProjectTemplate *a,
IdeProjectTemplate *b);
G_END_DECLS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment