[英]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.