diff --git a/CHANGELOG.md b/CHANGELOG.md index b178cec..fa179c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Improves startup performance and reduces package size ### Fixed +- Fixes [#239](https://github.com/eamodio/vscode-gitlens/issues/239) - `gitlens.advanced.quickPick.closeOnFocusOut` setting should be reversed - Fixes [#208](https://github.com/eamodio/vscode-gitlens/issues/208) - Gitlens doesn't work over UNC ## [7.1.0] - 2017-12-22 diff --git a/src/configuration.ts b/src/configuration.ts index 2554eb7..ae2354d 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -526,8 +526,10 @@ export class Configuration { affectsConfiguration: (section: string, resource?: Uri) => false }; - get(section?: string, resource?: Uri | null) { - return workspace.getConfiguration(section === undefined ? undefined : ExtensionKey, resource!).get(section === undefined ? ExtensionKey : section)!; + get(section?: string, resource?: Uri | null, defaultValue?: T) { + return defaultValue === undefined + ? workspace.getConfiguration(section === undefined ? undefined : ExtensionKey, resource!).get(section === undefined ? ExtensionKey : section)! + : workspace.getConfiguration(section === undefined ? undefined : ExtensionKey, resource!).get(section === undefined ? ExtensionKey : section, defaultValue)!; } changed(e: ConfigurationChangeEvent, section: string, resource?: Uri | null) { @@ -538,6 +540,10 @@ export class Configuration { return e === this.initializingChangeEvent; } + inspect(section?: string, resource?: Uri | null) { + return workspace.getConfiguration(section === undefined ? undefined : ExtensionKey, resource!).inspect(section === undefined ? ExtensionKey : section); + } + name(name: K) { return Functions.propOf(emptyConfig, name); } diff --git a/src/extension.ts b/src/extension.ts index f0a9f2b..2eddd7a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Objects } from './system'; +import { Objects, Versions } from './system'; import { ConfigurationTarget, ExtensionContext, extensions, languages, window, workspace } from 'vscode'; import { AnnotationController } from './annotations/annotationController'; import { configuration, Configuration, IConfig } from './configuration'; @@ -100,37 +100,51 @@ export async function activate(context: ExtensionContext) { // this method is called when your extension is deactivated export function deactivate() { } -const migration = { - major: 6, - minor: 1, - patch: 2 -}; - async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) { if (previousVersion === undefined) return; - const [major, minor, patch] = previousVersion.split('.'); - if (parseInt(major, 10) >= migration.major && parseInt(minor, 10) >= migration.minor && parseInt(patch, 10) >= migration.patch) return; + const previous = Versions.fromString(previousVersion); try { - const section = configuration.name('advanced')('messages').value; - const messages: { [key: string]: boolean } = configuration.get(section); + if (Versions.compare(previous, Versions.from(6, 1, 2)) !== 1) { + try { + const section = configuration.name('advanced')('messages').value; + const messages: { [key: string]: boolean } = configuration.get(section); - let migrated = false; + let migrated = false; - for (const m of Objects.values(SuppressedMessages)) { - const suppressed = context.globalState.get(m); - if (suppressed === undefined) continue; + for (const m of Objects.values(SuppressedMessages)) { + const suppressed = context.globalState.get(m); + if (suppressed === undefined) continue; - migrated = true; - messages[m] = suppressed; + migrated = true; + messages[m] = suppressed; - context.globalState.update(m, undefined); - } + context.globalState.update(m, undefined); + } - if (!migrated) return; + if (!migrated) return; - await configuration.update(section, messages, ConfigurationTarget.Global); + await configuration.update(section, messages, ConfigurationTarget.Global); + } + catch (ex) { + Logger.error(ex, 'migrateSettings - messages'); + } + } + + if (Versions.compare(previous, Versions.from(7, 1, 0)) !== 1) { + // https://github.com/eamodio/vscode-gitlens/issues/239 + const section = configuration.name('advanced')('quickPick')('closeOnFocusOut').value; + const inspection = configuration.inspect(section); + if (inspection !== undefined) { + if (inspection.globalValue !== undefined) { + await configuration.update(section, !inspection.globalValue, ConfigurationTarget.Global); + } + else if (inspection.workspaceFolderValue !== undefined) { + await configuration.update(section, !inspection.workspaceFolderValue, ConfigurationTarget.WorkspaceFolder); + } + } + } } catch (ex) { Logger.error(ex, 'migrateSettings'); diff --git a/src/quickPicks/common.ts b/src/quickPicks/common.ts index 740090d..b0746cc 100644 --- a/src/quickPicks/common.ts +++ b/src/quickPicks/common.ts @@ -10,7 +10,7 @@ import { Keyboard, KeyboardScope, KeyMapping, Keys } from '../keyboard'; import { ResultsExplorer } from '../views/resultsExplorer'; export function getQuickPickIgnoreFocusOut() { - return configuration.get(configuration.name('advanced')('quickPick')('closeOnFocusOut').value); + return !configuration.get(configuration.name('advanced')('quickPick')('closeOnFocusOut').value); } export function showQuickPickProgress(message: string, mapping?: KeyMapping): CancellationTokenSource { diff --git a/src/system.ts b/src/system.ts index 11ed5a1..3c2aac0 100644 --- a/src/system.ts +++ b/src/system.ts @@ -14,3 +14,4 @@ export * from './system/iterable'; export * from './system/object'; export * from './system/searchTree'; export * from './system/string'; +export * from './system/version'; diff --git a/src/system/version.ts b/src/system/version.ts new file mode 100644 index 0000000..94acc6a --- /dev/null +++ b/src/system/version.ts @@ -0,0 +1,35 @@ +'use strict'; + +export namespace Versions { + export interface Version { + major: number; + minor: number; + patch: number; + } + + export function compare(v1: Version, v2: Version): number { + if (v1.major > v2.major) return 1; + if (v1.major < v2.major) return -1; + + if (v1.minor > v2.minor) return 1; + if (v1.minor < v2.minor) return -1; + + if (v1.patch > v2.patch) return 1; + if (v1.patch < v2.patch) return -1; + + return 0; + } + + export function from(major: string | number, minor: string | number, patch: string | number): Version { + return { + major: typeof major === 'string' ? parseInt(major, 10) : major, + minor: typeof minor === 'string' ? parseInt(minor, 10) : minor, + patch: typeof patch === 'string' ? parseInt(patch, 10) : patch + }; + } + + export function fromString(version: string): Version { + const [major, minor, patch] = version.split('.'); + return from(major, minor, patch); + } +} \ No newline at end of file