After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 690011 - gd-main-toolbar: Add support for modes
gd-main-toolbar: Add support for modes
Status: RESOLVED FIXED
Product: libgd
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: libgd maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-12-10 22:45 UTC by Debarshi Ray
Modified: 2013-02-03 22:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
main-toolbar: Add support for modes (8.72 KB, patch)
2012-12-10 22:59 UTC, Debarshi Ray
reviewed Details | Review
main-toolbar: Add support for modes (8.71 KB, patch)
2012-12-11 08:10 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2012-12-10 22:45:18 UTC
Some applications lot more modes other than overview, selection and preview. These are represented by using radio buttons in the centre of the toolbar. For example:
  -  https://live.gnome.org/Design/Apps/Calendar
  -  https://live.gnome.org/Design/Apps/Clock
  -  https://live.gnome.org/Design/Apps/Photos

It would be nice to support these in GdMainToolbar.
Comment 1 Debarshi Ray 2012-12-10 22:59:15 UTC
Created attachment 231222 [details] [review]
main-toolbar: Add support for modes

Applications which do not need modes should not require any changes.

I tried using a GtkButtonBox to avoid having to set the minimum width of the buttons with:
gtk_widget_set_size_request (button, 100, -1);

However, I could not get it to honour the vexpand=TRUE of the buttons inside it. Since the buttons on the left and right have vexpand=TRUE, this causes their bottom edges to be misaligned.

I am not sure whether 100 is a good number or not. GtkButtonBox uses 85, gnome-calendar uses 80 and gnome-clocks uses 100.
Comment 2 Cosimo Cecchi 2012-12-11 03:06:21 UTC
Review of attachment 231222 [details] [review]:

Thanks, this looks good except for some minor comments

::: libgd/gd-main-toolbar.c
@@ +235,3 @@
 
+  /* centered mode group */
+  self->priv->modes_grid = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

This is not a grid, so I think it should be renamed to modes_box.

@@ +439,3 @@
+GtkWidget *
+gd_main_toolbar_add_mode (GdMainToolbar *self,
+ * @self:

I think I'd rename "name" to "label" to avoid any confusion here.

@@ +446,3 @@
+  button = gtk_radio_button_new_with_label (NULL, name);
+  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
+ */

Why is this set_size_request needed at all?
Comment 3 Debarshi Ray 2012-12-11 08:09:53 UTC
(In reply to comment #2)
> ::: libgd/gd-main-toolbar.c
> @@ +235,3 @@
> 
> +  /* centered mode group */
> +  self->priv->modes_grid = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
> 
> This is not a grid, so I think it should be renamed to modes_box.

Done.

> @@ +439,3 @@
> +GtkWidget *
> +gd_main_toolbar_add_mode (GdMainToolbar *self,
> + * @self:
> 
> I think I'd rename "name" to "label" to avoid any confusion here.

Done.

> @@ +446,3 @@
> +  button = gtk_radio_button_new_with_label (NULL, name);
> +  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
> + */
> 
> Why is this set_size_request needed at all?

To enforce a minimum width for the buttons, just like having them in GtkButtonBox. eg., if you have a button in a GtkButtonBox with GTK_STOCK_OK, the button is much wider than required because the minimum width of is set to be 85. Others, like gnome-calendar and gnome-clocks use 80 and 100 respectively.

I do not know what is the best way to do this.
Comment 4 Debarshi Ray 2012-12-11 08:10:48 UTC
Created attachment 231243 [details] [review]
main-toolbar: Add support for modes
Comment 5 Cosimo Cecchi 2012-12-12 15:32:21 UTC
Review of attachment 231243 [details] [review]:

Thanks, this looks good now.
Comment 6 Debarshi Ray 2012-12-12 17:14:01 UTC
Thanks for the review!
Comment 7 Paolo Borelli 2013-02-03 17:31:41 UTC
I took the liberty of committing an obvious fix: http://git.gnome.org/browse/libgd/commit/?id=ee7333b87b57d9c5f0ff614c11e43bd37d6a30ce

However when trying to use this api I find it a bit weird:

1) add_mode returns "GtkWidget", but you are supposed to connect to "toggled" so the caller must know that it is a ToggleButton... the api should retunr GtkToggleButton so that introspection/vala knows the right type

2) having to connect to each button is cumbersome: what about having a mode-changed signal on the toolbar? add mode could return an int and mode-changed pass the int to the handler

3) (bikeshedding) "mode" is a pretty bad name for this imho: I'd expect the "mode" of the toolbar to be for instance "normal" and "selection"... what about "add_page" instead?
Comment 8 Cosimo Cecchi 2013-02-03 22:21:28 UTC
Paolo, thanks for the fix, that must have been a copy/paste mistake :)

How does it make a difference for Vala/introspection to know that is a GtkToggleButton? I mean, even gtk_toggle_button_new returns a GtkWidget, so I think it's fine as long as we document that the returned widget is actually a toggle button.

I agree wrt. the other two points you make; can you please file them as separate bugs against libgd? Thanks.
Comment 9 Paolo Borelli 2013-02-03 22:29:33 UTC
(In reply to comment #8)
> How does it make a difference for Vala/introspection to know that is a
> GtkToggleButton?

Well, vala complains that the Widget class does not have a "toggle" signal, so you need to downcast which is a bit ugly.

Anyway I'll the other bugs separately.