예제 #1
0
        private Boolean SaveModel(bool showSaveAsDialog)
        {
            Boolean saved = false;

            if(Directory.Exists(this.appSettings.ModelFilePath))
            {
                saveModelFileDialog.InitialDirectory = this.appSettings.ModelFilePath;
            }

            if(showSaveAsDialog)
            {
                // [Save Model As]
                saveModelFileDialog.Title = this.localizer.GetValue("UserMessages","saveModelAs");
                saveModelFileDialog.FileName = ((this.modelFileName == string.Empty)
                    ? model.Name : Path.GetFileNameWithoutExtension(this.modelFileName));
                if(saveModelFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    this.appSettings.AddToRecentFileList(saveModelFileDialog.FileName);
                    this.UpdateRecentFileList();

                    UCMDocument ucmdoc = new UCMDocument();
                    ucmdoc.Model = model;
                    ucmdoc.Version = this.GetType().Assembly.GetName().Version.ToString(2);
                    XmlSerializer s = new XmlSerializer(typeof(UCMDocument));
                    TextWriter w = new StreamWriter(saveModelFileDialog.FileName);
                    s.Serialize(w, ucmdoc);
                    w.Close();

                    this.appSettings.ModelFilePath = Path.GetDirectoryName(saveModelFileDialog.FileName);
                    this.modelFilePath = Path.GetDirectoryName(saveModelFileDialog.FileName);
                    this.modelFileName = Path.GetFileName(saveModelFileDialog.FileName);
                    this.SetModified(false);
                    saved = true;
                }
            }
            else
            {
                UCMDocument ucmdoc = new UCMDocument();
                ucmdoc.Model = model;
                ucmdoc.Version = this.GetType().Assembly.GetName().Version.ToString(2);
                XmlSerializer s = new XmlSerializer(typeof(UCMDocument));
                TextWriter w = new StreamWriter(Path.Combine(this.modelFilePath, this.modelFileName));
                s.Serialize(w, ucmdoc);
                w.Close();
                this.SetModified(false);
                saved = true;
            }

            // Cambia il titolo della finestra
            int sub = this.Text.IndexOf("-");
            if(sub != -1)
            {
                this.Text = this.Text.Substring(0,sub - 1) + " - " + this.modelFileName;
            }
            else
            {
                this.Text += " - " + this.modelFileName;
            }

            return saved;
        }
예제 #2
0
        /**
         * @brief Gestione del modello
         *
         * Apre un modello da file sulla base della selezione utente
         * dal menu File - elementi recenti
         *
         * @note Il metodo richiama this::CloseModel nel caso
         * in cui vi sia un modello già in uso che necessita
         * di essere salvato
         */
        private void OpenRecentModel(string modelFilePath)
        {
            UCMDocument ucmdoc = new UCMDocument();;

            this.CloseModel();

            if(!File.Exists(modelFilePath))
            {
                MessageBox.Show(this,this.localizer.GetValue("UserMessages","cannotOpenFile"));
                return;
            }

            this.appSettings.ModelFilePath = Path.GetDirectoryName(modelFilePath);
            this.modelFilePath = Path.GetDirectoryName(modelFilePath);
            this.modelFileName = Path.GetFileName(modelFilePath);

            System.Char [] separators = {' ','\r','\n',',','.','-','+','\\','\'','?','!'};
            foreach(System.Char c in separators)
            {
                this.separators.Add(c);
            }

            this.hdc.Clear();

            this.LockModified();
            Win32.SendMessage(frmModelBrowser.tvModelBrowser.Handle,Win32.WM_SETREDRAW,0,(IntPtr)0);
            this.Cursor = Cursors.WaitCursor;
            try
            {
                XmlSerializer s = new XmlSerializer(typeof(UCMDocument));
                TextReader r = new StreamReader(modelFilePath);
                ucmdoc = (UCMDocument)s.Deserialize(r);
                r.Close();
                model = ucmdoc.Model;
                BuildView(model);
            }
            catch(XmlException e)
            {
                MessageBox.Show(this,e.Message,Application.ProductName);
                this.NewModel();
            }

            Win32.SendMessage(frmModelBrowser.tvModelBrowser.Handle,Win32.WM_SETREDRAW,1,(IntPtr)0);
            frmModelBrowser.tvModelBrowser.Invalidate();

            this.UnlockModified();
            this.Cursor = Cursors.Default;

            // Cambia il titolo della finestra
            int sub = this.Text.IndexOf("-");
            if(sub != -1)
            {
                this.Text = this.Text.Substring(0,sub - 1) + " - " + this.modelFileName;
            }
            else
            {
                this.Text += " - " + this.modelFileName;
            }

            this.SetModified(false);

            this.TestVersion(ucmdoc.Version);
        }