plug-ins: fix the new unit editor (!655).

- Don't forget to run gimp_ui_init() to get GIMP's styling in plug-ins.
- Process the "key-press-event" signal so that Escape key closes the window (as
  it used to before the MR commit).
- Expand vertically the tree view, otherwise resizing the window leaves a lot of
  ugly empty space, even though the tree view is still shown incomplete with a
  scrollbar.
- Fix the Help button (which was doing nothing).
- Use full words for the "Refresh" and "Help" buttons, rather than icons. Text
  is usually prefered for UI discoverability/understandability, unless there is
  a space issue (i.e. too many icons for all of them to be words).
- Add a "OK" button too, and reorder the buttons similarly to how we usually
  order them.
- Minor coding style fixes (alignments…).
This commit is contained in:
Jehan 2022-10-11 21:18:48 +02:00
parent dc8298ce76
commit e4e87d65ca
1 changed files with 64 additions and 27 deletions

View File

@ -79,23 +79,29 @@ static GimpValueArray * editor_run (GimpProcedure *procedure
const GimpValueArray *args, const GimpValueArray *args,
gpointer run_data); gpointer run_data);
static GimpUnit new_unit_dialog (GtkWindow *main_window, static GimpUnit new_unit_dialog (GtkWindow *main_window,
GimpUnit template); GimpUnit template);
static void on_app_activate (GApplication *gapp, static void on_app_activate (GApplication *gapp,
gpointer user_data); gpointer user_data);
static void new_unit_action (GSimpleAction *action,
GVariant *param, static gboolean unit_editor_key_press_event (GtkWidget *window,
gpointer user_data); GdkEventKey *event,
static void duplicate_unit_action (GSimpleAction *action, gpointer user_data);
GVariant *param, static void unit_editor_help_clicked (GtkWidget *window);
gpointer user_data);
static void refresh_action (GSimpleAction *action, static void new_unit_action (GSimpleAction *action,
GVariant *param, GVariant *param,
gpointer user_data); gpointer user_data);
static void saved_toggled_callback (GtkCellRendererToggle *celltoggle, static void duplicate_unit_action (GSimpleAction *action,
gchar *path_string, GVariant *param,
GtkListStore *list_store); gpointer user_data);
static void unit_list_init (GtkTreeView *tv); static void refresh_action (GSimpleAction *action,
GVariant *param,
gpointer user_data);
static void saved_toggled_callback (GtkCellRendererToggle *celltoggle,
gchar *path_string,
GtkListStore *list_store);
static void unit_list_init (GtkTreeView *tv);
G_DEFINE_TYPE (GimpUnitEditor, gimp_unit_editor, GIMP_TYPE_PLUG_IN) G_DEFINE_TYPE (GimpUnitEditor, gimp_unit_editor, GIMP_TYPE_PLUG_IN)
@ -244,22 +250,28 @@ on_app_activate (GApplication *gapp, gpointer user_data)
gtk_header_bar_set_has_subtitle (GTK_HEADER_BAR (headerbar), FALSE); gtk_header_bar_set_has_subtitle (GTK_HEADER_BAR (headerbar), FALSE);
gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), TRUE); gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), TRUE);
button = gtk_button_new_from_icon_name (GIMP_ICON_VIEW_REFRESH, button = gtk_button_new_with_mnemonic (_("_Refresh"));
GTK_ICON_SIZE_BUTTON);
gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.refresh"); gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.refresh");
gtk_widget_set_tooltip_text (button, _("Refresh"));
gtk_widget_show (button); gtk_widget_show (button);
gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), button); gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), button);
if (gimp_show_help_button ()) if (gimp_show_help_button ())
{ {
button = gtk_button_new_from_icon_name (GIMP_ICON_HELP, button = gtk_button_new_with_mnemonic (_("_Help"));
GTK_ICON_SIZE_BUTTON); g_signal_connect_swapped (button, "clicked",
gtk_widget_set_tooltip_text (button, _("Help")); G_CALLBACK (unit_editor_help_clicked),
self->window);
gtk_widget_show (button); gtk_widget_show (button);
gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), button); gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), button);
} }
button = gtk_button_new_with_mnemonic (_("_OK"));
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy),
self->window);
gtk_widget_show (button);
gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), button);
gtk_window_set_titlebar (self->window, headerbar); gtk_window_set_titlebar (self->window, headerbar);
gtk_widget_show (headerbar); gtk_widget_show (headerbar);
@ -299,6 +311,7 @@ on_app_activate (GApplication *gapp, gpointer user_data)
gtk_widget_set_size_request (self->tv, -1, 220); gtk_widget_set_size_request (self->tv, -1, 220);
gtk_container_add (GTK_CONTAINER (scrolled_win), self->tv); gtk_container_add (GTK_CONTAINER (scrolled_win), self->tv);
gtk_widget_set_vexpand (self->tv, TRUE);
gtk_widget_show (self->tv); gtk_widget_show (self->tv);
rend = gtk_cell_renderer_toggle_new (); rend = gtk_cell_renderer_toggle_new ();
@ -352,9 +365,31 @@ on_app_activate (GApplication *gapp, gpointer user_data)
unit_list_init (GTK_TREE_VIEW (self->tv)); unit_list_init (GTK_TREE_VIEW (self->tv));
g_signal_connect (self->window, "key-press-event",
G_CALLBACK (unit_editor_key_press_event),
NULL);
gtk_widget_show (GTK_WIDGET (self->window)); gtk_widget_show (GTK_WIDGET (self->window));
} }
static gboolean
unit_editor_key_press_event (GtkWidget *window,
GdkEventKey *event,
gpointer user_data)
{
if (event->state == 0 &&
event->keyval == GDK_KEY_Escape)
gtk_widget_destroy (GTK_WIDGET (window));
return FALSE;
}
static void
unit_editor_help_clicked (GtkWidget *window)
{
gimp_standard_help_func (PLUG_IN_PROC, window);
}
static GimpValueArray * static GimpValueArray *
editor_run (GimpProcedure *procedure, editor_run (GimpProcedure *procedure,
const GimpValueArray *args, const GimpValueArray *args,
@ -362,6 +397,8 @@ editor_run (GimpProcedure *procedure,
{ {
GimpUnitEditor *editor = GIMP_UNIT_EDITOR (run_data); GimpUnitEditor *editor = GIMP_UNIT_EDITOR (run_data);
gimp_ui_init (PLUG_IN_BINARY);
editor->app = gtk_application_new (NULL, G_APPLICATION_FLAGS_NONE); editor->app = gtk_application_new (NULL, G_APPLICATION_FLAGS_NONE);
g_signal_connect (editor->app, "activate", G_CALLBACK (on_app_activate), editor); g_signal_connect (editor->app, "activate", G_CALLBACK (on_app_activate), editor);
@ -401,9 +438,9 @@ new_unit_dialog (GtkWindow *main_window,
NULL); NULL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog), gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK, GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL, GTK_RESPONSE_CANCEL,
-1); -1);
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (grid), 6); gtk_grid_set_row_spacing (GTK_GRID (grid), 6);