11import * as vscode from "vscode" ;
22import { AtelierAPI } from "../api" ;
3- import { config , filesystemSchemas , projectsExplorerProvider , schemas } from "../extension" ;
4- import { compareConns } from "../providers/DocumentContentProvider" ;
3+ import { config , filesystemSchemas , projectsExplorerProvider } from "../extension" ;
54import { isfsDocumentName } from "../providers/FileSystemProvider/FileSystemProvider" ;
6- import { compileErrorMsg , getWsServerConnection , handleError , notIsfs , notNull } from "../utils" ;
5+ import { compileErrorMsg , getWsFolder , getWsServerConnection , handleError , notNull } from "../utils" ;
76import { exportList } from "./export" ;
87import { OtherStudioAction , StudioActions } from "./studio" ;
98import { NodeBase , ProjectNode , ProjectRootNode , RoutineNode , CSPFileNode , ClassNode } from "../explorer/nodes" ;
@@ -14,31 +13,37 @@ export interface ProjectItem {
1413 Type : string ;
1514}
1615
17- export async function pickProject ( api : AtelierAPI ) : Promise < string | undefined > {
18- const ns = api . config . ns . toUpperCase ( ) ;
16+ export async function pickProject ( api : AtelierAPI , allowCreate = true ) : Promise < string | undefined > {
1917 const projects : vscode . QuickPickItem [ ] = await api
2018 . actionQuery ( "SELECT Name, Description FROM %Studio.Project" , [ ] )
2119 . then ( ( data ) =>
2220 data . result . content . map ( ( prj ) => {
2321 return { label : prj . Name , detail : prj . Description } ;
2422 } )
2523 ) ;
26- if ( projects . length === 0 ) {
27- const create = await vscode . window . showQuickPick ( [ "Yes" , "No" ] , {
28- title : `Namespace ${ ns } on server '${ api . serverId } ' contains no projects. Create one?` ,
29- } ) ;
30- if ( create == "Yes" ) {
31- return createProject ( undefined , api ) ;
24+ if ( projects . length == 0 ) {
25+ if ( allowCreate ) {
26+ const create = await vscode . window . showQuickPick ( [ "Yes" , "No" ] , {
27+ title : `Namespace ${ api . ns } on server '${ api . serverId } ' contains no projects. Create one?` ,
28+ } ) ;
29+ if ( create == "Yes" ) {
30+ return createProject ( undefined , api ) ;
31+ }
32+ } else {
33+ vscode . window . showInformationMessage (
34+ `Namespace ${ api . ns } on server '${ api . serverId } ' contains no projects.` ,
35+ "Dismiss"
36+ ) ;
3237 }
3338 return ;
3439 }
3540 return new Promise < string | undefined > ( ( resolve ) => {
3641 let result : string ;
3742 let resolveOnHide = true ;
3843 const quickPick = vscode . window . createQuickPick ( ) ;
39- quickPick . title = `Select a project in namespace ${ ns } on server '${ api . serverId } ', or click '+' to add one.` ;
44+ quickPick . title = `Select a project in namespace ${ api . ns } on server '${ api . serverId } '${ allowCreate ? " , or click '+' to add one" : "" } .` ;
4045 quickPick . items = projects ;
41- quickPick . buttons = [ { iconPath : new vscode . ThemeIcon ( "add" ) , tooltip : "Create new project" } ] ;
46+ quickPick . buttons = allowCreate ? [ { iconPath : new vscode . ThemeIcon ( "add" ) , tooltip : "Create new project" } ] : [ ] ;
4247
4348 async function addAndResolve ( ) {
4449 resolveOnHide = false ;
@@ -879,64 +884,38 @@ export async function modifyProject(
879884 }
880885}
881886
882- export async function exportProjectContents ( node : ProjectNode | undefined ) : Promise < any > {
883- let workspaceFolder : string ;
884- const api = new AtelierAPI ( node . workspaceFolderUri ) ;
885- api . setNamespace ( node . namespace ) ;
886- const project = node . label ;
887- if ( notIsfs ( node . workspaceFolderUri ) ) {
888- workspaceFolder = node . workspaceFolder ;
889- } else {
890- const conn = config ( "conn" , node . workspaceFolder ) ;
891- const workspaceList = vscode . workspace . workspaceFolders
892- . filter ( ( folder ) => {
893- if ( schemas . includes ( folder . uri . scheme ) ) {
894- return false ;
895- }
896- const wFolderConn = config ( "conn" , folder . name ) ;
897- if ( ! compareConns ( conn , wFolderConn ) ) {
898- return false ;
899- }
900- if ( ! wFolderConn . active ) {
901- return false ;
902- }
903- if ( wFolderConn . ns . toLowerCase ( ) != node . namespace . toLowerCase ( ) ) {
904- return false ;
905- }
906- return true ;
907- } )
908- . map ( ( el ) => el . name ) ;
909- if ( workspaceList . length > 1 ) {
910- const selection = await vscode . window . showQuickPick ( workspaceList , {
911- title : "Pick the workspace folder to export files to." ,
912- } ) ;
913- if ( selection === undefined ) {
914- return ;
887+ export async function exportProjectContents ( ) : Promise < any > {
888+ try {
889+ const wsFolder = await getWsFolder ( "Pick a workspace folder to export files to." , true , false , true , true ) ;
890+ if ( ! wsFolder ) {
891+ if ( wsFolder === undefined ) {
892+ // Strict equality needed because undefined == null
893+ vscode . window . showErrorMessage (
894+ "'Export Project Contents from Server...' command requires a workspace folder with an active server connection." ,
895+ "Dismiss"
896+ ) ;
915897 }
916- workspaceFolder = selection ;
917- } else if ( workspaceList . length === 1 ) {
918- workspaceFolder = workspaceList . pop ( ) ;
919- } else {
920- vscode . window . showInformationMessage (
921- "There are no folders in the current workspace that code can be exported to." ,
922- "Dismiss"
923- ) ;
924898 return ;
925899 }
900+ const api = new AtelierAPI ( wsFolder . uri ) ;
901+ const project = await pickProject ( api , false ) ;
902+ if ( ! project ) return ;
903+ await exportList (
904+ await api
905+ . actionQuery (
906+ "SELECT CASE WHEN sod.Name %STARTSWITH '/' THEN SUBSTR(sod.Name,2) ELSE sod.Name END Name " +
907+ "FROM %Library.RoutineMgr_StudioOpenDialog('*',1,1,1,1,0,1) AS sod JOIN %Studio.Project_ProjectItemsList(?) AS pil " +
908+ "ON sod.Name = pil.Name OR (pil.Type = 'CLS' AND pil.Name||'.cls' = sod.Name) " +
909+ "OR (pil.Type = 'CSP' AND pil.Name = SUBSTR(sod.Name,2)) OR (pil.Type = 'DIR' AND sod.Name %STARTSWITH '/'||pil.Name||'/')" ,
910+ [ project ]
911+ )
912+ . then ( ( data ) => data . result . content . map ( ( e ) => e . Name ) ) ,
913+ wsFolder . name ,
914+ api . ns
915+ ) ;
916+ } catch ( error ) {
917+ handleError ( error , "Error executing 'Export Project Contents from Server...' command." ) ;
926918 }
927- if ( workspaceFolder === undefined ) {
928- return ;
929- }
930- const exportFiles : string [ ] = await api
931- . actionQuery (
932- "SELECT CASE WHEN sod.Name %STARTSWITH '/' THEN SUBSTR(sod.Name,2) ELSE sod.Name END Name " +
933- "FROM %Library.RoutineMgr_StudioOpenDialog('*',1,1,1,1,0,1) AS sod JOIN %Studio.Project_ProjectItemsList(?) AS pil " +
934- "ON sod.Name = pil.Name OR (pil.Type = 'CLS' AND pil.Name||'.cls' = sod.Name) " +
935- "OR (pil.Type = 'CSP' AND pil.Name = SUBSTR(sod.Name,2)) OR (pil.Type = 'DIR' AND sod.Name %STARTSWITH '/'||pil.Name||'/')" ,
936- [ project ]
937- )
938- . then ( ( data ) => data . result . content . map ( ( e ) => e . Name ) ) ;
939- return exportList ( exportFiles , workspaceFolder , node . namespace ) ;
940919}
941920
942921export async function compileProjectContents ( node : ProjectNode ) : Promise < any > {
0 commit comments