Skip to content

Commit 865269b

Browse files
authored
ui: Add a new placeholder object (#13304)
Gives a simple reusable object to show when no active items are available. Make use of this new object in [email protected] when the recent and favorite categories are empty.
1 parent b0d117d commit 865269b

3 files changed

Lines changed: 146 additions & 14 deletions

File tree

data/theme/cinnamon-sass/widgets/_base.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@
5050
-pie-background-color: rgba(140, 140, 140, 0.6);
5151
}
5252

53+
// placeholder
54+
55+
.placeholder {
56+
spacing: 8px;
57+
padding: $base_padding * 2;
58+
59+
.placeholder-icon { color: $insensitive_fg_color; }
60+
.placeholder-label {
61+
@extend %title_3;
62+
text-align: center;
63+
color: $insensitive_fg_color;
64+
padding-top: 8px;
65+
}
66+
67+
.placeholder-description {
68+
color: $insensitive_fg_color;
69+
text-align: center;
70+
}
71+
}
72+
5373
// ripples
5474

5575
.ripple-pointer-location {

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const Pango = imports.gi.Pango;
2626
const SearchProviderManager = imports.ui.searchProviderManager;
2727
const SignalManager = imports.misc.signalManager;
2828
const Params = imports.misc.params;
29+
const Placeholder = imports.ui.placeholder;
2930

3031
const INITIAL_BUTTON_LOAD = 30;
3132

@@ -2246,14 +2247,19 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
22462247
button.actor.visible = this.menu.isOpen && this.lastSelectedCategory === "recent";
22472248
} else {
22482249
this.noRecentDocuments = true;
2249-
let button = new SimpleMenuItem(this, { name: _("No recent documents"),
2250-
type: 'no-recent',
2251-
styleClass: 'appmenu-application-button',
2252-
reactive: false,
2253-
activatable: false });
2254-
button.addLabel(button.name, 'appmenu-application-button-label');
2250+
let button = new SimpleMenuItem(this, {
2251+
type: 'no-recent',
2252+
reactive:false,
2253+
});
2254+
let placeHolder = new Placeholder.Placeholder({
2255+
icon_name: 'xsi-document-open-recent-symbolic',
2256+
title: _('No Recent Documents'),
2257+
});
2258+
button.actor.y_expand = true;
2259+
button.actor.y_align = Clutter.ActorAlign.CENTER;
2260+
button.actor.add_child(placeHolder);
22552261
this._recentButtons.push(button);
2256-
this.applicationsBox.add_actor(button.actor);
2262+
this.applicationsBox.add_child(button.actor);
22572263
button.actor.visible = this.menu.isOpen && this.lastSelectedCategory === "recent";
22582264
}
22592265
}
@@ -2294,14 +2300,20 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
22942300
});
22952301
}
22962302
else {
2297-
let button = new SimpleMenuItem(this, { name: _("No favorite documents"),
2298-
type: 'no-favorites',
2299-
styleClass: 'appmenu-application-button',
2300-
reactive: false,
2301-
activatable: false });
2302-
button.addLabel(button.name, 'appmenu-application-button-label');
2303+
let button = new SimpleMenuItem(this, {
2304+
type: 'no-favorites',
2305+
reactive: false,
2306+
});
2307+
let placeHolder = new Placeholder.Placeholder({
2308+
icon_name: 'xsi-user-favorites-symbolic',
2309+
title: _('No Favorite Documents'),
2310+
description: _("Files you add to Favorites in your file manager will be shown here")
2311+
});
2312+
button.actor.y_expand = true;
2313+
button.actor.y_align = Clutter.ActorAlign.CENTER;
2314+
button.actor.add_child(placeHolder);
23032315
this._favoriteDocButtons.push(button);
2304-
this.applicationsBox.add_actor(button.actor);
2316+
this.applicationsBox.add_child(button.actor);
23052317
button.actor.visible = this.menu.isOpen && this.lastSelectedCategory === "favorite";
23062318
}
23072319
}

js/ui/placeholder.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
2+
3+
const { Clutter, GObject, Pango, St } = imports.gi;
4+
5+
var Placeholder = GObject.registerClass({
6+
Properties: {
7+
'icon-name': GObject.ParamSpec.string(
8+
'icon-name', null, null,
9+
GObject.ParamFlags.READWRITE |
10+
GObject.ParamFlags.CONSTRUCT,
11+
null),
12+
'title': GObject.ParamSpec.string(
13+
'title', null, null,
14+
GObject.ParamFlags.READWRITE |
15+
GObject.ParamFlags.CONSTRUCT,
16+
null),
17+
'description': GObject.ParamSpec.string(
18+
'description', null, null,
19+
GObject.ParamFlags.READWRITE |
20+
GObject.ParamFlags.CONSTRUCT,
21+
null),
22+
},
23+
}, class Placeholder extends St.BoxLayout {
24+
_init(params) {
25+
this._icon = new St.Icon({
26+
style_class: 'placeholder-icon',
27+
icon_size: 64,
28+
icon_type: St.IconType.SYMBOLIC,
29+
x_align: Clutter.ActorAlign.CENTER,
30+
});
31+
32+
this._title = new St.Label({
33+
style_class: 'placeholder-label',
34+
x_align: Clutter.ActorAlign.CENTER,
35+
});
36+
this._title.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
37+
this._title.clutter_text.line_wrap = true;
38+
39+
this._description = new St.Label({
40+
style_class: 'placeholder-description',
41+
x_align: Clutter.ActorAlign.CENTER,
42+
});
43+
this._description.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
44+
this._description.clutter_text.line_wrap = true;
45+
46+
super._init({
47+
style_class: 'placeholder',
48+
reactive: false,
49+
vertical: true,
50+
x_expand: true,
51+
y_expand: true,
52+
...params,
53+
});
54+
55+
this.add_child(this._icon);
56+
this.add_child(this._title);
57+
this.add_child(this._description);
58+
}
59+
60+
get icon_name() {
61+
return this._icon.icon_name;
62+
}
63+
64+
set icon_name(iconName) {
65+
if (this._icon.icon_name === iconName)
66+
return;
67+
68+
this._icon.icon_name = iconName;
69+
this.notify('icon-name');
70+
}
71+
72+
get title() {
73+
return this._title.text;
74+
}
75+
76+
set title(title) {
77+
if (this._title.text === title)
78+
return;
79+
80+
this._title.text = title;
81+
this.notify('title');
82+
}
83+
84+
get description() {
85+
return this._description.text;
86+
}
87+
88+
set description(description) {
89+
if (this._description.text === description)
90+
return;
91+
92+
if (description === null)
93+
this._description.visible = false;
94+
else
95+
this._description.visible = true;
96+
97+
this._description.text = description;
98+
this.notify('description');
99+
}
100+
});

0 commit comments

Comments
 (0)