<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/registry/common/platform';
import { IViewsRegistry, Extensions, ITreeViewDescriptor, ITreeViewDataProvider, ITreeItem, TreeItemCollapsibleState, IViewsService, TreeViewItemHandleArg } from 'vs/workbench/common/views';
import { localize } from 'vs/nls';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { CustomTreeViewPane, CustomTreeView } from 'vs/workbench/browser/parts/views/customView';
import { VIEW_CONTAINER } from 'vs/workbench/contrib/files/browser/explorerViewlet';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ALL_RESOURCE_KEYS, CONTEXT_SYNC_ENABLEMENT, IUserDataSyncStoreService, USER_DATA_SYNC_SCHEME, ResourceKey } from 'vs/platform/userDataSync/common/userDataSync';
import { registerAction2, Action2, MenuId } from 'vs/platform/actions/common/actions';
import { IContextKeyService, RawContextKey, ContextKeyExpr, ContextKeyEqualsExpr } from 'vs/platform/contextkey/common/contextkey';
import { URI } from 'vs/base/common/uri';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { FolderThemeIcon, FileThemeIcon } from 'vs/platform/theme/common/themeService';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';

const CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW = new RawContextKey<boolean>('showUserDataSyncHistoryView', false);

export class UserDataSyncHistoryViewContribution implements IWorkbenchContribution {

	private readonly viewId = 'workbench.views.syncHistory';

	constructor(
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IContextKeyService private readonly contextKeyService: IContextKeyService,
	) {
		this.registerView();
		this.registerActions();
	}

	private registerView(): void {
		const that = this;
		const name = localize('title', "Sync History");
		const viewEnablementContext = CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW.bindTo(this.contextKeyService);
		const treeView = this.instantiationService.createInstance(CustomTreeView, this.viewId, name);
		const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
		viewsRegistry.registerViews([<ITreeViewDescriptor>{
			id: this.viewId,
			name,
			ctorDescriptor: new SyncDescriptor(CustomTreeViewPane),
			when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW),
			canToggleVisibility: false,
			canMoveView: true,
			treeView,
			collapsed: false,
			order: 100,
		}], VIEW_CONTAINER);

