update Antedit

This commit is contained in:
lxsang 2021-11-22 18:51:29 +01:00
parent afade6884e
commit 2813117cc0
9 changed files with 106 additions and 16 deletions

View File

@ -6,6 +6,7 @@ The editor functionality can be extended by its extension mechanism.
Extension can be developed/released/isntalled by the editor itself. Extension can be developed/released/isntalled by the editor itself.
### Change logs ### Change logs
- 0.1.13-b: Allow file upload in file view, add menu context in tabbar
- 0.1.12-b: fix recent files not adding correctly - 0.1.12-b: fix recent files not adding correctly
- 0.1.11-b: fix file type parsing from path - 0.1.11-b: fix file type parsing from path
- 0.1.10-b: Antedit now has it own extension manager - 0.1.10-b: Antedit now has it own extension manager

View File

@ -6,6 +6,7 @@ The editor functionality can be extended by its extension mechanism.
Extension can be developed/released/isntalled by the editor itself. Extension can be developed/released/isntalled by the editor itself.
### Change logs ### Change logs
- 0.1.13-b: Allow file upload in file view, add menu context in tabbar
- 0.1.12-b: fix recent files not adding correctly - 0.1.12-b: fix recent files not adding correctly
- 0.1.11-b: fix file type parsing from path - 0.1.11-b: fix file type parsing from path
- 0.1.10-b: Antedit now has it own extension manager - 0.1.10-b: Antedit now has it own extension manager

File diff suppressed because one or more lines are too long

View File

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

Binary file not shown.

View File

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

View File

