shoko/Tab.cs

77 lines
1.7 KiB
C#
Raw Normal View History

2023-10-02 18:49:24 +00:00
using HtmlAgilityPack;
using ImGuiNET;
namespace Shoko;
class Tab
{
ProtoHandler Handler;
MediaHandler Document;
public bool IsOpen = true;
Exception Error = null;
string txtURL = "";
public Tab(string url)
{
Load(url);
txtURL = url;
}
public void Load(string url)
{
Error = null;
try
{
Handler = ProtoHandler.GetHandler(url);
Handler.CurrentTab = this;
Handler.Load();
Document = MediaHandler.GetHandler(Handler);
Document.Load();
txtURL = Handler.URL.ToString();
}
catch(Exception ex)
{
Error = ex;
}
}
public void Render()
{
var title = txtURL;
if(Document is not null)
{
title = Document.Title;
}
Gui.Window(title+"###"+GetHashCode().ToString(), ref IsOpen, ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.HorizontalScrollbar, ()=>
{
Gui.MenuBar(()=>{
Gui.Menu("File", ()=>{
Gui.MenuItem("Close", null, ()=> IsOpen = false);
});
if(Error is null)
{
Handler.MenuBar();
Document.MenuBar();
}
ImGui.InputText("##url", ref txtURL, 1024);
Gui.Button("Go", ()=>{
Load(txtURL);
});
});
if(Error is not null)
{
ImGui.Text("error: can't load page");
ImGui.Text(Error.Message);
}
else
{
Document.Render();
Handler.Render();
}
});
}
}