		registerAction2(class extends Action2 {
			constructor() {
				super({
					id: 'workbench.actions.showSyncHistory',
					title: { value: localize('workbench.action.showRemoteUserDatraView', "Show Sync History"), original: `Show Sync History` },
					category: { value: localize('sync', "Sync"), original: `Sync` },
					menu: {
						id: MenuId.CommandPalette,
						when: CONTEXT_SYNC_ENABLEMENT
					},
				});
			}
			async run(accessor: ServicesAccessor): Promise<void> {
				const instantiationService = accessor.get(IInstantiationService);
				const viewsService = accessor.get(IViewsService);
				if (!treeView.dataProvider) {
					treeView.dataProvider = instantiationService.createInstance(UserDataSyncHistoryViewDataProvider);
				}
				viewEnablementContext.set(true);
				viewsService.openView(that.viewId, true);
			}
		});
	}

	private registerActions() {
		const that = this;
		registerAction2(class extends Action2 {
			constructor() {
				super({
					id: 'workbench.actions.openRef',
					title: localize('workbench.action.openRef', "Open Ref"),
				});
			}
			async run(accessor: ServicesAccessor, resource: URI): Promise<void> {
				const editorService = accessor.get(IEditorService);
				await editorService.openEditor({ resource });
			}
		});
		registerAction2(class extends Action2 {
			constructor() {
				super({
					id: 'workbench.actions.deleteRef',
					title: localize('workbench.action.deleteRef', "Delete"),
					menu: {
						id: MenuId.ViewItemContext,<commit_msg>set data provide on tree visibility<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/registry/common/platform';
import { IViewsRegistry, Extensions, ITreeViewDescriptor, ITreeViewDataProvider, ITreeItem, TreeItemCollapsibleState, IViewsService, TreeViewItemHandleArg } from 'vs/workbench/common/views';
import { localize } from 'vs/nls';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { CustomTreeViewPane, CustomTreeView } from 'vs/workbench/browser/parts/views/customView';
import { VIEW_CONTAINER } from 'vs/workbench/contrib/files/browser/explorerViewlet';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ALL_RESOURCE_KEYS, CONTEXT_SYNC_ENABLEMENT, IUserDataSyncStoreService, USER_DATA_SYNC_SCHEME, ResourceKey } from 'vs/platform/userDataSync/common/userDataSync';
import { registerAction2, Action2, MenuId } from 'vs/platform/actions/common/actions';
import { IContextKeyService, RawContextKey, ContextKeyExpr, ContextKeyEqualsExpr } from 'vs/platform/contextkey/common/contextkey';
import { URI } from 'vs/base/common/uri';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { FolderThemeIcon, FileThemeIcon } from 'vs/platform/theme/common/themeService';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';

const CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW = new RawContextKey<boolean>('showUserDataSyncHistoryView', false);

export class UserDataSyncHistoryViewContribution implements IWorkbenchContribution {

	private readonly viewId = 'workbench.views.syncHistory';

	constructor(
		@IInstantiationService private readonly instantiationService: IInstantiationService,
		@IContextKeyService private readonly contextKeyService: IContextKeyService,
	) {
		this.registerView();
		this.registerActions();
	}

	private registerView(): void {
		const that = this;
		const name = localize('title', "Sync History");
		const viewEnablementContext = CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW.bindTo(this.contextKeyService);
		const treeView = this.instantiationService.createInstance(CustomTreeView, this.viewId, name);
		const disposable = treeView.onDidChangeVisibility(visible => {
			if (visible && !treeView.dataProvider) {
				disposable.dispose();
				treeView.dataProvider = this.instantiationService.createInstance(UserDataSyncHistoryViewDataProvider);
			}
		});
		const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
		viewsRegistry.registerViews([<ITreeViewDescriptor>{
			id: this.viewId,
			name,
			ctorDescriptor: new SyncDescriptor(CustomTreeViewPane),
			when: ContextKeyExpr.and(CONTEXT_SYNC_ENABLEMENT, CONTEXT_SHOW_USER_DATA_SYNC_HISTORY_VIEW),
			canToggleVisibility: false,
			canMoveView: true,
			treeView,
			collapsed: false,
			order: 100,
		}], VIEW_CONTAINER);

		registerAction2(class extends Action2 {
			constructor() {
				super({
					id: 'workbench.actions.showSyncHistory',
					title: { value: localize('workbench.action.showRemoteUserDatraView', "Show Sync History"), original: `Show Sync History` },
					category: { value: localize('sync', "Sync"), original: `Sync` },
					menu: {
						id: MenuId.CommandPalette,
						when: CONTEXT_SYNC_ENABLEMENT
					},
				});
			}
			async run(accessor: ServicesAccessor): Promise<void> {
				viewEnablementContext.set(true);
				accessor.get(IViewsService).openView(that.viewId, true);
			}
		});
	}

	private registerActions() {
		const that = this;
		registerAction2(class extends Action2 {
			constructor() {
				super({
					id: 'workbench.actions.openRef',
					title: localize('workbench.action.openRef', "Open Ref"),
				});
			}
			async run(accessor: ServicesAccessor, resource: URI): Promise<void> {
				const editorService = accessor.get(IEditorService);
				await editorService.openEditor({ resource });
			}
		});
		registerAction2(class extends Action2 {
			constructor() {
				super({
					id: 'workbench.actions.deleteRef',
					title: localize('workbench.action.deleteRef', "Delete"),
					menu: {
						id: MenuId.ViewItemContext,
{'fraction_non_alphanumeric': 0.14386506449123582, 'fraction_numerical': 0.0024253114320361593, 'mean_word_length': 4.289795918367347, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6440831', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2558, 'n_words': 515}