Esempio n. 1
0
File: Editor.cs Progetto: zparr/ATF
        /// <summary>
        /// Saves the document at the given URI</summary>
        /// <param name="document">Document to save</param>
        /// <param name="uri">New document URI</param>
        public void Save(IDocument document, Uri uri)
        {
            string   filePath = uri.LocalPath;
            FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate;

            using (FileStream stream = new FileStream(filePath, fileMode))
            {
                DomXmlWriter          writer = new DomXmlWriter(m_schemaLoader.TypeCollection);
                WinGuiWpfDataDocument eventSequenceDocument = (WinGuiWpfDataDocument)document;
                writer.Write(eventSequenceDocument.DomNode, stream, uri);
            }
        }
Esempio n. 2
0
File: Editor.cs Progetto: zparr/ATF
        /// <summary>
        /// Notifies the client that its Control has been activated. Activation occurs when
        /// the Control gets focus, or a parent "host" Control gets focus.</summary>
        /// <param name="control">Client Control that was activated</param>
        /// <remarks>This method is only called by IControlHostService if the Control was previously
        /// registered for this IControlHostClient.</remarks>
        void IControlHostClient.Activate(object control)
        {
            WinGuiWpfDataDocument document = null;

            if (control is System.Windows.Forms.Control)
            {
                document = ((System.Windows.Forms.Control)control).Tag as WinGuiWpfDataDocument;
            }

            if (document != null)
            {
                m_documentRegistry.ActiveDocument = document;

                WinGuiWpfDataContext context = document.As <WinGuiWpfDataContext>();
                m_contextRegistry.ActiveContext = context;
            }
        }
Esempio n. 3
0
File: Editor.cs Progetto: zparr/ATF
        /// <summary>
        /// Requests permission to close the client's Control</summary>
        /// <param name="control">Client Control to be closed</param>
        /// <returns>True if the Control can close, or false to cancel</returns>
        /// <remarks>
        /// 1. This method is only called by IControlHostService if the Control was previously
        /// registered for this IControlHostClient.
        /// 2. If true is returned, the IControlHostService calls its own
        /// UnregisterControl. The IControlHostClient has to call RegisterControl again
        /// if it wants to re-register this Control.</remarks>
        bool IControlHostClient.Close(object control, bool mainWindowClosing)
        {
            bool closed = true;

            if (control is Control)
            {
                WinGuiWpfDataDocument document = ((Control)control).Tag as WinGuiWpfDataDocument;
                if (document != null)
                {
                    closed = m_documentService.Close(document);
                    if (closed)
                    {
                        m_contextRegistry.RemoveContext(document);
                    }
                }
            }
            return(closed);
        }
Esempio n. 4
0
File: Editor.cs Progetto: zparr/ATF
        /// <summary>
        /// Opens or creates a document at the given URI</summary>
        /// <param name="uri">Document URI</param>
        /// <returns>Document, or null if the document couldn't be opened or created</returns>
        public IDocument Open(Uri uri)
        {
            DomNode node     = null;
            string  filePath = uri.LocalPath;
            string  fileName = Path.GetFileName(filePath);

            if (File.Exists(filePath))
            {
                // read existing document using standard XML reader
                using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    DomXmlReader reader = new DomXmlReader(m_schemaLoader);
                    node = reader.Read(stream, uri);
                }
            }
            else
            {
                // create new document by creating a Dom node of the root type defined by the schema
                node = new DomNode(Schema.winGuiCommonDataType.Type, Schema.winGuiCommonDataRootElement);
            }

            WinGuiWpfDataDocument document = null;

            if (node != null)
            {
                // Initialize Dom extensions now that the data is complete
                node.InitializeExtensions();

                WinGuiWpfDataContext context = node.As <WinGuiWpfDataContext>();
                context.SelectionChanged += ContextSelectionChanged;

                ControlInfo controlInfo = new ControlInfo(Path.Combine(filePath, fileName), StandardControlGroup.Center, new Sce.Atf.Wpf.Docking.DockContent(null, null), this);
                context.ControlInfo = controlInfo;

                // set document URI
                document     = node.As <WinGuiWpfDataDocument>();
                document.Uri = uri;

                context.ListView.Tag = document;

                // If the document is empty, add some data so there's something to look at
                if (!context.Items.Any(typeof(object)))
                {
                    DomNode domNode = new DomNode(Schema.eventType.Type);
                    domNode.SetAttribute(Schema.eventType.nameAttribute, "First Event");
                    domNode.SetAttribute(Schema.eventType.durationAttribute, 100);
                    var dataObject = new System.Windows.DataObject(new object[] { domNode });
                    context.Insert(dataObject);

                    domNode = new DomNode(Schema.eventType.Type);
                    domNode.SetAttribute(Schema.eventType.nameAttribute, "Second Event");
                    domNode.SetAttribute(Schema.eventType.durationAttribute, 200);
                    var dataObject2 = new System.Windows.DataObject(new object[] { domNode });
                    context.Insert(dataObject2);
                }

                // show the ListView control
                ControlInfo registeredControlInfo = (ControlInfo)m_controlHostService.RegisterControl(context.ListView,
                                                                                                      fileName,
                                                                                                      "WPF Sample file",
                                                                                                      controlInfo.Group,
                                                                                                      fileName,
                                                                                                      this);

                if (registeredControlInfo.DockContent != null)
                {
                    registeredControlInfo.DockContent.Closing += DockContent_Closing;
                }
            }

            return(document);
        }