1
1
/*
2
- * Copyright 2016-2023 elementary, Inc. (https://elementary.io)
2
+ * Copyright 2016-2024 elementary, Inc. (https://elementary.io)
3
3
* Copyright 2016 Corentin Noël <corentin@elementary.io>
4
4
* SPDX-License-Identifier: LGPL-2.1-or-later
5
5
*/
@@ -10,9 +10,11 @@ public class Tasks.Widgets.EditableLabel : Gtk.EventBox {
10
10
private Gtk . Label title;
11
11
private Gtk . Entry entry;
12
12
private Gtk . Stack stack;
13
- private Gtk . Box box;
14
13
15
- public string text { get ; set ; }
14
+ private Gtk . EventControllerMotion motion_controller;
15
+ private Gtk . GestureMultiPress click_gesture;
16
+
17
+ public string text { get ; set ; default = " " ; }
16
18
17
19
public bool editing {
18
20
get { return stack. visible_child == entry; }
@@ -27,7 +29,7 @@ public class Tasks.Widgets.EditableLabel : Gtk.EventBox {
27
29
changed ();
28
30
}
29
31
30
- stack. set_visible_child (box );
32
+ stack. set_visible_child (title );
31
33
}
32
34
}
33
35
}
@@ -37,71 +39,47 @@ public class Tasks.Widgets.EditableLabel : Gtk.EventBox {
37
39
}
38
40
39
41
construct {
40
- valign = Gtk . Align . CENTER ;
41
- events |= Gdk . EventMask . ENTER_NOTIFY_MASK ;
42
- events |= Gdk . EventMask . LEAVE_NOTIFY_MASK ;
43
- events |= Gdk . EventMask . BUTTON_PRESS_MASK ;
42
+ valign = CENTER ;
44
43
45
44
title = new Gtk .Label (" " ) {
46
- ellipsize = Pango . EllipsizeMode . END ,
45
+ ellipsize = END ,
47
46
xalign = 0
48
47
};
49
48
50
- var edit_button = new Gtk .Button () {
51
- image = new Gtk .Image .from_icon_name (" edit-symbolic" , Gtk . IconSize . MENU ),
52
- tooltip_text = _ ("Edit …")
53
- };
54
- edit_button.get_style_context ().add_class (Gtk .STYLE_CLASS_FLAT );
55
-
56
- var button_revealer = new Gtk .Revealer () {
57
- valign = Gtk . Align . CENTER ,
58
- transition_type = Gtk . RevealerTransitionType . CROSSFADE
59
- };
60
- button_revealer.add (edit_button );
61
-
62
- box = new Gtk .Box (Gtk . Orientation . HORIZONTAL , 12 ) {
63
- valign = Gtk . Align . CENTER
64
- };
65
- box.add (title );
66
- box.add (button_revealer );
67
-
68
49
entry = new Gtk .Entry () {
69
50
hexpand = true
70
51
};
71
52
72
53
stack = new Gtk .Stack () {
73
54
hhomogeneous = false ,
74
- transition_type = Gtk . StackTransitionType . CROSSFADE
55
+ transition_type = CROSSFADE
75
56
};
76
- stack.add (box );
57
+ stack. add (title );
77
58
stack. add (entry);
78
59
79
60
add (stack);
80
61
81
62
bind_property (" text" , title, " label" );
82
63
83
- enter_notify_event.connect ((event ) => {
84
- if (event. detail != Gdk . NotifyType . INFERIOR ) {
85
- button_revealer. reveal_child = true ;
86
- }
87
-
88
- return Gdk . EVENT_PROPAGATE ;
89
- });
64
+ motion_controller = new Gtk .EventControllerMotion (this ) {
65
+ propagation_phase = CAPTURE
66
+ };
90
67
91
- leave_notify_event.connect ((event ) => {
92
- if (event. detail != Gdk . NotifyType . INFERIOR ) {
93
- button_revealer. reveal_child = false ;
94
- }
68
+ click_gesture = new Gtk .GestureMultiPress (this );
95
69
96
- return Gdk . EVENT_PROPAGATE ;
70
+ motion_controller. enter. connect (() = > {
71
+ get_window (). set_cursor (
72
+ new Gdk .Cursor .from_name (Gdk . Display . get_default (), " text" )
73
+ );
97
74
});
98
75
99
- button_press_event.connect ((event ) => {
100
- editing = true ;
101
- return Gdk . EVENT_PROPAGATE ;
76
+ motion_controller. leave. connect (() = > {
77
+ get_window (). set_cursor (
78
+ new Gdk .Cursor .from_name (Gdk . Display . get_default (), " default" )
79
+ );
102
80
});
103
81
104
- edit_button.clicked .connect (() => {
82
+ click_gesture . released . connect (() = > {
105
83
editing = true ;
106
84
});
107
85
@@ -111,15 +89,16 @@ public class Tasks.Widgets.EditableLabel : Gtk.EventBox {
111
89
}
112
90
});
113
91
114
- grab_focus.connect (() => {
115
- editing = true ;
116
- });
117
-
118
92
entry. focus_out_event. connect ((event) = > {
119
93
if (stack. visible_child == entry) {
120
94
editing = false ;
121
95
}
96
+
122
97
return Gdk . EVENT_PROPAGATE ;
123
98
});
124
99
}
100
+
101
+ public override void grab_focus () {
102
+ editing = true ;
103
+ }
125
104
}
0 commit comments