Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 9b65780

Browse files
darkwingjasonLaster
authored andcommitted
Provide a method to clear the root if no child sources are found (#5743)
1 parent c330eb3 commit 9b65780

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

assets/panel/debugger.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ projectTextSearch.noResults=No results found
235235
# does not have any sources.
236236
sources.noSourcesAvailable=This page has no sources
237237

238+
# LOCALIZATION NOTE (sources.noSourcesAvailableRoot): Text shown when the debugger
239+
# does not have any sources under a specific directory root.
240+
sources.noSourcesAvailableRoot=This directory root has no sources
241+
238242
# LOCALIZATION NOTE (sourceSearch.search.key2): Key shortcut to open the search
239243
# for searching within a the currently opened files in the editor
240244
# Do not localize "CmdOrCtrl+F", or change the format of the string. These are

src/components/PrimaryPanes/Sources.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@
226226
display: block;
227227
}
228228

229-
.sources-list-custom-root .sources-list {
229+
.sources-list-custom-root .sources-list,
230+
.sources-list-custom-root .no-sources-message {
230231
position: absolute;
231232
top: 26px;
232233
right: 0;

src/components/PrimaryPanes/SourcesTree.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ class SourcesTree extends Component<Props, State> {
311311
);
312312
};
313313

314+
renderEmptyElement(message) {
315+
return <div className="no-sources-message">{message}</div>;
316+
}
317+
314318
render() {
315319
const { expanded, projectRoot } = this.props;
316320
const {
@@ -329,14 +333,22 @@ class SourcesTree extends Component<Props, State> {
329333
this.props.setExpandedState(expandedState);
330334
};
331335

336+
const isEmpty = sourceTree.contents.length === 0;
337+
332338
const isCustomRoot = projectRoot !== "";
333339
let roots = () => sourceTree.contents;
334340

335341
let clearProjectRootButton = null;
336342

337343
// The "sourceTree.contents[0]" check ensures that there are contents
338344
// A custom root with no existing sources will be ignored
339-
if (isCustomRoot && sourceTree.contents[0]) {
345+
if (isCustomRoot) {
346+
let rootLabel = projectRoot.split("/").pop();
347+
if (sourceTree.contents[0]) {
348+
rootLabel = sourceTree.contents[0].name;
349+
roots = () => sourceTree.contents[0].contents;
350+
}
351+
340352
clearProjectRootButton = (
341353
<button
342354
className="sources-clear-root"
@@ -345,15 +357,15 @@ class SourcesTree extends Component<Props, State> {
345357
>
346358
<Svg name="home" />
347359
<Svg name="breadcrumb" class />
348-
<span className="sources-clear-root-label">
349-
{sourceTree.contents[0].name}
350-
</span>
360+
<span className="sources-clear-root-label">{rootLabel}</span>
351361
</button>
352362
);
353-
roots = () => sourceTree.contents[0].contents;
354363
}
355364

356-
const isEmpty = sourceTree.contents.length === 0;
365+
if (isEmpty && !isCustomRoot) {
366+
return this.renderEmptyElement(L10N.getStr("sources.noSourcesAvailable"));
367+
}
368+
357369
const treeProps = {
358370
autoExpandAll: false,
359371
autoExpandDepth: expanded ? 0 : 1,
@@ -374,14 +386,6 @@ class SourcesTree extends Component<Props, State> {
374386

375387
const tree = <ManagedTree {...treeProps} />;
376388

377-
if (isEmpty) {
378-
return (
379-
<div className="no-sources-message">
380-
{L10N.getStr("sources.noSourcesAvailable")}
381-
</div>
382-
);
383-
}
384-
385389
const onKeyDown = e => {
386390
if (e.keyCode === 13 && focusedItem) {
387391
this.selectItem(focusedItem);
@@ -399,9 +403,13 @@ class SourcesTree extends Component<Props, State> {
399403
{clearProjectRootButton}
400404
</div>
401405
) : null}
402-
<div className="sources-list" onKeyDown={onKeyDown}>
403-
{tree}
404-
</div>
406+
{isEmpty ? (
407+
this.renderEmptyElement(L10N.getStr("sources.noSourcesAvailableRoot"))
408+
) : (
409+
<div className="sources-list" onKeyDown={onKeyDown}>
410+
{tree}
411+
</div>
412+
)}
405413
</div>
406414
);
407415
}

0 commit comments

Comments
 (0)