Exemplo n.º 1
0
        private SetsViewItem CreateTextEditorSetsViewItem(ITextEditor textEditor)
        {
            var modifierIcon = new FontIcon()
            {
                Glyph      = "\uF127",
                FontSize   = 1.5,
                Width      = 3,
                Height     = 3,
                Foreground = new SolidColorBrush(ThemeSettingsService.AppAccentColor),
            };

            var textEditorSetsViewItem = new SetsViewItem
            {
                Header  = textEditor.EditingFileName ?? textEditor.FileNamePlaceholder,
                Content = textEditor,
                SelectionIndicatorForeground = new SolidColorBrush(ThemeSettingsService.AppAccentColor),
                Icon = modifierIcon
            };

            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 = textEditor.IsModified ? Visibility.Visible : Visibility.Collapsed;
            textEditorSetsViewItem.ContextFlyout   = new TabContextFlyout(this, textEditor);

            return(textEditorSetsViewItem);
        }
Exemplo n.º 2
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();
                }
            }
        }
Exemplo n.º 3
0
        private void CreateNewTextEditorSet(string text, StorageFile file, Encoding encoding, LineEnding lineEnding)
        {
            var textEditor = new TextEditor()
            {
                EditingFile = file,
                Encoding    = encoding,
                LineEnding  = lineEnding,
                Saved       = true,
            };

            textEditor.SetText(text);
            textEditor.Loaded                        += TextEditor_Loaded;
            textEditor.Unloaded                      += TextEditor_Unloaded;
            textEditor.KeyDown                       += TextEditor_KeyDown;
            textEditor.OnSetClosingKeyDown           += TextEditor_OnSetClosingKeyDown;
            textEditor.OnFindButtonClicked           += TextEditor_OnFindButtonClicked;
            textEditor.OnFindAndReplaceButtonClicked += TextEditor_OnFindAndReplaceButtonClicked;

            var newItem = new SetsViewItem
            {
                Header  = file == null ? DefaultFileName : 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;
            Sets.Items?.Add(newItem);
            newItem.IsSelected = true;
            Sets.ScrollToLastSet();
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
0
        private void CreateNewTextEditorSet(string text, StorageFile file, Encoding encoding, LineEnding lineEnding)
        {
            var textEditor = new TextEditor()
            {
                EditingFile = file,
                Encoding    = encoding,
                LineEnding  = lineEnding,
                Saved       = true,
            };

            textEditor.SetText(text);
            textEditor.Loaded                        += TextEditor_Loaded;
            textEditor.Unloaded                      += TextEditor_Unloaded;
            textEditor.KeyDown                       += TextEditor_KeyDown;
            textEditor.OnSetClosingKeyDown           += TextEditor_OnSetClosingKeyDown;
            textEditor.OnFindButtonClicked           += TextEditor_OnFindButtonClicked;
            textEditor.OnFindAndReplaceButtonClicked += TextEditor_OnFindAndReplaceButtonClicked;

            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;

            // Notepads should replace current "New Document.txt" with open file if it is empty and it is the only tab that has been created.
            if (Sets.Items?.Count == 1 && file != null)
            {
                if (((Sets.SelectedItem as SetsViewItem)?.Content is TextEditor editor))
                {
                    if (editor.Saved && editor.EditingFile == null)
                    {
                        Sets.Items.Clear();
                    }
                }
            }

            Sets.Items?.Add(newItem);

            if (Sets.Items?.Count > 1)
            {
                newItem.IsSelected = true;
                Sets.ScrollToLastSet();
            }
        }
Exemplo n.º 7
0
        public TabContextFlyout(SetsView tabs, SetsViewItem tab)
        {
            _tabs = tabs;
            _tab  = tab;

            Items.Add(Close);
            Items.Add(CloseOthers);
            Items.Add(CloseRight);
            Items.Add(CloseSaved);
            Items.Add(new MenuFlyoutSeparator());
            Items.Add(CopyFullPath);
            Items.Add(OpenContainingFolder);

            Opening += TabContextFlyout_Opening;
            Closed  += TabContextFlyout_Closed;
        }
Exemplo n.º 8
0
        private SetsViewItem CreateTextEditorSetsViewItem(ITextEditor textEditor)
        {
            var textEditorSetsViewItem = new SetsViewItem
            {
                Header  = textEditor.EditingFileName ?? textEditor.FileNamePlaceholder,
                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 = textEditor.IsModified ? Visibility.Visible : Visibility.Collapsed;
            textEditorSetsViewItem.ContextFlyout   = new TabContextFlyout(this, textEditor);

            return(textEditorSetsViewItem);
        }
Exemplo n.º 9
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);
        }