Example #1
0
        public void OpenTextEditor(ITextEditor textEditor, int atIndex = -1)
        {
            SetsViewItem textEditorSetsViewItem = CreateTextEditorSetsViewItem(textEditor);

            // Notepads should replace current "Untitled.txt" with open file if it is empty and it is the only tab that has been created.
            // If index != -1, it means set was created after a drag and drop, we should skip this logic
            if (GetNumberOfOpenedTextEditors() == 1 && textEditor.EditingFile != null && atIndex == -1)
            {
                var selectedEditor = GetAllTextEditors().First();
                if (selectedEditor.EditingFile == null && !selectedEditor.IsModified)
                {
                    Sets.Items?.Clear();
                }
            }

            if (atIndex == -1)
            {
                Sets.Items?.Add(textEditorSetsViewItem);
            }
            else
            {
                Sets.Items?.Insert(atIndex, textEditorSetsViewItem);
            }

            if (GetNumberOfOpenedTextEditors() > 1)
            {
                Sets.SelectedItem = textEditorSetsViewItem;
                if (atIndex == -1)
                {
                    Sets.ScrollToLastSet();
                }
            }
        }
Example #2
0
        private void OpenNewTextEditor(string text,
                                       StorageFile file,
                                       long dateModifiedFileTime,
                                       Encoding encoding,
                                       LineEnding lineEnding)
        {
            //LoggingService.LogInfo("Opening a text editor.");
            var textEditor = new TextEditor
            {
                ExtensionProvider = _extensionProvider
            };

            textEditor.Init(new TextFile(text, encoding, lineEnding, dateModifiedFileTime), file);
            textEditor.Loaded           += TextEditor_Loaded;
            textEditor.Unloaded         += TextEditor_Unloaded;
            textEditor.SelectionChanged += TextEditor_SelectionChanged;
            textEditor.KeyDown          += TextEditorKeyDown;
            textEditor.EditorModificationStateChanged += TextEditor_OnEditorModificationStateChanged;
            textEditor.ModeChanged += TextEditor_ModeChanged;
            textEditor.FileModificationStateChanged += (sender, args) => { TextEditorFileModificationStateChanged?.Invoke(this, sender as TextEditor); };
            textEditor.LineEndingChanged            += (sender, args) => { TextEditorLineEndingChanged?.Invoke(this, sender as TextEditor); };
            textEditor.EncodingChanged += (sender, args) => { TextEditorEncodingChanged?.Invoke(this, sender as TextEditor); };

            var newItem = new SetsViewItem
            {
                Header  = file == null ? DefaultNewFileName : file.Name,
                Content = textEditor,
                SelectionIndicatorForeground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush,
                Icon = new SymbolIcon(Symbol.Save)
                {
                    Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush,
                }
            };

            if (newItem.Content == null || newItem.Content is Page)
            {
                throw new Exception("Content should not be null and type should not be Page (SetsView does not work well with Page controls)");
            }

            newItem.Icon.Visibility = Visibility.Collapsed;
            newItem.ContextFlyout   = new TabContextFlyout(this, textEditor);

            // Notepads should replace current "Untitled.txt" with open file if it is empty and it is the only tab that has been created.
            if (GetNumberOfOpenedTextEditors() == 1 && file != null)
            {
                var selectedEditor = GetAllTextEditors().First();
                if (selectedEditor.EditingFile == null && !selectedEditor.IsModified)
                {
                    Sets.Items?.Clear();
                }
            }

            Sets.Items?.Add(newItem);

            if (GetNumberOfOpenedTextEditors() > 1)
            {
                Sets.SelectedItem = newItem;
                Sets.ScrollToLastSet();
            }
        }
