Ejemplo n.º 1
0
        private void UpdateUiResult(string result, bool isError)
        {
            OutputArea.Text = result;

            IThemedHighlightingManager hm = ThemedHighlightingManager.Instance;

            hm.SetCurrentTheme("VS2019_Dark");
            if (isError)
            {
                OutputArea.SyntaxHighlighting = hm.GetDefinitionByExtension(".txt");
            }
            else
            {
                OutputArea.SyntaxHighlighting = hm.GetDefinitionByExtension(".grazor");
            }


            if (!isError && settings.OpenFile)
            {
                string savedFilePath = Serializer.SaveTemporaryFile(result);
                System.Diagnostics.Process.Start(savedFilePath);
            }

            isLoading  = false;
            hasChanged = false;
            LoadingOverlay.Visibility = Visibility.Collapsed;
            oldText = result;
        }
        /// <summary>
        /// Loads a text document from the persistance of the file system
        /// and updates all corresponding states in this viewmodel.
        /// </summary>
        /// <param name="paramFilePath"></param>
        /// <returns></returns>
        public bool LoadDocument(string paramFilePath)
        {
            if (File.Exists(paramFilePath))
            {
                IsDirty    = false;
                IsReadOnly = false;

                // Check file attributes and set to read-only if file attributes indicate that
                if ((System.IO.File.GetAttributes(paramFilePath) & FileAttributes.ReadOnly) != 0)
                {
                    IsReadOnly       = true;
                    IsReadOnlyReason = "This file cannot be edit because another process is currently writting to it.\n" +
                                       "Change the file access permissions or save the file in a different location if you want to edit it.";
                }

                try
                {
                    var fileEncoding = GetEncoding(paramFilePath);

                    using (FileStream fs = new FileStream(paramFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (StreamReader reader = FileReader.OpenStream(fs, fileEncoding))
                        {
                            Document.Text = reader.ReadToEnd();
                            FileEncoding  = reader.CurrentEncoding; // assign encoding after ReadToEnd() so that the StreamReader can autodetect the encoding
                        }
                    }

                    FilePath        = paramFilePath;
                    IsContentLoaded = true;

                    // Setting this to null and then to some useful value ensures that the Foldings work
                    // Installing Folding Manager is invoked via HighlightingChange
                    // (so this works even when changing from test.XML to test1.XML)
                    HighlightingDefinition = null;

                    if (_hlManager != null)
                    {
                        string extension = System.IO.Path.GetExtension(paramFilePath);
                        HighlightingDefinition = _hlManager.GetDefinitionByExtension(extension);
                    }

                    return(true);
                }
                catch (System.Exception exc)
                {
                    IsReadOnly       = true;
                    IsReadOnlyReason = exc.Message;
                    Document.Text    = string.Empty;

                    FilePath               = string.Empty;
                    IsContentLoaded        = false;
                    HighlightingDefinition = null;
                }
            }

            return(false);
        }
        public ChangeLogPage()
        {
            InitializeComponent();

            IThemedHighlightingManager hm = ThemedHighlightingManager.Instance;

            hm.SetCurrentTheme("VS2019_Dark");
            AdditionalDataField.SyntaxHighlighting = hm.GetDefinitionByExtension(".js");
        }
Ejemplo n.º 4
0
        public MainWindow()
        {
            InitializeComponent();
            settings = Serializer.GetSettings();
            if (settings.FontSize < 1)
            {
                settings.FontSize = 20;
            }

            IThemedHighlightingManager hm = ThemedHighlightingManager.Instance;

            hm.SetCurrentTheme("VS2019_Dark");
            InputArea.SyntaxHighlighting  = hm.GetDefinitionByExtension(".grazor");
            OutputArea.SyntaxHighlighting = hm.GetDefinitionByExtension(".grazor");

            InputArea.FontSize  = settings.FontSize;
            OutputArea.FontSize = settings.FontSize;

            if (!settings.LineNumbers)
            {
                InputArea.ShowLineNumbers  = false;
                OutputArea.ShowLineNumbers = false;
            }
            else
            {
                InputArea.Loaded  += (object send, RoutedEventArgs e) => SetLineNumberMargin(InputArea);
                OutputArea.Loaded += (object send, RoutedEventArgs e) => SetLineNumberMargin(OutputArea);
            }

            InputArea.WordWrap  = settings.WordWrap;
            OutputArea.WordWrap = settings.WordWrap;

            InputArea.Loaded  += (object send, RoutedEventArgs e) => SetContextMenuIcons(InputArea);
            OutputArea.Loaded += (object send, RoutedEventArgs e) => SetContextMenuIcons(OutputArea);

            var heightDescriptor = DependencyPropertyDescriptor.FromProperty(RowDefinition.HeightProperty, typeof(ItemsControl));

            heightDescriptor.AddValueChanged(TopRow, SplitterHeightChanged);

            BuildExample(Serializer.GetExamples());
        }
        public VersionPage()
        {
            InitializeComponent();

            redColor   = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            whiteColor = new SolidColorBrush(Color.FromRgb(255, 255, 255));

            IThemedHighlightingManager hm = ThemedHighlightingManager.Instance;

            hm.SetCurrentTheme("VS2019_Dark");
            AdditionalDataField.SyntaxHighlighting = hm.GetDefinitionByExtension(".js");
        }
Ejemplo n.º 6
0
        private static void SetAvalonTheme(bool isDark)
        {
            IThemedHighlightingManager hm = ThemedHighlightingManager.Instance;

            hm.SetCurrentTheme(isDark ? "VS2019_Dark" : "Light");
            MainWindow window = (MainWindow)Application.Current.MainWindow;

            window.textEditor.SyntaxHighlighting          = hm.GetDefinitionByExtension(".js");
            window.textEditor.Background                  = new SolidColorBrush(isDark ? Color.FromRgb(30, 30, 30) : Color.FromRgb(255, 255, 255));
            window.textEditor.Foreground                  = new SolidColorBrush(isDark ? Color.FromRgb(255, 255, 255) : Color.FromRgb(0, 0, 0));
            window.textEditor.LineNumbersForeground       = new SolidColorBrush(isDark ? Color.FromRgb(190, 190, 190) : Color.FromRgb(60, 60, 60));
            window.textEditor.EditorCurrentLineBackground = new SolidColorBrush(isDark ? Color.FromRgb(37, 37, 37) : Color.FromRgb(245, 245, 245));
        }
Ejemplo n.º 7
0
        public ExCode(CodeControlModel codeModel, Settings appSettings)
        {
            InitializeComponent();
            model    = codeModel;
            settings = appSettings;
            if (settings.FontSize < 1)
            {
                settings.FontSize = 20;
            }

            Parent.Margin = new Thickness(0, model.MarginAbove, 0, model.MarginBelow);

            whiteBrush = new SolidColorBrush(Color.FromRgb(255, 255, 255));
            greenBrush = new SolidColorBrush(Color.FromRgb(129, 237, 104));

            CodeEditor.Loaded  += (object send, RoutedEventArgs e) => EditorLoadedEvent();
            CodeEditor.WordWrap = settings.WordWrap;

            // Set text area fields content type to use JSON (js) highlighting
            IThemedHighlightingManager hm = ThemedHighlightingManager.Instance;

            hm.SetCurrentTheme("VS2019_Dark");
            CodeEditor.SyntaxHighlighting = hm.GetDefinitionByExtension(".grazor");
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets a highlighting definition by extension. Returns null if the definition is not found.
 /// </summary>
 /// <param name="extension"></param>
 /// <returns></returns>
 public IHighlightingDefinition GetDefinitionByExtension(string extension)
 {
     return(_hlManager.GetDefinitionByExtension(extension));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Invoke this method to apply a change of theme to the content of the document
        /// (eg: Adjust the highlighting colors when changing from "Dark" to "Light"
        ///      WITH current text document loaded.)
        /// </summary>
        internal void OnAppThemeChanged(IThemedHighlightingManager hlManager)
        {
            if (hlManager == null)
            {
                return;
            }

            // Does this highlighting definition have an associated highlighting theme?
            if (hlManager.CurrentTheme.HlTheme != null)
            {
                // A highlighting theme with GlobalStyles?
                // Apply these styles to the resource keys of the editor
                foreach (var item in hlManager.CurrentTheme.HlTheme.GlobalStyles)
                {
                    switch (item.TypeName)
                    {
                    case "DefaultStyle":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorBackground, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorForeground, item.foregroundcolor);
                        break;

                    case "CurrentLineBackground":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorCurrentLineBackgroundBrushKey, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorCurrentLineBorderBrushKey, item.bordercolor);
                        break;

                    case "LineNumbersForeground":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorLineNumbersForeground, item.foregroundcolor);
                        break;

                    case "Selection":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorSelectionBrush, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorSelectionBorder, item.bordercolor);
                        break;

                    case "Hyperlink":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorLinkTextBackgroundBrush, item.backgroundcolor);
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorLinkTextForegroundBrush, item.foregroundcolor);
                        break;

                    case "NonPrintableCharacter":
                        ApplyToDynamicResource(AehnlichViewLib.Themes.ResourceKeys.EditorNonPrintableCharacterBrush, item.foregroundcolor);
                        break;

                    default:
                        throw new System.ArgumentOutOfRangeException("GlobalStyle named '{0}' is not supported.", item.TypeName);
                    }
                }
            }

            if (IsHighlightingDefinitionOff == true)
            {
                return;
            }

            // 1st try: Find highlighting based on currently selected highlighting
            // The highlighting name may be the same as before, but the highlighting theme has just changed
            if (HighlightingDefinition != null)
            {
                // Reset property for currently select highlighting definition
                HighlightingDefinition = hlManager.GetDefinition(HighlightingDefinition.Name);

                if (HighlightingDefinition != null)
                {
                    return;
                }
            }

            // 2nd try: Find highlighting based on extension of file currenlty being viewed
            if (string.IsNullOrEmpty(this.FileName))
            {
                return;
            }

            string extension = System.IO.Path.GetExtension(this.FileName);

            if (string.IsNullOrEmpty(extension))
            {
                return;
            }

            // Reset property for currently select highlighting definition
            HighlightingDefinition = hlManager.GetDefinitionByExtension(extension);
        }
        /// <summary>
        /// Invoke this method to apply a change of theme to the content of the document
        /// (eg: Adjust the highlighting colors when changing from "Dark" to "Light"
        ///      WITH current text document loaded.)
        /// </summary>
        internal void OnAppThemeChanged(IThemedHighlightingManager hlManager)
        {
            if (hlManager == null)
            {
                return;
            }

            // Does this highlighting definition have an associated highlighting theme?
            if (hlManager.CurrentTheme.HlTheme != null)
            {
                // A highlighting theme with GlobalStyles?
                // Apply these styles to the resource keys of the editor
                foreach (var item in hlManager.CurrentTheme.HlTheme.GlobalStyles)
                {
                    switch (item.TypeName)
                    {
                    case "DefaultStyle":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorBackground, item.backgroundcolor);
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorForeground, item.foregroundcolor);
                        break;

                    case "CurrentLineBackground":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorCurrentLineBackgroundBrushKey, item.backgroundcolor);
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorCurrentLineBorderBrushKey, item.bordercolor);
                        break;

                    case "LineNumbersForeground":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorLineNumbersForeground, item.foregroundcolor);
                        break;

