简体   繁体   English

有人可以帮我保存脚本或打开 Monaco api 吗? C#

[英]Can someone help me to save script or open into/from Monaco api? C#

Need to help, How to Save/Open file from/to Monaco Highlighting Syntax Lua?需要帮助,如何从/向 Monaco Highlighting Syntax Lua 保存/打开文件? Also, locally saved script(I don't need the refresh button)另外,本地保存的脚本(我不需要刷新按钮)

I have project at my Form executor Roblox:/我在我的表单执行器 Roblox 中有一个项目:/

No, i didn't do anything since i have no experience to C# and keep skidding (using people's script)不,我没有做任何事情,因为我没有使用 C# 的经验并且一直在打滑(使用人们的脚本)

To save a script using the Monaco API in C#, you can use the following code:要在 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());

This code gets the active text view, gets the current document path, and then uses the File.WriteAllText method to save the contents of the text view to the specified file path.此代码获取活动文本视图,获取当前文档路径,然后使用 File.WriteAllText 方法将文本视图的内容保存到指定的文件路径。

To open a script using the Monaco API in C#, you can use the following code:要在 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);

This code gets the active text view, reads the contents of the specified file into a string, and then sets the text of the text view to the contents of the file.此代码获取活动的文本视图,将指定文件的内容读入字符串,然后将文本视图的文本设置为文件的内容。

Note that the GetActiveTextView and GetWpfTextView methods, as well as the GetDocumentPath method, are helper functions that are not shown in the above code.请注意,GetActiveTextView 和 GetWpfTextView 方法以及 GetDocumentPath 方法是上面代码中未显示的辅助函数。 You may need to implement these methods in order to use the code in your project.您可能需要实现这些方法才能在您的项目中使用这些代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM