Skip to content

Commit

Permalink
Dirty Editors
Browse files Browse the repository at this point in the history
Fixes: eclipse-theia#8296

1. Fix disposable.
2. fix code.

Signed-off-by: Anas Shahid <[email protected]>
  • Loading branch information
Anas Shahid committed Aug 4, 2020
1 parent fe24630 commit fc1d495
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/navigator/src/browser/navigator-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ import { NavigatorContextKeyService } from './navigator-context-key-service';
import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { NavigatorDiff } from './navigator-diff';
import { NavigatorLayoutVersion3Migration } from './navigator-layout-migrations';
import { NavigatorWidgetTabBarDecorator } from './navigator-widget-tab-bar-decorator';
import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator';

export default new ContainerModule(bind => {
bindFileNavigatorPreferences(bind);
bind(FileNavigatorFilter).toSelf().inSingletonScope();

bind(NavigatorContextKeyService).toSelf().inSingletonScope();

bindViewContribution(bind, FileNavigatorContribution);
bind(FrontendApplicationContribution).toService(FileNavigatorContribution);
bind(TabBarToolbarContribution).toService(FileNavigatorContribution);
Expand Down Expand Up @@ -72,4 +73,6 @@ export default new ContainerModule(bind => {
bind(ApplicationShellLayoutMigration).to(NavigatorLayoutVersion3Migration).inSingletonScope();

bind(NavigatorDiff).toSelf().inSingletonScope();
bind(NavigatorWidgetTabBarDecorator).toSelf().inSingletonScope();
bind(TabBarDecorator).toService(NavigatorWidgetTabBarDecorator);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/********************************************************************************
* Copyright (C) 2020 Ericsson 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, inject, postConstruct } from 'inversify';
import { Event, Emitter } from '@theia/core/lib/common/event';
import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator';
import { EXPLORER_VIEW_CONTAINER_ID } from './navigator-widget';
import { Title, Widget, ApplicationShell, Navigatable, Saveable } from '@theia/core/lib/browser';
import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';

@injectable()
export class NavigatorWidgetTabBarDecorator implements TabBarDecorator {

readonly id = 'theia-navigator-widget-tabbar-decorator';
protected readonly emitter = new Emitter<void>();

@inject(ApplicationShell)
protected readonly shell: ApplicationShell;

@postConstruct()
protected init(): void {
this.shell.onDidAddWidget(w => {
console.dir(w);
if (Navigatable.is(w) && Saveable.isSource(w)) {
w.saveable.onDirtyChanged(() => console.log('object'));
}
});
}

decorate(title: Title<Widget>): WidgetDecoration.Data[] {
if (title.owner.id === EXPLORER_VIEW_CONTAINER_ID) {
const changes = this.getDirtyEditors().length;
return changes > 0 ? [{ badge: changes }] : [];
} else {
return [];
}
}

getDirtyEditors(): Widget[] {
return this.shell.widgets.filter(widget => Navigatable.is(widget) && Saveable.isDirty(widget));
}

get onDidChangeDecorations(): Event<void> {
return this.emitter.event;
}

protected fireDidChangeDecorations(): void {
this.emitter.fire(undefined);
}
}

0 comments on commit fc1d495

Please sign in to comment.