time-plugin: Port to WindowActivatable

This commit is contained in:
JosephMcc 2017-01-11 03:00:03 -08:00
parent 30a61a9fd8
commit 33cb6f4b32
3 changed files with 685 additions and 751 deletions

View File

@ -3,14 +3,16 @@ DIST_SUBDIRS = \
filebrowser \
modelines \
sort \
spell
spell \
time
SUBDIRS = \
docinfo \
filebrowser \
modelines \
sort \
spell
spell \
time
if ENABLE_ENCHANT
SUBDIRS += spell

View File

@ -16,8 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id$
*/
/*
@ -38,12 +36,11 @@
#include <glib/gi18n-lib.h>
#include <glib.h>
#include <gmodule.h>
#include <gio/gio.h>
#include <libpeas/peas-activatable.h>
#include <libpeas-gtk/peas-gtk-configurable.h>
#include <xed/xed-window.h>
#include <xed/xed-window-activatable.h>
#include <libpeas-gtk/peas-gtk-configurable.h>
#include <xed/xed-debug.h>
#include <xed/xed-utils.h>
@ -104,9 +101,17 @@ enum
NUM_COLUMNS
};
typedef struct _TimeConfigureDialog TimeConfigureDialog;
typedef enum
{
PROMPT_SELECTED_FORMAT = 0, /* Popup dialog with list preselected */
PROMPT_CUSTOM_FORMAT, /* Popup dialog with entry preselected */
USE_SELECTED_FORMAT, /* Use selected format directly */
USE_CUSTOM_FORMAT /* Use custom format directly */
} XedTimePluginPromptType;
struct _TimeConfigureDialog
typedef struct _TimeConfigureWidget TimeConfigureWidget;
struct _TimeConfigureWidget
{
GtkWidget *content;
@ -144,17 +149,9 @@ struct _ChooseFormatDialog
GSettings *settings;
};
typedef enum
{
PROMPT_SELECTED_FORMAT = 0, /* Popup dialog with list preselected */
PROMPT_CUSTOM_FORMAT, /* Popup dialog with entry preselected */
USE_SELECTED_FORMAT, /* Use selected format directly */
USE_CUSTOM_FORMAT /* Use custom format directly */
} XedTimePluginPromptType;
struct _XedTimePluginPrivate
{
GtkWidget *window;
XedWindow *window;
GSettings *settings;
@ -165,22 +162,23 @@ struct _XedTimePluginPrivate
enum
{
PROP_0,
PROP_OBJECT
PROP_WINDOW
};
static void peas_activatable_iface_init (PeasActivatableInterface *iface);
static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface);
static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTimePlugin,
xed_time_plugin,
PEAS_TYPE_EXTENSION_BASE,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
peas_activatable_iface_init)
G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE,
xed_window_activatable_iface_init)
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE,
peas_gtk_configurable_iface_init))
static void time_cb (GtkAction *action, XedTimePlugin *plugin);
static void time_cb (GtkAction *action,
XedTimePlugin *plugin);
static const GtkActionEntry action_entries[] =
{
@ -223,132 +221,79 @@ xed_time_plugin_dispose (GObject *object)
xed_debug_message (DEBUG_PLUGINS, "XedTimePlugin disposing");
if (plugin->priv->window != NULL)
{
g_object_unref (plugin->priv->window);
plugin->priv->window = NULL;
}
if (plugin->priv->action_group)
{
g_object_unref (plugin->priv->action_group);
plugin->priv->action_group = NULL;
}
g_clear_object (&plugin->priv->window);
g_clear_object (&plugin->priv->action_group);
G_OBJECT_CLASS (xed_time_plugin_parent_class)->dispose (object);
}
static void
update_ui (XedTimePluginPrivate *data)
update_ui (XedTimePlugin *plugin)
{
XedWindow *window;
XedView *view;
GtkAction *action;
xed_debug (DEBUG_PLUGINS);
window = XED_WINDOW (data->window);
view = xed_window_get_active_view (window);
view = xed_window_get_active_view (plugin->priv->window);
xed_debug_message (DEBUG_PLUGINS, "View: %p", view);
action = gtk_action_group_get_action (data->action_group,
"InsertDateAndTime");
gtk_action_set_sensitive (action,
(view != NULL) &&
gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
action = gtk_action_group_get_action (plugin->priv->action_group, "InsertDateAndTime");
gtk_action_set_sensitive (action, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
}
static void
xed_time_plugin_activate (PeasActivatable *activatable)
xed_time_plugin_activate (XedWindowActivatable *activatable)
{
XedTimePlugin *plugin;
XedTimePluginPrivate *data;
XedWindow *window;
XedTimePluginPrivate *priv;
GtkUIManager *manager;
xed_debug (DEBUG_PLUGINS);
plugin = XED_TIME_PLUGIN (activatable);
data = plugin->priv;
window = XED_WINDOW (data->window);
priv = XED_TIME_PLUGIN (activatable)->priv;
manager = xed_window_get_ui_manager (priv->window);
manager = xed_window_get_ui_manager (window);
priv->action_group = gtk_action_group_new ("XedTimePluginActions");
gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE);
gtk_action_group_add_actions (priv->action_group, action_entries, G_N_ELEMENTS (action_entries), activatable);
data->action_group = gtk_action_group_new ("XedTimePluginActions");
gtk_action_group_set_translation_domain (data->action_group,
GETTEXT_PACKAGE);
gtk_action_group_add_actions (data->action_group,
action_entries,
G_N_ELEMENTS (action_entries),
plugin);
gtk_ui_manager_insert_action_group (manager, priv->action_group, -1);
gtk_ui_manager_insert_action_group (manager, data->action_group, -1);
data->ui_id = gtk_ui_manager_new_merge_id (manager);
priv->ui_id = gtk_ui_manager_new_merge_id (manager);
gtk_ui_manager_add_ui (manager,
data->ui_id,
priv->ui_id,
MENU_PATH,
"InsertDateAndTime",
"InsertDateAndTime",
GTK_UI_MANAGER_MENUITEM,
FALSE);
update_ui (data);
update_ui (XED_TIME_PLUGIN (activatable));
}
static void
xed_time_plugin_deactivate (PeasActivatable *activatable)
xed_time_plugin_deactivate (XedWindowActivatable *activatable)
{
XedTimePluginPrivate *data;
XedWindow *window;
XedTimePluginPrivate *priv;
GtkUIManager *manager;
xed_debug (DEBUG_PLUGINS);
data = XED_TIME_PLUGIN (activatable)->priv;
window = XED_WINDOW (data->window);
priv = XED_TIME_PLUGIN (activatable)->priv;
manager = xed_window_get_ui_manager (priv->window);
manager = xed_window_get_ui_manager (window);
gtk_ui_manager_remove_ui (manager, data->ui_id);
gtk_ui_manager_remove_action_group (manager, data->action_group);
gtk_ui_manager_remove_ui (manager, priv->ui_id);
gtk_ui_manager_remove_action_group (manager, priv->action_group);
}
static void
xed_time_plugin_update_state (PeasActivatable *activatable)
xed_time_plugin_update_state (XedWindowActivatable *activatable)
{
xed_debug (DEBUG_PLUGINS);
update_ui (XED_TIME_PLUGIN (activatable)->priv);
}
/* whether we should prompt the user or use the specified format */
static XedTimePluginPromptType
get_prompt_type (XedTimePlugin *plugin)
{
XedTimePluginPromptType prompt_type;
prompt_type = g_settings_get_enum (plugin->priv->settings,
PROMPT_TYPE_KEY);
return prompt_type;
}
static void
set_prompt_type (GSettings *settings,
XedTimePluginPromptType prompt_type)
{
if (!g_settings_is_writable (settings,
PROMPT_TYPE_KEY))
{
return;
}
g_settings_set_enum (settings,
PROMPT_TYPE_KEY,
prompt_type);
update_ui (XED_TIME_PLUGIN (activatable));
}
/* The selected format in the list */
@ -357,28 +302,24 @@ get_selected_format (XedTimePlugin *plugin)
{
gchar *sel_format;
sel_format = g_settings_get_string (plugin->priv->settings,
SELECTED_FORMAT_KEY);
sel_format = g_settings_get_string (plugin->priv->settings, SELECTED_FORMAT_KEY);
return sel_format ? sel_format : g_strdup (formats [0]);
}
static void
set_selected_format (GSettings *settings,
const gchar *format)
{
g_return_if_fail (format != NULL);
// static void
// set_selected_format (XedTimePlugin *plugin,
// const gchar *format)
// {
// g_return_if_fail (format != NULL);
if (!g_settings_is_writable (settings,
SELECTED_FORMAT_KEY))
{
return;
}
// if (!g_settings_is_writable (plugin->priv->settings, SELECTED_FORMAT_KEY))
// {
// return;
// }
g_settings_set_string (settings,
SELECTED_FORMAT_KEY,
format);
}
// g_settings_set_string (settings, SELECTED_FORMAT_KEY, format);
// }
/* the custom format in the entry */
static gchar *
@ -386,26 +327,24 @@ get_custom_format (XedTimePlugin *plugin)
{
gchar *format;
format = g_settings_get_string (plugin->priv->settings,
CUSTOM_FORMAT_KEY);
format = g_settings_get_string (plugin->priv->settings, CUSTOM_FORMAT_KEY);
return format ? format : g_strdup (DEFAULT_CUSTOM_FORMAT);
}
static void
set_custom_format (GSettings *settings,
const gchar *format)
{
g_return_if_fail (format != NULL);
// static void
// set_custom_format (XedTimePlugin *plugin,
// const gchar *format)
// {
// g_return_if_fail (format != NULL);
if (!g_settings_is_writable (settings,
CUSTOM_FORMAT_KEY))
return;
// if (!g_settings_is_writable (plugin->priv->settings, CUSTOM_FORMAT_KEY))
// {
// return;
// }
g_settings_set_string (settings,
CUSTOM_FORMAT_KEY,
format);
}
// g_settings_set_string (plugin->priv->settings, CUSTOM_FORMAT_KEY, format);
// }
static gchar *
get_time (const gchar* format)
@ -422,11 +361,15 @@ get_time (const gchar* format)
g_return_val_if_fail (format != NULL, NULL);
if (strlen (format) == 0)
{
return g_strdup (" ");
}
locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
if (locale_format == NULL)
{
return g_strdup (" ");
}
clock = time (NULL);
now = localtime (&clock);
@ -450,22 +393,26 @@ get_time (const gchar* format)
g_free (out);
if (out_utf8 == NULL)
{
out_utf8 = g_strdup (" ");
}
}
return out_utf8;
}
static void
configure_dialog_destroyed (GtkWidget *widget,
configure_widget_destroyed (GtkWidget *widget,
gpointer data)
{
TimeConfigureDialog *dialog = (TimeConfigureDialog *) data;
TimeConfigureWidget *conf_widget = (TimeConfigureWidget *) data;
xed_debug (DEBUG_PLUGINS);
g_object_unref (dialog->settings);
g_slice_free (TimeConfigureDialog, data);
g_object_unref (conf_widget->settings);
g_slice_free (TimeConfigureWidget, data);
xed_debug_message (DEBUG_PLUGINS, "END");
}
static void
@ -475,6 +422,8 @@ choose_format_dialog_destroyed (GtkWidget *widget,
xed_debug (DEBUG_PLUGINS);
g_slice_free (ChooseFormatDialog, data);
xed_debug_message (DEBUG_PLUGINS, "END");
}
static GtkTreeModel *
@ -493,8 +442,7 @@ create_model (GtkWidget *listview,
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
/* Set tree view model*/
gtk_tree_view_set_model (GTK_TREE_VIEW (listview),
GTK_TREE_MODEL (store));
gtk_tree_view_set_model (GTK_TREE_VIEW (listview), GTK_TREE_MODEL (store));
g_object_unref (G_OBJECT (store));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (listview));
@ -512,14 +460,13 @@ create_model (GtkWidget *listview,
xed_debug_message (DEBUG_PLUGINS, "%d : %s", i, str);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COLUMN_FORMATS, str,
COLUMN_INDEX, i,
-1);
gtk_list_store_set (store, &iter, COLUMN_FORMATS, str, COLUMN_INDEX, i, -1);
g_free (str);
if (sel_format && strcmp (formats[i], sel_format) == 0)
{
gtk_tree_selection_select_iter (selection, &iter);
}
++i;
}
@ -557,8 +504,7 @@ scroll_to_selected (GtkTreeView *tree_view)
path = gtk_tree_model_get_path (model, &iter);
g_return_if_fail (path != NULL);
gtk_tree_view_scroll_to_cell (tree_view,
path, NULL, TRUE, 1.0, 0.0);
gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 1.0, 0.0);
gtk_tree_path_free (path);
}
}
@ -578,8 +524,7 @@ create_formats_list (GtkWidget *listview,
/* the Available formats column */
cell = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (
_("Available formats"),
column = gtk_tree_view_column_new_with_attributes (_("Available formats"),
cell,
"text", COLUMN_FORMATS,
NULL);
@ -588,10 +533,8 @@ create_formats_list (GtkWidget *listview,
/* Create model, it also add model to the tree view */
create_model (listview, sel_format, plugin);
g_signal_connect (listview,
"realize",
G_CALLBACK (scroll_to_selected),
NULL);
g_signal_connect (listview, "realize",
G_CALLBACK (scroll_to_selected), NULL);
gtk_widget_show (listview);
}
@ -635,54 +578,60 @@ choose_format_dialog_button_toggled (GtkToggleButton *button,
gtk_widget_set_sensitive (dialog->list, FALSE);
gtk_widget_set_sensitive (dialog->custom_entry, TRUE);
gtk_widget_set_sensitive (dialog->custom_format_example, TRUE);
return;
}
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list)))
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list)))
{
gtk_widget_set_sensitive (dialog->list, TRUE);
gtk_widget_set_sensitive (dialog->custom_entry, FALSE);
gtk_widget_set_sensitive (dialog->custom_format_example, FALSE);
return;
}
else
{
g_return_if_reached ();
}
}
static void
configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *dialog)
configure_widget_button_toggled (GtkToggleButton *button,
TimeConfigureWidget *conf_widget)
{
XedTimePluginPromptType prompt_type;
xed_debug (DEBUG_PLUGINS);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->custom)))
{
gtk_widget_set_sensitive (dialog->list, FALSE);
gtk_widget_set_sensitive (dialog->custom_entry, TRUE);
gtk_widget_set_sensitive (dialog->custom_format_example, TRUE);
gtk_widget_set_sensitive (conf_widget->list, FALSE);
gtk_widget_set_sensitive (conf_widget->custom_entry, TRUE);
gtk_widget_set_sensitive (conf_widget->custom_format_example, TRUE);
set_prompt_type (dialog->settings, USE_CUSTOM_FORMAT);
return;
prompt_type = USE_CUSTOM_FORMAT;
}
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list)))
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->use_list)))
{
gtk_widget_set_sensitive (dialog->list, TRUE);
gtk_widget_set_sensitive (dialog->custom_entry, FALSE);
gtk_widget_set_sensitive (dialog->custom_format_example, FALSE);
gtk_widget_set_sensitive (conf_widget->list, TRUE);
gtk_widget_set_sensitive (conf_widget->custom_entry, FALSE);
gtk_widget_set_sensitive (conf_widget->custom_format_example, FALSE);
set_prompt_type (dialog->settings, USE_SELECTED_FORMAT);
return;
prompt_type = USE_SELECTED_FORMAT;
}
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->prompt)))
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (conf_widget->prompt)))
{
gtk_widget_set_sensitive (dialog->list, FALSE);
gtk_widget_set_sensitive (dialog->custom_entry, FALSE);
gtk_widget_set_sensitive (dialog->custom_format_example, FALSE);
gtk_widget_set_sensitive (conf_widget->list, FALSE);
gtk_widget_set_sensitive (conf_widget->custom_entry, FALSE);
gtk_widget_set_sensitive (conf_widget->custom_format_example, FALSE);
set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT);
return;
prompt_type = PROMPT_SELECTED_FORMAT;
}
else
{
g_return_if_reached ();
}
g_settings_set_enum (conf_widget->settings, PROMPT_TYPE_KEY, prompt_type);
}
static gint
@ -714,27 +663,36 @@ get_format_from_list (GtkWidget *listview)
g_return_val_if_reached (0);
}
// static void
// configure_dialog_selection_changed (GtkTreeSelection *selection,
// TimeConfigureDialog *dialog)
// {
// gint sel_format;
// sel_format = get_format_from_list (dialog->list);
// set_selected_format (dialog->settings, formats[sel_format]);
// }
static void
configure_dialog_selection_changed (GtkTreeSelection *selection,
TimeConfigureDialog *dialog)
on_configure_widget_selection_changed (GtkTreeSelection *selection,
TimeConfigureWidget *conf_widget)
{
gint sel_format;
sel_format = get_format_from_list (dialog->list);
set_selected_format (dialog->settings, formats[sel_format]);
sel_format = get_format_from_list (conf_widget->list);
g_settings_set_string (conf_widget->settings, SELECTED_FORMAT_KEY, formats[sel_format]);
}
static TimeConfigureDialog *
get_configure_dialog (XedTimePlugin *plugin)
static TimeConfigureWidget *
get_configure_widget (XedTimePlugin *plugin)
{
TimeConfigureDialog *dialog = NULL;
TimeConfigureWidget *widget = NULL;
GtkTreeSelection *selection;
gchar *data_dir;
gchar *ui_file;
GtkWidget *content;
GtkWidget *viewport;
XedTimePluginPromptType prompt_type;
gchar *sf, *cf;
gchar *sf;
GtkWidget *error_widget;
gboolean ret;
gchar *root_objects[] = {
@ -744,22 +702,22 @@ get_configure_dialog (XedTimePlugin *plugin)
xed_debug (DEBUG_PLUGINS);
dialog = g_slice_new (TimeConfigureDialog);
dialog->settings = g_object_ref (plugin->priv->settings);
widget = g_slice_new (TimeConfigureWidget);
widget->settings = g_object_ref (plugin->priv->settings);
data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
ui_file = g_build_filename (data_dir, "xed-time-setup-dialog.ui", NULL);
ret = xed_utils_get_ui_objects (ui_file,
root_objects,
&error_widget,
"time_dialog_content", &dialog->content,
"time_dialog_content", &widget->content,
"formats_viewport", &viewport,
"formats_tree", &dialog->list,
"always_prompt", &dialog->prompt,
"never_prompt", &dialog->use_list,
"use_custom", &dialog->custom,
"custom_entry", &dialog->custom_entry,
"custom_format_example", &dialog->custom_format_example,
"formats_tree", &widget->list,
"always_prompt", &widget->prompt,
"never_prompt", &widget->use_list,
"use_custom", &widget->custom,
"custom_entry", &widget->custom_entry,
"custom_format_example", &widget->custom_format_example,
NULL);
g_free (data_dir);
@ -771,56 +729,61 @@ get_configure_dialog (XedTimePlugin *plugin)
}
sf = get_selected_format (plugin);
create_formats_list (dialog->list, sf, plugin);
create_formats_list (widget->list, sf, plugin);
g_free (sf);
prompt_type = get_prompt_type (plugin);
prompt_type = g_settings_get_enum (plugin->priv->settings, PROMPT_TYPE_KEY);
g_settings_bind (dialog->settings, CUSTOM_FORMAT_KEY,
dialog->custom_entry, "text",
g_settings_bind (widget->settings, CUSTOM_FORMAT_KEY,
widget->custom_entry, "text",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
if (prompt_type == USE_CUSTOM_FORMAT)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->custom), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->custom), TRUE);
gtk_widget_set_sensitive (dialog->list, FALSE);
gtk_widget_set_sensitive (dialog->custom_entry, TRUE);
gtk_widget_set_sensitive (dialog->custom_format_example, TRUE);
gtk_widget_set_sensitive (widget->list, FALSE);
gtk_widget_set_sensitive (widget->custom_entry, TRUE);
gtk_widget_set_sensitive (widget->custom_format_example, TRUE);
}
else if (prompt_type == USE_SELECTED_FORMAT)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->use_list), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->use_list), TRUE);
gtk_widget_set_sensitive (dialog->list, TRUE);
gtk_widget_set_sensitive (dialog->custom_entry, FALSE);
gtk_widget_set_sensitive (dialog->custom_format_example, FALSE);
gtk_widget_set_sensitive (widget->list, TRUE);
gtk_widget_set_sensitive (widget->custom_entry, FALSE);
gtk_widget_set_sensitive (widget->custom_format_example, FALSE);
}
else
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->prompt), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->prompt), TRUE);
gtk_widget_set_sensitive (dialog->list, FALSE);
gtk_widget_set_sensitive (dialog->custom_entry, FALSE);
gtk_widget_set_sensitive (dialog->custom_format_example, FALSE);
gtk_widget_set_sensitive (widget->list, FALSE);
gtk_widget_set_sensitive (widget->custom_entry, FALSE);
gtk_widget_set_sensitive (widget->custom_format_example, FALSE);
}
updated_custom_format_example (GTK_ENTRY (dialog->custom_entry),
GTK_LABEL (dialog->custom_format_example));
updated_custom_format_example (GTK_ENTRY (widget->custom_entry), GTK_LABEL (widget->custom_format_example));
/* setup a window of a sane size. */
gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200);
g_signal_connect (dialog->custom, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog);
g_signal_connect (dialog->prompt, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog);
g_signal_connect (dialog->use_list, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog);
g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog);
g_signal_connect (dialog->custom_entry, "changed", G_CALLBACK (updated_custom_format_example), dialog->custom_format_example);
g_signal_connect (widget->custom, "toggled",
G_CALLBACK (configure_widget_button_toggled), widget);
g_signal_connect (widget->prompt, "toggled",
G_CALLBACK (configure_widget_button_toggled), widget);
g_signal_connect (widget->use_list, "toggled",
G_CALLBACK (configure_widget_button_toggled), widget);
g_signal_connect (widget->content, "destroy",
G_CALLBACK (configure_widget_destroyed), widget);
g_signal_connect (widget->custom_entry, "changed",
G_CALLBACK (updated_custom_format_example), widget->custom_format_example);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list));
g_signal_connect (selection, "changed", G_CALLBACK (configure_dialog_selection_changed), dialog);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget->list));
g_signal_connect (selection, "changed",
G_CALLBACK (on_configure_widget_selection_changed), widget);
return dialog;
return widget;
}
static void
@ -849,8 +812,8 @@ choose_format_dialog_row_activated (GtkTreeView *list,
sel_format = get_format_from_list (dialog->list);
the_time = get_time (formats[sel_format]);
set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT);
set_selected_format (dialog->settings, formats[sel_format]);
g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_SELECTED_FORMAT);
g_settings_set_string (dialog->settings, SELECTED_FORMAT_KEY, formats[sel_format]);
g_return_if_fail (the_time != NULL);
@ -873,7 +836,9 @@ get_choose_format_dialog (GtkWindow *parent,
GtkWindowGroup *wg = NULL;
if (parent != NULL)
{
wg = gtk_window_get_group (parent);
}
dialog = g_slice_new (ChooseFormatDialog);
dialog->settings = plugin->priv->settings;
@ -905,26 +870,24 @@ get_choose_format_dialog (GtkWindow *parent,
NULL);
if (wg != NULL)
{
gtk_window_group_add_window (wg, GTK_WINDOW (err_dialog));
}
gtk_window_set_resizable (GTK_WINDOW (err_dialog), FALSE);
gtk_dialog_set_default_response (GTK_DIALOG (err_dialog), GTK_RESPONSE_OK);
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (err_dialog))),
error_widget);
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (err_dialog))), error_widget);
g_signal_connect (G_OBJECT (err_dialog),
"response",
G_CALLBACK (gtk_widget_destroy),
NULL);
g_signal_connect (G_OBJECT (err_dialog), "response",
G_CALLBACK (gtk_widget_destroy), NULL);
gtk_widget_show_all (err_dialog);
return NULL;
}
gtk_window_group_add_window (wg,
GTK_WINDOW (dialog->dialog));
gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog));
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), parent);
gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE);
@ -933,7 +896,7 @@ get_choose_format_dialog (GtkWindow *parent,
g_free (sf);
cf = get_custom_format (plugin);
gtk_entry_set_text (GTK_ENTRY(dialog->custom_entry), cf);
gtk_entry_set_text (GTK_ENTRY (dialog->custom_entry), cf);
g_free (cf);
updated_custom_format_example (GTK_ENTRY (dialog->custom_entry),
@ -963,29 +926,18 @@ get_choose_format_dialog (GtkWindow *parent,
/* setup a window of a sane size. */
gtk_widget_set_size_request (dialog->list, 10, 200);
gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
GTK_RESPONSE_OK);
gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK);
g_signal_connect (dialog->custom,
"toggled",
G_CALLBACK (choose_format_dialog_button_toggled),
dialog);
g_signal_connect (dialog->use_list,
"toggled",
G_CALLBACK (choose_format_dialog_button_toggled),
dialog);
g_signal_connect (dialog->dialog,
"destroy",
G_CALLBACK (choose_format_dialog_destroyed),
dialog);
g_signal_connect (dialog->custom_entry,
"changed",
G_CALLBACK (updated_custom_format_example),
dialog->custom_format_example);
g_signal_connect (dialog->list,
"row_activated",
G_CALLBACK (choose_format_dialog_row_activated),
dialog);
g_signal_connect (dialog->custom, "toggled",
G_CALLBACK (choose_format_dialog_button_toggled), dialog);
g_signal_connect (dialog->use_list, "toggled",
G_CALLBACK (choose_format_dialog_button_toggled), dialog);
g_signal_connect (dialog->dialog, "destroy",
G_CALLBACK (choose_format_dialog_destroyed), dialog);
g_signal_connect (dialog->custom_entry, "changed",
G_CALLBACK (updated_custom_format_example), dialog->custom_format_example);
g_signal_connect (dialog->list, "row_activated",
G_CALLBACK (choose_format_dialog_row_activated), dialog);
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
@ -1002,9 +954,7 @@ choose_format_dialog_response_cb (GtkWidget *widget,
case GTK_RESPONSE_HELP:
{
xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP");
xed_help_display (GTK_WINDOW (widget),
NULL,
"xed-insert-date-time-plugin");
xed_help_display (GTK_WINDOW (widget), NULL, "xed-insert-date-time-plugin");
break;
}
case GTK_RESPONSE_OK:
@ -1021,8 +971,8 @@ choose_format_dialog_response_cb (GtkWidget *widget,
sel_format = get_format_from_list (dialog->list);
the_time = get_time (formats[sel_format]);
set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT);
set_selected_format (dialog->settings, formats[sel_format]);
g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_SELECTED_FORMAT);
g_settings_set_string (dialog->settings, SELECTED_FORMAT_KEY, formats[sel_format]);
}
else
{
@ -1031,8 +981,8 @@ choose_format_dialog_response_cb (GtkWidget *widget,
format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry));
the_time = get_time (format);
set_prompt_type (dialog->settings, PROMPT_CUSTOM_FORMAT);
set_custom_format (dialog->settings, format);
g_settings_set_enum (dialog->settings, PROMPT_TYPE_KEY, PROMPT_CUSTOM_FORMAT);
g_settings_set_string (dialog->settings, CUSTOM_FORMAT_KEY, format);
}
g_return_if_fail (the_time != NULL);
@ -1053,18 +1003,19 @@ static void
time_cb (GtkAction *action,
XedTimePlugin *plugin)
{
XedWindow *window;
XedTimePluginPrivate *priv;
GtkTextBuffer *buffer;
gchar *the_time = NULL;
XedTimePluginPromptType prompt_type;
xed_debug (DEBUG_PLUGINS);
window = XED_WINDOW (plugin->priv->window);
buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (window));
priv = plugin->priv;
buffer = GTK_TEXT_BUFFER (xed_window_get_active_document (priv->window));
g_return_if_fail (buffer != NULL);
prompt_type = get_prompt_type (plugin);
prompt_type = g_settings_get_enum (plugin->priv->settings, PROMPT_TYPE_KEY);
if (prompt_type == USE_CUSTOM_FORMAT)
{
@ -1082,18 +1033,14 @@ time_cb (GtkAction *action,
{
ChooseFormatDialog *dialog;
dialog = get_choose_format_dialog (GTK_WINDOW (window),
prompt_type,
plugin);
dialog = get_choose_format_dialog (GTK_WINDOW (priv->window), prompt_type, plugin);
if (dialog != NULL)
{
dialog->buffer = buffer;
dialog->settings = plugin->priv->settings;
dialog->settings = priv->settings;
g_signal_connect (dialog->dialog,
"response",
G_CALLBACK (choose_format_dialog_response_cb),
dialog);
g_signal_connect (dialog->dialog, "response",
G_CALLBACK (choose_format_dialog_response_cb), dialog);
gtk_widget_show (GTK_WIDGET (dialog->dialog));
}
@ -1111,11 +1058,11 @@ time_cb (GtkAction *action,
static GtkWidget *
xed_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable)
{
TimeConfigureDialog *dialog;
TimeConfigureWidget *widget;
dialog = get_configure_dialog (XED_TIME_PLUGIN (configurable));
widget = get_configure_widget (XED_TIME_PLUGIN (configurable));
return dialog->content;
return widget->content;
}
static void
@ -1128,8 +1075,8 @@ xed_time_plugin_set_property (GObject *object,
switch (prop_id)
{
case PROP_OBJECT:
plugin->priv->window = GTK_WIDGET (g_value_dup_object (value));
case PROP_WINDOW:
plugin->priv->window = XED_WINDOW (g_value_dup_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -1147,7 +1094,7 @@ xed_time_plugin_get_property (GObject *object,
switch (prop_id)
{
case PROP_OBJECT:
case PROP_WINDOW:
g_value_set_object (value, plugin->priv->window);
break;
default:
@ -1166,7 +1113,7 @@ xed_time_plugin_class_init (XedTimePluginClass *klass)
object_class->set_property = xed_time_plugin_set_property;
object_class->get_property = xed_time_plugin_get_property;
g_object_class_override_property (object_class, PROP_OBJECT, "object");
g_object_class_override_property (object_class, PROP_WINDOW, "window");
g_type_class_add_private (object_class, sizeof (XedTimePluginPrivate));
}
@ -1178,7 +1125,7 @@ xed_time_plugin_class_finalize (XedTimePluginClass *klass)
}
static void
peas_activatable_iface_init (PeasActivatableInterface *iface)
xed_window_activatable_iface_init (XedWindowActivatableInterface *iface)
{
iface->activate = xed_time_plugin_activate;
iface->deactivate = xed_time_plugin_deactivate;
@ -1197,7 +1144,7 @@ peas_register_types (PeasObjectModule *module)
xed_time_plugin_register_type (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE,
XED_TYPE_WINDOW_ACTIVATABLE,
XED_TYPE_TIME_PLUGIN);
peas_object_module_register_extension_type (module,

View File

@ -30,9 +30,6 @@
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define XED_TYPE_TIME_PLUGIN (xed_time_plugin_get_type ())
#define XED_TIME_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TIME_PLUGIN, XedTimePlugin))
#define XED_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TIME_PLUGIN, XedTimePluginClass))
@ -40,13 +37,9 @@ G_BEGIN_DECLS
#define XED_IS_TIME_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TIME_PLUGIN))
#define XED_TIME_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TIME_PLUGIN, XedTimePluginClass))
/* Private structure type */
typedef struct _XedTimePluginPrivate XedTimePluginPrivate;
/*
* Main object structure
*/
typedef struct _XedTimePlugin XedTimePlugin;
typedef struct _XedTimePluginPrivate XedTimePluginPrivate;
typedef struct _XedTimePluginClass XedTimePluginClass;
struct _XedTimePlugin
{
@ -56,19 +49,11 @@ struct _XedTimePlugin
XedTimePluginPrivate *priv;
};
/*
* Class definition
*/
typedef struct _XedTimePluginClass XedTimePluginClass;
struct _XedTimePluginClass
{
PeasExtensionBaseClass parent_class;
};
/*
* Public methods
*/
GType xed_time_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */