Skip to content

Commit

Permalink
Fix duplicate tab when opening from file explorer that already is open
Browse files Browse the repository at this point in the history
Fixes #569

Opening from the file explorer a trace uses the file URI to open the
the trace viewer widget. Then it scans the file system for traces,
posts the traces and experiment to the trace server. Only at that
point the experiment UUID is known. Theia keeps a map from
with a key using URI+TraceWidgetOpenOptions to widget. When opening the
first time the open options are undefined and the key is only the URI.

Closing the trace that map will cleared. When opening the trace from
the trace explorer, the TraceWidgetOpenOption will be populated with
the experiment UUID, but the URI is not known anymore.

When the user now opens the same trace from same file location, the URI
is used but the there is no way to know the corresponding UUID until
the trace(s) and experiment is created on the server.

The fix provided checks uses this UUID to match the UUID of any widgets
that are already open. If an widget is already open it will close the
new widget since it's a duplicate.

The solution proposed will fix the issue, but a follow-up patch needs
to be worked that avoids opening the tab first and closing it when
a duplicate is detected.

Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
  • Loading branch information
bhufmann committed Nov 24, 2021
1 parent 42da057 commit ccddaaf
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DisposableCollection, MessageService, Path } from '@theia/core';
import { ApplicationShell, Message, StatusBar } from '@theia/core/lib/browser';
import { ApplicationShell, Message, StatusBar, WidgetManager } from '@theia/core/lib/browser';
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
import { inject, injectable, postConstruct } from 'inversify';
import * as React from 'react';
Expand Down Expand Up @@ -71,6 +71,7 @@ export class TraceViewerWidget extends ReactWidget {
@inject(TheiaMessageManager) protected readonly _signalHandler: TheiaMessageManager;
@inject(MessageService) protected readonly messageService: MessageService;
@inject(TraceExplorerContribution) protected readonly traceExplorerContribution: TraceExplorerContribution;
@inject(WidgetManager) protected readonly widgetManager!: WidgetManager;

@postConstruct()
async init(): Promise<void> {
Expand Down Expand Up @@ -204,14 +205,23 @@ export class TraceViewerWidget extends ReactWidget {
} else {
const experiment = await this.experimentManager.openExperiment(this.uri.name + this.uri.ext, traces);
if (experiment) {
this.openedExperiment = experiment;
this.title.label = 'Trace: ' + experiment.name;
this.id = experiment.UUID;

if (this.isVisible) {
const widgets = this.widgetManager.getWidgets(TraceViewerWidget.ID);
const widget = widgets.find(w => w.id === experiment.UUID);
let sendSignal = true;
if (widget) {
// Close widget if it had been opened previously.
cancellation.cancel();
this.dispose();
} else {
this.openedExperiment = experiment;
this.title.label = 'Trace: ' + experiment.name;
this.id = experiment.UUID;
sendSignal = this.isVisible;
this.fetchMarkerSets(experiment.UUID);
}
if (sendSignal) {
signalManager().fireTraceViewerTabActivatedSignal(experiment);
}
this.fetchMarkerSets(experiment.UUID);
this.traceExplorerContribution.openView({
activate: true
});
Expand Down

0 comments on commit ccddaaf

Please sign in to comment.