gedit-style-scheme-dialog.c 6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * gedit-style-scheme-dialog.c
 * This file is part of gedit
 *
 * Copyright (C) 2007 Paolo Borelli
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA 02111-1307, USA. 
 */

/*
 * Modified by the gedit Team, 2001-2003. See the AUTHORS file for a 
 * list of people on the gedit Team.  
 * See the ChangeLog files for a list of changes. 
 *
 * $Id: gedit-preferences-dialog.c 5645 2007-06-24 19:42:53Z pborelli $
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib/gi18n.h>

#include "gedit-style-scheme-dialog.h"
#include "gedit-utils.h"
#include "gedit-debug.h"
#include "gedit-help.h"
42
#include "gedit-dirs.h"
43 44 45 46 47 48 49 50 51

#define GEDIT_STYLE_SCHEME_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
						      GEDIT_TYPE_STYLE_SCHEME_DIALOG, \
						      GeditStyleSchemeDialogPrivate))

struct _GeditStyleSchemeDialogPrivate
{
	GeditStyleSchemeGenerator *generator;
	
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
	GtkWidget                 *scheme_name_entry;
	
	GtkWidget                 *normal_text_checkbutton;
	GtkWidget                 *normal_text_colorbutton;
	
	GtkWidget                 *background_checkbutton;
	GtkWidget                 *background_colorbutton;
	
	GtkWidget                 *selected_text_checkbutton;
	GtkWidget                 *selected_text_colorbutton;
	
	GtkWidget                 *selection_checkbutton;
	GtkWidget                 *selection_colorbutton;
	
	GtkWidget                 *current_line_checkbutton;
	GtkWidget                 *current_line_colorbutton;
	
	GtkWidget                 *search_hl_checkbutton;
	GtkWidget                 *search_hl_colorbutton;
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
};


G_DEFINE_TYPE(GeditStyleSchemeDialog, gedit_style_scheme_dialog, GTK_TYPE_DIALOG)


static void
gedit_style_scheme_dialog_finalize (GObject *object)
{
	GeditStyleSchemeDialog *dlg = GEDIT_STYLE_SCHEME_DIALOG (object);
	
	g_object_unref (dlg->priv->generator); 
	
	G_OBJECT_CLASS (gedit_style_scheme_dialog_parent_class)->finalize (object);
}

static void 
gedit_style_scheme_dialog_class_init (GeditStyleSchemeDialogClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->finalize = gedit_style_scheme_dialog_finalize;

	g_type_class_add_private (object_class, sizeof(GeditStyleSchemeDialogPrivate));
}

static void
dialog_response_handler (GtkDialog *dlg,
			 gint       res_id)
{
	gedit_debug (DEBUG_PREFS);

	switch (res_id)
	{
		case GTK_RESPONSE_HELP:
			gedit_help_display (GTK_WINDOW (dlg),
107
					    NULL,
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
					    "gedit-prefs"); // FIXME

			g_signal_stop_emission_by_name (dlg, "response");

			break;

		default:
			gtk_widget_destroy (GTK_WIDGET(dlg));
	}
}

static void
gedit_style_scheme_dialog_init (GeditStyleSchemeDialog *dlg)
{
	GtkWidget *error_widget;
123
	GtkWidget *main_vbox;
124
	gboolean ret;
125
	gchar *file;
126 127 128 129 130
	gchar *root_objects[] = {
		"contents",
		NULL
	};
	
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	gedit_debug (DEBUG_PREFS);

	dlg->priv = GEDIT_STYLE_SCHEME_DIALOG_GET_PRIVATE (dlg);

	gtk_dialog_add_buttons (GTK_DIALOG (dlg),
				GTK_STOCK_CLOSE,
				GTK_RESPONSE_CLOSE,
				GTK_STOCK_HELP,
				GTK_RESPONSE_HELP,
				NULL);

	gtk_window_set_title (GTK_WINDOW (dlg), _("gedit Style Scheme editor"));
	gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
	gtk_dialog_set_has_separator (GTK_DIALOG (dlg), FALSE);
	gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE);

	g_signal_connect (dlg,
			  "response",
			  G_CALLBACK (dialog_response_handler),
			  NULL);

152 153
	file = gedit_dirs_get_ui_file ("gedit-style-scheme-dialog.ui");
	ret = gedit_utils_get_ui_objects (file,
154
		root_objects,
155
		&error_widget,
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
		
		"contents", &main_vbox,

		"scheme_name_entry", &dlg->priv->scheme_name_entry,

		"normal_text_checkbutton", &dlg->priv->normal_text_checkbutton,
		"normal_text_colorbutton", &dlg->priv->normal_text_colorbutton,

		"background_checkbutton", &dlg->priv->background_checkbutton,
		"background_colorbutton", &dlg->priv->background_colorbutton,

		"selected_text_checkbutton", &dlg->priv->selected_text_checkbutton,
		"selected_text_colorbutton", &dlg->priv->selected_text_colorbutton,

		"selection_checkbutton", &dlg->priv->selection_checkbutton,
		"selection_colorbutton", &dlg->priv->selection_colorbutton,
172

173 174 175 176 177
		"current_line_checkbutton", &dlg->priv->current_line_checkbutton,
		"current_line_colorbutton", &dlg->priv->current_line_colorbutton,

		"search_hl_checkbutton", &dlg->priv->search_hl_checkbutton,
		"search_hl_colorbutton", &dlg->priv->search_hl_colorbutton,
178 179

		NULL);
180
	g_free (file);
181 182 183 184 185

	if (!ret)
	{
		gtk_widget_show (error_widget);
			
186 187 188
		gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
		                    error_widget,
		                    TRUE, TRUE, 0);
189 190 191 192 193

		return;
	}

	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
194
			    main_vbox,
195
			    FALSE, FALSE, 0);
196
	g_objet_unref (main_vbox);
197 198
}

199 200 201 202 203 204 205 206 207 208
static void
set_generator (GeditStyleSchemeDialog    *dlg, 
	       GeditStyleSchemeGenerator *generator)
{
	dlg->priv->generator = g_object_ref (generator);
	
	gtk_entry_set_text (GTK_ENTRY (dlg->priv->scheme_name_entry),
			    gedit_style_scheme_generator_get_scheme_name (dlg->priv->generator));
}

209 210 211 212 213
GtkWidget *
gedit_style_scheme_dialog_new (GeditStyleSchemeGenerator *generator)
{
	GeditStyleSchemeDialog *dlg;
	
214
	g_return_val_if_fail (GEDIT_IS_STYLE_SCHEME_GENERATOR (generator), NULL);
215
	
216
	dlg = GEDIT_STYLE_SCHEME_DIALOG (g_object_new (GEDIT_TYPE_STYLE_SCHEME_DIALOG, NULL));
217
	
218 219
	set_generator (dlg, generator);

220 221
	return GTK_WIDGET (dlg);
}
222
/* ex:ts=8:noet: */