public EditorElement(string filePath)
        {
            InitializeComponent();

            bracketSearcher = new SPBracketSearcher();
            bracketHighlightRenderer = new BracketHighlightRenderer(editor.TextArea.TextView);
            editor.TextArea.IndentationStrategy = new EditorIndetationStrategy();

            FadeJumpGridIn = (Storyboard)this.Resources["FadeJumpGridIn"];
            FadeJumpGridOut = (Storyboard)this.Resources["FadeJumpGridOut"];

            this.KeyDown += EditorElement_KeyDown;

            editor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            editor.TextArea.SelectionChanged += TextArea_SelectionChanged;
            editor.TextArea.PreviewKeyDown += TextArea_PreviewKeyDown;
            editor.PreviewMouseWheel += PrevMouseWheel;
            editor.MouseDown += editor_MouseDown;
            editor.TextArea.TextEntered += TextArea_TextEntered;

            FileInfo fInfo = new FileInfo(filePath);
            if (fInfo.Exists)
            {
                fileWatcher = new FileSystemWatcher(fInfo.DirectoryName) { IncludeSubdirectories = false };
                fileWatcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite;
                fileWatcher.Filter = "*" + fInfo.Extension;
                fileWatcher.Changed += fileWatcher_Changed;
                fileWatcher.EnableRaisingEvents = true;
            }
            else
            {
                fileWatcher = null;
            }
            _FullFilePath = filePath;
            editor.Options.ConvertTabsToSpaces = false;
            editor.Options.EnableHyperlinks = false;
            editor.Options.HighlightCurrentLine = true;
            editor.Options.AllowScrollBelowDocument = true;
            editor.TextArea.SelectionCornerRadius = 0.0;
            editor.Options.ConvertTabsToSpaces = Program.OptionsObject.Editor_ReplaceTabsToWhitespace;

            editor.FontFamily = new FontFamily(Program.OptionsObject.Editor_FontFamily);
            editor.WordWrap = Program.OptionsObject.Editor_WordWrap;
            UpdateFontSize(Program.OptionsObject.Editor_FontSize, false);

            colorizeSelection = new ColorizeSelection();
            editor.TextArea.TextView.LineTransformers.Add(colorizeSelection);
            editor.SyntaxHighlighting = new AeonEditorHighlighting();

            LoadAutoCompletes();

            using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (StreamReader reader = FileReader.OpenStream(fs, Encoding.UTF8))
                {
                    string source = reader.ReadToEnd();
                    source = ((source.Replace("\r\n", "\n")).Replace("\r", "\n")).Replace("\n", "\r\n"); //normalize line endings
                    editor.Text = source;
                }
            }
            _NeedsSave = false;

            var encoding = new UTF8Encoding(false);
            editor.Encoding = encoding; //let them read in whatever encoding they want - but save in UTF8

            foldingManager = FoldingManager.Install(editor.TextArea);
            foldingStrategy = new SPFoldingStrategy();
            foldingStrategy.UpdateFoldings(foldingManager, editor.Document);

            regularyTimer = new Timer(2000.0);
            regularyTimer.Elapsed += regularyTimer_Elapsed;
            regularyTimer.Start();

            CompileBox.IsChecked = (bool?)filePath.EndsWith(".sp");
        }
Exemple #2
0
        public EditorElement(string filePath)
        {
            InitializeComponent();

            bracketSearcher                     = new SPBracketSearcher();
            bracketHighlightRenderer            = new BracketHighlightRenderer(editor.TextArea.TextView);
            editor.TextArea.IndentationStrategy = new EditorIndetationStrategy();

            FadeJumpGridIn  = (Storyboard)Resources["FadeJumpGridIn"];
            FadeJumpGridOut = (Storyboard)Resources["FadeJumpGridOut"];

            KeyDown += EditorElement_KeyDown;

            editor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            editor.TextArea.SelectionChanged      += TextArea_SelectionChanged;
            editor.TextArea.PreviewKeyDown        += TextArea_PreviewKeyDown;
            editor.PreviewMouseWheel     += PrevMouseWheel;
            editor.MouseDown             += editor_MouseDown;
            editor.TextArea.TextEntered  += TextArea_TextEntered;
            editor.TextArea.TextEntering += TextArea_TextEntering;

            var fInfo = new FileInfo(filePath);

            if (fInfo.Exists)
            {
                fileWatcher = new FileSystemWatcher(fInfo.DirectoryName)
                {
                    IncludeSubdirectories = false
                };
                fileWatcher.NotifyFilter        = NotifyFilters.Size | NotifyFilters.LastWrite;
                fileWatcher.Filter              = "*" + fInfo.Extension;
                fileWatcher.Changed            += fileWatcher_Changed;
                fileWatcher.EnableRaisingEvents = true;
            }
            else
            {
                fileWatcher = null;
            }

            _FullFilePath = filePath;
            editor.Options.ConvertTabsToSpaces      = false;
            editor.Options.EnableHyperlinks         = false;
            editor.Options.EnableEmailHyperlinks    = false;
            editor.Options.HighlightCurrentLine     = true;
            editor.Options.AllowScrollBelowDocument = true;
            editor.Options.ShowSpaces             = Program.OptionsObject.Editor_ShowSpaces;
            editor.Options.ShowTabs               = Program.OptionsObject.Editor_ShowTabs;
            editor.Options.IndentationSize        = Program.OptionsObject.Editor_IndentationSize;
            editor.TextArea.SelectionCornerRadius = 0.0;
            editor.Options.ConvertTabsToSpaces    = Program.OptionsObject.Editor_ReplaceTabsToWhitespace;

            Brush currentLineBackground = new SolidColorBrush(Color.FromArgb(0x20, 0x88, 0x88, 0x88));
            Brush currentLinePenBrush   = new SolidColorBrush(Color.FromArgb(0x30, 0x88, 0x88, 0x88));

            currentLinePenBrush.Freeze();
            var currentLinePen = new Pen(currentLinePenBrush, 1.0);

            currentLineBackground.Freeze();
            currentLinePen.Freeze();
            editor.TextArea.TextView.CurrentLineBackground = currentLineBackground;
            editor.TextArea.TextView.CurrentLineBorder     = currentLinePen;

            editor.FontFamily = new FontFamily(Program.OptionsObject.Editor_FontFamily);
            editor.WordWrap   = Program.OptionsObject.Editor_WordWrap;
            UpdateFontSize(Program.OptionsObject.Editor_FontSize, false);

            colorizeSelection = new ColorizeSelection();
            editor.TextArea.TextView.LineTransformers.Add(colorizeSelection);
            editor.SyntaxHighlighting = new AeonEditorHighlighting();

            LoadAutoCompletes();

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var reader = FileReader.OpenStream(fs, Encoding.UTF8))
                {
                    var source = reader.ReadToEnd();
                    source = source.Replace("\r\n", "\n").Replace("\r", "\n")
                             .Replace("\n", "\r\n"); //normalize line endings
                    editor.Text = source;
                }
            }

            _NeedsSave = false;

            Language_Translate(true); //The Fontsize and content must be loaded

            var encoding = new UTF8Encoding(false);

            editor.Encoding = encoding; //let them read in whatever encoding they want - but save in UTF8

            foldingManager  = FoldingManager.Install(editor.TextArea);
            foldingStrategy = new SPFoldingStrategy();
            foldingStrategy.UpdateFoldings(foldingManager, editor.Document);

            regularyTimer          = new Timer(500.0);
            regularyTimer.Elapsed += regularyTimer_Elapsed;
            regularyTimer.Start();

            AutoSaveTimer          = new Timer();
            AutoSaveTimer.Elapsed += AutoSaveTimer_Elapsed;
            StartAutoSaveTimer();

            CompileBox.IsChecked = filePath.EndsWith(".sp");
        }
        public EditorElement(string filePath)
        {
            InitializeComponent();

            bracketSearcher                     = new SPBracketSearcher();
            bracketHighlightRenderer            = new BracketHighlightRenderer(editor.TextArea.TextView);
            editor.TextArea.IndentationStrategy = new EditorIndetationStrategy();

            FadeJumpGridIn  = (Storyboard)this.Resources["FadeJumpGridIn"];
            FadeJumpGridOut = (Storyboard)this.Resources["FadeJumpGridOut"];

            this.KeyDown += EditorElement_KeyDown;

            editor.TextArea.Caret.PositionChanged += Caret_PositionChanged;
            editor.TextArea.SelectionChanged      += TextArea_SelectionChanged;
            editor.TextArea.PreviewKeyDown        += TextArea_PreviewKeyDown;
            editor.PreviewMouseWheel    += PrevMouseWheel;
            editor.MouseDown            += editor_MouseDown;
            editor.TextArea.TextEntered += TextArea_TextEntered;

            FileInfo fInfo = new FileInfo(filePath);

            if (fInfo.Exists)
            {
                fileWatcher = new FileSystemWatcher(fInfo.DirectoryName)
                {
                    IncludeSubdirectories = false
                };
                fileWatcher.NotifyFilter        = NotifyFilters.Size | NotifyFilters.LastWrite;
                fileWatcher.Filter              = "*" + fInfo.Extension;
                fileWatcher.Changed            += fileWatcher_Changed;
                fileWatcher.EnableRaisingEvents = true;
            }
            else
            {
                fileWatcher = null;
            }
            _FullFilePath = filePath;
            editor.Options.ConvertTabsToSpaces      = false;
            editor.Options.EnableHyperlinks         = false;
            editor.Options.HighlightCurrentLine     = true;
            editor.Options.AllowScrollBelowDocument = true;
            editor.TextArea.SelectionCornerRadius   = 0.0;

            editor.FontFamily = new FontFamily(Program.OptionsObject.Editor_FontFamily);
            editor.WordWrap   = Program.OptionsObject.Editor_WordWrap;
            UpdateFontSize(Program.OptionsObject.Editor_FontSize, false);

            colorizeSelection = new ColorizeSelection();
            editor.TextArea.TextView.LineTransformers.Add(colorizeSelection);
            editor.SyntaxHighlighting = new AeonEditorHighlighting();

            LoadAutoCompletes();

            using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (StreamReader reader = FileReader.OpenStream(fs, Encoding.UTF8))
                {
                    string source = reader.ReadToEnd();
                    source      = ((source.Replace("\r\n", "\n")).Replace("\r", "\n")).Replace("\n", "\r\n"); //normalize line endings
                    editor.Text = source;
                }
            }
            _NeedsSave = false;

            var encoding = new UTF8Encoding(false);

            editor.Encoding = encoding; //let them read in whatever encoding they want - but save in UTF8

            foldingManager  = FoldingManager.Install(editor.TextArea);
            foldingStrategy = new SPFoldingStrategy();
            foldingStrategy.UpdateFoldings(foldingManager, editor.Document);

            regularyTimer          = new Timer(2000.0);
            regularyTimer.Elapsed += regularyTimer_Elapsed;
            regularyTimer.Start();

            CompileBox.IsChecked = (bool?)filePath.EndsWith(".sp");
        }