mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-06 17:02:54 +02:00
#110 - Support for workspaces with multiple folders
This commit is contained in:
+2
-1
@@ -1,6 +1,6 @@
|
||||
# Change Log
|
||||
|
||||
## [4.1.0] - 2021-XX-XX
|
||||
## [4.1.0] - 2021-XX-XX - [Release Notes](https://beta.frontmatter.codes/updates/v4.1.0)
|
||||
|
||||
### ✨ New features
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
### 🎨 Enhancements
|
||||
|
||||
- [#110](https://github.com/estruyf/vscode-front-matter/issues/110): Add support for workspaces with multiple folders
|
||||
- [#117](https://github.com/estruyf/vscode-front-matter/issues/117): Allow to specify a singleline of text in the metadata fields
|
||||
- [#119](https://github.com/estruyf/vscode-front-matter/issues/119): Multi-select support for choice fields
|
||||
- [#121](https://github.com/estruyf/vscode-front-matter/issues/121): Choice fields support ID/title objects as well as a regular string
|
||||
|
||||
+25
-2
@@ -6,6 +6,7 @@ import uniqBy = require("lodash.uniqby");
|
||||
import { Template } from "./Template";
|
||||
import { Notifications } from "../helpers/Notifications";
|
||||
import { Settings } from "../helpers";
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
export const WORKSPACE_PLACEHOLDER = `[[workspace]]`;
|
||||
|
||||
@@ -114,8 +115,31 @@ export class Folders {
|
||||
*/
|
||||
public static getWorkspaceFolder(): Uri | undefined {
|
||||
const folders = workspace.workspaceFolders;
|
||||
if (folders && folders.length > 0) {
|
||||
|
||||
if (folders && folders.length === 1) {
|
||||
return folders[0].uri;
|
||||
} else if (folders && folders.length > 1) {
|
||||
let projectFolder = undefined;
|
||||
|
||||
for (const folder of folders) {
|
||||
if (!projectFolder && existsSync(join(folder.uri.fsPath, Settings.globalFile))) {
|
||||
projectFolder = folder.uri;
|
||||
}
|
||||
}
|
||||
|
||||
if (!projectFolder) {
|
||||
window.showWorkspaceFolderPick({
|
||||
placeHolder: `Please select the main workspace folder for Front Matter to use.`
|
||||
}).then(selectedFolder => {
|
||||
if (selectedFolder) {
|
||||
Settings.createGlobalFile(selectedFolder.uri);
|
||||
// Full reload to make sure the whole extension is reloaded correctly
|
||||
commands.executeCommand(`workbench.action.reloadWindow`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return projectFolder;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -126,7 +150,6 @@ export class Folders {
|
||||
public static getProjectFolderName(): string {
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
if (wsFolder) {
|
||||
// const projectFolder = wsFolder?.fsPath.split('\\').join('/').split('/').pop();
|
||||
return basename(wsFolder.fsPath);
|
||||
}
|
||||
return "";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { workspace, Uri } from "vscode";
|
||||
import { CONFIG_KEY, SETTING_TEMPLATES_FOLDER } from "../constants";
|
||||
import { join } from "path";
|
||||
import * as fs from "fs";
|
||||
import { Notifications } from "../helpers/Notifications";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Notifications } from './Notifications';
|
||||
import { workspace } from 'vscode';
|
||||
import { Uri, workspace } from 'vscode';
|
||||
import * as vscode from 'vscode';
|
||||
import { TaxonomyType } from '../models';
|
||||
import { SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, CONFIG_KEY } from '../constants';
|
||||
@@ -9,8 +9,8 @@ import { existsSync, readFileSync, watch, writeFileSync } from 'fs';
|
||||
import { Extension } from './Extension';
|
||||
|
||||
export class Settings {
|
||||
public static globalFile = "frontmatter.json";
|
||||
private static config: vscode.WorkspaceConfiguration;
|
||||
private static globalFile = "frontmatter.json";
|
||||
private static globalConfig: any;
|
||||
|
||||
public static init() {
|
||||
@@ -131,7 +131,10 @@ export class Settings {
|
||||
*/
|
||||
public static createTeamSettings() {
|
||||
const wsFolder = Folders.getWorkspaceFolder();
|
||||
this.createGlobalFile(wsFolder);
|
||||
}
|
||||
|
||||
public static createGlobalFile(wsFolder: Uri | undefined | null) {
|
||||
const initialConfig = {
|
||||
"$schema": `https://${Extension.getInstance().isBetaVersion() ? `beta.` : ``}frontmatter.codes/frontmatter.schema.json`
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user