src/font-combo-menu.h
src/font-combo-menu-item.c
src/font-combo-menu-item.h
+src/font-history.c
+src/font-history.h
+src/font-history-model.c
+src/font-history-model.h
src/font-sample.c
src/font-sample.h
src/font-util.c
font-sample.h \
font-util.c \
font-util.h \
+ font-history.c \
+ font-history.h \
+ font-history-model.c \
+ font-history-model.h \
cairo-label-path.c \
cairo-label-path.h \
cairo-markup-path.c \
prefs-model.h \
font-util.c \
font-util.h \
+ font-history.c \
+ font-history.h \
+ font-history-model.c \
+ font-history-model.h \
str-util.c \
str-util.h \
color.c \
#include "font-combo-menu-item.h"
#include "font-util.h"
+#include "font-history.h"
#include "marshal.h"
struct _glFontComboMenuPrivate {
- gchar *font_family;
+ gchar *font_family;
+
+ GtkWidget *recent_menu_item;
+ GtkWidget *recent_sub_menu;
};
/* Local function prototypes */
/*===========================================*/
-static void gl_font_combo_menu_finalize (GObject *object);
+static void gl_font_combo_menu_finalize (GObject *object);
+
+static void menu_item_activate_cb (glFontComboMenuItem *item,
+ glFontComboMenu *this);
+
+static GtkWidget *new_font_sub_menu (glFontComboMenu *this,
+ const GList *list);
+
+static void font_history_changed_cb (glFontComboMenu *this);
-static void menu_item_activate_cb (glFontComboMenuItem *item,
- glFontComboMenu *this);
/****************************************************************************/
menu_item = gtk_separator_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
- menu_item = gtk_menu_item_new_with_label (_("Proportional fonts"));
+
+ menu_item = gtk_menu_item_new_with_label (_("Recent fonts"));
gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
- sub_menu = gtk_menu_new ();
+ list = gl_font_history_model_get_family_list (gl_font_history);
+ sub_menu = new_font_sub_menu (this, list);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
+ gtk_widget_set_sensitive (menu_item, list != NULL);
- list = gl_font_util_get_proportional_families ();
- for ( p = (GList *)list; p != NULL; p = p->next )
- {
- menu_item = gl_font_combo_menu_item_new (p->data);
- gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menu_item);
- g_signal_connect (menu_item, "activate",
- G_CALLBACK (menu_item_activate_cb), this);
- }
+ this->priv->recent_menu_item = menu_item;
+ this->priv->recent_sub_menu = sub_menu;
- menu_item = gtk_menu_item_new_with_label (_("Fixed-width fonts"));
+ menu_item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
+
+
+ menu_item = gtk_menu_item_new_with_label (_("Proportional fonts"));
gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
- sub_menu = gtk_menu_new ();
+ list = gl_font_util_get_proportional_families ();
+ sub_menu = new_font_sub_menu (this, list);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
+ gtk_widget_set_sensitive (menu_item, list != NULL);
+
+ menu_item = gtk_menu_item_new_with_label (_("Fixed-width fonts"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
list = gl_font_util_get_fixed_width_families ();
- for ( p = (GList *)list; p != NULL; p = p->next )
- {
- menu_item = gl_font_combo_menu_item_new (p->data);
- gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menu_item);
- g_signal_connect (menu_item, "activate",
- G_CALLBACK (menu_item_activate_cb), this);
- }
+ sub_menu = new_font_sub_menu (this, list);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
+ gtk_widget_set_sensitive (menu_item, list != NULL);
menu_item = gtk_menu_item_new_with_label (_("All fonts"));
gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
- sub_menu = gtk_menu_new ();
+ list = gl_font_util_get_all_families ();
+ sub_menu = new_font_sub_menu (this, list);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
+ gtk_widget_set_sensitive (menu_item, list != NULL);
- list = gl_font_util_get_all_families ();
- for ( p = (GList *)list; p != NULL; p = p->next )
- {
- menu_item = gl_font_combo_menu_item_new (p->data);
- gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menu_item);
- g_signal_connect (menu_item, "activate",
- G_CALLBACK (menu_item_activate_cb), this);
- }
+
+ gtk_widget_show_all (GTK_WIDGET (this));
+
+
+ g_signal_connect_swapped (gl_font_history, "changed",
+ G_CALLBACK (font_history_changed_cb), this);
}
}
+/*****************************************************************************/
+/* Create a new font sub menu from font list. */
+/*****************************************************************************/
+static GtkWidget *
+new_font_sub_menu (glFontComboMenu *this,
+ const GList *list)
+{
+ GtkWidget *menu;
+ GtkWidget *menu_item;
+ GList *p;
+
+ menu = gtk_menu_new ();
+
+ for ( p = (GList *)list; p != NULL; p = p->next )
+ {
+ menu_item = gl_font_combo_menu_item_new (p->data);
+ gtk_widget_show_all (menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ g_signal_connect (menu_item, "activate",
+ G_CALLBACK (menu_item_activate_cb), this);
+ }
+
+ gtk_widget_show (menu);
+ return menu;
+}
+
+
+/*****************************************************************************/
+/* Font history changed callback. */
+/*****************************************************************************/
+static void
+font_history_changed_cb (glFontComboMenu *this)
+{
+ const GList *list;
+
+ /*
+ * Remove old sub menu
+ */
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (this->priv->recent_menu_item),
+ NULL);
+
+ /*
+ * Build new sub menu
+ */
+ list = gl_font_history_model_get_family_list (gl_font_history);
+ this->priv->recent_sub_menu = new_font_sub_menu (this, list);
+
+ /*
+ * Attach to top-level menu item
+ */
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (this->priv->recent_menu_item),
+ this->priv->recent_sub_menu);
+ gtk_widget_set_sensitive (this->priv->recent_menu_item, list != NULL);
+}
+
+
/*
--- /dev/null
+/*
+ * font-history-model.c
+ * Copyright (C) 2009 Jim Evins <evins@snaught.com>.
+ *
+ * This file is part of gLabels.
+ *
+ * gLabels 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gLabels 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 gLabels. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "font-history-model.h"
+
+#include <libglabels/libglabels.h>
+#include "marshal.h"
+
+
+/*========================================================*/
+/* Private types. */
+/*========================================================*/
+
+/** GL_FONT_HISTORY_MODEL Private fields */
+struct _glFontHistoryModelPrivate {
+
+ guint max_n;
+
+ GList *family_list;
+};
+
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+
+/*========================================================*/
+/* Private globals. */
+/*========================================================*/
+
+static guint signals[LAST_SIGNAL] = {0};
+
+
+/*========================================================*/
+/* Private function prototypes. */
+/*========================================================*/
+
+static void gl_font_history_model_finalize (GObject *object);
+
+
+/*****************************************************************************/
+/* Object infrastructure. */
+/*****************************************************************************/
+G_DEFINE_TYPE (glFontHistoryModel, gl_font_history_model, G_TYPE_OBJECT);
+
+
+/*****************************************************************************/
+/* Class Init Function. */
+/*****************************************************************************/
+static void
+gl_font_history_model_class_init (glFontHistoryModelClass *class)
+{
+ GObjectClass *gobject_class = (GObjectClass *) class;
+
+ gl_font_history_model_parent_class = g_type_class_peek_parent (class);
+
+ gobject_class->finalize = gl_font_history_model_finalize;
+
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ G_OBJECT_CLASS_TYPE (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (glFontHistoryModelClass, changed),
+ NULL, NULL,
+ gl_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function. */
+/*****************************************************************************/
+static void
+gl_font_history_model_init (glFontHistoryModel *this)
+{
+ this->priv = g_new0 (glFontHistoryModelPrivate, 1);
+}
+
+
+/*****************************************************************************/
+/* Finalize Method. */
+/*****************************************************************************/
+static void
+gl_font_history_model_finalize (GObject *object)
+{
+ glFontHistoryModel *this;
+ GList *p;
+
+ g_return_if_fail (object && IS_GL_FONT_HISTORY_MODEL (object));
+ this = GL_FONT_HISTORY_MODEL (object);
+
+ for ( p = this->priv->family_list; p; p=p->next )
+ {
+ g_free (p->data);
+ }
+ g_list_free (this->priv->family_list);
+
+ g_free (this->priv);
+
+ G_OBJECT_CLASS (gl_font_history_model_parent_class)->finalize (object);
+}
+
+
+/*****************************************************************************/
+/** New Object Generator. */
+/*****************************************************************************/
+glFontHistoryModel *
+gl_font_history_model_new (guint n)
+{
+ glFontHistoryModel *this;
+
+ this = g_object_new (TYPE_GL_FONT_HISTORY_MODEL, NULL);
+
+ this->priv->max_n = n;
+
+ return this;
+}
+
+
+/*****************************************************************************/
+/* Add font to history. */
+/*****************************************************************************/
+void
+gl_font_history_model_add_family (glFontHistoryModel *this,
+ const gchar *family)
+{
+ GList *p;
+
+ /*
+ * If already in list, remove that entry.
+ */
+ p = g_list_find_custom (this->priv->family_list,
+ family,
+ (GCompareFunc)lgl_str_utf8_casecmp);
+ if (p)
+ {
+ this->priv->family_list =
+ g_list_remove_link (this->priv->family_list, p);
+ g_free (p->data);
+ g_list_free_1 (p);
+ }
+
+ /*
+ * Now prepend to list.
+ */
+ this->priv->family_list =
+ g_list_prepend (this->priv->family_list, g_strdup (family));
+
+ /*
+ * Truncate list to maximum size
+ */
+ while (g_list_length (this->priv->family_list) > this->priv->max_n)
+ {
+ p = g_list_last (this->priv->family_list);
+ this->priv->family_list =
+ g_list_remove_link (this->priv->family_list, p);
+ g_free (p->data);
+ g_list_free_1 (p);
+ }
+
+ g_signal_emit (G_OBJECT(this), signals[CHANGED], 0);
+}
+
+
+/*****************************************************************************/
+/* Get font. */
+/*****************************************************************************/
+const GList *
+gl_font_history_model_get_family_list (glFontHistoryModel *this)
+{
+ return this->priv->family_list;
+}
+
+
+
+/*
+ * Local Variables: -- emacs
+ * mode: C -- emacs
+ * c-basic-offset: 8 -- emacs
+ * tab-width: 8 -- emacs
+ * indent-tabs-mode: nil -- emacs
+ * End: -- emacs
+ */
--- /dev/null
+/*
+ * font-history-model.h
+ * Copyright (C) 2009 Jim Evins <evins@snaught.com>.
+ *
+ * This file is part of gLabels.
+ *
+ * gLabels 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gLabels 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 gLabels. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GL_FONT_HISTORY_MODEL_H__
+#define __GL_FONT_HISTORY_MODEL_H__
+
+
+#include <glib-object.h>
+
+
+G_BEGIN_DECLS
+
+/* Utility Macros */
+#define TYPE_GL_FONT_HISTORY_MODEL (gl_font_history_model_get_type ())
+#define GL_FONT_HISTORY_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_FONT_HISTORY_MODEL, glFontHistoryModel))
+#define GL_FONT_HISTORY_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_FONT_HISTORY_MODEL, glFontHistoryModelClass))
+#define IS_GL_FONT_HISTORY_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_FONT_HISTORY_MODEL))
+#define IS_GL_FONT_HISTORY_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_FONT_HISTORY_MODEL))
+#define GL_FONT_HISTORY_MODEL_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_FONT_HISTORY_MODEL, glFontHistoryModelClass))
+
+
+/* Type definitions */
+typedef struct _glFontHistoryModel glFontHistoryModel;
+typedef struct _glFontHistoryModelPrivate glFontHistoryModelPrivate;
+typedef struct _glFontHistoryModelClass glFontHistoryModelClass;
+
+
+/** GL_FONT_HISTORY_MODEL Object */
+struct _glFontHistoryModel {
+ GObject parent;
+
+ glFontHistoryModelPrivate *priv;
+};
+
+/** GL_FONT_HISTORY_MODEL Class */
+struct _glFontHistoryModelClass {
+ GObjectClass parent_class;
+
+ /*
+ * Signals
+ */
+ void (*changed) (glFontHistoryModel *this,
+ gpointer user_data);
+
+
+};
+
+
+GType gl_font_history_model_get_type (void) G_GNUC_CONST;
+
+glFontHistoryModel *gl_font_history_model_new (guint n);
+
+void gl_font_history_model_add_family (glFontHistoryModel *this,
+ const gchar *family);
+
+const GList *gl_font_history_model_get_family_list (glFontHistoryModel *this);
+
+
+G_END_DECLS
+
+#endif /* __GL_FONT_HISTORY_MODEL_H__ */
+
+
+
+/*
+ * Local Variables: -- emacs
+ * mode: C -- emacs
+ * c-basic-offset: 8 -- emacs
+ * tab-width: 8 -- emacs
+ * indent-tabs-mode: nil -- emacs
+ * End: -- emacs
+ */
--- /dev/null
+/*
+ * font-history.c
+ * Copyright (C) 2009 Jim Evins <evins@snaught.com>.
+ *
+ * This file is part of gLabels.
+ *
+ * gLabels 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gLabels 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 gLabels. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "font-history.h"
+
+
+#define MAX_FONTS 10
+
+
+/*========================================================*/
+/* Public globals. */
+/*========================================================*/
+
+glFontHistoryModel *gl_font_history = NULL;
+
+
+/*========================================================*/
+/* Private types. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private globals. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private function prototypes. */
+/*========================================================*/
+
+
+/*****************************************************************************/
+/* Initialize font history. */
+/*****************************************************************************/
+void
+gl_font_history_init (void)
+{
+ gl_font_history = gl_font_history_model_new (MAX_FONTS);
+}
+
+
+
+/*
+ * Local Variables: -- emacs
+ * mode: C -- emacs
+ * c-basic-offset: 8 -- emacs
+ * tab-width: 8 -- emacs
+ * indent-tabs-mode: nil -- emacs
+ * End: -- emacs
+ */
--- /dev/null
+/*
+ * font-history.h
+ * Copyright (C) 2009 Jim Evins <evins@snaught.com>.
+ *
+ * This file is part of gLabels.
+ *
+ * gLabels 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gLabels 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 gLabels. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GL_FONT_HISTORY_H__
+#define __GL_FONT_HISTORY_H__
+
+
+#include "font-history-model.h"
+
+
+G_BEGIN_DECLS
+
+
+glFontHistoryModel *gl_font_history;
+
+
+void gl_font_history_init (void);
+
+
+G_END_DECLS
+
+#endif /* __GL_FONT_HISTORY_H__ */
+
+
+
+/*
+ * Local Variables: -- emacs
+ * mode: C -- emacs
+ * c-basic-offset: 8 -- emacs
+ * tab-width: 8 -- emacs
+ * indent-tabs-mode: nil -- emacs
+ * End: -- emacs
+ */
#include "print-op.h"
#include "file-util.h"
#include "prefs.h"
+#include "font-history.h"
#include "debug.h"
/*============================================*/
gl_merge_init ();
lgl_db_init ();
gl_prefs_init ();
+ gl_font_history_init ();
/* now print the files */
for (p = file_list; p; p = p->next) {
#include "recent.h"
#include "mini-preview-pixbuf-cache.h"
#include "prefs.h"
+#include "font-history.h"
#include "debug.h"
#include "window.h"
#include "file.h"
gl_mini_preview_pixbuf_cache_init ();
gl_merge_init ();
gl_recent_init ();
+ gl_font_history_init ();
/* Parse args and build the list of files to be loaded at startup */
#include <string.h>
#include "font-util.h"
+#include "font-history.h"
#include "debug.h"
ltext->priv->size_changed = TRUE;
+ gl_font_history_model_add_family (gl_font_history, DEFAULT_FONT_FAMILY);
+
g_signal_connect (G_OBJECT(ltext->priv->buffer), "changed",
G_CALLBACK(buffer_changed_cb), ltext);
}
ltext->priv->size_changed = TRUE;
+ gl_font_history_model_add_family (gl_font_history, ltext->priv->font_family);
+
gl_label_object_emit_changed (GL_LABEL_OBJECT(ltext));
gl_debug (DEBUG_LABEL, "END");