Remove filetypes array from API.
Replace filetypes_get_from_uid() with filetypes_lookup_by_name(). Use a hash table for filetypes, but keep the old filetypes array available for now. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-filetypes@2538 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
676d7ca071
commit
5340f2b9c8
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
2008-04-28 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
||||
* src/plugindata.h, src/filetypes.c, src/filetypes.h, src/plugins.c,
|
||||
plugins/vcdiff.c:
|
||||
Remove filetypes array from API.
|
||||
Replace filetypes_get_from_uid() with filetypes_lookup_by_name().
|
||||
Use a hash table for filetypes, but keep the old filetypes array
|
||||
available for now.
|
||||
|
||||
|
||||
2008-04-27 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
||||
* configure.in, tagmanager/lregex.c, tagmanager/include/regex.h,
|
||||
|
||||
@ -286,8 +286,8 @@ static void show_output(const gchar *std_output, const gchar *name_prefix,
|
||||
idx = find_by_filename(filename);
|
||||
if ( idx == -1)
|
||||
{
|
||||
idx = p_document->new_file(filename,
|
||||
geany_data->filetypes[GEANY_FILETYPES_DIFF], text);
|
||||
filetype *ft = p_filetypes->lookup_by_name("Diff");
|
||||
idx = p_document->new_file(filename, ft, text);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
133
src/filetypes.c
133
src/filetypes.c
@ -39,7 +39,10 @@
|
||||
#include "sciwrappers.h"
|
||||
|
||||
|
||||
filetype *filetypes[GEANY_MAX_FILE_TYPES];
|
||||
GHashTable *filetypes_hash = NULL; /**< Array of filetype pointers */
|
||||
|
||||
/* built-in filetypes only */
|
||||
filetype *builtin_filetypes[GEANY_MAX_FILE_TYPES] = {NULL};
|
||||
|
||||
|
||||
/* This is the order of unique ids used in the config file.
|
||||
@ -88,18 +91,8 @@ static GtkWidget *radio_items[GEANY_MAX_FILE_TYPES];
|
||||
static void filetypes_create_menu_item(GtkWidget *menu, const gchar *label, filetype *ftype);
|
||||
|
||||
|
||||
/* Create the filetype array and fill it with the known filetypes. */
|
||||
void filetypes_init_types()
|
||||
static void fill_filetypes(void)
|
||||
{
|
||||
filetype_id ft_id;
|
||||
|
||||
for (ft_id = 0; ft_id < GEANY_MAX_FILE_TYPES; ft_id++)
|
||||
{
|
||||
filetypes[ft_id] = g_new0(filetype, 1);
|
||||
filetypes[ft_id]->programs = g_new0(struct build_programs, 1);
|
||||
filetypes[ft_id]->actions = g_new0(struct build_actions, 1);
|
||||
}
|
||||
|
||||
#define C /* these macros are only to ease navigation */
|
||||
filetypes[GEANY_FILETYPES_C]->id = GEANY_FILETYPES_C;
|
||||
filetypes[GEANY_FILETYPES_C]->uid = FILETYPE_UID_C;
|
||||
@ -487,6 +480,38 @@ void filetypes_init_types()
|
||||
}
|
||||
|
||||
|
||||
static void create_builtin_filetypes(void)
|
||||
{
|
||||
filetype_id ft_id;
|
||||
|
||||
for (ft_id = 0; ft_id < GEANY_MAX_FILE_TYPES; ft_id++)
|
||||
{
|
||||
filetypes[ft_id] = g_new0(filetype, 1);
|
||||
filetypes[ft_id]->programs = g_new0(struct build_programs, 1);
|
||||
filetypes[ft_id]->actions = g_new0(struct build_actions, 1);
|
||||
}
|
||||
fill_filetypes();
|
||||
}
|
||||
|
||||
|
||||
/* Create the filetype array and fill it with the known filetypes. */
|
||||
void filetypes_init_types()
|
||||
{
|
||||
filetype_id ft_id;
|
||||
|
||||
g_return_if_fail(filetypes_hash == NULL);
|
||||
|
||||
create_builtin_filetypes();
|
||||
|
||||
filetypes_hash = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
|
||||
for (ft_id = 0; ft_id < GEANY_MAX_FILE_TYPES; ft_id++)
|
||||
{
|
||||
filetypes_add(filetypes[ft_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define create_sub_menu(menu, item, title) \
|
||||
(menu) = gtk_menu_new(); \
|
||||
(item) = gtk_menu_item_new_with_mnemonic((title)); \
|
||||
@ -765,32 +790,38 @@ static void filetypes_create_menu_item(GtkWidget *menu, const gchar *label, file
|
||||
}
|
||||
|
||||
|
||||
static void free_filetype(G_GNUC_UNUSED gpointer key, gpointer value,
|
||||
G_GNUC_UNUSED gpointer user_data)
|
||||
{
|
||||
filetype *ft = value;
|
||||
|
||||
g_return_if_fail(ft != NULL);
|
||||
|
||||
g_free(ft->name);
|
||||
g_free(ft->title);
|
||||
g_free(ft->extension);
|
||||
g_free(ft->comment_open);
|
||||
g_free(ft->comment_close);
|
||||
g_free(ft->context_action_cmd);
|
||||
g_free(ft->programs->compiler);
|
||||
g_free(ft->programs->linker);
|
||||
g_free(ft->programs->run_cmd);
|
||||
g_free(ft->programs->run_cmd2);
|
||||
g_free(ft->programs);
|
||||
g_free(ft->actions);
|
||||
|
||||
g_strfreev(ft->pattern);
|
||||
g_free(ft);
|
||||
}
|
||||
|
||||
|
||||
/* frees the array and all related pointers */
|
||||
void filetypes_free_types()
|
||||
{
|
||||
gint i;
|
||||
g_return_if_fail(filetypes_hash != NULL);
|
||||
|
||||
for(i = 0; i < GEANY_MAX_FILE_TYPES; i++)
|
||||
{
|
||||
if (filetypes[i])
|
||||
{
|
||||
g_free(filetypes[i]->name);
|
||||
g_free(filetypes[i]->title);
|
||||
g_free(filetypes[i]->extension);
|
||||
g_free(filetypes[i]->comment_open);
|
||||
g_free(filetypes[i]->comment_close);
|
||||
g_free(filetypes[i]->context_action_cmd);
|
||||
g_free(filetypes[i]->programs->compiler);
|
||||
g_free(filetypes[i]->programs->linker);
|
||||
g_free(filetypes[i]->programs->run_cmd);
|
||||
g_free(filetypes[i]->programs->run_cmd2);
|
||||
g_free(filetypes[i]->programs);
|
||||
g_free(filetypes[i]->actions);
|
||||
|
||||
g_strfreev(filetypes[i]->pattern);
|
||||
g_free(filetypes[i]);
|
||||
}
|
||||
}
|
||||
g_hash_table_foreach(filetypes_hash, free_filetype, NULL);
|
||||
g_hash_table_destroy(filetypes_hash);
|
||||
}
|
||||
|
||||
|
||||
@ -1040,3 +1071,37 @@ gboolean filetype_has_tags(filetype *ft)
|
||||
}
|
||||
|
||||
|
||||
/* Add a filetype pointer to the list of available filetypes. */
|
||||
void filetypes_add(filetype *ft)
|
||||
{
|
||||
g_return_if_fail(ft);
|
||||
g_return_if_fail(ft->name);
|
||||
|
||||
g_hash_table_insert(filetypes_hash, ft->name, ft);
|
||||
}
|
||||
|
||||
|
||||
/* Remove a filetype pointer from the list of available filetypes. */
|
||||
void filetypes_remove(filetype *ft)
|
||||
{
|
||||
g_return_if_fail(ft);
|
||||
|
||||
if (!g_hash_table_remove(filetypes_hash, ft))
|
||||
g_warning("Could not remove filetype %p!", ft);
|
||||
}
|
||||
|
||||
|
||||
/** Find a filetype pointer from its @c name field. */
|
||||
filetype *filetypes_lookup_by_name(const gchar *name)
|
||||
{
|
||||
filetype *ft;
|
||||
|
||||
g_return_val_if_fail(NZV(name), NULL);
|
||||
|
||||
ft = g_hash_table_lookup(filetypes_hash, name);
|
||||
if (ft == NULL)
|
||||
g_warning("Could not find filetype '%s'!", name);
|
||||
return ft;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -121,7 +121,15 @@ struct filetype
|
||||
struct build_actions *actions;
|
||||
};
|
||||
|
||||
extern filetype *filetypes[GEANY_MAX_FILE_TYPES];
|
||||
#define filetypes builtin_filetypes
|
||||
extern filetype *builtin_filetypes[GEANY_MAX_FILE_TYPES];
|
||||
|
||||
|
||||
void filetypes_add(filetype *ft);
|
||||
|
||||
void filetypes_remove(filetype *ft);
|
||||
|
||||
filetype *filetypes_lookup_by_name(const gchar *name);
|
||||
|
||||
|
||||
/* If uid is valid, return corresponding filetype, otherwise NULL. */
|
||||
|
||||
@ -35,12 +35,12 @@
|
||||
|
||||
/* The API version should be incremented whenever any plugin data types below are
|
||||
* modified or appended to. */
|
||||
static const gint api_version = 53;
|
||||
static const gint api_version = 54;
|
||||
|
||||
/* The ABI version should be incremented whenever existing fields in the plugin
|
||||
* data types below have to be changed or reordered. It should stay the same if fields
|
||||
* are only appended, as this doesn't affect existing fields. */
|
||||
static const gint abi_version = 24;
|
||||
static const gint abi_version = 25;
|
||||
|
||||
/** Check the plugin can be loaded by Geany.
|
||||
* This performs runtime checks that try to ensure:
|
||||
@ -155,9 +155,8 @@ typedef struct GeanyData
|
||||
{
|
||||
GeanyApp *app; /**< Geany application data fields */
|
||||
GtkWidget *tools_menu; /**< Most plugins should add menu items to the Tools menu only */
|
||||
GArray *doc_array; /**< Dynamic array of document pointers */
|
||||
struct filetype **filetypes;
|
||||
struct GeanyPrefs *prefs;
|
||||
GArray *doc_array; /**< Dynamic array of document structs */
|
||||
struct GeanyPrefs *prefs; /* Note: this will be split up in future versions */
|
||||
struct EditorPrefs *editor_prefs; /**< Editor settings */
|
||||
struct BuildInfo *build_info; /**< Current build information */
|
||||
|
||||
@ -367,7 +366,7 @@ HighlightingFuncs;
|
||||
typedef struct FiletypeFuncs
|
||||
{
|
||||
filetype* (*detect_from_filename) (const gchar *utf8_filename);
|
||||
filetype* (*get_from_uid) (gint uid);
|
||||
filetype* (*lookup_by_name) (const gchar *name);
|
||||
}
|
||||
FiletypeFuncs;
|
||||
|
||||
|
||||
@ -227,7 +227,7 @@ static HighlightingFuncs highlighting_funcs = {
|
||||
|
||||
static FiletypeFuncs filetype_funcs = {
|
||||
&filetypes_detect_from_filename,
|
||||
&filetypes_get_from_uid
|
||||
&filetypes_lookup_by_name
|
||||
};
|
||||
|
||||
static NavQueueFuncs navqueue_funcs = {
|
||||
@ -241,7 +241,6 @@ static GeanyData geany_data = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
&doc_funcs,
|
||||
&sci_funcs,
|
||||
@ -267,7 +266,6 @@ geany_data_init(void)
|
||||
geany_data.app = app;
|
||||
geany_data.tools_menu = lookup_widget(app->window, "tools1_menu");
|
||||
geany_data.doc_array = doc_array;
|
||||
geany_data.filetypes = filetypes;
|
||||
geany_data.prefs = &prefs;
|
||||
geany_data.editor_prefs = &editor_prefs;
|
||||
geany_data.build_info = &build_info;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user