private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var doc = CityDocument.New();

            if (DocumentManager.Switch(doc))
            {
                NewDocument();
            }
        }
        public static CityDocument Open(string fileName)
        {
            CityDocument doc = new CityDocument();

            doc.FileName = fileName;
            doc.HasFile  = true;
            doc.Content  = CityDistrict.LoadCml(fileName);
            doc.Snapshot();
            return(doc);
        }
        public static CityDocument New()
        {
            CityDocument doc = new CityDocument();

            doc.FileName = string.Empty;
            doc.HasFile  = false;
            doc.Content  = new CityDistrict();
            doc.Snapshot();
            return(doc);
        }
 public static bool Switch(CityDocument doc)
 {
     if (ActiveDocument.Modified)
     {
         bool save = false;
         if (Environment.OSVersion.Version.Major >= 6) // running in win7
         {
             var result = TaskDialog.Show("Save document", "CityGUI", "Current document has been modified. Do you want to save? ", TaskDialogButton.Yes | TaskDialogButton.No | TaskDialogButton.Cancel, TaskDialogIcon.SecurityWarning);
             if (result == Result.Yes)
             {
                 save = true;
             }
             else if (result == Result.Cancel)
             {
                 return(false);
             }
         }
         else // running in xp
         {
             var result = MessageBox.Show("Current document has been modified. Do you want to save? ", "CityGUI", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
             if (result == DialogResult.Yes)
             {
                 save = true;
             }
             else if (result == DialogResult.Cancel)
             {
                 return(false);
             }
         }
         if (save)
         {
             if (ActiveDocument.HasFile)
             {
                 ActiveDocument.Save();
             }
             else
             {
                 SaveFileDialog sfd = new SaveFileDialog();
                 sfd.Title  = "Save CityXML";
                 sfd.Filter = "CityXML File (*.cml)|*.cml";
                 if (sfd.ShowDialog() == DialogResult.OK)
                 {
                     ActiveDocument.SaveAs(sfd.FileName);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
     _activeDocument = doc;
     return(true);
 }
 private void Viewer_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         var files = (string[])e.Data.GetData(DataFormats.FileDrop);
         if (files[0].EndsWith("cml"))
         {
             var doc = CityDocument.Open(files[0]);
             if (DocumentManager.Switch(doc))
             {
                 NewDocument();
             }
         }
     }
 }
        private void openWithoutFactorsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open CityXML";
            ofd.Filter = "CityXML File (*.cml)|*.cml";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var doc = CityDocument.Open(ofd.FileName);
                if (DocumentManager.Switch(doc))
                {
                    NewDocument();
                }
            }
        }