Ejemplo n.º 1
0
        private bool OptionDifficultySettingChanged(OptionDifficultySetting value)
        {
            //save the change in the config file
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(c_configFile, FileMode.Create, isf))
                {
                    using (StreamWriter sr = new StreamWriter(isfs))
                    {
                        sr.WriteLine(value.ToString());
                    }
                }
            }

            // Show or hide UI elements appropriately
            if (m_workspace.Difficulty == OptionDifficultySetting.MaterialBalance)
            {
                Compounds_DF_TabControl.SelectedItem = DFAnalysisTab;
                CompoundTableTab.Visibility          = Visibility.Collapsed;
            }
            else
            {
                CompoundTableTab.Visibility = Visibility.Visible;
            }

            // Tell the control palette that the difficulty changed
            PrimaryPalette.RefreshPalette(value);

            return(true);
        }
Ejemplo n.º 2
0
        public MainPage()
        {
            // Required to initialize variables
            InitializeComponent();

            // Set the workspace for the equation editor and other controls
            m_workspace.Equations.Add(new ChemProV.Logic.Equations.EquationModel());
            WorkSpace.EquationEditor.SetWorkspace(m_workspace);
            WorkSpace.CommentsPane.SetWorkspace(m_workspace);
            m_workspace.DegreesOfFreedomAnalysis.PropertyChanged +=
                new PropertyChangedEventHandler(DegreesOfFreedomAnalysis_PropertyChanged);
            m_workspace.DegreesOfFreedomAnalysis.Comments.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(DFCommentsCollectionChanged);
            WorkSpace.SetWorkspace(m_workspace);
            CompoundTable.SetWorkspace(m_workspace);

            // Tell the palette control to update
            PrimaryPalette.RefreshPalette(m_workspace.Difficulty);

            // Monitor when the difficulty changes so we can update the config file
            m_workspace.PropertyChanged += delegate(object o, PropertyChangedEventArgs e)
            {
                if (e.PropertyName.Equals("Difficulty"))
                {
                    OptionDifficultySettingChanged(m_workspace.Difficulty);
                }
            };

            // Monitor when the comments pane visibility changes so we can update tooltips
            WorkSpace.PropertyChanged += delegate(object o, PropertyChangedEventArgs e)
            {
                if (e.PropertyName.Equals("CommentsPaneVisible"))
                {
                    ToolTipService.SetToolTip(CommentPaneButton, WorkSpace.CommentsPaneVisible ?
                                              "Hide comments pane" : "Show comments pane");
                }
            };

            if (Application.Current.IsRunningOutOfBrowser)
            {
                Install_Button.Click -= new RoutedEventHandler(InstallButton_Click);
                ButtonToolbar.Children.Remove(Install_Button);
            }

            this.Loaded += new RoutedEventHandler(LoadConfigFile);

            this.MouseLeftButtonDown  += new MouseButtonEventHandler(MainPage_MouseButton);
            this.MouseLeftButtonUp    += new MouseButtonEventHandler(MainPage_MouseButton);
            this.MouseRightButtonDown += new MouseButtonEventHandler(MainPage_MouseButton);
            this.MouseRightButtonUp   += new MouseButtonEventHandler(MainPage_MouseButton);

            if (App.Current.IsRunningOutOfBrowser)
            {
                App.Current.MainWindow.Closing += new EventHandler <ClosingEventArgs>(MainWindow_Closing);
            }

            //listen for selection changes in our children
            WorkSpace.ValidationChecked += new EventHandler(WorkSpace_ValidationChecked);

            CompoundTable.ConstantClicked += new EventHandler(CompoundTable_ConstantClicked);

            //setup timer
            saveTimer.Interval = autoSaveTimeSpan;
            saveTimer.Tick    += new EventHandler(autoSave);
            saveTimer.Start();

            //find our version number
            Assembly asm = Assembly.GetExecutingAssembly();

            if (asm.FullName != null)
            {
                AssemblyName assemblyName = new AssemblyName(asm.FullName);
                versionNumber = assemblyName.Version.ToString();
            }

            // Intialize the static App class
            Core.App.Init(this, PrimaryPalette);

            // Make sure that when the equation editor or compounds control gets focus that the
            // control palette switches back to select mode
            WorkSpace.EquationEditor.GotFocus += delegate(object sender, RoutedEventArgs e)
            {
                Core.App.ControlPalette.SwitchToSelect(false);
            };
            CompoundTable.GotFocus += delegate(object sender, RoutedEventArgs e)
            {
                Core.App.ControlPalette.SwitchToSelect(false);
            };

            // Show the debug tab if this is a debug build
#if DEBUG
            DebugTab.Visibility = System.Windows.Visibility.Visible;

            m_workspace.StreamsCollectionChanged      += new EventHandler(WorkspaceStreamsCollectionChanged);
            m_workspace.ProcessUnitsCollectionChanged += new EventHandler(WorkspaceProcessUnitsCollectionChanged);
#endif
        }
Ejemplo n.º 3
0
        private void OpenFileFromDisk()
        {
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter = c_loadFileFilter;
            bool?openFileResult = false;

            openFileResult = openDialog.ShowDialog();

            // Make sure that the user selected a file and clicked OK
            if (!openFileResult.HasValue || !openFileResult.Value)
            {
                return;
            }

            bool openFile = false;

            if (WorkSpace.DrawingCanvas.Children.Count > 0)
            {
                MessageBoxResult result = MessageBox.Show(
                    "Opening a new file will erase the current process flow diagram.  " +
                    "Click OK to continue or CANCEL to go back and save.  This action cannot be undone.",
                    "Open File Confirmation", MessageBoxButton.OKCancel);
                if (MessageBoxResult.OK == result)
                {
                    openFile = true;
                }
            }
            else
            {
                openFile = true;
            }

            if (openFile)
            {
                WorkSpace.DrawingCanvas.ClearDrawingCanvas();

                //delete the tempory file as they do not want it
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (isf.FileExists(c_autoSaveFileName))
                    {
                        isf.DeleteFile(c_autoSaveFileName);
                    }
                }

                // Put the file name info in the save button's tooltip
                ToolTipService.SetToolTip(SaveAsButton, "Save as... (file was opened as \"" +
                                          openDialog.File.Name + "\")");

                // Make sure we don't have a palette tool active
                PrimaryPalette.SwitchToSelect();

                FileStream fs;
                // Open the file for reading
                try
                {
                    fs = openDialog.File.OpenRead();
                }
                catch (Exception)
                {
                    MessageBox.Show("The specified file could not be opened");
                    return;
                }

                // This means we succeeded in opening the file for reading and writing
                LoadChemProVFile(fs);

                // We've loaded, so we're done with the stream
                fs.Dispose();
                fs = null;

                // Tell the drawing canvas to update stream positions now that everything is loaded
                WorkSpace.DrawingCanvas.UpdateAllStreamLocations();
            }
        }