diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml index b20402d7c..2b62ee402 100644 --- a/js/js-resources.gresource.xml +++ b/js/js-resources.gresource.xml @@ -158,7 +158,6 @@ ui/realms/realmIndicator.js ui/realms/realmManager.js - ui/realms/realmSearchProvider.js ui/realms/realmSwitcher.js ui/realms/realmLabels.js ui/realms/realmWindowMenu.js diff --git a/js/ui/realms/realmSearchProvider.js b/js/ui/realms/realmSearchProvider.js deleted file mode 100644 index 70693f479..000000000 --- a/js/ui/realms/realmSearchProvider.js +++ /dev/null @@ -1,329 +0,0 @@ -import Clutter from 'gi://Clutter'; -import GObject from 'gi://GObject'; -import Pango from 'gi://Pango'; -import Shell from 'gi://Shell'; -import St from 'gi://St'; - -import * as Search from '../search.js'; -import * as Main from '../main.js'; -import * as Util from '../../misc/util.js'; - -// Based on ProviderInfo in search.js -const RealmProviderInfo = GObject.registerClass( -class RealmProviderInfo extends St.Button { - _init() { - super._init({ - style_class: 'search-provider-icon', - reactive: false, - can_focus: false, - accessible_name: "Realms", - track_hover: false, - y_align: Clutter.ActorAlign.START, - }); - - this._content = new St.BoxLayout({ - vertical: false, - style_class: 'list-search-provider-content' - }); - this.set_child(this._content); - - let icon = new St.Icon({ - icon_size: this.PROVIDER_ICON_SIZE, - icon_name: 'computer' - }); - - let detailsBox = new St.BoxLayout({ - style_class: 'list-search-provider-details', - vertical: true, - x_expand: true - }); - - let nameLabel = new St.Label({ - text: "Realms", - x_align: Clutter.ActorAlign.START - }); - - this._moreLabel = new St.Label({ x_align: Clutter.ActorAlign.START }); - - detailsBox.add_child(nameLabel); - detailsBox.add_child(this._moreLabel); - - - this._content.add_child(icon); - this._content.add_child(detailsBox); - } - - get PROVIDER_ICON_SIZE() { - return 48; - } - - setMoreCount(count) { - this._moreLabel.text = ngettext("%d more", "%d more", count).format(count); - this._moreLabel.visible = count > 0; - } -}); - -const MAX_LIST_SEARCH_RESULTS_ROWS = 10; - -// Based on ListSearchResult in search.js -const RealmSearchResult = GObject.registerClass( -class ListSearchResult extends Search.SearchResult { - _init(provider, metaInfo, resultsView) { - super._init(provider, metaInfo, resultsView); - - this.style_class = 'list-search-result'; - - let content = new St.BoxLayout({ - style_class: 'list-search-result-content', - vertical: false, - x_align: Clutter.ActorAlign.FILL, - x_expand: true, - y_expand: true, - }); - this.set_child(content); - - let titleBox = new St.BoxLayout({ - style_class: 'list-search-result-title', - y_align: Clutter.ActorAlign.CENTER, - }); - - content.add_child(titleBox); - - // An icon for, or thumbnail of, content - let icon = this.metaInfo['createIcon'](this.ICON_SIZE); - if (icon) - titleBox.add_icon(icon); - - let title = new St.Label({ - text: this.metaInfo['name'], - y_align: Clutter.ActorAlign.CENTER, - }); - titleBox.add_child(title); - - this.label_actor = title; - - if (this.metaInfo['description']) { - this._descriptionLabel = new St.Label({ - style_class: 'list-search-result-description', - x_expand: true, - x_align: Clutter.ActorAlign.START, - y_align: Clutter.ActorAlign.CENTER, - }); - this._descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE; - content.add_child(this._descriptionLabel); - - this._resultsView.connectObject( - 'terms-changed', this._highlightTerms.bind(this), this); - - this._highlightTerms(); - } - - this._createConfigButton(content); - } - - _createConfigButton(content) { - let id = this.metaInfo['id']; - - if (id != ':new:') { - this.configButton = new St.Button({ - style_class: 'button', - track_hover: true, - can_focus: true, - child: new St.Icon({ - style_class: 'realm-config-icon', - icon_name: 'emblem-system-symbolic', - icon_size: 24, - }), - }); - - this.configButton.connect('clicked', () => { - Main.overview.toggle(); - Util.spawn(['/usr/libexec/realm-config-ui', id]); - }); - - content.add_child(this.configButton); - } - } - - get ICON_SIZE() { - return 24; - } - - _highlightTerms() { - let markup = this._resultsView.highlightTerms(this.metaInfo['description'].split('\n')[0]); - this._descriptionLabel.clutter_text.set_markup(markup); - } -}); - -// Based on ListSearchResults in search.js -const RealmSearchResults = GObject.registerClass( -class RealmSearchResults extends Search.SearchResultsBase { - _init(provider, resultsView) { - super._init(provider, resultsView); - - this._container = new St.BoxLayout({ style_class: 'search-section-content' }); - this.providerInfo = new RealmProviderInfo(); - this.providerInfo.connect('key-focus-in', this._keyFocusIn.bind(this)); - this.providerInfo.connect('clicked', () => { - Main.overview.toggle(); - }); - - this._container.add_child(this.providerInfo); - - this._content = new St.BoxLayout({ - style_class: 'list-search-results', - vertical: true, - x_expand: true, - }); - this._container.add_child(this._content); - - this._resultDisplayBin.set_child(this._container); - } - - _setMoreCount(count) { - this.providerInfo.setMoreCount(count); - } - - _getMaxDisplayedResults() { - return MAX_LIST_SEARCH_RESULTS_ROWS; - } - - _clearResultDisplay() { - this._content.remove_all_children(); - } - - _createResultDisplay(meta) { - return super._createResultDisplay(meta) || - new RealmSearchResult(this.provider, meta, this._resultsView); - } - - _addItem(display) { - this._content.add_child(display); - } - - getFirstResult() { - if (this._content.get_n_children() > 0) - return this._content.get_child_at_index(0); - else - return null; - } -}); - -export const RealmSearchProvider = class RealmSearchProvider { - constructor() { - this._shellRealms = Shell.Realms.get_default(); - this.id = 'realms'; - this.isRemoteProvider = false; - this.canLaunchSearch = false; - this.display = null; - } - - createResultDisplay(resultsView) { - this.display = new RealmSearchResults(this, resultsView); - this.display.connect('notify::focus-child', resultsView._focusChildChanged.bind(resultsView)); - this.display.hide(); - resultsView._content.add_child(this.display); - } - - createIcon(size, realm) { - if (realm.is_running()) { - return new St.Icon({ icon_name: 'emblem-synchronizing', icon_size: size }); - } else { - return new St.Icon({ icon_name: 'exaile', icon_size: size }); - } - } - - createRealmMeta(realm) { - let id = realm.get_realm_name(); - let description = ''; - if (realm.is_running()) { - description = `Set realm-${id} as current realm`; - } else { - description = `Start realm-${id}`; - } - - return { - id: id, - name: `realm-${id}`, - description: description, - createIcon: size => { - return this.createIcon(size, realm); - }, - }; - } - - createNewRealmMeta() { - return { - id: ':new:', - name: 'New Realm', - description: 'Create a new realm', - createIcon: size => { - return new St.Icon({ - icon_name: 'computer', - icon_size: size, - }); - } - } - } - - getResultMetas (ids) { - let metas = []; - - for (let id of ids) { - if (id == ":new:") { - metas.push(this.createNewRealmMeta()); - } else { - let realm = this._shellRealms.realm_by_name(id); - if (realm && !realm.is_current()) { - metas.push(this.createRealmMeta(realm)); - } else { - log(`No realm found for ${id}`); - } - } - } - return new Promise(resolve => resolve(metas)); - } - - activateResult (resultId, _terms) { - - if (resultId == ':new:') { - Main.overview.toggle(); - Util.spawn(['/usr/libexec/realm-config-ui', '--new']); - return; - } - - let realm = this._shellRealms.realm_by_name(resultId); - if (realm) { - realm.set_current(); - } else { - log(`No realm found for ${resultId}`); - } - } - - filterResults(results, maxNumber) { - return results.slice(0, maxNumber) - } - - getInitialResultSet(terms, _cancellable) { - let realms = this._shellRealms.get_all_realms(); - let matches = []; - - if (terms.length == 1 && "new".startsWith(terms[0])) { - matches.push(":new:"); - } - - for (let realm of realms) { - if (!realm.is_current()) { - let name = realm.get_realm_name(); - if (terms.every(t => name.indexOf(t) != -1)) { - matches.push(name); - } - } - } - return new Promise(resolve => resolve(matches)); - } - - getSubsearchResultSet(previousResults, terms, cancellable) { - return this.getInitialResultSet(terms, cancellable); - } -} diff --git a/js/ui/search.js b/js/ui/search.js index 5cbd159e7..665dae490 100644 --- a/js/ui/search.js +++ b/js/ui/search.js @@ -149,7 +149,7 @@ class GridSearchResult extends SearchResult { } }); -export const SearchResultsBase = GObject.registerClass({ +const SearchResultsBase = GObject.registerClass({ GTypeFlags: GObject.TypeFlags.ABSTRACT, Properties: { 'focus-child': GObject.ParamSpec.object(