Ejemplo n.º 1
0
        /// <summary>
        /// Update the canvas with the content of the XML editor/view
        /// (updates from canvas to viewmodel are initiated in the <seealso cref="XmlView"/> class).
        /// </summary>
        /// <param name="p"></param>
        private void OnUpdateDesignerCommand_Execute(object p)
        {
            try
            {
                // Look-up plugin model
                string          plugin = this.DocumentViewModel.dm_DocumentDataModel.PluginModelName;
                PluginModelBase m      = PluginManager.GetPluginModel(plugin);

                // Look-up shape converter
                UmlTypeToStringConverterBase conv = null;
                conv = m.ShapeConverter;

                // Convert Xml document into a list of shapes and page definition
                List <ShapeViewModelBase> coll;
                PageViewModelBase         page = conv.ReadDocument(this.Document.Text,
                                                                   this.DocumentViewModel.vm_CanvasViewModel, out coll);

                // Apply new page and shape definitions to data model
                this.DocumentViewModel.dm_DocumentDataModel.LoadFileFromCollection(page, coll);
            }
            catch (Exception exp)
            {
                this.XmlStatusMessage = string.Format("The document is in an invalid state: '{0}'.", exp.Message);
                this.DocumentViewModel.dm_DocumentDataModel.State = DataModel.ModelState.Invalid;
                //// TODO XXX this.DocumentViewModel.dm_DocumentDataModel.DocumentRoot = new XElement("InvalidDocument");
            }
        }
Ejemplo n.º 2
0
        /*/ <summary>
         * /// This property is inherited from an abstract property
         * /// but does not make sense for this class - we therefore throw an error here.
         * /// </summary>
         * public override string TypeKey
         * {
         * get
         * {
         *  throw new NotImplementedException();
         * }
         * }
         */
        #endregion properties

        #region methods
        /// <summary>
        /// Persist an Xml document and its content into an XML formated string.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="docRoot"></param>
        /// <returns></returns>
        public static string Write(PageViewModelBase root,
                                   IEnumerable <ShapeViewModelBase> docRoot)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent              = true;
            settings.IndentChars         = "  "; // 2 spaces as indentation
            settings.NewLineOnAttributes = true;

            try
            {
                using (var sw = new StringWriter())
                {
                    using (XmlWriter writer = XmlWriter.Create(sw, settings))
                    {
                        root.SaveDocument(writer, docRoot);
                    }

                    return(sw.ToString());
                }
            }
            catch (Exception e)
            {
                throw new Exception("An exception occured when writing XML.", e);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Save the current content of the document into a file on the file system
 /// (this inlcudes all children if any).
 /// </summary>
 /// <param name="filename"></param>
 public bool SaveDocument(
     string filename,
     ObservableCollection <ShapeViewModelBase> docRoot
     )
 {
     return(PageViewModelBase.Write(filename, this, docRoot));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Paste element from windows clipboard into current selection on to the canvas.
        /// </summary>
        private void OnPasteCommand_Executed()
        {
            try
            {
                string xmlDocument = Clipboard.GetText();

                if (string.IsNullOrEmpty(xmlDocument) == true)
                {
                    return;
                }

                // Look-up plugin model
                string          plugin = this.DocumentViewModel.dm_DocumentDataModel.PluginModelName;
                PluginModelBase m      = PluginManager.GetPluginModel(plugin);

                // Look-up shape converter
                UmlTypeToStringConverterBase conv = null;
                conv = m.ShapeConverter;

                List <ShapeViewModelBase> coll;
                // Convert Xml document into a list of shapes and page definition
                PageViewModelBase page = conv.ReadDocument(xmlDocument,
                                                           this.DocumentViewModel.vm_CanvasViewModel, out coll);

                if (coll == null)
                {
                    return;
                }

                if (coll.Count == 0)
                {
                    return;
                }

                this.DocumentViewModel.dm_DocumentDataModel.BeginOperation("PasteCommandModel.OnExecute");

                _SelectedItem.Clear();
                foreach (var shape in coll)
                {
                    this.DocumentViewModel.dm_DocumentDataModel.AddShape(shape);
                    _SelectedItem.Add(shape);
                }

                this.DocumentViewModel.dm_DocumentDataModel.EndOperation("PasteCommandModel.OnExecute");
            }
            catch
            {
                var msgBox = ServiceLocator.Current.GetInstance <IMessageBoxService>();

                msgBox.Show(MiniUML.Framework.Local.Strings.STR_MSG_NoShapeInClipboard,
                            MiniUML.Framework.Local.Strings.STR_UnexpectedErrorCaption,
                            MsgBoxButtons.OK, MsgBoxImage.Warning);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Load the contents of a file from the windows file system into memory and display it.
        /// </summary>
        /// <param name="filename"></param>
        public override void LoadFile(string filename)
        {
            // Look-up plugin model
            string          plugin = this.dm_DocumentDataModel.PluginModelName;
            PluginModelBase m      = PluginManager.GetPluginModel(plugin);

            // Look-up shape converter
            UmlTypeToStringConverterBase conv = null;

            conv = m.ShapeConverter;

            // Convert Xml document into a list of shapes and page definition
            List <ShapeViewModelBase> coll;
            PageViewModelBase         page = conv.LoadDocument(filename, this.mCanvasViewModel, out coll);

            // Apply new page and shape definitions to data model
            this.mDataModel.LoadFileFromCollection(page, coll);

            this.prop_DocumentFilePath = filename;
            this.vm_CanvasViewModel.SelectedItem.Clear();
        }
Ejemplo n.º 6
0
            public override void OnExecute(object sender, ExecutedRoutedEventArgs e)
            {
                // Save changes before closing current document?
                if (this.mViewModel.QuerySaveChanges() == false)
                {
                    return;
                }

                Size currentPageSize = this.mViewModel.dm_DocumentDataModel.PageSize;

                Thickness currentPageMargins = this.mViewModel.dm_DocumentDataModel.PageMargins;

                // Create NewDocumentWindow
                IFactory newDocumentWindowFactory = Application.Current.Resources["NewDocumentWindowFactory"] as IFactory;
                Window   newDocumentWindow        = newDocumentWindowFactory.CreateObject(_MsgBox) as Window;

                // Configure window.
                PageViewModelBase newDocumentWindowViewModel = new PageViewModelBase()
                {
                    prop_PageSize    = currentPageSize,
                    prop_PageMargins = currentPageMargins
                };

                newDocumentWindow.DataContext = newDocumentWindowViewModel;
                newDocumentWindow.Owner       = Application.Current.MainWindow;

                // Show window; return if canceled.
                if (!newDocumentWindow.ShowDialog().GetValueOrDefault())
                {
                    return;
                }

                // Create document.
                newDocumentWindow.DataContext         = null;
                this.mViewModel.prop_DocumentFilePath = null;
                this.mViewModel.vm_CanvasViewModel.SelectedItem.Clear();
                this.mViewModel._DataModel.New(newDocumentWindowViewModel);
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="copyThis"></param>
        public PageViewModelBase(PageViewModelBase copyThis)
            : this()
        {
            if (copyThis == null)
            {
                return;
            }

            if (copyThis.mElements != null)
            {
                this.mElements = new ObservableCollection <ShapeViewModelBase>(copyThis.mElements);
            }

            if (copyThis.mPageMargins != null)
            {
                this.mPageMargins = new Thickness(copyThis.mPageMargins.Left, copyThis.mPageMargins.Top,
                                                  copyThis.mPageMargins.Right, copyThis.mPageMargins.Bottom);
            }

            if (copyThis.mPageSize != null)
            {
                this.mPageSize = new Size(copyThis.mPageSize.Width, copyThis.mPageSize.Height);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Persist an Xml document and its content into
        /// an XML formated text file.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="docRoot"></param>
        /// <returns></returns>
        public static bool Write(string filePathName,
                                 PageViewModelBase root,
                                 IEnumerable <ShapeViewModelBase> docRoot)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent              = true;
            settings.IndentChars         = "  "; // 2 spaces as indentation
            settings.NewLineOnAttributes = true;

            try
            {
                using (XmlWriter writer = XmlWriter.Create(filePathName, settings))
                {
                    root.SaveDocument(writer, docRoot);
                }

                return(true);
            }
            catch (Exception e)
            {
                throw new Exception("An error occured when writing XML.", e);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Save the current content of the document as XML string
 /// (this inlcudes all children if any).
 /// </summary>
 /// <returns></returns>
 public string SaveDocument(IEnumerable <ShapeViewModelBase> mDocRoot)
 {
     return(PageViewModelBase.Write(this, mDocRoot));
 }