update compatibility to AntOS next

This commit is contained in:
mrsang
2021-04-21 11:37:58 +02:00
parent bc33f7ff10
commit 190c2fd346
1014 changed files with 96281 additions and 2092 deletions

6
CodePad/README.md Normal file
View File

@ -0,0 +1,6 @@
# CodePad
A simple yet powerful code/text editor.
CodePad is a text editor based on the ACE editor.
## Change logs
- v0.1.5-a: CodePad moved out of AntOS based system as regular AntOS package

170
CodePad/assets/main.css Normal file
View File

@ -0,0 +1,170 @@
afx-app-window[data-id = "codepad"] .ace_editor {
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container
{
/*border-top: 1px solid #272822;*/
overflow: hidden;
overflow-x: auto;
font-size: 12px;
scrollbar-width: none;
/*scrollbar-color: #656565 transparent;*/
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container::-webkit-scrollbar {
height: 0;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container::-webkit-scrollbar-track {
background: transparent;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container::-webkit-scrollbar-thumb {
background-color: #656565;
border: 0;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul
{
width: intrinsic;
width: -moz-max-content;
width: -webkit-max-content;
width: max-content;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view ul afx-list-item:nth-child(even) li.selected,
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul > afx-list-item > li.selected{
background-color:#272822;
color:white;
border: 0;
border-radius: 0;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view afx-list-view i.closable:before {
color:afafaf;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view ul afx-list-item:nth-child(even) li,
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul li{
background-color:#333333;
color:#afafaf;
border-radius: 0;
border: 0;
padding-top: 5px;
padding-bottom: 5px;
padding-right: 20px;
border-right: 1px solid #272822;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-vbox[data-id = "sidebar"]{
background-color:#272822;
}
afx-app-window[data-id = "codepad"] div.afx-window-content {
background-color:#333333;
}
afx-app-window[data-id = "codepad"] afx-resizer {
background-color:#272822;
border-right: 1px solid #656565;
border-bottom: 1px solid #656565;
}
afx-app-window[data-id = "codepad"] .bottom-tab-content {
background-color:#272822;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-tree-view{
color: white;
padding: 0;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-tree-view afx-tree-view-item ul li{
padding-left: 10px;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper .afx_tree_item_selected ul{
background-color: #116cd6;
}
afx-app-window[data-id = "codepad"] afx-file-view afx-tree-view .afx-tree-view-item:before{
color: white;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper div[data-id="statctn"]{
color: white;
background-color: #007acc;
padding-right: 10px;
padding-top: 5px;
font-size: 11px;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper div[data-id="statctn"] afx-label {
padding-left: 10px;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper{
border-radius: 0px;
border: 0;
/*border: 1px solid #37373d;*/
background-color: transparent;
box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.65);
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper afx-list-view ul afx-list-item:nth-child(even) li
{
background-color: transparent;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper afx-list-view afx-list-item li{
background-color: transparent;
color:#afafaf;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper div.list-container > ul li:hover{
background-color: #37373d;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper afx-list-view ul afx-list-item:nth-child(even) li.selected,
afx-app-window[data-id = "cmd-win"] .afx-window-wrappe dafx-list-viewafx-list-view ul li.selected
{
background-color: #116cd6;
color:white;
}
afx-app-window[data-id = "cmd-win"] .afx-window-top{
height: 0;
border:0;
}
afx-app-window[data-id = "cmd-win"] input{
border: 1px solid #007acc;
border-radius: 0;
font-size: 12px;
color:#afafaf;
background-color:#272822;
padding-left: 5px;
margin: 3px;
}
afx-app-window[data-id = "cmd-win"] .afx-window-content{
background-color:#272822;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] {
overflow-y: auto;
overflow-x: hidden;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre {
margin: 3px;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
font-family: monospace;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre.code-pad-log-error {
color: red;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre.code-pad-log-warn {
color: orange;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre.code-pad-log-info {
color: white;
}
afx-app-window[data-id = "codepad"] afx-button[ data-id="logger-clear" ] button{
border: 0;
background: transparent;
}

View File

@ -0,0 +1,38 @@
<afx-app-window apptitle="Code" width="600" height="400" data-id="codepad">
<afx-vbox>
<afx-hbox>
<afx-vbox data-width = "155" min-width="155" data-id = "sidebar">
<div data-height="10"></div>
<afx-file-view chdir="false" data-id = "fileview" view="tree" status = "false">
</afx-file-view>
</afx-vbox>
<afx-resizer data-width = "3" ></afx-resizer>
<afx-vbox>
<afx-hbox>
<afx-vbox data-id="left-panel">
<afx-tab-bar closable="true" data-height="26" data-id = "left-tabbar"></afx-tab-bar>
<div data-id="left-editorarea"></div>
</afx-vbox>
<afx-resizer data-width="3"></afx-resizer>
<afx-vbox data-id="right-panel">
<afx-tab-bar closable="true" data-height="26" data-id = "right-tabbar"></afx-tab-bar>
<div data-id="right-editorarea"></div>
</afx-vbox>
</afx-hbox>
<afx-resizer data-height = "3" dir = "ve" attachnext = "true" ></afx-resizer>
<afx-tab-container data-id = "bottombar" data-height="150" min-height="150" tabbarheight= "22">
<afx-hbox tabname="__(Output)" iconclass = "fa fa-file-text" class = "bottom-tab-content">
<afx-button text = "" data-id="logger-clear" iconclass="fa fa-trash" data-width="21"></afx-button>
<div data-id="output-tab" iconclass = "fa fa-file-text" >
</div>
</afx-hbox>
</afx-tab-container>
</afx-vbox>
</afx-hbox>
<div data-height="20" data-id="statctn">
<afx-label text=" " data-id = "current-file-lbl" style="float:left;"></afx-label>
<afx-label data-id="langstat" style="float:right; padding-right: 10px;"></afx-label>
<afx-label data-id="editorstat" style="float:right;"></afx-label>
</div>
</afx-vbox>
</afx-app-window>

87
CodePad/build.json Normal file
View File

@ -0,0 +1,87 @@
{
"name": "CodePad",
"targets":{
"clean": {
"jobs": [
{
"name": "vfs-rm",
"data": ["build/debug","build/release"]
}
]
},
"build": {
"require": ["ts"],
"jobs":[
{
"name": "vfs-mkdir",
"data": ["build","build/debug","build/release"]
},
{
"name": "ts-import",
"data": ["sdk://core/ts/core.d.ts", "sdk://core/ts/jquery.d.ts","sdk://core/ts/antos.d.ts"]
},
{
"name": "ts-compile",
"data": {
"src": [
"ts/ACEModel.ts",
"ts/BaseEditorModel.ts",
"ts/main.ts"
],
"dest": "build/debug/main.js"
}
}
]
},
"uglify": {
"require": ["terser"],
"jobs": [
{
"name":"terser-uglify",
"data": ["build/debug/main.js"]
}
]
},
"copy": {
"jobs": [
{
"name": "vfs-cp",
"data": {
"src": [
"assets/main.css",
"assets/scheme.html",
"package.json",
"README.md"
],
"dest":"build/debug"
}
}
]
},
"debug": {
"depend": ["build", "copy"]
},
"run": {
"depend": ["debug"],
"jobs": [
{
"name": "sdk-run-app",
"data": "build/debug"
}
]
},
"release": {
"depend": ["debug","uglify"],
"require": ["zip"],
"jobs": [
{
"name": "zip-mk",
"data": {
"src":"build/debug",
"dest":"build/release/CodePad.zip"
}
}
]
}
}
}

View File

@ -0,0 +1,6 @@
# CodePad
A simple yet powerful code/text editor.
CodePad is a text editor based on the ACE editor.
## Change logs
- v0.1.5-a: CodePad moved out of AntOS based system as regular AntOS package

View File

@ -0,0 +1,170 @@
afx-app-window[data-id = "codepad"] .ace_editor {
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container
{
/*border-top: 1px solid #272822;*/
overflow: hidden;
overflow-x: auto;
font-size: 12px;
scrollbar-width: none;
/*scrollbar-color: #656565 transparent;*/
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container::-webkit-scrollbar {
height: 0;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container::-webkit-scrollbar-track {
background: transparent;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container::-webkit-scrollbar-thumb {
background-color: #656565;
border: 0;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul
{
width: intrinsic;
width: -moz-max-content;
width: -webkit-max-content;
width: max-content;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view ul afx-list-item:nth-child(even) li.selected,
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul > afx-list-item > li.selected{
background-color:#272822;
color:white;
border: 0;
border-radius: 0;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view afx-list-view i.closable:before {
color:afafaf;
}
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view ul afx-list-item:nth-child(even) li,
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul li{
background-color:#333333;
color:#afafaf;
border-radius: 0;
border: 0;
padding-top: 5px;
padding-bottom: 5px;
padding-right: 20px;
border-right: 1px solid #272822;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-vbox[data-id = "sidebar"]{
background-color:#272822;
}
afx-app-window[data-id = "codepad"] div.afx-window-content {
background-color:#333333;
}
afx-app-window[data-id = "codepad"] afx-resizer {
background-color:#272822;
border-right: 1px solid #656565;
border-bottom: 1px solid #656565;
}
afx-app-window[data-id = "codepad"] .bottom-tab-content {
background-color:#272822;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-tree-view{
color: white;
padding: 0;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-tree-view afx-tree-view-item ul li{
padding-left: 10px;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper .afx_tree_item_selected ul{
background-color: #116cd6;
}
afx-app-window[data-id = "codepad"] afx-file-view afx-tree-view .afx-tree-view-item:before{
color: white;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper div[data-id="statctn"]{
color: white;
background-color: #007acc;
padding-right: 10px;
padding-top: 5px;
font-size: 11px;
}
afx-app-window[data-id = "codepad"] .afx-window-wrapper div[data-id="statctn"] afx-label {
padding-left: 10px;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper{
border-radius: 0px;
border: 0;
/*border: 1px solid #37373d;*/
background-color: transparent;
box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.65);
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper afx-list-view ul afx-list-item:nth-child(even) li
{
background-color: transparent;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper afx-list-view afx-list-item li{
background-color: transparent;
color:#afafaf;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper div.list-container > ul li:hover{
background-color: #37373d;
}
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper afx-list-view ul afx-list-item:nth-child(even) li.selected,
afx-app-window[data-id = "cmd-win"] .afx-window-wrappe dafx-list-viewafx-list-view ul li.selected
{
background-color: #116cd6;
color:white;
}
afx-app-window[data-id = "cmd-win"] .afx-window-top{
height: 0;
border:0;
}
afx-app-window[data-id = "cmd-win"] input{
border: 1px solid #007acc;
border-radius: 0;
font-size: 12px;
color:#afafaf;
background-color:#272822;
padding-left: 5px;
margin: 3px;
}
afx-app-window[data-id = "cmd-win"] .afx-window-content{
background-color:#272822;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] {
overflow-y: auto;
overflow-x: hidden;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre {
margin: 3px;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
font-family: monospace;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre.code-pad-log-error {
color: red;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre.code-pad-log-warn {
color: orange;
}
afx-app-window[data-id = "codepad"] div[data-id="output-tab"] pre.code-pad-log-info {
color: white;
}
afx-app-window[data-id = "codepad"] afx-button[ data-id="logger-clear" ] button{
border: 0;
background: transparent;
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,22 @@
{
"app":"CodePad",
"pkgname": "CodePad",
"name": "Code",
"description":"Code editor",
"info":{
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com",
"licences": "GPLv3"
},
"version":"0.1.5-b",
"category":"Development",
"iconclass":"fa fa-pencil-square-o",
"dependencies": ["ACECore@1.4.12-r"],
"mimes":[
"text/.*",
"[^/]*/json.*",
"[^/]*/.*ml",
"[^/]*/javascript",
"dir"
]
}

View File

@ -0,0 +1,38 @@
<afx-app-window apptitle="Code" width="600" height="400" data-id="codepad">
<afx-vbox>
<afx-hbox>
<afx-vbox data-width = "155" min-width="155" data-id = "sidebar">
<div data-height="10"></div>
<afx-file-view chdir="false" data-id = "fileview" view="tree" status = "false">
</afx-file-view>
</afx-vbox>
<afx-resizer data-width = "3" ></afx-resizer>
<afx-vbox>
<afx-hbox>
<afx-vbox data-id="left-panel">
<afx-tab-bar closable="true" data-height="26" data-id = "left-tabbar"></afx-tab-bar>
<div data-id="left-editorarea"></div>
</afx-vbox>
<afx-resizer data-width="3"></afx-resizer>
<afx-vbox data-id="right-panel">
<afx-tab-bar closable="true" data-height="26" data-id = "right-tabbar"></afx-tab-bar>
<div data-id="right-editorarea"></div>
</afx-vbox>
</afx-hbox>
<afx-resizer data-height = "3" dir = "ve" attachnext = "true" ></afx-resizer>
<afx-tab-container data-id = "bottombar" data-height="150" min-height="150" tabbarheight= "22">
<afx-hbox tabname="__(Output)" iconclass = "fa fa-file-text" class = "bottom-tab-content">
<afx-button text = "" data-id="logger-clear" iconclass="fa fa-trash" data-width="21"></afx-button>
<div data-id="output-tab" iconclass = "fa fa-file-text" >
</div>
</afx-hbox>
</afx-tab-container>
</afx-vbox>
</afx-hbox>
<div data-height="20" data-id="statctn">
<afx-label text=" " data-id = "current-file-lbl" style="float:left;"></afx-label>
<afx-label data-id="langstat" style="float:right; padding-right: 10px;"></afx-label>
<afx-label data-id="editorstat" style="float:right;"></afx-label>
</div>
</afx-vbox>
</afx-app-window>

Binary file not shown.

22
CodePad/package.json Normal file
View File

@ -0,0 +1,22 @@
{
"app":"CodePad",
"pkgname": "CodePad",
"name": "Code",
"description":"Code editor",
"info":{
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com",
"licences": "GPLv3"
},
"version":"0.1.5-b",
"category":"Development",
"iconclass":"fa fa-pencil-square-o",
"dependencies": ["ACECore@1.4.12-r"],
"mimes":[
"text/.*",
"[^/]*/json.*",
"[^/]*/.*ml",
"[^/]*/javascript",
"dir"
]
}

348
CodePad/ts/ACEModel.ts Normal file
View File

@ -0,0 +1,348 @@
var ace: any;
namespace OS {
export namespace application {
/**
* Wrapper model for the ACE text editor
*
* @export
* @class ACEModel
* @extends {BaseEditorModel}
*/
export class ACEModel extends BaseEditorModel {
/**
* Current editor mode
*
* @private
* @type {GenericObject<any>}
* @memberof ACEModel
*/
private mode: GenericObject<any>;
/**
* Reference to ACE language modes
*
* @private
* @type {GenericObject<any>}
* @memberof ACEModel
*/
private modes: GenericObject<any>;
/**
* Creates an instance of ACEModel.
* @param {ACEModel} app instance
* @param {GUI.tag.TabBarTag} tabbar tabbar element
* @param {HTMLElement} editorarea main editor container element
* @memberof ACEModel
*/
constructor(app: BaseApplication, tabbar: GUI.tag.TabBarTag, editorarea: HTMLElement) {
ace.require("ace/ext/language_tools");
super(app, tabbar, editorarea);
this.modes = ace.require("ace/ext/modelist");
}
/**
* Reset the editor
*
* @protected
* @memberof ACEModel
*/
protected resetEditor(): void {
this.setValue("");
this.editor.getSession().setUndoManager(new ace.UndoManager());
}
/**
* Get a text model from the current editor session
*
* @protected
* @return {*}
* @memberof ACEModel
*/
protected getTexModel() {
const textModel = {} as any;
textModel.cursor = this.editor.getCursorPosition();
textModel.cache = this.getValue();
textModel.um = this.editor.session.getUndoManager();
textModel.langmode = this.mode;
return textModel;
}
/**
* Set text model to current editor session
*
* @protected
* @param {*} model
* @memberof ACEModel
*/
protected setTextModel(model: any): void {
this.editor.getSession().setUndoManager(new ace.UndoManager());
this.setValue(model.cache);
this.setMode(model.langmode);
if (model.cursor) {
this.setCursor(model.cursor);
}
this.editor.getSession().setUndoManager(model.um);
}
/**
* Create new editor model from file
*
* @protected
* @param {EditorFileHandle} file
* @return {*} {*}
* @memberof ACEModel
*/
protected newTextModelFrom(file: EditorFileHandle): any {
const textModel = {} as any;
textModel.um = new ace.UndoManager();
textModel.cache = file.cache;
textModel.cursor = undefined;
if (file.path.toString() !== "Untitled") {
textModel.langmode = this.getModeForPath(file.path);
} else {
textModel.langmode = {
text: "Text",
mode: "ace/mode/text",
};
}
return textModel;
}
/**
* Get language modes
*
* @return {*} {GenericObject<any>[]}
* @memberof ACEModel
*/
getModes(): GenericObject<any>[] {
const list = [];
let v: GenericObject<any>;
for (v of Array.from(this.modes.modes)) {
list.push({ text: v.caption, mode: v.mode });
}
return list;
}
/**
* Set the editor theme
*
* @param {string} theme theme name
* @memberof ACEModel
*/
setTheme(theme: string): void {
this.editor.setTheme(theme);
}
/**
* Set the editor cursor
*
* @private
* @param {GenericObject<any>} c cursor option
* @memberof ACEModel
*/
private setCursor(c: GenericObject<any>): void {
this.editor.renderer.scrollCursorIntoView(
{
row: c.row,
column: c.column,
},
0.5
);
this.editor.selection.moveTo(
c.row,
c.column
);
}
/**
* Set editor language mode
*
* The mode object should be in the following format:
* ```ts
* {
* text: string,
* mode: string
* }
* ```
*
* @param {GenericObject<any>} m language mode object
* @memberof ACEModel
*/
setMode(m: GenericObject<any>): void {
this.mode = m;
this.editor.getSession().setMode(m.mode);
}
/**
* Reference to the editor instance
*
* @protected
* @type {GenericObject<any>}
* @memberof ACEModel
*/
protected editor: GenericObject<any>;
/**
* Setup the editor
*
* @protected
* @param {HTMLElement} el editor container DOM
* @memberof ACEModel
*/
protected editorSetup(el: HTMLElement): void {
this.editor = ace.edit(el);
this.editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
highlightActiveLine: true,
highlightSelectedWord: true,
behavioursEnabled: true,
wrap: true,
fontSize: "10pt",
showInvisibles: true,
});
this.editor.setTheme("ace/theme/monokai");
this.editor.completers.push({
getCompletions(
editor: any,
session: any,
pos: any,
prefix: any,
callback: any
) { },
});
this.editor.getSession().setUseWrapMode(true);
}
/**
* Register to editor event
*
* @param {string} evt_str event name
* @param {() => void} callback callback function
* @memberof ACEModel
*/
on(evt_str: string, callback: () => void): void {
switch (evt_str) {
case "input":
case "focus":
this.editor.on(evt_str, callback);
break;
case "changeCursor":
this.editor
.getSession()
.selection.on(evt_str, callback);
break;
default:
break;
}
}
/**
* Resize the editor
*
* @memberof ACEModel
*/
resize(): void {
this.editor.resize();
}
/**
* Focus on the editor
*
* @memberof ACEModel
*/
focus(): void {
this.editor.focus();
}
/**
* Get language mode from path
*
* @protected
* @param {string} path
* @return {*} {GenericObject<any>}
* @memberof ACEModel
*/
protected getModeForPath(path: string): GenericObject<any> {
const m = this.modes.getModeForPath(path);
return {
text: m.caption,
mode: m.mode
}
}
/**
* Get the editor status
*
* @return {*} {GenericObject<any>}
* @memberof ACEModel
*/
getEditorStatus(): GenericObject<any> {
const c = this.editor.session.selection.getCursor();
const l = this.editor.session.getLength();
return {
row: c.row,
column: c.column,
line: l,
langmode: this.mode,
file: this.currfile.path
}
}
/**
* Get editor value
*
* @return {*} {string}
* @memberof ACEModel
*/
getValue(): string {
return this.editor.getValue();
}
/**
* Set editor value
*
* @param {string} value
* @memberof ACEModel
*/
setValue(value: string): void {
this.editor.setValue(value, -1);
}
/**
* Get ACE themes
*/
getThemes(): any {
const themes = ace.require("ace/ext/themelist");
const data = [];
for(let k in themes.themesByName)
{
const v = themes.themesByName[k];
data.push({ text: v.caption, theme: v.theme });
}
return data;
}
}
}
}

View File

@ -0,0 +1,572 @@
namespace OS {
declare var $:any;
export namespace application {
/**
* Extends the [[RemoteFileHandle]] interface with some useful
* properties used by the Editor API
*/
export type EditorFileHandle = API.VFS.RemoteFileHandle & {
/**
* The text will be displayed on the tab bar when opened
*
* @type {string}
*/
text: string;
/**
* Editor text model attached to the file
* modification history of the file
*
* @type {any}
*/
textModel: any;
/**
* Indicate whether the file is selected
*
* @type {boolean}
*/
selected: boolean;
};
export abstract class BaseEditorModel {
/**
* Reference to the current editing file handle
*
* @protected
* @type {EditorFileHandle}
* @memberof BaseEditorModel
*/
protected currfile: EditorFileHandle;
/**
* Referent to the parent app
*
* @private
* @type {BaseApplication}
* @memberof BaseEditorModel
*/
private app: BaseApplication;
/**
* Reference to the editor tab bar UI
*
* @private
* @type {GUI.tag.TabBarTag}
* @memberof BaseEditorModel
*/
private tabbar: GUI.tag.TabBarTag;
/**
* Referent to the editor container
*
* @private
* @type {HTMLElement}
* @memberof BaseEditorModel
*/
private container: HTMLElement;
onstatuschange: (stat: GenericObject<any>) => void;
/**
* Editor mutex
*
* @private
* @type {boolean}
* @memberof BaseEditorModel
*/
private editormux: boolean;
/**
* Creates an instance of BaseEditorModel.
*
* @param {Antedit} app parent app
* @param {GUI.tag.TabBarTag} tabbar tabbar DOM element
* @param {HTMLElement} editorarea editor container DOM element
* @memberof BaseEditorModel
*/
constructor(app: BaseApplication, tabbar: GUI.tag.TabBarTag, editorarea: HTMLElement) {
this.container = editorarea;
this.currfile = "Untitled".asFileHandle() as EditorFileHandle;
this.tabbar = tabbar;
this.editorSetup(editorarea);
this.app = app;
this.editormux = false;
this.onstatuschange = undefined;
this.on("focus", () => {
if (this.onstatuschange)
this.onstatuschange(this.getEditorStatus());
});
this.on("input", () => {
if (this.editormux) {
this.editormux = false;
return false;
}
if (!this.currfile.dirty) {
this.currfile.dirty = true;
this.currfile.text += "*";
return this.tabbar.update(undefined);
}
});
this.on("changeCursor", () => {
if (this.onstatuschange)
this.onstatuschange(this.getEditorStatus());
});
this.tabbar.ontabselect = (e) => {
return this.selecteTab($(e.data.item).index());
};
this.tabbar.ontabclose = (e) => {
const it = e.data.item;
if (!it) {
return false;
}
if (!it.data.dirty) {
return this.closeTab(it);
}
this.app.openDialog("YesNoDialog", {
title: __("Close tab"),
text: __("Close without saving ?"),
}).then((d) => {
if (d) {
return this.closeTab(it);
}
return this.focus();
});
return false;
};
}
/**
* Find a tab on the tabbar corresponding to a file handle
*
* @private
* @param {EditorFileHandle} file then file handle to search
* @returns {number}
* @memberof BaseEditorModel
*/
private findTabByFile(file: EditorFileHandle): number {
const lst = this.tabbar.items;
const its = (() => {
const result = [];
for (let i = 0; i < lst.length; i++) {
const d = lst[i];
if (d.hash() === file.hash()) {
result.push(i);
}
}
return result;
})();
if (its.length === 0) {
return -1;
}
return its[0];
}
/**
* Create new tab when opening a file
*
* @private
* @param {EditorFileHandle} file
* @memberof BaseEditorModel
*/
private newTab(file: EditorFileHandle): void {
file.text = file.basename ? file.basename : file.path;
if (!file.cache) {
file.cache = "";
}
file.textModel = this.newTextModelFrom(file);
this.currfile.selected = false;
file.selected = true;
//console.log cnt
this.tabbar.push(file);
}
/**
* Close a tab when a file is closed
*
* @private
* @param {GUI.tag.ListViewItemTag} it reference to the tab to close
* @returns {boolean}
* @memberof BaseEditorModel
*/
private closeTab(it: GUI.tag.ListViewItemTag): boolean {
this.tabbar.delete(it);
const cnt = this.tabbar.items.length;
if (cnt === 0) {
this.openFile(
"Untitled".asFileHandle() as EditorFileHandle
);
return false;
}
this.tabbar.selected = cnt - 1;
return false;
}
/**
* Select a tab by its index
*
* @private
* @param {number} i tab index
* @returns {void}
* @memberof BaseEditorModel
*/
private selecteTab(i: number): void {
//return if i is @tabbar.get "selidx"
const file = this.tabbar.items[i] as EditorFileHandle;
if (!file) {
return;
}
//return if file is @currfile
if (this.currfile !== file) {
this.currfile.textModel = this.getTexModel();
this.currfile.selected = false;
this.currfile = file;
}
this.editormux = true;
this.setTextModel(file.textModel);
if (this.onstatuschange)
this.onstatuschange(this.getEditorStatus());
this.focus();
}
/**
* Select an opened file, this will select the corresponding tab
*
* @param {(EditorFileHandle | string)} file
* @memberof BaseEditorModel
*/
selectFile(file: EditorFileHandle | string): void {
const i = this.findTabByFile(
file.asFileHandle() as EditorFileHandle
);
if (i !== -1) {
this.tabbar.selected = i;
}
}
/**
* Open a file in new tab. If the file is already opened,
* the just select the tab
*
*
* @param {EditorFileHandle} file file to open
* @returns {void}
* @memberof BaseEditorModel
*/
openFile(file: EditorFileHandle): void {
//find tab
const i = this.findTabByFile(file);
if (i !== -1) {
this.tabbar.selected = i;
return;
}
if (file.path.toString() === "Untitled") {
this.newTab(file);
return;
}
file.read()
.then((d) => {
file.cache = d || "";
return this.newTab(file);
})
.catch((e) => {
return this.app.error(
__("Unable to open: {0}", file.path),
e
);
});
}
/**
* write a file
*
* @private
* @param {EditorFileHandle} file
* @memberof BaseEditorModel
*/
private write(file: EditorFileHandle): void {
this.currfile.cache = this.getValue();
file.write("text/plain")
.then((d) => {
file.dirty = false;
file.text = file.basename;
this.tabbar.update(undefined);
})
.catch((e) =>
this.app.error(__("Unable to save file: {0}", file.path), e)
);
}
/**
* Save the current opened file
*
* @return {*} {void}
* @memberof BaseEditorModel
*/
save(): void {
this.currfile.cache = this.getValue();
if (this.currfile.basename) {
return this.write(this.currfile);
}
return this.saveAs();
}
/**
* Save the current file as another file
*
* @public
* @memberof BaseEditorModel
*/
saveAs(): void {
this.app.openDialog("FileDialog", {
title: __("Save as"),
file: this.currfile,
}).then((f) => {
let d = f.file.path.asFileHandle();
if (f.file.type === "file") {
d = d.parent();
}
this.currfile.setPath(`${d.path}/${f.name}`);
this.write(this.currfile);
});
}
/**
* Get all dirty file handles in the editor
*
* @return {*} {EditorFileHandle[]}
* @memberof BaseEditorModel
*/
dirties(): EditorFileHandle[] {
const result = [];
for (let v of Array.from(this.tabbar.items)) {
if (v.dirty) {
result.push(v);
}
}
return result;
}
/**
* Context menu handle for the editor
*
* @memberof BaseEditorModel
*/
set contextmenuHandle(cb: (e: any, m: any) => void) {
this.container.contextmenuHandle = cb;
}
/**
* Close all opened files
*
* @memberof BaseEditorModel
*/
closeAll(): void {
this.tabbar.items = [];
this.resetEditor();
}
/**
* Check whether the editor is dirty
*
* @return {*} {boolean}
* @memberof BaseEditorModel
*/
isDirty(): boolean {
return this.dirties().length > 0;
}
/**
* Set up the editor instance
* Should be implemented by subclass
*
* @protected
* @abstract
* @param {HTMLElement} el
* @memberof BaseEditorModel
*/
protected abstract editorSetup(el: HTMLElement): void;
/**
* Listen to editor event
*
* Should be implemented by subclasses
*
* @abstract
* @param {string} evt_str
* @param {() => void} callback
* @memberof BaseEditorModel
*/
abstract on(evt_str: string, callback: () => void): void;
/**
* Resize the editor
*
* Should be implemented by subclasses
*
* @abstract
* @memberof BaseEditorModel
*/
abstract resize(): void;
/**
* Make the editor focused
*
* Should be implemented by subclasses
*
* @abstract
* @memberof BaseEditorModel
*/
abstract focus(): void;
/**
* Get language mode from file extension
*
* Should be implemented by subclasses
*
* @protected
* @abstract
* @param {string} path
* @return {*} {GenericObject<any>}
* @memberof BaseEditorModel
*/
protected abstract getModeForPath(path: string): GenericObject<any>;
/**
* Query the editor status
*
* Should be implemented by subclasses
*
* @abstract
* @return {*} {GenericObject<any>}
* @memberof BaseEditorModel
*/
abstract getEditorStatus(): GenericObject<any>;
/**
* Get the editor value
*
* Should be implemented by subclasses
*
* @abstract
* @return {*} {string}
* @memberof BaseEditorModel
*/
abstract getValue(): string;
/**
* Set the editor value
*
* Should be implemented by subclasses
*
* @abstract
* @param {string} value
* @memberof BaseEditorModel
*/
abstract setValue(value: string): void;
/**
* Set the editor language mode
*
* Should be implemented by subclasses
*
* @abstract
* @param {GenericObject<any>} m
* @memberof BaseEditorModel
*/
abstract setMode(m: GenericObject<any>): void;
/**
* Get textModel from the current editor session
*
* @protected
* @abstract
* @return {*} {*}
* @memberof BaseEditorModel
*/
protected abstract getTexModel(): any;
/**
* Set text model to the current editor session
*
* @protected
* @abstract
* @param {*} model
* @memberof BaseEditorModel
*/
protected abstract setTextModel(model: any): void;
/**
* Create new text model from the VFS file
*
* @protected
* @abstract
* @param {EditorFileHandle} file
* @return {*} {*}
* @memberof BaseEditorModel
*/
protected abstract newTextModelFrom(file: EditorFileHandle): any;
/**
* Reset the editor
*
* @protected
* @abstract
* @memberof BaseEditorModel
*/
protected abstract resetEditor(): void;
/**
* Set the current editor theme
*
* Should be implemented by subclasses
*
* @abstract
* @param {string} theme
* @memberof BaseEditorModel
*/
abstract setTheme(theme: string): void;
/**
* Get the current support themes
*
* @abstract
* @memberof BaseEditorModel
*/
abstract getThemes(): any;
/**
* Get all language modes supported by the editor
*
* @abstract
* @return {*} {GenericObject<any>[]}
* @memberof BaseEditorModel
*/
abstract getModes(): GenericObject<any>[];
}
}
}

1083
CodePad/ts/main.ts Normal file

File diff suppressed because it is too large Load Diff