<commit_before>/** @babel */

import {
	CompositeDisposable,
	Disposable,
} from "atom";
import commands from "./commands";
import config from "./config";
import helper from "./helper";
import StatusBarManager from "./widgets/StatusBarManager";
import Notifications from "./Notifications";
import {promisify} from "promisificator";

export default {
	config,

	/**
	 * Activate package
	 * @return {void}
	 */
	activate() {
		this.updateConfig();

		// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
		this.disposables = new CompositeDisposable();
		this.contextMenuDisposables = {};
		this.confirmationDialogs = {};

		for (const command in commands) {
			const cmd = commands[command];

			// observe confirm dialog settings
			if (cmd.confirm) {
				this.disposables.add(atom.config.observe(`git-menu.confirmationDialogs.${command}`, value => {
					this.confirmationDialogs[command] = value;
				}));
			} else {
				this.confirmationDialogs[command] = false;
			}

			// add command
			this.disposables.add(atom.commands.add("atom-workspace", `context-git:${command}`, (event) => {
				Notifications.addError("Deprecated Command", "'context-git:*' commands are deprecated. Please use 'git-menu:*' instead.");
				return this.dispatchCommand(command, cmd)(event);
			}));
			this.disposables.add(atom.commands.add("atom-workspace", `git-menu:${command}`, this.dispatchCommand(command, cmd)));

			if (cmd.label) {
				// add to context menu
				this.disposables.add(atom.config.observe(`git-menu.contextMenuItems.${command}`, value => {
					if (value) {
						this.contextMenuDisposables[command] = atom.contextMenu.add({
							"atom-workspace, atom-text-editor, .tree-view, .tab-bar": [{
								label: "Git",
								submenu: [{
									label: cmd.label.replace("&", "&&"),
									command: `git-menu:${command}`,
								}],
							}],
						});
						this.disposables.add(this.contextMenuDisposables[command]);
					} else {
						if (this.contextMenuDisposables[command]) {
							this.disposables.remove(this.contextMenuDisposables[command]);
							this.contextMenuDisposables[command].dispose();
							delete this.contextMenuDisposables[command];
						}
					}
				}));
			}

			if (cmd.keymap) {
				// add key binding
				atom.keymaps.add("git-menu", {
					"atom-workspace": {
						[cmd.keymap]: `git-menu:${command}`
					}
				});
			}
		}
	},

	/**
	 * Deactivate package
	 * @return {void}
	 */
	deactivate() {
		this.disposables.dispose();
	},

	/**
	 * Copy config from context-git to git-menu
	 * @return {void}
	 */
	updateConfig() {
		try {
			const hasGitMenuConfig = "git-menu" in atom.config.settings;
			const hasContextGitConfig = "context-git" in atom.config.settings;
			if (hasGitMenuConfig || !hasContextGitConfig) {
				return;
			}

			const contextGitConfig = atom.config.getAll("context-git");
			contextGitConfig.forEach((cfg) => {
				let {scopeSelector} = cfg;
				if (scopeSelector === "*") {
					scopeSelector = null;
				}
				for (const key in cfg.value) {
					const value = cfg.value[key];
					atom.config.set(`git-menu.${key}`, value, {scopeSelector});
				}
			});
		} catch (ex) {}
	},

	/**
	 * Consume the status bar service
	 * @param  {mixed} statusBar Status bar service
	 * @return {void}
	 */
	statusBarService(statusBar) {
		if (!this.statusBarManager) {
			this.statusBarManager = new StatusBarManager(statusBar);
			this.disposables.add(new Disposable(() => this.statusBarManager.destroy()));
		}
	},

	dispatchCommand(command, cmd) {
		return async event => {
			const filePaths = helper.getPaths(event.target);

			// show confirm dialog if applicable
			if (this.confirmationDialogs[command]) {
				const {message} = cmd.confirm;
				let {detail} = cmd.confirm;
				if (typeof detail === "function") {
					detail = await detail(filePaths);
				}
				const [, major, minor] = atom.getVersion().match(/^(\d+)\.(\d+)\.(\d+)/);
				let confirmButton, hideDialog;
				if (major > 1 || minor > 24) {
					[confirmButton, hideDialog] = await promisify(atom.confirm.bind(atom), {rejectOnError: false, alwaysReturnArray: true})({
						type: "warning",
						checkboxLabel: "Never Show This Dialog Again",
						message,
						detail,
						buttons: [
							cmd.label,
							"Cancel",
						]
					});
				} else {
					const response = atom.confirm({
						message,
						detailedMessage: detail,
						buttons: [
							cmd.label,
							"Never Show This Dialog Again",
							"Cancel",
						]
					});

					hideDialog = (response === 1);
					confirmButton = (response === 0 ? response : response - 1);
				}

				if (hideDialog) {
					atom.config.set(`git-menu.confirmationDialogs.${command}`, false);
				}
				if (confirmButton === 1) {
					return;
				}
			}

			try {
				// run command
				const {title, message} = await cmd.command(filePaths, this.statusBarManager);
				Notifications.addSuccess(title, message);
			} catch (err) {
				if (err) {
					const message = (err.stack ? err.stack : err.toString());
					Notifications.addError(`Context Git: ${cmd.label}`, message);
				}
			}

			if (this.statusBarManager) {
				this.statusBarManager.hide();
			}
		};
	},
};
<commit_msg>remove context-git:* commands from command palette<commit_after>/** @babel */

