antosdk-apps/GitGraph/main.ts

67 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-07-04 19:31:17 +02:00
namespace OS {
export namespace API
{
export declare class LibGitGraph
{
constructor(options:GenericObject<any>);
base_dir: VFS.BaseFileHandle;
on_open_diff: (file:VFS.BaseFileHandle[]) => void;
list_file: (commit: string) => Promise<string[]>;
get_changes: (file:string, commit: string) => Promise<string>;
get_file: (file:string, commit: string) => Promise<string>
}
}
export namespace application {
/**
*
* @class GitGraph
* @extends {BaseApplication}
*/
export class GitGraph extends BaseApplication {
private graph: API.LibGitGraph;
private curr_repo: API.VFS.BaseFileHandle;
2022-07-04 19:31:17 +02:00
constructor(args: AppArgumentsType[]) {
super("GitGraph", args);
if(args && args[0])
{
this.curr_repo = args[0].path.asFileHandle();
if(args[0].type === "file")
this.curr_repo = this.curr_repo.parent();
}
2022-07-04 19:31:17 +02:00
}
main(): void {
this.graph = new API.LibGitGraph({
2022-07-04 19:31:17 +02:00
target: this.find("git-graph")
});
this.graph.on_open_diff = (files) => {
2022-07-04 19:31:17 +02:00
this._gui.launch("Antedit", [])
.then((p) =>{
2022-07-04 19:58:51 +02:00
p.observable.one("launched",() =>(p as any).openDiff(files));
})
.catch(e => this.error(__("Unable to open diff with Antedit: {0}", e.toString()),e ));
2022-07-04 19:58:51 +02:00
2022-07-04 19:31:17 +02:00
}
(this.find("btn-open") as GUI.tag.ButtonTag).onbtclick = (e) => {
this.openDialog("FileDialog", {
title: __("Select a repository"),
type: "dir",
}).then((d) => {
this.setRepo(d.file);
});
};
this.setRepo(this.curr_repo);
}
private setRepo(d:API.VFS.BaseFileHandle): void
{
if(!d) return;
(this.find("txt-repo") as GUI.tag.LabelTag).text = d.path;
this.curr_repo = d;
this.graph.base_dir = d;
2022-07-04 19:31:17 +02:00
}
}
GitGraph.dependencies = ["pkg://GitGraph/libgitgraph.js"];
2022-07-04 19:31:17 +02:00
}
}