Merge lp:~tintou/granite/alertview into lp:~elementary-pantheon/granite/granite

Proposed by Corentin Noël
Status: Merged
Approved by: Danielle Foré
Approved revision: 860
Merged at revision: 859
Proposed branch: lp:~tintou/granite/alertview
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 220 lines (+171/-0)
3 files modified
demo/GraniteDemo.vala (+13/-0)
lib/CMakeLists.txt (+1/-0)
lib/Widgets/AlertView.vala (+157/-0)
To merge this branch: bzr merge lp:~tintou/granite/alertview
Reviewer Review Type Date Requested Status
Cameron Norman (community) Approve
Danielle Foré ux Approve
elementary Pantheon team code Pending
Review via email: mp+260207@code.launchpad.net

Commit message

New AlertView widget

Description of the change

New AlertView widget

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

Looks solid here :)

review: Approve (ux)
Revision history for this message
Cameron Norman (cameronnemo) wrote :

One tiny documentation grammar issue, I commented inline.

review: Needs Fixing (docs)
lp:~tintou/granite/alertview updated
860. By Corentin Noël

[Documentation] fixed grammar.

Revision history for this message
Corentin Noël (tintou) wrote :

I fixed the grammar issue

Revision history for this message
Cameron Norman (cameronnemo) wrote :

