[AppIcon] Make BaseWellItem a subclass of AppIcon

Part of https://bugzilla.gnome.org/show_bug.cgi?id=590563
This commit is contained in:
Dan Winship 2009-09-11 17:13:50 -04:00
parent 8f660f563c
commit 18dbc5462f
2 changed files with 44 additions and 41 deletions

View File

@ -38,8 +38,6 @@ const WELL_MENU_COLOR = new Clutter.Color();
WELL_MENU_COLOR.from_pixel(0xffffffff); WELL_MENU_COLOR.from_pixel(0xffffffff);
const WELL_MENU_SELECTED_COLOR = new Clutter.Color(); const WELL_MENU_SELECTED_COLOR = new Clutter.Color();
WELL_MENU_SELECTED_COLOR.from_pixel(0x005b97ff); WELL_MENU_SELECTED_COLOR.from_pixel(0x005b97ff);
const WELL_MENU_BORDER_COLOR = new Clutter.Color();
WELL_MENU_BORDER_COLOR.from_pixel(0x787878ff);
const WELL_MENU_SEPARATOR_COLOR = new Clutter.Color(); const WELL_MENU_SEPARATOR_COLOR = new Clutter.Color();
WELL_MENU_SEPARATOR_COLOR.from_pixel(0x787878ff); WELL_MENU_SEPARATOR_COLOR.from_pixel(0x787878ff);
const WELL_MENU_BORDER_WIDTH = 1; const WELL_MENU_BORDER_WIDTH = 1;
@ -497,7 +495,7 @@ WellMenu.prototype = {
this.actor.connect('allocate', Lang.bind(this, this._allocate)); this.actor.connect('allocate', Lang.bind(this, this._allocate));
this._windowContainer = new Shell.Menu({ orientation: Big.BoxOrientation.VERTICAL, this._windowContainer = new Shell.Menu({ orientation: Big.BoxOrientation.VERTICAL,
border_color: WELL_MENU_BORDER_COLOR, border_color: AppIcon.APPICON_BORDER_COLOR,
border: WELL_MENU_BORDER_WIDTH, border: WELL_MENU_BORDER_WIDTH,
background_color: WELL_MENU_BACKGROUND_COLOR, background_color: WELL_MENU_BACKGROUND_COLOR,
padding: 4, padding: 4,
@ -519,7 +517,7 @@ WellMenu.prototype = {
this._arrow = new Shell.DrawingArea(); this._arrow = new Shell.DrawingArea();
this._arrow.connect('redraw', Lang.bind(this, function (area, texture) { this._arrow.connect('redraw', Lang.bind(this, function (area, texture) {
Shell.draw_box_pointer(texture, WELL_MENU_BORDER_COLOR, WELL_MENU_BACKGROUND_COLOR); Shell.draw_box_pointer(texture, AppIcon.APPICON_BORDER_COLOR, WELL_MENU_BACKGROUND_COLOR);
})); }));
this.actor.add_actor(this._arrow); this.actor.add_actor(this._arrow);
@ -757,17 +755,14 @@ function BaseWellItem(appInfo, isFavorite) {
} }
BaseWellItem.prototype = { BaseWellItem.prototype = {
__proto__: AppIcon.AppIcon.prototype,
_init: function(appInfo, isFavorite) { _init: function(appInfo, isFavorite) {
this.appInfo = appInfo; AppIcon.AppIcon.prototype._init.call(this, appInfo);
this.isFavorite = isFavorite; this.isFavorite = isFavorite;
this.icon = new AppIcon.AppIcon(appInfo);
this.windows = this.icon.windows; this._draggable = DND.makeDraggable(this.actor, true);
this.actor = new Shell.ButtonBox({ orientation: Big.BoxOrientation.VERTICAL,
border: WELL_MENU_BORDER_WIDTH,
corner_radius: WELL_MENU_CORNER_RADIUS,
reactive: true });
this.icon.actor._delegate = this;
this._draggable = DND.makeDraggable(this.icon.actor, true);
// Do these as anonymous functions to avoid conflict with handlers in subclasses // Do these as anonymous functions to avoid conflict with handlers in subclasses
this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) { this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
@ -789,7 +784,6 @@ BaseWellItem.prototype = {
} }
} }
})); }));
this.actor.append(this.icon.actor, Big.BoxPackFlags.NONE);
}, },
shellWorkspaceLaunch : function() { shellWorkspaceLaunch : function() {
@ -804,14 +798,14 @@ BaseWellItem.prototype = {
this.appInfo.launch(); this.appInfo.launch();
}, },
getDragActor: function(stageX, stageY) { getDragActor: function() {
return this.icon.getDragActor(stageX, stageY); return this.createDragActor();
}, },
// Returns the original icon that is being used as a source for the cloned texture // Returns the original icon that is being used as a source for the cloned texture
// that represents the item as it is being dragged. // that represents the item as it is being dragged.
getDragActorSource: function() { getDragActorSource: function() {
return this.icon.getDragActorSource(); return this.actor;
} }
} }
@ -915,21 +909,11 @@ InactiveWellItem.prototype = {
BaseWellItem.prototype._init.call(this, appInfo, isFavorite); BaseWellItem.prototype._init.call(this, appInfo, isFavorite);
this.actor.connect('notify::pressed', Lang.bind(this, this._onPressedChanged)); this.actor.connect('notify::pressed', Lang.bind(this, this._onPressedChanged));
this.actor.connect('notify::hover', Lang.bind(this, this._onHoverChanged));
this.actor.connect('activate', Lang.bind(this, this._onActivate)); this.actor.connect('activate', Lang.bind(this, this._onActivate));
}, },
_onPressedChanged: function() { _onPressedChanged: function() {
let pressed = this.actor.pressed; this.setHighlight(this.actor.pressed);
if (pressed) {
this.actor.border_color = WELL_MENU_BORDER_COLOR;
} else {
this.actor.border_color = TRANSPARENT_COLOR;
}
},
_onHoverChanged: function() {
let hover = this.actor.hover;
}, },
_onActivate: function() { _onActivate: function() {

View File

@ -15,7 +15,17 @@ GLOW_COLOR.from_pixel(0x4f6ba4ff);
const GLOW_PADDING_HORIZONTAL = 3; const GLOW_PADDING_HORIZONTAL = 3;
const GLOW_PADDING_VERTICAL = 3; const GLOW_PADDING_VERTICAL = 3;
const APP_ICON_SIZE = 48; const APPICON_ICON_SIZE = 48;
const APPICON_PADDING = 1;
const APPICON_BORDER_WIDTH = 1;
const APPICON_CORNER_RADIUS = 4;
const APPICON_BORDER_COLOR = new Clutter.Color();
APPICON_BORDER_COLOR.from_pixel(0x787878ff);
const TRANSPARENT_COLOR = new Clutter.Color();
TRANSPARENT_COLOR.from_pixel(0x00000000);
function AppIcon(appInfo) { function AppIcon(appInfo) {
this._init(appInfo); this._init(appInfo);
@ -30,17 +40,19 @@ AppIcon.prototype = {
} }
this._resortWindows(); this._resortWindows();
this.actor = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL, this.actor = new Shell.ButtonBox({ orientation: Big.BoxOrientation.VERTICAL,
corner_radius: 2, border: APPICON_BORDER_WIDTH,
padding: 1, corner_radius: APPICON_CORNER_RADIUS,
padding: APPICON_PADDING,
reactive: true }); reactive: true });
this.actor._delegate = this;
let iconBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL, let iconBox = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
x_align: Big.BoxAlignment.CENTER, x_align: Big.BoxAlignment.CENTER,
y_align: Big.BoxAlignment.CENTER, y_align: Big.BoxAlignment.CENTER,
width: APP_ICON_SIZE, width: APPICON_ICON_SIZE,
height: APP_ICON_SIZE }); height: APPICON_ICON_SIZE });
this.icon = appInfo.create_icon_texture(APP_ICON_SIZE); this.icon = appInfo.create_icon_texture(APPICON_ICON_SIZE);
iconBox.append(this.icon, Big.BoxPackFlags.NONE); iconBox.append(this.icon, Big.BoxPackFlags.NONE);
this.actor.append(iconBox, Big.BoxPackFlags.EXPAND); this.actor.append(iconBox, Big.BoxPackFlags.EXPAND);
@ -123,11 +135,18 @@ AppIcon.prototype = {
}); });
}, },
getDragActor: function() { // AppIcon itself is not a draggable, but if you want to make
return this.appInfo.create_icon_texture(APP_ICON_SIZE); // a subclass of it draggable, you can use this method to create
// a drag actor
createDragActor: function() {
return this.appInfo.create_icon_texture(APPICON_ICON_SIZE);
}, },
getDragActorSource: function() { setHighlight: function(highlight) {
return this.icon; if (highlight) {
this.actor.border_color = APPICON_BORDER_COLOR;
} else {
this.actor.border_color = TRANSPARENT_COLOR;
}
} }
}; };