diff --git a/ChangeLog b/ChangeLog index e54411bfbf..9a71fbc6cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-12-26 Matthias Clasen + + * gtk/gtklabel.c (gtk_label_class_init): Add a gtk-label-select-on-focus + setting. + (gtk_label_grab_focus): And use it here to select the contents of + the label when appropriate. + (gtk_label_class_init): Use the same keybindings for select all/ + unselect all as GtkEntry and GtkTextView. + + * gtk/gtkdialog.c (gtk_dialog_map): When looking for the initial + focus, avoid leaving a selection in a label. + 2005-12-25 Matthias Clasen * gtk/gtkwindow.c: Documentation fixes. (#324815, diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index e54411bfbf..9a71fbc6cd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +2005-12-26 Matthias Clasen + + * gtk/gtklabel.c (gtk_label_class_init): Add a gtk-label-select-on-focus + setting. + (gtk_label_grab_focus): And use it here to select the contents of + the label when appropriate. + (gtk_label_class_init): Use the same keybindings for select all/ + unselect all as GtkEntry and GtkTextView. + + * gtk/gtkdialog.c (gtk_dialog_map): When looking for the initial + focus, avoid leaving a selection in a label. + 2005-12-25 Matthias Clasen * gtk/gtkwindow.c: Documentation fixes. (#324815, diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index 59a5a30f98..6ed9952aa0 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -353,8 +353,13 @@ gtk_dialog_map (GtkWidget *widget) first_focus = window->focus_widget; else if (first_focus == window->focus_widget) break; + + if (!GTK_IS_LABEL (window->focus_widget)) + break; + else + gtk_label_select_region (GTK_LABEL (window->focus_widget), 0, 0); } - while (GTK_IS_LABEL (window->focus_widget)); + while (TRUE); tmp_list = children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 821a6ec7a3..1e62d0d4ea 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -52,7 +52,8 @@ typedef struct gint width_chars; gint max_width_chars; guint single_line_mode : 1; - guint have_transform : 1; + guint have_transform : 1; + guint in_click : 1; gdouble angle; } GtkLabelPrivate; @@ -136,6 +137,7 @@ static gboolean gtk_label_button_release (GtkWidget *widget, GdkEventButton *event); static gboolean gtk_label_motion (GtkWidget *widget, GdkEventMotion *event); +static void gtk_label_grab_focus (GtkWidget *widget); static void gtk_label_set_text_internal (GtkLabel *label, @@ -281,6 +283,7 @@ gtk_label_class_init (GtkLabelClass *class) widget_class->screen_changed = gtk_label_screen_changed; widget_class->mnemonic_activate = gtk_label_mnemonic_activate; widget_class->drag_data_get = gtk_label_drag_data_get; + widget_class->grab_focus = gtk_label_grab_focus; class->move_cursor = gtk_label_move_cursor; class->copy_clipboard = gtk_label_copy_clipboard; @@ -554,12 +557,44 @@ gtk_label_class_init (GtkLabelClass *class) add_move_binding (binding_set, GDK_KP_Left, GDK_CONTROL_MASK, GTK_MOVEMENT_WORDS, -1); - - add_move_binding (binding_set, GDK_a, GDK_CONTROL_MASK, - GTK_MOVEMENT_PARAGRAPH_ENDS, -1); - add_move_binding (binding_set, GDK_e, GDK_CONTROL_MASK, - GTK_MOVEMENT_PARAGRAPH_ENDS, 1); + /* select all */ + gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, + "move_cursor", 3, + G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS, + G_TYPE_INT, -1, + G_TYPE_BOOLEAN, FALSE); + + gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, + "move_cursor", 3, + G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS, + G_TYPE_INT, 1, + G_TYPE_BOOLEAN, TRUE); + + gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK, + "move_cursor", 3, + G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS, + G_TYPE_INT, -1, + G_TYPE_BOOLEAN, FALSE); + + gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK, + "move_cursor", 3, + G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS, + G_TYPE_INT, 1, + G_TYPE_BOOLEAN, TRUE); + + /* unselect all */ + gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_SHIFT_MASK | GDK_CONTROL_MASK, + "move_cursor", 3, + G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS, + G_TYPE_INT, 0, + G_TYPE_BOOLEAN, FALSE); + + gtk_binding_entry_add_signal (binding_set, GDK_backslash, GDK_CONTROL_MASK, + "move_cursor", 3, + G_TYPE_ENUM, GTK_MOVEMENT_PARAGRAPH_ENDS, + G_TYPE_INT, 0, + G_TYPE_BOOLEAN, FALSE); add_move_binding (binding_set, GDK_f, GDK_MOD1_MASK, GTK_MOVEMENT_WORDS, 1); @@ -594,6 +629,13 @@ gtk_label_class_init (GtkLabelClass *class) /* copy */ gtk_binding_entry_add_signal (binding_set, GDK_c, GDK_CONTROL_MASK, "copy_clipboard", 0); + + gtk_settings_install_property (g_param_spec_boolean ("gtk-label-select-on-focus", + P_("Select on focus"), + P_("Whether to select the contents of a selectable label when it is focused"), + TRUE, + GTK_PARAM_READWRITE)); + g_type_class_add_private (class, sizeof (GtkLabelPrivate)); } @@ -2712,11 +2754,37 @@ gtk_label_select_word (GtkLabel *label) gtk_label_select_region_index (label, min, max); } +static void +gtk_label_grab_focus (GtkWidget *widget) +{ + GtkLabel *label; + GtkLabelPrivate *priv; + gboolean select_on_focus; + + label = GTK_LABEL (widget); + + if (label->select_info == NULL) + return FALSE; + + priv = GTK_LABEL_GET_PRIVATE (label); + + GTK_WIDGET_CLASS (parent_class)->grab_focus (widget); + + g_object_get (gtk_widget_get_settings (widget), + "gtk-label-select-on-focus", + &select_on_focus, + NULL); + + if (select_on_focus && !priv->in_click) + gtk_label_select_region (label, 0, -1); +} + static gboolean gtk_label_button_press (GtkWidget *widget, GdkEventButton *event) { GtkLabel *label; + GtkLabelPrivate *priv; gint index = 0; gint min, max; @@ -2728,8 +2796,14 @@ gtk_label_button_press (GtkWidget *widget, label->select_info->in_drag = FALSE; if (event->button == 1) { - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); + if (!GTK_WIDGET_HAS_FOCUS (widget)) + { + priv = GTK_LABEL_GET_PRIVATE (label); + + priv->in_click = TRUE; + gtk_widget_grab_focus (widget); + priv->in_click = FALSE; + } if (event->type == GDK_3BUTTON_PRESS) {