Skip to content

Commit ec42dcd

Browse files
authored
Merge pull request #7696 from sagemathinc/toggle-autobuild
tex/rmd/qmd: "build on save" toggle button
2 parents c1a9ae2 + cd4947d commit ec42dcd

File tree

9 files changed

+58
-15
lines changed

9 files changed

+58
-15
lines changed

src/packages/frontend/account/editor-settings/checkboxes.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
*/
55

66
import { Map } from "immutable";
7-
import { Rendered, Component } from "../../app-framework";
7+
8+
import { Checkbox } from "@cocalc/frontend/antd-bootstrap";
9+
import { Component, Rendered } from "@cocalc/frontend/app-framework";
810
import { capitalize, is_different, keys } from "@cocalc/util/misc";
911
import { JUPYTER_CLASSIC_MODERN } from "@cocalc/util/theme";
10-
import { Checkbox } from "../../antd-bootstrap";
1112

1213
const EDITOR_SETTINGS_CHECKBOXES: { [setting: string]: string | Rendered } = {
1314
extra_button_bar:
@@ -40,7 +41,7 @@ const EDITOR_SETTINGS_CHECKBOXES: { [setting: string]: string | Rendered } = {
4041
/* commented out since we are never using this.
4142
disable_jupyter_windowing:
4243
"never use windowing with Jupyter notebooks (windowing is sometimes used on the Chrome browser to make very large notebooks render quickly, but can lead to trouble)",*/
43-
};
44+
} as const;
4445

