Skip to content

Commit e36b5c5

Browse files
committed
Add option to disable Show Local button
1 parent 11e6e65 commit e36b5c5

File tree

6 files changed

+285
-6
lines changed

6 files changed

+285
-6
lines changed

patches/disable-show-local.diff

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
Index: code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
2+
===================================================================
3+
--- code-server.orig/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
4+
+++ code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
5+
@@ -17,6 +17,7 @@ export const serverOptions: OptionDescri
6+
'disable-update-check': { type: 'boolean' },
7+
'auth': { type: 'string' },
8+
'disable-file-downloads': { type: 'boolean' },
9+
+ 'disable-show-local': { type: 'boolean' },
10+
'locale': { type: 'string' },
11+
'disable-getting-started-override': { type: 'boolean' },
12+
13+
@@ -101,6 +102,7 @@ export interface ServerParsedArgs {
14+
'disable-update-check'?: boolean;
15+
'auth'?: string
16+
'disable-file-downloads'?: boolean;
17+
+ 'disable-show-local'?: boolean;
18+
'locale'?: string
19+
'disable-getting-started-override'?: boolean,
20+
21+
Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
22+
===================================================================
23+
--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts
24+
+++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts
25+
@@ -335,6 +335,7 @@ export class WebClientServer {
26+
webviewEndpoint: vscodeBase + this._staticRoute + '/out/vs/workbench/contrib/webview/browser/pre',
27+
userDataPath: this._environmentService.userDataPath,
28+
isEnabledFileDownloads: !this._environmentService.args['disable-file-downloads'],
29+
+ isEnabledShowLocal: !this._environmentService.args['disable-show-local'],
30+
isEnabledCoderGettingStarted: !this._environmentService.args['disable-getting-started-override'],
31+
_wrapWebWorkerExtHostInIframe,
32+
developmentOptions: { enableSmokeTestDriver: this._environmentService.args['enable-smoke-test-driver'] ? true : undefined, logLevel: this._logService.getLevel() },
33+
Index: code-server/lib/vscode/src/vs/workbench/browser/web.api.ts
34+
===================================================================
35+
--- code-server.orig/lib/vscode/src/vs/workbench/browser/web.api.ts
36+
+++ code-server/lib/vscode/src/vs/workbench/browser/web.api.ts
37+
@@ -287,6 +287,11 @@ export interface IWorkbenchConstructionO
38+
readonly isEnabledFileDownloads?: boolean
39+
40+
/**
41+
+ * Whether the "Show local" button is enabled.
42+
+ */
43+
+ readonly isEnabledShowLocal?: boolean
44+
+
45+
+ /**
46+
* Whether to use Coder's custom Getting Started text.
47+
*/
48+
readonly isEnabledCoderGettingStarted?: boolean
49+
Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
50+
===================================================================
51+
--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
52+
+++ code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
53+
@@ -39,6 +39,11 @@ export interface IBrowserWorkbenchEnviro
54+
readonly isEnabledFileDownloads?: boolean;
55+
56+
/**
57+
+ * Enable Show Local button on File Dialogs.
58+
+ */
59+
+ readonly isEnabledShowLocal?: boolean;
60+
+
61+
+ /**
62+
* Enable Coder's custom getting started text.
63+
*/
64+
readonly isEnabledCoderGettingStarted?: boolean;
65+
@@ -128,6 +133,13 @@ export class BrowserWorkbenchEnvironment
66+
return this.options.isEnabledFileDownloads;
67+
}
68+
69+
+ get isEnabledShowLocal(): boolean {
70+
+ if (typeof this.options.isEnabledShowLocal === "undefined") {
71+
+ throw new Error('isEnabledShowLocal was not provided to the browser');
72+
+ }
73+
+ return this.options.isEnabledShowLocal;
74+
+ }
75+
+
76+
get isEnabledCoderGettingStarted(): boolean {
77+
if (typeof this.options.isEnabledCoderGettingStarted === "undefined") {
78+
throw new Error('isEnabledCoderGettingStarted was not provided to the browser');
79+
Index: code-server/lib/vscode/src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts
80+
===================================================================
81+
--- code-server.orig/lib/vscode/src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts
82+
+++ code-server/lib/vscode/src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts
83+
@@ -18,7 +18,7 @@ import { IModelService } from 'vs/editor
84+
import { ILanguageService } from 'vs/editor/common/languages/language';
85+
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
86+
import { Schemas } from 'vs/base/common/network';
87+
-import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
88+
+import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
89+
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
90+
import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
91+
import { equalsIgnoreCase, format, startsWithIgnoreCase } from 'vs/base/common/strings';
92+
@@ -142,7 +142,7 @@ export class SimpleFileDialog implements
93+
@IFileDialogService private readonly fileDialogService: IFileDialogService,
94+
@IModelService private readonly modelService: IModelService,
95+
@ILanguageService private readonly languageService: ILanguageService,
96+
- @IWorkbenchEnvironmentService protected readonly environmentService: IWorkbenchEnvironmentService,
97+
+ @IBrowserWorkbenchEnvironmentService protected readonly environmentService: IBrowserWorkbenchEnvironmentService,
98+
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,
99+
@IPathService protected readonly pathService: IPathService,
100+
@IKeybindingService private readonly keybindingService: IKeybindingService,
101+
@@ -286,20 +286,22 @@ export class SimpleFileDialog implements
102+
this.filePickBox.autoFocusOnList = false;
103+
this.filePickBox.ignoreFocusOut = true;
104+
this.filePickBox.ok = true;
105+
- if ((this.scheme !== Schemas.file) && this.options && this.options.availableFileSystems && (this.options.availableFileSystems.length > 1) && (this.options.availableFileSystems.indexOf(Schemas.file) > -1)) {
106+
- this.filePickBox.customButton = true;
107+
- this.filePickBox.customLabel = nls.localize('remoteFileDialog.local', 'Show Local');
108+
- let action;
109+
- if (isSave) {
110+
- action = SaveLocalFileCommand;
111+
- } else {
112+
- action = this.allowFileSelection ? (this.allowFolderSelection ? OpenLocalFileFolderCommand : OpenLocalFileCommand) : OpenLocalFolderCommand;
113+
- }
114+
- const keybinding = this.keybindingService.lookupKeybinding(action.ID);
115+
- if (keybinding) {
116+
- const label = keybinding.getLabel();
117+
- if (label) {
118+
- this.filePickBox.customHover = format('{0} ({1})', action.LABEL, label);
119+
+ if ((this.environmentService.isEnabledFileDownloads || !isSave) && this.environmentService.isEnabledShowLocal) {
120+
+ if ((this.scheme !== Schemas.file) && this.options && this.options.availableFileSystems && (this.options.availableFileSystems.length > 1) && (this.options.availableFileSystems.indexOf(Schemas.file) > -1)) {
121+
+ this.filePickBox.customButton = true;
122+
+ this.filePickBox.customLabel = nls.localize('remoteFileDialog.local', 'Show Local');
123+
+ let action;
124+
+ if (isSave) {
125+
+ action = SaveLocalFileCommand;
126+
+ } else {
127+
+ action = this.allowFileSelection ? (this.allowFolderSelection ? OpenLocalFileFolderCommand : OpenLocalFileCommand) : OpenLocalFolderCommand;
128+
+ }
129+
+ const keybinding = this.keybindingService.lookupKeybinding(action.ID);
130+
+ if (keybinding) {
131+
+ const label = keybinding.getLabel();
132+
+ if (label) {
133+
+ this.filePickBox.customHover = format('{0} ({1})', action.LABEL, label);
134+
+ }
135+
}
136+
}
137+
}

patches/series

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ display-language.diff
1919
cli-window-open.diff
2020
getting-started.diff
2121
safari.diff
22+
disable-show-local.diff

src/node/cli.ts

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface UserProvidedCodeArgs {
4848
"github-auth"?: string
4949
"disable-update-check"?: boolean
5050
"disable-file-downloads"?: boolean
51+
"disable-show-local"?: boolean
5152
"disable-workspace-trust"?: boolean
5253
"disable-getting-started-override"?: boolean
5354
"disable-proxy"?: boolean
@@ -170,6 +171,11 @@ export const options: Options<Required<UserProvidedArgs>> = {
170171
description:
171172
"Disable file downloads from Code. This can also be set with CS_DISABLE_FILE_DOWNLOADS set to 'true' or '1'.",
172173
},
174+
"disable-show-local": {
175+
type: "boolean",
176+
description:
177+
"Disable 'Show Local' button in Save and Open dialogs.",
178+
},
173179
"disable-workspace-trust": {
174180
type: "boolean",
175181
description: "Disable Workspace Trust feature. This switch only affects the current session.",

test/e2e/downloads.test.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => {
2323

2424
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(true)
2525
})
26+
27+
test("should see the 'Show Local' button on 'Save As'", async ({ codeServerPage }) => {
28+
// Setup
29+
const workspaceDir = await codeServerPage.workspaceDir
30+
const fileName = "unique-file-save-as.txt"
31+
const tmpFilePath = path.join(workspaceDir, fileName)
32+
await fs.writeFile(tmpFilePath, "Hello World")
33+
34+
// Action
35+
await codeServerPage.page.waitForSelector(`text=${fileName}`)
36+
37+
await codeServerPage.openFile(fileName)
38+
await codeServerPage.page.click(".tab")
39+
await codeServerPage.navigateMenus(["File", "Auto Save"])
40+
await codeServerPage.page.keyboard.type("Making some edits.")
41+
await codeServerPage.navigateMenus(["File", "Save As..."])
42+
await codeServerPage.page.waitForSelector(".quick-input-widget")
43+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
44+
})
45+
2646
})
2747

2848
describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-downloads"], {}, async () => {
@@ -35,7 +55,7 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d
3555
// Setup
3656
const workspaceDir = await codeServerPage.workspaceDir
3757
const tmpFilePath = path.join(workspaceDir, "unique-file.txt")
38-
await fs.writeFile(tmpFilePath, "hello world")
58+
await fs.writeFile(tmpFilePath, "Hello World")
3959

4060
// Action
4161
const fileInExplorer = await codeServerPage.page.waitForSelector("text=unique-file.txt")
@@ -45,4 +65,20 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d
4565

4666
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(false)
4767
})
68+
69+
test("should not see the 'Show Local' button on 'Save As'", async ({ codeServerPage }) => {
70+
// Setup
71+
const workspaceDir = await codeServerPage.workspaceDir
72+
const fileName = "unique-file-save-as.txt"
73+
const tmpFilePath = path.join(workspaceDir, fileName)
74+
await fs.writeFile(tmpFilePath, "Hello World")
75+
76+
// Action
77+
await codeServerPage.page.waitForSelector(`text=${fileName}`)
78+
await codeServerPage.openFile(fileName)
79+
await codeServerPage.page.click(".tab")
80+
await codeServerPage.navigateMenus(["File", "Save As..."])
81+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
82+
})
83+
4884
})

test/e2e/models/CodeServer.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export class CodeServerPage {
401401
* Open a file by using menus.
402402
*/
403403
async openFile(file: string) {
404-
await this.navigateMenus(["File", "Open File"])
404+
await this.navigateMenus(["File", "Open File..."])
405405
await this.navigateQuickInput([path.basename(file)])
406406
await this.waitForTab(file)
407407
}
@@ -488,19 +488,19 @@ export class CodeServerPage {
488488
// splitting them into two steps each we can cancel before running the
489489
// action.
490490
steps.push({
491-
fn: () => this.page.hover(`${selector} :text("${item}")`, { trial: true }),
491+
fn: () => this.page.hover(`${selector} :text-is("${item}")`, { trial: true }),
492492
name: `${item}:hover:trial`,
493493
})
494494
steps.push({
495-
fn: () => this.page.hover(`${selector} :text("${item}")`, { force: true }),
495+
fn: () => this.page.hover(`${selector} :text-is("${item}")`, { force: true }),
496496
name: `${item}:hover:force`,
497497
})
498498
steps.push({
499-
fn: () => this.page.click(`${selector} :text("${item}")`, { trial: true }),
499+
fn: () => this.page.click(`${selector} :text-is("${item}")`, { trial: true }),
500500
name: `${item}:click:trial`,
501501
})
502502
steps.push({
503-
fn: () => this.page.click(`${selector} :text("${item}")`, { force: true }),
503+
fn: () => this.page.click(`${selector} :text-is("${item}")`, { force: true }),
504504
name: `${item}:click:force`,
505505
})
506506
}

test/e2e/show-local.test.ts

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { promises as fs } from "fs"
2+
import * as path from "path"
3+
import { clean } from "../utils/helpers"
4+
import { describe, test, expect } from "./baseFixture"
5+
6+
describe("Show Local (enabled)", ["--disable-workspace-trust"], {}, () => {
7+
const testName = "show-local-enabled"
8+
test.beforeAll(async () => {
9+
await clean(testName)
10+
})
11+
12+
test("should see the 'Show Local' button on Open File", async ({ codeServerPage }) => {
13+
// Action
14+
await codeServerPage.navigateMenus(["File", "Open File..."])
15+
await codeServerPage.page.waitForSelector(".quick-input-widget")
16+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
17+
})
18+
19+
test("should see the 'Show Local' button on Save as File", async ({ codeServerPage }) => {
20+
// Setup
21+
const workspaceDir = await codeServerPage.workspaceDir
22+
const fileName = "unique-file-save-as.txt"
23+
const tmpFilePath = path.join(workspaceDir, fileName)
24+
await fs.writeFile(tmpFilePath, "Hello World")
25+
26+
// Action
27+
await codeServerPage.page.waitForSelector(`text=${fileName}`)
28+
29+
await codeServerPage.openFile(fileName)
30+
await codeServerPage.page.click(".tab")
31+
await codeServerPage.navigateMenus(["File", "Auto Save"])
32+
await codeServerPage.page.keyboard.type("Edit edit edit.")
33+
await codeServerPage.navigateMenus(["File", "Save As..."])
34+
await codeServerPage.page.waitForSelector(".quick-input-widget")
35+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
36+
})
37+
38+
test("should see the 'Show Local' button on Save File", async ({ codeServerPage }) => {
39+
40+
// Action
41+
await codeServerPage.navigateMenus(["File", "New Text File"])
42+
await codeServerPage.waitForTab("Untitled-1")
43+
await codeServerPage.navigateMenus(["File", "Save"])
44+
await codeServerPage.page.waitForSelector(".quick-input-widget")
45+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
46+
})
47+
48+
test("should see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => {
49+
// Action
50+
await codeServerPage.navigateMenus(["File", "Save Workspace As..."])
51+
await codeServerPage.page.waitForSelector(".quick-input-widget")
52+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
53+
})
54+
})
55+
56+
describe("Show Local (disabled)", ["--disable-workspace-trust", "--disable-show-local"], {}, () => {
57+
const testName = "show-local-disabled"
58+
test.beforeAll(async () => {
59+
await clean(testName)
60+
})
61+
62+
test("should not see the 'Show Local' button on Open File", async ({ codeServerPage }) => {
63+
// Action
64+
await codeServerPage.navigateMenus(["File", "Open File..."])
65+
await codeServerPage.page.waitForSelector(".quick-input-widget")
66+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
67+
})
68+
69+
test("should not see the 'Show Local' button on Save as File'", async ({ codeServerPage }) => {
70+
// Setup
71+
const workspaceDir = await codeServerPage.workspaceDir
72+
const fileName = "unique-file-save-as.txt"
73+
const tmpFilePath = path.join(workspaceDir, fileName)
74+
await fs.writeFile(tmpFilePath, "Hello World")
75+
76+
// Action
77+
await codeServerPage.page.waitForSelector(`text=${fileName}`)
78+
await codeServerPage.openFile(fileName)
79+
await codeServerPage.page.click(".tab")
80+
await codeServerPage.navigateMenus(["File", "Save As..."])
81+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
82+
})
83+
84+
test("should not see the 'Show Local' button on Save File", async ({ codeServerPage }) => {
85+
// Action
86+
await codeServerPage.navigateMenus(["File", "New Text File"])
87+
await codeServerPage.waitForTab("Untitled-1")
88+
await codeServerPage.navigateMenus(["File", "Save"])
89+
await codeServerPage.page.waitForSelector(".quick-input-widget")
90+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
91+
})
92+
93+
test("should not see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => {
94+
// Action
95+
await codeServerPage.navigateMenus(["File", "Save Workspace As..."])
96+
await codeServerPage.page.waitForSelector(".quick-input-widget")
97+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
98+
})
99+
})

0 commit comments

Comments
 (0)