Beispiel #1
0
        private void NewSessionAction(object obj)
        {
            var sessionManager = ServiceLocator.Instance.Get <ISessionManager>();

            if (!sessionManager.IsSaved)
            {
                var userResult = MessageBox.Show("Do you want to save changes you made to " + sessionManager.Name + "?", "Sentinel", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
                if (userResult == MessageBoxResult.Cancel)
                {
                    return;
                }
                if (userResult == MessageBoxResult.Yes)
                {
                    SaveSession.Execute(null);

                    // if the user clicked "Cancel" at the save dialog box
                    if (!sessionManager.IsSaved)
                    {
                        return;
                    }
                }
            }

            // Remove the tab control.
            if (tabControl.Items.Count > 0)
            {
                var tab = tabControl.SelectedItem;
                tabControl.Items.Remove(tab);
            }

            Add.Execute(null);
        }
Beispiel #2
0
        private void LoadSessionAction(object obj)
        {
            var sessionManager = ServiceLocator.Instance.Get <ISessionManager>();
            var fileNameToLoad = (string)obj;

            if (!sessionManager.IsSaved)
            {
                var userResult = MessageBox.Show("Do you want to save changes you made to " + sessionManager.Name + "?", "Sentinel", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
                if (userResult == MessageBoxResult.Cancel)
                {
                    return;
                }
                if (userResult == MessageBoxResult.Yes)
                {
                    SaveSession.Execute(null);

                    // if the user clicked "Cancel" at the save dialog box
                    if (!sessionManager.IsSaved)
                    {
                        return;
                    }
                }
            }

            if (fileNameToLoad == null)
            {
                // Open file dialog
                //open a save file dialog
                OpenFileDialog openFile = new OpenFileDialog
                {
                    FileName    = sessionManager.Name,
                    DefaultExt  = ".sntl",
                    Filter      = "Sentinel session (.sntl)|*.sntl",
                    FilterIndex = 0
                };

                if ((bool)!openFile.ShowDialog(this))
                {
                    return;
                }

                fileNameToLoad = openFile.FileName;
            }

            //TODO: can be changed to just clear?
            //tabControl.Items.Clear();

            // Remove the tab control
            if (tabControl.Items.Count > 0)
            {
                var tab = tabControl.SelectedItem;
                tabControl.Items.Remove(tab);
            }

            RemoveBindingReferences();

            sessionManager.LoadSession(fileNameToLoad);
            AddToRecentFiles(fileNameToLoad);

            BindViewToViewModel();

            if (!sessionManager.ProviderSettings.Any())
            {
                return;
            }

            var frame = ServiceLocator.Instance.Get <IWindowFrame>();

            // Add to the tab control.
            var newTab = new TabItem {
                Header = sessionManager.Name, Content = frame
            };

            tabControl.Items.Add(newTab);
            tabControl.SelectedItem = newTab;
        }