From 564ca51a2544db1be35fd1493110b6db8ecdc4a6 Mon Sep 17 00:00:00 2001 From: monsta Date: Sun, 4 Dec 2016 17:33:08 +0300 Subject: time plugin: port to libpeas mostly adapted from: https://git.gnome.org/browse/gedit/commit/?id=529bb71a0d3d514639611a7e989767e24a47dc6b https://git.gnome.org/browse/gedit/commit/?id=69a0f7450453b787c5b5fbcb59366493501797a9 --- plugins/time/pluma-time-plugin.c | 226 ++++++++++++++++++++++++++------------- plugins/time/pluma-time-plugin.h | 9 +- 2 files changed, 159 insertions(+), 76 deletions(-) (limited to 'plugins/time') diff --git a/plugins/time/pluma-time-plugin.c b/plugins/time/pluma-time-plugin.c index 1cda2c35..0a49f850 100644 --- a/plugins/time/pluma-time-plugin.c +++ b/plugins/time/pluma-time-plugin.c @@ -40,7 +40,10 @@ #include #include #include +#include +#include +#include #include #include @@ -48,7 +51,6 @@ PLUMA_TYPE_TIME_PLUGIN, \ PlumaTimePluginPrivate)) -#define WINDOW_DATA_KEY "PlumaTimePluginWindowData" #define MENU_PATH "/MenuBar/EditMenu/EditOps_4" /* GSettings keys */ @@ -152,24 +154,32 @@ typedef enum struct _PlumaTimePluginPrivate { - GSettings *settings; -}; + GtkWidget *window; -PLUMA_PLUGIN_REGISTER_TYPE(PlumaTimePlugin, pluma_time_plugin) + GSettings *settings; -typedef struct -{ GtkActionGroup *action_group; guint ui_id; -} WindowData; +}; -typedef struct -{ - PlumaWindow *window; - PlumaTimePlugin *plugin; -} ActionData; +enum { + PROP_0, + PROP_OBJECT +}; + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); -static void time_cb (GtkAction *action, ActionData *data); +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaTimePlugin, + pluma_time_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, + peas_gtk_configurable_iface_init)) + +static void time_cb (GtkAction *action, PlumaTimePlugin *plugin); static const GtkActionEntry action_entries[] = { @@ -206,23 +216,37 @@ pluma_time_plugin_finalize (GObject *object) } static void -free_window_data (WindowData *data) +pluma_time_plugin_dispose (GObject *object) { - g_return_if_fail (data != NULL); + PlumaTimePlugin *plugin = PLUMA_TIME_PLUGIN (object); + + pluma_debug_message (DEBUG_PLUGINS, "PlumaTimePlugin 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_object_unref (data->action_group); - g_free (data); + G_OBJECT_CLASS (pluma_time_plugin_parent_class)->dispose (object); } static void -update_ui_real (PlumaWindow *window, - WindowData *data) +update_ui (PlumaTimePluginPrivate *data) { + PlumaWindow *window; PlumaView *view; GtkAction *action; pluma_debug (DEBUG_PLUGINS); + window = PLUMA_WINDOW (data->window); view = pluma_window_get_active_view (window); pluma_debug_message (DEBUG_PLUGINS, "View: %p", view); @@ -235,41 +259,33 @@ update_ui_real (PlumaWindow *window, } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_time_plugin_activate (PeasActivatable *activatable) { + PlumaTimePlugin *plugin; + PlumaTimePluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; pluma_debug (DEBUG_PLUGINS); - data = g_new (WindowData, 1); - action_data = g_new (ActionData, 1); - - action_data->plugin = PLUMA_TIME_PLUGIN (plugin); - action_data->window = window; + plugin = PLUMA_TIME_PLUGIN (activatable); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); manager = pluma_window_get_ui_manager (window); data->action_group = gtk_action_group_new ("PlumaTimePluginActions"); gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->action_group, + gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) g_free); + plugin); gtk_ui_manager_insert_action_group (manager, data->action_group, -1); data->ui_id = gtk_ui_manager_new_merge_id (manager); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, @@ -278,41 +294,33 @@ impl_activate (PlumaPlugin *plugin, GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, data); + update_ui (data); } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_time_plugin_deactivate (PeasActivatable *activatable) { + PlumaTimePluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - manager = pluma_window_get_ui_manager (window); + data = PLUMA_TIME_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = pluma_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -impl_update_ui (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_time_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - pluma_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - update_ui_real (window, data); + update_ui (PLUMA_TIME_PLUGIN (activatable)->priv); } /* whether we should prompt the user or use the specified format */ @@ -735,7 +743,7 @@ get_configure_dialog (PlumaTimePlugin *plugin) gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6); - data_dir = pluma_plugin_get_data_dir (PLUMA_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "pluma-time-setup-dialog.ui", NULL); ret = pluma_utils_get_ui_objects (ui_file, root_objects, @@ -894,7 +902,7 @@ get_choose_format_dialog (GtkWindow *parent, dialog = g_new0 (ChooseFormatDialog, 1); - data_dir = pluma_plugin_get_data_dir (PLUMA_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "pluma-time-dialog.ui", NULL); ret = pluma_utils_get_ui_objects (ui_file, NULL, @@ -1067,28 +1075,30 @@ choose_format_dialog_response_cb (GtkWidget *widget, static void time_cb (GtkAction *action, - ActionData *data) + PlumaTimePlugin *plugin) { + PlumaWindow *window; GtkTextBuffer *buffer; gchar *the_time = NULL; PlumaTimePluginPromptType prompt_type; pluma_debug (DEBUG_PLUGINS); - buffer = GTK_TEXT_BUFFER (pluma_window_get_active_document (data->window)); + window = PLUMA_WINDOW (plugin->priv->window); + buffer = GTK_TEXT_BUFFER (pluma_window_get_active_document (window)); g_return_if_fail (buffer != NULL); - prompt_type = get_prompt_type (data->plugin); + prompt_type = get_prompt_type (plugin); if (prompt_type == USE_CUSTOM_FORMAT) { - gchar *cf = get_custom_format (data->plugin); + gchar *cf = get_custom_format (plugin); the_time = get_time (cf); g_free (cf); } else if (prompt_type == USE_SELECTED_FORMAT) { - gchar *sf = get_selected_format (data->plugin); + gchar *sf = get_selected_format (plugin); the_time = get_time (sf); g_free (sf); } @@ -1096,13 +1106,13 @@ time_cb (GtkAction *action, { ChooseFormatDialog *dialog; - dialog = get_choose_format_dialog (GTK_WINDOW (data->window), + dialog = get_choose_format_dialog (GTK_WINDOW (window), prompt_type, - data->plugin); + plugin); if (dialog != NULL) { dialog->buffer = buffer; - dialog->plugin = data->plugin; + dialog->plugin = plugin; g_signal_connect (dialog->dialog, "response", @@ -1187,13 +1197,13 @@ configure_dialog_response_cb (GtkWidget *widget, } static GtkWidget * -impl_create_configure_dialog (PlumaPlugin *plugin) +pluma_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { TimeConfigureDialog *dialog; - dialog = get_configure_dialog (PLUMA_TIME_PLUGIN (plugin)); + dialog = get_configure_dialog (PLUMA_TIME_PLUGIN (configurable)); - dialog->plugin = PLUMA_TIME_PLUGIN (plugin); + dialog->plugin = PLUMA_TIME_PLUGIN (configurable); g_signal_connect (dialog->dialog, "response", @@ -1203,19 +1213,91 @@ impl_create_configure_dialog (PlumaPlugin *plugin) return GTK_WIDGET (dialog->dialog); } +static void +pluma_time_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PlumaTimePlugin *plugin = PLUMA_TIME_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +pluma_time_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PlumaTimePlugin *plugin = PLUMA_TIME_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void pluma_time_plugin_class_init (PlumaTimePluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); object_class->finalize = pluma_time_plugin_finalize; + object_class->dispose = pluma_time_plugin_dispose; + object_class->set_property = pluma_time_plugin_set_property; + object_class->get_property = pluma_time_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; - - plugin_class->create_configure_dialog = impl_create_configure_dialog; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_type_class_add_private (object_class, sizeof (PlumaTimePluginPrivate)); } + +static void +pluma_time_plugin_class_finalize (PlumaTimePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_time_plugin_activate; + iface->deactivate = pluma_time_plugin_deactivate; + iface->update_state = pluma_time_plugin_update_state; +} + +static void +peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface) +{ + iface->create_configure_widget = pluma_time_plugin_create_configure_widget; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_time_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_TIME_PLUGIN); + + peas_object_module_register_extension_type (module, + PEAS_GTK_TYPE_CONFIGURABLE, + PLUMA_TYPE_TIME_PLUGIN); +} diff --git a/plugins/time/pluma-time-plugin.h b/plugins/time/pluma-time-plugin.h index 7795c9c8..3b9bb7bf 100644 --- a/plugins/time/pluma-time-plugin.h +++ b/plugins/time/pluma-time-plugin.h @@ -25,7 +25,8 @@ #include #include -#include +#include +#include G_BEGIN_DECLS @@ -49,7 +50,7 @@ typedef struct _PlumaTimePlugin PlumaTimePlugin; struct _PlumaTimePlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; /*< private >*/ PlumaTimePluginPrivate *priv; @@ -62,7 +63,7 @@ typedef struct _PlumaTimePluginClass PlumaTimePluginClass; struct _PlumaTimePluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -71,7 +72,7 @@ struct _PlumaTimePluginClass GType pluma_time_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS -- cgit v1.2.1 From 95d29254d97484cbbece5a7acd994025d90699e1 Mon Sep 17 00:00:00 2001 From: monsta Date: Sun, 4 Dec 2016 19:54:27 +0300 Subject: time plugin: adapt configure dialog to libpeas interface mostly adapted from: https://git.gnome.org/browse/gedit/commit/?id=f9cfaba1bca880e40048cb7ac044b9e34627c378 https://git.gnome.org/browse/gedit/commit/?id=20011152c7a6b372dec92120439faad7a730d35b --- plugins/time/pluma-time-plugin.c | 219 +++++++++++++-------------------------- 1 file changed, 71 insertions(+), 148 deletions(-) (limited to 'plugins/time') diff --git a/plugins/time/pluma-time-plugin.c b/plugins/time/pluma-time-plugin.c index 0a49f850..1266f971 100644 --- a/plugins/time/pluma-time-plugin.c +++ b/plugins/time/pluma-time-plugin.c @@ -108,7 +108,7 @@ typedef struct _TimeConfigureDialog TimeConfigureDialog; struct _TimeConfigureDialog { - GtkWidget *dialog; + GtkWidget *content; GtkWidget *list; @@ -120,8 +120,7 @@ struct _TimeConfigureDialog GtkWidget *custom_entry; GtkWidget *custom_format_example; - /* Info needed for the response handler */ - PlumaTimePlugin *plugin; + GSettings *settings; }; typedef struct _ChooseFormatDialog ChooseFormatDialog; @@ -141,7 +140,8 @@ struct _ChooseFormatDialog /* Info needed for the response handler */ GtkTextBuffer *buffer; - PlumaTimePlugin *plugin; + + GSettings *settings; }; typedef enum @@ -336,16 +336,16 @@ get_prompt_type (PlumaTimePlugin *plugin) } static void -set_prompt_type (PlumaTimePlugin *plugin, +set_prompt_type (GSettings *settings, PlumaTimePluginPromptType prompt_type) { - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, PROMPT_TYPE_KEY)) { return; } - g_settings_set_enum (plugin->priv->settings, + g_settings_set_enum (settings, PROMPT_TYPE_KEY, prompt_type); } @@ -363,18 +363,18 @@ get_selected_format (PlumaTimePlugin *plugin) } static void -set_selected_format (PlumaTimePlugin *plugin, +set_selected_format (GSettings *settings, const gchar *format) { g_return_if_fail (format != NULL); - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, SELECTED_FORMAT_KEY)) { return; } - g_settings_set_string (plugin->priv->settings, + g_settings_set_string (settings, SELECTED_FORMAT_KEY, format); } @@ -392,16 +392,16 @@ get_custom_format (PlumaTimePlugin *plugin) } static void -set_custom_format (PlumaTimePlugin *plugin, +set_custom_format (GSettings *settings, const gchar *format) { g_return_if_fail (format != NULL); - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, CUSTOM_FORMAT_KEY)) return; - g_settings_set_string (plugin->priv->settings, + g_settings_set_string (settings, CUSTOM_FORMAT_KEY, format); } @@ -456,13 +456,24 @@ get_time (const gchar* format) } static void -dialog_disposed (GObject *obj, gpointer dialog_pointer) +configure_dialog_destroyed (GtkWidget *widget, + gpointer data) { + TimeConfigureDialog *dialog = (TimeConfigureDialog *) data; + pluma_debug (DEBUG_PLUGINS); - g_free (dialog_pointer); + g_object_unref (dialog->settings); + g_slice_free (TimeConfigureDialog, data); +} + +static void +choose_format_dialog_destroyed (GtkWidget *widget, + gpointer data) +{ + pluma_debug (DEBUG_PLUGINS); - pluma_debug_message (DEBUG_PLUGINS, "END"); + g_slice_free (ChooseFormatDialog, data); } static GtkTreeModel * @@ -648,6 +659,7 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, TRUE); gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + set_prompt_type (dialog->settings, USE_CUSTOM_FORMAT); return; } @@ -657,6 +669,7 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, FALSE); gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + set_prompt_type (dialog->settings, USE_SELECTED_FORMAT); return; } @@ -666,6 +679,7 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, FALSE); gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); return; } } @@ -699,13 +713,23 @@ 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 TimeConfigureDialog * get_configure_dialog (PlumaTimePlugin *plugin) { TimeConfigureDialog *dialog = NULL; + GtkTreeSelection *selection; gchar *data_dir; gchar *ui_file; - GtkWidget *content; GtkWidget *viewport; PlumaTimePluginPromptType prompt_type; gchar *sf, *cf; @@ -718,37 +742,15 @@ get_configure_dialog (PlumaTimePlugin *plugin) pluma_debug (DEBUG_PLUGINS); - GtkWidget *dlg = gtk_dialog_new_with_buttons (_("Configure insert date/time plugin..."), - NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); - - g_return_val_if_fail (dlg != NULL, NULL); - - dialog = g_new0 (TimeConfigureDialog, 1); - dialog->dialog = dlg; - - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6); - + dialog = g_slice_new (TimeConfigureDialog); + dialog->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, "pluma-time-setup-dialog.ui", NULL); ret = pluma_utils_get_ui_objects (ui_file, root_objects, &error_widget, - "time_dialog_content", &content, + "time_dialog_content", &dialog->content, "formats_viewport", &viewport, "formats_tree", &dialog->list, "always_prompt", &dialog->prompt, @@ -763,27 +765,20 @@ get_configure_dialog (PlumaTimePlugin *plugin) if (!ret) { - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - error_widget, - TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - - gtk_widget_show (error_widget); - - return dialog; + return NULL; } - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - sf = get_selected_format (plugin); create_formats_list (dialog->list, sf, plugin); g_free (sf); prompt_type = get_prompt_type (plugin); - cf = get_custom_format (plugin); - gtk_entry_set_text (GTK_ENTRY(dialog->custom_entry), cf); - g_free (cf); + g_settings_bind (dialog->settings, + CUSTOM_FORMAT_KEY, + dialog->custom_entry, + "text", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); if (prompt_type == USE_CUSTOM_FORMAT) { @@ -816,14 +811,6 @@ get_configure_dialog (PlumaTimePlugin *plugin) /* setup a window of a sane size. */ gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - content, FALSE, FALSE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); - - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); - g_signal_connect (dialog->custom, "toggled", G_CALLBACK (configure_dialog_button_toggled), @@ -836,15 +823,21 @@ get_configure_dialog (PlumaTimePlugin *plugin) "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (dialog_disposed), + 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); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list)); + g_signal_connect (selection, + "changed", + G_CALLBACK (configure_dialog_selection_changed), + dialog); + return dialog; } @@ -874,8 +867,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->plugin, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats[sel_format]); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); + set_selected_format (dialog->settings, formats[sel_format]); g_return_if_fail (the_time != NULL); @@ -900,7 +893,8 @@ get_choose_format_dialog (GtkWindow *parent, if (parent != NULL) wg = gtk_window_get_group (parent); - dialog = g_new0 (ChooseFormatDialog, 1); + dialog = g_slice_new (ChooseFormatDialog); + dialog->settings = plugin->priv->settings; data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "pluma-time-dialog.ui", NULL); @@ -999,8 +993,8 @@ get_choose_format_dialog (GtkWindow *parent, G_CALLBACK (choose_format_dialog_button_toggled), dialog); g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (dialog_disposed), + "destroy", + G_CALLBACK (choose_format_dialog_destroyed), dialog); g_signal_connect (dialog->custom_entry, "changed", @@ -1045,8 +1039,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->plugin, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats[sel_format]); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); + set_selected_format (dialog->settings, formats[sel_format]); } else { @@ -1055,8 +1049,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->plugin, PROMPT_CUSTOM_FORMAT); - set_custom_format (dialog->plugin, format); + set_prompt_type (dialog->settings, PROMPT_CUSTOM_FORMAT); + set_custom_format (dialog->settings, format); } g_return_if_fail (the_time != NULL); @@ -1112,7 +1106,7 @@ time_cb (GtkAction *action, if (dialog != NULL) { dialog->buffer = buffer; - dialog->plugin = plugin; + dialog->settings = plugin->priv->settings; g_signal_connect (dialog->dialog, "response", @@ -1132,70 +1126,6 @@ time_cb (GtkAction *action, g_free (the_time); } -static void -ok_button_pressed (TimeConfigureDialog *dialog) -{ - gint sel_format; - const gchar *custom_format; - - pluma_debug (DEBUG_PLUGINS); - - sel_format = get_format_from_list (dialog->list); - - custom_format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) - { - set_prompt_type (dialog->plugin, USE_CUSTOM_FORMAT); - set_custom_format (dialog->plugin, custom_format); - } - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) - { - set_prompt_type (dialog->plugin, USE_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats [sel_format]); - } - else - { - /* Default to prompt the user with the list selected */ - set_prompt_type (dialog->plugin, PROMPT_SELECTED_FORMAT); - } - - pluma_debug_message (DEBUG_PLUGINS, "Sel: %d", sel_format); -} - -static void -configure_dialog_response_cb (GtkWidget *widget, - gint response, - TimeConfigureDialog *dialog) -{ - switch (response) - { - case GTK_RESPONSE_HELP: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); - - pluma_help_display (GTK_WINDOW (widget), - NULL, - "pluma-insert-date-time-plugin#pluma-date-time-configure"); - break; - } - case GTK_RESPONSE_OK: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); - - ok_button_pressed (dialog); - - gtk_widget_destroy (dialog->dialog); - break; - } - case GTK_RESPONSE_CANCEL: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } - } -} - static GtkWidget * pluma_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { @@ -1203,14 +1133,7 @@ pluma_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable) dialog = get_configure_dialog (PLUMA_TIME_PLUGIN (configurable)); - dialog->plugin = PLUMA_TIME_PLUGIN (configurable); - - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (configure_dialog_response_cb), - dialog); - - return GTK_WIDGET (dialog->dialog); + return dialog->content; } static void -- cgit v1.2.1 From e1fbe56adf49a5f4d3a3bb493933d9ae5a5c081f Mon Sep 17 00:00:00 2001 From: monsta Date: Mon, 5 Dec 2016 17:36:57 +0300 Subject: plugins: make them actually recognized and loaded by Pluma - use *.plugin extension instead of *.pluma-plugin - use "Plugin" section name instead of "Pluma Plugin" mostly adapted from: https://git.gnome.org/browse/gedit/commit/?id=1d56b827f14096891bb03dbd5e8211fdad1331ad https://git.gnome.org/browse/gedit/commit/?id=7c22769d73f756b9d1388febd147c9d267ed54cb --- plugins/time/Makefile.am | 6 +++--- plugins/time/time.plugin.desktop.in | 8 ++++++++ plugins/time/time.pluma-plugin.desktop.in | 8 -------- 3 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 plugins/time/time.plugin.desktop.in delete mode 100644 plugins/time/time.pluma-plugin.desktop.in (limited to 'plugins/time') diff --git a/plugins/time/Makefile.am b/plugins/time/Makefile.am index d1f8fe3b..30363e76 100644 --- a/plugins/time/Makefile.am +++ b/plugins/time/Makefile.am @@ -21,11 +21,11 @@ ui_DATA = \ pluma-time-dialog.ui \ pluma-time-setup-dialog.ui -plugin_in_files = time.pluma-plugin.desktop.in +plugin_in_files = time.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) @INTLTOOL_XML_NOMERGE_RULE@ time_gschema_in = org.mate.pluma.plugins.time.gschema.xml.in diff --git a/plugins/time/time.plugin.desktop.in b/plugins/time/time.plugin.desktop.in new file mode 100644 index 00000000..a59f2085 --- /dev/null +++ b/plugins/time/time.plugin.desktop.in @@ -0,0 +1,8 @@ +[Plugin] +Module=time +IAge=2 +_Name=Insert Date/Time +_Description=Inserts current date and time at the cursor position. +Authors=Paolo Maggi ;Lee Mallabone +Copyright=Copyright © 2002-2005 Paolo Maggi +Website=http://www.mate-desktop.org diff --git a/plugins/time/time.pluma-plugin.desktop.in b/plugins/time/time.pluma-plugin.desktop.in deleted file mode 100644 index af812768..00000000 --- a/plugins/time/time.pluma-plugin.desktop.in +++ /dev/null @@ -1,8 +0,0 @@ -[Pluma Plugin] -Module=time -IAge=2 -_Name=Insert Date/Time -_Description=Inserts current date and time at the cursor position. -Authors=Paolo Maggi ;Lee Mallabone -Copyright=Copyright © 2002-2005 Paolo Maggi -Website=http://www.mate-desktop.org -- cgit v1.2.1