Skip to content

Commit 8599c22

Browse files
committed
allow some minimal opening of files when a project isn't running; ask to open on save (fix #8284)
1 parent 59a9bdf commit 8599c22

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import { SHELLS } from "./editor";
110110
import { test_line } from "./simulate_typing";
111111
import { misspelled_words } from "./spell-check";
112112
import { log_opened_time } from "@cocalc/frontend/project/open-file";
113+
import { ensure_project_running } from "@cocalc/frontend/project/project-start-warning";
113114

114115
interface gutterMarkerParams {
115116
line: number;
@@ -1237,6 +1238,9 @@ export class Actions<
12371238
// several other formatting actions.
12381239
// Doing this automatically is fraught with error, since cursors aren't precise...
12391240
if (explicit) {
1241+
if (!await this.ensureProjectIsRunning(`save ${this.path} to disk`)) {
1242+
return;
1243+
}
12401244
const account: any = this.redux.getStore("account");
12411245
if (
12421246
account &&
@@ -2172,6 +2176,10 @@ export class Actions<
21722176
}
21732177
}
21742178

2179+
ensureProjectIsRunning = async (what: string): Promise<boolean> => {
2180+
return await ensure_project_running(this.project_id, what);
2181+
};
2182+
21752183
public format_support_for_syntax(
21762184
available_features: AvailableFeatures,
21772185
syntax: FormatterSyntax,

src/packages/frontend/project/directory-listing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function get_directory_listing(opts: ListingOpts) {
4242
timeout = 0.5;
4343
time0 = server_time();
4444
if (opts.trigger_start_project === false) {
45-
return { files: [] };
45+
return { files: [], noRunning: true };
4646
}
4747
redux.getActions("projects").start_project(opts.project_id);
4848
} else {

src/packages/frontend/project/fetch-directory-listing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ const fetchDirectoryListing = reuseInFlight(
9797
}
9898
const directory_listings = store.get("directory_listings");
9999
let listing2 = directory_listings.get(compute_server_id) ?? Map();
100+
if (listing.noRunning && (listing2.get(path)?.size ?? 0) > 0) {
101+
// do not change it
102+
return;
103+
}
100104
listing2 = listing2.set(path, value);
101105
actions.setState({
102106
directory_listings: directory_listings.set(compute_server_id, listing2),

src/packages/frontend/project/open-file.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
// Implement the open_file actions for opening one single file in a project.
77

88
import { callback } from "awaiting";
9-
109
import { alert_message } from "@cocalc/frontend/alerts";
1110
import { redux } from "@cocalc/frontend/app-framework";
1211
import { local_storage } from "@cocalc/frontend/editor-local-storage";
13-
import { dialogs } from "@cocalc/frontend/i18n";
14-
import { getIntl } from "@cocalc/frontend/i18n/get-intl";
1512
import Fragment, { FragmentId } from "@cocalc/frontend/misc/fragment-id";
1613
import { remove } from "@cocalc/frontend/project-file";
1714
import { ProjectActions } from "@cocalc/frontend/project_actions";
@@ -26,7 +23,6 @@ import {
2623
uuid,
2724
} from "@cocalc/util/misc";
2825
import { SITE_NAME } from "@cocalc/util/theme";
29-
import { ensure_project_running } from "./project-start-warning";
3026
import { normalize } from "./utils";
3127
import { syncdbPath as ipynbSyncdbPath } from "@cocalc/util/jupyter/names";
3228
import { termPath } from "@cocalc/util/terminal/names";
@@ -146,19 +142,6 @@ export async function open_file(
146142
opts.fragmentId = Fragment.decode(location.hash);
147143
}
148144

149-
const intl = await getIntl();
150-
if (!tabIsOpened()) {
151-
return;
152-
}
153-
const what = intl.formatMessage(dialogs.project_open_file_what, {
154-
path: opts.path,
155-
});
156-
157-
if (!(await ensure_project_running(actions.project_id, what))) {
158-
if (!actions.open_files) return; // closed
159-
actions.open_files.delete(opts.path);
160-
return;
161-
}
162145
if (!tabIsOpened()) {
163146
return;
164147
}

0 commit comments

Comments
 (0)