Posted
Well I really wanted to create a savetabs, but I didn't find something like that for a webview if you guys could help me I'd be really grateful and that's it.
Cancel
Post
Replied
no spoon feeding for you child.
All ill tell you is how to do it, just make some folder and store .txt or some type of file that can keep the content of the editor you have and then just update it and place it into the editor once its opened
Comments
darckisane0103 -2 Reputation
Commented
private void SaveTabs()
{
string str = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "bin", "tabs");
if (!Directory.Exists(str))
Directory.CreateDirectory(str);
foreach (TabItem tab in this._tabs)
{
ChromiumWebBrowser content = (ChromiumWebBrowser) tab.Content;
if (content.CanExecuteJavascriptInMainFrame)
{
Task<JavascriptResponse> scriptAsync = content.EvaluateScriptAsync("editor.getValue();", new TimeSpan?(), false);
scriptAsync.Wait();
if (scriptAsync.Result != null && scriptAsync.Result.Success && scriptAsync.Result.Result != null)
{
string contents = scriptAsync.Result.Result.ToString();
string path2 = tab.Header.ToString() + ".lua";
System.IO.File.WriteAllText(Path.Combine(str, path2), contents);
}
}
}
}
private void LoadTabs()
{
for (int removeIndex = this.EditorControl.Items.Count - 1; removeIndex >= 1; --removeIndex)
this.EditorControl.Items.RemoveAt(removeIndex);
foreach (FileInfo file1 in new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", "tabs")).GetFiles("*.lua"))
{
FileInfo file = file1;
string withoutExtension = Path.GetFileNameWithoutExtension(file.Name);
TabItem insertItem = new TabItem();
insertItem.Header = (object) withoutExtension;
ChromiumWebBrowser chromiumWebBrowser = new ChromiumWebBrowser();
chromiumWebBrowser.Name = "MonacoEditor";
chromiumWebBrowser.Address = AppDomain.CurrentDomain.BaseDirectory + "/Monaco/index.html";
ChromiumWebBrowser newEditor = chromiumWebBrowser;
this._monacoEditors.Add(newEditor);
insertItem.Content = (object) newEditor;
insertItem.Style = this.FindResource((object) "CustomCreateTab") as Style;
this.EditorControl.Items.Insert(this.EditorControl.Items.Count, (object) insertItem);
this._tabs.Add(insertItem);
newEditor.FrameLoadEnd += (EventHandler<FrameLoadEndEventArgs>) ((s, e) => newEditor.ExecuteScriptAsync("editor.setValue(`" + System.IO.File.ReadAllText(file.FullName).Replace("`", "\\`") + "`);"));
}
}
private void LoadMainEditor()
{
string path = AppDomain.CurrentDomain.BaseDirectory + "/Main.lua";
if (!System.IO.File.Exists(path))
return;
string code = System.IO.File.ReadAllText(path);
if (this.MonacoEditor.IsBrowserInitialized)
this.MonacoEditor.ExecuteScriptAsync("editor.setValue(`" + code.Replace("`", "\\`") + "`);");
else
this.MonacoEditor.FrameLoadEnd += (EventHandler<FrameLoadEndEventArgs>) ((sender, args) => this.MonacoEditor.ExecuteScriptAsync("editor.setValue(`" + code.Replace("`", "\\`") + "`);"));
}
private void SaveMainEditor() => System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/Main.lua", this.ExecuteJavascriptOnMainEditor("editor.getValue();"));
private string ExecuteJavascriptOnMainEditor(string script)
{
if (this.MonacoEditor == null)
return "";
Task<JavascriptResponse> scriptAsync = this.MonacoEditor.EvaluateScriptAsync(script, new TimeSpan?(), false);
scriptAsync.Wait();
return scriptAsync.Result != null && scriptAsync.Result.Success && scriptAsync.Result.Result != null ? scriptAsync.Result.Result.ToString() : "";
}
this is correct?
Zayn 13 Reputation
Commented
is that from my tutorial wtf
Cancel
Post
#Road to 15 Rep
https://media.discordapp.net/attachments/1081737726048608379/1088936664941989979/WRDBanner3.png
PC Specs: RTX 4080 OC (16GB), 32 GB 3200MHz, i7-11700k
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Comments
Zayn 13 Reputation
Commented
@darckisane0103, I have a method check it
0