Browse Source

Renames constants

main
Eric Amodio 1 year ago
parent
commit
8136c4c275
7 changed files with 48 additions and 41 deletions
  1. +2
    -2
      src/commands/resetViewsLayout.ts
  2. +22
    -18
      src/constants.ts
  3. +4
    -4
      src/eventBus.ts
  4. +3
    -3
      src/system/webview.ts
  5. +2
    -2
      src/views/viewBase.ts
  6. +8
    -5
      src/webviews/webviewController.ts
  7. +7
    -7
      src/webviews/webviewsController.ts

+ 2
- 2
src/commands/resetViewsLayout.ts View File

@ -1,4 +1,4 @@
import type { QualifiedViewIds } from '../constants';
import type { ViewIds } from '../constants';
import { Commands, viewIdsByDefaultContainerId } from '../constants';
import type { Container } from '../container';
import { command, executeCoreCommand } from '../system/command';
@ -19,7 +19,7 @@ export class ResetViewsLayoutCommand extends Command {
for (const [containerId, viewIds] of viewIdsByDefaultContainerId) {
try {
void (await executeCoreCommand('vscode.moveViews', {
viewIds: viewIds.map<QualifiedViewIds>(v => `gitlens.views.${v}`),
viewIds: viewIds.map<ViewIds>(v => `gitlens.views.${v}`),
destinationId: containerId,
}));
} catch {}

+ 22
- 18
src/constants.ts View File

@ -314,8 +314,10 @@ export const enum Commands {
Deprecated_ShowFileHistoryInView = 'gitlens.showFileHistoryInView',
}
export type CustomEditorIds = 'rebase';
export type TreeViewIds =
export type CustomEditorTypes = 'rebase';
export type CustomEditorIds = `gitlens.${CustomEditorTypes}`;
export type TreeViewTypes =
| 'branches'
| 'commits'
| 'contributors'
@ -328,19 +330,24 @@ export type TreeViewIds =
| 'tags'
| 'workspaces'
| 'worktrees';
export type WebviewIds = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus';
export type WebviewViewIds = 'account' | 'commitDetails' | 'graph' | 'graphDetails' | 'home' | 'timeline';
export type TreeViewIds = `gitlens.views.${TreeViewTypes}`;
export type WebviewTypes = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus';
export type WebviewIds = `gitlens.views.${WebviewTypes}`;
export type WebviewViewTypes = 'account' | 'commitDetails' | 'graph' | 'graphDetails' | 'home' | 'timeline';
export type WebviewViewIds = `gitlens.views.${WebviewViewTypes}`;
export type ViewTypes = TreeViewTypes | WebviewViewTypes;
export type ViewIds = TreeViewIds | WebviewViewIds;
export type QualifiedViewIds = `gitlens.views.${ViewIds}`;
export type ViewContainerIds = 'gitlens' | 'gitlensInspect' | 'gitlensPanel';
export type QualifiedViewContainerIds = `workbench.view.extension.${ViewContainerIds}`;
export type ViewContainerTypes = 'gitlens' | 'gitlensInspect' | 'gitlensPanel';
export type ViewContainerIds = `workbench.view.extension.${ViewContainerTypes}`;
export type CoreViewContainerIds = 'scm';
export type QualifiedCoreViewContainerIds = `workbench.view.${CoreViewContainerIds}`;
export type CoreViewContainerTypes = 'scm';
export type CoreViewContainerIds = `workbench.view.${CoreViewContainerTypes}`;
// export const viewIds: ViewIds[] = [
// export const viewTypes: ViewTypes[] = [
// 'account',
// 'branches',
// 'commits',
@ -361,10 +368,7 @@ export type QualifiedCoreViewContainerIds = `workbench.view.${CoreViewContainerI
// 'worktrees',
// ];
export const viewIdsByDefaultContainerId = new Map<
QualifiedViewContainerIds | QualifiedCoreViewContainerIds,
ViewIds[]
>([
export const viewIdsByDefaultContainerId = new Map<ViewContainerIds | CoreViewContainerIds, ViewTypes[]>([
[
'workbench.view.scm',
['branches', 'commits', 'remotes', 'repositories', 'stashes', 'tags', 'worktrees', 'contributors'],
@ -380,12 +384,12 @@ export const viewIdsByDefaultContainerId = new Map<
export type ContextKeys =
| `${typeof extensionPrefix}:action:${string}`
| `${typeof extensionPrefix}:key:${Keys}`
| `${typeof extensionPrefix}:webview:${WebviewIds | CustomEditorIds}:${
| `${typeof extensionPrefix}:webview:${WebviewTypes | CustomEditorTypes}:${
| 'active'
| 'focus'
| 'inputFocus'
| 'visible'}`
| `${typeof extensionPrefix}:webviewView:${WebviewViewIds}:${'active' | 'focus' | 'inputFocus' | 'visible'}`
| `${typeof extensionPrefix}:webviewView:${WebviewViewTypes}:${'active' | 'focus' | 'inputFocus' | 'visible'}`
| `${typeof extensionPrefix}:activeFileStatus`
| `${typeof extensionPrefix}:annotationStatus`
| `${typeof extensionPrefix}:debugging`
@ -446,8 +450,8 @@ export type CoreCommands =
| 'workbench.files.action.focusFilesExplorer'
| 'workbench.view.explorer'
| 'workbench.view.scm'
| `${QualifiedViewContainerIds | QualifiedCoreViewContainerIds}.resetViewContainerLocation`
| `${QualifiedViewIds}.${'focus' | 'removeView' | 'resetViewLocation' | 'toggleVisibility'}`;
| `${ViewContainerIds | CoreViewContainerIds}.resetViewContainerLocation`
| `${ViewIds}.${'focus' | 'removeView' | 'resetViewLocation' | 'toggleVisibility'}`;
export type CoreGitCommands =
| 'git.fetch'

+ 4
- 4
src/eventBus.ts View File

@ -1,7 +1,7 @@
import type { Disposable, Uri } from 'vscode';
import { EventEmitter } from 'vscode';
import type { ViewsConfigKeys } from './config';
import type { CustomEditorIds, WebviewIds, WebviewViewIds } from './constants';
import type { CustomEditorTypes, WebviewTypes, WebviewViewTypes } from './constants';
import type { GitCaches } from './git/gitProvider';
import type { GitCommit } from './git/models/commit';
import type { GitRevisionReference } from './git/models/reference';
@ -40,9 +40,9 @@ interface EventBusEvent {
}
export type EventBusSource =
| `gitlens.${CustomEditorIds}`
| `gitlens.${WebviewIds}`
| `gitlens.views.${WebviewViewIds}`
| `gitlens.${CustomEditorTypes}`
| `gitlens.${WebviewTypes}`
| `gitlens.views.${WebviewViewTypes}`
| `gitlens.views.${ViewsConfigKeys}`;
export type EventBusOptions = {

+ 3
- 3
src/system/webview.ts View File

@ -1,7 +1,7 @@
import type { WebviewIds, WebviewViewIds } from '../constants';
import type { WebviewTypes, WebviewViewTypes } from '../constants';
export interface WebviewItemContext<TValue = unknown> {
webview?: `gitlens.${WebviewIds}` | `gitlens.views.${WebviewViewIds}`;
webview?: `gitlens.${WebviewTypes}` | `gitlens.views.${WebviewViewTypes}`;
webviewItem: string;
webviewItemValue: TValue;
}
@ -15,7 +15,7 @@ export function isWebviewItemContext(
}
export interface WebviewItemGroupContext<TValue = unknown> {
webview?: `gitlens.${WebviewIds}` | `gitlens.views.${WebviewViewIds}`;
webview?: `gitlens.${WebviewTypes}` | `gitlens.views.${WebviewViewTypes}`;
webviewItemGroup: string;
webviewItemGroupValue: TValue;
}

+ 2
- 2
src/views/viewBase.ts View File

@ -28,7 +28,7 @@ import type {
WorktreesViewConfig,
} from '../config';
import { viewsCommonConfigKeys, viewsConfigKeys } from '../config';
import type { TreeViewIds } from '../constants';
import type { TreeViewTypes } from '../constants';
import type { Container } from '../container';
import { executeCoreCommand } from '../system/command';
import { configuration } from '../system/configuration';
@ -138,7 +138,7 @@ export abstract class ViewBase<
constructor(
public readonly container: Container,
public readonly id: `gitlens.views.${TreeViewIds}`,
public readonly id: `gitlens.views.${TreeViewTypes}`,
public readonly name: string,
private readonly trackingFeature: TrackedUsageFeatures,
) {

+ 8
- 5
src/webviews/webviewController.ts View File

@ -1,7 +1,7 @@
import type { ViewBadge, Webview, WebviewPanel, WebviewView, WindowState } from 'vscode';
import { Disposable, EventEmitter, Uri, ViewColumn, window, workspace } from 'vscode';
import { getNonce } from '@env/crypto';
import type { Commands, CustomEditorIds, WebviewIds, WebviewViewIds } from '../constants';
import type { Commands, CustomEditorTypes, WebviewTypes, WebviewViewTypes } from '../constants';
import type { Container } from '../container';
import { executeCommand, executeCoreCommand } from '../system/command';
import { setContext } from '../system/context';
@ -585,18 +585,18 @@ export function replaceWebviewHtmlTokens(
}
export function resetContextKeys(
contextKeyPrefix: `gitlens:webview:${WebviewIds | CustomEditorIds}` | `gitlens:webviewView:${WebviewViewIds}`,
contextKeyPrefix: `gitlens:webview:${WebviewTypes | CustomEditorTypes}` | `gitlens:webviewView:${WebviewViewTypes}`,
): void {
void setContext(`${contextKeyPrefix}:visible`, false);
void setContext(`${contextKeyPrefix}:inputFocus`, false);
void setContext(`${contextKeyPrefix}:focus`, false);
if (contextKeyPrefix.startsWith('gitlens:webview:')) {
void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewIds | CustomEditorIds}`}:active`, false);
void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewTypes | CustomEditorTypes}`}:active`, false);
}
}
export function setContextKeys(
contextKeyPrefix: `gitlens:webview:${WebviewIds | CustomEditorIds}` | `gitlens:webviewView:${WebviewViewIds}`,
contextKeyPrefix: `gitlens:webview:${WebviewTypes | CustomEditorTypes}` | `gitlens:webviewView:${WebviewViewTypes}`,
active?: boolean,
focus?: boolean,
inputFocus?: boolean,
@ -604,7 +604,10 @@ export function setContextKeys(
void setContext(`${contextKeyPrefix}:visible`, true);
if (contextKeyPrefix.startsWith('gitlens:webview:')) {
if (active != null) {
void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewIds | CustomEditorIds}`}:active`, active);
void setContext(
`${contextKeyPrefix as `gitlens:webview:${WebviewTypes | CustomEditorTypes}`}:active`,
active,
);
if (!active) {
focus = false;

+ 7
- 7
src/webviews/webviewsController.ts View File

@ -7,7 +7,7 @@ import type {
WebviewViewResolveContext,
} from 'vscode';
import { Disposable, Uri, ViewColumn, window } from 'vscode';
import type { Commands, WebviewIds, WebviewViewIds } from '../constants';
import type { Commands, WebviewTypes, WebviewViewTypes } from '../constants';
import type { Container } from '../container';
import { ensurePlusFeaturesEnabled } from '../plus/subscription/utils';
import { executeCoreCommand, registerCommand } from '../system/command';
@ -19,11 +19,11 @@ import type { WebviewProvider } from './webviewController';
import { WebviewController } from './webviewController';
export interface WebviewPanelDescriptor {
id: `gitlens.${WebviewIds}`;
id: `gitlens.${WebviewTypes}`;
readonly fileName: string;
readonly iconPath: string;
readonly title: string;
readonly contextKeyPrefix: `gitlens:webview:${WebviewIds}`;
readonly contextKeyPrefix: `gitlens:webview:${WebviewTypes}`;
readonly trackingFeature: TrackedUsageFeatures;
readonly plusFeature: boolean;
readonly column?: ViewColumn;
@ -37,7 +37,7 @@ interface WebviewPanelRegistration {
}
export interface WebviewPanelProxy extends Disposable {
readonly id: `gitlens.${WebviewIds}`;
readonly id: `gitlens.${WebviewTypes}`;
readonly ready: boolean;
readonly visible: boolean;
close(): void;
@ -46,10 +46,10 @@ export interface WebviewPanelProxy extends Disposable {
}
export interface WebviewViewDescriptor {
id: `gitlens.views.${WebviewViewIds}`;
id: `gitlens.views.${WebviewViewTypes}`;
readonly fileName: string;
readonly title: string;
readonly contextKeyPrefix: `gitlens:webviewView:${WebviewViewIds}`;
readonly contextKeyPrefix: `gitlens:webviewView:${WebviewViewTypes}`;
readonly trackingFeature: TrackedUsageFeatures;
readonly plusFeature: boolean;
readonly webviewOptions?: WebviewOptions;
@ -65,7 +65,7 @@ interface WebviewViewRegistration {
}
export interface WebviewViewProxy extends Disposable {
readonly id: `gitlens.views.${WebviewViewIds}`;
readonly id: `gitlens.views.${WebviewViewTypes}`;
readonly ready: boolean;
readonly visible: boolean;
refresh(force?: boolean): Promise<void>;

Loading…
Cancel
Save