@@ -19,7 +19,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
19
19
import { SketchFactory } from './sketch-factory' ;
20
20
import { ArduinoToolbar } from './toolbar/arduino-toolbar' ;
21
21
import { EditorManager , EditorMainMenu } from '@theia/editor/lib/browser' ;
22
- import { ContextMenuRenderer , OpenerService , Widget , StatusBar , ShellLayoutRestorer , StatusBarAlignment } from '@theia/core/lib/browser' ;
22
+ import { ContextMenuRenderer , OpenerService , Widget , StatusBar , ShellLayoutRestorer , StatusBarAlignment , LabelProvider } from '@theia/core/lib/browser' ;
23
23
import { OpenFileDialogProps , FileDialogService } from '@theia/filesystem/lib/browser/file-dialog' ;
24
24
import { FileSystem , FileStat } from '@theia/filesystem/lib/common' ;
25
25
import { ArduinoToolbarContextMenu } from './arduino-file-menu' ;
@@ -113,6 +113,9 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
113
113
@inject ( ShellLayoutRestorer )
114
114
protected readonly layoutRestorer : ShellLayoutRestorer ;
115
115
116
+ @inject ( LabelProvider )
117
+ protected readonly labelProvider : LabelProvider ;
118
+
116
119
protected boardsToolbarItem : BoardsToolBarItem | null ;
117
120
protected wsSketchCount : number = 0 ;
118
121
@@ -375,9 +378,21 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
375
378
}
376
379
377
380
protected async openSketchFilesInNewWindow ( uri : string ) {
378
- const location = new URL ( window . location . href ) ;
379
- location . searchParams . set ( 'sketch' , uri ) ;
380
- this . windowService . openNewWindow ( location . toString ( ) ) ;
381
+ const url = new URL ( window . location . href ) ;
382
+ const currentSketch = url . searchParams . get ( 'sketch' ) ;
383
+ // Nothing to do if we want to open the same sketch which is already opened.
384
+ if ( ! ! currentSketch && new URI ( currentSketch ) . toString ( ) === new URI ( uri ) . toString ( ) ) {
385
+ this . messageService . info ( `The '${ this . labelProvider . getLongName ( new URI ( uri ) ) } ' is already opened.` ) ;
386
+ // NOOP.
387
+ return ;
388
+ }
389
+ // Preserve the current window if the `sketch` is not in the `searchParams`.
390
+ url . searchParams . set ( 'sketch' , uri ) ;
391
+ if ( ! currentSketch ) {
392
+ setTimeout ( ( ) => window . location . href = url . toString ( ) , 100 ) ;
393
+ return ;
394
+ }
395
+ this . windowService . openNewWindow ( url . toString ( ) ) ;
381
396
}
382
397
383
398
async openSketchFiles ( uri : string ) {
0 commit comments