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*/ 15 16// The module 'vscode' contains the VS Code extensibility API 17// Import the module and reference it with the alias vscode in your code below 18 19import * as vscode from 'vscode'; 20import { 21 EVENT_ERROR, 22 EVENT_INFORMATION, 23 EVENT_WARNING 24} from './eventtype'; 25import { Logger } from './log'; 26import { Callback } from './define'; 27 28export function doAsyncQuickPick(valueList: string[], options?: vscode.QuickPickOptions, cb?: Callback) { 29 vscode.window.showQuickPick(valueList, options).then((value) => { 30 if (cb) { 31 cb(value); 32 } else { 33 toastMsg(EVENT_ERROR, 'No cb in showQuickPick'); 34 } 35 }) 36} 37 38export async function doSyncQuickPick(valueList: string[], options?: vscode.QuickPickOptions) { 39 return await vscode.window.showQuickPick(valueList, options); 40} 41 42export function doAsyncInputBox(options?: vscode.InputBoxOptions, cb?: Callback) { 43 vscode.window.showInputBox(options).then((value) => { 44 if (cb) { 45 cb(value); 46 } else { 47 toastMsg(EVENT_ERROR, 'No cb in showInputBox'); 48 } 49 }) 50} 51 52export async function doSyncInputBox(options?: vscode.InputBoxOptions) { 53 return await vscode.window.showInputBox(options); 54} 55 56export function doAsyncProgress(options: vscode.ProgressOptions, cb: Callback) { 57 vscode.window.withProgress({ 58 location: vscode.ProgressLocation.Notification, 59 title: 'Generating HDF...', 60 cancellable: false 61 }, async (progress) => { 62 cb(progress); 63 }) 64} 65 66export function doAsyncOpenDialog(options: vscode.OpenDialogOptions, cb: Callback) { 67 vscode.window.showOpenDialog(options).then(fileUri => { 68 cb(fileUri); 69 }) 70} 71 72export function toastMsg(event: string, msg: string) { 73 switch(event) { 74 case EVENT_ERROR: 75 Logger.getInstance().error(msg); 76 vscode.window.showErrorMessage(msg); 77 break; 78 case EVENT_INFORMATION: 79 Logger.getInstance().info(msg); 80 vscode.window.showInformationMessage(msg); 81 break; 82 case EVENT_WARNING: 83 Logger.getInstance().warn(msg); 84 vscode.window.showWarningMessage(msg); 85 break; 86 default: 87 Logger.getInstance().debug(msg); 88 vscode.window.showInformationMessage(msg); 89 break; 90 } 91}