[Xfce-bugs] [Bug 15973] Center action buttons in conflict dialog window

bugzilla-daemon at xfce.org bugzilla-daemon at xfce.org
Thu Sep 19 04:46:00 CEST 2019


https://bugzilla.xfce.org/show_bug.cgi?id=15973

--- Comment #4 from fuank <greob at yahoo.com.sg> ---
I got it to work!  It's probably not the best looking code though, but it
works. I'll finalize the patch submission soon but feel free to scold me in the
meantime if you have suggestions. I'm not used to GTK and C programming. ;)

Not fond of having multiple callbacks instead of just one, but I couldn't
figure out how to manipulate the GtkWidget button objects to extract their ID
or something.


static void cancel_button_callback ( GtkWidget *button, gpointer dialog)
{
  gtk_dialog_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
}
static void skipall_button_callback ( GtkWidget *button, gpointer dialog)
{
  gtk_dialog_response (GTK_DIALOG(dialog), THUNAR_JOB_RESPONSE_NO_ALL);
}
static void skip_button_callback ( GtkWidget *button, gpointer dialog)
{
  gtk_dialog_response (GTK_DIALOG(dialog), THUNAR_JOB_RESPONSE_NO);
}
static void replaceall_button_callback ( GtkWidget *button, gpointer dialog)
{
  gtk_dialog_response (GTK_DIALOG(dialog), THUNAR_JOB_RESPONSE_YES_ALL);
}
static void replace_button_callback ( GtkWidget *button, gpointer dialog)
{
  gtk_dialog_response (GTK_DIALOG(dialog), THUNAR_JOB_RESPONSE_YES);
}

(...)

  GtkWidget         *cancel_button;
  GtkWidget         *button_box;
  GtkWidget         *skipall_button;
  GtkWidget         *skip_button;
  GtkWidget         *replaceall_button;
  GtkWidget         *replace_button;
  GtkWidget         *button_container;

  dialog = gtk_dialog_new();
  gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE);
  gtk_window_set_modal (GTK_WINDOW(dialog), TRUE);
  gtk_window_set_title (GTK_WINDOW(dialog), _("Confirm to replace files"));
  gtk_dialog_set_default_response (GTK_DIALOG (dialog),
THUNAR_JOB_RESPONSE_YES);

  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);

  cancel_button = gtk_button_new_with_mnemonic (_("_Cancel"));
  skipall_button = gtk_button_new_with_mnemonic (_("S_kip All"));
  skip_button = gtk_button_new_with_mnemonic (_("_Skip"));
  replaceall_button = gtk_button_new_with_mnemonic (_("Replace _All"));
  replace_button = gtk_button_new_with_mnemonic (_("_Replace"));

  gtk_widget_show (cancel_button);
  gtk_widget_show (skipall_button);
  gtk_widget_show (skip_button);
  gtk_widget_show (replaceall_button);
  gtk_widget_show (replace_button);

  g_signal_connect (cancel_button, "clicked", G_CALLBACK
(cancel_button_callback), dialog);
  g_signal_connect (skipall_button, "clicked", G_CALLBACK
(skipall_button_callback), dialog);
  g_signal_connect (skip_button, "clicked", G_CALLBACK (skip_button_callback),
dialog);
  g_signal_connect (replaceall_button, "clicked", G_CALLBACK
(replaceall_button_callback), dialog);
  g_signal_connect (replace_button, "clicked", G_CALLBACK
(replace_button_callback), dialog);

  gtk_container_add (GTK_CONTAINER(button_box), cancel_button);
  gtk_container_add (GTK_CONTAINER(button_box), skipall_button);
  gtk_container_add (GTK_CONTAINER(button_box), skip_button);  
  gtk_container_add (GTK_CONTAINER(button_box), replaceall_button);
  gtk_container_add (GTK_CONTAINER(button_box), replace_button);
  gtk_container_add (GTK_CONTAINER(content_area), button_box);
  gtk_widget_set_hexpand (button_box, GTK_ALIGN_CENTER); 
  gtk_widget_set_halign (button_box, GTK_ALIGN_CENTER); 

  gtk_widget_show (button_box);

(...)

  /* run the dialog */
  response = gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);


Demonstration video: 
https://giant.gfycat.com/ColossalTimelyIrishwaterspaniel.mp4  or
https://giant.gfycat.com/ColossalTimelyIrishwaterspaniel.webm

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the Xfce-bugs mailing list