Need to help, How to Save/Open file from/to Monaco Highlighting Syntax Lua ? Also, locally saved script(I don't need the refresh button)
I have project at my Form executor Roblox :/
No, i didn't do anything since i have no experience to C# and keep skidding (using people's script)
CodePudding user response:
To save a script using the Monaco API in C#, you can use the following code:
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.
To open a script using the Monaco API in C#, you can use the following code:
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. You may need to implement these methods in order to use the code in your project.