Example #1
0
        /// <summary>
        /// Does a command</summary>
        /// <param name="commandTag">Command</param>
        public virtual void DoCommand(object commandTag)
        {
            var iconClicked = false;

            if ((CommandService != null) && (CommandService is CommandServiceBase))
            {
                var commandServiceBase = CommandService as CommandServiceBase;
                iconClicked = commandServiceBase.IconClicked;
            }

            if ((commandTag is RecentDocumentInfo) && (!iconClicked))
            {
                // User clicked on a document in the MRU to open it.
                var       info     = (RecentDocumentInfo)commandTag;
                IDocument document = null;
                // info.Type is a user-readable string, so it may have been localized and so no
                //  longer matches. Try to find the client by matching the file extension.
                IDocumentClient client = FindClientFromUri(info.Uri);
                if (client != null && client.CanOpen(info.Uri))
                {
                    document = m_documentService.OpenExistingDocument(client, info.Uri);
                }

                // To-do: If the document can't be opened, it would probably be better to keep the
                //  document in the list and have a context menu command for removing the link, like
                //  Microsoft Word does.
                if (document == null &&
                    System.Diagnostics.Debugger.IsAttached == false)
                {
                    RemoveDocument(info);
                }
            }
            else
            {
                // User either clicked on the Pin command directly, or clicked the pin icon on a document
                // entry in the MRU. Either way, treat this as a Pin command.
                RecentDocumentInfo info;
                if (commandTag is RecentDocumentInfo)
                {
                    info = (RecentDocumentInfo)commandTag;
                }
                else
                {
                    info = GetActiveRecentDocumentInfo();
                }

                if (info != null)
                {
                    info.Pinned = !info.Pinned;
                }
            }
        }
Example #2
0
        // 'Safe' in the sense that all exceptions are caught (and reported via OnOpenException).
        private IDocument SafeOpen(IDocumentClient client, Uri uri)
        {
            IDocument document = null;

            try
            {
                if (client.CanOpen(uri))
                {
                    if (OnDocumentOpening(uri))
                    {
                        document = client.Open(uri);
                        if (document != null)
                        {
                            OnDocumentOpened(document);
                            DocumentOpened.Raise(this, new DocumentEventArgs(document, DocumentEventType.Opened));

                            DocumentRegistry.ActiveDocument = document;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // DAN: Added this - if an exception occurs during line:
                // DocumentRegistry.ActiveDocument = document;
                // then we need to remove it
                if (DocumentRegistry.ActiveDocument == document)
                {
                    DocumentRegistry.Remove(document);
                }

                document = null;

                // Let's share the exception directly. We used to wrap it in another Exception
                //  object but this hides the actual exception in the error dialog.
                OnOpenException(ex);
            }

            return(document);
        }
        // 'Safe' in the sense that all exceptions are caught (and reported via OnOpenException).
        private IDocument SafeOpen(IDocumentClient client, Uri uri)
        {
            IDocument document = null;
            try
            {
                if (client.CanOpen(uri))
                {
                    if (OnDocumentOpening(uri))
                    {
                        document = client.Open(uri);
                        if (document != null)
                        {
                            OnDocumentOpened(document);
                            DocumentOpened.Raise(this, new DocumentEventArgs(document, DocumentEventType.Opened));

                            DocumentRegistry.ActiveDocument = document;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // DAN: Added this - if an exception occurs during line:
                // DocumentRegistry.ActiveDocument = document; 
                // then we need to remove it
                if (DocumentRegistry.ActiveDocument == document)
                    DocumentRegistry.Remove(document);

                document = null;

                // Let's share the exception directly. We used to wrap it in another Exception
                //  object but this hides the actual exception in the error dialog.
                OnOpenException(ex);
            }

            return document;
        }