Commit c2fbbed2 authored by Jesse van den Kieboom's avatar Jesse van den Kieboom

Use css stylesheet file instead of inline styles

parent 1d094b50
......@@ -29,13 +29,17 @@ gsettings_SCHEMAS = org.gnome.gedit.gschema.xml
convertdir = $(datadir)/GConf/gsettings
convert_DATA = gedit.convert
cssdir = $(datadir)/gedit/css
css_DATA = gedit.css
EXTRA_DIST = \
$(desktop_in_files) \
$(service_in_files) \
$(man_MANS) \
gedit.pc.in \
org.gnome.gedit.gschema.xml.in.in \
gedit.convert
gedit.convert \
gedit.css
CLEANFILES = \
$(desktop_DATA) \
......
/* Make buttons as small as possible */
GeditStatusComboBox GtkButton, GeditCloseButton {
-GtkButton-default-border : 0;
-GtkButton-default-outside-border : 0;
-GtkButton-inner-border: 0;
-GtkWidget-focus-line-width : 0;
-GtkWidget-focus-padding : 0;
padding: 0;
}
/* Apply style to the last notebook when the main window is in fullscreen mode
(is set both when in maximized and in fullscreen mode), to remove the
right padding from the notebook */
GeditWindow.fullscreen GeditMultiNotebook GeditNotebook.last {
/* Note that top/bottom/left padding is hard coded for now to 2px
because we can't set only the right padding. See:
https://bugzilla.gnome.org/show_bug.cgi?id=647605 */
padding: 2px 0 2px 2px;
}
......@@ -22,37 +22,16 @@
#include "gedit-close-button.h"
struct _GeditCloseButtonClassPrivate
{
GtkCssProvider *css;
};
G_DEFINE_TYPE_WITH_CODE (GeditCloseButton, gedit_close_button, GTK_TYPE_BUTTON,
g_type_add_class_private (g_define_type_id, sizeof (GeditCloseButtonClassPrivate)))
G_DEFINE_TYPE (GeditCloseButton, gedit_close_button, GTK_TYPE_BUTTON)
static void
gedit_close_button_class_init (GeditCloseButtonClass *klass)
{
static const gchar button_style[] =
"* {\n"
"-GtkButton-default-border : 0;\n"
"-GtkButton-default-outside-border : 0;\n"
"-GtkButton-inner-border: 0;\n"
"-GtkWidget-focus-line-width : 0;\n"
"-GtkWidget-focus-padding : 0;\n"
"padding: 0;\n"
"}";
klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClassPrivate);
klass->priv->css = gtk_css_provider_new ();
gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
}
static void
gedit_close_button_init (GeditCloseButton *button)
{
GtkStyleContext *context;
GtkWidget *image;
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
......@@ -60,12 +39,6 @@ gedit_close_button_init (GeditCloseButton *button)
gtk_widget_show (image);
gtk_container_add (GTK_CONTAINER (button), image);
/* make it small */
context = gtk_widget_get_style_context (GTK_WIDGET (button));
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (GEDIT_CLOSE_BUTTON_GET_CLASS (button)->priv->css),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
GtkWidget *
......
......@@ -36,7 +36,6 @@ G_BEGIN_DECLS
typedef struct _GeditCloseButton GeditCloseButton;
typedef struct _GeditCloseButtonClass GeditCloseButtonClass;
typedef struct _GeditCloseButtonClassPrivate GeditCloseButtonClassPrivate;
struct _GeditCloseButton
{
......@@ -46,8 +45,6 @@ struct _GeditCloseButton
struct _GeditCloseButtonClass
{
GtkButtonClass parent_class;
GeditCloseButtonClassPrivate *priv;
};
GType gedit_close_button_get_type (void) G_GNUC_CONST;
......
......@@ -36,7 +36,6 @@ struct _GeditMultiNotebookPrivate
GeditTab *active_tab;
guint removing_notebook : 1;
guint collapse : 1;
};
enum
......@@ -450,6 +449,12 @@ add_notebook (GeditMultiNotebook *mnb,
mnb->priv->notebooks = g_list_append (mnb->priv->notebooks,
notebook);
gtk_style_context_add_class (gtk_widget_get_style_context (notebook),
"first");
gtk_style_context_add_class (gtk_widget_get_style_context (notebook),
"last");
}
else
{
......@@ -458,7 +463,6 @@ add_notebook (GeditMultiNotebook *mnb,
GtkAllocation allocation;
GtkWidget *active_notebook = mnb->priv->active_notebook;
gint active_nb_pos;
gboolean collapse_new_notebook = FALSE;
paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_show (paned);
......@@ -472,6 +476,16 @@ add_notebook (GeditMultiNotebook *mnb,
gtk_container_remove (GTK_CONTAINER (parent), active_notebook);
gtk_container_add (GTK_CONTAINER (parent), paned);
/* check if we need to uncollapse the active notebook */
if (active_notebook == g_list_last (mnb->priv->notebooks)->data)
{
gtk_style_context_remove_class (gtk_widget_get_style_context (active_notebook),
"last");
gtk_style_context_add_class (gtk_widget_get_style_context (notebook),
"last");
}
gtk_paned_pack1 (GTK_PANED (paned), active_notebook, TRUE, FALSE);
g_object_unref (active_notebook);
......@@ -481,26 +495,11 @@ add_notebook (GeditMultiNotebook *mnb,
gtk_paned_set_position (GTK_PANED (paned),
allocation.width / 2);
/* check if we need to uncollapse the active notebook */
if (active_notebook == g_list_last (mnb->priv->notebooks)->data &&
mnb->priv->collapse)
{
collapse_new_notebook = TRUE;
gedit_notebook_collapse_border (GEDIT_NOTEBOOK (active_notebook),
FALSE);
}
active_nb_pos = g_list_index (mnb->priv->notebooks,
active_notebook);
mnb->priv->notebooks = g_list_insert (mnb->priv->notebooks,
notebook,
active_nb_pos + 1);
if (collapse_new_notebook)
{
gedit_notebook_collapse_border (GEDIT_NOTEBOOK (notebook),
TRUE);
}
}
gtk_widget_show (notebook);
......@@ -532,14 +531,25 @@ remove_notebook (GeditMultiNotebook *mnb,
if (current->next != NULL)
{
new_notebook = GTK_WIDGET (current->next->data);
if (current->prev == NULL)
{
gtk_style_context_add_class (gtk_widget_get_style_context (new_notebook),
"first");
}
}
else
{
new_notebook = GTK_WIDGET (mnb->priv->notebooks->data);
/* we must check if we need to collapse the new last notebook */
gedit_notebook_collapse_border (GEDIT_NOTEBOOK (current->prev->data),
mnb->priv->collapse);
gtk_style_context_add_class (gtk_widget_get_style_context (current->prev->data),
"last");
}
if (current->prev == NULL)
{
gtk_style_context_remove_class (gtk_widget_get_style_context (notebook),
"first");
}
parent = gtk_widget_get_parent (notebook);
......@@ -574,6 +584,9 @@ remove_notebook (GeditMultiNotebook *mnb,
g_object_unref (children->data);
g_list_free (children);
gtk_style_context_remove_region (gtk_widget_get_style_context (notebook),
"notebook");
disconnect_notebook_signals (mnb, notebook);
g_signal_emit (G_OBJECT (mnb), signals[NOTEBOOK_REMOVED], 0, notebook);
......@@ -905,21 +918,6 @@ gedit_multi_notebook_next_notebook (GeditMultiNotebook *mnb)
gtk_widget_grab_focus (notebook);
}
void
gedit_multi_notebook_collapse_notebook_border (GeditMultiNotebook *mnb,
gboolean collapse)
{
GeditNotebook *notebook;
g_return_if_fail (GEDIT_IS_MULTI_NOTEBOOK (mnb));
mnb->priv->collapse = (collapse != FALSE);
notebook = GEDIT_NOTEBOOK (g_list_last (mnb->priv->notebooks)->data);
gedit_notebook_collapse_border (notebook, collapse);
}
void
gedit_multi_notebook_foreach_notebook (GeditMultiNotebook *mnb,
GtkCallback callback,
......
......@@ -123,9 +123,6 @@ void gedit_multi_notebook_remove_active_notebook (GeditMultiNotebook *mnb);
void gedit_multi_notebook_previous_notebook (GeditMultiNotebook *mnb);
void gedit_multi_notebook_next_notebook (GeditMultiNotebook *mnb);
void gedit_multi_notebook_collapse_notebook_border (GeditMultiNotebook *mnb,
gboolean collapse);
void gedit_multi_notebook_foreach_notebook (GeditMultiNotebook *mnb,
GtkCallback callback,
gpointer callback_data);
......
......@@ -62,8 +62,6 @@ struct _GeditNotebookPrivate
GeditNotebookShowTabsModeType show_tabs_mode;
GtkCssProvider *css;
guint close_buttons_sensitive : 1;
guint ignore_focused_page_update : 1;
};
......@@ -169,12 +167,6 @@ gedit_notebook_dispose (GObject *object)
notebook->priv->ui_settings = NULL;
}
if (notebook->priv->css != NULL)
{
g_object_unref (notebook->priv->css);
notebook->priv->css = NULL;
}
G_OBJECT_CLASS (gedit_notebook_parent_class)->dispose (object);
}
......@@ -685,66 +677,4 @@ gedit_notebook_get_close_buttons_sensitive (GeditNotebook *nb)
return nb->priv->close_buttons_sensitive;
}
static void
remove_right_padding (GeditNotebook *nb)
{
GtkStyleContext *context;
GtkBorder padding;
gchar *modified_style;
GError *error = NULL;
const gchar style[] =
".notebook {\n"
"padding: %d 0 %d %d;\n"
"}";
/* FIXME: find out a css like way to do this, right now padding-right/left
doesn't work */
context = gtk_widget_get_style_context (GTK_WIDGET (nb));
gtk_style_context_get_padding (context, gtk_style_context_get_state (context),
&padding);
modified_style = g_strdup_printf (style, padding.top, padding.bottom, padding.left);
/* make it as small as possible */
if (nb->priv->css == NULL)
{
nb->priv->css = gtk_css_provider_new ();
}
if (gtk_css_provider_load_from_data (nb->priv->css, modified_style, -1, &error))
{
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (nb->priv->css),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
else
{
g_warning ("%s", error->message);
g_error_free (error);
}
g_free (modified_style);
}
void
gedit_notebook_collapse_border (GeditNotebook *nb,
gboolean collapse)
{
g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
if (collapse)
{
remove_right_padding (nb);
}
/* if we made some modification put it back to the default state */
else if (nb->priv->css != NULL)
{
GtkStyleContext *context;
context = gtk_widget_get_style_context (GTK_WIDGET (nb));
gtk_style_context_remove_provider (context,
GTK_STYLE_PROVIDER (nb->priv->css));
}
}
/* ex:set ts=8 noet: */
......@@ -120,9 +120,6 @@ void gedit_notebook_set_close_buttons_sensitive
gboolean gedit_notebook_get_close_buttons_sensitive
(GeditNotebook *nb);
void gedit_notebook_collapse_border (GeditNotebook *nb,
gboolean collapse);
G_END_DECLS
#endif /* GEDIT_NOTEBOOK_H */
......
......@@ -43,11 +43,6 @@ struct _GeditStatusComboBoxPrivate
GtkWidget *current_item;
};
struct _GeditStatusComboBoxClassPrivate
{
GtkCssProvider *css;
};
/* Signals */
enum
{
......@@ -65,8 +60,7 @@ enum
static guint signals[NUM_SIGNALS] = { 0 };
G_DEFINE_TYPE_WITH_CODE (GeditStatusComboBox, gedit_status_combo_box, GTK_TYPE_EVENT_BOX,
g_type_add_class_private (g_define_type_id, sizeof (GeditStatusComboBoxClassPrivate)))
G_DEFINE_TYPE (GeditStatusComboBox, gedit_status_combo_box, GTK_TYPE_EVENT_BOX)
static void
gedit_status_combo_box_finalize (GObject *object)
......@@ -148,15 +142,6 @@ gedit_status_combo_box_class_init (GeditStatusComboBoxClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
static const gchar style[] =
"* {\n"
"-GtkButton-default-border : 0;\n"
"-GtkButton-default-outside-border : 0;\n"
"-GtkButton-inner-border: 0;\n"
"-GtkWidget-focus-line-width : 0;\n"
"-GtkWidget-focus-padding : 0;\n"
"padding: 0;\n"
"}";
object_class->finalize = gedit_status_combo_box_finalize;
object_class->get_property = gedit_status_combo_box_get_property;
......@@ -182,11 +167,6 @@ gedit_status_combo_box_class_init (GeditStatusComboBoxClass *klass)
G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GeditStatusComboBoxPrivate));
klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GEDIT_TYPE_STATUS_COMBO_BOX, GeditStatusComboBoxClassPrivate);
klass->priv->css = gtk_css_provider_new ();
gtk_css_provider_load_from_data (klass->priv->css, style, -1, NULL);
}
static void
......@@ -325,8 +305,6 @@ set_shadow_type (GeditStatusComboBox *combo)
static void
gedit_status_combo_box_init (GeditStatusComboBox *self)
{
GtkStyleContext *context;
self->priv = GEDIT_STATUS_COMBO_BOX_GET_PRIVATE (self);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (self), TRUE);
......@@ -386,16 +364,6 @@ gedit_status_combo_box_init (GeditStatusComboBox *self)
"deactivate",
G_CALLBACK (menu_deactivate),
self);
/* make it as small as possible */
context = gtk_widget_get_style_context (GTK_WIDGET (self->priv->button));
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (GEDIT_STATUS_COMBO_BOX_GET_CLASS (self)->priv->css),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
context = gtk_widget_get_style_context (GTK_WIDGET (self->priv->frame));
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (GEDIT_STATUS_COMBO_BOX_GET_CLASS (self)->priv->css),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
/* public functions */
......
......@@ -50,8 +50,6 @@ struct _GeditStatusComboBox
struct _GeditStatusComboBoxClass
{
GtkEventBoxClass parent_class;
GeditStatusComboBoxClassPrivate *priv;
void (*changed) (GeditStatusComboBox *combo,
GtkMenuItem *item);
......
......@@ -382,8 +382,18 @@ gedit_window_window_state_event (GtkWidget *widget,
show = !(event->new_window_state &
(GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN));
gedit_multi_notebook_collapse_notebook_border (window->priv->multi_notebook,
!show);
if (show)
{
gtk_style_context_remove_class (gtk_widget_get_style_context (widget),
"fullscreen");
}
else
{
gtk_style_context_add_class (gtk_widget_get_style_context (widget),
"fullscreen");
}
gtk_widget_reset_style (widget);
}
if (GTK_WIDGET_CLASS (gedit_window_parent_class)->window_state_event)
......
......@@ -158,6 +158,38 @@ gedit_main_window (void)
}
}
static void
load_css ()
{
/* Load css */
GtkCssProvider *css = gtk_css_provider_new ();
gchar *css_path;
GError *error = NULL;
css_path = g_build_filename (gedit_dirs_get_gedit_data_dir (),
"css",
"gedit.css",
NULL);
if (!gtk_css_provider_load_from_path (css, css_path, &error))
{
g_warning ("Failed to load stylesheet `%s': %s",
css_path,
error->message);
g_error_free (error);
}
else
{
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
GTK_STYLE_PROVIDER (css),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
g_free (css_path);
g_object_unref (css);
}
static void
gedit_main (gboolean service)
{
......@@ -185,6 +217,8 @@ gedit_main (gboolean service)
gedit_debug_message (DEBUG_APP, "Init session manager");
gedit_session_init ();
load_css ();
if (!service && gedit_session_is_restored ())
{
restored = gedit_session_load ();
......
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