import {
	CompositeDisposable,
	Disposable,
} from "atom";
import commands from "./commands";
import config from "./config";
import helper from "./helper";
import StatusBarManager from "./widgets/StatusBarManager";
import Notifications from "./Notifications";
import {promisify} from "promisificator";

export default {
	config,

	/**
	 * Activate package
	 * @return {void}
	 */
	activate() {
		this.updateConfig();

		// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
		this.disposables = new CompositeDisposable();
		this.contextMenuDisposables = {};
		this.confirmationDialogs = {};

		for (const command in commands) {
			const cmd = commands[command];

			// observe confirm dialog settings
			if (cmd.confirm) {
				this.disposables.add(atom.config.observe(`git-menu.confirmationDialogs.${command}`, value => {
					this.confirmationDialogs[command] = value;
				}));
			} else {
				this.confirmationDialogs[command] = false;
			}

			// add command
			this.disposables.add(atom.commands.add("atom-workspace", `context-git:${command}`, {
				didDispatch: (event) => {
					Notifications.addError("Deprecated Command", "'context-git:*' commands are deprecated. Please use 'git-menu:*' instead.");
					return this.dispatchCommand(command, cmd)(event);
				},
				hiddenInCommandPalette: true,
			}));
			this.disposables.add(atom.commands.add("atom-workspace", `git-menu:${command}`, this.dispatchCommand(command, cmd)));

			if (cmd.label) {
				// add to context menu
				this.disposables.add(atom.config.observe(`git-menu.contextMenuItems.${command}`, value => {
					if (value) {
						this.contextMenuDisposables[command] = atom.contextMenu.add({
							"atom-workspace, atom-text-editor, .tree-view, .tab-bar": [{
								label: "Git",
								submenu: [{
									label: cmd.label.replace("&", "&&"),
									command: `git-menu:${command}`,
								}],
							}],
						});
						this.disposables.add(this.contextMenuDisposables[command]);
					} else {
						if (this.contextMenuDisposables[command]) {
							this.disposables.remove(this.contextMenuDisposables[command]);
							this.contextMenuDisposables[command].dispose();
							delete this.contextMenuDisposables[command];
						}
					}
				}));
			}

			if (cmd.keymap) {
				// add key binding
				atom.keymaps.add("git-menu", {
					"atom-workspace": {
						[cmd.keymap]: `git-menu:${command}`
					}
				});
			}
		}
	},

	/**
	 * Deactivate package
	 * @return {void}
	 */
	deactivate() {
		this.disposables.dispose();
	},

	/**
	 * Copy config from context-git to git-menu
	 * @return {void}
	 */
	updateConfig() {
		try {
			const hasGitMenuConfig = "git-menu" in atom.config.settings;
			const hasContextGitConfig = "context-git" in atom.config.settings;
			if (hasGitMenuConfig || !hasContextGitConfig) {
				return;
			}

			const contextGitConfig = atom.config.getAll("context-git");
			contextGitConfig.forEach((cfg) => {
				let {scopeSelector} = cfg;
				if (scopeSelector === "*") {
					scopeSelector = null;
				}
				for (const key in cfg.value) {
					const value = cfg.value[key];
					atom.config.set(`git-menu.${key}`, value, {scopeSelector});
				}
			});
		} catch (ex) {}
	},

	/**
	 * Consume the status bar service
	 * @param  {mixed} statusBar Status bar service
	 * @return {void}
	 */
	statusBarService(statusBar) {
		if (!this.statusBarManager) {
			this.statusBarManager = new StatusBarManager(statusBar);
			this.disposables.add(new Disposable(() => this.statusBarManager.destroy()));
		}
	},

	dispatchCommand(command, cmd) {
		return async event => {
			const filePaths = helper.getPaths(event.target);

			// show confirm dialog if applicable
			if (this.confirmationDialogs[command]) {
				const {message} = cmd.confirm;
				let {detail} = cmd.confirm;
				if (typeof detail === "function") {
					detail = await detail(filePaths);
				}
				const [, major, minor] = atom.getVersion().match(/^(\d+)\.(\d+)\.(\d+)/);
				let confirmButton, hideDialog;
				if (major > 1 || minor > 24) {
					[confirmButton, hideDialog] = await promisify(atom.confirm.bind(atom), {rejectOnError: false, alwaysReturnArray: true})({
						type: "warning",
						checkboxLabel: "Never Show This Dialog Again",
						message,
						detail,
						buttons: [
							cmd.label,
							"Cancel",
						]
					});
				} else {
					const response = atom.confirm({
						message,
						detailedMessage: detail,
						buttons: [
							cmd.label,
							"Never Show This Dialog Again",
							"Cancel",
						]
					});

					hideDialog = (response === 1);
					confirmButton = (response === 0 ? response : response - 1);
				}

				if (hideDialog) {
					atom.config.set(`git-menu.confirmationDialogs.${command}`, false);
				}
				if (confirmButton === 1) {
					return;
				}
			}

			try {
				// run command
				const {title, message} = await cmd.command(filePaths, this.statusBarManager);
				Notifications.addSuccess(title, message);
			} catch (err) {
				if (err) {
					const message = (err.stack ? err.stack : err.toString());
					Notifications.addError(`Context Git: ${cmd.label}`, message);
				}
			}

			if (this.statusBarManager) {
				this.statusBarManager.hide();
			}
		};
	},
};

{'fraction_non_alphanumeric': 0.15517077347540673, 'fraction_numerical': 0.0013319379697459804, 'mean_word_length': 2.9878603945371776, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 19, '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': '6218227', 'n_tokens_mistral': 4270, 'n_tokens_neox': 3267, 'n_words': 684}