#134 - Promote settings question

This commit is contained in:
Elio Struyf
2021-10-05 13:26:11 +02:00
parent 014911b7a9
commit 1d8c192c07
4 changed files with 44 additions and 4 deletions
+1
View File
@@ -19,6 +19,7 @@
- [#127](https://github.com/estruyf/vscode-front-matter/issues/127): Title bar action added to open the dashboard
- [#128](https://github.com/estruyf/vscode-front-matter/issues/128): Support for multi-select on image fields added
- [#131](https://github.com/estruyf/vscode-front-matter/issues/131): Folder creation support added on media dashboard
- [#134](https://github.com/estruyf/vscode-front-matter/issues/134): On startup, the extension checks if local settings can be promoted
### 🐞 Fixes
+2 -1
View File
@@ -2,5 +2,6 @@
export const ExtensionState = {
PagesView: `frontMatter:Pages:ViewType`,
SelectedFolder: `frontMatter:SelectedFolder`,
Version: `frontMatter:Version`
Version: `frontMatter:Version`,
SettingPromoted: `frontMatter:Settings:Promoted`
};
+2
View File
@@ -34,6 +34,8 @@ export async function activate(context: vscode.ExtensionContext) {
SettingsHelper.init();
extension.migrateSettings();
SettingsHelper.checkToPromote();
collection = vscode.languages.createDiagnosticCollection('frontMatter');
+39 -3
View File
@@ -1,8 +1,8 @@
import { Notifications } from './Notifications';
import { commands, Uri, workspace } from 'vscode';
import { commands, Uri, workspace, window } from 'vscode';
import * as vscode from 'vscode';
import { TaxonomyType } from '../models';
import { SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, CONFIG_KEY, CONTEXT, SETTINGS_CONTENT_STATIC_FOLDER } from '../constants';
import { ContentType, TaxonomyType } from '../models';
import { SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, CONFIG_KEY, CONTEXT, SETTINGS_CONTENT_STATIC_FOLDER, ExtensionState } from '../constants';
import { Folders } from '../commands/Folders';
import { join, basename } from 'path';
import { existsSync, readFileSync, watch, writeFileSync } from 'fs';
@@ -34,6 +34,26 @@ export class Settings {
});
}
/**
* Check if the setting is present in the workspace and ask to promote them to the global settings
*/
public static async checkToPromote() {
const isPromoted = await Extension.getInstance().getState<boolean | undefined>(ExtensionState.SettingPromoted);
if (!isPromoted) {
if (Settings.hasSettings()) {
window.showInformationMessage(`You have local settings. Would you like to promote them to the global settings ("frontmatter.json")?`, 'Yes', 'No').then(async (result) => {
if (result === "Yes") {
Settings.promote();
}
if (result === "No" || result === "Yes") {
Extension.getInstance().setState(ExtensionState.SettingPromoted, true);
}
});
}
}
}
/**
* Check for config changes on global and local settings
* @param callback
@@ -116,6 +136,12 @@ export class Settings {
Settings.globalConfig = JSON.parse(localConfig);
Settings.globalConfig[`${CONFIG_KEY}.${name}`] = value;
writeFileSync(fmConfig, JSON.stringify(Settings.globalConfig, null, 2), 'utf8');
const workspaceSettingValue = Settings.hasWorkspaceSettings<ContentType[]>(name);
if (workspaceSettingValue) {
await Settings.update(name, undefined);
}
return;
}
} else {
@@ -199,6 +225,16 @@ export class Settings {
Notifications.info(`All settings promoted to team level.`);
}
/**
* Check if the setting is present in the workspace
* @param name
* @returns
*/
public static hasWorkspaceSettings<T>(name: string): T | undefined {
const setting = Settings.config.inspect<T>(name);
return (setting && typeof setting.workspaceValue !== "undefined") ? setting.workspaceValue : undefined;
}
/**
* Check if there are any Front Matter settings in the workspace
* @returns