Ejemplo n.º 1
0
        /// <summary>
        /// Serialize a new map or update if already exists
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="fileName"></param>
        private void SerializeMapCreateOrUpdate(PersistentTree tree, string fileName)
        {
            var fileMode = FileMode.OpenOrCreate;

            using (var fileStream = new FileStream(fileName, fileMode))
            {
                using (var zip = new ZipArchive(fileStream, ZipArchiveMode.Update))
                {
                    zip.GetEntry(MAPXMLFILE)?.Delete();

                    foreach (var a in tree.DeletedLargeObjects)
                    {
                        zip.GetEntry(a)?.Delete();
                    }

                    foreach (var o in tree.NewLargeObjects)
                    {
                        var objectEntry = zip.CreateEntry(o.Key, CompressionLevel.NoCompression);
                        using (Stream stream = objectEntry.Open()) o.Value.SaveToStream(stream);
                    }

                    var xmlEntry = zip.CreateEntry(MAPXMLFILE, CompressionLevel.NoCompression);
                    using (Stream stream = xmlEntry.Open())
                    {
                        new MindMapSerializer().Serialize(stream, tree);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mapView">Must not be null</param>
 /// <param name="tree"></param>
 public Tab(MapView mapView, PersistentTree tree)
     : base(mapView.Canvas)
 {
     Tree = tree;
     MapView = mapView;
     tree.DirtyChanged += Tree_DirtyChanged;
 }
Ejemplo n.º 3
0
 private void PersistenceManager_CurrentTreeChanged(PersistenceManager manager, PersistentTree oldTree, PersistentTree newTree)
 {
     if (oldTree != null)
     {
         Unregister(oldTree.Tree);
     }
     if (newTree != null)
     {
         Register(newTree.Tree);
     }
 }
Ejemplo n.º 4
0
 public void SerializeMap(PersistentTree tree, string fileName, bool overwrite)
 {
     if (overwrite)
     {
         SerializeMapOverwrite(tree, fileName);
     }
     else
     {
         SerializeMapCreateOrUpdate(tree, fileName);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Serialize a new map or overwrite if file already exists
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="fileName"></param>
        private void SerializeMapOverwrite(PersistentTree tree, string fileName)
        {
            var fileMode = FileMode.Create;

            using (var fileStream = new FileStream(fileName, fileMode))
            {
                using (var zip = new ZipArchive(fileStream, ZipArchiveMode.Update))
                {
                    foreach (var o in tree.LargeObjectsDictionary)
                    {
                        var objectEntry = zip.CreateEntry(o.Key, CompressionLevel.NoCompression);
                        using (Stream stream = objectEntry.Open()) o.Value.SaveToStream(stream);
                    }

                    var xmlEntry = zip.CreateEntry(MAPXMLFILE, CompressionLevel.NoCompression);
                    using (Stream stream = xmlEntry.Open())
                    {
                        new MindMapSerializer().Serialize(stream, tree);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Method which actually saves the file to disk. Other methods like SaveAsMap and SaveMap invoke this.
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="fileName"></param>
        private void SaveMapInternal(PersistentTree tree, string fileName = null)
        {
            Debug.Assert(tree.FileName != null || fileName != null, "Saving: Missing file name.");

            noteCrtl.UpdateNodeFromEditor();

            if (tree != null)
            {
                if (fileName == null)
                {
                    tree.Save();
                }
                else
                {
                    tree.Save(fileName);
                }

                MetaModel.MetaModel.Instance.RecentFiles.Add(tree.FileName);
            }
        }
Ejemplo n.º 7
0
        private ContinueOperation PromptForUnsavedChanges(PersistentTree tree)
        {
            if (tree.IsDirty)
            {
                DialogResult result = MessageBox.Show("Do you want to save changes?", "Unsaved Changes",
                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
                switch (result)
                {
                    case DialogResult.Yes:
                        SaveMap(tree);
                        break;
                    case DialogResult.Cancel:
                        return ContinueOperation.Cancel;
                }
            }

            return ContinueOperation.Continue;
        }
Ejemplo n.º 8
0
 public void SaveMap(PersistentTree tree)
 {
     if (tree != null)
     {
         if (tree.IsNewMap)
         {
             SaveAsMap(tree);
         }
         else
         {
             SaveMapInternal(tree);
         }
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="tree">should not be null</param>
 public void SaveAsMap(PersistentTree tree)
 {
     SaveFileDialog file = new SaveFileDialog();
     file.AddExtension = true;
     file.DefaultExt = "mm";
     file.Filter = "MindMap files (*.mm)|*.mm|All files (*.*)|*.*|Text (*.txt)|*.txt";
     file.InitialDirectory = Path.GetDirectoryName(PersistenceManager.CurrentTree.FileName);
     file.FileName = tree.IsNewMap? CurrentMapCtrl.MapView.Tree.RootNode.Text : PersistenceManager.CurrentTree.FileName;
     if (file.ShowDialog() == DialogResult.OK)
     {
         SaveMapInternal(tree, file.FileName);
     }
     mainForm.EditorTabs.UpdateAppTitle();
 }
Ejemplo n.º 10
0
 private void Tree_DirtyChanged(PersistentTree tree)
 {
     UpdateTitle();
 }