@@ -3,10 +3,12 @@ import { NavigatableWidget } from '@theia/core/lib/browser/navigatable';
3
3
import { Saveable } from '@theia/core/lib/browser/saveable' ;
4
4
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell' ;
5
5
import { WindowService } from '@theia/core/lib/browser/window/window-service' ;
6
+ import { ApplicationError } from '@theia/core/lib/common/application-error' ;
6
7
import { nls } from '@theia/core/lib/common/nls' ;
7
8
import { inject , injectable } from '@theia/core/shared/inversify' ;
8
9
import { EditorManager } from '@theia/editor/lib/browser/editor-manager' ;
9
10
import { WorkspaceInput } from '@theia/workspace/lib/browser/workspace-service' ;
11
+ import { SketchesError } from '../../common/protocol' ;
10
12
import { StartupTasks } from '../../electron-common/startup-task' ;
11
13
import { ArduinoMenus } from '../menu/arduino-menus' ;
12
14
import { CurrentSketch } from '../sketches-service-client-impl' ;
@@ -35,7 +37,29 @@ export class SaveAsSketch extends CloudSketchContribution {
35
37
36
38
override registerCommands ( registry : CommandRegistry ) : void {
37
39
registry . registerCommand ( SaveAsSketch . Commands . SAVE_AS_SKETCH , {
38
- execute : ( args ) => this . saveAs ( args ) ,
40
+ execute : async ( args ) => {
41
+ try {
42
+ return await this . saveAs ( args ) ;
43
+ } catch ( err ) {
44
+ let message = String ( err ) ;
45
+ if ( ApplicationError . is ( err ) ) {
46
+ if ( SketchesError . SketchAlreadyContainsThisFile . is ( err ) ) {
47
+ message = nls . localize (
48
+ 'arduino/sketch/sketchAlreadyContainsThisFileMessage' ,
49
+ 'Failed to save sketch "{0}" as "{1}". {2}' ,
50
+ err . data . sourceSketchName ,
51
+ err . data . targetSketchName ,
52
+ err . message
53
+ ) ;
54
+ } else {
55
+ message = err . message ;
56
+ }
57
+ } else if ( err instanceof Error ) {
58
+ message = err . message ;
59
+ }
60
+ this . messageService . error ( message ) ;
61
+ }
62
+ } ,
39
63
} ) ;
40
64
}
41
65
@@ -58,13 +82,14 @@ export class SaveAsSketch extends CloudSketchContribution {
58
82
* Resolves `true` if the sketch was successfully saved as something.
59
83
*/
60
84
private async saveAs (
61
- {
85
+ params = SaveAsSketch . Options . DEFAULT
86
+ ) : Promise < boolean > {
87
+ const {
62
88
execOnlyIfTemp,
63
89
openAfterMove,
64
90
wipeOriginal,
65
91
markAsRecentlyOpened,
66
- } : SaveAsSketch . Options = SaveAsSketch . Options . DEFAULT
67
- ) : Promise < boolean > {
92
+ } = params ;
68
93
assertConnectedToBackend ( {
69
94
connectionStatusService : this . connectionStatusService ,
70
95
messageService : this . messageService ,
0 commit comments