示例#1
0
/* Return the font size in Pango units for the font size setting */
gint
get_font_size(PangoFontDescription *font)
{
	I7App *theapp = i7_app_get();
	double size = pango_font_description_get_size(font);

	if(pango_font_description_get_size_is_absolute(font))
		size *= 96.0 / 72.0; /* a guess; not likely to be absolute anyway */
	if(size == 0.0)
		size = DEFAULT_SIZE_STANDARD * PANGO_SCALE;

	switch(g_settings_get_enum(i7_app_get_prefs(theapp), PREFS_FONT_SIZE)) {
		case FONT_SIZE_MEDIUM:
			size *= RELATIVE_SIZE_MEDIUM;
			break;
		case FONT_SIZE_LARGE:
			size *= RELATIVE_SIZE_LARGE;
			break;
		case FONT_SIZE_HUGE:
			size *= RELATIVE_SIZE_HUGE;
			break;
		default:
			size *= RELATIVE_SIZE_STANDARD;
	}
	return size;
}
示例#2
0
/*
 * get_font_family:
 *
 * Return a font description for the font setting. Must be freed.
 */
static PangoFontDescription *
get_font_family(void)
{
	I7App *theapp = i7_app_get();
	GSettings *prefs = i7_app_get_prefs(theapp);

	switch(g_settings_get_enum(prefs, PREFS_FONT_SET)) {
		case FONT_MONOSPACE:
			return get_desktop_monospace_font();
		case FONT_CUSTOM:
		{
			char *customfont = g_settings_get_string(prefs, PREFS_CUSTOM_FONT);
			PangoFontDescription *retval;
			if(customfont) {
				retval = pango_font_description_from_string(customfont);
				g_free(customfont);
				return retval;
			}
			/* else fall through */
		}
		default:
			;
	}
	return get_desktop_standard_font();
}
示例#3
0
void
populate_schemes_list(GtkListStore *list)
{
	I7App *theapp = i7_app_get();
	GSettings *prefs = i7_app_get_prefs(theapp);
	gtk_list_store_clear(list);
	i7_app_foreach_color_scheme(theapp, (GFunc)store_color_scheme, list);
	select_style_scheme(theapp->prefs->schemes_view, g_settings_get_string(prefs, PREFS_STYLE_SCHEME));
}
/**
 * i7_app_get_current_color_scheme:
 * @self: the app
 *
 * Get the appropriate color scheme for the current settings.
 *
 * Returns: (transfer none): the appropriate #GtkSourceStyleScheme.
 */
