gemini icon indicating copy to clipboard operation
gemini copied to clipboard

How to get CodeEditor's Text

Open 3HMonkey opened this issue 7 years ago • 6 comments

Hello guys, sorry for the question but how can I access the content of the CodeEditor? For example after opening a cs file.

3HMonkey avatar May 28 '17 21:05 3HMonkey

I mean in detail if you open a cs file for example, an editor opens. Them youll be able to input some content to the Texteditor. I gonna work with this content, for example parsing the text. But I really dont know how to get the text out of it.

3HMonkey avatar Jun 10 '17 09:06 3HMonkey

Hello, you need to create your own module, with ViewModel class inherites from the PersistedDocument class. Combine two examples Gemini.Demo.TextEditor module with Gemini.Demo.Home HelixViewModel/View that uses codeeditor.

luferau avatar Jun 12 '17 08:06 luferau

For example if you add .cs extension in _extensions list in file Gemini.Demo.Modules.TextEditor.EditorProvider.cs

private readonly List _extensions = new List { ".txt", ".cmd", ".cs" };

.cs files will be open by Gemini.Demo.Modules.TextEditor module in TextBox (see TextEditor.View.EditorView.xaml)

You need to replace TextBox with an CodeEditor, you can see how it's done in Gemini.Demo.Home HelixViewModel/View

luferau avatar Jun 12 '17 08:06 luferau

Hey and thank you for the quick feedback. Btw I tried adding a custom module and I exported it. One of the problems is now, that anytime I open a file using the menu or the toolbar, it opens it by using the original IEditorProvider instead of my custom one ?

3HMonkey avatar Jun 12 '17 19:06 3HMonkey

Do you add your required extension to List _extensions of your EditorProvider class?

luferau avatar Jun 13 '17 06:06 luferau

Yes, for example, if I add a new file extension like "*.test", this is shown in the file list on the menu. Afterwards I try to get an instance of EditorProvider which will always return null. It finds only a CodeEditorProvider instance. Btw I also dont know how to get the Text of the text box inside another module. For example to do some compiling stuff etc.

3HMonkey avatar Jun 15 '17 21:06 3HMonkey