I tested and looked over the code and it looks good here.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'demo/GraniteDemo.vala'
2--- demo/GraniteDemo.vala 2015-05-15 09:08:34 +0000
3+++ demo/GraniteDemo.vala 2015-06-08 15:07:04 +0000
4@@ -79,6 +79,7 @@
5 create_sourcelist ();
6 create_modebutton ();
7 create_dynamictab ();
8+ create_alert ();
9
10 window.add (main_stack);
11 window.set_default_size (800, 550);
12@@ -113,6 +114,7 @@
13 welcome.append ("tag-new", "SourceList", "A widget that can display a list of items organized in categories.");
14 welcome.append ("object-inverse", "ModeButton", "This widget is a multiple option modal switch");
15 welcome.append ("document-open", "DynamicNotebook", "Tab bar widget designed for a variable number of tabs.");
16+ welcome.append ("dialog-warning", "AlertView", "A View showing that an action is required to function.");
17 welcome.activated.connect ((index) => {
18 switch (index) {
19 case 0:
20@@ -131,6 +133,10 @@
21 home_button.show ();
22 main_stack.set_visible_child_name ("dynamictab");
23 break;
24+ case 4:
25+ home_button.show ();
26+ main_stack.set_visible_child_name ("alert");
27+ break;
28 }
29 });
30 main_stack.add_named (welcome, "welcome");
31@@ -215,6 +221,13 @@
32 main_stack.add_named (grid, "modebutton");
33 }
34
35+ private void create_alert () {
36+ var alert = new Granite.Widgets.AlertView ("Nothing here", "Maybe you can enable <b>something</b> to hide it but <i>otherwise</i> it will stay here", "dialog-warning");
37+ main_stack.add_named (alert, "alert");
38+ alert.show_action ("Hide this button");
39+ alert.action_activated.connect (() => {alert.hide_action ();});
40+ }
41+
42 int i;
43 private void create_dynamictab () {
44 var notebook = new Granite.Widgets.DynamicNotebook ();
45
46=== added file 'doc/images/AlertView.png'
47Binary files doc/images/AlertView.png 1970-01-01 00:00:00 +0000 and doc/images/AlertView.png 2015-06-08 15:07:04 +0000 differ
48=== modified file 'lib/CMakeLists.txt'
49--- lib/CMakeLists.txt 2015-03-25 22:30:35 +0000
50+++ lib/CMakeLists.txt 2015-06-08 15:07:04 +0000
51@@ -19,6 +19,7 @@
52 Services/ContractorProxy.vala
53 Services/IconFactory.vala
54 Services/SimpleCommand.vala
55+ Widgets/AlertView.vala
56 Widgets/Utils.vala
57 Widgets/WrapLabel.vala
58 Widgets/AboutDialog.vala
59
60=== added file 'lib/Widgets/AlertView.vala'
61--- lib/Widgets/AlertView.vala 1970-01-01 00:00:00 +0000
62+++ lib/Widgets/AlertView.vala 2015-06-08 15:07:04 +0000
63@@ -0,0 +1,157 @@
64+/*
65+ * Copyright (C) 2012-2015 Granite Developers (https://launchpad.net/granite)
66+ *
67+ * This program or library is free software; you can redistribute it
68+ * and/or modify it under the terms of the GNU Lesser General Public
69+ * License as published by the Free Software Foundation; either
70+ * version 3 of the License, or (at your option) any later version.
71+ *
72+ * This library is distributed in the hope that it will be useful,
73+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
74+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
75+ * Lesser General Public License for more details.
76+ *
77+ * You should have received a copy of the GNU Lesser General
78+ * Public License along with this library; if not, write to the
79+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
80+ * Boston, MA 02110-1301 USA.
81+ *
82+ * Authored by: Corentin Noël <corentin@elementary.io>
83+ */
84+
85+/**
86+ * The AlertView widget shows to the user that some actions are now restricted.
87+ *
88+ * It can be used to show an empty view or hiding a panel when this one is disabled.
89+ *
90+ * {{../../doc/images/AlertView.png}}
91+ */
92+public class Granite.Widgets.AlertView : Gtk.Grid {
93+ public signal void action_activated ();
94+
95+ /**
96+ * The first line of text, should be short and not contain markup.
97+ */
98+ public string title {
99+ get {
100+ return title_label.label;
101+ }
102+ set {
103+ title_label.label = value;
104+ }
105+ }
106+
107+ /**
108+ * The second line of text, explaining why this alert is shown.
109+ * You may need to escape it with #escape_text or #printf_escaped
110+ */
111+ public string description {
112+ get {
113+ return description_label.label;
114+ }
115+ set {
116+ description_label.label = value;
117+ }
118+ }
119+
120+ /**
121+ * The icon name
122+ */
123+ public string icon_name {
124+ owned get {
125+ return image.icon_name;
126+ }
127+ set {
128+ image.set_from_icon_name (value, Gtk.IconSize.DIALOG);
129+ }
130+ }
131+
132+ private Gtk.Label title_label;
133+ private Gtk.Label description_label;
134+ private Gtk.Image image;
135+ private Gtk.Button action_button;
136+ private Gtk.Revealer action_revealer;
137+
138+ /**
139+ * Makes new AlertView
140+ *
141+ * @param title the first line of text
142+ * @param description the second line of text
143+ * @param icon_name the icon to be shown
144+ */
145+ public AlertView (string title, string description, string icon_name) {
146+ Object (title: title, description: description, icon_name: icon_name);
147+ }
148+
149+ construct {
150+ get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
151+ row_spacing = 12;
152+ column_spacing = 12;
153+
154+ title_label = new Gtk.Label (null);
155+ title_label.hexpand = true;
156+ title_label.get_style_context ().add_class ("h2");
157+ title_label.halign = Gtk.Align.START;
158+ title_label.valign = Gtk.Align.START;
159+
160+ description_label = new Gtk.Label (null);
161+ description_label.hexpand = true;
162+ description_label.wrap = true;
163+ description_label.justify = Gtk.Justification.FILL;
164+ description_label.use_markup = true;
165+ description_label.halign = Gtk.Align.START;
166+ description_label.valign = Gtk.Align.START;
167+
168+ action_button = new Gtk.Button ();
169+ action_button.margin_top = 12;
170+
171+ action_revealer = new Gtk.Revealer ();
172+ action_revealer.add (action_button);
173+ action_revealer.halign = Gtk.Align.END;
174+ action_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_UP;
175+
176+ image = new Gtk.Image ();
177+ var image_box = new Gtk.EventBox ();
178+ image_box.halign = Gtk.Align.END;
179+ image_box.add (image);
180+
181+ attach (image_box, 1, 1, 1, 2);
182+ attach (title_label, 2, 1, 1, 1);
183+ attach (description_label, 2, 2, 1, 1);
184+ attach (action_revealer, 2, 3, 1, 1);
185+
186+ // Needed to center the text and image in the window.
187+ var left_grid = new Gtk.Grid ();
188+ left_grid.expand = true;
189+ attach (left_grid, 0, 0, 1, 1);
190+
191+ var right_grid = new Gtk.Grid ();
192+ right_grid.expand = true;
193+ attach (right_grid, 3, 4, 1, 1);
194+
195+ action_button.clicked.connect (() => {action_activated ();});
196+ }
197+
198+ /**
199+ * Creates the action button with the given label
200+ *
201+ * @param label the text of the action button
202+ */
203+ public void show_action (string? label = null) {
204+ if (label != null)
205+ action_button.label = label;
206+
207+ if (action_button.label == null)
208+ return;
209+
210+ action_revealer.set_reveal_child (true);
211+ action_revealer.show_all ();
212+ }
213+
214+ /**
215+ * Hides the action button.
216+ */
217+ public void hide_action () {
218+ action_revealer.set_reveal_child (false);
219+ }
220+}

Subscribers

People subscribed via source and target branches