[AppIcon] redo constructor to take a params object, add "size" param
Add a "size" parameter to allow changing the AppIcon size, and then simplify the constructor by taking an object with parameters like gobject-introspection constructors do, rather than taking a large number of miscellaneous arguments. https://bugzilla.gnome.org/show_bug.cgi?id=597498
This commit is contained in:
parent
e5efecd2bd
commit
45dd342cc0
@ -109,7 +109,8 @@ AltTabPopup.prototype = {
|
|||||||
let workspaceIcons = [];
|
let workspaceIcons = [];
|
||||||
let otherIcons = [];
|
let otherIcons = [];
|
||||||
for (let i = 0; i < apps.length; i++) {
|
for (let i = 0; i < apps.length; i++) {
|
||||||
let appIcon = new AppIcon.AppIcon(apps[i], AppIcon.MenuType.BELOW, false);
|
let appIcon = new AppIcon.AppIcon({ appInfo: apps[i],
|
||||||
|
menuType: AppIcon.MenuType.BELOW });
|
||||||
if (this._hasWindowsOnWorkspace(appIcon, activeWorkspace))
|
if (this._hasWindowsOnWorkspace(appIcon, activeWorkspace))
|
||||||
workspaceIcons.push(appIcon);
|
workspaceIcons.push(appIcon);
|
||||||
else
|
else
|
||||||
|
@ -452,7 +452,9 @@ BaseWellItem.prototype = {
|
|||||||
__proto__: AppIcon.AppIcon.prototype,
|
__proto__: AppIcon.AppIcon.prototype,
|
||||||
|
|
||||||
_init: function(appInfo, isFavorite) {
|
_init: function(appInfo, isFavorite) {
|
||||||
AppIcon.AppIcon.prototype._init.call(this, appInfo, AppIcon.MenuType.ON_RIGHT, true);
|
AppIcon.AppIcon.prototype._init.call(this, { appInfo: appInfo,
|
||||||
|
menuType: AppIcon.MenuType.ON_RIGHT,
|
||||||
|
glow: true });
|
||||||
|
|
||||||
this.isFavorite = isFavorite;
|
this.isFavorite = isFavorite;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ 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 APPICON_ICON_SIZE = 48;
|
const APPICON_DEFAULT_ICON_SIZE = 48;
|
||||||
|
|
||||||
const APPICON_PADDING = 1;
|
const APPICON_PADDING = 1;
|
||||||
const APPICON_BORDER_WIDTH = 1;
|
const APPICON_BORDER_WIDTH = 1;
|
||||||
@ -49,14 +49,19 @@ TRANSPARENT_COLOR.from_pixel(0x00000000);
|
|||||||
|
|
||||||
const MenuType = { NONE: 0, ON_RIGHT: 1, BELOW: 2 };
|
const MenuType = { NONE: 0, ON_RIGHT: 1, BELOW: 2 };
|
||||||
|
|
||||||
function AppIcon(appInfo, menuType) {
|
function AppIcon(params) {
|
||||||
this._init(appInfo, menuType || MenuType.NONE);
|
this._init(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppIcon.prototype = {
|
AppIcon.prototype = {
|
||||||
_init : function(appInfo, menuType, showGlow) {
|
_init : function(params) {
|
||||||
this.appInfo = appInfo;
|
this.appInfo = params.appInfo;
|
||||||
this._menuType = menuType;
|
if (!this.appInfo)
|
||||||
|
throw new Error('AppIcon constructor requires "appInfo" param');
|
||||||
|
|
||||||
|
this._menuType = ('menuType' in params) ? params.menuType : MenuType.NONE;
|
||||||
|
this._iconSize = ('size' in params) ? params.size : APPICON_DEFAULT_ICON_SIZE;
|
||||||
|
let showGlow = ('glow' in params) ? params.glow : false;
|
||||||
|
|
||||||
this.actor = new Shell.ButtonBox({ orientation: Big.BoxOrientation.VERTICAL,
|
this.actor = new Shell.ButtonBox({ orientation: Big.BoxOrientation.VERTICAL,
|
||||||
border: APPICON_BORDER_WIDTH,
|
border: APPICON_BORDER_WIDTH,
|
||||||
@ -66,13 +71,13 @@ AppIcon.prototype = {
|
|||||||
this.actor._delegate = this;
|
this.actor._delegate = this;
|
||||||
this.highlight_border_color = APPICON_DEFAULT_BORDER_COLOR;
|
this.highlight_border_color = APPICON_DEFAULT_BORDER_COLOR;
|
||||||
|
|
||||||
this.windows = Shell.AppMonitor.get_default().get_windows_for_app(appInfo.get_id());
|
this.windows = Shell.AppMonitor.get_default().get_windows_for_app(this.appInfo.get_id());
|
||||||
for (let i = 0; i < this.windows.length; i++) {
|
for (let i = 0; i < this.windows.length; i++) {
|
||||||
this.windows[i].connect('notify::user-time', Lang.bind(this, this._resortWindows));
|
this.windows[i].connect('notify::user-time', Lang.bind(this, this._resortWindows));
|
||||||
}
|
}
|
||||||
this._resortWindows();
|
this._resortWindows();
|
||||||
|
|
||||||
if (menuType != MenuType.NONE) {
|
if (this._menuType != MenuType.NONE) {
|
||||||
this.actor.connect('button-press-event', Lang.bind(this, this._updateMenuOnButtonPress));
|
this.actor.connect('button-press-event', Lang.bind(this, this._updateMenuOnButtonPress));
|
||||||
this.actor.connect('notify::hover', Lang.bind(this, this._updateMenuOnHoverChanged));
|
this.actor.connect('notify::hover', Lang.bind(this, this._updateMenuOnHoverChanged));
|
||||||
this.actor.connect('activate', Lang.bind(this, this._updateMenuOnActivate));
|
this.actor.connect('activate', Lang.bind(this, this._updateMenuOnActivate));
|
||||||
@ -84,9 +89,9 @@ AppIcon.prototype = {
|
|||||||
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: APPICON_ICON_SIZE,
|
width: this._iconSize,
|
||||||
height: APPICON_ICON_SIZE });
|
height: this._iconSize });
|
||||||
this.icon = appInfo.create_icon_texture(APPICON_ICON_SIZE);
|
this.icon = this.appInfo.create_icon_texture(this._iconSize);
|
||||||
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);
|
||||||
@ -101,7 +106,7 @@ AppIcon.prototype = {
|
|||||||
font_name: "Sans 12px",
|
font_name: "Sans 12px",
|
||||||
line_alignment: Pango.Alignment.CENTER,
|
line_alignment: Pango.Alignment.CENTER,
|
||||||
ellipsize: Pango.EllipsizeMode.END,
|
ellipsize: Pango.EllipsizeMode.END,
|
||||||
text: appInfo.get_name() });
|
text: this.appInfo.get_name() });
|
||||||
nameBox.add_actor(this._name);
|
nameBox.add_actor(this._name);
|
||||||
if (showGlow) {
|
if (showGlow) {
|
||||||
this._glowBox = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL });
|
this._glowBox = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL });
|
||||||
@ -189,7 +194,7 @@ AppIcon.prototype = {
|
|||||||
// a subclass of it draggable, you can use this method to create
|
// a subclass of it draggable, you can use this method to create
|
||||||
// a drag actor
|
// a drag actor
|
||||||
createDragActor: function() {
|
createDragActor: function() {
|
||||||
return this.appInfo.create_icon_texture(APPICON_ICON_SIZE);
|
return this.appInfo.create_icon_texture(this._iconSize);
|
||||||
},
|
},
|
||||||
|
|
||||||
setHighlight: function(highlight) {
|
setHighlight: function(highlight) {
|
||||||
|
Loading…
Reference in New Issue
Block a user