コード例 #1
0
ファイル: Commands.cs プロジェクト: lonchak23/simpleCAD
        //=============================================================================
        protected override void _Execute(object parameter)
        {
            MainWindow_ViewModel vm = parameter as MainWindow_ViewModel;

            if (vm != null)
            {
                // Create OpenFileDialog
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

                // Set filter for file extension and default file extension
                dlg.DefaultExt = ".scad";
                dlg.Filter     = "SimpleCAD drawings (.scad)|*.scad";

                // Display OpenFileDialog by calling ShowDialog method
                Nullable <bool> result = dlg.ShowDialog();

                // Get the selected file name and display in a TextBox
                if (result == true)
                {
                    // save or create
                    FileStream fs = new FileStream(dlg.FileName, FileMode.Open);
                    if (fs != null)
                    {
                        BinaryFormatter bf    = new BinaryFormatter();
                        SimpleCAD_State state = (SimpleCAD_State)bf.Deserialize(fs);

                        Document newDoc = vm.DocManager.Add(dlg.FileName, state);
                        if (newDoc != null)
                        {
                            newDoc.IsSelected = true;
                        }
                    }
                }
            }
        }
コード例 #2
0
 public Document(DocumentManager docManager, string strPath, SimpleCAD_State state)
 {
     m_DocManager = docManager;
     Path         = strPath;
     if (state != null)
     {
         m_states.Add(state);
         m_CurrentStateIndex = 0;
     }
 }
コード例 #3
0
        public bool Save(string strNewPath)
        {
            string strPath = strNewPath;

            if (string.IsNullOrEmpty(strPath))
            {
                strPath = Path;
            }

            if (string.IsNullOrEmpty(strPath))
            {
                return(false);
            }

            if (m_states.Count == 0)
            {
                return(false);
            }

            //
            if (strPath != Path)
            {
                Path = strPath;
            }

            FileStream fs = new FileStream(Path, FileMode.OpenOrCreate);

            if (fs == null)
            {
                return(false);
            }

            SimpleCAD_State state = m_states[m_states.Count - 1];

            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, state);

            //
            if (m_states.Count > 1)
            {
                m_states.RemoveRange(0, m_states.Count - 1);
                m_CurrentStateIndex = 0;
            }

            NotifyPropertyChanged(() => DisplayName);
            NotifyPropertyChanged(() => ChangesCount);

            return(true);
        }
コード例 #4
0
 //=============================================================================
 public Document Add(string strPath, SimpleCAD_State state)
 {
     return(Add(new Document(this, strPath, state)));
 }