Example #1
0
 /// <summary>
 /// Returns a content view model for the specified contentID which needs to be displayed as a document
 /// The contentID is the ID used in AvalonDock
 /// </summary>
 /// <param name="contentId">The contentID which needs to be displayed as a document in Wider</param>
 /// <returns>The content view model for the given info</returns>
 public ContentViewModel GetViewModelFromContentId(String contentId)
 {
     for (Int32 i = ContentHandlers.Count - 1; i >= 0; i--)
     {
         IContentHandler opener = ContentHandlers[i];
         if (opener.ValidateContentFromId(contentId))
         {
             ContentViewModel vm = opener.OpenContentFromId(contentId);
             vm.Handler = opener;
             return(vm);
         }
     }
     return(null);
 }
Example #2
0
 /// <summary>
 /// Returns a content view model for the specified object which needs to be displayed as a document
 /// The object could be anything - based on the handlers, a content view model is returned
 /// </summary>
 /// <param name="info">The object which needs to be displayed as a document in Wider</param>
 /// <returns>The content view model for the given info</returns>
 public ContentViewModel GetViewModel(Object info)
 {
     for (Int32 i = ContentHandlers.Count - 1; i >= 0; i--)
     {
         IContentHandler opener = ContentHandlers[i];
         if (opener.ValidateContentType(info))
         {
             ContentViewModel vm = opener.OpenContent(info);
             vm.Handler = opener;
             return(vm);
         }
     }
     return(null);
 }
Example #3
0
        /// <summary>
        /// Opens the contentID
        /// </summary>
        /// <param name="contentID">The contentID to open</param>
        /// <param name="makeActive">if set to <c>true</c> makes the new document as the active document.</param>
        /// <returns>A document which was added to the workspace as a content view model</returns>
        public ContentViewModel OpenFromID(String contentID, Boolean makeActive = false)
        {
            //Let the handler figure out which view model to return
            ContentViewModel openValue = _handler.GetViewModelFromContentId(contentID);

            if (openValue != null)
            {
                //Check if the document is already open
                foreach (ContentViewModel contentViewModel in _workspace.Documents)
                {
                    if (contentViewModel.Model.Location != null)
                    {
                        if (contentViewModel.Model.Location.Equals(openValue.Model.Location))
                        {
                            _logger.Log($"Document {contentViewModel.Model.Location} already open.",
                                        Category.Info, Priority.Low);

                            if (makeActive)
                            {
                                _workspace.ActiveDocument = contentViewModel;
                            }

                            return(contentViewModel);
                        }
                    }
                }

                _logger.Log($"Opening content with {contentID} !!", Category.Info, Priority.Low);

                // Publish the event to the Application - subscribers can use this object
                _eventAggregator.GetEvent <OpenContentEvent>().Publish(openValue);

                _workspace.Documents.Add(openValue);

                if (makeActive)
                {
                    _workspace.ActiveDocument = openValue;
                }

                //Add it to the recent documents opened
                _recentSettings.Update(openValue);

                return(openValue);
            }

            _logger.Log($"Unable to find a IContentHandler to open content with ID = {contentID}",
                        Category.Warn, Priority.High);
            return(null);
        }
Example #4
0
        private void NewDocument()
        {
            if (_workspace == null)
            {
                _workspace = _container.Resolve <IWorkspace>();
            }

            if (_availableNewContent.Count == 1)
            {
                IContentHandler  handler   = _dictionary[_availableNewContent[0]];
                ContentViewModel openValue = handler.NewContent(_availableNewContent[0]);
                _workspace.Documents.Add(openValue);
                _workspace.ActiveDocument = openValue;
            }
            else
            {
                INewFileWindow window = _container.Resolve <INewFileWindow>();
                if (window == null)
                {
                    return;
                }
                Brush backup = _statusBar.Background;
                _statusBar.Background = _newBackground;
                _statusBar.Text       = "Select a new file";
                //if (Application.Current.MainWindow is MetroWindow)
                //{
                //    window.Resources = Application.Current.MainWindow.Resources;
                //    Window win = Application.Current.MainWindow as MetroWindow;
                //    window.Resources = win.Resources;
                //    //window.GlowBrush = win.GlowBrush;
                //    //window.TitleForeground = win.TitleForeground;
                //}
                window.DataContext = _availableNewContent;
                if (window.ShowDialog() == true)
                {
                    NewContentAttribute newContent = window.NewContent;
                    if (newContent != null)
                    {
                        IContentHandler  handler   = _dictionary[newContent];
                        ContentViewModel openValue = handler.NewContent(newContent);
                        _workspace.Documents.Add(openValue);
                        _workspace.ActiveDocument = openValue;
                    }
                }
                _statusBar.Background = backup;
                _statusBar.Clear();
            }
        }
Example #5
0
        /// <summary>
        /// Opens the object - if object is null, show a open file dialog to select a file to open
        /// </summary>
        /// <param name="location">The optional object to open</param>
        /// <returns>A document which was added to the workspace as a content view model</returns>
        public ContentViewModel Open(Object location = null)
        {
            Boolean?         result;
            ContentViewModel returnValue = null;

            if (location == null)
            {
                _dialog.Filter = "";
                String sep = "";
                List <FileContentAttribute> attributes =
                    _handler.ContentHandlers.SelectMany(
                        handler =>
                        (FileContentAttribute[])
                        (handler.GetType()).GetCustomAttributes(typeof(FileContentAttribute), true)).ToList();
                attributes.Sort((attribute, contentAttribute) => attribute.Priority - contentAttribute.Priority);
                foreach (FileContentAttribute contentAttribute in attributes)
                {
                    _dialog.Filter = String.Format("{0}{1}{2} ({3})|{3}", _dialog.Filter, sep, contentAttribute.Display,
                                                   contentAttribute.Extension);
                    sep = "|";
                }

                result   = _dialog.ShowDialog();
                location = _dialog.FileName;
            }
            else
            {
                result = true;
            }

            if (result == true && !String.IsNullOrWhiteSpace(location.ToString()))
            {
                //Let the handler figure out which view model to return
                if (_handler != null)
                {
                    ContentViewModel openValue = _handler.GetViewModel(location);

                    if (openValue != null)
                    {
                        //Check if the document is already open
                        foreach (ContentViewModel contentViewModel in _workspace.Documents)
                        {
                            if (contentViewModel.Model.Location != null)
                            {
                                if (contentViewModel.Model.Location.Equals(openValue.Model.Location))
                                {
                                    _logger.Log(
                                        $"Document {contentViewModel.Model.Location} already open - making it active",
                                        Category.Info, Priority.Low);
                                    _workspace.ActiveDocument = contentViewModel;
                                    return(contentViewModel);
                                }
                            }
                        }

                        _logger.Log("Opening file" + location + " !!", Category.Info, Priority.Low);

                        // Publish the event to the Application - subscribers can use this object
                        _eventAggregator.GetEvent <OpenContentEvent>().Publish(openValue);

                        //Add it to the actual workspace
                        _workspace.Documents.Add(openValue);

                        //Make it the active document
                        _workspace.ActiveDocument = openValue;

                        //Add it to the recent documents opened
                        _recentSettings.Update(openValue);

                        returnValue = openValue;
                    }
                    else
                    {
                        _logger.Log("Unable to find a IContentHandler to open " + location, Category.Warn, Priority.High);
                    }
                }
            }
            else
            {
                _logger.Log("Canceled out of open file dialog", Category.Info, Priority.Low);
            }
            return(returnValue);
        }