Commit 699ad10f authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Allow to use the selected font in the text editor (bug #170299):

2005-06-11  Michael Natterer  <mitch@gimp.org>

	Allow to use the selected font in the text editor (bug #170299):

	* app/widgets/gimptexteditor.[ch]: added a "Use selected font"
	toggle and an API to set/get the selected font name.

	* app/tools/gimptextoptions.c: update the editor's font when the
	text option's font changes. Renamed text editor callbacks to
	gimp_text_options_editor_foo().
parent b7b5e156
2005-06-11 Michael Natterer <mitch@gimp.org>
Allow to use the selected font in the text editor (bug #170299):
* app/widgets/gimptexteditor.[ch]: added a "Use selected font"
toggle and an API to set/get the selected font name.
* app/tools/gimptextoptions.c: update the editor's font when the
text option's font changes. Renamed text editor callbacks to
gimp_text_options_editor_foo().
2005-06-10 Michael Natterer <mitch@gimp.org>
* configure.in: don't try to generate tips/Makefile.
......
......@@ -513,8 +513,8 @@ gimp_text_options_gui (GimpToolOptions *tool_options)
}
static void
gimp_text_options_dir_changed (GimpTextEditor *editor,
GimpTextOptions *options)
gimp_text_options_editor_dir_changed (GimpTextEditor *editor,
GimpTextOptions *options)
{
g_object_set (options,
"base-direction", editor->base_dir,
......@@ -522,9 +522,9 @@ gimp_text_options_dir_changed (GimpTextEditor *editor,
}
static void
gimp_text_options_notify_dir (GimpTextOptions *options,
GParamSpec *pspec,
GimpTextEditor *editor)
gimp_text_options_editor_notify_dir (GimpTextOptions *options,
GParamSpec *pspec,
GimpTextEditor *editor)
{
GimpTextDirection dir;
......@@ -535,12 +535,25 @@ gimp_text_options_notify_dir (GimpTextOptions *options,
gimp_text_editor_set_direction (editor, dir);
}
static void
gimp_text_options_editor_notify_font (GimpTextOptions *options,
GParamSpec *pspec,
GimpTextEditor *editor)
{
const gchar *font_name;
font_name = gimp_context_get_font_name (GIMP_CONTEXT (options));
gimp_text_editor_set_font_name (editor, font_name);
}
GtkWidget *
gimp_text_options_editor_new (GimpTextOptions *options,
GimpMenuFactory *menu_factory,
const gchar *title)
{
GtkWidget *editor;
GtkWidget *editor;
const gchar *font_name;
g_return_val_if_fail (GIMP_IS_TEXT_OPTIONS (options), NULL);
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL);
......@@ -548,14 +561,21 @@ gimp_text_options_editor_new (GimpTextOptions *options,
editor = gimp_text_editor_new (title, menu_factory);
font_name = gimp_context_get_font_name (GIMP_CONTEXT (options));
gimp_text_editor_set_direction (GIMP_TEXT_EDITOR (editor),
options->base_dir);
gimp_text_editor_set_font_name (GIMP_TEXT_EDITOR (editor),
font_name);
g_signal_connect_object (editor, "dir-changed",
G_CALLBACK (gimp_text_options_dir_changed),
G_CALLBACK (gimp_text_options_editor_dir_changed),
options, 0);
g_signal_connect_object (options, "notify::base-direction",
G_CALLBACK (gimp_text_options_notify_dir),
G_CALLBACK (gimp_text_options_editor_notify_dir),
editor, 0);
g_signal_connect_object (options, "notify::font",
G_CALLBACK (gimp_text_options_editor_notify_font),
editor, 0);
return editor;
......
......@@ -48,8 +48,12 @@ enum
static void gimp_text_editor_class_init (GimpTextEditorClass *klass);
static void gimp_text_editor_init (GimpTextEditor *editor);
static void gimp_text_editor_finalize (GObject *object);
static void gimp_text_editor_text_changed (GtkTextBuffer *buffer,
GimpTextEditor *editor);
static void gimp_text_editor_font_toggled (GtkToggleButton *button,
GimpTextEditor *editor);
static GimpDialogClass *parent_class = NULL;
......@@ -87,8 +91,12 @@ gimp_text_editor_get_type (void)
static void
gimp_text_editor_class_init (GimpTextEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_text_editor_finalize;
text_editor_signals[TEXT_CHANGED] =
g_signal_new ("text-changed",
G_TYPE_FROM_CLASS (klass),
......@@ -112,7 +120,7 @@ gimp_text_editor_class_init (GimpTextEditorClass *klass)
}
static void
gimp_text_editor_init (GimpTextEditor *editor)
gimp_text_editor_init (GimpTextEditor *editor)
{
editor->view = NULL;
editor->file_dialog = NULL;
......@@ -130,6 +138,20 @@ gimp_text_editor_init (GimpTextEditor *editor)
}
}
static void
gimp_text_editor_finalize (GObject *object)
{
GimpTextEditor *editor = GIMP_TEXT_EDITOR (object);
if (editor->font_name)
g_free (editor->font_name);
if (editor->ui_manager)
g_object_unref (editor->ui_manager);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/* public functions */
......@@ -204,6 +226,16 @@ gimp_text_editor_new (const gchar *title,
gtk_widget_set_size_request (editor->view, 128, 64);
editor->font_toggle =
gtk_check_button_new_with_mnemonic (_("_Use selected font"));
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (editor)->vbox),
editor->font_toggle, FALSE, FALSE, 0);
gtk_widget_show (editor->font_toggle);
g_signal_connect (editor->font_toggle, "toggled",
G_CALLBACK (gimp_text_editor_font_toggled),
editor);
gtk_widget_grab_focus (editor->view);
gimp_ui_manager_update (editor->ui_manager, editor);
......@@ -282,6 +314,39 @@ gimp_text_editor_get_direction (GimpTextEditor *editor)
return editor->base_dir;
}
void
gimp_text_editor_set_font_name (GimpTextEditor *editor,
const gchar *font_name)
{
g_return_if_fail (GIMP_IS_TEXT_EDITOR (editor));
if (editor->font_name)
g_free (editor->font_name);
editor->font_name = g_strdup (font_name);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->font_toggle)))
{
PangoFontDescription *font_desc = NULL;
if (font_name)
font_desc = pango_font_description_from_string (font_name);
gtk_widget_modify_font (editor->view, font_desc);
if (font_desc)
pango_font_description_free (font_desc);
}
}
const gchar *
gimp_text_editor_get_font_name (GimpTextEditor *editor)
{
g_return_val_if_fail (GIMP_IS_TEXT_EDITOR (editor), NULL);
return editor->font_name;
}
/* private functions */
......@@ -291,3 +356,18 @@ gimp_text_editor_text_changed (GtkTextBuffer *buffer,
{
g_signal_emit (editor, text_editor_signals[TEXT_CHANGED], 0);
}
static void
gimp_text_editor_font_toggled (GtkToggleButton *button,
GimpTextEditor *editor)
{
PangoFontDescription *font_desc = NULL;
if (gtk_toggle_button_get_active (button) && editor->font_name)
font_desc = pango_font_description_from_string (editor->font_name);
gtk_widget_modify_font (editor->view, font_desc);
if (font_desc)
pango_font_description_free (font_desc);
}
......@@ -36,7 +36,10 @@ struct _GimpTextEditor
/*< private >*/
GimpTextDirection base_dir;
gchar *font_name;
GtkWidget *view;
GtkWidget *font_toggle;
GtkWidget *file_dialog;
GimpUIManager *ui_manager;
};
......@@ -63,5 +66,9 @@ void gimp_text_editor_set_direction (GimpTextEditor *editor,
GimpTextDirection base_dir);
GimpTextDirection gimp_text_editor_get_direction (GimpTextEditor *editor);
void gimp_text_editor_set_font_name (GimpTextEditor *editor,
const gchar *font_name);
const gchar * gimp_text_editor_get_font_name (GimpTextEditor *editor);
#endif /* __GIMP_TEXT_EDITOR_H__ */
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