mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 17:27:22 +08:00
This reverts commit9e5ab71e50. Reason for revert: The Cl was reverted due to devtools pak file limitation. That issue has been fixed in https://chromium-review.googlesource.com/c/chromium/src/+/2558341 Original change's description: > Revert "[Loc] Migrate changes tool to localization V2" > > This reverts commitabcb8f7aa8. > > Reason for revert: Consistently causing autoroll issues when rolling devtools-frontend into Chromium - see https://chromium-review.googlesource.com/c/chromium/src/+/2554521 for an example. > > To recreate this, do a debug build of Chromium with this patch applied to DevTools. It's causing an issue with duplicate keys in the pak files. No DevTools Frontend builds do a debug build of Chromium with the DevTools frontend patch applied so our CQ will be green despite causing an issue. > > You can run this locally in Chromium to reproduce via: > > autoninja -C out/Default chrome:packed_resources_extra > > Which will show the error. > > Original change's description: > > [Loc] Migrate changes tool to localization V2 > > > > Migrate changes tool > > Tested with en-XL: https://imgur.com/a/hFDBjQV > > > > > > Bug: 1136655 > > Change-Id: Ic434c3085b9e2f2cf44583cca7ee1ce8f1d412f2 > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2548688 > > Commit-Queue: Christy Chen <chrche@microsoft.com> > > Reviewed-by: Simon Zünd <szuend@chromium.org> > > TBR=szuend@chromium.org,chrche@microsoft.com > > Change-Id: I94b27434562f6a6bff3be381ab8a5802bd8b03f9 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: 1136655 > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2557044 > Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> > Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> TBR=szuend@chromium.org,chrche@microsoft.com,jacktfranklin@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: 1136655 Change-Id: I35166a6f4f38462073b933c01c169b3c8d14311b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2567344 Reviewed-by: Simon Zünd <szuend@chromium.org> Reviewed-by: Christy Chen <chrche@microsoft.com> Commit-Queue: Christy Chen <chrche@microsoft.com>
169 lines
5.7 KiB
JavaScript
169 lines
5.7 KiB
JavaScript
// Copyright 2017 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 '../common/common.js';
|
|
import * as i18n from '../i18n/i18n.js';
|
|
import * as Snippets from '../snippets/snippets.js';
|
|
import * as UI from '../ui/ui.js';
|
|
import * as Workspace from '../workspace/workspace.js';
|
|
import * as WorkspaceDiff from '../workspace_diff/workspace_diff.js';
|
|
|
|
export const UIStrings = {
|
|
/**
|
|
*@description Name of an item from source map
|
|
*@example {compile.html} PH1
|
|
*/
|
|
sFromSourceMap: '{PH1} (from source map)',
|
|
};
|
|
const str_ = i18n.i18n.registerUIStrings('changes/ChangesSidebar.js', UIStrings);
|
|
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
|
|
|
|
export class ChangesSidebar extends UI.Widget.Widget {
|
|
/**
|
|
* @param {!WorkspaceDiff.WorkspaceDiff.WorkspaceDiffImpl} workspaceDiff
|
|
*/
|
|
constructor(workspaceDiff) {
|
|
super();
|
|
this._treeoutline = new UI.TreeOutline.TreeOutlineInShadow();
|
|
this._treeoutline.setFocusable(false);
|
|
this._treeoutline.registerRequiredCSS('changes/changesSidebar.css', {enableLegacyPatching: true});
|
|
this._treeoutline.setComparator((a, b) => a.titleAsText().compareTo(b.titleAsText()));
|
|
this._treeoutline.addEventListener(UI.TreeOutline.Events.ElementSelected, this._selectionChanged, this);
|
|
UI.ARIAUtils.markAsTablist(this._treeoutline.contentElement);
|
|
|
|
this.element.appendChild(this._treeoutline.element);
|
|
|
|
/** @type {!Map<!Workspace.UISourceCode.UISourceCode, !UISourceCodeTreeElement>} */
|
|
this._treeElements = new Map();
|
|
this._workspaceDiff = workspaceDiff;
|
|
this._workspaceDiff.modifiedUISourceCodes().forEach(this._addUISourceCode.bind(this));
|
|
this._workspaceDiff.addEventListener(
|
|
WorkspaceDiff.WorkspaceDiff.Events.ModifiedStatusChanged, this._uiSourceCodeMofiedStatusChanged, this);
|
|
}
|
|
|
|
/**
|
|
* @param {!Workspace.UISourceCode.UISourceCode} uiSourceCode
|
|
* @param {boolean=} omitFocus
|
|
*/
|
|
selectUISourceCode(uiSourceCode, omitFocus) {
|
|
const treeElement = this._treeElements.get(uiSourceCode);
|
|
if (!treeElement) {
|
|
return;
|
|
}
|
|
treeElement.select(omitFocus);
|
|
}
|
|
|
|
/**
|
|
* @return {?Workspace.UISourceCode.UISourceCode}
|
|
*/
|
|
selectedUISourceCode() {
|
|
// @ts-ignore uiSourceCode seems to be dynamically attached.
|
|
return this._treeoutline.selectedTreeElement ? this._treeoutline.selectedTreeElement.uiSourceCode : null;
|
|
}
|
|
|
|
_selectionChanged() {
|
|
this.dispatchEventToListeners(Events.SelectedUISourceCodeChanged);
|
|
}
|
|
|
|
/**
|
|
* @param {!Common.EventTarget.EventTargetEvent} event
|
|
*/
|
|
_uiSourceCodeMofiedStatusChanged(event) {
|
|
if (event.data.isModified) {
|
|
this._addUISourceCode(event.data.uiSourceCode);
|
|
} else {
|
|
this._removeUISourceCode(event.data.uiSourceCode);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {!Workspace.UISourceCode.UISourceCode} uiSourceCode
|
|
*/
|
|
_removeUISourceCode(uiSourceCode) {
|
|
const treeElement = this._treeElements.get(uiSourceCode);
|
|
this._treeElements.delete(uiSourceCode);
|
|
if (this._treeoutline.selectedTreeElement === treeElement) {
|
|
const nextElementToSelect = treeElement.previousSibling || treeElement.nextSibling;
|
|
if (nextElementToSelect) {
|
|
nextElementToSelect.select(true);
|
|
} else {
|
|
treeElement.deselect();
|
|
this._selectionChanged();
|
|
}
|
|
}
|
|
if (treeElement) {
|
|
this._treeoutline.removeChild(treeElement);
|
|
treeElement.dispose();
|
|
}
|
|
if (this._treeoutline.rootElement().childCount() === 0) {
|
|
this._treeoutline.setFocusable(false);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {!Workspace.UISourceCode.UISourceCode} uiSourceCode
|
|
*/
|
|
_addUISourceCode(uiSourceCode) {
|
|
const treeElement = new UISourceCodeTreeElement(uiSourceCode);
|
|
this._treeElements.set(uiSourceCode, treeElement);
|
|
this._treeoutline.setFocusable(true);
|
|
this._treeoutline.appendChild(treeElement);
|
|
if (!this._treeoutline.selectedTreeElement) {
|
|
treeElement.select(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @enum {symbol}
|
|
*/
|
|
export const Events = {
|
|
SelectedUISourceCodeChanged: Symbol('SelectedUISourceCodeChanged')
|
|
};
|
|
|
|
export class UISourceCodeTreeElement extends UI.TreeOutline.TreeElement {
|
|
/**
|
|
* @param {!Workspace.UISourceCode.UISourceCode} uiSourceCode
|
|
*/
|
|
constructor(uiSourceCode) {
|
|
super();
|
|
this.uiSourceCode = uiSourceCode;
|
|
this.listItemElement.classList.add('navigator-' + uiSourceCode.contentType().name() + '-tree-item');
|
|
UI.ARIAUtils.markAsTab(this.listItemElement);
|
|
|
|
let iconType = 'largeicon-navigator-file';
|
|
if (Snippets.ScriptSnippetFileSystem.isSnippetsUISourceCode(this.uiSourceCode)) {
|
|
iconType = 'largeicon-navigator-snippet';
|
|
}
|
|
const defaultIcon = UI.Icon.Icon.create(iconType, 'icon');
|
|
this.setLeadingIcons([defaultIcon]);
|
|
|
|
this._eventListeners = [
|
|
uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged, this._updateTitle, this),
|
|
uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyChanged, this._updateTitle, this),
|
|
uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCommitted, this._updateTitle, this)
|
|
];
|
|
|
|
this._updateTitle();
|
|
}
|
|
|
|
_updateTitle() {
|
|
let titleText = this.uiSourceCode.displayName();
|
|
if (this.uiSourceCode.isDirty()) {
|
|
titleText = '*' + titleText;
|
|
}
|
|
this.title = titleText;
|
|
|
|
let tooltip = this.uiSourceCode.url();
|
|
if (this.uiSourceCode.contentType().isFromSourceMap()) {
|
|
tooltip = i18nString(UIStrings.sFromSourceMap, {PH1: this.uiSourceCode.displayName()});
|
|
}
|
|
this.tooltip = tooltip;
|
|
}
|
|
|
|
dispose() {
|
|
Common.EventTarget.EventTarget.removeEventListeners(this._eventListeners);
|
|
}
|
|
}
|