Skip to content

Commit

Permalink
Merge pull request #286 from zowe/SaveAs
Browse files Browse the repository at this point in the history
Save as
  • Loading branch information
DivergentEuropeans authored Aug 8, 2022
2 parents 3641414 + 9a11024 commit 4e7c4bc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 38 deletions.
12 changes: 12 additions & 0 deletions webClient/src/app/core/menu-bar/menu-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ export class MenuBarComponent implements OnInit, OnDestroy {
this.closeAll();
} else if (event.which === KeyCode.KEY_R && event.shiftKey) {
this.refreshFile();
} else if (event.which === KeyCode.KEY_S && event.shiftKey) {
this.saveAsFile();
}
// else if (event.which === KeyCode.KEY_S && event.ctrlKey) { TODO
// this.saveAll();
Expand Down Expand Up @@ -629,6 +631,16 @@ export class MenuBarComponent implements OnInit, OnDestroy {
}
}

saveAsFile() {
let fileContext = this.editorControl.fetchActiveFile();
let directory = fileContext.model.path || this.editorControl.activeDirectory;
if (!fileContext) {
this.snackBar.open('Warning: Cannot save, no content found', 'Dismiss', {duration: MessageDuration.Medium, panelClass: 'center'});
} else {
let sub = this.monacoService.saveFile(fileContext, directory, true).subscribe(() => { sub.unsubscribe(); });
}
}