GtkSourceStyleScheme *
i7_app_get_current_color_scheme(I7App *self)
{
	I7_APP_USE_PRIVATE(self, priv);
	GSettings *prefs = i7_app_get_prefs(self);
	gchar *scheme_name = g_settings_get_string(prefs, PREFS_STYLE_SCHEME);
	GtkSourceStyleScheme *scheme = gtk_source_style_scheme_manager_get_scheme(priv->color_scheme_manager, scheme_name);
	g_free(scheme_name);
	return scheme;
}
示例#5
0
static void
on_config_custom_font_changed(GSettings *settings, const char *key)
{
	/* update application to reflect new value */
	I7App *theapp = i7_app_get();
	GSettings *prefs = i7_app_get_prefs(theapp);
	if(g_settings_get_enum(prefs, PREFS_FONT_SET) == FONT_CUSTOM) {
		update_font(GTK_WIDGET(theapp->prefs->source_example));
		update_font(GTK_WIDGET(theapp->prefs->tab_example));
		i7_app_foreach_document(theapp, (I7DocumentForeachFunc)i7_document_update_fonts, NULL);
	}
}
示例#6
0
void
on_style_add_clicked(GtkButton *button, I7App *app)
{
	/* From gedit/dialogs/gedit-preferences-dialog.c */
	GtkWidget *chooser = gtk_file_chooser_dialog_new(_("Add Color Scheme"),
		GTK_WINDOW(app->prefs->window),	GTK_FILE_CHOOSER_ACTION_OPEN,
		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
		GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT,
		NULL);
	gtk_window_set_destroy_with_parent(GTK_WINDOW(chooser), TRUE);

	/* Filters */
	GtkFileFilter *filter = gtk_file_filter_new();
	gtk_file_filter_set_name(filter, _("Color Scheme Files"));
	gtk_file_filter_add_pattern(filter, "*.xml");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), filter);
	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(chooser), filter);

	filter = gtk_file_filter_new();
	gtk_file_filter_set_name(filter, _("All Files"));
	gtk_file_filter_add_pattern(filter, "*");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), filter);

	gtk_dialog_set_default_response(GTK_DIALOG(chooser), GTK_RESPONSE_ACCEPT);

	if(gtk_dialog_run(GTK_DIALOG(chooser)) != GTK_RESPONSE_ACCEPT) {
		gtk_widget_destroy(chooser);
		return;
	}

	GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(chooser));
	if(!file)
		return;

	gtk_widget_destroy(chooser);

	const char *scheme_id = i7_app_install_color_scheme(app, file);
	g_object_unref(file);

	if(!scheme_id) {
		error_dialog(GTK_WINDOW(app->prefs->window), NULL, _("The selected color scheme cannot be installed."));
		return;
	}

	populate_schemes_list(app->prefs->schemes_list);

	I7App *theapp = i7_app_get();
	GSettings *prefs = i7_app_get_prefs(theapp);
	g_settings_set_string(prefs, PREFS_STYLE_SCHEME, scheme_id);
}
示例#7
0
void
on_styles_list_cursor_changed(GtkTreeView *view, I7App *app)
{
	GtkTreeSelection *selection = gtk_tree_view_get_selection(view);
	GtkTreeIter iter;
	GtkTreeModel *model;
	if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
		I7App *theapp = i7_app_get();
		GSettings *prefs = i7_app_get_prefs(theapp);
		gchar *id;
		gtk_tree_model_get(model, &iter, ID_COLUMN, &id, -1);
		g_settings_set_string(prefs, PREFS_STYLE_SCHEME, id);
		gtk_widget_set_sensitive(app->prefs->style_remove, id && i7_app_color_scheme_is_user_scheme(i7_app_get(), id));
		g_free(id);
	} else
		; /* Do nothing; no selection */
}
示例#8
0
/* Callback for beginning the print operation, we give the printed pages our
 tab width from the preferences, and the margins from the page setup dialog. */