4546
interface Props {
4647
editor_settings: Map<string, any>;

src/packages/frontend/components/icon.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
DatabaseFilled,
6868
DatabaseOutlined,
6969
DeleteOutlined,
70+
DeliveredProcedureOutlined,
7071
DeploymentUnitOutlined,
7172
DesktopOutlined,
7273
DoubleLeftOutlined,
@@ -185,6 +186,7 @@ import {
185186
StarOutlined,
186187
StepBackwardOutlined,
187188
StepForwardOutlined,
189+
StopFilled,
188190
StopOutlined,
189191
StrikethroughOutlined,
190192
SwapOutlined,
@@ -331,6 +333,7 @@ const IconSpec: { [name: string]: any } = {
331333
"deployment-unit": DeploymentUnitOutlined,
332334
dedicated: DatabaseOutlined, // icon for "dedicated resources", looks like a server rack
333335
desktop: DesktopOutlined,
336+
"delivered-procedure-outlined": DeliveredProcedureOutlined,
334337
digitalocean: { IconFont: "digitalocean" },
335338
discord: { IconFont: "discord" },
336339
"disk-drive": { IconFont: "disk-drive" },
@@ -541,6 +544,7 @@ const IconSpec: { [name: string]: any } = {
541544
"step-backward": StepBackwardOutlined,
542545
"step-forward": StepForwardOutlined,
543546
stop: { IconFont: "stop" }, // the ant-design "stop" looks weird.
547+
"stop-filled": StopFilled,
544548
stopwatch: FieldTimeOutlined,
545549
store: { IconFont: "store" },
546550
strikethrough: StrikethroughOutlined,

src/packages/frontend/frame-editors/code-editor/actions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
Store,
3333
TypedMap,
3434
createTypedMap,
35+
redux,
3536
} from "@cocalc/frontend/app-framework";
3637
import type { PageActions } from "@cocalc/frontend/app/actions";
3738
import { syncAllComputeServers } from "@cocalc/frontend/compute/sync-all";
@@ -98,6 +99,7 @@ import * as cm_doc_cache from "./doc";
9899
import { SHELLS } from "./editor";
99100
import { test_line } from "./simulate_typing";
100101
import { misspelled_words } from "./spell-check";
102+
import { set_account_table } from "../../account/util";
101103

102104
interface gutterMarkerParams {
103105
line: number;
@@ -3009,4 +3011,12 @@ export class Actions<
30093011
tour(_id: string, _refs: any): TourProps["steps"] {
30103012
return [];
30113013
}
3014+
3015+
// toggle autobuild on save via the menu or button
3016+
public build_on_save(): void {
3017+
const val = redux
3018+
.getStore("account")
3019+
.getIn(["editor_settings", "build_on_save"]);
3020+
set_account_table({ editor_settings: { build_on_save: !val } });
3021+
}
30123022
}

src/packages/frontend/frame-editors/frame-tree/commands/generic-commands.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,32 @@ addCommands({
435435
build: {
436436
group: "build",
437437
label: "Build",
438-
title:
439-
"Build the document. To disable automatic builds, change Account → Editor → 'Build on save'.",
438+
title: (
439+
<>
440+
Build the document.
441+
<br />
442+
To enable or disable automatic builds, click on the 'Build on Save'
443+
button or menu entry.
444+
</>
445+
),
440446
icon: "play-circle",
441447
},
442-
448+
build_on_save: {
449+
group: "build",
450+
label: () => (
451+
<>
452+
Build on Save{" "}
453+
{redux.getStore("account").getIn(["editor_settings", "build_on_save"])
454+
? "(Enabled)"
455+
: "(Disabled)"}
456+
</>
457+
),
458+
title: "Toggle automatic build on file save.",
459+
icon: () =>
460+
redux.getStore("account").getIn(["editor_settings", "build_on_save"])
461+
? "delivered-procedure-outlined"
462+
: "stop-filled",
463+
},
443464
force_build: {
444465
group: "build",
445466
label: "Force Build",

src/packages/frontend/frame-editors/latex-editor/editor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const EDITOR_SPEC = {
4343
commands: set([
4444
"format_action",
4545
"build",
46+
"build_on_save",
4647
"force_build",
4748
"print",
4849
"decrease_font_size",
@@ -75,6 +76,7 @@ const EDITOR_SPEC = {
7576
"format-font",
7677
"format-color",
7778
"build",
79+
"build_on_save",
7880
"show_table_of_contents",
7981
]),
8082
customizeCommands: {
@@ -136,7 +138,7 @@ const EDITOR_SPEC = {
136138
"rescan_latex_directive",
137139
"word_count",
138140
]),
139-
buttons: set(["build", "force_build", "clean"]),
141+
buttons: set(["build", "force_build", "build_on_save", "clean"]),
140142
} as EditorDescription,
141143

142144
latex_table_of_contents: {

src/packages/frontend/frame-editors/qmd-editor/actions.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
Quarto Editor Actions
88
*/
99

10-
import { path_split } from "@cocalc/util/misc";
11-
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
1210
import { Set } from "immutable";
1311
import { debounce } from "lodash";
14-
import { redux } from "../../app-framework";
15-
import { markdown_to_html_frontmatter } from "../../markdown";
12+
13+
import { redux } from "@cocalc/frontend/app-framework";
14+
import { markdown_to_html_frontmatter } from "@cocalc/frontend/markdown";
15+
import { path_split } from "@cocalc/util/misc";
16+
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
1617
import {
1718
Actions as BaseActions,
1819
CodeEditorState,
@@ -42,7 +43,7 @@ export class Actions extends MarkdownActions {
4243
}
4344
}
4445

45-
private do_implicit_builds(): boolean {
46+
private do_build_on_save(): boolean {
4647
const account: any = this.redux.getStore("account");
4748
if (account != null) {
4849
return !!account.getIn(["editor_settings", "build_on_save"]);
@@ -59,7 +60,7 @@ export class Actions extends MarkdownActions {
5960
);
6061

6162
const do_build = reuseInFlight(async () => {
62-
if (!this.do_implicit_builds()) return;
63+
if (!this.do_build_on_save()) return;
6364
if (this._syncstring == null) return;
6465
const hash = this._syncstring.hash_of_saved_version();
6566
if (this._last_qmd_hash != hash) {

src/packages/frontend/frame-editors/qmd-editor/editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ const EDITOR_SPEC = {
4545
"redo",
4646
"format",
4747
"build",
48+
"build_on_save",
4849
]),
4950
buttons: set([
5051
"format-ai_formula",
5152
"decrease_font_size",
5253
"increase_font_size",
5354
"build",
55+
"build_on_save",
5456
]),
5557
} as EditorDescription,
5658

src/packages/frontend/frame-editors/rmd-editor/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class Actions extends MarkdownActions {
8282
);
8383
}
8484

85-
private do_implicit_builds(): boolean {
85+
private do_build_on_save(): boolean {
8686
const account: any = this.redux.getStore("account");
8787
if (account != null) {
8888
return !!account.getIn(["editor_settings", "build_on_save"]);
@@ -99,7 +99,7 @@ export class Actions extends MarkdownActions {
9999
);
100100

101101
const do_build = reuseInFlight(async () => {
102-
if (!this.do_implicit_builds()) return;
102+
if (!this.do_build_on_save()) return;
103103
if (this._syncstring == null) return;
104104
const hash = this._syncstring.hash_of_saved_version();
105105
if (this._last_rmd_hash != hash) {

src/packages/frontend/frame-editors/rmd-editor/editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ const EDITOR_SPEC = {
4848
"redo",
4949
"format",
5050
"build",
51+
"build_on_save",
5152
]),
5253
buttons: set([
5354
"format-ai_formula",
5455
"decrease_font_size",
5556
"increase_font_size",
5657
"build",
58+
"build_on_save",
5759
]),
5860
} as EditorDescription,
5961

0 commit comments

Comments
 (0)