Example #3
0
        private void OpenNewTextEditor(string text,
                                       StorageFile file,
                                       Encoding encoding,
                                       LineEnding lineEnding)
        {
            var textEditor = new TextEditor()
            {
                EditingFile       = file,
                Encoding          = encoding,
                LineEnding        = lineEnding,
                Saved             = true,
                ExtensionProvider = _extensionProvider
            };

            textEditor.SetText(text);
            textEditor.ClearUndoQueue();
            textEditor.Loaded                 += TextEditor_Loaded;
            textEditor.Unloaded               += TextEditor_Unloaded;
            textEditor.TextChanging           += TextEditor_TextChanging;
            textEditor.SelectionChanged       += TextEditor_SelectionChanged;
            textEditor.KeyDown                += OnTextEditorKeyDown;
            textEditor.OnEditorClosingKeyDown += TextEditor_OnClosingKeyDown;

            var newItem = new SetsViewItem
            {
                Header  = file == null ? DefaultNewFileName : file.Name,
                Content = textEditor,
                SelectionIndicatorForeground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush,
                Icon = new SymbolIcon(Symbol.Save)
                {
                    Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush,
                }
            };

            newItem.Icon.Visibility = Visibility.Collapsed;
            newItem.ContextFlyout   = new TabContextFlyout(this, textEditor);

            // Notepads should replace current "Untitled.txt" with open file if it is empty and it is the only tab that has been created.
            if (GetNumberOfOpenedTextEditors() == 1 && file != null)
            {
                var selectedEditor = GetSelectedTextEditor();
                if (selectedEditor.Saved && selectedEditor.EditingFile == null)
                {
                    Sets.Items?.Clear();
                }
            }

            Sets.Items?.Add(newItem);

            if (GetNumberOfOpenedTextEditors() > 1)
            {
                Sets.SelectedItem = newItem;
                Sets.ScrollToLastSet();
            }
        }
Example #4
0
        public ITextEditor OpenNewTextEditor(
            Guid id,
            string text,
            StorageFile file,
            long dateModifiedFileTime,
            Encoding encoding,
            LineEnding lineEnding,
            bool isModified,
            int atIndex = -1)
        {
            TextEditor textEditor = new TextEditor
            {
                Id = id,
                ExtensionProvider = _extensionProvider
            };

            textEditor.Init(new TextFile(text, encoding, lineEnding, dateModifiedFileTime), file, isModified: isModified);
            textEditor.Loaded                       += TextEditor_Loaded;
            textEditor.Unloaded                     += TextEditor_Unloaded;
            textEditor.SelectionChanged             += TextEditor_SelectionChanged;
            textEditor.KeyDown                      += TextEditorKeyDown;
            textEditor.ModificationStateChanged     += TextEditor_OnEditorModificationStateChanged;
            textEditor.ModeChanged                  += TextEditor_ModeChanged;
            textEditor.FileModificationStateChanged += (sender, args) => { TextEditorFileModificationStateChanged?.Invoke(this, sender as ITextEditor); };
            textEditor.LineEndingChanged            += (sender, args) => { TextEditorLineEndingChanged?.Invoke(this, sender as ITextEditor); };
            textEditor.EncodingChanged              += (sender, args) => { TextEditorEncodingChanged?.Invoke(this, sender as ITextEditor); };

            var textEditorSetsViewItem = new SetsViewItem
            {
                Header  = textEditor.EditingFileName ?? DefaultNewFileName,
                Content = textEditor,
                SelectionIndicatorForeground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush,
                Icon = new SymbolIcon(Symbol.Save)
                {
                    Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush,
                }
            };

            if (textEditorSetsViewItem.Content == null || textEditorSetsViewItem.Content is Page)
            {
                throw new Exception("Content should not be null and type should not be Page (SetsView does not work well with Page controls)");
            }

            textEditorSetsViewItem.Icon.Visibility = isModified ? Visibility.Visible : Visibility.Collapsed;
            textEditorSetsViewItem.ContextFlyout   = new TabContextFlyout(this, textEditor);

            // Notepads should replace current "Untitled.txt" with open file if it is empty and it is the only tab that has been created.
            // If index != -1, it means set was created after a drag and drop, we should skip this logic
            if (GetNumberOfOpenedTextEditors() == 1 && file != null && atIndex == -1)
            {
                var selectedEditor = GetAllTextEditors().First();
                if (selectedEditor.EditingFile == null && !selectedEditor.IsModified)
                {
                    Sets.Items?.Clear();
                }
            }

            if (atIndex == -1)
            {
                Sets.Items?.Add(textEditorSetsViewItem);
            }
            else
            {
                Sets.Items?.Insert(atIndex, textEditorSetsViewItem);
            }

            if (GetNumberOfOpenedTextEditors() > 1)
            {
                Sets.SelectedItem = textEditorSetsViewItem;
                Sets.ScrollToLastSet();
            }

            return(textEditor);
        }