@ -1,5 +1,5 @@
namespace OS { namespace OS {
declare var $:any; //declare var $:any;
export namespace application { export namespace application {
/** /**
@ -69,6 +69,9 @@ namespace OS {
*/ */
private container: HTMLElement; private container: HTMLElement;
/**
* Editor status monitoring
*/
onstatuschange: (stat: GenericObject<any>) => void; onstatuschange: (stat: GenericObject<any>) => void;
/** /**
@ -190,12 +193,11 @@ namespace OS {
/** /**
* Close a tab when a file is closed * Close a tab when a file is closed
* *
* @private
* @param {GUI.tag.ListViewItemTag} it reference to the tab to close * @param {GUI.tag.ListViewItemTag} it reference to the tab to close
* @returns {boolean} * @returns {boolean}
* @memberof BaseEditorModel * @memberof BaseEditorModel
*/ */
private closeTab(it: GUI.tag.ListViewItemTag): boolean { closeTab(it: GUI.tag.ListViewItemTag): boolean {
this.tabbar.delete(it); this.tabbar.delete(it);
const cnt = this.tabbar.items.length; const cnt = this.tabbar.items.length;
@ -387,6 +389,28 @@ namespace OS {
return this.dirties().length > 0; return this.dirties().length > 0;
} }
/**
* Set model tabbar menu context event
*
* @memberof BaseEditorModel
*/
setTabbarCtxMenu(items: GenericObject<any>[], handle:(tab:GUI.tag.ListViewItemTag, mdata: GenericObject<any>) => void): void
{
this.tabbar.contextmenuHandle = (evt, m) => {
m.items = items;
m.onmenuselect = (e) => {
if(handle)
{
/**
* get the tab under the cursor
*/
const tab = $(evt.target).closest("afx-list-item");
handle(tab[0], e.data.item.data);
}
};
return m.show(evt);
}
}
/** /**
* Set up the editor instance * Set up the editor instance

View File

@ -332,15 +332,17 @@ namespace OS {
monaco.editor.setTheme("vs-dark"); monaco.editor.setTheme("vs-dark");
// add editor instance // add editor instance
this.eum const left_editor = new OS.application.MonacoEditorModel(
.add(new OS.application.MonacoEditorModel(
this, this,
this.find("left-tabbar") as GUI.tag.TabBarTag, this.find("left-tabbar") as GUI.tag.TabBarTag,
this.find("left-editorarea")) as BaseEditorModel) this.find("left-editorarea")) as BaseEditorModel;
.add(new OS.application.MonacoEditorModel( const right_editor = new OS.application.MonacoEditorModel(
this, this,
this.find("right-tabbar") as GUI.tag.TabBarTag, this.find("right-tabbar") as GUI.tag.TabBarTag,
this.find("right-editorarea")) as BaseEditorModel); this.find("right-editorarea")) as BaseEditorModel;
left_editor.setTabbarCtxMenu(this.tb_ctxmenu, (tab, data) => this.tabbar_ctx_menu_handle(tab,data, left_editor));
right_editor.setTabbarCtxMenu(this.tb_ctxmenu, (tab, data) => this.tabbar_ctx_menu_handle(tab,data, right_editor));
this.eum.add(left_editor).add(right_editor);
this.eum.onstatuschange = (st) => this.eum.onstatuschange = (st) =>
this.updateStatus(st) this.updateStatus(st)
$(wrapper).css('visibility', 'visible'); $(wrapper).css('visibility', 'visible');
@ -348,6 +350,54 @@ namespace OS {
this.eum.active.openFile(file); this.eum.active.openFile(file);
} }
/**
* Get the context menu items
*/
private get tb_ctxmenu(): GenericObject<any>[]
{
return [
{ text: "__(Close)", id: "close" },
{ text: "__(Close All)", id: "close-all" },
{ text: "__(Move to other side)", id: "mv-side" },
];
}
private tabbar_ctx_menu_handle(tab: GUI.tag.ListViewItemTag, data: GenericObject<any>, model: BaseEditorModel): void {
switch(data.id)
{
case "close":
if(!tab)
{
return;
}
model.closeTab(tab);
break;
case "close-all":
model.closeAll();
model.openFile("Untitled".asFileHandle() as EditorFileHandle)
break;
case "mv-side":
if(!tab)
{
return;
}
let other_model = this.eum.editors[0];
if(model == other_model)
{
other_model = this.eum.editors[1];
}
other_model.openFile(tab.data as EditorFileHandle);
model.closeTab(tab);
if(this.split_mode == false)
{
this.toggleSplitMode();
}
break;
default:
break;
}
}
/** /**
* Set up the text editor * Set up the text editor
* *
@ -390,6 +440,7 @@ namespace OS {
{ text: "__(New folder)", id: "newdir" }, { text: "__(New folder)", id: "newdir" },
{ text: "__(Rename)", id: "rename" }, { text: "__(Rename)", id: "rename" },
{ text: "__(Delete)", id: "delete" }, { text: "__(Delete)", id: "delete" },
{ text: "__(Upload)", id: "upload" },
]; ];
m.onmenuselect = (e) => { m.onmenuselect = (e) => {
return this.ctxFileMenuHandle(e); return this.ctxFileMenuHandle(e);
@ -806,7 +857,7 @@ namespace OS {
} catch (e) { } catch (e) {
return this.error( return this.error(
__("Fail to create: {0}", e.stack), __("Fail to create: {0}", e.stack),
e __e(e)
); );
} }
}); });
@ -826,7 +877,7 @@ namespace OS {
} catch (e) { } catch (e) {
return this.error( return this.error(
__("Fail to create: {0}", dir.path), __("Fail to create: {0}", dir.path),
e __e(e)
); );
} }
}); });
@ -852,7 +903,7 @@ namespace OS {
} catch (e) { } catch (e) {
return this.error( return this.error(
__("Fail to rename: {0}", file.path), __("Fail to rename: {0}", file.path),
e __e(e)
); );
} }
}); });
@ -881,11 +932,23 @@ namespace OS {
} catch (e) { } catch (e) {
return this.error( return this.error(
__("Fail to delete: {0}", file.path), __("Fail to delete: {0}", file.path),
e __e(e)
); );
} }
}); });
break; break;
case "upload":
if(!dir)
{
return;
}
dir.upload()
.then((d) => {
this.notify(__("File uploaded to: {0}", dir.path));
return this.fileview.update(dir.path);
})
.catch((e) => this.error(__("Unable to upload file: {e}", e.toString()), __e(e)));
break;
default: default:
} }
} }
@ -1288,6 +1351,7 @@ namespace OS {
} }
} }
dirties(): EditorFileHandle[] { dirties(): EditorFileHandle[] {
let list = []; let list = [];
for (let ed of this.models) { for (let ed of this.models) {

View File

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