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 { IModel } from "../model/imodel"; 17import { IView } from "./iview"; 18import { 19 EVENT_ERROR, 20 EVENT_INFORMATION, 21 EVENT_PROGRESS, 22 EVENT_WARNING 23} from '../common/eventtype'; 24import { IController } from '../controller/icontroller'; 25import { toastMsg } from '../common/widget'; 26import { H2dtscppMod } from '../model/h2dtscppmod'; 27 28export class H2dtscppView 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 = 'h2dtscppview'; 36 this.model = H2dtscppMod.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 DTSCPP...', 60 cancellable: false 61 }, async (progress) => { 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 showMsg(event: string, msg: string): void { 74 toastMsg(event, msg); 75 } 76}