[英]Can someone help me to save script or open into/from Monaco api? C#
需要帮助,如何从/向 Monaco Highlighting Syntax Lua 保存/打开文件? 另外,本地保存的脚本(我不需要刷新按钮)
我在我的表单执行器 Roblox 中有一个项目:/
不,我没有做任何事情,因为我没有使用 C# 的经验并且一直在打滑(使用人们的脚本)
要在 C# 中使用 Monaco API 保存脚本,您可以使用以下代码:
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
// Get the active text view
IVsTextView textView = GetActiveTextView();
IWpfTextView wpfTextView = GetWpfTextView(textView);
// Get the current document path
string documentPath = GetDocumentPath(textView);
// Save the document
File.WriteAllText(documentPath, wpfTextView.TextBuffer.CurrentSnapshot.GetText());
此代码获取活动文本视图,获取当前文档路径,然后使用 File.WriteAllText 方法将文本视图的内容保存到指定的文件路径。
要在 C# 中使用 Monaco API 打开脚本,您可以使用以下代码:
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
// Get the active text view
IVsTextView textView = GetActiveTextView();
IWpfTextView wpfTextView = GetWpfTextView(textView);
// Get the file path of the script to open
string filePath = "C:\path\to\script.txt";
// Read the contents of the file
string script = File.ReadAllText(filePath);
// Set the text of the text view to the contents of the file
wpfTextView.TextBuffer.Replace(new Span(0, wpfTextView.TextBuffer.CurrentSnapshot.Length), script);
此代码获取活动的文本视图,将指定文件的内容读入字符串,然后将文本视图的文本设置为文件的内容。
请注意,GetActiveTextView 和 GetWpfTextView 方法以及 GetDocumentPath 方法是上面代码中未显示的辅助函数。 您可能需要实现这些方法才能在您的项目中使用这些代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.