Antedit: allow reload current editing file

This commit is contained in:
Dany LE 2022-08-25 12:41:47 +02:00
parent e16959c28d
commit 6fe3723e48
8 changed files with 1782 additions and 911 deletions

View File

@ -4,8 +4,8 @@ the editor that powers VS Code.
The editor functionality can be extended by its extension mechanism.
Extension can be developed/released/isntalled by the editor itself.
### Change logs
- 0.2.3-b: Allow reload current file via context menu in case of external changes
- 0.2.2-b: Support horizotal scrolling on horizotal tabbars
- 0.2.1-b: Add open file to right, editor actions are only attached to code editor
- 0.2.0-b: Support diff mode in editor + fix new Monaco version compatible bug

Binary file not shown.

View File

@ -7,7 +7,7 @@
"author": "Xuan Sang LE",
"email": "mrsang@iohub.dev"
},
"version": "0.2.2-b",
"version": "0.2.3-b",
"category": "Development",
"iconclass": "bi bi-journal-code",
"mimes": [

View File

@ -159,7 +159,7 @@ namespace OS {
* @type {boolean}
* @memberof BaseEditorModel
*/
//private editormux: boolean;
private editormux: boolean;
/**
@ -176,7 +176,7 @@ namespace OS {
this.tabbar = tabbar;
this.editorSetup(editorarea);
this.app = app;
// this.editormux = false;
this.editormux = false;
this.onstatuschange = undefined;
this.on("focus", () => {
@ -184,12 +184,10 @@ namespace OS {
this.onstatuschange(this.getEditorStatus());
});
this.on("input", () => {
// console.log(this.editormux, this.currfile.dirty);
/*if (this.editormux) {
if (this.editormux) {
this.editormux = false;
console.log("set editor mux to false");
return false;
}*/
}
if (!this.currfile.dirty) {
this.currfile.dirty = true;
this.currfile.text += "*";
@ -401,6 +399,47 @@ namespace OS {
return this.saveAs();
}
/**
* Reload the current openned file
*
* @return {*} {Promise<any>}
* @memberof BaseEditorModel
*/
reload(): Promise<any> {
return new Promise(async (ok,r) =>{
try {
if (this.currfile.path.toString() === "Untitled") {
return ok(true);
}
if(this.currfile.dirty)
{
const ret = await this.app.openDialog("YesNoDialog", {
title: __("File modified"),
text: __("Continue without saving ?"),
});
if(!ret)
{
return ok(true);
}
}
const d = await this.currfile.read();
this.currfile.cache = d || "";
this.currfile.dirty = false;
this.currfile.text = this.currfile.basename ? this.currfile.basename : this.currfile.path;
this.editormux = true;
this.setValue(this.currfile.cache);
this.tabbar.update(undefined);
}
catch(e){
this.app.error(
__("Unable to open: {0}", this.currfile.path),
e
);
r(e);
};
})
}
/**
* Save the current file as another file
*

View File

@ -62,6 +62,10 @@ namespace OS {
this.editor.setPosition(model.position);
this.editor.revealLineInCenter(model.position.lineNumber);
}
if(this.editor == this._code_editor)
{
this.editor.updateOptions({readOnly: false, domReadOnly: false});
}
}
@ -208,7 +212,7 @@ namespace OS {
* @memberof MonacoEditorModel
*/
protected editorSetup(el: HTMLElement): void {
// create two editor instancs for code mode and diff mode
// create two editor instances for code mode and diff mode
this.code_container = $("<div />")
.css("width", "100%")
.css("height", "100%");
@ -220,7 +224,9 @@ namespace OS {
$(el).append(this.diff_container);
this._code_editor = monaco.editor.create(this.code_container[0], {
value: "",
language: 'textplain'
language: 'textplain',
readOnly: false,
domReadOnly: false
});
this._diff_editor = monaco.editor.createDiffEditor(this.diff_container[0],{
readOnly: true

View File

@ -367,6 +367,7 @@ namespace OS {
{
return [
{ text: "__(Close)", id: "close" },
{ text: "__(Reload)", id: "reload", shortcut: "A-R"},
{ text: "__(Close All)", id: "close-all" },
{ text: "__(Move to other side)", id: "mv-side" },
];
@ -385,6 +386,9 @@ namespace OS {
case "close-all":
model.closeAll();
break;
case "reload":
this.eum.active.reload();
break;
case "mv-side":
if(!tab)
{
@ -471,6 +475,7 @@ namespace OS {
this.bindKey("ALT-F", () => this.menuAction("opendir"));
this.bindKey("CTRL-S", () => this.menuAction("save"));
this.bindKey("ALT-W", () => this.menuAction("saveas"));
this.bindKey("ALT-R", () => this.eum.active.reload());
const list_container = $(".list-container", this.find("editor-main-container"));
list_container.each((i,el) => {

2621
Antedit/ts/monaco.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antedit/README.md",
"category": "Development",
"author": "Xuan Sang LE",
"version": "0.2.2-b",
"version": "0.2.3-b",
"dependencies": ["MonacoCore@0.33.0-r"],
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antedit/build/release/Antedit.zip"
},