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();
        }
Exemple #2
0
 /// <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;
 }
Exemple #3
0
        /// <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);
        }
Exemple #5
0
 public void AddEditor(IDocumentEditor editor)
 {
     if (!editors.Add(editor))
     {
         return;
     }
     editor.Window.OnClose += () => RemoveEditor(editor);
 }
Exemple #6
0
        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);
        }
Exemple #7
0
        static async Task BindEditorAsync(IDocumentEditor newEditor)
        {
            var docRef = newEditor.DocumentReference;

            if (!docRef.IsOpen)
            {
                await docRef.Open();
            }
            newEditor.BindDocument();
        }
Exemple #8
0
        private static void OnEditTestStation(IDocumentEditor source, Document document, TestStationDescription11 obj,
                                              bool saveDocumentOnCompletion)
        {
            EditDocumentDelegate handler = EditTestStation;

            if (handler != null)
            {
                handler(source, document, obj, saveDocumentOnCompletion);
            }
        }
Exemple #9
0
 protected virtual void UpdateCaretInfo(IDocumentEditor sender)
 {
     if (sender != null)
     {
         HasCaret        = true;
         CaretLine       = sender.CaretLine;
         CaretColumn     = sender.CaretColumn;
         IsCaretOverride = sender.IsCaretOverride;
     }
 }
Exemple #10
0
        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;
        }
Exemple #11
0
        /// <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));
            }
        }
Exemple #12
0
        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);
            }
        }
Exemple #13
0
        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;
        }
Exemple #15
0
 /// <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;
            }
        }
Exemple #17
0
        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;
        }
Exemple #18
0
        /// <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;
            }
        }
Exemple #21
0
        /// <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);
        }
Exemple #22
0
        /// <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);
        }
Exemple #23
0
 public void RemoveEditor(IDocumentEditor editor)
 {
     editors.Remove(editor);
 }
Exemple #24
0
 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 );
 }
Exemple #26
0
 /// <summary>
 /// Initializes the DocumentClosedEventArgs
 /// </summary>
 /// <param name="editor">The document editor</param>
 public DocumentClosedEventArgs(IDocumentEditor editor)
     : base(editor)
 {
 }
Exemple #27
0
 /// <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 );
 }
Exemple #29
0
 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;
        }
Exemple #33
0
 /// <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 );
 }