protected TextEditorWidgetBase(IUIStyle style, IDocumentEditor <TView, TDocument> editor) : base(style, editor) { if (editor == null) { throw new ArgumentNullException(); } ActionMap = new KeyboardActionMap(); RemoteCarets = new ObservableCollection <ICaret>(); RemoteCarets.CollectionChanged += OnRemoteCaretsChanged; Caret = new Caret <TView, TDocument>(UIStyle, Content); Caret.AddNotify(this); RaiseChildAdded(0, Caret); KeyTyped += OnKeyTyped; KeyPressed += OnKeyPressed; KeyRepeated += OnKeyPressed; MouseUp += OnMouseUp; MouseDown += OnMouseDown; MouseDragged += OnMouseDragged; Cursor = MouseCursor.IBeam; Focusable = true; ReadOnly = false; InstallKeyMap(); }
/// <summary> /// For testing to override the document view used. /// </summary> /// <param name="style"></param> /// <param name="editor"></param> public TextField(IUIStyle style, IDocumentEditor <DocumentView <PlainTextDocument>, PlainTextDocument> editor) : base(style, editor) { WrapText = WrapText.None; Content.Document.PushFilter(new LineBreakFilter(Content.ViewFactory.TextProcessingRules)); Content.Document.PushFilter(new MaxLengthFilter(Content.Document, () => MaxLength)); Clip = true; }
/// <summary> /// Closes an active document. /// </summary> /// <param name="editor">The document editor attached</param> /// <returns>True if closed successfully</returns> /// <remarks>Shows the 'are you sure' prompt if there are unsaved edits.</remarks> public bool Close(IDocumentEditor editor) { // Show the 'are you sure' prompt if necesary if (editor.AttachedDocument.IsDirty) { switch (CloseUnsavedDialog.ShowDialog(OwnerWindow, editor.AttachedDocument)) { case CloseUnsavedDialogResult.Save: Save(); break; case CloseUnsavedDialogResult.Cancel: return(false); } } // Close DocumentManager.Close(editor); // Update ActiveDocument if (editor == ActiveDocumentEditor) { ActiveDocumentEditor = null; } return(true); }
private LayoutDocument OpenDocument(IDocumentEditor editor) { // Create document LayoutDocument document = new LayoutDocument(); document.Content = editor.EditorUI; document.Title = GetDocumentTitle(editor.AttachedDocument); // Set up events document.Closing += Document_Closing; document.Closed += Document_Closed; document.IsActiveChanged += Document_IsActiveChanged; // Add to dictionary _openedDocuments.Add(document, editor); // Add to layout documentPane.Children.Add(document); documentPane.SelectedContentIndex = documentPane.IndexOf(document); // Subscribe to document events editor.AttachedDocument.PropertyChanged += Document_PropertyChanged; if (editor.AttachedDocument.Reference != null) { editor.AttachedDocument.Reference.PropertyChanged += Reference_PropertyChanged; } return(document); }
public void AddEditor(IDocumentEditor editor) { if (!editors.Add(editor)) { return; } editor.Window.OnClose += () => RemoveEditor(editor); }
public static bool EditDocument(IDocumentEditor source, Document _document, string uuid, string documentContent, bool saveDocumentOnCompletion) { bool documentSaved = false; Document document = GetDocument(uuid); if (document != null) { string content = Encoding.UTF8.GetString(_document.DocumentContent); switch (document.DocumentType) { case dbDocument.DocumentType.INSTRUMENT_DESCRIPTION: { InstrumentDescription obj = InstrumentDescription.Deserialize(content); OnEditInstrument(source, document, obj, saveDocumentOnCompletion); break; } case dbDocument.DocumentType.TEST_ADAPTER_DESCRIPTION: { TestAdapterDescription1 obj = TestAdapterDescription1.Deserialize(content); OnEditTestAdapter(source, document, obj, saveDocumentOnCompletion); break; } case dbDocument.DocumentType.TEST_STATION_DESCRIPTION: { TestStationDescription11 obj = TestStationDescription11.Deserialize(content); OnEditTestStation(source, document, obj, saveDocumentOnCompletion); break; } case dbDocument.DocumentType.UUT_DESCRIPTION: { UUTDescription obj = UUTDescription.Deserialize(content); OnEditUut(source, document, obj, saveDocumentOnCompletion); break; } default: { MessageBox.Show( string.Format("There is currently no editor available for document type \"{0}\".", document.DocumentType)); break; } } } return(documentSaved); }
static async Task BindEditorAsync(IDocumentEditor newEditor) { var docRef = newEditor.DocumentReference; if (!docRef.IsOpen) { await docRef.Open(); } newEditor.BindDocument(); }
private static void OnEditTestStation(IDocumentEditor source, Document document, TestStationDescription11 obj, bool saveDocumentOnCompletion) { EditDocumentDelegate handler = EditTestStation; if (handler != null) { handler(source, document, obj, saveDocumentOnCompletion); } }
protected virtual void UpdateCaretInfo(IDocumentEditor sender) { if (sender != null) { HasCaret = true; CaretLine = sender.CaretLine; CaretColumn = sender.CaretColumn; IsCaretOverride = sender.IsCaretOverride; } }
protected TextWidgetBase(IUIStyle style, IDocumentEditor <TView, TDocument> editor) : base(style) { textStyles = StyleSystem.StylesFor <TextStyleDefinition>(); ChildrenChanged += HandleOnChildrenChanged; DocumentEditor = editor; Content = DocumentEditor.CreateDocumentView(AnchoredRect.CreateTopAnchored()); WrapText = WrapText.Auto; }
/// <summary> /// Closes a document editor /// </summary> /// <param name="editor"></param> public void Close(IDocumentEditor editor) { // Remove from list of opened editors _editors.Remove(editor); // Close event if (DocumentClosed != null) { DocumentClosed(this, new DocumentClosedEventArgs(editor)); } }
private static void OnEditUut(IDocumentEditor source, Document document, UUTDescription obj, bool saveDocumentOnCompletion) { bool ret = false; EditDocumentDelegate handler = EditUUT; if (handler != null) { handler(source, document, obj, saveDocumentOnCompletion); } }
private static void OnEditTestAdapter(IDocumentEditor source, Document document, TestAdapterDescription1 obj, bool saveDocumentOnCompletion) { bool ret = false; EditDocumentDelegate handler = EditTestAdapter; if (handler != null) { handler(source, document, obj, saveDocumentOnCompletion); } }
public DocumentEditorViewModel(IDocumentEditor documentEditor, IExporter exporter) { Ensure.ArgumentNotNull(documentEditor, "documentEditor"); Ensure.ArgumentNotNull(exporter, "exporter"); _documentEditor = documentEditor; _fontSize = DefaultFontSize; _documentEditor.New(); _document = new TextDocument(); _exporter = exporter; }
/// <summary> /// Saves the active document /// </summary> public bool Save(IDocumentEditor editor) { if (editor.AttachedDocument.Reference != null) { DocumentManager.Save(editor.AttachedDocument); return(true); } else { return(SaveAs(editor)); } }
private void SetUpToolbox(IDocumentEditor editor) { var toolboxProvider = editor as IToolboxProvider; // Set toolbar panel toolboxPanel.ItemsSource = toolboxProvider; // Enable 'allow drop' if (toolboxProvider != null) { editor.EditorUI.AllowDrop = true; } }
public TextArea(IUIStyle style, IDocumentEditor <DocumentView <PlainTextDocument>, PlainTextDocument> editor) : base(style, editor) { ActionMap.Register(new KeyStroke(Keys.Enter), OnEnterPressed); ActionMap.Register(new KeyStroke(Keys.PageUp), OnPageUpPressed); ActionMap.Register(new KeyStroke(Keys.PageDown), OnPageDownPressed); lineNumberRenderer = new LineNumberWidget(UIStyle); lineNumberRenderer.AddNotify(this); lineNumberRenderer.Anchor = AnchoredRect.CreateLeftAnchored(); lineNumberRenderer.DocumentView = Content; RaiseChildAdded(0, lineNumberRenderer); DisplayLineNumbers = true; Caret.CaretChanged += OnCaretChanged; }
/// <summary> /// Creates a new document in the specified path, with the specified format, and opens it /// </summary> /// <param name="format"></param> /// <param name="path"></param> public IDocumentEditor Create(IDocumentTemplate format) { // Create document var document = format.CreateDocument(); document.IsDirty = true; // Find and create editor IDocumentEditor editor = CreateEditor(document); // Trigger event if (DocumentOpened != null) { DocumentOpened(this, new DocumentOpenedEventArgs(editor)); } return(editor); }
public DocumentView(IDocumentEditor <DocumentView <TDocument>, TDocument> editor) : base(editor.Style) { if (editor == null) { throw new ArgumentNullException(nameof(editor)); } Style.ValueChanged += OnStyleValueChanged; StyleInvalidated += (s, a) => ResetDocumentView(); TextStyles = Style.StyleSystem.StylesFor <TextStyleDefinition>(); Highlighter = new Highligher <TDocument>(this); ViewFactory = editor.CreateViewFactory(); Document = editor.CreateDocument(); Focusable = false; Enabled = false; }
void Document_IsActiveChanged(object sender, EventArgs e) { LayoutDocument document = (LayoutDocument)sender; IDocumentEditor editor = _openedDocuments[document]; if (document.IsActive) { // Set active editor in controller DocumentController.ActiveDocumentEditor = editor; // Set up toolbox SetUpToolbox(editor); } else { // Disable drop, so that we don't drop invalid items in an editor editor.EditorUI.AllowDrop = false; } }
/// <summary> /// Displays a 'save as' dialog, and saves active document /// </summary> public bool SaveAs(IDocumentEditor editor) { // Show save dialog SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = Resources.Strings.Dialog_SaveDocument_Title; dialog.Filter = Resources.Strings.Dialog_FileType_AllFiles + "|*.*"; dialog.FileName = editor.AttachedDocument.Reference.StoragePath; bool?res = dialog.ShowDialog(); if (res.HasValue && res.Value) { DocumentManager.SaveAs(dialog.FileName, editor.AttachedDocument); return(true); } return(false); }
/// <summary> /// Attempts to create an editor for the document /// </summary> /// <param name="document">The document</param> /// <exception cref="ArgumentException">Thrown if failed to create editor</exception> /// <returns>The editor</returns> private IDocumentEditor CreateEditor(IDocument document) { IDocumentEditor editor = null; foreach (var factory in Factories) { if (factory.CanEdit(document.GetType())) { editor = factory.CreateEditor(document); break; } } if (editor == null) { throw new ArgumentException("Failed to create editor."); } _editors.Add(editor); return(editor); }
public void RemoveEditor(IDocumentEditor editor) { editors.Remove(editor); }
public TestDocumentViewEditor(IDocumentEditor <DocumentView <TDocument>, TDocument> backend) { this.backend = backend; }
private static void OnEditUut( IDocumentEditor source, Document document, UUTDescription obj, bool saveDocumentOnCompletion) { bool ret = false; EditDocumentDelegate handler = EditUUT; if (handler != null) handler( source, document, obj, saveDocumentOnCompletion ); }
/// <summary> /// Initializes the DocumentClosedEventArgs /// </summary> /// <param name="editor">The document editor</param> public DocumentClosedEventArgs(IDocumentEditor editor) : base(editor) { }
/// <summary> /// Initializes the DocumentOpenedEventArgs /// </summary> /// <param name="editor">The document editor</param> public DocumentOpenedEventArgs(IDocumentEditor editor) : base(editor) { }
private static void OnEditTestAdapter( IDocumentEditor source, Document document, TestAdapterDescription1 obj, bool saveDocumentOnCompletion) { bool ret = false; EditDocumentDelegate handler = EditTestAdapter; if (handler != null) handler( source, document, obj, saveDocumentOnCompletion ); }
public TestDocumentView(IDocumentEditor <DocumentView <TDocument>, TDocument> editor) : base(editor) { }
static async Task BindEditorAsync (IDocumentEditor newEditor) { var docRef = newEditor.DocumentReference; if (!docRef.IsOpen) { await docRef.Open (); } newEditor.BindDocument (); }
public async Task CloseDocumentEditor (IDocumentEditor editor, bool unbindUI, bool deleteThumbnail, bool reloadThumbnail) { var docRef = editor.DocumentReference; if (docRef == null) return; var doc = docRef.Document; if (doc == null) return; Debug.WriteLine ("CLOSE " + docRef.File.Path); if (!doc.IsOpen) return; docRef.IsNew = false; Settings.LastDocumentPath = ""; try { await docRef.Close (); editor.UnbindDocument (); if (unbindUI) { editor.UnbindUI (); } InvalidateThumbnail (docRef.File, deleteThumbnail:deleteThumbnail, reloadThumbnail:reloadThumbnail); } catch (Exception ex) { Debug.WriteLine (ex); } }
public static bool EditDocument( IDocumentEditor source, Document _document, string uuid, string documentContent, bool saveDocumentOnCompletion) { bool documentSaved = false; Document document = GetDocument( uuid ); if (document != null) { string content = Encoding.UTF8.GetString( _document.DocumentContent ); switch (document.DocumentType) { case dbDocument.DocumentType.INSTRUMENT_DESCRIPTION: { InstrumentDescription obj = InstrumentDescription.Deserialize( content ); OnEditInstrument( source, document, obj, saveDocumentOnCompletion ); break; } case dbDocument.DocumentType.TEST_ADAPTER_DESCRIPTION: { TestAdapterDescription1 obj = TestAdapterDescription1.Deserialize( content ); OnEditTestAdapter( source, document, obj, saveDocumentOnCompletion ); break; } case dbDocument.DocumentType.TEST_STATION_DESCRIPTION: { TestStationDescription11 obj = TestStationDescription11.Deserialize( content ); OnEditTestStation( source, document, obj, saveDocumentOnCompletion ); break; } case dbDocument.DocumentType.UUT_DESCRIPTION: { UUTDescription obj = UUTDescription.Deserialize( content ); OnEditUut( source, document, obj, saveDocumentOnCompletion ); break; } default: { MessageBox.Show( string.Format( "There is currently no editor available for document type \"{0}\".", document.DocumentType ) ); break; } } } return documentSaved; }
/// <summary> /// Initializes the DocumentOpenedEventArgs /// </summary> /// <param name="editor">The document editor</param> public DocumentEventArgsBase(IDocumentEditor editor) { Editor = editor; }
private static void OnEditTestStation( IDocumentEditor source, Document document, TestStationDescription11 obj, bool saveDocumentOnCompletion) { EditDocumentDelegate handler = EditTestStation; if (handler != null) handler( source, document, obj, saveDocumentOnCompletion ); }