@@ -9,9 +9,11 @@ import {
99 Uri ,
1010 window ,
1111 Webview ,
12- workspace
12+ workspace ,
13+ commands
1314} from 'vscode' ;
1415
16+ import * as fs from 'fs' ;
1517import * as path from 'path' ;
1618import { TextDecoder } from 'util' ;
1719
@@ -172,7 +174,7 @@ export class TableView {
172174 // load data
173175 workspace . fs . readFile ( this . _documentUri ) . then ( ( binaryData : Uint8Array ) => {
174176 const textData : string = new TextDecoder ( ) . decode ( binaryData ) ;
175- this . logTextData ( textData ) ;
177+ // this.logTextData(textData);
176178
177179 // parse dsv data for now
178180 const dsvParser = d3 . dsvFormat ( this . delimiter ) ;
@@ -195,8 +197,32 @@ export class TableView {
195197 * Saves table data in a new data file.
196198 */
197199 public async saveData ( data : any , dataFileName : string , dataFileType : string ) : Promise < void > {
198- console . log ( 'tabView:saveData(): saving data:' , dataFileName ) ;
199- this . logTextData ( data ) ;
200+ console . log ( 'tableView:saveData(): saving data:' , dataFileName ) ;
201+ // this.logTextData(data);
202+
203+ // create full data file path for saving data
204+ let dataFilePath : string = path . dirname ( this . _documentUri . fsPath ) ;
205+ dataFilePath = path . join ( dataFilePath , dataFileName ) ;
206+
207+ // display save file dialog
208+ const dataFileUri : Uri | undefined = await window . showSaveDialog ( {
209+ defaultUri : Uri . parse ( dataFilePath ) . with ( { scheme : 'file' } )
210+ } ) ;
211+
212+ if ( dataFileUri ) {
213+ // save data
214+ // TODO: switch to using workspace.fs for data save
215+ // workspace.fs.writeFile(dataFileUri, data);
216+ fs . writeFile ( dataFileUri . fsPath , data , ( error ) => {
217+ if ( error ) {
218+ window . showErrorMessage ( `Unable to save data file: '${ dataFileUri . fsPath } '. \n\t Error: ${ error . message } ` ) ;
219+ }
220+ else {
221+ // show saved data file
222+ commands . executeCommand ( 'vscode.open' , dataFileUri ) ;
223+ }
224+ } ) ;
225+ }
200226 }
201227
202228 /**
0 commit comments