Browse Source

Adds context menu command to change workspace sync setting

main
Ramin Tadayon 1 year ago
parent
commit
aa9ff02252
No known key found for this signature in database GPG Key ID: 79D60DDE3DFB95F5
8 changed files with 106 additions and 0 deletions
  1. +14
    -0
      package.json
  2. +1
    -0
      src/constants.ts
  3. +7
    -0
      src/env/browser/pathMapping/workspacesWebPathMappingProvider.ts
  4. +28
    -0
      src/env/node/pathMapping/workspacesLocalPathMappingProvider.ts
  5. +5
    -0
      src/plus/workspaces/workspacesPathMappingProvider.ts
  6. +39
    -0
      src/plus/workspaces/workspacesService.ts
  7. +5
    -0
      src/views/nodes/repositoriesNode.ts
  8. +7
    -0
      src/views/workspacesView.ts

+ 14
- 0
package.json View File

@ -6960,6 +6960,11 @@
"icon": "$(window)" "icon": "$(window)"
}, },
{ {
"command": "gitlens.views.workspaces.changeLocalSync",
"title": "Change Workspace Sync Setting...",
"category": "GitLens"
},
{
"command": "gitlens.views.workspaces.repo.locate", "command": "gitlens.views.workspaces.repo.locate",
"title": "Locate Repository...", "title": "Locate Repository...",
"category": "GitLens", "category": "GitLens",
@ -9518,6 +9523,10 @@
"when": "false" "when": "false"
}, },
{ {
"command": "gitlens.views.workspaces.changeLocalSync",
"when": "false"
},
{
"command": "gitlens.views.workspaces.repo.openInNewWindow", "command": "gitlens.views.workspaces.repo.openInNewWindow",
"when": "false" "when": "false"
}, },
@ -11182,6 +11191,11 @@
"group": "2_gitlens_quickopen@5" "group": "2_gitlens_quickopen@5"
}, },
{ {
"command": "gitlens.views.workspaces.changeLocalSync",
"when": "viewItem =~ /(gitlens:workspace\\b(?=.*?\\b\\+(cloud|local)\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+hasPath\\b)|gitlens:repositories\\b(?=.*?\\b\\+synced\\b))/",
"group": "2_gitlens_quickopen@6"
},
{
"command": "gitlens.views.workspaces.delete", "command": "gitlens.views.workspaces.delete",
"when": "viewItem =~ /gitlens:workspace\\b(?=.*?\\b\\+cloud\\b)/", "when": "viewItem =~ /gitlens:workspace\\b(?=.*?\\b\\+cloud\\b)/",
"group": "6_gitlens_actions@1" "group": "6_gitlens_actions@1"

+ 1
- 0
src/constants.ts View File

@ -404,6 +404,7 @@ export type TreeViewCommands = `gitlens.views.${
| 'copy' | 'copy'
| 'refresh' | 'refresh'
| 'addRepos' | 'addRepos'
| 'changeLocalSync'
| 'convert' | 'convert'
| 'create' | 'create'
| 'createLocal' | 'createLocal'

+ 7
- 0
src/env/browser/pathMapping/workspacesWebPathMappingProvider.ts View File

@ -39,4 +39,11 @@ export class WorkspacesWebPathMappingProvider implements WorkspacesPathMappingPr
): Promise<boolean> { ): Promise<boolean> {
return false; return false;
} }
async updateCodeWorkspaceFileSettings(
_uri: Uri,
_options: { workspaceSyncSetting?: WorkspaceSyncSetting },
): Promise<boolean> {
return false;
}
} }

+ 28
- 0
src/env/node/pathMapping/workspacesLocalPathMappingProvider.ts View File

@ -211,4 +211,32 @@ export class WorkspacesLocalPathMappingProvider implements WorkspacesPathMapping
return true; return true;
} }
async updateCodeWorkspaceFileSettings(
uri: Uri,
options: { workspaceSyncSetting?: WorkspaceSyncSetting },
): Promise<boolean> {
let codeWorkspaceFileContents: CodeWorkspaceFileContents;
let data;
try {
data = await workspace.fs.readFile(uri);
codeWorkspaceFileContents = JSON.parse(data.toString()) as CodeWorkspaceFileContents;
} catch (error) {
return false;
}
if (options.workspaceSyncSetting != null) {
codeWorkspaceFileContents.settings['gitkraken.workspaceSyncSetting'] = options.workspaceSyncSetting;
}
const outputData = new Uint8Array(Buffer.from(JSON.stringify(codeWorkspaceFileContents)));
try {
await workspace.fs.writeFile(uri, outputData);
} catch (error) {
Logger.error(error, 'updateCodeWorkspaceFileSettings');
return false;
}
return true;
}
} }

+ 5
- 0
src/plus/workspaces/workspacesPathMappingProvider.ts View File

@ -28,4 +28,9 @@ export interface WorkspacesPathMappingProvider {
workspaceRepoFilePaths: string[], workspaceRepoFilePaths: string[],
options?: { workspaceId?: string; workspaceSyncSetting?: WorkspaceSyncSetting }, options?: { workspaceId?: string; workspaceSyncSetting?: WorkspaceSyncSetting },
): Promise<boolean>; ): Promise<boolean>;
updateCodeWorkspaceFileSettings(
uri: Uri,
options: { workspaceSyncSetting?: WorkspaceSyncSetting },
): Promise<boolean>;
} }

+ 39
- 0
src/plus/workspaces/workspacesService.ts View File

@ -68,6 +68,10 @@ export class WorkspacesService implements Disposable {
this._disposable.dispose(); this._disposable.dispose();
} }
get currentWorkspaceId(): string | undefined {
return this._currentWorkspaceId;
}
private onSubscriptionChanged(event: SubscriptionChangeEvent): void { private onSubscriptionChanged(event: SubscriptionChangeEvent): void {
if ( if (
event.current.account == null || event.current.account == null ||
@ -1030,6 +1034,41 @@ export class WorkspacesService implements Disposable {
void this.openCodeWorkspaceFile(workspaceId, { location: open.location }); void this.openCodeWorkspaceFile(workspaceId, { location: open.location });
} }
async changeCurrentCodeWorkspaceSyncSetting(): Promise<void> {
if (
workspace.workspaceFile == null ||
this._currentWorkspaceId == null ||
this._currentWorkspaceSyncSetting == null
) {
return;
}
let syncOptions = [
{ title: 'Always', option: WorkspaceSyncSetting.Always },
{ title: 'Never', option: WorkspaceSyncSetting.Never },
{ title: 'Ask every time', option: WorkspaceSyncSetting.Ask },
];
syncOptions = syncOptions.filter(s => s.option !== this._currentWorkspaceSyncSetting);
// Show a quickpick without the current sync setting as an option
const newWorkspaceSyncOption = await window.showQuickPick(
syncOptions.map(s => s.title),
{
placeHolder: 'Choose a new sync setting for this workspace',
},
);
if (newWorkspaceSyncOption == null) return;
const newWorkspaceSyncSetting = syncOptions.find(s => s.title === newWorkspaceSyncOption)?.option;
if (newWorkspaceSyncSetting == null) return;
const updated = await this._workspacesPathProvider.updateCodeWorkspaceFileSettings(workspace.workspaceFile, {
workspaceSyncSetting: newWorkspaceSyncSetting,
});
if (!updated) return;
this._currentWorkspaceSyncSetting = newWorkspaceSyncSetting;
}
async openCodeWorkspaceFile(workspaceId: string, options?: { location?: OpenWorkspaceLocation }): Promise<void> { async openCodeWorkspaceFile(workspaceId: string, options?: { location?: OpenWorkspaceLocation }): Promise<void> {
const workspace = this.getCloudWorkspace(workspaceId) ?? this.getLocalWorkspace(workspaceId); const workspace = this.getCloudWorkspace(workspaceId) ?? this.getLocalWorkspace(workspaceId);
if (workspace == null) return; if (workspace == null) return;

+ 5
- 0
src/views/nodes/repositoriesNode.ts View File

@ -51,6 +51,7 @@ export class RepositoriesNode extends SubscribeableViewNode
getTreeItem(): TreeItem { getTreeItem(): TreeItem {
const isInWorkspacesView = this.view instanceof WorkspacesView; const isInWorkspacesView = this.view instanceof WorkspacesView;
const isSyncedWorkspace = isInWorkspacesView && this.view.container.workspaces.currentWorkspaceId != null;
const item = new TreeItem( const item = new TreeItem(
isInWorkspacesView ? 'Current Window' : 'Repositories', isInWorkspacesView ? 'Current Window' : 'Repositories',
isInWorkspacesView ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.Expanded, isInWorkspacesView ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.Expanded,
@ -65,6 +66,10 @@ export class RepositoriesNode extends SubscribeableViewNode
contextValue += '+workspaces'; contextValue += '+workspaces';
} }
if (isSyncedWorkspace) {
contextValue += '+synced';
}
item.contextValue = contextValue; item.contextValue = contextValue;
return item; return item;
} }

+ 7
- 0
src/views/workspacesView.ts View File

@ -129,6 +129,13 @@ export class WorkspacesView extends ViewBase<'workspaces', WorkspacesViewNode, W
this, this,
), ),
registerViewCommand( registerViewCommand(
this.getQualifiedCommand('changeLocalSync'),
async () => {
await this.container.workspaces.changeCurrentCodeWorkspaceSyncSetting();
},
this,
),
registerViewCommand(
this.getQualifiedCommand('delete'), this.getQualifiedCommand('delete'),
async (node: WorkspaceNode) => { async (node: WorkspaceNode) => {
await this.container.workspaces.deleteCloudWorkspace(node.workspace.id); await this.container.workspaces.deleteCloudWorkspace(node.workspace.id);

Loading…
Cancel
Save