Skip to content

Commit

Permalink
set dirty icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmetanakol authored and edgarmueller committed Aug 29, 2018
1 parent 71afecb commit eaf4478
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/browser/ResourceSaveable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Disposable, Event, MaybePromise, Resource } from '@theia/core/lib/common';
import { Saveable } from "@theia/core/lib/browser";
import {Saveable, WidgetManager} from "@theia/core/lib/browser";
import { DIRTY_CLASS, TreeEditorWidget } from './theia-tree-editor-widget';
import * as _ from 'lodash';
import { unmanaged } from 'inversify';

export class ResourceSaveable implements Saveable {
autoSave;
Expand All @@ -16,7 +19,9 @@ export class ResourceSaveable implements Saveable {
}
);

constructor(private resource: Resource, private getData: () => any) {}
constructor(private resource: Resource,
private getData: () => any,
@unmanaged() protected readonly widgetManager: WidgetManager) {}

save(): MaybePromise<void> {
return this.onSave(this.getData()).then(this.doSave)
Expand All @@ -27,6 +32,9 @@ export class ResourceSaveable implements Saveable {
return this.resource.saveContents(content, { encoding: 'UTF-8' })
.then(() => {
this.dirty = false;
const widget = _.head(this.widgetManager.getWidgets('theia-tree-editor')) as TreeEditorWidget;
const dirtyClass = ` ${DIRTY_CLASS}`;
widget.title.className = widget.title.className.replace(dirtyClass, '');
});
} else {
console.warn('resource cannot save');
Expand Down
1 change: 0 additions & 1 deletion src/browser/theia-tree-editor-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { OpenerOptions, WidgetManager, WidgetOpenHandler } from '@theia/core/lib
import { EditorContextMenu } from '@theia/editor/lib/browser';
import { TreeEditorWidget } from './theia-tree-editor-widget';


export const UISchemaDownloadCommand = {
id: 'UISchemaDownload.command',
label: "Download UI Schema"
Expand Down
3 changes: 2 additions & 1 deletion src/browser/theia-tree-editor-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const defaultResourceParser = (content: string): Promise<any> => {
};

let widgetCounter = 0;
export const DIRTY_CLASS = 'theia-mod-dirty';
@injectable()
export class TreeEditorWidget extends BaseWidget implements SaveableSource {
saveable: Saveable;
Expand Down Expand Up @@ -57,7 +58,7 @@ export class TreeEditorWidget extends BaseWidget implements SaveableSource {
.then(parsedContent => {
Promise.resolve(this.store).then(initializedStore => {
initializedStore.dispatch(Actions.update('', () => parsedContent));
const Editor = withProps({'saveable': this.saveable})(this.options.EditorComponent);
const Editor = withProps({'widget': this})(this.options.EditorComponent);
ReactDOM.render(
<Provider store={initializedStore}>
<Editor/>
Expand Down
2 changes: 1 addition & 1 deletion src/browser/tree-editor-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface TreeEditorProps {
filterPredicate: any;
labelProvider: any;
imageProvider: any;
saveable: any;
widget: any;
}

export interface LabelDefinition {
Expand Down

0 comments on commit eaf4478

Please sign in to comment.