1 |
|
2 |
|
3 |
|
4 |
|
5 | import * as Common from '../../core/common/common.js';
|
6 | import * as i18n from '../../core/i18n/i18n.js';
|
7 | import * as Platform from '../../core/platform/platform.js';
|
8 | import * as Components from '../../ui/legacy/components/utils/utils.js';
|
9 | import * as UI from '../../ui/legacy/legacy.js';
|
10 | import * as Workspace from '../workspace/workspace.js';
|
11 |
|
12 | import {FileSystemWorkspaceBinding} from './FileSystemWorkspaceBinding.js';
|
13 | import {NetworkPersistenceManager} from './NetworkPersistenceManager.js';
|
14 |
|
15 | import type {PersistenceBinding} from './PersistenceImpl.js';
|
16 | import {Events, PersistenceImpl} from './PersistenceImpl.js';
|
17 |
|
18 | const UIStrings = {
|
19 | |
20 |
|
21 |
|
22 |
|
23 | linkedToSourceMapS: 'Linked to source map: {PH1}',
|
24 | |
25 |
|
26 |
|
27 |
|
28 | linkedToS: 'Linked to {PH1}',
|
29 | };
|
30 | const str_ = i18n.i18n.registerUIStrings('models/persistence/PersistenceUtils.ts', UIStrings);
|
31 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
|
32 | export class PersistenceUtils {
|
33 | static tooltipForUISourceCode(uiSourceCode: Workspace.UISourceCode.UISourceCode): string {
|
34 | const binding = PersistenceImpl.instance().binding(uiSourceCode);
|
35 | if (!binding) {
|
36 | return '';
|
37 | }
|
38 | if (uiSourceCode === binding.network) {
|
39 | return FileSystemWorkspaceBinding.tooltipForUISourceCode(binding.fileSystem);
|
40 | }
|
41 | if (binding.network.contentType().isFromSourceMap()) {
|
42 | return i18nString(
|
43 | UIStrings.linkedToSourceMapS, {PH1: Platform.StringUtilities.trimMiddle(binding.network.url(), 150)});
|
44 | }
|
45 | return i18nString(UIStrings.linkedToS, {PH1: Platform.StringUtilities.trimMiddle(binding.network.url(), 150)});
|
46 | }
|
47 |
|
48 | static iconForUISourceCode(uiSourceCode: Workspace.UISourceCode.UISourceCode): UI.Icon.Icon|null {
|
49 | const binding = PersistenceImpl.instance().binding(uiSourceCode);
|
50 | if (binding) {
|
51 | if (!binding.fileSystem.url().startsWith('file://')) {
|
52 | return null;
|
53 | }
|
54 | const icon = UI.Icon.Icon.create('mediumicon-file-sync');
|
55 | UI.Tooltip.Tooltip.install(icon, PersistenceUtils.tooltipForUISourceCode(binding.network));
|
56 |
|
57 | if (NetworkPersistenceManager.instance().project() === binding.fileSystem.project()) {
|
58 | icon.style.filter = 'hue-rotate(160deg)';
|
59 | }
|
60 | return icon;
|
61 | }
|
62 | if (uiSourceCode.project().type() !== Workspace.Workspace.projectTypes.FileSystem ||
|
63 | !uiSourceCode.url().startsWith('file://')) {
|
64 | return null;
|
65 | }
|
66 |
|
67 | const icon = UI.Icon.Icon.create('mediumicon-file');
|
68 | UI.Tooltip.Tooltip.install(icon, PersistenceUtils.tooltipForUISourceCode(uiSourceCode));
|
69 | return icon;
|
70 | }
|
71 | }
|
72 |
|
73 | export class LinkDecorator extends Common.ObjectWrapper.ObjectWrapper<Components.Linkifier.LinkDecorator.EventTypes>
|
74 | implements Components.Linkifier.LinkDecorator {
|
75 | constructor(persistence: PersistenceImpl) {
|
76 | super();
|
77 | persistence.addEventListener(Events.BindingCreated, this.bindingChanged, this);
|
78 | persistence.addEventListener(Events.BindingRemoved, this.bindingChanged, this);
|
79 | }
|
80 |
|
81 | private bindingChanged(event: Common.EventTarget.EventTargetEvent<PersistenceBinding>): void {
|
82 | const binding = event.data;
|
83 | this.dispatchEventToListeners(Components.Linkifier.LinkDecorator.Events.LinkIconChanged, binding.network);
|
84 | }
|
85 |
|
86 | linkIcon(uiSourceCode: Workspace.UISourceCode.UISourceCode): UI.Icon.Icon|null {
|
87 | return PersistenceUtils.iconForUISourceCode(uiSourceCode);
|
88 | }
|
89 | }
|