diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 39bf74778..fe5b43299 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -191,17 +191,22 @@ Signals.addSignalMethods(MenuItem.prototype); /* This class represents a display containing a collection of application items. * The applications are sorted based on their popularity by default, and based on * their name if some search filter is applied. + * + * showPrefs - a boolean indicating if this AppDisplay should contain preference + * applets, rather than applications */ -function AppDisplay() { - this._init(); +function AppDisplay(showPrefs) { + this._init(showPrefs); } AppDisplay.prototype = { __proto__: GenericDisplay.GenericDisplay.prototype, - _init : function() { + _init : function(showPrefs) { GenericDisplay.GenericDisplay.prototype._init.call(this); + this._showPrefs = showPrefs; + this._menus = []; this._menuDisplays = []; @@ -359,30 +364,32 @@ AppDisplay.prototype = { this._allItems = {}; this._appCategories = {}; - // Loop over the toplevel menu items, load the set of desktop file ids - // associated with each one, skipping empty menus - let allMenus = this._appSystem.get_menus(); - this._menus = []; - for (let i = 0; i < allMenus.length; i++) { - let menu = allMenus[i]; - let menuApps = this._appSystem.get_applications_for_menu(menu.id); - let hasVisibleApps = menuApps.some(function (app) { return !app.get_is_nodisplay(); }); - if (!hasVisibleApps) { - continue; - } - this._menus.push(menu); - for (let j = 0; j < menuApps.length; j++) { - let app = menuApps[j]; + if (this._showPrefs) { + // Get the desktop file ids for settings/preferences. + // These are used for search results, but not in the app menus. + let settings = this._appSystem.get_all_settings(); + for (let i = 0; i < settings.length; i++) { + let app = settings[i]; this._addApp(app); } - } - - // Now grab the desktop file ids for settings/preferences. - // These show up in search, but not with the rest of apps. - let settings = this._appSystem.get_all_settings(); - for (let i = 0; i < settings.length; i++) { - let app = settings[i]; - this._addApp(app); + } else { + // Loop over the toplevel menu items, load the set of desktop file ids + // associated with each one, skipping empty menus + let allMenus = this._appSystem.get_menus(); + this._menus = []; + for (let i = 0; i < allMenus.length; i++) { + let menu = allMenus[i]; + let menuApps = this._appSystem.get_applications_for_menu(menu.id); + let hasVisibleApps = menuApps.some(function (app) { return !app.get_is_nodisplay(); }); + if (!hasVisibleApps) { + continue; + } + this._menus.push(menu); + for (let j = 0; j < menuApps.length; j++) { + let app = menuApps[j]; + this._addApp(app); + } + } } this._appsStale = false; diff --git a/js/ui/dash.js b/js/ui/dash.js index 85a494a12..41feb7203 100644 --- a/js/ui/dash.js +++ b/js/ui/dash.js @@ -70,6 +70,10 @@ const PANE_BORDER_WIDTH = 2; const PANE_BACKGROUND_COLOR = new Clutter.Color(); PANE_BACKGROUND_COLOR.from_pixel(0x000000f4); +const APPS = "apps"; +const PREFS = "prefs"; +const DOCS = "docs"; + /* * Returns the index in an array of a given length that is obtained * if the provided index is incremented by an increment and the array @@ -83,6 +87,17 @@ function _getIndexWrapped(index, increment, length) { return (index + increment + length) % length; } +function _createDisplay(displayType) { + if (displayType == APPS) + return new AppDisplay.AppDisplay(); + else if (displayType == PREFS) + return new AppDisplay.AppDisplay(true); + else if (displayType == DOCS) + return new DocDisplay.DocDisplay(); + + return null; +} + function Pane() { this._init(); } @@ -158,12 +173,12 @@ Pane.prototype = { } Signals.addSignalMethods(Pane.prototype); -function ResultArea(displayClass, enableNavigation) { - this._init(displayClass, enableNavigation); +function ResultArea(displayType, enableNavigation) { + this._init(displayType, enableNavigation); } ResultArea.prototype = { - _init : function(displayClass, enableNavigation) { + _init : function(displayType, enableNavigation) { this.actor = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL }); this.resultsContainer = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL, spacing: DEFAULT_PADDING @@ -172,7 +187,7 @@ ResultArea.prototype = { this.navContainer = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL }); this.resultsContainer.append(this.navContainer, Big.BoxPackFlags.NONE); - this.display = new displayClass(); + this.display = _createDisplay(displayType); this.navArea = this.display.getNavigationArea(); if (enableNavigation && this.navArea) @@ -229,10 +244,10 @@ ResultPane.prototype = { this._dash = dash; }, - // Create an instance of displayClass and pack it into this pane's - // content area. Return the displayClass instance. - packResults: function(displayClass, enableNavigation) { - let resultArea = new ResultArea(displayClass, enableNavigation); + // Create a display of displayType and pack it into this pane's + // content area. Return the display. + packResults: function(displayType, enableNavigation) { + let resultArea = new ResultArea(displayType, enableNavigation); createPaneForDetails(this._dash, resultArea.display); @@ -726,7 +741,7 @@ Dash.prototype = { this._appsSection.header.moreLink.connect('activated', Lang.bind(this, function (link) { if (this._moreAppsPane == null) { this._moreAppsPane = new ResultPane(this); - this._moreAppsPane.packResults(AppDisplay.AppDisplay, true); + this._moreAppsPane.packResults(APPS, true); this._addPane(this._moreAppsPane); link.setPane(this._moreAppsPane); } @@ -754,7 +769,7 @@ Dash.prototype = { this._docsSection.header.moreLink.connect('activated', Lang.bind(this, function (link) { if (this._moreDocsPane == null) { this._moreDocsPane = new ResultPane(this); - this._moreDocsPane.packResults(DocDisplay.DocDisplay, true); + this._moreDocsPane.packResults(DOCS, true); this._addPane(this._moreDocsPane); link.setPane(this._moreDocsPane); } @@ -773,17 +788,20 @@ Dash.prototype = { })); this._searchSections = [ - { type: "apps", + { type: APPS, title: _("APPLICATIONS"), header: null, - resultArea: null, - displayClass: AppDisplay.AppDisplay + resultArea: null }, - { type: "docs", + { type: PREFS, + title: _("PREFERENCES"), + header: null, + resultArea: null + }, + { type: DOCS, title: _("RECENT DOCUMENTS"), header: null, - resultArea: null, - displayClass: DocDisplay.DocDisplay + resultArea: null } ]; @@ -795,7 +813,7 @@ Dash.prototype = { this._showSingleSearchSection(section.type); })); this._searchResultsSection.content.append(section.header.actor, Big.BoxPackFlags.NONE); - section.resultArea = new ResultArea(section.displayClass, false); + section.resultArea = new ResultArea(section.type, false); section.resultArea.controlBox.hide(); this._searchResultsSection.content.append(section.resultArea.actor, Big.BoxPackFlags.EXPAND); createPaneForDetails(this, section.resultArea.display);