[placeDisplay] Fix dnd regression

DND from the places section broke with 1c4c3afb when St.Label was
replaced with St.Button.
To fix, replace St.Button with St.Clickable and use a fake_release
when starting a drag.

https://bugzilla.gnome.org/show_bug.cgi?id=609218
This commit is contained in:
Florian Müllner 2010-02-23 14:25:09 +01:00
parent 8b792f8942
commit ddfe9442fa
2 changed files with 65 additions and 16 deletions

View File

@ -516,10 +516,18 @@ StTooltip {
/* Places */ /* Places */
.places-actions { .places-item-box {
spacing: 4px; spacing: 4px;
} }
.places-item {
padding: 2px;
}
.places-actions {
spacing: 2px;
}
#placesDevices { #placesDevices {
padding-top: 4px; padding-top: 4px;
} }

View File

@ -408,31 +408,44 @@ DashPlaceDisplayItem.prototype = {
this.name = info.name; this.name = info.name;
this._info = info; this._info = info;
this._icon = info.iconFactory(PLACES_ICON_SIZE); this._icon = info.iconFactory(PLACES_ICON_SIZE);
this.actor = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
spacing: 4 }); this.actor = new St.Clickable({ style_class: 'places-item',
let text = new St.Button({ style_class: 'places-item', reactive: true,
label: info.name, x_align: St.Align.START,
x_align: St.Align.START }); x_fill: true });
text.connect('clicked', Lang.bind(this, this._onClicked));
let iconBox = new St.Bin({ child: this._icon, reactive: true }); let box = new St.BoxLayout({ style_class: 'places-item-box' });
iconBox.connect('button-release-event', this.actor.set_child(box);
Lang.bind(this, this._onClicked));
this.actor.append(iconBox, Big.BoxPackFlags.NONE); let bin = new St.Bin({ child: this._icon });
this.actor.append(text, Big.BoxPackFlags.EXPAND); box.add(bin);
let text = new St.Label({ text: info.name });
box.add(text, { expand: true, x_fill: true });
if (info.isRemovable()) { if (info.isRemovable()) {
let removeIcon = St.TextureCache.get_default().load_icon_name ('media-eject', PLACES_ICON_SIZE); let removeIcon = St.TextureCache.get_default().load_icon_name ('media-eject', PLACES_ICON_SIZE);
let removeIconBox = new St.Button({ child: removeIcon, let removeIconBox = new St.Clickable({ child: removeIcon,
reactive: true }); reactive: true });
this.actor.append(removeIconBox, Big.BoxPackFlags.NONE); box.add(removeIconBox);
removeIconBox.connect('clicked', removeIconBox.connect('clicked',
Lang.bind(this, function() { Lang.bind(this, function() {
this._info.remove(); this._info.remove();
})); }));
} }
this.actor.connect('clicked', Lang.bind(this, this._onClicked));
this.actor.connect('notify::hover',
Lang.bind(this, this._onHoverChanged));
this.actor.connect('button-press-event',
Lang.bind(this, this._onButtonPress));
this.actor.connect('button-release-event',
Lang.bind(this, this._onButtonRelease));
this.actor._delegate = this; this.actor._delegate = this;
let draggable = DND.makeDraggable(this.actor); this._dragStartX = null;
this._dragStartY = null;
this._draggable = DND.makeDraggable(this.actor, true);
}, },
_onClicked: function(b) { _onClicked: function(b) {
@ -440,6 +453,34 @@ DashPlaceDisplayItem.prototype = {
Main.overview.hide(); Main.overview.hide();
}, },
_onButtonPress: function(actor, event) {
if (event.get_button() != 1)
return false;
let [stageX, stageY] = event.get_coords();
this._dragStartX = stageX;
this._dragStartY = stageY;
},
_onButtonRelease: function(actor, event) {
if (event.get_button() != 1)
return false;
this._dragStartX = null;
this._dragStartY = null;
},
_onHoverChanged: function(button) {
let hover = button.hover;
if (!hover) {
if (button.pressed && this._dragStartX != null) {
button.fake_release();
this._draggable.startDrag(this._dragStartX, this._dragStartY,
global.get_current_time());
}
}
},
getDragActorSource: function() { getDragActorSource: function() {
return this._icon; return this._icon;
}, },