mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-14 14:56:33 +00:00
PROEDITOR-27: Try to preserve the window.
When opening sketches. Rules: - If `sketch` is missing from the URL, we reuse the same window. - NOOP, if we try to open the currently opened sketch. - Otherwise, use the existing logic: open sketch in a new window. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
2914379586
commit
82df8a6add
@ -19,7 +19,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
|
|||||||
import { SketchFactory } from './sketch-factory';
|
import { SketchFactory } from './sketch-factory';
|
||||||
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
||||||
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
|
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
|
||||||
import { ContextMenuRenderer, OpenerService, Widget, StatusBar, ShellLayoutRestorer, StatusBarAlignment } from '@theia/core/lib/browser';
|
import { ContextMenuRenderer, OpenerService, Widget, StatusBar, ShellLayoutRestorer, StatusBarAlignment, LabelProvider } from '@theia/core/lib/browser';
|
||||||
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
||||||
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
|
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
|
||||||
import { ArduinoToolbarContextMenu } from './arduino-file-menu';
|
import { ArduinoToolbarContextMenu } from './arduino-file-menu';
|
||||||
@ -113,6 +113,9 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
@inject(ShellLayoutRestorer)
|
@inject(ShellLayoutRestorer)
|
||||||
protected readonly layoutRestorer: ShellLayoutRestorer;
|
protected readonly layoutRestorer: ShellLayoutRestorer;
|
||||||
|
|
||||||
|
@inject(LabelProvider)
|
||||||
|
protected readonly labelProvider: LabelProvider;
|
||||||
|
|
||||||
protected boardsToolbarItem: BoardsToolBarItem | null;
|
protected boardsToolbarItem: BoardsToolBarItem | null;
|
||||||
protected wsSketchCount: number = 0;
|
protected wsSketchCount: number = 0;
|
||||||
|
|
||||||
@ -375,9 +378,21 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async openSketchFilesInNewWindow(uri: string) {
|
protected async openSketchFilesInNewWindow(uri: string) {
|
||||||
const location = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
location.searchParams.set('sketch', uri);
|
const currentSketch = url.searchParams.get('sketch');
|
||||||
this.windowService.openNewWindow(location.toString());
|
// Nothing to do if we want to open the same sketch which is already opened.
|
||||||
|
if (!!currentSketch && new URI(currentSketch).toString() === new URI(uri).toString()) {
|
||||||
|
this.messageService.info(`The '${this.labelProvider.getLongName(new URI(uri))}' is already opened.`);
|
||||||
|
// NOOP.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Preserve the current window if the `sketch` is not in the `searchParams`.
|
||||||
|
url.searchParams.set('sketch', uri);
|
||||||
|
if (!currentSketch) {
|
||||||
|
setTimeout(() => window.location.href = url.toString(), 100);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.windowService.openNewWindow(url.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
async openSketchFiles(uri: string) {
|
async openSketchFiles(uri: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user