Merge lp:~philip.scott/pantheon-photos/editable-title into lp:~pantheon-photos/pantheon-photos/trunk

Proposed by Felipe Escoto
Status: Merged
Approved by: Danielle Foré
Approved revision: 3037
Merged at revision: 3038
Proposed branch: lp:~philip.scott/pantheon-photos/editable-title
Merge into: lp:~pantheon-photos/pantheon-photos/trunk
Diff against target: 184 lines (+131/-5)
3 files modified
src/CMakeLists.txt (+2/-1)
src/sidebar/EditableTitle.vala (+125/-0)
src/sidebar/metadata/LibraryProperties.vala (+4/-4)
To merge this branch: bzr merge lp:~philip.scott/pantheon-photos/editable-title
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+310114@code.launchpad.net

Commit message

LibraryProperties: Change title entry for an EditableTitle

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

I would like to have:
* The whole label be activatable
* save on focus out

I think without those it feels a little awkward

review: Needs Fixing
Revision history for this message
Felipe Escoto (philip.scott) wrote :

I kinda disagree on the save on focus out. I feel like having that confirmation is good either with clicking the button, or by pressing enter

But it does feel a lot less awkward with the whole label being clickable

3035. By Felipe Escoto

Editable label on Library Details

Revision history for this message
Danielle Foré (danrabbit) wrote :

It appears that clicking the icon focuses the entry automatically, but clicking the label does not

3036. By Felipe Escoto

Grab focus and refactoring

Revision history for this message
Danielle Foré (danrabbit) wrote :

I think you might have made a small oops :p

Revision history for this message
Danielle Foré (danrabbit) :
3037. By Felipe Escoto

Fixed my oops

Revision history for this message
Felipe Escoto (philip.scott) :
Revision history for this message
Danielle Foré (danrabbit) wrote :