//// Not changing selection color here since this should be controlled by current AccentColor via BindToMLib
                    case "Selection":
////							ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorSelectionBrush, item.backgroundcolor);
////							ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorSelectionBorder, item.bordercolor);
                        break;

                    case "Hyperlink":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorLinkTextBackgroundBrush, item.backgroundcolor);
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorLinkTextForegroundBrush, item.foregroundcolor);
                        break;

                    case "NonPrintableCharacter":
                        ApplyToDynamicResource(TextEditLib.Themes.ResourceKeys.EditorNonPrintableCharacterBrush, item.foregroundcolor);
                        break;

                    default:
                        throw new System.ArgumentOutOfRangeException("GlobalStyle named '{0}' is not supported.", item.TypeName);
                    }
                }
            }

            // 1st try: Find highlighting based on currently selected highlighting
            // The highlighting name may be the same as before, but the highlighting theme has just changed
            if (HighlightingDefinition != null)
            {
                // Reset property for currently select highlighting definition
                HighlightingDefinition = hlManager.GetDefinition(HighlightingDefinition.Name);
                NotifyPropertyChanged(() => this.HighlightingDefinitions);

                if (HighlightingDefinition != null)
                {
                    return;
                }
            }

            // 2nd try: Find highlighting based on extension of file currenlty being viewed
            if (string.IsNullOrEmpty(FilePath))
            {
                // No file path is available -> no default highlighting
                HighlightingDefinition = null;
                NotifyPropertyChanged(() => this.HighlightingDefinitions);
                return;
            }

            string extension = System.IO.Path.GetExtension(FilePath);

            if (string.IsNullOrEmpty(extension))
            {
                // File path is available but no extension to speak of -> no default highlighting
                HighlightingDefinition = null;
                NotifyPropertyChanged(() => this.HighlightingDefinitions);
                return;
            }

            // Reset property for currently select highlighting definition
            HighlightingDefinition = hlManager.GetDefinitionByExtension(extension);
            NotifyPropertyChanged(() => this.HighlightingDefinitions);
        }