Sorted out accelerators stuff a bit

This commit is contained in:
Yevgen Muntyan 2005-07-25 07:41:51 +00:00
parent b7a816168d
commit af34545c24
13 changed files with 451 additions and 270 deletions

View File

@ -39,9 +39,9 @@
<mainprogram>tests/editor</mainprogram>
<directoryradio>executable</directoryradio>
<customdirectory>/</customdirectory>
<programargs/>
<programargs></programargs>
<terminal>false</terminal>
<autocompile>true</autocompile>
<autocompile>false</autocompile>
<envvars/>
</run>
<configurations>
@ -54,13 +54,13 @@
<cflags>-O0 -g3 -pg</cflags>
<cxxflags>-O0 -g3 -pg</cxxflags>
<envvars/>
<topsourcedir></topsourcedir>
<cppflags></cppflags>
<ldflags></ldflags>
<ccompilerbinary></ccompilerbinary>
<cxxcompilerbinary></cxxcompilerbinary>
<f77compilerbinary></f77compilerbinary>
<f77flags></f77flags>
<topsourcedir/>
<cppflags/>
<ldflags/>
<ccompilerbinary/>
<cxxcompilerbinary/>
<f77compilerbinary/>
<f77flags/>
</debug>
<optimized>
<configargs>--enable-all-gcc-warnings=fatal --enable-developer-mode</configargs>

View File

@ -895,7 +895,6 @@ static void install_actions (MooApp *app, GType type)
"label", _about,
"tooltip", about,
"icon-stock-id", GTK_STOCK_ABOUT,
"accel", "",
"closure::callback", moo_app_about_dialog,
NULL);
@ -920,7 +919,6 @@ static void install_actions (MooApp *app, GType type)
"name", "Execute Script",
"label", "_Execute Script",
"tooltip", "Execute Script",
"accel", "",
"icon-stock-id", GTK_STOCK_EXECUTE,
"closure::callback", moo_app_python_execute_file,
NULL);

View File

@ -252,7 +252,6 @@ static void moo_edit_window_class_init (MooEditWindowClass *klass)
"label", "_Delete",
"tooltip", "Delete",
"icon-stock-id", GTK_STOCK_DELETE,
"accel", "",
"closure::signal", "delete-selection",
"closure::proxy-func", moo_edit_window_get_active_doc,
NULL);

View File

@ -19,6 +19,8 @@ AM_CFLAGS = \
noinst_LTLIBRARIES = libmooui.la
libmooui_la_SOURCES = \
mooaccel.c \
mooaccel.h \
mooaction.c \
mooaction.h \
mooactiongroup.c \

344
moo/mooui/mooaccel.c Normal file
View File

