Ejemplo n.º 1
0
Archivo: Editor.cs Proyecto: 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);
                EventSequenceDocument eventSequenceDocument = (EventSequenceDocument)document;
                writer.Write(eventSequenceDocument.DomNode, stream, uri);
            }
        }
Ejemplo n.º 2
0
Archivo: Editor.cs Proyecto: 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(Control control)
        {
            EventSequenceDocument document = control.Tag as EventSequenceDocument;

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

                EventSequenceContext context = document.As <EventSequenceContext>();
                m_contextRegistry.ActiveContext = context;
            }
        }
Ejemplo n.º 3
0
Archivo: Editor.cs Proyecto: 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.eventSequenceType.Type, Schema.eventSequenceRootElement);
            }

            EventSequenceDocument document = null;

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

                EventSequenceContext context = node.As <EventSequenceContext>();

                ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);
                context.ControlInfo = controlInfo;

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

                // set document GUIs for search and replace
                document.SearchUI  = new DomNodeSearchToolStrip();
                document.ReplaceUI = new DomNodeReplaceToolStrip();
                document.ResultsUI = new DomNodeSearchResultsListView(m_contextRegistry);

                context.ListView.Tag = document;

                // show the ListView control
                m_controlHostService.RegisterControl(context.ListView, controlInfo, this);
            }

            return(document);
        }
Ejemplo n.º 4
0
Archivo: Editor.cs Proyecto: zparr/ATF
        /// <summary>
        /// Requests permission to close the client's Control. Allows user to save document before it closes.</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(Control control)
        {
            bool closed = true;

            EventSequenceDocument document = control.Tag as EventSequenceDocument;

            if (document != null)
            {
                closed = m_documentService.Close(document);
                if (closed)
                {
                    m_contextRegistry.RemoveContext(document);
                }
            }

            return(closed);
        }