forked from eclipsesource/theia-tree-editor-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Saveable refactor (eclipsesource#22)
Provide preliminary API to allow overriding of save and load behavior
- Loading branch information
1 parent
b04842e
commit 5737a22
Showing
4 changed files
with
72 additions
and
65 deletions.
There are no files selected for viewing
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,41 @@ | ||
import { Disposable, Event, MaybePromise, Resource } from '@theia/core/lib/common'; | ||
import { Saveable } from "@theia/core/lib/browser"; | ||
|
||
export class ResourceSaveable implements Saveable { | ||
autoSave; | ||
dirty: boolean = false; | ||
onDirtyChanged: Event<void> = Object.assign((listener: (e) => any) => { | ||
let result: Disposable; | ||
result = { | ||
dispose: () => {} | ||
}; | ||
|
||
return result; | ||
}, { | ||
maxListeners: 30 | ||
} | ||
); | ||
|
||
constructor(private resource: Resource, private getData: () => any) {} | ||
|
||
save(): MaybePromise<void> { | ||
return this.onSave(this.getData()).then(this.doSave) | ||
} | ||
|
||
doSave = (content: string): MaybePromise<void> => { | ||
if ( this.resource.saveContents !== undefined ) { | ||
return this.resource.saveContents(content, { encoding: 'UTF-8' }) | ||
.then(() => { | ||
this.dirty = false; | ||
}); | ||
} else { | ||
console.warn('resource cannot save'); | ||
return undefined; | ||
} | ||
} | ||
|
||
onSave(data: any): Promise<string> { | ||
const content = JSON.stringify(data, null, 2); | ||
return Promise.resolve(content); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './theia-tree-editor-widget'; | ||
export * from './tree-editor-utils'; | ||
|
||
export * from './ResourceSaveable'; |
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