11import { ensureDirSync , pathExists , ensureDir , writeFile } from "fs-extra" ;
22import { join } from "path" ;
33import { dirSync } from "tmp-promise" ;
4- import { Uri , window as Window , workspace , env } from "vscode" ;
4+ import { Uri , window as Window , workspace } from "vscode" ;
55import { CodeQLCliServer } from "./codeql-cli/cli" ;
66import { UserCancellationException } from "./common/vscode/progress" ;
77import { extLogger , OutputChannelLogger } from "./common" ;
@@ -12,6 +12,7 @@ import { isQueryLanguage, QueryLanguage } from "./common/query-language";
1212import { isCodespacesTemplate } from "./config" ;
1313import { AppCommandManager } from "./common/commands" ;
1414import { getOnDiskWorkspaceFolders } from "./common/vscode/workspace-folders" ;
15+ import { showBinaryChoiceDialog } from "./common/vscode/dialog" ;
1516
1617// Shared temporary folder for the extension.
1718export const tmpDir = dirSync ( {
@@ -139,140 +140,6 @@ async function internalShowAndLog(
139140 return result ;
140141}
141142
142- /**
143- * Opens a modal dialog for the user to make a yes/no choice.
144- *
145- * @param message The message to show.
146- * @param modal If true (the default), show a modal dialog box, otherwise dialog is non-modal and can
147- * be closed even if the user does not make a choice.
148- * @param yesTitle The text in the box indicating the affirmative choice.
149- * @param noTitle The text in the box indicating the negative choice.
150- *
151- * @return
152- * `true` if the user clicks 'Yes',
153- * `false` if the user clicks 'No' or cancels the dialog,
154- * `undefined` if the dialog is closed without the user making a choice.
155- */
156- export async function showBinaryChoiceDialog (
157- message : string ,
158- modal = true ,
159- yesTitle = "Yes" ,
160- noTitle = "No" ,
161- ) : Promise < boolean | undefined > {
162- const yesItem = { title : yesTitle , isCloseAffordance : false } ;
163- const noItem = { title : noTitle , isCloseAffordance : true } ;
164- const chosenItem = await Window . showInformationMessage (
165- message ,
166- { modal } ,
167- yesItem ,
168- noItem ,
169- ) ;
170- if ( ! chosenItem ) {
171- return undefined ;
172- }
173- return chosenItem ?. title === yesItem . title ;
174- }
175-
176- /**
177- * Opens a modal dialog for the user to make a yes/no choice.
178- *
179- * @param message The message to show.
180- * @param modal If true (the default), show a modal dialog box, otherwise dialog is non-modal and can
181- * be closed even if the user does not make a choice.
182- *
183- * @return
184- * `true` if the user clicks 'Yes',
185- * `false` if the user clicks 'No' or cancels the dialog,
186- * `undefined` if the dialog is closed without the user making a choice.
187- */
188- export async function showBinaryChoiceWithUrlDialog (
189- message : string ,
190- url : string ,
191- ) : Promise < boolean | undefined > {
192- const urlItem = { title : "More Information" , isCloseAffordance : false } ;
193- const yesItem = { title : "Yes" , isCloseAffordance : false } ;
194- const noItem = { title : "No" , isCloseAffordance : true } ;
195- let chosenItem ;
196-
197- // Keep the dialog open as long as the user is clicking the 'more information' option.
198- // To prevent an infinite loop, if the user clicks 'more information' 5 times, close the dialog and return cancelled
199- let count = 0 ;
200- do {
201- chosenItem = await Window . showInformationMessage (
202- message ,
203- { modal : true } ,
204- urlItem ,
205- yesItem ,
206- noItem ,
207- ) ;
208- if ( chosenItem === urlItem ) {
209- await env . openExternal ( Uri . parse ( url , true ) ) ;
210- }
211- count ++ ;
212- } while ( chosenItem === urlItem && count < 5 ) ;
213-
214- if ( ! chosenItem || chosenItem . title === urlItem . title ) {
215- return undefined ;
216- }
217- return chosenItem . title === yesItem . title ;
218- }
219-
220- /**
221- * Show an information message with a customisable action.
222- * @param message The message to show.
223- * @param actionMessage The call to action message.
224- *
225- * @return `true` if the user clicks the action, `false` if the user cancels the dialog.
226- */
227- export async function showInformationMessageWithAction (
228- message : string ,
229- actionMessage : string ,
230- ) : Promise < boolean > {
231- const actionItem = { title : actionMessage , isCloseAffordance : false } ;
232- const chosenItem = await Window . showInformationMessage ( message , actionItem ) ;
233- return chosenItem === actionItem ;
234- }
235-
236- /**
237- * Opens a modal dialog for the user to make a choice between yes/no/never be asked again.
238- *
239- * @param message The message to show.
240- * @param modal If true (the default), show a modal dialog box, otherwise dialog is non-modal and can
241- * be closed even if the user does not make a choice.
242- * @param yesTitle The text in the box indicating the affirmative choice.
243- * @param noTitle The text in the box indicating the negative choice.
244- * @param neverTitle The text in the box indicating the opt out choice.
245- *
246- * @return
247- * `Yes` if the user clicks 'Yes',
248- * `No` if the user clicks 'No' or cancels the dialog,
249- * `No, and never ask me again` if the user clicks 'No, and never ask me again',
250- * `undefined` if the dialog is closed without the user making a choice.
251- */
252- export async function showNeverAskAgainDialog (
253- message : string ,
254- modal = true ,
255- yesTitle = "Yes" ,
256- noTitle = "No" ,
257- neverAskAgainTitle = "No, and never ask me again" ,
258- ) : Promise < string | undefined > {
259- const yesItem = { title : yesTitle , isCloseAffordance : true } ;
260- const noItem = { title : noTitle , isCloseAffordance : false } ;
261- const neverAskAgainItem = {
262- title : neverAskAgainTitle ,
263- isCloseAffordance : false ,
264- } ;
265- const chosenItem = await Window . showInformationMessage (
266- message ,
267- { modal } ,
268- yesItem ,
269- noItem ,
270- neverAskAgainItem ,
271- ) ;
272-
273- return chosenItem ?. title ;
274- }
275-
276143/** Check if the current workspace is the CodeTour and open the workspace folder.
277144 * Without this, we can't run the code tour correctly.
278145 **/
0 commit comments