コード例 #1
0
        /// <summary>
        /// Closes the document and removes any views of it from the UI</summary>
        /// <param name="document">Document to close</param>
        public void Close(IDocument document)
        {
            StoryDocument doc = document.As <StoryDocument>();

            m_controlHostService.UnregisterControl(doc.Control);

            // close the document
            m_documentRegistry.Remove(document);
        }
コード例 #2
0
        /// <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>
        public bool Close(Control control)
        {
            StoryDocument document = control.Tag as StoryDocument;

            if (document != null)
            {
                return(m_documentService.Close(document));
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Checks whether the client can do the command, if it handles it</summary>
        /// <param name="commandTag">Command to be done</param>
        /// <returns>True iff client can do the command</returns>
        public bool CanDoCommand(object commandTag)
        {
            bool          canDo = false;
            StoryDocument doc   = m_documentRegistry.ActiveDocument as StoryDocument;

            if (commandTag is StandardCommand)
            {
                if (doc != null)
                {
                    //switch ((StandardCommand)commandTag)
                    //{
                    //    case StandardCommand.EditUndo:
                    //        canDo = doc.Editor.CanUndo;
                    //        break;

                    //    case StandardCommand.EditRedo:
                    //        canDo = doc.Editor.CanRedo;
                    //        break;

                    //    case StandardCommand.EditCut:
                    //    case StandardCommand.EditDelete:
                    //        canDo = doc.Editor.HasSelection && !doc.Editor.ReadOnly;
                    //        break;

                    //    case StandardCommand.EditCopy:
                    //        canDo = doc.Editor.HasSelection;
                    //        break;

                    //    case StandardCommand.EditPaste:
                    //        canDo = doc.Editor.CanPaste;
                    //        break;
                    //}
                }
            }
            else if (commandTag is Command)
            {
                switch ((Command)commandTag)
                {
                case Command.Goto:
                case Command.FindReplace:
                    canDo = doc != null;
                    break;

                default:
                    canDo = true;
                    break;
                }
            }

            return(canDo);
        }
コード例 #4
0
        /// <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);
                StoryDocument storyDocument = (StoryDocument)document;
                if (storyDocument != null)
                {
                    storyDocument.Write();
                    writer.Write(storyDocument.DomNode, stream, uri);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Does the command</summary>
        /// <param name="commandTag">Command to be done</param>
        public void DoCommand(object commandTag)
        {
            StoryDocument activeDocument = m_documentRegistry.ActiveDocument as StoryDocument;

            if (commandTag is StandardCommand)
            {
                //switch ((StandardCommand)commandTag)
                //{
                //    case StandardCommand.EditUndo:
                //        activeDocument.Editor.Undo();
                //        break;

                //    case StandardCommand.EditRedo:
                //        activeDocument.Editor.Redo();
                //        break;

                //    case StandardCommand.EditCut:
                //        activeDocument.Editor.Cut();
                //        break;

                //    case StandardCommand.EditCopy:
                //        activeDocument.Editor.Copy();
                //        break;

                //    case StandardCommand.EditPaste:
                //        activeDocument.Editor.Paste();
                //        break;

                //    case StandardCommand.EditDelete:
                //        activeDocument.Editor.Delete();
                //        break;
                //}
            }
            else if (commandTag is Command)
            {
                switch ((Command)commandTag)
                {
                    //case Command.FindReplace:
                    //    activeDocument.Editor.ShowFindReplaceForm();
                    //    break;

                    //case Command.Goto:
                    //    activeDocument.Editor.ShowGoToLineForm();
                    //    break;
                }
            }
        }
コード例 #6
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.storyType.Type, Schema.storyRootElement);
            }

            StoryDocument document = null;

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

                // set document URI
                document = node.As <StoryDocument>();
                document.Init(uri);
                document.Read();

                // show the ListView control
                m_controlHostService.RegisterControl(document.Control, document.ControlInfo, this);
            }

            return(document);
        }
コード例 #7
0
 public StoryTextEditor(StoryDocument document)
 {
     m_Document = document;
     m_Control = new StoryTextEditorControl(this);
 }
コード例 #8
0
        /// <summary>
        /// Makes the document visible to the user</summary>
        /// <param name="document">Document to show</param>
        public void Show(IDocument document)
        {
            StoryDocument doc = document.As <StoryDocument>();

            m_controlHostService.Show(doc.Control);
        }
コード例 #9
0
 public StoryTextEditor(StoryDocument document)
 {
     m_Document = document;
     m_Control  = new StoryTextEditorControl(this);
 }