dash: Refactor some common code

Take the code that gets an app from a "source" that's duplicated
in lots of spots and refactor it out.

https://bugzilla.gnome.org/show_bug.cgi?id=685313
This commit is contained in:
Jasper St. Pierre 2012-10-02 21:13:47 -03:00
parent be24ee435c
commit 147a6e49dc

View File

@ -21,6 +21,18 @@ const DASH_ITEM_LABEL_SHOW_TIME = 0.15;
const DASH_ITEM_LABEL_HIDE_TIME = 0.1; const DASH_ITEM_LABEL_HIDE_TIME = 0.1;
const DASH_ITEM_HOVER_TIMEOUT = 300; const DASH_ITEM_HOVER_TIMEOUT = 300;
function getAppFromSource(source) {
if (source instanceof AppDisplay.AppWellIcon) {
let appSystem = Shell.AppSystem.get_default();
return appSystem.lookup_app(source.getId());
} else if (source.metaWindow) {
let tracker = Shell.WindowTracker.get_default();
return tracker.get_window_app(source.metaWindow);
} else {
return null;
}
}
// A container like StBin, but taking the child's scale into account // A container like StBin, but taking the child's scale into account
// when requesting a size // when requesting a size
const DashItemContainer = new Lang.Class({ const DashItemContainer = new Lang.Class({
@ -279,14 +291,9 @@ const ShowAppsIcon = new Lang.Class({
}, },
acceptDrop: function(source, actor, x, y, time) { acceptDrop: function(source, actor, x, y, time) {
let app = null; let app = getAppFromSource(source);
if (source instanceof AppDisplay.AppWellIcon) { if (app == null)
let appSystem = Shell.AppSystem.get_default(); return false;
app = appSystem.lookup_app(source.getId());
} else if (source.metaWindow) {
let tracker = Shell.WindowTracker.get_default();
app = tracker.get_window_app(source.metaWindow);
}
let id = app.get_id(); let id = app.get_id();
@ -382,7 +389,6 @@ const Dash = new Lang.Class({
this._workId = Main.initializeDeferredWork(this._box, Lang.bind(this, this._redisplay)); this._workId = Main.initializeDeferredWork(this._box, Lang.bind(this, this._redisplay));
this._tracker = Shell.WindowTracker.get_default();
this._appSystem = Shell.AppSystem.get_default(); this._appSystem = Shell.AppSystem.get_default();
this._appSystem.connect('installed-changed', Lang.bind(this, this._queueRedisplay)); this._appSystem.connect('installed-changed', Lang.bind(this, this._queueRedisplay));
@ -429,12 +435,8 @@ const Dash = new Lang.Class({
}, },
_onDragMotion: function(dragEvent) { _onDragMotion: function(dragEvent) {
let app = null; let app = getAppFromSource(dragEvent.source);
if (dragEvent.source instanceof AppDisplay.AppWellIcon) if (app == null)
app = this._appSystem.lookup_app(dragEvent.source.getId());
else if (dragEvent.source.metaWindow)
app = this._tracker.get_window_app(dragEvent.source.metaWindow);
else
return DND.DragMotionResult.CONTINUE; return DND.DragMotionResult.CONTINUE;
let id = app.get_id(); let id = app.get_id();
@ -762,11 +764,7 @@ const Dash = new Lang.Class({
}, },
handleDragOver : function(source, actor, x, y, time) { handleDragOver : function(source, actor, x, y, time) {
let app = null; let app = getAppFromSource(source);
if (source instanceof AppDisplay.AppWellIcon)
app = this._appSystem.lookup_app(source.getId());
else if (source.metaWindow)
app = this._tracker.get_window_app(source.metaWindow);
// Don't allow favoriting of transient apps // Don't allow favoriting of transient apps
if (app == null || app.is_window_backed()) if (app == null || app.is_window_backed())
@ -847,12 +845,7 @@ const Dash = new Lang.Class({
// Draggable target interface // Draggable target interface
acceptDrop : function(source, actor, x, y, time) { acceptDrop : function(source, actor, x, y, time) {
let app = null; let app = getAppFromSource(source);
if (source instanceof AppDisplay.AppWellIcon) {
app = this._appSystem.lookup_app(source.getId());
} else if (source.metaWindow) {
app = this._tracker.get_window_app(source.metaWindow);
}
// Don't allow favoriting of transient apps // Don't allow favoriting of transient apps
if (app == null || app.is_window_backed()) { if (app == null || app.is_window_backed()) {