xedit-statusbar: Clean up and fix some deprecation warnings

This commit is contained in:
JosephMcc 2016-01-26 12:32:39 -08:00
parent d071bf422e
commit f6c4752434
2 changed files with 181 additions and 4650 deletions

File diff suppressed because it is too large Load Diff

View File

@ -39,30 +39,26 @@
#include "xedit-statusbar.h" #include "xedit-statusbar.h"
#define XEDIT_STATUSBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\ #define XEDIT_STATUSBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\
XEDIT_TYPE_STATUSBAR,\ XEDIT_TYPE_STATUSBAR,\
XeditStatusbarPrivate)) XeditStatusbarPrivate))
#if GTK_CHECK_VERSION (3, 0, 0)
#define gtk_hbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_HORIZONTAL,Y)
#endif
struct _XeditStatusbarPrivate struct _XeditStatusbarPrivate
{ {
GtkWidget *overwrite_mode_label; GtkWidget *overwrite_mode_label;
GtkWidget *cursor_position_label; GtkWidget *cursor_position_label;
GtkWidget *state_frame; GtkWidget *state_frame;
GtkWidget *load_image; GtkWidget *load_image;
GtkWidget *save_image; GtkWidget *save_image;
GtkWidget *print_image; GtkWidget *print_image;
GtkWidget *error_frame; GtkWidget *error_frame;
GtkWidget *error_event_box; GtkWidget *error_event_box;
/* tmp flash timeout data */ /* tmp flash timeout data */
guint flash_timeout; guint flash_timeout;
guint flash_context_id; guint flash_context_id;
guint flash_message_id; guint flash_message_id;
}; };
G_DEFINE_TYPE(XeditStatusbar, xedit_statusbar, GTK_TYPE_STATUSBAR) G_DEFINE_TYPE(XeditStatusbar, xedit_statusbar, GTK_TYPE_STATUSBAR)
@ -71,37 +67,37 @@ G_DEFINE_TYPE(XeditStatusbar, xedit_statusbar, GTK_TYPE_STATUSBAR)
static gchar * static gchar *
get_overwrite_mode_string (gboolean overwrite) get_overwrite_mode_string (gboolean overwrite)
{ {
return g_strconcat (" ", overwrite ? _("OVR") : _("INS"), NULL); return g_strconcat (" ", overwrite ? _("OVR") : _("INS"), NULL);
} }
static gint static gint
get_overwrite_mode_length (void) get_overwrite_mode_length (void)
{ {
return 2 + MAX (g_utf8_strlen (_("OVR"), -1), g_utf8_strlen (_("INS"), -1)); return 2 + MAX (g_utf8_strlen (_("OVR"), -1), g_utf8_strlen (_("INS"), -1));
} }
static void static void
xedit_statusbar_dispose (GObject *object) xedit_statusbar_dispose (GObject *object)
{ {
XeditStatusbar *statusbar = XEDIT_STATUSBAR (object); XeditStatusbar *statusbar = XEDIT_STATUSBAR (object);
if (statusbar->priv->flash_timeout > 0) if (statusbar->priv->flash_timeout > 0)
{ {
g_source_remove (statusbar->priv->flash_timeout); g_source_remove (statusbar->priv->flash_timeout);
statusbar->priv->flash_timeout = 0; statusbar->priv->flash_timeout = 0;
} }
G_OBJECT_CLASS (xedit_statusbar_parent_class)->dispose (object); G_OBJECT_CLASS (xedit_statusbar_parent_class)->dispose (object);
} }
static void static void
xedit_statusbar_class_init (XeditStatusbarClass *klass) xedit_statusbar_class_init (XeditStatusbarClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = xedit_statusbar_dispose; object_class->dispose = xedit_statusbar_dispose;
g_type_class_add_private (object_class, sizeof (XeditStatusbarPrivate)); g_type_class_add_private (object_class, sizeof (XeditStatusbarPrivate));
} }
#define CURSOR_POSITION_LABEL_WIDTH_CHARS 18 #define CURSOR_POSITION_LABEL_WIDTH_CHARS 18
@ -109,94 +105,89 @@ xedit_statusbar_class_init (XeditStatusbarClass *klass)
static void static void
xedit_statusbar_init (XeditStatusbar *statusbar) xedit_statusbar_init (XeditStatusbar *statusbar)
{ {
GtkWidget *hbox; GtkWidget *hbox;
GtkWidget *error_image; GtkWidget *error_image;
statusbar->priv = XEDIT_STATUSBAR_GET_PRIVATE (statusbar); statusbar->priv = XEDIT_STATUSBAR_GET_PRIVATE (statusbar);
#if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_set_margin_top (GTK_WIDGET (statusbar), 0);
gtk_widget_set_margin_top (GTK_WIDGET (statusbar), 0); gtk_widget_set_margin_bottom (GTK_WIDGET (statusbar), 0);
gtk_widget_set_margin_bottom (GTK_WIDGET (statusbar), 0);
#endif
statusbar->priv->overwrite_mode_label = gtk_label_new (NULL); statusbar->priv->overwrite_mode_label = gtk_label_new (NULL);
gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->overwrite_mode_label), gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->overwrite_mode_label),
get_overwrite_mode_length ()); get_overwrite_mode_length ());
gtk_widget_show (statusbar->priv->overwrite_mode_label); gtk_widget_show (statusbar->priv->overwrite_mode_label);
gtk_box_pack_end (GTK_BOX (statusbar), gtk_box_pack_end (GTK_BOX (statusbar),
statusbar->priv->overwrite_mode_label, statusbar->priv->overwrite_mode_label,
FALSE, TRUE, 0); FALSE, TRUE, 0);
statusbar->priv->cursor_position_label = gtk_label_new (NULL); statusbar->priv->cursor_position_label = gtk_label_new (NULL);
gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label), gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label),
CURSOR_POSITION_LABEL_WIDTH_CHARS); CURSOR_POSITION_LABEL_WIDTH_CHARS);
gtk_widget_show (statusbar->priv->cursor_position_label); gtk_widget_show (statusbar->priv->cursor_position_label);
gtk_box_pack_end (GTK_BOX (statusbar), gtk_box_pack_end (GTK_BOX (statusbar),
statusbar->priv->cursor_position_label, statusbar->priv->cursor_position_label,
FALSE, TRUE, 0); FALSE, TRUE, 0);
statusbar->priv->state_frame = gtk_frame_new (NULL); statusbar->priv->state_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame), gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame),
GTK_SHADOW_IN); GTK_SHADOW_IN);
hbox = gtk_hbox_new (FALSE, 0); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (statusbar->priv->state_frame), hbox); gtk_container_add (GTK_CONTAINER (statusbar->priv->state_frame), hbox);
statusbar->priv->load_image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU); statusbar->priv->load_image = gtk_image_new_from_icon_name ("document-open-symbolic", GTK_ICON_SIZE_MENU);
statusbar->priv->save_image = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); statusbar->priv->save_image = gtk_image_new_from_icon_name ("document-save-symbolic", GTK_ICON_SIZE_MENU);
statusbar->priv->print_image = gtk_image_new_from_stock (GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU); statusbar->priv->print_image = gtk_image_new_from_icon_name ("printer-symbolic", GTK_ICON_SIZE_MENU);
gtk_widget_show (hbox); gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
statusbar->priv->load_image, statusbar->priv->load_image,
FALSE, TRUE, 4); FALSE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
statusbar->priv->save_image, statusbar->priv->save_image,
FALSE, TRUE, 4); FALSE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
statusbar->priv->print_image, statusbar->priv->print_image,
FALSE, TRUE, 4); FALSE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (statusbar), gtk_box_pack_start (GTK_BOX (statusbar),
statusbar->priv->state_frame, statusbar->priv->state_frame,
FALSE, TRUE, 0); FALSE, TRUE, 0);
statusbar->priv->error_frame = gtk_frame_new (NULL); statusbar->priv->error_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->error_frame), GTK_SHADOW_IN); gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->error_frame), GTK_SHADOW_IN);
error_image = gtk_image_new_from_icon_name ("dialog-error", GTK_ICON_SIZE_MENU);
#if GTK_CHECK_VERSION (3, 10, 0)
error_image = gtk_image_new_from_icon_name ("dialog-error", GTK_ICON_SIZE_MENU);
#else
error_image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_MENU);
#endif
#if GTK_CHECK_VERSION (3, 14, 0) #if GTK_CHECK_VERSION (3, 14, 0)
gtk_widget_set_margin_start (error_image, 4); gtk_widget_set_margin_start (error_image, 4);
gtk_widget_set_margin_end (error_image, 4); gtk_widget_set_margin_end (error_image, 4);
gtk_widget_set_margin_top (error_image, 0); gtk_widget_set_margin_top (error_image, 0);
gtk_widget_set_margin_bottom (error_image, 0); gtk_widget_set_margin_bottom (error_image, 0);
#else #else
gtk_misc_set_padding (GTK_MISC (error_image), 4, 0); gtk_misc_set_padding (GTK_MISC (error_image), 4, 0);
gtk_widget_show (error_image); gtk_widget_show (error_image);
#endif #endif
statusbar->priv->error_event_box = gtk_event_box_new (); statusbar->priv->error_event_box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (statusbar->priv->error_event_box), gtk_event_box_set_visible_window (GTK_EVENT_BOX (statusbar->priv->error_event_box),
FALSE); FALSE);
gtk_widget_show (statusbar->priv->error_event_box); gtk_widget_show (statusbar->priv->error_event_box);
gtk_container_add (GTK_CONTAINER (statusbar->priv->error_frame), gtk_container_add (GTK_CONTAINER (statusbar->priv->error_frame),
statusbar->priv->error_event_box); statusbar->priv->error_event_box);
gtk_container_add (GTK_CONTAINER (statusbar->priv->error_event_box), gtk_container_add (GTK_CONTAINER (statusbar->priv->error_event_box),
error_image); error_image);
gtk_box_pack_start (GTK_BOX (statusbar), gtk_box_pack_start (GTK_BOX (statusbar),
statusbar->priv->error_frame, statusbar->priv->error_frame,
FALSE, TRUE, 0); FALSE, TRUE, 0);
gtk_box_reorder_child (GTK_BOX (statusbar), gtk_box_reorder_child (GTK_BOX (statusbar),
statusbar->priv->error_frame, statusbar->priv->error_frame,
0); 0);
} }
/** /**
@ -209,7 +200,7 @@ xedit_statusbar_init (XeditStatusbar *statusbar)
GtkWidget * GtkWidget *
xedit_statusbar_new (void) xedit_statusbar_new (void)
{ {
return GTK_WIDGET (g_object_new (XEDIT_TYPE_STATUSBAR, NULL)); return GTK_WIDGET (g_object_new (XEDIT_TYPE_STATUSBAR, NULL));
} }
/** /**
@ -223,23 +214,23 @@ void
xedit_statusbar_set_overwrite (XeditStatusbar *statusbar, xedit_statusbar_set_overwrite (XeditStatusbar *statusbar,
gboolean overwrite) gboolean overwrite)
{ {
gchar *msg; gchar *msg;
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
msg = get_overwrite_mode_string (overwrite); msg = get_overwrite_mode_string (overwrite);
gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), msg); gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), msg);
g_free (msg); g_free (msg);
} }
void void
xedit_statusbar_clear_overwrite (XeditStatusbar *statusbar) xedit_statusbar_clear_overwrite (XeditStatusbar *statusbar)
{ {
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), NULL); gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), NULL);
} }
/** /**
@ -252,35 +243,35 @@ xedit_statusbar_clear_overwrite (XeditStatusbar *statusbar)
**/ **/
void void
xedit_statusbar_set_cursor_position (XeditStatusbar *statusbar, xedit_statusbar_set_cursor_position (XeditStatusbar *statusbar,
gint line, gint line,
gint col) gint col)
{ {
gchar *msg = NULL; gchar *msg = NULL;
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
if ((line >= 0) || (col >= 0)) if ((line >= 0) || (col >= 0))
{ {
/* Translators: "Ln" is an abbreviation for "Line", Col is an abbreviation for "Column". Please, /* Translators: "Ln" is an abbreviation for "Line", Col is an abbreviation for "Column". Please,
use abbreviations if possible to avoid space problems. */ use abbreviations if possible to avoid space problems. */
msg = g_strdup_printf (_(" Ln %d, Col %d"), line, col); msg = g_strdup_printf (_(" Ln %d, Col %d"), line, col);
} }
gtk_label_set_text (GTK_LABEL (statusbar->priv->cursor_position_label), msg); gtk_label_set_text (GTK_LABEL (statusbar->priv->cursor_position_label), msg);
g_free (msg); g_free (msg);
} }
static gboolean static gboolean
remove_message_timeout (XeditStatusbar *statusbar) remove_message_timeout (XeditStatusbar *statusbar)
{ {
gtk_statusbar_remove (GTK_STATUSBAR (statusbar), gtk_statusbar_remove (GTK_STATUSBAR (statusbar),
statusbar->priv->flash_context_id, statusbar->priv->flash_context_id,
statusbar->priv->flash_message_id); statusbar->priv->flash_message_id);
/* remove the timeout */ /* remove the timeout */
statusbar->priv->flash_timeout = 0; statusbar->priv->flash_timeout = 0;
return FALSE; return FALSE;
} }
/* FIXME this is an issue for introspection */ /* FIXME this is an issue for introspection */
@ -294,91 +285,91 @@ remove_message_timeout (XeditStatusbar *statusbar)
*/ */
void void
xedit_statusbar_flash_message (XeditStatusbar *statusbar, xedit_statusbar_flash_message (XeditStatusbar *statusbar,
guint context_id, guint context_id,
const gchar *format, ...) const gchar *format, ...)
{ {
const guint32 flash_length = 3000; /* three seconds */ const guint32 flash_length = 3000; /* three seconds */
va_list args; va_list args;
gchar *msg; gchar *msg;
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
g_return_if_fail (format != NULL); g_return_if_fail (format != NULL);
va_start (args, format); va_start (args, format);
msg = g_strdup_vprintf (format, args); msg = g_strdup_vprintf (format, args);
va_end (args); va_end (args);
/* remove a currently ongoing flash message */ /* remove a currently ongoing flash message */
if (statusbar->priv->flash_timeout > 0) if (statusbar->priv->flash_timeout > 0)
{ {
g_source_remove (statusbar->priv->flash_timeout); g_source_remove (statusbar->priv->flash_timeout);
statusbar->priv->flash_timeout = 0; statusbar->priv->flash_timeout = 0;
gtk_statusbar_remove (GTK_STATUSBAR (statusbar), gtk_statusbar_remove (GTK_STATUSBAR (statusbar),
statusbar->priv->flash_context_id, statusbar->priv->flash_context_id,
statusbar->priv->flash_message_id); statusbar->priv->flash_message_id);
} }
statusbar->priv->flash_context_id = context_id; statusbar->priv->flash_context_id = context_id;
statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar), statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar),
context_id, context_id,
msg); msg);
statusbar->priv->flash_timeout = g_timeout_add (flash_length, statusbar->priv->flash_timeout = g_timeout_add (flash_length,
(GSourceFunc) remove_message_timeout, (GSourceFunc) remove_message_timeout,
statusbar); statusbar);
g_free (msg); g_free (msg);
} }
void void
xedit_statusbar_set_window_state (XeditStatusbar *statusbar, xedit_statusbar_set_window_state (XeditStatusbar *statusbar,
XeditWindowState state, XeditWindowState state,
gint num_of_errors) gint num_of_errors)
{ {
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
gtk_widget_hide (statusbar->priv->state_frame); gtk_widget_hide (statusbar->priv->state_frame);
gtk_widget_hide (statusbar->priv->save_image); gtk_widget_hide (statusbar->priv->save_image);
gtk_widget_hide (statusbar->priv->load_image); gtk_widget_hide (statusbar->priv->load_image);
gtk_widget_hide (statusbar->priv->print_image); gtk_widget_hide (statusbar->priv->print_image);
if (state & XEDIT_WINDOW_STATE_SAVING) if (state & XEDIT_WINDOW_STATE_SAVING)
{ {
gtk_widget_show (statusbar->priv->state_frame); gtk_widget_show (statusbar->priv->state_frame);
gtk_widget_show (statusbar->priv->save_image); gtk_widget_show (statusbar->priv->save_image);
} }
if (state & XEDIT_WINDOW_STATE_LOADING) if (state & XEDIT_WINDOW_STATE_LOADING)
{ {
gtk_widget_show (statusbar->priv->state_frame); gtk_widget_show (statusbar->priv->state_frame);
gtk_widget_show (statusbar->priv->load_image); gtk_widget_show (statusbar->priv->load_image);
} }
if (state & XEDIT_WINDOW_STATE_PRINTING) if (state & XEDIT_WINDOW_STATE_PRINTING)
{ {
gtk_widget_show (statusbar->priv->state_frame); gtk_widget_show (statusbar->priv->state_frame);
gtk_widget_show (statusbar->priv->print_image); gtk_widget_show (statusbar->priv->print_image);
} }
if (state & XEDIT_WINDOW_STATE_ERROR) if (state & XEDIT_WINDOW_STATE_ERROR)
{ {
gchar *tip; gchar *tip;
tip = g_strdup_printf (ngettext("There is a tab with errors", tip = g_strdup_printf (ngettext("There is a tab with errors",
"There are %d tabs with errors", "There are %d tabs with errors",
num_of_errors), num_of_errors),
num_of_errors); num_of_errors);
gtk_widget_set_tooltip_text (statusbar->priv->error_event_box, gtk_widget_set_tooltip_text (statusbar->priv->error_event_box,
tip); tip);
g_free (tip); g_free (tip);
gtk_widget_show (statusbar->priv->error_frame); gtk_widget_show (statusbar->priv->error_frame);
} }
else else
{ {
gtk_widget_hide (statusbar->priv->error_frame); gtk_widget_hide (statusbar->priv->error_frame);
} }
} }