Coder Social home page Coder Social logo

sora-editor-dotnet's Introduction

SoraEditorBindings

This is a C# binding of https://github.com/Rosemoe/sora-editor enabling the use of Sora Editor in .NET for Android. No modifications to the base code of the code editor have been made. Currently the bindings include the Editor and TextMate modules. Theare are only a few custom additions for specific use cases. They are optional and "off" by default.

Refer to the original repository and its "app" module for more detailed guides on using the editor.
Here is a quick tutorial for easily setting it up with TextMate:
Firstly create a folder structure like this in your Android Assets. The languages folder here contains a languages.json file.
Assets/sora_editor/themes
Assets/sora_editor/languages
Assets/sora_editor/languages/lang_name_here (this one might not matter if you use a languages.json, that's where the paths are important)

void Init(CodeEditor editor)
{
  FileProviderRegistry.Instance.AddFileProvider(new AssetsFileResolver(editor.Context.Assets));
  InitEditorLanguages();
  InitEditorThemes();
  editor.ColorScheme = TextMateColorScheme.Create(ThemeRegistry.Instance);
  editor.EditorLanguage = TextMateLanguage.Create("source.cs", true);
  ...
}


//Not related to the next 2 methods themselves but a Visual Studio bug.
//In case it isn't fixed yet add something like this in your ".csproj".
//Otherwise the debug builds can't seem to find default methods in Java interfaces and the runtime crashes.
//<SupportedOSPlatformVersion Condition=" '$(Configuration)' == 'Debug' ">24</SupportedOSPlatformVersion>
//<SupportedOSPlatformVersion Condition=" '$(Configuration)' == 'Release' ">21</SupportedOSPlatformVersion>

void InitEditorThemes() 
{
  var assetsRoot = "sora_editor/themes";
  var themes = new string[]
  {
    $"{assetsRoot}/darcula.json" //List your themes here
  };
  
  for (int i=0; i<themes.Length; i++)
  {
    var theme = themes[i];
    var src = IThemeSource.FromInputStream(FileProviderRegistry.Instance.TryGetInputStream(theme), theme, null);
    var model = new ThemeModel(src, theme);
    ThemeRegistry.Instance.LoadTheme(model, i == 0); //First theme is loaded as default
  }
}

void InitEditorLanguages()
{
  GrammarRegistry.Instance.LoadGrammars("sora_editor/languages/languages.json");
}


//The scope here can be for example "source.cs" or "source.java" but some grammars use scopes like "text.xml".
//You might want to write a method which handles that depending on your requirments.
void SetLanguage(CodeEditor editor, string scope)
{
  editor.EditorLanguage.JavaCast<TextMateLanguage>().UpdateLanguage(scope);
}

void SetTheme(CodeEditor editor, string theme)
{ 
  var assetsRoot = "sora_editor/themes";
  if (theme.StartsWith(assetsRoot)) //Enforce full path to the theme. You could change that from the ThemeModel creation.
  {
    theme = $"{assetsRoot}/theme"
  }
  ThemeRegistry.Instance.SetTheme(theme);
}

sora-editor-dotnet's People

Contributors

radimitrov avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

71126225

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.