static void
on_begin_print(GtkPrintOperation *print, GtkPrintContext *context,
	I7Document *document)
{
	I7App *theapp = i7_app_get();
	GSettings *prefs = i7_app_get_prefs(theapp);
	GtkSourcePrintCompositor *compositor = gtk_source_print_compositor_new(i7_document_get_buffer(document));
	g_signal_connect(print, "draw-page", G_CALLBACK(on_draw_page), compositor);
	g_signal_connect(print, "end-print", G_CALLBACK(on_end_print), compositor);

	/* Design our printed page */
	unsigned tabwidth = g_settings_get_uint(prefs, PREFS_TAB_WIDTH);
	if(tabwidth == 0)
		tabwidth = DEFAULT_TAB_WIDTH;
	gtk_source_print_compositor_set_tab_width(compositor, tabwidth);
	gtk_source_print_compositor_set_wrap_mode(compositor, GTK_WRAP_WORD_CHAR);
	PangoFontDescription *font = get_font_description();
	gchar *fontstring = pango_font_description_to_string(font);
	pango_font_description_free(font);
	gtk_source_print_compositor_set_body_font_name(compositor, fontstring);
	g_free(fontstring);
	GtkPageSetup *setup = i7_app_get_page_setup(i7_app_get());
	gtk_source_print_compositor_set_top_margin(compositor, gtk_page_setup_get_top_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM);
	gtk_source_print_compositor_set_bottom_margin(compositor, gtk_page_setup_get_bottom_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM);
	gtk_source_print_compositor_set_left_margin(compositor, gtk_page_setup_get_left_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM);
	gtk_source_print_compositor_set_right_margin(compositor, gtk_page_setup_get_right_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM);

	/* Display a notification in the status bar while paginating */
	i7_document_display_status_message(document, _("Paginating..."), PRINT_OPERATIONS);
	while(!gtk_source_print_compositor_paginate(compositor, context)) {
		i7_document_display_progress_percentage(document, gtk_source_print_compositor_get_pagination_progress(compositor));
		while(gtk_events_pending())
			gtk_main_iteration();
	}
	i7_document_display_progress_percentage(document, 0.0);
	i7_document_remove_status_message(document, PRINT_OPERATIONS);

	gtk_print_operation_set_n_pages(print, gtk_source_print_compositor_get_n_pages(compositor));
}
示例#9
0
/* Update the tab stops for a GtkSourceView */
gboolean
update_tabs(GtkSourceView *view)
{
	I7App *theapp = i7_app_get();
	GSettings *prefs = i7_app_get_prefs(theapp);
	unsigned spaces = g_settings_get_uint(prefs, PREFS_TAB_WIDTH);
	if(spaces == 0)
		spaces = DEFAULT_TAB_WIDTH;
	gtk_source_view_set_tab_width(view, spaces);

	/* Set the hanging indent on wrapped lines to be a number of pixels equal
	 * to twice the number of spaces in a tab; i.e. we estimate a space to be
	 * four pixels. Not always true, but close enough.*/
	gboolean indent_wrapped = g_settings_get_boolean(prefs, PREFS_INDENT_WRAPPED);
	if(!indent_wrapped)
		spaces = 0;
	g_object_set(view,
	    "indent", -2 * spaces,
	    NULL);

	return FALSE; /* one-shot idle function */
}
示例#10
0
void
on_style_remove_clicked(GtkButton *button, I7App *app)
{
	GtkTreeSelection *selection = gtk_tree_view_get_selection(app->prefs->schemes_view);
	GtkTreeModel *model;
	GtkTreeIter iter;
	if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
		gchar *id;
		gchar *name;
		gtk_tree_model_get(model, &iter,
			ID_COLUMN, &id,
			NAME_COLUMN, &name,
			-1);

		if(!i7_app_uninstall_color_scheme(app, id))
			error_dialog(GTK_WINDOW(app->prefs->window), NULL, _("Could not remove color scheme \"%s\"."), name);
		else {
			gchar *new_id = NULL;
			GtkTreeIter new_iter;
			gboolean new_iter_set = FALSE;

			/* If the removed style scheme is the last of the list, set as new
			 default style scheme the previous one, otherwise set the next one.
			 To make this possible, we need to get the id of the new default
			 style scheme before re-populating the list. */
			GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
			/* Try to move to the next path */
			gtk_tree_path_next(path);
			if(!gtk_tree_model_get_iter(model, &new_iter, path)) {
				/* It seems the removed style scheme was the last of the list.
				 Try to move to the previous one */
				gtk_tree_path_free(path);
				path = gtk_tree_model_get_path(model, &iter);
				gtk_tree_path_prev(path);
				if(gtk_tree_model_get_iter(model, &new_iter, path))
					new_iter_set = TRUE;
			}
			else
				new_iter_set = TRUE;
			gtk_tree_path_free(path);

			if(new_iter_set)
				gtk_tree_model_get(model, &new_iter,
					ID_COLUMN, &new_id,
					-1);

			if(!new_id)
				new_id = g_strdup("inform");

			populate_schemes_list(app->prefs->schemes_list);

			I7App *theapp = i7_app_get();
			GSettings *prefs = i7_app_get_prefs(theapp);
			g_settings_set(prefs, PREFS_STYLE_SCHEME, new_id);

			g_free(new_id);
		}
		g_free(id);
		g_free(name);
	}
}
示例#11
0
/* Display any errors from the NI compiler and continue on. This function is
 called from a child process watch, so the GDK lock is not held and must be
 acquired for any GUI calls. */