@ -0,0 +1,344 @@
/*
* mooui/mooaccel.c
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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.
*
* See COPYING file that comes with this distribution.
*/
#include "mooui/mooaccel.h"
#include "mooutils/mooprefs.h"
#include <gtk/gtk.h>
#include <string.h>
#define MOO_ACCEL_PREFS_KEY "Shortcuts"
static GHashTable *moo_accel_map = NULL; /* char* -> char* */
static GHashTable *moo_default_accel_map = NULL; /* char* -> char* */
static void watch_gtk_accel_map (void);
static void block_watch_gtk_accel_map (void);
static void unblock_watch_gtk_accel_map (void);
static void sync_accel_prefs (const char *accel_path);
static void init_accel_map (void)
{
static gboolean done = FALSE;
if (!done)
{
done = TRUE;
moo_accel_map =
g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
moo_default_accel_map =
g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
watch_gtk_accel_map ();
}
}
static char *accel_path_to_prefs_key (const char *accel_path)
{
GString *key;
const char *p;
if (accel_path && accel_path[0] == '<')
{
accel_path = strchr (accel_path, '/');
if (accel_path)
accel_path++;
}
if (!accel_path || !accel_path[0])
return NULL;
key = g_string_new (MOO_ACCEL_PREFS_KEY);
while (accel_path && *accel_path)
{
p = strchr (accel_path, '/');
g_string_append (key, "::");
if (p)
{
g_string_append_len (key, accel_path, p - accel_path);
accel_path = p + 1;
}
else
{
g_string_append (key, accel_path);
accel_path = NULL;
}
}
if (key->len > strlen (MOO_ACCEL_PREFS_KEY))
{
return g_string_free (key, FALSE);
}
else
{
g_string_free (key, TRUE);
return NULL;
}
}
void moo_prefs_set_accel (const char *accel_path,
const char *accel)
{
char *key = accel_path_to_prefs_key (accel_path);
g_return_if_fail (key != NULL);
moo_prefs_set (key, accel);
g_free (key);
}
const char *moo_prefs_get_accel (const char *accel_path)
{
const char *accel;
char *key = accel_path_to_prefs_key (accel_path);
g_return_val_if_fail (key != NULL, NULL);
accel = moo_prefs_get (key);
g_free (key);
return accel;
}
void moo_set_accel (const char *accel_path,
const char *accel)
{
guint accel_key = 0;
GdkModifierType accel_mods = 0;
GtkAccelKey old;
g_return_if_fail (accel_path != NULL && accel != NULL);
init_accel_map ();
if (*accel)
{
gtk_accelerator_parse (accel, &accel_key, &accel_mods);
if (accel_key || accel_mods) {
g_hash_table_insert (moo_accel_map,
g_strdup (accel_path),
gtk_accelerator_name (accel_key, accel_mods));
}
else {
g_warning ("could not parse accelerator '%s'", accel);
g_hash_table_insert (moo_accel_map,
g_strdup (accel_path),
g_strdup (""));
}
}
else {
g_hash_table_insert (moo_accel_map,
g_strdup (accel_path),
g_strdup (""));
}
block_watch_gtk_accel_map ();
if (gtk_accel_map_lookup_entry (accel_path, &old))
{
if (accel_key != old.accel_key || accel_mods != old.accel_mods)
{
if (accel_key || accel_mods)
{
if (!gtk_accel_map_change_entry (accel_path, accel_key,
accel_mods, TRUE))
g_warning ("could not set accel '%s' for accel_path '%s'",
accel, accel_path);
}
else
{
gtk_accel_map_change_entry (accel_path, 0, 0, TRUE);
}
}
}
else
{
if (accel_key || accel_mods)
{
gtk_accel_map_add_entry (accel_path,
accel_key,
accel_mods);
}
}
unblock_watch_gtk_accel_map ();
}
void moo_set_default_accel (const char *accel_path,
const char *accel)
{
const char *old_accel;
g_return_if_fail (accel_path != NULL && accel != NULL);
init_accel_map ();
old_accel = moo_get_default_accel (accel_path);
if (old_accel && !strcmp (old_accel, accel))
return;
if (*accel)
{
guint accel_key = 0;
GdkModifierType accel_mods = 0;
gtk_accelerator_parse (accel, &accel_key, &accel_mods);
if (accel_key || accel_mods)
{
g_hash_table_insert (moo_default_accel_map,
g_strdup (accel_path),
gtk_accelerator_name (accel_key, accel_mods));
}
else
{
g_warning ("could not parse accelerator '%s'", accel);
}
}
else
{
g_hash_table_insert (moo_default_accel_map,
g_strdup (accel_path),
g_strdup (""));
}
}
const char *moo_get_accel (const char *accel_path)
{
g_return_val_if_fail (accel_path != NULL, NULL);
init_accel_map ();
return g_hash_table_lookup (moo_accel_map, accel_path);
}
const char *moo_get_default_accel (const char *accel_path)
{
g_return_val_if_fail (accel_path != NULL, NULL);
init_accel_map ();
return g_hash_table_lookup (moo_default_accel_map, accel_path);
}
static void accel_map_changed (G_GNUC_UNUSED GtkAccelMap *object,
gchar *accel_path,
guint accel_key,
GdkModifierType accel_mods)
{
char *accel;
const char *old_accel;
const char *default_accel;
init_accel_map ();
old_accel = moo_get_accel (accel_path);
default_accel = moo_get_default_accel (accel_path);
if (!old_accel)
return;
if (accel_key)
accel = gtk_accelerator_name (accel_key, accel_mods);
else
accel = g_strdup ("");
g_return_if_fail (accel != NULL);
if (strcmp (accel, old_accel))
g_hash_table_insert (moo_accel_map,
g_strdup (accel_path),
g_strdup (accel));
sync_accel_prefs (accel_path);
g_free (accel);
}
static void watch_gtk_accel_map (void)
{
GtkAccelMap *accel_map = gtk_accel_map_get ();
g_return_if_fail (accel_map != NULL);
g_signal_connect (accel_map, "changed",
G_CALLBACK (accel_map_changed), NULL);
}
static void block_watch_gtk_accel_map (void)
{
GtkAccelMap *accel_map = gtk_accel_map_get ();
g_return_if_fail (accel_map != NULL);
g_signal_handlers_block_by_func (accel_map,
(gpointer) accel_map_changed,
NULL);
}
static void unblock_watch_gtk_accel_map (void)
{
GtkAccelMap *accel_map = gtk_accel_map_get ();
g_return_if_fail (accel_map != NULL);
g_signal_handlers_unblock_by_func (accel_map,
(gpointer) accel_map_changed,
NULL);
}
char *moo_get_accel_label (const char *accel)
{
guint key;
GdkModifierType mods;
g_return_val_if_fail (accel != NULL, g_strdup (""));
init_accel_map ();
if (*accel)
{
gtk_accelerator_parse (accel, &key, &mods);
return gtk_accelerator_get_label (key, mods);
}
else
{
return g_strdup ("");
}
}
static void sync_accel_prefs (const char *accel_path)
{
const char *default_accel, *accel;
g_return_if_fail (accel_path != NULL);
init_accel_map ();
accel = moo_get_accel (accel_path);
default_accel = moo_get_default_accel (accel_path);
if (!accel) accel = "";
if (!default_accel) default_accel = "";
if (strcmp (accel, default_accel))
moo_prefs_set_accel (accel_path, accel);
else
moo_prefs_set_accel (accel_path, NULL);
}

