Add "New Window" menu item
Refactor the current menu code to support both window selection and "normal" menu items. Add a "New Window" item which does what you'd expect. Clean up the way we handle highlighting the window items to be more direct; rather than looping over all items in most cases, just directly manipulate one item https://bugzilla.gnome.org/show_bug.cgi?id=594557
This commit is contained in:
parent
471006ba67
commit
2c0661d377
@ -503,10 +503,10 @@ WellMenu.prototype = {
|
|||||||
padding: 4,
|
padding: 4,
|
||||||
corner_radius: WELL_MENU_CORNER_RADIUS,
|
corner_radius: WELL_MENU_CORNER_RADIUS,
|
||||||
width: Main.overview._dash.actor.width * 0.75 });
|
width: Main.overview._dash.actor.width * 0.75 });
|
||||||
this._windowContainer.connect('unselected', Lang.bind(this, this._onWindowUnselected));
|
this._windowContainer.connect('unselected', Lang.bind(this, this._onItemUnselected));
|
||||||
this._windowContainer.connect('selected', Lang.bind(this, this._onWindowSelected));
|
this._windowContainer.connect('selected', Lang.bind(this, this._onItemSelected));
|
||||||
this._windowContainer.connect('cancelled', Lang.bind(this, this._onWindowSelectionCancelled));
|
this._windowContainer.connect('cancelled', Lang.bind(this, this._onWindowSelectionCancelled));
|
||||||
this._windowContainer.connect('activate', Lang.bind(this, this._onWindowActivate));
|
this._windowContainer.connect('activate', Lang.bind(this, this._onItemActivate));
|
||||||
this.actor.add_actor(this._windowContainer);
|
this.actor.add_actor(this._windowContainer);
|
||||||
|
|
||||||
// Stay popped up on release over application icon
|
// Stay popped up on release over application icon
|
||||||
@ -595,19 +595,24 @@ WellMenu.prototype = {
|
|||||||
|
|
||||||
this._appendWindows(currentWorkspaceWindows, iconsDiffer);
|
this._appendWindows(currentWorkspaceWindows, iconsDiffer);
|
||||||
if (currentWorkspaceWindows.length > 0 && otherWorkspaceWindows.length > 0) {
|
if (currentWorkspaceWindows.length > 0 && otherWorkspaceWindows.length > 0) {
|
||||||
|
this._appendSeparator();
|
||||||
|
}
|
||||||
|
this._appendWindows(otherWorkspaceWindows, iconsDiffer);
|
||||||
|
|
||||||
|
this._appendSeparator();
|
||||||
|
|
||||||
|
this._newWindowMenuItem = this._appendMenuItem(null, _("New Window"));
|
||||||
|
},
|
||||||
|
|
||||||
|
_appendSeparator: function () {
|
||||||
let box = new Big.Box({ padding_top: 2, padding_bottom: 2 });
|
let box = new Big.Box({ padding_top: 2, padding_bottom: 2 });
|
||||||
box.append(new Clutter.Rectangle({ height: 1,
|
box.append(new Clutter.Rectangle({ height: 1,
|
||||||
color: WELL_MENU_SEPARATOR_COLOR }),
|
color: WELL_MENU_SEPARATOR_COLOR }),
|
||||||
Big.BoxPackFlags.EXPAND);
|
Big.BoxPackFlags.EXPAND);
|
||||||
this._windowContainer.append_separator(box, Big.BoxPackFlags.NONE);
|
this._windowContainer.append_separator(box, Big.BoxPackFlags.NONE);
|
||||||
}
|
|
||||||
this._appendWindows(otherWorkspaceWindows, iconsDiffer);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_appendWindows: function (windows, iconsDiffer) {
|
_appendMenuItem: function(iconTexture, labelText) {
|
||||||
for (let i = 0; i < windows.length; i++) {
|
|
||||||
let metaWindow = windows[i];
|
|
||||||
|
|
||||||
/* Use padding here rather than spacing in the box above so that
|
/* Use padding here rather than spacing in the box above so that
|
||||||
* we have a larger reactive area.
|
* we have a larger reactive area.
|
||||||
*/
|
*/
|
||||||
@ -616,22 +621,33 @@ WellMenu.prototype = {
|
|||||||
padding_bottom: 4,
|
padding_bottom: 4,
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
reactive: true });
|
reactive: true });
|
||||||
box._window = metaWindow;
|
|
||||||
let vCenter;
|
let vCenter;
|
||||||
if (iconsDiffer) {
|
if (iconTexture != null) {
|
||||||
vCenter = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
vCenter = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
||||||
let icon = Shell.TextureCache.get_default().bind_pixbuf_property(metaWindow, "mini-icon");
|
vCenter.append(iconTexture, Big.BoxPackFlags.NONE);
|
||||||
vCenter.append(icon, Big.BoxPackFlags.NONE);
|
|
||||||
box.append(vCenter, Big.BoxPackFlags.NONE);
|
box.append(vCenter, Big.BoxPackFlags.NONE);
|
||||||
}
|
}
|
||||||
vCenter = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
vCenter = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
||||||
let label = new Clutter.Text({ text: metaWindow.title,
|
let label = new Clutter.Text({ text: labelText,
|
||||||
font_name: WELL_MENU_FONT,
|
font_name: WELL_MENU_FONT,
|
||||||
ellipsize: Pango.EllipsizeMode.END,
|
ellipsize: Pango.EllipsizeMode.END,
|
||||||
color: WELL_MENU_COLOR });
|
color: WELL_MENU_COLOR });
|
||||||
vCenter.append(label, Big.BoxPackFlags.NONE);
|
vCenter.append(label, Big.BoxPackFlags.NONE);
|
||||||
box.append(vCenter, Big.BoxPackFlags.NONE);
|
box.append(vCenter, Big.BoxPackFlags.NONE);
|
||||||
this._windowContainer.append(box, Big.BoxPackFlags.NONE);
|
this._windowContainer.append(box, Big.BoxPackFlags.NONE);
|
||||||
|
return box;
|
||||||
|
},
|
||||||
|
|
||||||
|
_appendWindows: function (windows, iconsDiffer) {
|
||||||
|
for (let i = 0; i < windows.length; i++) {
|
||||||
|
let metaWindow = windows[i];
|
||||||
|
|
||||||
|
let icon = null;
|
||||||
|
if (iconsDiffer) {
|
||||||
|
icon = Shell.TextureCache.get_default().bind_pixbuf_property(metaWindow, "mini-icon");
|
||||||
|
}
|
||||||
|
let box = this._appendMenuItem(icon, metaWindow.title);
|
||||||
|
box._window = metaWindow;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -667,25 +683,24 @@ WellMenu.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setHighlightWindow: function (metaWindow) {
|
_lookupMenuItemForWindow: function (metaWindow) {
|
||||||
let children = this._windowContainer.get_children();
|
let children = this._windowContainer.get_children();
|
||||||
for (let i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
let child = children[i];
|
let child = children[i];
|
||||||
let menuMetaWindow = child._window;
|
let menuMetaWindow = child._window;
|
||||||
if (metaWindow != null && menuMetaWindow == metaWindow) {
|
if (menuMetaWindow == metaWindow)
|
||||||
child.background_color = WELL_MENU_SELECTED_COLOR;
|
return child;
|
||||||
} else {
|
|
||||||
child.background_color = TRANSPARENT_COLOR;
|
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
this.emit('highlight-window', metaWindow);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called while menu has a pointer grab
|
// Called while menu has a pointer grab
|
||||||
_onMenuEnter: function (actor, event) {
|
_onMenuEnter: function (actor, event) {
|
||||||
let clone = this._findWindowCloneForActor(event.get_source());
|
let clone = this._findWindowCloneForActor(event.get_source());
|
||||||
if (clone) {
|
if (clone) {
|
||||||
this._setHighlightWindow(clone.metaWindow);
|
let menu = this._lookupMenuItemForWindow(clone.metaWindow);
|
||||||
|
menu.background_color = WELL_MENU_SELECTED_COLOR;
|
||||||
|
this.emit('highlight-window', clone.metaWindow);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -693,22 +708,35 @@ WellMenu.prototype = {
|
|||||||
_onMenuLeave: function (actor, event) {
|
_onMenuLeave: function (actor, event) {
|
||||||
let clone = this._findWindowCloneForActor(event.get_source());
|
let clone = this._findWindowCloneForActor(event.get_source());
|
||||||
if (clone) {
|
if (clone) {
|
||||||
this._setHighlightWindow(null);
|
let menu = this._lookupMenuItemForWindow(clone.metaWindow);
|
||||||
|
menu.background_color = TRANSPARENT_COLOR;
|
||||||
|
this.emit('highlight-window', null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_onWindowUnselected: function (actor, child) {
|
_onItemUnselected: function (actor, child) {
|
||||||
this._setHighlightWindow(null);
|
child.background_color = TRANSPARENT_COLOR;
|
||||||
|
if (child._window) {
|
||||||
|
this.emit('highlight-window', null);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_onWindowSelected: function (actor, child) {
|
_onItemSelected: function (actor, child) {
|
||||||
this._setHighlightWindow(child._window);
|
child.background_color = WELL_MENU_SELECTED_COLOR;
|
||||||
|
if (child._window) {
|
||||||
|
this.emit('highlight-window', child._window);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_onWindowActivate: function (actor, child) {
|
_onItemActivate: function (actor, child) {
|
||||||
|
if (child._window) {
|
||||||
let metaWindow = child._window;
|
let metaWindow = child._window;
|
||||||
this.didActivateWindow = true;
|
this.didActivateWindow = true;
|
||||||
Main.overview.activateWindow(metaWindow, Clutter.get_current_event_time());
|
Main.overview.activateWindow(metaWindow, Clutter.get_current_event_time());
|
||||||
|
} else if (child == this._newWindowMenuItem) {
|
||||||
|
this._source.appInfo.launch();
|
||||||
|
Main.overview.hide();
|
||||||
|
}
|
||||||
this.emit('popup', false);
|
this.emit('popup', false);
|
||||||
this.actor.hide();
|
this.actor.hide();
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user