add more test, convert CodePad to type scipt

This commit is contained in:
Xuan Sang LE
2020-06-03 23:43:08 +02:00
parent af496b0aac
commit 6e95994892
36 changed files with 2818 additions and 1471 deletions

View File

@ -157,7 +157,7 @@ namespace OS {
trigger(evtName: string, data: any): void {
const trig = (name: string, d: any) => {
const names = [name, "*"];
for (let evt of Array.from(names)) {
for (let evt of names) {
if (!this.observable[evt]) {
continue;
}
@ -272,7 +272,7 @@ namespace OS {
) {
return;
}
for (let i of Array.from(announcer.listeners[app.pid])) {
for (let i of announcer.listeners[app.pid]) {
announcer.observable.off(i.e, i.f);
}
delete announcer.listeners[app.pid];

View File

@ -211,6 +211,10 @@ namespace OS {
this.host
);
}
else
{
this.error(__("Unable to find dialog scheme"));
}
}
/**
@ -846,7 +850,7 @@ namespace OS {
if (!e || !e.data.item) {
return;
}
setroot(e.data.item.get("data").path);
setroot(e.data.item.data.path);
};
location.data = this.systemsetting.VFS.mountpoints.filter(
(i) => i.type !== "app"
@ -884,7 +888,7 @@ namespace OS {
//verify the mime
let m = false;
if (f.mime) {
for (let v of Array.from(this.data.mimes)) {
for (let v of this.data.mimes) {
if (
f.mime.match(
new RegExp(v as string, "g")

View File

@ -378,7 +378,8 @@ namespace OS {
Object.defineProperty(Object.prototype, "__", {
value() {
return this.toString();
if(this)
return this.toString();
},
enumerable: false,
writable: true,

View File

@ -44,7 +44,7 @@ namespace OS {
* @interface BasicItemType
*/
export interface BasicItemType {
text: string;
text: string | FormatedString;
children?: BasicItemType[];
nodes?: BasicItemType[];
[propName: string]: any;
@ -190,7 +190,7 @@ namespace OS {
}
let m: API.PackageMetaType;
const mimes: Array<string[]> = [];
for (m of Array.from(metas)) {
for (m of metas) {
if (m) {
mimes.push(m.mimes);
}
@ -275,7 +275,7 @@ namespace OS {
if (apps.length === 1) {
return launch(apps[0].app, [it]);
}
const list = Array.from(apps).map((e) => ({
const list = apps.map((e) => ({
text: e.app,
icon: e.icon,
iconclass: e.iconclass,
@ -1041,17 +1041,16 @@ namespace OS {
pushServices(
(() => {
const result = [];
for (let v of Array.from(
for (let v of
setting.system.startup.services
)) {
) {
result.push(v);
}
return result;
})()
);
return Array.from(
setting.system.startup.apps
).map((a) => launch(a, []));
return
setting.system.startup.apps.map((a) => launch(a, []));
});
}
});

View File

@ -57,7 +57,7 @@ namespace OS {
return obj;
};
if (metaclass.dependencies) {
const libs = Array.from(metaclass.dependencies);
const libs = metaclass.dependencies;
return API.require(libs)
.then(() => resolve(f()))
.catch((e: Error) => reject(__e(e)));
@ -77,7 +77,7 @@ namespace OS {
export function appByPid(pid: number): BaseModel {
let app = undefined;
const find = function (l: Array<any>) {
for (let a of Array.from(l)) {
for (let a of l) {
if (a.pid === pid) {
return a;
}
@ -130,7 +130,7 @@ namespace OS {
if (!PM.processes[app]) {
return;
}
Array.from(PM.processes[app]).map((a) => a.quit(force));
PM.processes[app].map((a) => a.quit(force));
}
}
}

View File

@ -311,7 +311,7 @@ namespace OS {
v1.complex = true;
ar.push(v1);
} else if (v.mimes) {
for (let m of Array.from(v.mimes)) {
for (let m of v.mimes) {
if (t.match(new RegExp(m, "g"))) {
v1 = {};
for (k1 in v) {

View File

@ -356,12 +356,13 @@ namespace OS {
private refreshTree(): void {
//@treeview.root.set("selectedItem", null)
const tdata: TreeViewDataType = {
name: this.path,
text: this.path,
path: this.path,
open: true,
nodes: this.getTreeData(this.data),
nodes: this.getTreeData(this.data)
};
(this.refs.treeview as TreeViewTag).data = tdata;
// (this.refs.treeview as TreeViewTag).expandAll();
}
/**
@ -381,7 +382,7 @@ namespace OS {
if (v.filename[0] === "." && !this.showhidden) {
return undefined;
}
v.name = v.filename;
v.text = v.filename;
if (v.type === "dir") {
v.nodes = [];
v.open = false;
@ -500,13 +501,13 @@ namespace OS {
const tree = this.refs.treeview as TreeViewTag;
tree.fetch = (v) => {
return new Promise((resolve, reject) => {
if (!this.fetch) {
if (!this._fetch) {
return resolve(undefined);
}
if (!v.data.path) {
return resolve(undefined);
}
return this.fetch(v.data.path)
return this._fetch(v.data.path)
.then((d: API.FileInfoType[]) =>
resolve(
this.getTreeData(
@ -524,25 +525,25 @@ namespace OS {
list.dragndrop = true;
// even handles
list.onlistselect = (e) => {
this.fileselect(e.data.item.get("data"));
this.fileselect(e.data.item.data);
};
grid.onrowselect = (e) => {
this.fileselect(
$(e.data.item).children()[0].get("data")
$(e.data.item).children()[0].data
);
};
tree.ontreeselect = (e) => {
this.fileselect(e.data.item.get("data"));
this.fileselect(e.data.item.data);
};
// dblclick
list.onlistdbclick = (e) => {
this.filedbclick(e.data.item.get("data"));
this.filedbclick(e.data.item.data);
};
grid.oncelldbclick = (e) => {
this.filedbclick(e.data.item.get("data"));
this.filedbclick(e.data.item.data);
};
tree.ontreedbclick = (e) => {
this.filedbclick(e.data.item.get("data"));
this.filedbclick(e.data.item.data);
};
this.switchView();
}

View File

@ -181,7 +181,7 @@ namespace OS {
return;
}
$(this.refs.header).empty();
for (let item of Array.from(v)) {
for (let item of v) {
const el = $(`<${this.headeritem}>`).appendTo(
this.refs.header
);
@ -263,7 +263,7 @@ namespace OS {
el.data = row;
row.domel = rowel[0];
for (let cell of Array.from(row)) {
for (let cell of row) {
let tag = this.cellitem;
if (cell.tag) {
({ tag } = cell);

View File

@ -497,7 +497,7 @@ namespace OS {
return;
}
$(this.refs.btlist).empty();
for (let item of Array.from(v)) {
for (let item of v) {
$(this.refs.btlist).show();
const bt = $("<afx-button>").appendTo(this.refs.btlist);
(bt[0] as ButtonTag).set(item);
@ -524,7 +524,7 @@ namespace OS {
this._selectedItem = undefined;
this._selectedItems = [];
$(this.refs.mlist).empty();
for (let item of Array.from(data)) {
for (let item of data) {
this.push(item, false);
}
$(this.refs.container).off("mousedown", this._onmousedown);
@ -791,7 +791,7 @@ namespace OS {
* @memberof ListViewTag
*/
private idbclick(e: TagEventType) {
const evt = { id: this.aid, data: e };
const evt = { id: this.aid, data: { item: e.data } };
this._onlistdbclick(evt);
return this.observable.trigger("listdbclick", evt);
}
@ -943,7 +943,7 @@ namespace OS {
if (!e.data) {
return;
}
const evt = { id: this.aid, data: e };
const evt = { id: this.aid, data: {item: e.data} };
const r = this._onitemclose(evt);
if (!r) {
return;

View File

@ -16,7 +16,6 @@ namespace OS {
* @extends {AFXTag}
*/
export class TabBarTag extends AFXTag {
private _items: GenericObject<any>[];
private _selected: number;
private _ontabclose: (e: TagEventType) => boolean;
private _ontabselect: TagEventCallback;
@ -29,7 +28,6 @@ namespace OS {
super();
this._ontabclose = (e) => true;
this._ontabselect = (e) => {};
this._items = [];
}
/**
@ -108,7 +106,6 @@ namespace OS {
* @memberof TabBarTag
*/
set items(v: GenericObject<any>[]) {
this._items = v;
for (let i of v) {
i.closable = this.closable;
}
@ -122,7 +119,7 @@ namespace OS {
* @memberof TabBarTag
*/
get items(): GenericObject<any>[] {
return this._items;
return (this.refs.list as ListViewTag).data;
}
/**

View File

@ -149,7 +149,7 @@ namespace OS {
}
}
class HBoxTag extends TileLayoutTag {
export class HBoxTag extends TileLayoutTag {
constructor() {
super();
}
@ -162,7 +162,7 @@ namespace OS {
}
}
class VBoxTag extends TileLayoutTag {
export class VBoxTag extends TileLayoutTag {
constructor() {
super();

View File

@ -89,6 +89,7 @@ namespace OS {
this.treepath = v.path;
}
this.selected = v.selected;
v.domel = this;
this.ondatachange();
}
@ -171,6 +172,15 @@ namespace OS {
$(this.refs.toggle).addClass("afx-tree-view-folder-close");
}
/**
*
*
* @type {boolean}
* @memberof TreeViewItemPrototype
*/
get open(): boolean {
return this.hasattr("open");
}
/**
*
*
@ -264,7 +274,7 @@ namespace OS {
id: this.aid,
data: { item: this, dblclick: false },
};
this.indent = 0;
this._indent = 0;
}
/**
*
@ -602,7 +612,7 @@ namespace OS {
if (e.data.item === this.selectedItem && !e.data.dblclick) {
return;
}
this.selectedItem = e.data.item;
this._selectedItem = e.data.item;
const evt = { id: this.aid, data: e.data };
if (e.data.dblclick) {
this._ontreedbclick(evt);
@ -666,7 +676,7 @@ namespace OS {
}
let tag = this.itemtag;
if (v.tag) {
({ tag } = v);
tag = v.tag;
}
const el = $(`<${tag}>`).appendTo(this);
el[0].uify(this.observable);

View File

@ -169,7 +169,7 @@ namespace OS {
$(dom).attr("tooltip", tag.tooltip.__());
}
if (tag.children) {
for (let v of Array.from(tag.children)) {
for (let v of tag.children) {
$(this.mkui(v)).appendTo(dom);
}
}

View File

@ -134,7 +134,6 @@ namespace OS {
basename: string;
info: FileInfoType;
ext: string;
/**
*Creates an instance of BaseFileHandle.
* @param {string} path
@ -708,7 +707,7 @@ namespace OS {
* @class RemoteFileHandle
* @extends {BaseFileHandle}
*/
class RemoteFileHandle extends BaseFileHandle {
export class RemoteFileHandle extends BaseFileHandle {
constructor(path: string) {
super(path);
}
@ -1021,7 +1020,7 @@ namespace OS {
* @class ApplicationHandle
* @extends {BaseFileHandle}
*/
class ApplicationHandle extends BaseFileHandle {
export class ApplicationHandle extends BaseFileHandle {
/**
*Creates an instance of ApplicationHandle.
@ -1099,7 +1098,7 @@ namespace OS {
* @class BufferFileHandle
* @extends {BaseFileHandle}
*/
class BufferFileHandle extends BaseFileHandle {
export class BufferFileHandle extends BaseFileHandle {
constructor(path: string, mime: string, data: any) {
super(path);
if (data) {
@ -1188,7 +1187,7 @@ namespace OS {
* @class URLFileHandle
* @extends {BaseFileHandle}
*/
class URLFileHandle extends BaseFileHandle {
export class URLFileHandle extends BaseFileHandle {
constructor(path: string) {
super(path);
this.ready = true;
@ -1228,7 +1227,7 @@ namespace OS {
* @class SharedFileHandle
* @extends {API.VFS.BaseFileHandle}
*/
class SharedFileHandle extends API.VFS.BaseFileHandle {
export class SharedFileHandle extends API.VFS.BaseFileHandle {
constructor(path: string) {
super(path);
if (this.isRoot()) {