Skip to content

Commit

Permalink
Better openDiffOnClick+showInlineOpenFileActions (#6552)
Browse files Browse the repository at this point in the history
Part of #6515
  • Loading branch information
alexr00 authored Dec 17, 2024
1 parent 25db419 commit e24cd86
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2444,12 +2444,12 @@
{
"command": "review.openFile",
"group": "inline@0",
"when": "openDiffOnClick && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/ && config.git.showInlineOpenFileAction"
"when": "openDiffOnClick && showInlineOpenFileAction && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/"
},
{
"command": "pr.openDiffView",
"group": "inline@0",
"when": "!openDiffOnClick && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/"
"when": "!openDiffOnClick && showInlineOpenFileAction && view == prStatus:github && viewItem =~ /filechange(?!:DELETE)/"
},
{
"command": "pr.openFileOnGitHub",
Expand Down
1 change: 1 addition & 0 deletions src/common/settingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const EXPERIMENTAL_NOTIFICATIONS_SCORE = 'experimental.notificationsScore
export const GIT = 'git';
export const PULL_BEFORE_CHECKOUT = 'pullBeforeCheckout';
export const OPEN_DIFF_ON_CLICK = 'openDiffOnClick';
export const SHOW_INLINE_OPEN_FILE_ACTION = 'showInlineOpenFileAction';
export const AUTO_STASH = 'autoStash';

// GitHub Enterprise
Expand Down
21 changes: 18 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Logger from './common/logger';
import * as PersistentState from './common/persistentState';
import { parseRepositoryRemotes } from './common/remote';
import { Resource } from './common/resources';
import { BRANCH_PUBLISH, EXPERIMENTAL_CHAT, EXPERIMENTAL_NOTIFICATIONS, FILE_LIST_LAYOUT, GIT, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE } from './common/settingKeys';
import { BRANCH_PUBLISH, EXPERIMENTAL_CHAT, EXPERIMENTAL_NOTIFICATIONS, FILE_LIST_LAYOUT, GIT, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE, SHOW_INLINE_OPEN_FILE_ACTION } from './common/settingKeys';
import { TemporaryState } from './common/temporaryState';
import { Schemes, handler as uriHandler } from './common/uri';
import { EXTENSION_ID, FOCUS_REVIEW_MODE } from './constants';
Expand Down Expand Up @@ -286,8 +286,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<GitApi
await commands.focusView('github:activePullRequest:welcome');
showPRController.shouldShow = shouldShow;
});
const openDiff = vscode.workspace.getConfiguration(GIT, null).get(OPEN_DIFF_ON_CLICK, true);
await vscode.commands.executeCommand('setContext', 'openDiffOnClick', openDiff);
await setGitSettingContexts(context);

// initialize resources
Resource.initialize(context);
Expand All @@ -302,6 +301,22 @@ export async function activate(context: vscode.ExtensionContext): Promise<GitApi
return apiImpl;
}

async function setGitSettingContexts(context: vscode.ExtensionContext) {
// We set contexts instead of using the config directly in package.json because the git extension might not actually be available.
const settings: [string, () => void][] = [
['openDiffOnClick', () => vscode.workspace.getConfiguration(GIT, null).get(OPEN_DIFF_ON_CLICK, true)],
['showInlineOpenFileAction', () => vscode.workspace.getConfiguration(GIT, null).get(SHOW_INLINE_OPEN_FILE_ACTION, true)]
];
for (const [contextName, setting] of settings) {
commands.setContext(contextName, setting());
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(`${GIT}.${contextName}`)) {
commands.setContext(contextName, setting());
}
}));
}
}

async function doRegisterBuiltinGitProvider(context: vscode.ExtensionContext, credentialStore: CredentialStore, apiImpl: GitApiImpl): Promise<boolean> {
const builtInGitProvider = await registerBuiltinGitProvider(credentialStore, apiImpl);
if (builtInGitProvider) {
Expand Down

0 comments on commit e24cd86

Please sign in to comment.