aboutsummaryrefslogtreecommitdiffstats
path: root/qt-core/src/state.ts
blob: 50c2489f099861753804f78404ec71709672d08e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import * as vscode from 'vscode';

import {
  createLogger,
  QtInsRootConfigName,
  BaseStateManager,
  AdditionalQtPathsName,
  QtAdditionalPath
} from 'qt-lib';

const logger = createLogger('state');

export class WorkspaceStateManager extends BaseStateManager {
  constructor(
    context: vscode.ExtensionContext,
    folder: vscode.WorkspaceFolder
  ) {
    if (folder.uri.fsPath === '') {
      logger.error('folder is empty');
      throw new Error('folder is empty');
    }
    super(context, folder);
  }
  public getQtInstallationRoot(): string {
    return this._get<string>(QtInsRootConfigName, '');
  }
  public setQtInstallationRoot(folder: string): Thenable<void> {
    return this._update(QtInsRootConfigName, folder);
  }
  public getAdditionalQtPaths(): QtAdditionalPath[] {
    return this._get<QtAdditionalPath[]>(AdditionalQtPathsName, []);
  }
  public setAdditionalQtPaths(paths: QtAdditionalPath[]): Thenable<void> {
    return this._update(AdditionalQtPathsName, paths);
  }
  public async reset() {
    await this.setQtInstallationRoot('');
    await this.setAdditionalQtPaths([]);
  }
}

export class GlobalStateManager extends BaseStateManager {
  public getQtInstallationRoot(): string {
    return this._get<string>(QtInsRootConfigName, '');
  }
  public setQtInstallationRoot(folder: string): Thenable<void> {
    return this._update(QtInsRootConfigName, folder);
  }
  public getAdditionalQtPaths(): QtAdditionalPath[] {
    return this._get<QtAdditionalPath[]>(AdditionalQtPathsName, []);
  }
  public setAdditionalQtPaths(paths: QtAdditionalPath[]): Thenable<void> {
    return this._update(AdditionalQtPathsName, paths);
  }

  public async reset() {
    await this.setQtInstallationRoot('');
    await this.setAdditionalQtPaths([]);
  }
}