Merge lp:~philip.scott/granite/editable-title into lp:~elementary-pantheon/granite/granite

Proposed by Felipe Escoto
Status: Work in progress
Proposed branch: lp:~philip.scott/granite/editable-title
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 159 lines (+144/-0)
2 files modified
lib/CMakeLists.txt (+1/-0)
lib/Widgets/EditableTitle.vala (+143/-0)
To merge this branch: bzr merge lp:~philip.scott/granite/editable-title
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Adam Bieńkowski (community) code Needs Fixing
Review via email: mp+311101@code.launchpad.net

Commit message

EditableTitle class added

Description of the change

Moves the EditableTitle class that is been used in Pantheon Photos and on the Printers Plug into it's own class here on granite.

It could also be used on Audience's Library view and I'm also planning on using it on Spice Up's future presentations browser

To post a comment you must log in.
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

* Use construct {} method of constructing the object.
* Use "construct set" for text property.
* There's no way of determining if the user is currently editing the label or not
* changed signal could probably have an additional parameter for something like "previous_title".
* Hm, reading the code it seems that every press on the widget will cause the editing to procced, maybe check if it's left click? Or is that intentional?

review: Needs Fixing (code)
Revision history for this message
Danielle Foré (danrabbit) wrote :

Please assign copyright to "elementary LLC" instead of "Granite Developers". I'm unsure that "Granite Developers" holds up as a valid legal entity to assign copyright to.

Don't forget to add an example to Granite-Demo ;)

review: Needs Fixing
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Assign "events" once or use add_events() to avoid mess ups

Unmerged revisions

1013. By Felipe Escoto

Add EditableTile.vala

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/CMakeLists.txt'
2--- lib/CMakeLists.txt 2016-09-28 18:36:03 +0000
3+++ lib/CMakeLists.txt 2016-11-17 03:28:11 +0000
4@@ -27,6 +27,7 @@
5 Widgets/ModeButton.vala
6 Widgets/DatePicker.vala
7 Widgets/Entries.vala
8+ Widgets/EditableTitle.vala
9 Widgets/TimePicker.vala
10 Widgets/CollapsiblePaned.vala
11 Widgets/StaticNotebook.vala
12
13=== added file 'lib/Widgets/EditableTitle.vala'
14--- lib/Widgets/EditableTitle.vala 1970-01-01 00:00:00 +0000
15+++ lib/Widgets/EditableTitle.vala 2016-11-17 03:28:11 +0000
16@@ -0,0 +1,143 @@
17+/*-
18+ * Copyright (c) 2016 Granite Developers (https://launchpad.net/granite)
19+ *
20+ * This library is free software; you can redistribute it and/or
21+ * modify it under the terms of the GNU Library General Public
22+ * License as published by the Free Software Foundation; either
23+ * version 3 of the License, or (at your option) any later version.
24+ *
25+ * This library is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28+ * Library General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU Library General Public
31+ * License along with this library; if not, write to the
32+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33+ * Boston, MA 02111-1307, USA.
34+ *
35+ * Authored by: Corentin Noël <corentin@elementary.io>
36+ * Felipe Escoto <felescoto95@hotmail.com>
37+ */
38+
39+/**
40+ * The EditableTitle is for making lables that can be edited with just a single click
41+ */
42+public class Granite.Widgets.EditableTitle : Gtk.EventBox {
43+ /**
44+ * Sent when the user changes the widget's content and stops editing it
45+ */
46+ public signal void changed (string new_title);
47+
48+ private Gtk.Label title;
49+ private Gtk.Entry entry;
50+ private Gtk.Stack stack;
51+ private Gtk.Grid grid;
52+
53+ public string text {
54+ get {
55+ return title.label;
56+ }
57+
58+ set {
59+ title.label = value;
60+ }
61+ }
62+
63+ private bool editing {
64+ set {
65+ if (value) {
66+ entry.text = title.label;
67+ stack.set_visible_child (entry);
68+ entry.grab_focus ();
69+ } else {
70+ if (entry.text.strip () != "" && title.label != entry.text) {
71+ title.label = entry.text;
72+ changed (entry.text);
73+ }
74+
75+ stack.set_visible_child (grid);
76+ }
77+ }
78+ }
79+
80+ /**
81+ * Creates a new EditableTitle with the specified text
82+ *
83+ * @param text the initial text on the label
84+ */
85+ public EditableTitle (string text) {
86+ valign = Gtk.Align.CENTER;
87+ events |= Gdk.EventMask.ENTER_NOTIFY_MASK;
88+ events |= Gdk.EventMask.LEAVE_NOTIFY_MASK;
89+ events |= Gdk.EventMask.BUTTON_PRESS_MASK;
90+
91+ title = new Gtk.Label (text);
92+ title.ellipsize = Pango.EllipsizeMode.END;
93+ title.hexpand = true;
94+ ((Gtk.Misc) title).xalign = 0;
95+
96+ var edit_button = new Gtk.Button ();
97+ edit_button.image = new Gtk.Image.from_icon_name ("edit-symbolic", Gtk.IconSize.MENU);
98+ edit_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
99+ var button_revealer = new Gtk.Revealer ();
100+ button_revealer.valign = Gtk.Align.CENTER;
101+ button_revealer.transition_type = Gtk.RevealerTransitionType.CROSSFADE;
102+ button_revealer.add (edit_button);
103+
104+ grid = new Gtk.Grid ();
105+ grid.valign = Gtk.Align.CENTER;
106+ grid.column_spacing = 12;
107+ grid.add (title);
108+ grid.add (button_revealer);
109+
110+ entry = new Gtk.Entry ();
111+ entry.secondary_icon_name = "go-jump-symbolic";
112+
113+ stack = new Gtk.Stack ();
114+ stack.transition_type = Gtk.StackTransitionType.CROSSFADE;
115+ stack.add (grid);
116+ stack.add (entry);
117+ add (stack);
118+
119+ enter_notify_event.connect ((event) => {
120+ if (event.detail != Gdk.NotifyType.INFERIOR) {
121+ button_revealer.set_reveal_child (true);
122+ }
123+
124+ return false;
125+ });
126+
127+ leave_notify_event.connect ((event) => {
128+ if (event.detail != Gdk.NotifyType.INFERIOR) {
129+ button_revealer.set_reveal_child (false);
130+ }
131+
132+ return false;
133+ });
134+
135+ button_press_event.connect ((event) => {
136+ editing = true;
137+ return true;
138+ });
139+
140+ edit_button.clicked.connect (() => {
141+ editing = true;
142+ });
143+
144+ entry.activate.connect (() => {
145+ editing = false;
146+ });
147+
148+ entry.focus_out_event.connect ((event) => {
149+ editing = false;
150+ return false;
151+ });
152+
153+ entry.icon_release.connect ((p0, p1) => {
154+ if (p0 == Gtk.EntryIconPosition.SECONDARY) {
155+ editing = false;
156+ }
157+ });
158+ }
159+}

Subscribers

People subscribed via source and target branches