-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
359 additions
and
53 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
packages/console/src/browser/console-session-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { Emitter, Disposable, DisposableCollection } from '@theia/core'; | ||
import { ConsoleSession } from './console-session'; | ||
import { Severity } from '@theia/core/lib/common/severity'; | ||
|
||
@injectable() | ||
export class ConsoleSessionManager implements Disposable { | ||
|
||
protected readonly sessions = new Map<string, ConsoleSession>(); | ||
protected _selectedSession: ConsoleSession | undefined; | ||
protected _severity: Severity | undefined; | ||
|
||
protected readonly sessionAddedEmitter = new Emitter<ConsoleSession>(); | ||
protected readonly sessionDeletedEmitter = new Emitter<ConsoleSession>(); | ||
protected readonly sessionWasShownEmitter = new Emitter<ConsoleSession>(); | ||
protected readonly sessionWasHiddenEmitter = new Emitter<ConsoleSession>(); | ||
protected readonly selectedSessionChangedEmitter = new Emitter<ConsoleSession | undefined>(); | ||
protected readonly severityChangedEmitter = new Emitter<void>(); | ||
|
||
readonly onSessionAdded = this.sessionAddedEmitter.event; | ||
readonly onSessionDeleted = this.sessionDeletedEmitter.event; | ||
readonly onSessionWasShown = this.sessionWasShownEmitter.event; | ||
readonly onSessionWasHidden = this.sessionWasHiddenEmitter.event; | ||
readonly onSelectedSessionChanged = this.selectedSessionChangedEmitter.event; | ||
readonly onSeverityChanged = this.severityChangedEmitter.event; | ||
|
||
protected readonly toDispose = new DisposableCollection(); | ||
protected readonly toDisposeOnSessionDeletion = new Map<string, Disposable>(); | ||
|
||
dispose(): void { | ||
this.toDispose.dispose(); | ||
} | ||
|
||
get severity(): Severity | undefined { | ||
return this._severity; | ||
} | ||
|
||
set severity(value: Severity | undefined) { | ||
value = value || Severity.Ignore; | ||
this._severity = value; | ||
for (const session of this.sessions.values()) { | ||
session.severity = value; | ||
} | ||
this.severityChangedEmitter.fire(undefined); | ||
} | ||
|
||
get all(): ConsoleSession[] { | ||
return Array.from(this.sessions.values()); | ||
} | ||
|
||
get selectedSession(): ConsoleSession | undefined { | ||
return this._selectedSession; | ||
} | ||
|
||
set selectedSession(session: ConsoleSession | undefined) { | ||
const oldSession = this.selectedSession; | ||
this._selectedSession = session; | ||
this.selectedSessionChangedEmitter.fire(session); | ||
if (oldSession !== session) { | ||
if (oldSession) { | ||
this.sessionWasHiddenEmitter.fire(oldSession); | ||
} | ||
if (session) { | ||
this.sessionWasShownEmitter.fire(session); | ||
} | ||
} | ||
} | ||
|
||
get(id: string): ConsoleSession | undefined { | ||
return this.sessions.get(id); | ||
} | ||
|
||
add(session: ConsoleSession): void { | ||
this.sessions.set(session.id, session); | ||
this.sessionAddedEmitter.fire(session); | ||
if (this.sessions.size === 1) { | ||
this.selectedSession = session; | ||
} | ||
} | ||
|
||
delete(id: string): void { | ||
const session = this.sessions.get(id); | ||
if (this.sessions.delete(id) && session) { | ||
this.sessionDeletedEmitter.fire(session); | ||
if (this.sessions.size === 0) { | ||
this.selectedSessionChangedEmitter.fire(undefined); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.