Ejemplo n.º 1
0
void
edit_syntax_dialog (void) {
    char *old_syntax_type;
    int old_auto_syntax, syntax;
    char **names;
    int i;
    int force_reload = 0;
    int count = 0;

    names = (char**) g_malloc (sizeof (char*));
    names[0] = NULL;
    /* We fill the list of syntax files every time the editor is invoked.
       Instead we could save the list to a file and update it once the syntax
       file gets updated (either by testing or by explicit user command). */
    edit_load_syntax (NULL, &names, NULL);
    while (names[count++] != NULL);
    qsort(names, count - 1, sizeof(char*), pstrcmp);

    if ((syntax = exec_edit_syntax_dialog ((const char**) names)) < 0) {
	for (i = 0; names[i]; i++) {
	    g_free (names[i]);
	}
	g_free (names);
	return;
    }

    old_auto_syntax = option_auto_syntax;
    old_syntax_type = g_strdup (option_syntax_type);

    switch (syntax) {
	case 0: /* auto syntax */
	    option_auto_syntax = 1;
	    break;
	case 1: /* reload current syntax */
	    force_reload = 1;
	    break;
	default:
	    option_auto_syntax = 0;
	    g_free (option_syntax_type);
	    option_syntax_type = g_strdup (names[syntax - N_DFLT_ENTRIES]);
    }

    /* Load or unload syntax rules if the option has changed */
    if ((option_auto_syntax && !old_auto_syntax) || old_auto_syntax ||
	(old_syntax_type && option_syntax_type &&
	(strcmp (old_syntax_type, option_syntax_type) != 0)) ||
	force_reload)
	edit_load_syntax (wedit, NULL, option_syntax_type);

    for (i = 0; names[i]; i++) {
	g_free (names[i]);
    }
    g_free (names);
    g_free (old_syntax_type);
}
Ejemplo n.º 2
0
void
edit_syntax_dialog (WEdit * edit)
{
    GPtrArray *names;
    int syntax;

    names = g_ptr_array_new ();

    /* We fill the list of syntax files every time the editor is invoked.
       Instead we could save the list to a file and update it once the syntax
       file gets updated (either by testing or by explicit user command). */
    edit_load_syntax (NULL, names, NULL);
    g_ptr_array_sort (names, pstrcmp);

    syntax = exec_edit_syntax_dialog (names, edit->syntax_type);
    if (syntax >= 0)
    {
        gboolean force_reload = FALSE;
        char *current_syntax;
        int old_auto_syntax;

        current_syntax = g_strdup (edit->syntax_type);
        old_auto_syntax = option_auto_syntax;

        switch (syntax)
        {
        case 0:                /* auto syntax */
            option_auto_syntax = 1;
            break;
        case 1:                /* reload current syntax */
            force_reload = TRUE;
            break;
        default:
            option_auto_syntax = 0;
            g_free (edit->syntax_type);
            edit->syntax_type = g_strdup (g_ptr_array_index (names, syntax - N_DFLT_ENTRIES));
        }

        /* Load or unload syntax rules if the option has changed */
        if (force_reload || (option_auto_syntax && !old_auto_syntax) || old_auto_syntax ||
            (current_syntax != NULL && edit->syntax_type != NULL &&
             strcmp (current_syntax, edit->syntax_type) != 0))
            edit_load_syntax (edit, NULL, edit->syntax_type);

        g_free (current_syntax);
    }

    g_ptr_array_foreach (names, (GFunc) g_free, NULL);
    g_ptr_array_free (names, TRUE);
}
Ejemplo n.º 3
0
static void
edit_reload_syntax (void *data, void *user_data)
{
    (void) user_data;

    if (edit_widget_is_editor (WIDGET (data)))
    {
        WEdit *edit = (WEdit *) data;
        edit_load_syntax (edit, NULL, edit->syntax_type);
    }
}