Exemple #1
0
        private async void LoadFile(string fileName)
        {
            CloseAllModuleDialogs();
            CloseHistoryWindow();
            CloseNotesWindow();
            theNeuronArrayView.theSelection.selectedRectangles.Clear();
            CloseAllModuleDialogs();
            SuspendEngine();

            bool success = false;
            await Task.Run(delegate { success = XmlFile.Load(ref theNeuronArray, fileName); });

            if (!success)
            {
                CreateEmptyNetwork();
                Properties.Settings.Default["CurrentFile"] = currentFileName;
                Properties.Settings.Default.Save();
                return;
            }
            currentFileName = fileName;

            if (XmlFile.CanWriteTo(currentFileName))
            {
                SaveButton.IsEnabled = true;
            }
            else
            {
                SaveButton.IsEnabled = false;
            }

            setTitleBar();
            await Task.Delay(1000).ContinueWith(t => ShowDialogs());

            foreach (ModuleView na in theNeuronArray.modules)
            {
                if (na.TheModule != null)
                {
                    na.TheModule.SetUpAfterLoad();
                }
            }
            if (theNeuronArray.displayParams != null)
            {
                theNeuronArrayView.Dp = theNeuronArray.displayParams;
            }
            NeuronArrayView.SortAreas();

            AddFileToMRUList(currentFileName);
            Properties.Settings.Default["CurrentFile"] = currentFileName;
            Properties.Settings.Default.Save();

            Update();
            SetShowSynapsesCheckBox(theNeuronArray.ShowSynapses);
            SetPlayPauseButtonImage(theNeuronArray.EngineIsPaused);
            ResumeEngine();
        }
        private bool PromptToSaveChanges()
        {
            if (IsArrayEmpty())
            {
                return(false);
            }
            MainWindow.theNeuronArray.GetCounts(out long synapseCount, out int neuronInUseCount);
            if (neuronInUseCount == 0)
            {
                return(false);
            }
            if (theNeuronArray.GetUndoCount() == undoCountAtLastSave)
            {
                return(false);                                                      //no changes have been made
            }
            bool canWrite = XmlFile.CanWriteTo(currentFileName, out string message);

            SuspendEngine();

            bool             retVal   = false;
            MessageBoxResult mbResult = System.Windows.MessageBox.Show(this, "Do you want to save changes?", "Save", MessageBoxButton.YesNoCancel,
                                                                       MessageBoxImage.Asterisk, MessageBoxResult.No);

            if (mbResult == MessageBoxResult.Yes)
            {
                if (currentFileName != "" && canWrite)
                {
                    if (SaveFile(currentFileName))
                    {
                        undoCountAtLastSave = theNeuronArray.GetUndoCount();
                    }
                }
                else
                {
                    if (SaveAs())
                    {
                    }
                    else
                    {
                        retVal = true;
                    }
                }
            }
            if (mbResult == MessageBoxResult.Cancel)
            {
                retVal = true;
            }
            ResumeEngine();
            return(retVal);
        }
        //this enables and disables various menu entries based on circumstances
        private void MainMenu_MouseEnter(object sender, MouseEventArgs e)
        {
            LoadMRUMenu();
            LoadFindMenus();
            if (theNeuronArray != null && !useServers)
            {
                ThreadCount.Text = theNeuronArray.GetThreadCount().ToString();
            }
            else
            {
                ThreadCount.Text = "";
            }
            if (theNeuronArray != null)
            {
                Refractory.Text = theNeuronArray.GetRefractoryDelay().ToString();
            }
            else
            {
                Refractory.Text = "";
            }

            if (currentFileName != "" &&
                XmlFile.CanWriteTo(currentFileName, out string message) &&
                theNeuronArray != null)
            {
                EnableMenuItem(MainMenu.Items, "_Save", true);
                SaveButton.IsEnabled = true;
            }
            else
            {
                EnableMenuItem(MainMenu.Items, "_Save", false);
                SaveButton.IsEnabled = false;
            }
            if (!engineIsPaused)
            {
                EnableMenuItem(MainMenu.Items, "Run", false);
                EnableMenuItem(MainMenu.Items, "Pause", true);
            }
            else
            {
                EnableMenuItem(MainMenu.Items, "Run", true);
                EnableMenuItem(MainMenu.Items, "Pause", false);
            }
            if (useServers)
            {
                var tb0 = Utils.FindByName(MainMenu, "ThreadCount");
                if (tb0.Parent is UIElement ui)
                {
                    ui.Visibility = Visibility.Collapsed;
                }
                tb0 = Utils.FindByName(MainMenu, "Refractory");
                if (tb0.Parent is UIElement ui1)
                {
                    ui1.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                var tb0 = Utils.FindByName(MainMenu, "ThreadCount");
                if (tb0.Parent is UIElement ui)
                {
                    ui.Visibility = Visibility.Visible;
                }
                tb0 = Utils.FindByName(MainMenu, "Refractory");
                if (tb0.Parent is UIElement ui1)
                {
                    ui1.Visibility = Visibility.Visible;
                }
            }
            if (IsArrayEmpty())
            {
                EnableMenuItem(MainMenu.Items, "_Save", false);
                EnableMenuItem(MainMenu.Items, "Save _As", false);
                EnableMenuItem(MainMenu.Items, "_Insert", false);
                EnableMenuItem(MainMenu.Items, "_Properties", false);
                EnableMenuItem(MainMenu.Items, "_Notes", false);
            }
            else
            {
                EnableMenuItem(MainMenu.Items, "Save _As", true);
                EnableMenuItem(MainMenu.Items, "_Insert", true);
                EnableMenuItem(MainMenu.Items, "_Properties", true);
                EnableMenuItem(MainMenu.Items, "_Notes", true);
                MenuItem mi = (MenuItem)Utils.FindByName(MainMenu, "ShowSynapses");
                if (mi != null)
                {
                    mi.IsChecked = theNeuronArray.ShowSynapses;
                }
            }
            if (theNeuronArrayView.theSelection.selectedRectangles.Count == 0)
            {
                EnableMenuItem(MainMenu.Items, " Cut", false);
                EnableMenuItem(MainMenu.Items, " Copy", false);
                EnableMenuItem(MainMenu.Items, " Delete", false);
                EnableMenuItem(MainMenu.Items, " Move", false);
                EnableMenuItem(MainMenu.Items, " Clear Selection", false);
            }
            else
            {
                EnableMenuItem(MainMenu.Items, " Cut", true);
                EnableMenuItem(MainMenu.Items, " Copy", true);
                EnableMenuItem(MainMenu.Items, " Delete", true);
                if (arrayView.targetNeuronIndex < 0)
                {
                    EnableMenuItem(MainMenu.Items, " Move", false);
                }
                else
                {
                    EnableMenuItem(MainMenu.Items, " Move", true);
                }
                EnableMenuItem(MainMenu.Items, " Clear Selection", true);
            }
            if (arrayView.targetNeuronIndex < 0 || myClipBoard == null)
            {
                EnableMenuItem(MainMenu.Items, " Paste", false);
            }
            else
            {
                EnableMenuItem(MainMenu.Items, " Paste", true);
            }
            if (theNeuronArray != null && theNeuronArray.UndoPossible())
            {
                EnableMenuItem(MainMenu.Items, " Undo", true);
            }
            else
            {
                EnableMenuItem(MainMenu.Items, " Undo", false);
            }

            if (myClipBoard == null)
            {
                EnableMenuItem(MainMenu.Items, "Save Clipboard", false);
            }
            else
            {
                EnableMenuItem(MainMenu.Items, "Save Clipboard", true);
            }
        }