Skip to content

Commit f58bbf9

Browse files
BenRussertlgeiger
authored andcommitted
Add setting to view output in dock by default (#1022)
* Reuse output pane config to keep watch pane open if no kernel * Add config to open results in output pane by default * Set output config when toggling or clearing pane Off when clearing output On when toggle opens a new pane instance * Use output pane until completely closed * Revert "Set output config when toggling or clearing pane" This reverts commit d957c2f.
1 parent ef6bc43 commit f58bbf9

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

lib/components/output-area.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@ import Anser from "anser";
88

99
import History from "./result-view/history";
1010
import ScrollList from "./result-view/list";
11-
import { OUTPUT_AREA_URI } from "./../utils";
11+
import { OUTPUT_AREA_URI, EmptyMessage } from "./../utils";
1212

1313
import typeof store from "../store";
1414
import type { IObservableValue } from "mobx";
1515

16-
const EmptyMessage = () => {
17-
return (
18-
<ul className="background-message centered">
19-
<li>No output to display</li>
20-
</ul>
21-
);
22-
};
23-
2416
@observer
2517
class OutputArea extends React.Component<{ store: store }> {
2618
showHistory: IObservableValue<boolean> = observable(true);

lib/components/watch-sidebar/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ import React from "react";
55
import { observer } from "mobx-react";
66

77
import Watch from "./watch";
8-
import { WATCHES_URI } from "../../utils";
8+
import { WATCHES_URI, EmptyMessage } from "../../utils";
99

1010
import type Kernel from "./../../kernel";
1111
import typeof store from "../../store";
1212

1313
const Watches = observer(({ store: { kernel } }: { store: store }) => {
1414
if (!kernel) {
15-
atom.workspace.hide(WATCHES_URI);
16-
return null;
15+
if (atom.config.get("Hydrogen.outputAreaDock")) {
16+
return <EmptyMessage />;
17+
} else {
18+
atom.workspace.hide(WATCHES_URI);
19+
return null;
20+
}
1721
}
22+
1823
return (
1924
<div className="sidebar watch-sidebar">
2025
{kernel.watchesStore.watches.map(watch => (

lib/config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,18 @@ const Config = {
100100
default: "{}"
101101
},
102102
outputAreaDock: {
103-
title: "Output Area Dock",
103+
title: "Leave output dock open",
104104
description:
105105
"Do not close dock when switching to an editor without a running kernel",
106106
type: "boolean",
107107
default: false
108+
},
109+
outputAreaDefault: {
110+
title: "View output in the dock by default",
111+
description:
112+
"If enabled, output will be displayed in the dock by default rather than inline",
113+
type: "boolean",
114+
default: false
108115
}
109116
}
110117
};

lib/main.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import AutocompleteProvider from "./autocomplete-provider";
4040
import HydrogenProvider from "./plugin-api/hydrogen-provider";
4141
import {
4242
log,
43-
focus,
4443
reactFactory,
4544
isMultilanguageGrammar,
4645
renderDevTools,
@@ -349,11 +348,11 @@ const Hydrogen = {
349348
kernel.watchesStore.run();
350349
return;
351350
}
352-
const globalOutputStore = atom.workspace
353-
.getPaneItems()
354-
.find(item => item instanceof OutputPane)
355-
? kernel.outputStore
356-
: null;
351+
const globalOutputStore =
352+
atom.config.get("Hydrogen.outputAreaDefault") ||
353+
atom.workspace.getPaneItems().find(item => item instanceof OutputPane)
354+
? kernel.outputStore
355+
: null;
357356

358357
const { outputStore } = new ResultView(
359358
store.markers,
@@ -367,18 +366,7 @@ const Hydrogen = {
367366
outputStore.appendOutput(result);
368367
if (globalOutputStore) {
369368
globalOutputStore.appendOutput(result);
370-
371-
if (store.kernel !== kernel) return;
372-
373-
const container = atom.workspace.paneContainerForURI(OUTPUT_AREA_URI);
374-
const pane = atom.workspace.paneForURI(OUTPUT_AREA_URI);
375-
if (
376-
(container && container.isVisible && !container.isVisible()) ||
377-
(pane && pane.itemForURI(OUTPUT_AREA_URI) !== pane.getActiveItem())
378-
) {
379-
await atom.workspace.open(OUTPUT_AREA_URI, { searchAllPanes: true });
380-
focus(store.editor);
381-
}
369+
openOrShowDock(OUTPUT_AREA_URI);
382370
}
383371
});
384372
},

lib/utils.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@ export function focus(item: ?mixed) {
3838
}
3939
}
4040

41-
export function openOrShowDock(URI: string) {
41+
export async function openOrShowDock(URI: string): Promise<?void> {
4242
// atom.workspace.open(URI) will activate/focus the dock by default
4343
// dock.toggle() or dock.show() will leave focus wherever it was
4444

4545
// this function is basically workspace.open, except it
46-
// will not focus the pane if there is an open instance of that view
46+
// will not focus the newly opened pane
47+
let dock = atom.workspace.paneContainerForURI(URI);
48+
if (dock) return dock.show();
4749

48-
const dock = atom.workspace.paneContainerForURI(URI);
49-
if (!dock) {
50-
atom.workspace.open(URI, { searchAllPanes: true });
51-
} else {
52-
dock.show();
53-
}
50+
await atom.workspace.open(URI, {
51+
searchAllPanes: true,
52+
activatePane: false
53+
});
54+
dock = atom.workspace.paneContainerForURI(URI);
55+
return dock ? dock.show() : null;
5456
}
5557

5658
export function grammarToLanguage(grammar: ?atom$Grammar) {
@@ -216,3 +218,11 @@ export function rowRangeForCodeFoldAtBufferRow(
216218
return range ? [range.start.row, range.end.row] : null;
217219
}
218220
}
221+
222+
export const EmptyMessage = () => {
223+
return (
224+
<ul className="background-message centered">
225+
<li>No output to display</li>
226+
</ul>
227+
);
228+
};

0 commit comments

Comments
 (0)