//saveAll() {
// this.editorControl.saveAllFile.emit();
//}
Expand Down
7 changes: 7 additions & 0 deletions webClient/src/app/core/menu-bar/menu-bar.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ export const MENU = [
internalName: 'saveFile'
},
keyMap: 'Ctrl+S'
},
{
name: 'Save As',
action: {
internalName: 'saveAsFile'
},
keyMap: 'Alt+S+Shift'
},
{
name: 'group-end'
Expand Down
10 changes: 5 additions & 5 deletions webClient/src/app/editor/code-editor/monaco/monaco.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,17 @@ export class MonacoService implements OnDestroy {
return canBeISO;
}

saveFile(fileContext: ProjectContext, fileDirectory?: string): Observable<String> {
saveFile(fileContext: ProjectContext, fileDirectory?: string, saveAs?: boolean): Observable<String> {
return new Observable((obs) => {
if (fileContext.model.isDataset) {
this.editorControl.saveBuffer(fileContext, null).subscribe(() => obs.next('Save'));
this.editorControl.saveBuffer(fileContext, null, saveAs).subscribe(() => obs.next('Save'));
} else {
/* Issue a presave check to see if the
* file can be saved as ISO-8859-1,
* perhaps this should be done in real
* time as an enhancement.
*/
if (fileContext.temp) {
if (fileContext.temp || saveAs) {
let x = this.preSaveCheck(fileContext);
/* Open up a dialog with the standard,
* "save as" format.
Expand Down Expand Up @@ -462,7 +462,7 @@ export class MonacoService implements OnDestroy {
this.editorControl.getFileMetadata(fileContext.model.path + '/' + fileContext.model.name).subscribe(r => {
fileContext.model.encoding = r.ccsid;
if (r.ccsid && r.ccsid != 0) {
this.editorControl.saveBuffer(fileContext, null).subscribe(() => obs.next('Save'));
this.editorControl.saveBuffer(fileContext, null, saveAs).subscribe(() => obs.next('Save'));
}
/* The file was never tagged, so we should
* ask the user if they would like to tag it.
Expand All @@ -476,7 +476,7 @@ export class MonacoService implements OnDestroy {
});
saveRef.afterClosed().subscribe(result => {
if (result) {
this.editorControl.saveBuffer(fileContext, result).subscribe(() => obs.next('Save'));
this.editorControl.saveBuffer(fileContext, result, saveAs).subscribe(() => obs.next('Save'));
} else {
obs.next('Cancel');
}
Expand Down
71 changes: 38 additions & 33 deletions webClient/src/app/shared/editor-control/editor-control.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff
}

doSaving(context: ProjectContext, requestUrl: string, _activeFile: ProjectContext, results: any, isUntagged: boolean,
_observer: Observer<void>, _observable: Observable<void>) {
_observer: Observer<void>, _observable: Observable<void>, saveAs?: boolean) {
/* We must BASE64 encode the contents
* of the file before it is sent
* to the server.
Expand All @@ -550,36 +550,41 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff
* to save the file.
*/
this.http.put(requestUrl, encodedFileContents).subscribe(r => {

// if we are doing SaveAs then do not update the openedFileList
if(saveAs){
this.snackBar.open(`${results.fileName} has been saved!`, 'Close', { duration: MessageDuration.Short, panelClass: 'center' });
this.openDirectory.next(results.directory);
}
/* It was a new file, we
* can set the new fileName. */
if (results && !isUntagged) {
_activeFile.name = results.fileName;
_activeFile.model.name = results.fileName;
_activeFile.model.fileName = results.fileName;
_activeFile.model.encoding = this.getIntEncoding(results.encoding);
_activeFile.model.path = results.directory;
_activeFile.temp = false;
}
/* This will probably need to be changed
* for the sake of accessibility.
*/
this.snackBar.open(`${_activeFile.name} has been saved!`, 'Close', { duration: MessageDuration.Short, panelClass: 'center' });

/* Send buffer saved event */
this.bufferSaved.next({ buffer: _activeFile.model.contents, file: _activeFile.model.name });
let fileList = this.openFileList.getValue()
.map(file => {
if (file.id === context.id) {
file.changed = false;
}
return file;
});
this.openFileList.next(fileList);
if (results) {
this.openDirectory.next(results.directory);
else{
if (results && !isUntagged) {
_activeFile.name = results.fileName;
_activeFile.model.name = results.fileName;
_activeFile.model.fileName = results.fileName;
_activeFile.model.encoding = this.getIntEncoding(results.encoding);
_activeFile.model.path = results.directory;
_activeFile.temp = false;
}
/* This will probably need to be changed
* for the sake of accessibility.
*/
this.snackBar.open(`${_activeFile.name} has been saved!`, 'Close', { duration: MessageDuration.Short, panelClass: 'center' });
/* Send buffer saved event */
this.bufferSaved.next({ buffer: _activeFile.model.contents, file: _activeFile.model.name });
let fileList = this.openFileList.getValue()
.map(file => {
if (file.id === context.id) {
file.changed = false;
}
return file;
});
this.openFileList.next(fileList);
if (results) {
this.openDirectory.next(results.directory);
}
if (_observer != null) { _observer.next(null); }
}
if (_observer != null) { _observer.next(null); }
}, e => {
let error = e.error.error;

Expand Down Expand Up @@ -758,7 +763,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff
})
}

saveFileHandler(context?: ProjectContext, results?: any): Observable<void> {
saveFileHandler(context?: ProjectContext, results?: any, saveAs?: boolean): Observable<void> {
const _openFile = this.openFileList.getValue();
let _activeFile: ProjectContext;
let _observer: Observer<void>;
Expand Down Expand Up @@ -832,7 +837,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff
{ sessionID,
forceOverwrite,
lastChunk: true });
this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable);
this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable, saveAs);
/** Update the new encoding value, in opeFileList Models */
let index = this._openFileList.value.findIndex(item => item.id === _activeFile.id);
this._openFileList.value[index].model.encoding = this.getIntEncoding(targetEncoding);
Expand Down Expand Up @@ -872,7 +877,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff
{ forceOverwrite: true,
sessionID,
lastChunk: true });
this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable);
this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable, saveAs);
/** Update the new encoding value, in opeFileList Models */
let index = this._openFileList.value.findIndex(item => item.id === _activeFile.id);
this._openFileList.value[index].model.encoding = this.getIntEncoding(targetEncoding);
Expand Down Expand Up @@ -1082,12 +1087,12 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff
* @param path The path of the file into which the buffer should be saved, or null if the buffer is already associated with a file
* @returns An observable that pushes when the file has been saved
*/
saveBuffer(buffer: ZLUX.EditorBufferHandle, path: string | null): Observable<void> {
saveBuffer(buffer: ZLUX.EditorBufferHandle, path: string | null, saveAs?: boolean): Observable<void> {
this.saveFile.emit(<ProjectContext>buffer);
if (buffer.model.isDataset) {
return this.saveDatasetHandler(buffer, path);
} else {
return this.saveFileHandler(buffer, path);
return this.saveFileHandler(buffer, path, saveAs);
}
}
/**
Expand Down

0 comments on commit 4e7c4bc

Please sign in to comment.