History + DebugText

This commit is contained in:
Yuki 2023-10-02 18:13:48 -04:00
parent ee82b1bef4
commit cf8e42587b
2 changed files with 38 additions and 2 deletions

View File

@ -1,5 +1,6 @@
using System.Reflection;
using System.Text;
using System.Web;
using ImGuiNET;
using Raylib_cs;
@ -9,6 +10,8 @@ namespace Shoko;
[Protocol("shoko")]
class AboutProtoHandler : ProtoHandler
{
string txtDebug = "";
public AboutProtoHandler(Uri url)
{
URL = url;
@ -28,6 +31,10 @@ class AboutProtoHandler : ProtoHandler
case "version":
case "demo":
break;
case "debugtext":
txtDebug = HttpUtility.UrlDecode(URL.Query);
if(txtDebug.Length > 0) txtDebug = txtDebug[1..];
break;
default:
throw new NotImplementedException();
}
@ -69,6 +76,18 @@ class AboutProtoHandler : ProtoHandler
case "demo":
ImGui.ShowDemoWindow();
break;
case "debugtext":
ImGui.InputText("Text", ref txtDebug, 1024);
ImGui.SameLine();
Gui.Button("Debug", ()=>{
var tourl = new UriBuilder(URL)
{
Query = txtDebug
};
CurrentTab.Load(tourl.Uri.ToString());
});
ImGui.DebugTextEncoding(HttpUtility.UrlDecode(URL.Query));
break;
default:
break;
}

21
Tab.cs
View File

@ -1,4 +1,3 @@
using HtmlAgilityPack;
using ImGuiNET;
namespace Shoko;
@ -9,11 +8,13 @@ class Tab
MediaHandler Document;
public bool IsOpen = true;
Exception Error = null;
Stack<Uri> History;
string txtURL = "";
public Tab(string url)
{
History = new Stack<Uri>();
Load(url);
txtURL = url;
}
@ -21,14 +22,17 @@ class Tab
public void Load(string url)
{
Error = null;
ImGui.SetScrollX(0);
ImGui.SetScrollY(0);
try
{
Handler = ProtoHandler.GetHandler(url);
Handler.CurrentTab = this;
Handler.Load();
txtURL = Handler.URL.ToString();
History.Push(Handler.URL);
Document = MediaHandler.GetHandler(Handler);
Document.Load();
txtURL = Handler.URL.ToString();
}
catch(Exception ex)
{
@ -36,6 +40,15 @@ class Tab
}
}
public void Previous()
{
if(History.Count > 1)
{
History.Pop();
Load(History.Pop().ToString());
}
}
public void Render()
{
var title = txtURL;
@ -56,6 +69,10 @@ class Tab
Document.MenuBar();
}
Gui.Button("<<", ()=>{
Previous();
});
ImGui.InputText("##url", ref txtURL, 1024);
Gui.Button("Go", ()=>{