LGTM. I'm happy

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-09-24 19:18:52 +0000
3+++ src/CMakeLists.txt 2016-11-06 03:45:29 +0000
4@@ -175,6 +175,7 @@
5 sidebar/Entry.vala
6 sidebar/Sidebar.vala
7 sidebar/Tree.vala
8+ sidebar/EditableTitle.vala
9
10 sidebar/metadata/BasicProperties.vala
11 sidebar/metadata/ExtendedProperties.vala
12@@ -217,7 +218,7 @@
13
14 include_directories (${CMAKE_SOURCE_DIR}/vapi)
15 add_executable (${EXEC_NAME} ${VALA_C} ${PLUGIN_VALA_C} ${CONFIG_FILE})
16-target_link_libraries (${EXEC_NAME} ${DEPS_LIBRARIES})
17+target_link_libraries (${EXEC_NAME} ${DEPS_LIBRARIES})
18
19 install (TARGETS ${EXEC_NAME} RUNTIME DESTINATION bin)
20
21
22=== added file 'src/sidebar/EditableTitle.vala'
23--- src/sidebar/EditableTitle.vala 1970-01-01 00:00:00 +0000
24+++ src/sidebar/EditableTitle.vala 2016-11-06 03:45:29 +0000
25@@ -0,0 +1,125 @@
26+/*-
27+ * Copyright (c) 2016 Pantheon Developers (https://launchpad.net/pantheon-photos)
28+ *
29+ * This library is free software; you can redistribute it and/or
30+ * modify it under the terms of the GNU Library General Public
31+ * License as published by the Free Software Foundation; either
32+ * version 3 of the License, or (at your option) any later version.
33+ *
34+ * This library is distributed in the hope that it will be useful,
35+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
36+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37+ * Library General Public License for more details.
38+ *
39+ * You should have received a copy of the GNU Library General Public
40+ * License along with this library; if not, write to the
41+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
42+ * Boston, MA 02111-1307, USA.
43+ *
44+ * Authored by: Corentin Noël <corentin@elementary.io>
45+ */
46+
47+public class EditableTitle : Gtk.EventBox {
48+ public signal void changed (string new_title);
49+ private Gtk.Label title;
50+ private Gtk.Entry entry;
51+ private Gtk.Stack stack;
52+ private Gtk.Grid grid;
53+
54+ public string text {
55+ get {
56+ return title.label;
57+ }
58+
59+ set {
60+ title.label = value;
61+ }
62+ }
63+
64+ private bool editing {
65+ set {
66+ if (value) {
67+ entry.text = title.label;
68+ stack.set_visible_child (entry);
69+ entry.grab_focus ();
70+ } else {
71+ if (entry.text.strip () != "" && title.label != entry.text) {
72+ title.label = entry.text;
73+ changed (entry.text);
74+ }
75+
76+ stack.set_visible_child (grid);
77+ }
78+ }
79+ }
80+
81+ public EditableTitle (string? title_name) {
82+ valign = Gtk.Align.CENTER;
83+ events |= Gdk.EventMask.ENTER_NOTIFY_MASK;
84+ events |= Gdk.EventMask.LEAVE_NOTIFY_MASK;
85+ events |= Gdk.EventMask.BUTTON_PRESS_MASK;
86+
87+ title = new Gtk.Label (title_name);
88+ title.ellipsize = Pango.EllipsizeMode.END;
89+ title.hexpand = true;
90+ ((Gtk.Misc) title).xalign = 0;
91+
92+ var edit_button = new Gtk.Button ();
93+ edit_button.image = new Gtk.Image.from_icon_name ("edit-symbolic", Gtk.IconSize.MENU);
94+ edit_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
95+ var button_revealer = new Gtk.Revealer ();
96+ button_revealer.valign = Gtk.Align.CENTER;
97+ button_revealer.transition_type = Gtk.RevealerTransitionType.CROSSFADE;
98+ button_revealer.add (edit_button);
99+
100+ grid = new Gtk.Grid ();
101+ grid.valign = Gtk.Align.CENTER;
102+ grid.column_spacing = 12;
103+ grid.add (title);
104+ grid.add (button_revealer);
105+
106+ entry = new Gtk.Entry ();
107+ entry.secondary_icon_name = "go-jump-symbolic";
108+
109+ stack = new Gtk.Stack ();
110+ stack.transition_type = Gtk.StackTransitionType.CROSSFADE;
111+ stack.add (grid);
112+ stack.add (entry);
113+ add (stack);
114+
115+ enter_notify_event.connect ((event) => {
116+ if (event.detail != Gdk.NotifyType.INFERIOR) {
117+ button_revealer.set_reveal_child (true);
118+ }
119+
120+ return false;
121+ });
122+
123+ leave_notify_event.connect ((event) => {
124+ if (event.detail != Gdk.NotifyType.INFERIOR) {
125+ button_revealer.set_reveal_child (false);
126+ }
127+
128+ return false;
129+ });
130+
131+ button_press_event.connect ((event) => {
132+ editing = true;
133+ return false;
134+ });
135+
136+ edit_button.clicked.connect (() => {
137+ editing = true;
138+ });
139+
140+ entry.activate.connect (() => {
141+ editing = false;
142+ });
143+
144+ entry.icon_release.connect ((p0, p1) => {
145+ if (p0 == Gtk.EntryIconPosition.SECONDARY) {
146+ editing = false;
147+ }
148+ });
149+ }
150+}
151
152=== modified file 'src/sidebar/metadata/LibraryProperties.vala'
153--- src/sidebar/metadata/LibraryProperties.vala 2016-09-19 21:18:06 +0000
154+++ src/sidebar/metadata/LibraryProperties.vala 2016-11-06 03:45:29 +0000
155@@ -7,7 +7,7 @@
156 private class LibraryProperties : Properties {
157 private MediaSource? media_source;
158 private string comment;
159- private Gtk.Entry title_entry;
160+ private EditableTitle title_entry;
161 private Gtk.Entry tags_entry;
162 private PlaceHolderTextView comment_entry;
163 private bool is_media;
164@@ -66,9 +66,9 @@
165 base.internal_update_properties (page);
166
167 if (is_media) {
168- title_entry = new Gtk.Entry ();
169+ title_entry = new EditableTitle (null);
170 if (title != null)
171- title_entry.set_text (title);
172+ title_entry.text = title;
173 title_entry.changed.connect (title_entry_changed);
174 add_entry_line (_("Title"), title_entry);
175
176@@ -124,7 +124,7 @@
177 }
178
179 private void title_entry_changed () {
180- title = title_entry.get_text ();
181+ title = title_entry.text;
182 }
183
184 private void tags_entry_changed () {

Subscribers

People subscribed via source and target branches

to all changes: