Load() public method

Loads the text from the stream, auto-detecting the encoding.
This method sets IsModified to false.
public Load ( System.Stream stream ) : void
stream System.Stream
return void
Exemplo n.º 1
0
        public ScarEditorControl(UniFile file)
        {
            InitializeComponent();
            m_btnSave.Click += BtnSaveClick;

            m_file = file;

            m_editor = new TextEditor();
            m_wpfTextEditor.Child = m_editor;

            m_editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("LUA Highlighting");
            m_editor.ShowLineNumbers = true;
            m_editor.TextChanged += EditorTextChanged;
            m_editor.Load(file.Stream);
        }
Exemplo n.º 2
0
 public bool Open(string path)
 {
     try
     {
         editor.Load(path);
         Path = path;
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Cannot open {path}! Error message:\n\n{ex.Message}",
                         "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Logger.Log(ex.ToString());
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
        private DocumentInfo CreateTab(string fullPath, string title)
        {
            TextEditor editor = new TextEditor();
            editor.FontFamily = new FontFamily("Consolas");
            editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
            editor.ShowLineNumbers = true;
            if (!string.IsNullOrWhiteSpace(fullPath))
            {
                editor.Load(fullPath);
            }

            LayoutDocument document = new LayoutDocument();
            document.Title = title;
            document.Content = editor;
            document.Closing += document_Closing;

            _window.DocumentPane.InsertChildAt(_window.DocumentPane.ChildrenCount, document);
            document.IsSelected = true;

            DocumentInfo info = new DocumentInfo(fullPath, title, document, editor);
            _documents[info.ID] = info;

            document.ContentId = info.ID.ToString();

            return info;
        }
Exemplo n.º 4
0
        public Tab(string path)
        {
            // arrange
            matchingTokensBackground = Theme.Instance.MatchingTokensBackground.ToColor();

            #region Set Name and DocumentPath

            if (path.IsBlank())
            {
                IsSaved = false;
                Name = "new";
                DocumentPath = string.Empty;
            }
            else
            {
                if (!File.Exists(path))
                {
                    // Notifier.Show("Attempted to open a file that doesn't exist");
                    return;
                }

                IsSaved = true;
                Name = Path.GetFileName(path);
                DocumentPath = path;
            }

            #endregion

            #region Create editor

            Editor = new TextEditor();
            Editor.FontSize = 13;
            Editor.ShowLineNumbers = true;
            Editor.Options.EnableEmailHyperlinks = false;
            Editor.Options.EnableHyperlinks = false;
            Editor.Options.ShowBoxForControlCharacters = true;
            //Editor.Options.ConvertTabsToSpaces = true;
            Editor.Background = ThemeColorConverter.GetColor("Background");
            Editor.Foreground = ThemeColorConverter.GetColor("Foreground");
            Editor.FontFamily = new FontFamily(Theme.Instance.FontFamily);
            Editor.TextArea.PreviewKeyDown += EditorKeyDown;
            Editor.TextChanged += TextChanged;
            Editor.TextArea.SelectionChanged += SelectionChanged;
            Editor.TextArea.Caret.PositionChanged += CaretOffsetChanged;
            Editor.TextArea.GotFocus += EditorGotFocus;
            Editor.Encoding = System.Text.Encoding.GetEncoding("ASCII");

            #endregion

            #region Create context menu for editor

            var menu = new ContextMenu();

            menu.Items.Add(ContextMenuHelper.CreateManuItem("New Tab", "CTRL+T", () => Controller.Current.CreateNewTab("")));
            menu.Items.Add(ContextMenuHelper.CreateManuItem("Open Previous Tab", "CTRL+SHIFT+T", Controller.Current.OpenLastClosedTab));
            menu.Items.Add(ContextMenuHelper.CreateManuItem("Browse File", "CTRL+O", Controller.Current.BrowseFile));
            menu.Items.Add(new Separator());
            menu.Items.Add(ContextMenuHelper.CreateManuItem("Quick Jump", "CTRL+,", () => Controller.Current.GetWidget<Features.Projects.Widget>().Jump.ShowBox()));
            menu.Items.Add(ContextMenuHelper.CreateManuItem("Stats & Encoding", "CTRL+ALT (hold)", () => Controller.Current.GetWidget<Features.Stats.Widget>().ShowStats()));
            menu.Items.Add(new Separator());
            menu.Items.Add(GetChangleLanguageContextMenuItem());
            menu.Items.Add(ContextMenuHelper.CreateManuItem("Close Tab", "CTRL+F4", Controller.Current.CloseActiveTab));

            Editor.ContextMenu = menu;

            #endregion

            // renderer
            BlockHighlighter = new BlockHighlighter(this);
            Editor.TextArea.TextView.BackgroundRenderers.Add(BlockHighlighter);
            colorPreview = new ColorPreviewRenderer(this);
            Editor.TextArea.TextView.BackgroundRenderers.Add(colorPreview);

            // load language
            LoadLanguageHighlighterAndSyntax(null);

            // tab item
            TabHeader = new ExtendedTabHeader(this); // always before TabItem
            TabItem = new ExtendedTabItem(this);

            // assign completion window
            completionItems = new List<CompletionWindowItem>();

            // load? (always last)
            if (!path.IsBlank())
                Editor.Load(path);
        }
Exemplo n.º 5
0
 public void Load(Stream stream)
 {
     _editor.Load(stream);
     _lastTextSet = Text;
 }
        private void lstFile_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            TextBlock item = lstFiles.SelectedItem as TextBlock;
            string file = item.Text;

            var documentContent = new AvalonDock.DocumentContent();
            documentContent.Title = file;
            
            ICSharpCode.AvalonEdit.TextEditor newEditor = new ICSharpCode.AvalonEdit.TextEditor();
            newEditor.ShowLineNumbers = txtCode.ShowLineNumbers;
            newEditor.WordWrap = txtCode.WordWrap;
            newEditor.SyntaxHighlighting = txtCode.SyntaxHighlighting;
            newEditor.Background = Brushes.LightGray;
            newEditor.Load(Helper.GetCurrentWorkingDir() + "\\" + file + ".tex");
            newEditor.IsReadOnly = true;

            documentContent.Content = newEditor;
            documentContent.Show(dockManager);
            //select the just added document
            if(dockManager.ActiveDocument != null)
                dockManager.ActiveDocument.ContainerPane.SelectedIndex = 0;
        }