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.Reflection;
using System.Text; using System.Text;
using System.Web;
using ImGuiNET; using ImGuiNET;
using Raylib_cs; using Raylib_cs;
@ -9,6 +10,8 @@ namespace Shoko;
[Protocol("shoko")] [Protocol("shoko")]
class AboutProtoHandler : ProtoHandler class AboutProtoHandler : ProtoHandler
{ {
string txtDebug = "";
public AboutProtoHandler(Uri url) public AboutProtoHandler(Uri url)
{ {
URL = url; URL = url;
@ -28,6 +31,10 @@ class AboutProtoHandler : ProtoHandler
case "version": case "version":
case "demo": case "demo":
break; break;
case "debugtext":
txtDebug = HttpUtility.UrlDecode(URL.Query);
if(txtDebug.Length > 0) txtDebug = txtDebug[1..];
break;
default: default:
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -69,6 +76,18 @@ class AboutProtoHandler : ProtoHandler
case "demo": case "demo":
ImGui.ShowDemoWindow(); ImGui.ShowDemoWindow();
break; 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: default:
break; break;
} }

21
Tab.cs
View File

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