Exemplo n.º 1
0
 private bool OnDelDocumentCommandCanExecute(IPackageDocumentViewModel document)
 {
     if (string.IsNullOrEmpty(CurrentPackagePath))
     {
         return(false);
     }
     return(ShellService.CouldDeleteDocument(document));
 }
Exemplo n.º 2
0
        void OpenMetaFile(string fileName, bool addToRecentFile)
        {
            if (!ShellService.Clear())
            {
                Log.Info("Open File Canceled");
                return;
            }
            //if (!string.IsNullOrEmpty(ShellService.CurrentPackagePath))
            //{
            //    GloableCommands.NewCommand.Execute(null);
            //}

            if (GloableStaticInstanse.AppStatus != AppStatus.StaringAndOpeningPackage)
            {
                GloableStaticInstanse.AppStatus = AppStatus.OpeningPackage;
            }
            bool measureTime = false;

            if (!GloableStaticInstanse.StopWatch.IsRunning)
            {
                GloableStaticInstanse.StopWatch.Restart();
                measureTime = true;
            }
            CurrentPackagePath = fileName;
            string openMessage = Resources.OpenMessage;

            ShellService.Messager.WaitMessage.Show(openMessage);
            //TODO:
            // try
            {
                OpenPackage(fileName);
                if (addToRecentFile)
                {
                    AddToRecentFiles(fileName);
                }
            }

            //catch (Exception e1)
            //{
            //    MessageBox.Show("Could not Open File: " + e1.Message + e1.StackTrace);
            //    ExceptionMessage.ShowExceptionMessage(e1);
            //}
            // finally
            {
                //try
                {
                    ShellService.Messager.WaitMessage.Hide();
                }
                //catch (Exception e)
                //{
                //    MessageBox.Show(e.Message);
                //}
            }
            if (measureTime)
            {
                string message = string.Format(Properties.Resources.FileOpenTimeFormat, GloableStaticInstanse.StopWatch.ElapsedMilliseconds);
                Log.Info(message);
            }
            if (GloableStaticInstanse.AppStatus != AppStatus.StaringAndOpeningPackage)
            {
                GloableStaticInstanse.AppStatus = AppStatus.Running;
            }
        }
Exemplo n.º 3
0
        void OpenPackage(string packageFilePath)
        {
            if (!File.Exists(packageFilePath))
            {
                Log.Error("File Not Exist!");
                return;
            }
            _oderOpenDocumentItemList.Clear();
            int oderOpenDocumentItemNum = 0;
            var shellService            = ((ShellService)(ShellService));

            using (Package package = Package.Open(packageFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                //_EventAggregator.GetEvent<PackageBeforeOpenEvent>().Publish(package);
                PackageBeforeOpenEvent.SendWith(package);
                //load documents unopen
                var packageRelationShipDocumentsUnopen = package.GetRelationship(Package_DocumentsUnopen_ID);
                var layoutPartDocumentsUnopen          = package.GetPart(packageRelationShipDocumentsUnopen.TargetUri);
                var xmlSerilalizer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection <DocumentUnopen>));
                var unopenDocs     = xmlSerilalizer.Deserialize(layoutPartDocumentsUnopen.GetStream()) as ObservableCollection <DocumentUnopen>;
                if (unopenDocs != null)
                {
                    foreach (var item in unopenDocs)
                    {
                        shellService.DocumentsUnopen.Add(item);
                        if (item.KeepAliveWhenClose)
                        {
                            _oderOpenDocumentItemList.Add(new OderOpenDocumentItem()
                            {
                                IsUnopenDoc        = true,
                                UnopenDocContentId = item.ContentId,
                                DocUnopen          = item
                            });
                        }
                    }
                }
                //load avalondock panel layout
                var layoutRelationShip = package.GetRelationship(Package_PanelLayoutPart_ID);
                var layoutPart         = package.GetPart(layoutRelationShip.TargetUri);
                var packageManger      = this.GetDependencyResolver().Resolve <DockingManager>();
                var layoutSerializer   = new XmlLayoutSerializer(packageManger);
                layoutSerializer.LayoutSerializationCallback += (s, e) =>
                {
                    //Get LayoutContentViewModel From Package
                    if (e.Model is LayoutAnchorable)
                    {
                        var layoutAnchorable = e.Model as LayoutAnchorable;
                        Debug.Assert(package != null, "package != null");
                        var contentViewModel = OpenPackageContent(package, e.Model.ContentId);
                        var toolViewModel    = contentViewModel as IToolViewModel;
                        System.Diagnostics.Debug.Assert(toolViewModel != null);
                        e.Content = contentViewModel;
                        if (!ShellService.Tools.Contains_CompareByReference(toolViewModel))
                        {
                            ShellService.Tools.Add(toolViewModel);
                        }
                        toolViewModel.IsSelected = layoutAnchorable.IsSelected;
                        toolViewModel.IsActive   = layoutAnchorable.IsActive;
                        toolViewModel.IsVisible  = layoutAnchorable.IsVisible;
                        System.Diagnostics.Debug.Assert(ShellService.Documents.Count == 0);//the code of the avalondock behave in this kind of behavior, and the whole application assume the tools are loaded first.
                        return;
                    }
                    else if (e.Model is LayoutDocument)
                    {
                        var layoutDocument = e.Model as LayoutDocument;

                        //var contentViewModel = Services.ShellService.OpenPackageContent(package, e.Model.ContentId) as IDocumentViewModel;
                        //e.Content = contentViewModel;
                        //if (!ShellService.Documents.Contains_CompareByReference(contentViewModel))
                        //{
                        //    ShellService.Documents.Add(contentViewModel);
                        //}
                        //contentViewModel.IsSelected = layoutDocument.IsSelected;
                        //contentViewModel.IsActive = layoutDocument.IsActive;

                        _oderOpenDocumentItemList.Add(new OderOpenDocumentItem()
                        {
                            Num = oderOpenDocumentItemNum, LayoutContent = layoutDocument
                        });
                        oderOpenDocumentItemNum++;
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        return;
                    }
                };

                layoutSerializer.Deserialize(layoutPart.GetStream());
                foreach (var item in _oderOpenDocumentItemList)
                {
                    if (!item.IsUnopenDoc)
                    {
                        //bug fix for avalondock start form 2.1.0, because the close() methord work like 2.0.0
                        //in 2.0.0 close(){
                        //ILayoutRoot root = base.Root;
                        //ILayoutContainer parentAsContainer = base.Parent;
                        //parentAsContainer.RemoveChild(this);
                        //if (root != null)
                        //{
                        //    root.CollectGarbage();
                        //}}
                        //if (item.LayoutContent.Parent != null)
                        //{
                        item.LayoutContent.Parent.RemoveChild(item.LayoutContent);
                        //}
                    }
                }
                //Order Open Document;
                _oderOpenDocumentItemList.Sort((item) =>
                {
                    string packagePartId;
                    string contentId     = null;
                    contentId            = item.IsUnopenDoc ? item.UnopenDocContentId : item.LayoutContent.ContentId;
                    Type packagePartType = ContentID_ToTypeAndPackagePartID(contentId, out packagePartId);
                    return(packagePartType.GetAttributeValue((DocumentOpenOrderAttribute a) => a.Value));
                });

                IDocumentViewModel lastActiveDocument = null;
                foreach (var doc in _oderOpenDocumentItemList)
                {
                    if (doc.IsUnopenDoc)
                    {
                        var contentViewModel  = OpenPackageContent(package, doc.UnopenDocContentId);
                        var documentViewModel = contentViewModel as IDocumentViewModel;
                        System.Diagnostics.Debug.Assert(documentViewModel != null);
                        doc.DocUnopen.DocClosedButAlive = documentViewModel;
                        doc.DocUnopen = null;
                    }
                    else
                    {
                        var contentViewModel  = OpenPackageContent(package, doc.LayoutContent.ContentId);
                        var documentViewModel = contentViewModel as IDocumentViewModel;
                        System.Diagnostics.Debug.Assert(documentViewModel != null);
                        doc.LayoutContentViewModel = documentViewModel;
                        ShellService.OpenDocument(documentViewModel);
                        if (doc.LayoutContent.IsLastFocusedDocument)
                        {
                            lastActiveDocument = doc.LayoutContentViewModel;
                        }
                    }
                }
                _oderOpenDocumentItemList.RemoveAll(x => x.IsUnopenDoc);
                _oderOpenDocumentItemList.Sort((item) => item.Num);

                for (int i = 0; i < _oderOpenDocumentItemList.Count; i++)
                {
                    int indexInShellDocuments = ShellService.Documents.IndexOf(_oderOpenDocumentItemList[i].LayoutContentViewModel);
                    if (i != indexInShellDocuments)
                    {
                        ShellService.Documents.Move(indexInShellDocuments, i);
                    }
                    _oderOpenDocumentItemList[i].LayoutContentViewModel = null;
                }
                if (lastActiveDocument != null)
                {
                    ShellService.ActivateDocument(lastActiveDocument);
                }
                PackageAfterOpenEvent.SendWith(package);
                _oderOpenDocumentItemList.Clear();
            }
        }
Exemplo n.º 4
0
 private void OnDelDocumentCommandExecute(IPackageDocumentViewModel document)
 {
     ShellService.DeleteDocument(document);
 }