• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15import * as vscode from 'vscode';
16import { Dts2cppMod } from "../model/dts2cppmod";
17import { IModel } from "../model/imodel";
18import { IView } from "./iview";
19import {
20  EVENT_ERROR,
21  EVENT_INFORMATION,
22  EVENT_PROGRESS,
23  EVENT_WARNING
24} from '../common/eventtype';
25import { IController } from '../controller/icontroller';
26import { toastMsg } from '../common/widget';
27
28export class Dts2cppView extends IView {
29  name: string;
30  model: IModel;
31  controller: IController | undefined;
32  progress: vscode.Progress<{ message?: string; increment?: number; }> | undefined = undefined;
33  constructor() {
34    super();
35    this.name = 'dts2cppview';
36    this.model = Dts2cppMod.getInstance();
37  }
38
39  init(controller: IController): void {
40    this.controller = controller;
41
42    this.model.onEvent(EVENT_PROGRESS, (percent, info) => {
43      if (this.progress) {
44        this.progress.report({ increment: percent, message: info })
45      }
46    })
47    this.model.onEvent(EVENT_ERROR, (errno, errmsg) => {
48      vscode.window.showErrorMessage(errmsg);
49    })
50    this.model.onEvent(EVENT_WARNING, (errno, errmsg) => {
51      vscode.window.showWarningMessage(errmsg);
52    })
53  }
54
55  showProgress(): void {
56    try {
57      vscode.window.withProgress({
58        location: vscode.ProgressLocation.Notification,
59        title: "Generating CPP...",
60        cancellable: false
61      }, async (progress: vscode.Progress<{ message?: string; increment?: number; }>) => {
62        this.progress = progress;
63        if (this.controller) {
64          this.controller.start();
65        }
66      })
67    } catch (error) {
68      let errmsg = this.name + " showProgress error: " + JSON.stringify(error);
69      toastMsg(EVENT_ERROR, errmsg);
70    }
71
72  }
73
74  showMsg(event: string, msg: string): void {
75    toastMsg(event, msg);
76  }
77}