/// <summary> /// Standard constructor. See also static <seealso cref="LoadFile"/> method /// for construction from file saved on disk. /// </summary> protected EdiViewModel() : base(DocumentKey) { CloseOnErrorWithoutMessage = false; // Copy text editor settings from settingsmanager by default TextOptions = new ICSharpCode.AvalonEdit.TextEditorOptions(); WordWrap = false; var items = new ObservableCollection <UnitComboLib.Models.ListItem>(Options.GenerateScreenUnitList()); SizeUnitLabel = UnitComboLib.UnitViewModeService.CreateInstance(items, new ScreenConverter(), 0); TxtControl = new TextBoxController(); FilePath = GetDefaultFileNewName(); IsDirty = false; _mHighlightingDefinition = null; _mDocument = null; //new TextDocument(); TextEditorSelectionStart = 0; TextEditorSelectionLength = 0; InsertBlocks = null; }
public void Attach(ITextEditor editor) { this.editor = editor; inspectionManager = new IssueManager(editor); codeManipulation = new CodeManipulation(editor); renderer = new CaretReferenceHighlightRenderer(editor); // Patch editor options (indentation) to project-specific settings if (!editor.ContextActionProviders.IsReadOnly) { contextActionProviders = AddInTree.BuildItems<IContextActionProvider>("/SharpDevelop/ViewContent/TextEditor/C#/ContextActions", null); editor.ContextActionProviders.AddRange(contextActionProviders); } // Create instance of options adapter and register it as service var formattingPolicy = CSharpFormattingPolicies.Instance.GetProjectOptions(SD.ProjectService.FindProjectContainingFile(editor.FileName)); var textEditor = editor.GetService<TextEditor>(); if (textEditor != null) { options = new CodeEditorFormattingOptionsAdapter(textEditor.Options, editor.Options, formattingPolicy.OptionsContainer); var textViewServices = textEditor.TextArea.TextView.Services; // Unregister any previous ITextEditorOptions instance from editor, if existing, register our impl. textViewServices.RemoveService(typeof(ITextEditorOptions)); textViewServices.AddService(typeof(ITextEditorOptions), options); // Set TextEditor's options to same object originalEditorOptions = textEditor.Options; textEditor.Options = options.TextEditorOptions; } }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="TextEditorOptionsPageViewModel"/> class. /// (Do not use this constructor it is only for design-time support!) /// </summary> public TextEditorOptionsPageViewModel() : base("Text Editor") { Trace.Assert(WindowsHelper.IsInDesignMode, "This TextEditorOptionsPageViewModel constructor must not be used at runtime."); Options = new TextEditorOptions(); _fontStyleConverter = new FontStyleConverter(); _fontWeightConverter = new FontWeightConverter(); }
public CodeEditor() { FontFamily = new FontFamily("Consolas"); FontSize = 12; ShowLineNumbers = true; Options = new TextEditorOptions { ConvertTabsToSpaces = true }; }
void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue) { if (oldValue != null) { PropertyChangedWeakEventManager.RemoveListener(oldValue, this); } textArea.Options = newValue; if (newValue != null) { PropertyChangedWeakEventManager.AddListener(newValue, this); } OnOptionChanged(new PropertyChangedEventArgs(null)); }
/// <summary> /// Initializes a new instance of TextEditorOptions by copying all values /// from <paramref name="options"/> to the new instance. /// </summary> public TextEditorOptions(TextEditorOptions options) { // get all the fields in the class FieldInfo[] fields = typeof(TextEditorOptions).GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); // copy each value over to 'this' foreach(FieldInfo fi in fields) { if (!fi.IsNotSerialized) fi.SetValue(this, fi.GetValue(options)); } }
/// <summary> /// Initializes a new instance of TextEditorOptions by copying all values /// from <paramref name="options"/> to the new instance. /// </summary> public TextEditorOptions(TextEditorOptions options) { // get all the fields in the class FieldInfo[] fields = typeof(TextEditorOptions).GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); // copy each value over to 'this' foreach (FieldInfo fi in fields) { if (!fi.IsNotSerialized) { fi.SetValue(this, fi.GetValue(options)); } } }
/// <summary> /// Copies the options from the specified object. /// </summary> /// <param name="options">The options to copy.</param> public void Set(TextEditorOptions options) { var fields = typeof(TextEditorOptions).GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (var fieldInfo in fields) { if (!fieldInfo.IsNotSerialized) { fieldInfo.SetValue(this, fieldInfo.GetValue(options)); } } OnPropertyChanged(string.Empty); }
/// <inheritdoc /> /// <summary> /// Initialize viewmodel with data that should not be initialized in constructor /// but is usually necessary after creating default object. /// </summary> /// <param name="settingData"></param> public void InitInstance(IOptions settingData) { if (settingData != null) { FilePath = GetDefaultFileNewName(settingData.FileNewDefaultFileName, settingData.FileNewDefaultFileExtension); TextOptions = new ICSharpCode.AvalonEdit.TextEditorOptions(settingData.EditorTextOptions); HighlightingDefinition = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(_FilePath)); } // TODO: This should be moved into Settings project? InsertBlocks = new ObservableCollection <BlockDefinition>(SettingsView.Config.ViewModels.ConfigViewModel.GetDefaultBlockDefinitions()); if (settingData != null) { WordWrap = settingData.WordWarpText; } }
public CodeEditor() { _keystrokeTimer = new System.Timers.Timer(2000); _keystrokeTimer.Elapsed += KeystrokeTimeElapsed; _languageContext = new LanguageContext(); FontFamily = new FontFamily("Consolas"); FontSize = 12; ShowLineNumbers = true; Options = new TextEditorOptions { ConvertTabsToSpaces = true, HighlightCurrentLine = true, IndentationSize = 4, AllowScrollBelowDocument = true }; MouseHover += OnMouseHover; MouseHoverStopped += OnMouseHoverStopped; TextArea.Caret.PositionChanged += HighlightBrackets; _foldingStrategy = new PowershellFoldingStrategy(); var foldingUpdateTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(4) }; foldingUpdateTimer.Tick += delegate { UpdateFoldings(); }; foldingUpdateTimer.Start(); _bracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView, _languageContext); TextArea.TextView.BackgroundRenderers.Add(_bracketRenderer); _inlineScriptTransformer = new InlineScriptDocumentTransformer(this.TextArea.TextView, _languageContext); TextArea.TextView.BackgroundRenderers.Add(_inlineScriptTransformer); InitializeColorizer(); }
protected override void OnStartup() { _documentService = Editor.Services.GetInstance<IDocumentService>().ThrowIfMissing(); _windowService = Editor.Services.GetInstance<IWindowService>().ThrowIfMissing(); Options = new TextEditorOptions(); LoadOptions(); AddExtensionDescription(); AddDataTemplates(); AddCommands(); AddMenus(); AddContextMenu(); AddOptions(); AddStatusBarItems(); AddDocumentFactories(); AddSearchScopes(); Editor.PropertyChanged += OnEditorPropertyChanged; Editor.UIInvalidated += OnEditorUIInvalidated; _documentService.ActiveDocumentChanged += OnActiveDocumentChanged; ShowCommands(false); }
public OptionsAdapter(TextEditorOptions avalonEditOptions) { this.avalonEditOptions = avalonEditOptions; }
public CodeEditorFormattingOptionsAdapter(TextEditorOptions originalAvalonEditOptions, ITextEditorOptions originalSDOptions, CSharpFormattingOptionsContainer container) { if (originalAvalonEditOptions == null) throw new ArgumentNullException("originalAvalonEditOptions"); if (originalSDOptions == null) throw new ArgumentNullException("originalSDOptions"); if (container == null) throw new ArgumentNullException("container"); this.originalAvalonEditOptions = originalAvalonEditOptions; this.avalonEditOptions = new TextEditorOptions(originalAvalonEditOptions); this.originalSDOptions = originalSDOptions; this.container = container; // Update overridden options once UpdateOverriddenProperties(); CSharpFormattingPolicies.Instance.FormattingPolicyUpdated += OnFormattingPolicyUpdated; this.originalAvalonEditOptions.PropertyChanged += OnOrigAvalonOptionsPropertyChanged; this.originalSDOptions.PropertyChanged += OnSDOptionsPropertyChanged; }
public E2IndentationStrategy(TextEditorOptions options) { _options = options; }
public EditorWindow() { InitializeComponent(); //Create the Editor Manager this._manager = new EditorManager(this.textEditor, this.mnuCurrentHighlighter, this.stsCurrSyntax, this.stsSyntaxValidation, this.mnuSymbolBoundaries); //Set up the Editor Options TextEditorOptions options = new TextEditorOptions(); options.EnableEmailHyperlinks = Properties.Settings.Default.EnableClickableUris; options.EnableHyperlinks = Properties.Settings.Default.EnableClickableUris; options.ShowEndOfLine = Properties.Settings.Default.ShowEndOfLine; options.ShowSpaces = Properties.Settings.Default.ShowSpaces; options.ShowTabs = Properties.Settings.Default.ShowTabs; textEditor.Options = options; textEditor.ShowLineNumbers = true; if (Properties.Settings.Default.EditorFontFace != null) { textEditor.FontFamily = Properties.Settings.Default.EditorFontFace; } textEditor.FontSize = Math.Round(Properties.Settings.Default.EditorFontSize, 0); textEditor.Foreground = new SolidColorBrush(Properties.Settings.Default.EditorForeground); textEditor.Background = new SolidColorBrush(Properties.Settings.Default.EditorBackground); //Setup Options based on the User Config file if (!Properties.Settings.Default.UseUtf8Bom) { this.mnuUseBomForUtf8.IsChecked = false; Options.UseBomForUtf8 = false; } if (!Properties.Settings.Default.EnableSymbolSelection) { this._manager.IsSymbolSelectionEnabled = false; this.mnuSymbolSelectEnabled.IsChecked = false; } if (!Properties.Settings.Default.IncludeSymbolBoundaries) { this._manager.IncludeBoundaryInSymbolSelection = false; this.mnuSymbolSelectIncludeBoundary.IsChecked = false; } if (!Properties.Settings.Default.EnableAutoComplete) { this._manager.IsAutoCompleteEnabled = false; this.mnuAutoComplete.IsChecked = false; } if (!Properties.Settings.Default.EnableHighlighting) { this._manager.IsHighlightingEnabled = false; this.mnuEnableHighlighting.IsChecked = false; } if (!Properties.Settings.Default.EnableValidateAsYouType) { this._manager.IsValidateAsYouType = false; this.mnuValidateAsYouType.IsChecked = false; } if (!Properties.Settings.Default.ShowLineNumbers) { textEditor.ShowLineNumbers = false; this.mnuShowLineNumbers.IsChecked = false; } if (Properties.Settings.Default.WordWrap) { textEditor.WordWrap = true; this.mnuWordWrap.IsChecked = true; } if (Properties.Settings.Default.EnableClickableUris) { this.mnuClickableUris.IsChecked = true; } if (Properties.Settings.Default.ShowEndOfLine) { this.mnuShowSpecialEOL.IsChecked = true; } if (Properties.Settings.Default.ShowSpaces) { this.mnuShowSpecialSpaces.IsChecked = true; } if (Properties.Settings.Default.ShowTabs) { this.mnuShowSpecialTabs.IsChecked = true; } this._manager.SetHighlighter(Properties.Settings.Default.DefaultHighlighter); //Enable/Disable state dependent menu options this.mnuUndo.IsEnabled = textEditor.CanUndo; this.mnuRedo.IsEnabled = textEditor.CanRedo; //Create our Dialogs _ofd.Title = "Open RDF/SPARQL File"; _ofd.DefaultExt = ".rdf"; _ofd.Filter = FileFilterAll; _sfd.Title = "Save RDF/SPARQL File"; _sfd.DefaultExt = ".rdf"; _sfd.Filter = _ofd.Filter; //Setup dropping of files textEditor.AllowDrop = true; textEditor.Drop += new DragEventHandler(textEditor_Drop); }
/// <summary> /// Initializes a new instance of the <see cref="TextEditorOptionsPageViewModel"/> class. /// </summary> /// <param name="textExtension">The <see cref="TextExtension"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="textExtension"/> is <see langword="null"/>. /// </exception> public TextEditorOptionsPageViewModel(TextExtension textExtension) : base("Text Editor") { if (textExtension == null) throw new ArgumentNullException(nameof(textExtension)); _textExtension = textExtension; Options = new TextEditorOptions(); SetDefaultsCommand = new DelegateCommand(SetDefaults); SelectFontCommand = new DelegateCommand(SelectFont); _fontStretchConverter = new FontStretchConverter(); _fontStyleConverter = new FontStyleConverter(); _fontWeightConverter = new FontWeightConverter(); }
void OnOptionsChanged(TextEditorOptions oldValue, TextEditorOptions newValue) { if (oldValue != null) { PropertyChangedWeakEventManager.RemoveListener(oldValue, this); } textArea.Options = newValue; if (newValue != null) { PropertyChangedWeakEventManager.AddListener(newValue, this); } OnOptionChanged(new PropertyChangedEventArgs(null)); }
public ConsoleControl() { this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); object tmp; this.editorAdapter = EditorControlService.CreateEditor(out tmp); this.editor = (AvalonEdit.TextEditor)tmp; this.editor.SetValue(Grid.ColumnProperty, 0); this.editor.SetValue(Grid.RowProperty, 0); this.editor.ShowLineNumbers = false; if (consoleOptions == null) { consoleOptions = new TextEditorOptions(editor.Options); consoleOptions.AllowScrollBelowDocument = false; } this.editor.Options = consoleOptions; this.Children.Add(editor); editor.TextArea.ReadOnlySectionProvider = readOnlyRegion = new BeginReadOnlySectionProvider(); editor.TextArea.TextEntered += new TextCompositionEventHandler(editor_TextArea_TextEntered); editor.TextArea.PreviewKeyDown += new KeyEventHandler(editor_TextArea_PreviewKeyDown); }
public IndentationStrategy(TextEditorOptions options) { this.IndentationString = options.IndentationString; }
/// <summary> /// Copies the options from the specified object. /// </summary> /// <param name="options">The options to copy.</param> public void Set(TextEditorOptions options) { var fields = typeof(TextEditorOptions).GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (var fieldInfo in fields) { if (!fieldInfo.IsNotSerialized) fieldInfo.SetValue(this, fieldInfo.GetValue(options)); } OnPropertyChanged(string.Empty); }