@quick-game/cli
Version:
Command line interface for rapid qg development
91 lines • 4.41 kB
JavaScript
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Common from '../../core/common/common.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as Platform from '../../core/platform/platform.js';
import * as IconButton from '../../ui/components/icon_button/icon_button.js';
import * as Components from '../../ui/legacy/components/utils/utils.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as Workspace from '../workspace/workspace.js';
import { FileSystemWorkspaceBinding } from './FileSystemWorkspaceBinding.js';
import { HEADERS_FILENAME, NetworkPersistenceManager } from './NetworkPersistenceManager.js';
import { Events, PersistenceImpl } from './PersistenceImpl.js';
const UIStrings = {
/**
*@description Text in Persistence Utils of the Workspace settings in Settings
*@example {example.url} PH1
*/
linkedToSourceMapS: 'Linked to source map: {PH1}',
/**
*@description Text to show something is linked to another
*@example {example.url} PH1
*/
linkedToS: 'Linked to {PH1}',
};
const str_ = i18n.i18n.registerUIStrings('models/persistence/PersistenceUtils.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
export class PersistenceUtils {
static tooltipForUISourceCode(uiSourceCode) {
const binding = PersistenceImpl.instance().binding(uiSourceCode);
if (!binding) {
return '';
}
if (uiSourceCode === binding.network) {
return FileSystemWorkspaceBinding.tooltipForUISourceCode(binding.fileSystem);
}
if (binding.network.contentType().isFromSourceMap()) {
return i18nString(UIStrings.linkedToSourceMapS, { PH1: Platform.StringUtilities.trimMiddle(binding.network.url(), 150) });
}
return i18nString(UIStrings.linkedToS, { PH1: Platform.StringUtilities.trimMiddle(binding.network.url(), 150) });
}
static iconForUISourceCode(uiSourceCode) {
const binding = PersistenceImpl.instance().binding(uiSourceCode);
if (binding) {
if (!binding.fileSystem.url().startsWith('file://')) {
return null;
}
const icon = new IconButton.Icon.Icon();
icon.data = { iconName: 'document', color: 'var(--icon-default)', width: '16px', height: '16px' };
UI.Tooltip.Tooltip.install(icon, PersistenceUtils.tooltipForUISourceCode(binding.network));
if (NetworkPersistenceManager.instance().project() === binding.fileSystem.project()) {
icon.classList.add('dot', 'purple');
}
else {
icon.classList.add('dot', 'green');
}
return icon;
}
if (uiSourceCode.project().type() !== Workspace.Workspace.projectTypes.FileSystem ||
!uiSourceCode.url().startsWith('file://')) {
return null;
}
if (uiSourceCode.url().endsWith(HEADERS_FILENAME)) {
if (NetworkPersistenceManager.instance().hasMatchingNetworkUISourceCodeForHeaderOverridesFile(uiSourceCode)) {
const icon = new IconButton.Icon.Icon();
icon.data = { iconName: 'document', color: 'var(--icon-default)', width: '16px', height: '16px' };
icon.classList.add('dot', 'purple');
return icon;
}
}
const icon = new IconButton.Icon.Icon();
icon.data = { iconName: 'document', color: 'var(--icon-default)', width: '16px', height: '16px' };
UI.Tooltip.Tooltip.install(icon, PersistenceUtils.tooltipForUISourceCode(uiSourceCode));
return icon;
}
}
export class LinkDecorator extends Common.ObjectWrapper.ObjectWrapper {
constructor(persistence) {
super();
persistence.addEventListener(Events.BindingCreated, this.bindingChanged, this);
persistence.addEventListener(Events.BindingRemoved, this.bindingChanged, this);
}
bindingChanged(event) {
const binding = event.data;
this.dispatchEventToListeners(Components.Linkifier.LinkDecorator.Events.LinkIconChanged, binding.network);
}
linkIcon(uiSourceCode) {
return PersistenceUtils.iconForUISourceCode(uiSourceCode);
}
}
//# sourceMappingURL=PersistenceUtils.js.map