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 {
|
2022-07-05 22:45:28 +02:00
|
|
|
private graph: API.LibGitGraph;
|
|
|
|
private curr_repo: API.VFS.BaseFileHandle;
|
2022-07-04 19:31:17 +02:00
|
|
|
constructor(args: AppArgumentsType[]) {
|
|
|
|
super("GitGraph", args);
|
2022-07-05 22:45:28 +02:00
|
|
|
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 {
|
2022-07-05 22:45:28 +02:00
|
|
|
this.graph = new API.LibGitGraph({
|
2022-07-04 19:31:17 +02:00
|
|
|
target: this.find("git-graph")
|
|
|
|
});
|
2022-07-05 22:45:28 +02:00
|
|
|
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));
|
2022-07-04 21:13:55 +02:00
|
|
|
})
|
|
|
|
.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
|
|
|
}
|
2022-07-04 21:13:55 +02:00
|
|
|
(this.find("btn-open") as GUI.tag.ButtonTag).onbtclick = (e) => {
|
|
|
|
this.openDialog("FileDialog", {
|
|
|
|
title: __("Select a repository"),
|
|
|
|
type: "dir",
|
|
|
|
|
|
|
|
}).then((d) => {
|
2022-07-05 22:45:28 +02:00
|
|
|
this.setRepo(d.file);
|
2022-07-04 21:13:55 +02:00
|
|
|
});
|
|
|
|
};
|
2022-07-05 22:45:28 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-04 21:13:55 +02:00
|
|
|
GitGraph.dependencies = ["pkg://GitGraph/libgitgraph.js"];
|
2022-07-04 19:31:17 +02:00
|
|
|
}
|
|
|
|
}
|