6
6
const Meta = imports.gi.Meta;
7
7
const Shell = imports.gi.Shell;
8
8
const St = imports.gi.St;
9
const Mainloop = imports.mainloop;
10
11
const AppDisplay = imports.ui.appDisplay;
11
12
const AppFavorites = imports.ui.appFavorites;
16
17
const Workspace = imports.ui.workspace;
18
19
const DASH_ANIMATION_TIME = 0.2;
20
const DASH_ITEM_LABEL_SHOW_TIME = 0.15;
21
const DASH_ITEM_LABEL_HIDE_TIME = 0.1;
22
const DASH_ITEM_HOVER_TIMEOUT = 300;
20
24
// A container like StBin, but taking the child's scale into account
21
25
// when requesting a size
22
function DashItemContainer() {
26
const DashItemContainer = new Lang.Class({
27
Name: 'DashItemContainer',
26
DashItemContainer.prototype = {
27
29
_init: function() {
28
30
this.actor = new Shell.GenericContainer({ style_class: 'dash-item-container' });
29
31
this.actor.connect('get-preferred-width',
86
90
alloc.natural_size = natWidth * this.child.scale_y;
93
showLabel: function() {
94
if (this._label == null)
97
this._label.opacity = 0;
100
let [stageX, stageY] = this.actor.get_transformed_position();
102
let itemHeight = this.actor.allocation.y2 - this.actor.allocation.y1;
104
let labelHeight = this._label.get_height();
105
let yOffset = Math.floor((itemHeight - labelHeight) / 2)
107
let y = stageY + yOffset;
109
let node = this._label.get_theme_node();
110
let xOffset = node.get_length('-x-offset');
113
if (St.Widget.get_default_direction () == St.TextDirection.RTL)
114
x = stageX - this._label.get_width() - xOffset;
116
x = stageX + this.actor.get_width() + xOffset;
118
this._label.set_position(x, y);
119
Tweener.addTween(this._label,
121
time: DASH_ITEM_LABEL_SHOW_TIME,
122
transition: 'easeOutQuad',
126
setLabelText: function(text) {
127
if (this._label == null)
128
this._label = new St.Label({ style_class: 'dash-label'});
130
this._label.set_text(text);
131
Main.layoutManager.addChrome(this._label);
135
hideLabel: function () {
136
this._label.opacity = 255;
137
Tweener.addTween(this._label,
139
time: DASH_ITEM_LABEL_HIDE_TIME,
140
transition: 'easeOutQuad',
141
onComplete: Lang.bind(this, function() {
89
147
setChild: function(actor) {
90
148
if (this.child == actor)
93
this.actor.destroy_children();
151
this.actor.destroy_all_children();
95
153
this.child = actor;
96
154
this.actor.add_actor(this.child);
157
215
get childOpacity() {
158
216
return this._childOpacity;
162
function RemoveFavoriteIcon() {
166
RemoveFavoriteIcon.prototype = {
167
__proto__: DashItemContainer.prototype,
220
const RemoveFavoriteIcon = new Lang.Class({
221
Name: 'RemoveFavoriteIcon',
222
Extends: DashItemContainer,
169
224
_init: function() {
170
DashItemContainer.prototype._init.call(this);
172
227
this._iconBin = new St.Bin({ style_class: 'remove-favorite' });
173
228
this._iconActor = null;
225
function DragPlaceholderItem() {
229
DragPlaceholderItem.prototype = {
230
__proto__: DashItemContainer.prototype,
279
const DragPlaceholderItem = new Lang.Class({
280
Name: 'DragPlaceholderItem',
281
Extends: DashItemContainer,
232
283
_init: function() {
233
DashItemContainer.prototype._init.call(this);
234
this.setChild(new St.Bin({ style_class: 'dash-placeholder' }));
285
this.setChild(new St.Bin({ style_class: 'placeholder' }));
289
const Dash = new Lang.Class({
244
292
_init : function() {
245
293
this._maxHeight = -1;
246
294
this.iconSize = 64;
250
298
this._dragPlaceholderPos = -1;
251
299
this._animatingPlaceholdersCount = 0;
252
300
this._favRemoveTarget = null;
301
this._showLabelTimeoutId = 0;
302
this._resetHoverTimeoutId = 0;
303
this._labelShowing = false;
254
305
this._box = new St.BoxLayout({ name: 'dash',
383
434
Lang.bind(this, function() {
384
435
display.actor.opacity = 255;
386
display.actor.set_tooltip_text(app.get_name());
388
438
let item = new DashItemContainer();
389
439
item.setChild(display.actor);
441
item.setLabelText(app.get_name());
391
443
display.icon.setIconSize(this.iconSize);
444
display.actor.connect('notify::hover',
445
Lang.bind(this, function() {
446
this._onHover(item, display)
451
_onHover: function (item, display) {
452
if (display.actor.get_hover() && !display.isMenuUp) {
453
if (this._showLabelTimeoutId == 0) {
454
let timeout = this._labelShowing ? 0 : DASH_ITEM_HOVER_TIMEOUT;
455
this._showLabelTimeoutId = Mainloop.timeout_add(timeout,
456
Lang.bind(this, function() {
457
this._labelShowing = true;
461
if (this._resetHoverTimeoutId > 0) {
462
Mainloop.source_remove(this._resetHoverTimeoutId);
463
this._resetHoverTimeoutId = 0;
467
if (this._showLabelTimeoutId > 0)
468
Mainloop.source_remove(this._showLabelTimeoutId);
469
this._showLabelTimeoutId = 0;
471
if (this._labelShowing) {
472
this._resetHoverTimeoutId = Mainloop.timeout_add(DASH_ITEM_HOVER_TIMEOUT,
473
Lang.bind(this, function() {
474
this._labelShowing = false;
396
481
_adjustIconSize: function() {
397
482
// For the icon size, we only consider children which are "proper"
398
483
// icons (i.e. ignoring drag placeholders) and which are not
594
679
for (let i = 0; i < addedItems.length; i++)
595
this._box.insert_actor(addedItems[i].item.actor,
680
this._box.insert_child_at_index(addedItems[i].item.actor,
598
683
for (let i = 0; i < removedActors.length; i++) {
599
684
let item = removedActors[i]._delegate;
702
787
this._dragPlaceholder = new DragPlaceholderItem();
703
788
this._dragPlaceholder.child.set_width (this.iconSize);
704
789
this._dragPlaceholder.child.set_height (this.iconSize / 2);
705
this._box.insert_actor(this._dragPlaceholder.actor,
706
this._dragPlaceholderPos);
790
this._box.insert_child_at_index(this._dragPlaceholder.actor,
791
this._dragPlaceholderPos);
708
793
this._dragPlaceholder.animateIn();