Пример #1
0
        /// <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(Path.Combine(filePath, fileName),
                                                          StandardControlGroup.Center,
                                                          new DockContent(null, null), this);
                context.ControlInfo = controlInfo;

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

                context.Document = document;

                // show the document editor
                // This line requires references to System.Drawing and System.Windows.Forms. Would really like to remove those dependencies!
                m_controlHostService.RegisterControl(context.View,
                                                     fileName,
                                                     "Event sequence document",
                                                     StandardControlGroup.Center,
                                                     Path.Combine(filePath, fileName),
                                                     this);
            }

            return(document);
        }
Пример #2
0
        /// <summary>
        /// Registers a control with the control host service</summary>
        /// <param name="def">Control definition</param>
        /// <param name="control">Control</param>
        /// <param name="client">Client that owns the control and receives notifications
        /// about its status, or null if no notifications are needed</param>
        /// <returns>IControlInfo for registered control</returns>
        public IControlInfo RegisterControl(ControlDef def, object control, IControlHostClient client)
        {
            Requires.NotNull(def, "def");
            Requires.NotNull(control, "control");
            Requires.NotNullOrEmpty(def.Id, "def.Id");
            Requires.NotNull(client, "client");

            if (m_registeredContents.Any <ControlInfo>(x => x.Id == def.Id))
            {
                throw new ArgumentException("Content with id " + def.Id + " already registered");
            }

            IDockContent dockContent = m_dockPanel.RegisterContent(control, def.Id, ControlGroupToDockTo(def.Group));

            dockContent.IsFocusedChanged += DockContent_IsFocusedChanged;

            ControlInfo contentInfo = new ControlInfo(def.Name, def.Description, def.Id, def.Group, def.ImageSourceKey, dockContent, client);

            m_registeredContents.Add(contentInfo);

            if (m_commandService != null)
            {
                contentInfo.Command = m_commandService.RegisterCommand(
                    dockContent,
                    StandardMenu.Window,
                    StandardCommandGroup.WindowDocuments,
                    contentInfo.Name,
                    "Activate Control".Localize(),
                    Keys.None, null, CommandVisibility.Menu,
                    this).GetCommandItem();
            }

            ActivateClient(client, true);

            return(contentInfo);
        }
Пример #3
0
        /// <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;
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <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(Path.Combine(filePath, fileName),
                    StandardControlGroup.Center,
                    new DockContent(null, null), this);
                context.ControlInfo = controlInfo;

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

                context.Document = document;

                // show the document editor
                // This line requires references to System.Drawing and System.Windows.Forms. Would really like to remove those dependencies!
                m_controlHostService.RegisterControl(context.View, 
                    fileName, 
                    "Event sequence document", 
                    StandardControlGroup.Center, 
                    Path.Combine(filePath, fileName), 
                    this);
            }

            return document;
        }