38
moo/mooui/mooaccel.h Normal file
View File

@ -0,0 +1,38 @@
/*
* mooui/mooaccel.h
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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.
*
* See COPYING file that comes with this distribution.
*/
#ifndef MOOUI_MOOACCEL_H
#define MOOUI_MOOACCEL_H
#include <glib.h>
G_BEGIN_DECLS
void moo_prefs_set_accel (const char *accel_path,
const char *accel);
const char *moo_prefs_get_accel (const char *accel_path);
void moo_set_accel (const char *accel_path,
const char *accel);
const char *moo_get_accel (const char *accel_path);
void moo_set_default_accel (const char *accel_path,
const char *accel);
const char *moo_get_default_accel (const char *accel_path);
char *moo_get_accel_label (const char *accel);
G_END_DECLS
#endif /* MOOUI_MOOACCEL_H */

View File

@ -13,6 +13,7 @@
#include "mooui/mooaction.h"
#include "mooui/mooactiongroup.h"
#include "mooui/mooaccel.h"
#include "mooutils/moomarshals.h"
#include "mooutils/moocompat.h"
#include <gtk/gtk.h>
@ -116,10 +117,6 @@ static guint signals[LAST_SIGNAL] = {0};
G_DEFINE_TYPE (MooAction, moo_action, G_TYPE_OBJECT)
static GHashTable *accel_map = NULL; /* char* -> char* */
static GHashTable *default_accel_map = NULL; /* char* -> char* */
static void moo_action_class_init (MooActionClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@ -136,13 +133,6 @@ static void moo_action_class_init (MooActionClass *klass)
klass->create_menu_item = moo_action_create_menu_item_real;
klass->create_tool_item = moo_action_create_tool_item_real;
accel_map = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
default_accel_map = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
g_object_class_install_property (gobject_class,
PROP_ID,
g_param_spec_string ("id",
@ -348,9 +338,29 @@ GObject *moo_action_constructor (GType type,
action->constructed = TRUE;
if (action->dead)
{
action->visible = FALSE;
action->sensitive = FALSE;
action->no_accel = TRUE;
g_free (action->accel);
action->accel = g_strdup ("");
g_free (action->default_accel);
action->default_accel = g_strdup ("");
g_free (action->stock_id);
action->stock_id = NULL;
g_free (action->icon_stock_id);
action->icon_stock_id = NULL;
g_free (action->label);
action->label = g_strdup ("");
g_free (action->tooltip);
action->tooltip = g_strdup ("");
if (action->icon) g_object_unref (action->icon);
action->icon = NULL;
return object;
}
if (!action->id || !action->id[0]) {
if (!action->id || !action->id[0])
{
g_critical ("%s: no action id", G_STRLOC);
if (!action->id)
action->id = g_strdup ("");
@ -360,7 +370,8 @@ GObject *moo_action_constructor (GType type,
if (!action->name)
action->name = g_strdup (action->id);
if (!action->group_id) {
if (!action->group_id)
{
g_critical ("action doesn't have group id");
if (!action->group_id)
action->group_id = g_strdup ("");
@ -370,8 +381,9 @@ GObject *moo_action_constructor (GType type,
action->accel = g_strdup ("");
if (!action->default_accel)
action->default_accel = g_strdup (action->accel);
moo_action_set_accel (action, action->accel);
moo_action_set_default_accel (action, action->default_accel);
moo_action_set_accel (action, action->accel);
return object;
}
@ -601,11 +613,6 @@ static void moo_action_set_tooltip (MooAction *action,
void moo_action_set_accel (MooAction *action,
const char *accel)
{
const char *accel_path;
guint accel_key = 0;
GdkModifierType accel_mods = 0;
GtkAccelKey old;
g_return_if_fail (MOO_IS_ACTION (action));
if (!action->constructed) {
@ -615,66 +622,14 @@ void moo_action_set_accel (MooAction *action,
}
g_return_if_fail (accel != NULL);
accel_path = moo_action_get_accel_path (action);
if (accel[0])
{
gtk_accelerator_parse (accel, &accel_key, &accel_mods);
if (accel_key || accel_mods) {
g_hash_table_insert (accel_map,
g_strdup (accel_path),
gtk_accelerator_name (accel_key, accel_mods));
}
else {
g_warning ("could not parse accelerator '%s'", accel);
g_hash_table_insert (accel_map,
g_strdup (accel_path),
g_strdup (""));
}
}
else {
g_hash_table_insert (accel_map,
g_strdup (accel_path),
g_strdup (""));
}
g_object_notify (G_OBJECT (action), "accel");
if (gtk_accel_map_lookup_entry (accel_path, &old))
{
if (accel_key == old.accel_key && accel_mods == old.accel_mods)
return;
if (accel_key || accel_mods)
{
if (!gtk_accel_map_change_entry (accel_path, accel_key,
accel_mods, TRUE))
g_warning ("could not set accel '%s' for accel_path '%s'",
accel, accel_path);
}
else
{
gtk_accel_map_change_entry (accel_path, 0, 0, TRUE);
}
}
else
{
if (accel_key || accel_mods)
{
gtk_accel_map_add_entry (accel_path,
accel_key,
accel_mods);
}
}
moo_set_accel (moo_action_get_accel_path (action), accel);
}
void moo_action_set_default_accel (MooAction *action,
const char *accel)
{
const char *accel_path;
const char *old_accel;
g_return_if_fail (MOO_IS_ACTION (action));
if (!action->constructed) {
@ -684,76 +639,33 @@ void moo_action_set_default_accel (MooAction *action,
}
g_return_if_fail (accel != NULL);
accel_path = moo_action_get_accel_path (action);
old_accel = g_hash_table_lookup (default_accel_map, accel_path);
if (old_accel && !strcmp (old_accel, accel))
return;
if (accel[0]) {
guint accel_key = 0;
GdkModifierType accel_mods = 0;
gtk_accelerator_parse (accel, &accel_key, &accel_mods);
if (accel_key || accel_mods) {
g_hash_table_insert (default_accel_map,
g_strdup (accel_path),
gtk_accelerator_name (accel_key, accel_mods));
g_object_notify (G_OBJECT (action), "default-accel");
}
else {
g_warning ("could not parse accelerator '%s'", accel);
}
}
else {
g_hash_table_insert (default_accel_map,
g_strdup (accel_path),
g_strdup (""));
g_object_notify (G_OBJECT (action), "default-accel");
}
moo_set_default_accel (moo_action_get_accel_path (action), accel);
}
const char *moo_action_get_accel (MooAction *action)
{
g_return_val_if_fail (MOO_IS_ACTION (action), NULL);
return g_hash_table_lookup (accel_map,
moo_action_get_accel_path (action));
return moo_get_accel (moo_action_get_accel_path (action));
}
const char *moo_action_get_default_accel (MooAction *action)
{
g_return_val_if_fail (MOO_IS_ACTION (action), NULL);
return g_hash_table_lookup (default_accel_map,
moo_action_get_accel_path (action));
return moo_get_default_accel (moo_action_get_accel_path (action));
}
char *moo_action_get_accel_label (MooAction *action)
{
const char *accel;
guint key;
GdkModifierType mods;
g_return_val_if_fail (MOO_IS_ACTION (action), NULL);
accel = moo_action_get_accel (action);
if (!accel[0]) return g_strdup ("");
gtk_accelerator_parse (accel, &key, &mods);
return gtk_accelerator_get_label (key, mods);
return moo_get_accel_label (moo_action_get_accel (action));
}
char *moo_action_get_default_accel_label (MooAction *action)
{
const char *accel;
guint key;
GdkModifierType mods;
g_return_val_if_fail (MOO_IS_ACTION (action), NULL);
accel = moo_action_get_default_accel (action);
if (!accel[0]) return g_strdup ("");
gtk_accelerator_parse (accel, &key, &mods);
return gtk_accelerator_get_label (key, mods);
return moo_get_accel_label (moo_action_get_default_accel (action));
}
@ -761,7 +673,11 @@ void moo_action_set_no_accel (MooAction *action,
gboolean no_accel)
{
g_return_if_fail (MOO_IS_ACTION (action));
action->no_accel = no_accel;
if (no_accel)
moo_action_set_accel (action, "");
}
gboolean moo_action_get_no_accel (MooAction *action)
@ -1100,15 +1016,3 @@ static void moo_action_add_proxy (MooAction *action,
(GWeakNotify)action_destroyed,
proxy);
}
const char *moo_action_get_path (MooAction *action)
{
static char *path = NULL;
g_return_val_if_fail (MOO_IS_ACTION (action), NULL);
g_free (path);
path = g_strdup_printf ("%s::%s", action->group_id, action->id);
return path;
}

View File

@ -106,8 +106,6 @@ const char *moo_action_get_id (MooAction *action);
const char *moo_action_get_group_id (MooAction *action);
const char *moo_action_get_name (MooAction *action);
const char *moo_action_get_path (MooAction *action);
const char *moo_action_get_accel_path (MooAction *action);
void moo_action_set_no_accel (MooAction *action,

View File

@ -12,6 +12,7 @@
*/
#include "mooui/mooshortcutsprefs.h"
#include "mooui/mooaccel.h"
#include "mooutils/mooaccelbutton.h"
#include "mooutils/moostock.h"
#include "mooutils/mooprefs.h"
@ -199,16 +200,21 @@ GtkWidget *moo_shortcuts_prefs_page_new (MooActionGroup *actions)
"text", COLUMN_ACTION_NAME,
NULL);
gtk_tree_view_append_column (stuff->treeview, column);
gtk_tree_view_column_set_sort_column_id (column, COLUMN_ACTION_NAME);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Shortcut",
renderer,
"text", COLUMN_ACCEL,
NULL);
gtk_tree_view_append_column (stuff->treeview, column);
gtk_tree_view_column_set_sort_column_id (column, COLUMN_ACCEL);
stuff->selection = gtk_tree_view_get_selection (stuff->treeview);
gtk_tree_selection_set_mode (stuff->selection, GTK_SELECTION_SINGLE);
gtk_tree_view_set_headers_clickable (stuff->treeview, TRUE);
g_signal_connect_swapped (stuff->selection, "changed",
G_CALLBACK (tree_selection_changed),
stuff);
@ -234,8 +240,7 @@ static void apply_one (MooAction *action,
Shortcut *shortcut,
G_GNUC_UNUSED Stuff *stuff)
{
char *prefs_key = g_strdup_printf (MOO_ACCEL_PREFS_KEY "::%s",
moo_action_get_path (action));
const char *accel_path = moo_action_get_accel_path (action);
const char *accel = moo_action_get_accel (action);
const char *default_accel = moo_action_get_default_accel (action);
@ -243,26 +248,24 @@ static void apply_one (MooAction *action,
case NONE:
if (accel[0])
moo_action_set_accel (action, "");
moo_prefs_set (prefs_key, "");
moo_prefs_set_accel (accel_path, "");
break;
case CUSTOM:
if (strcmp (accel, shortcut->accel))
moo_action_set_accel (action, shortcut->accel);
moo_prefs_set (prefs_key, shortcut->accel);
moo_prefs_set_accel (accel_path, shortcut->accel);
break;
case DEFAULT:
if (strcmp (accel, default_accel))
moo_action_set_accel (action, default_accel);
moo_prefs_set (prefs_key, NULL);
moo_prefs_set_accel (accel_path, NULL);
break;
default:
g_assert_not_reached ();
}
g_free (prefs_key);
}
static void apply (Stuff *stuff)

View File

@ -20,12 +20,10 @@
G_BEGIN_DECLS
#define MOO_ACCEL_PREFS_KEY "shortcuts"
GtkWidget *moo_shortcuts_prefs_page_new (MooActionGroup *group);
GtkWidget *moo_shortcuts_prefs_dialog_new (MooActionGroup *group);
void moo_shortcuts_prefs_dialog_run (MooActionGroup *group,
GtkWidget *parent);
GtkWidget *moo_shortcuts_prefs_page_new (MooActionGroup *group);
GtkWidget *moo_shortcuts_prefs_dialog_new (MooActionGroup *group);
void moo_shortcuts_prefs_dialog_run (MooActionGroup *group,
GtkWidget *parent);
G_END_DECLS

View File

@ -12,7 +12,7 @@
*/
#include "mooui/moouiobject-impl.h"
#include "mooui/mooshortcutsprefs.h"
#include "mooui/mooaccel.h"
#include "mooui/mootoggleaction.h"
#include "mooui/moomenuaction.h"
#include "mooutils/mooprefs.h"
@ -322,14 +322,11 @@ void moo_ui_object_add_action (MooUIObject *object,
group = moo_ui_object_get_actions (object);
moo_action_group_add_action (group, action);
if (!action->dead) {
char *key;
if (!action->dead)
{
const char *accel;
key = g_strdup_printf ("%s::%s", MOO_ACCEL_PREFS_KEY, moo_action_get_path (action));
accel = moo_prefs_get (key);
accel = moo_prefs_get_accel (moo_action_get_accel_path (action));
if (accel) moo_action_set_accel (action, accel);
g_free (key);
}
}

View File

@ -165,7 +165,6 @@ static void moo_window_class_init (MooWindowClass *klass)
"label", "Configure _Shortcuts...",
"tooltip", "Configure _Shortcuts...",
"icon-stock-id", MOO_STOCK_KEYBOARD,
"default-accel", "",
"closure::callback", moo_window_shortcuts_prefs_dialog,
NULL);
@ -509,91 +508,6 @@ static void moo_window_shortcuts_prefs_dialog (MooWindow *window)
}
#if 0
void moo_window_new_action (gpointer window,
const char *id,
const char *first_prop,
...)
{
MooAction *action;
char *key;
const char *accel;
va_list args;
g_return_if_fail (MOO_IS_WINDOW (window));
va_start (args, first_prop);
action = moo_ui_object_new_actionv (MOO_UI_OBJECT (window), id, first_prop, args);
va_end (args);
key = g_strdup_printf ("%s::%s", MOO_ACCEL_PREFS_KEY, moo_action_get_path (action));
accel = moo_prefs_get (key);
if (accel) moo_action_set_accel (action, accel);
g_free (key);
}
void moo_window_new_toggle_action (gpointer window,
const char *id,
const char *first_prop,
...)
{
MooUIObject *object;
MooAction *action;
char *key;
const char *accel;
va_list args;
g_return_if_fail (MOO_IS_WINDOW (window));
object = MOO_UI_OBJECT (window);
action = MOO_ACTION (g_object_new (MOO_TYPE_TOGGLE_ACTION,
"id", id,
"group_id", moo_ui_object_get_id (object),
"group_name", moo_ui_object_get_name (object),
NULL));
va_start (args, first_prop);
g_object_set_valist (G_OBJECT (action), first_prop, args);
va_end (args);
moo_ui_object_add_action (MOO_UI_OBJECT (object), action);
g_object_unref (action);
key = g_strdup_printf ("%s::%s", MOO_ACCEL_PREFS_KEY, moo_action_get_path (action));
accel = moo_prefs_get (key);
if (accel) moo_action_set_accel (action, accel);
g_free (key);
}
void moo_window_add_standard_actions (MooWindow *window)
{
MooAction *toolbar_style_action;
moo_window_new_toggle_action (window, "ShowToolbar",
"name", "Show Toolbar",
"label", "Show Toolbar",
"tooltip", "Show Toolbar",
"default-accel", "",
"toggled-callback", moo_window_show_toolbar_toggled,
"toggled-data", window,
NULL);
toolbar_style_action =
MOO_ACTION (g_object_new (MOO_TYPE_MENU_ACTION,
"id", "ToolbarStyle",
"name", "Toolbar Style",
"group_name", moo_ui_object_get_name (MOO_UI_OBJECT (window)),
"create-menu-func", moo_window_create_toolbar_style_menu,
"create-menu-data", window,
"no-accel", TRUE,
NULL));
moo_ui_object_add_action (MOO_UI_OBJECT (window), toolbar_style_action);
window->priv->toolbar_style_action = toolbar_style_action;
}
#endif
static void moo_window_show_toolbar_toggled (MooWindow *window,
gboolean show)
{

View File

@ -602,13 +602,10 @@ gboolean moo_prefs_load (const char *file)
#ifdef __WIN32__
#define LINE_SEPARATOR "\r\n"
#define LINE_SEPARATOR_LEN 2
#elif defined(OS_DARWIN)
#define LINE_SEPARATOR "\r"
#define LINE_SEPARATOR_LEN 1
#else
#define LINE_SEPARATOR "\n"
#define LINE_SEPARATOR_LEN 1
#endif
typedef struct {
@ -624,6 +621,7 @@ static void write_item (const char *key,
gsize written;
GIOStatus status;
GError *err = NULL;
char *string;
if (!(item->value && item->changed) || stuff->error)
return;
@ -646,23 +644,11 @@ static void write_item (const char *key,
}
}
string = g_strdup_printf ("%s=%s" LINE_SEPARATOR, key, item->value);
status = g_io_channel_write_chars (stuff->file,
key, strlen (key),
string, -1,
&written, &err);
if (status == G_IO_STATUS_NORMAL)
status = g_io_channel_write_chars (stuff->file,
"=", 1,
&written, &err);
if (status == G_IO_STATUS_NORMAL)
status = g_io_channel_write_chars (stuff->file,
item->value,
strlen (item->value),
&written, &err);
if (status == G_IO_STATUS_NORMAL)
status = g_io_channel_write_chars (stuff->file,
LINE_SEPARATOR,
LINE_SEPARATOR_LEN,
&written, &err);
g_free (string);
if (status != G_IO_STATUS_NORMAL)
{