static void
finish_ni_compiler(GPid pid, gint status, CompilerData *data)
{
    I7_STORY_USE_PRIVATE(data->story, priv);
    I7App *theapp = i7_app_get();
    GSettings *prefs = i7_app_get_prefs(theapp);

    /* Clear the progress indicator */
    gdk_threads_enter();
    i7_document_remove_status_message(I7_DOCUMENT(data->story), COMPILE_OPERATIONS);
    i7_document_clear_progress(I7_DOCUMENT(data->story));
    gdk_threads_leave();

    /* Get the ni.exe exit code */
    int exit_code = WIFEXITED(status)? WEXITSTATUS(status) : -1;

    /* Display the appropriate HTML error or success page */
    GFile *problems_file = NULL;
    if(exit_code <= 1) {
        /* In the case of success or a "normal" failure, or a negative error
         code should one occur, display the compiler's generated Problems.html*/
        problems_file = g_file_get_child(data->builddir_file, "Problems.html");
    } else {
        gchar *file = g_strdup_printf("Error%i.html", exit_code);
        problems_file = i7_app_check_data_file_va(theapp, "Resources", "en", file, NULL);
        g_free(file);
        if(!problems_file)
            problems_file = i7_app_get_data_file_va(theapp, "Resources", "en", "Error0.html", NULL);
    }

    g_clear_object(&data->results_file);
    data->results_file = problems_file; /* assumes reference */

    if(g_settings_get_boolean(prefs, PREFS_SHOW_DEBUG_LOG)) {
        /* Update */
        gdk_threads_enter();
        while(gtk_events_pending())
            gtk_main_iteration();
        gdk_threads_leave();

        /* Refresh the debug log */
        gchar *text;
        GFile *debug_file = g_file_get_child(data->builddir_file, "Debug log.txt");
        /* Ignore errors, just don't show it if it's not there */
        if(g_file_load_contents(debug_file, NULL, &text, NULL, NULL, NULL)) {
            gdk_threads_enter();
            gtk_text_buffer_set_text(priv->debug_log, text, -1);
            gdk_threads_leave();
            g_free(text);
        }
        g_object_unref(debug_file);

        /* Refresh the I6 code */
        GFile *i6_file = g_file_get_child(data->builddir_file, "auto.inf");
        if(g_file_load_contents(i6_file, NULL, &text, NULL, NULL, NULL)) {
            gdk_threads_enter();
            gtk_text_buffer_set_text(GTK_TEXT_BUFFER(priv->i6_source), text, -1);
            gdk_threads_leave();
            g_free(text);
        }
        g_object_unref(i6_file);
    }

    /* Stop here and show the Results/Report tab if there was an error */
    if(exit_code != 0) {
        finish_compiling(FALSE, data);
        return;
    }

    /* Reload the Index in the background */
    i7_story_reload_index_tabs(data->story, FALSE);

    /* Read in the Blorb manifest */
    GFile *file = i7_document_get_file(I7_DOCUMENT(data->story));
    GFile *manifest_file = g_file_get_child(file, "manifest.plist");
    g_object_unref(file);
    PlistObject *manifest = plist_read_file(manifest_file, NULL, NULL);
    g_object_unref(manifest_file);
    /* If that failed, then silently keep the old manifest */
    if(manifest) {
        plist_object_free(priv->manifest);
        priv->manifest = manifest;
    }

    /* Decide what to do next */
    if(data->refresh_only) {
        I7Story *story = data->story;
        finish_compiling(TRUE, data);
        /* Hold the GDK lock for the callback */
        gdk_threads_enter();
        (priv->compile_finished_callback)(story, priv->compile_finished_callback_data);
        gdk_threads_leave();
        return;
    }

    prepare_i6_compiler(data);
    start_i6_compiler(data);
}