示例#1
0
        private void OKButton_Click_Save(object sender, RoutedEventArgs e)
        {
            // Don't do anything if there's nothing selected in the tree
            if (null == MainTreeView.SelectedItem ||
                null == (MainTreeView.SelectedItem as Control).Tag)
            {
                return;
            }

            // Hide the buttons and show the progress bar
            OKButton.Visibility        = System.Windows.Visibility.Collapsed;
            CancelButton.Visibility    = System.Windows.Visibility.Collapsed;
            MainProgressBar.Visibility = System.Windows.Visibility.Visible;

            // Get a reference to the workspace
            Logic.Workspace ws = Core.App.Workspace.DrawingCanvasReference.GetWorkspace();

            // Get the selected tree view item
            Control item = MainTreeView.SelectedItem as Control;

            // Setup callback for save completion
            m_state.OnSaveComplete -= this.State_OnSaveComplete;
            m_state.OnSaveComplete += this.State_OnSaveComplete;

            RelevantAssignment.AssignmentStream assignmentObj =
                item.Tag as RelevantAssignment.AssignmentStream;
            if (null == assignmentObj)
            {
                m_state.CurrentAssignment = (item.Tag as RelevantAssignment);

                TreeViewItem tvi = item as TreeViewItem;

                // If the selected item is the actual course item and not an assignment file beneath it, then
                // we can only save if there are 0 or 1 files. Otherwise it's ambiguous what the user wants
                // to save and we need to return.
                if (0 == tvi.Items.Count)
                {
                    (tvi.Tag as RelevantAssignment).SaveAsync(null, ws, this.SaveCompleteCrossThread);
                }
                else if (1 == tvi.Items.Count)
                {
                    (tvi.Tag as RelevantAssignment).SaveAsync(
                        (tvi.Items[0] as TreeViewItem).Tag as RelevantAssignment.AssignmentStream,
                        ws, this.SaveCompleteCrossThread);
                }
                else
                {
                    // Show the buttons and hide the progress bar
                    OKButton.Visibility        = System.Windows.Visibility.Visible;
                    CancelButton.Visibility    = System.Windows.Visibility.Visible;
                    MainProgressBar.Visibility = System.Windows.Visibility.Collapsed;

                    MessageBox.Show("You have selected a assignment that has multiple files within it. Please " +
                                    "select a specific file to save to.");
                }

                return;
            }
            assignmentObj.Parent.SaveAsync(assignmentObj, ws, this.SaveCompleteCrossThread);
            m_state.CurrentAssignment = assignmentObj.Parent;
        }
示例#2
0
        private void OKButton_Click_Open(object sender, RoutedEventArgs e)
        {
            // Don't do anything if there's nothing selected in the tree
            if (null == MainTreeView.SelectedItem ||
                null == (MainTreeView.SelectedItem as Control).Tag)
            {
                return;
            }

            // Get a reference to the workspace
            Logic.Workspace ws = Core.App.Workspace.DrawingCanvasReference.GetWorkspace();

            // Get the selected tree view item
            Control selectedItem = MainTreeView.SelectedItem as Control;

            // Get the assignment stream for the selected item
            RelevantAssignment.AssignmentStream ras = (MainTreeView.SelectedItem as TreeViewItem).Tag as
                                                      RelevantAssignment.AssignmentStream;
            if (null != ras)
            {
                m_state.CurrentAssignment = ras.Parent;
                if (0 == ras.Length)
                {
                    MessageBox.Show("Assignment has yet to be submitted. You may save your work to OSBLE to " +
                                    "submit the first version for this assignment.");
                }
                else
                {
                    // Hide the buttons and show the progress bar
                    OKButton.Visibility        = System.Windows.Visibility.Collapsed;
                    CancelButton.Visibility    = System.Windows.Visibility.Collapsed;
                    MainProgressBar.Visibility = System.Windows.Visibility.Visible;

                    try
                    {
                        ws.Load(ras);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("File could not be loaded. It is recommended that you try downloading " +
                                        "the file from the OSBLE web interface.");
                    }

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

                this.DialogResult = true;
            }
            else
            {
                RelevantAssignment ra = (MainTreeView.SelectedItem as TreeViewItem).Tag as RelevantAssignment;

                // If there's not an assignment associated with this node then we just ignore
                if (null == ra)
                {
                    return;
                }

                if (0 == (MainTreeView.SelectedItem as TreeViewItem).Items.Count)
                {
                    if (AssignmentTypes.Basic == ra.ActualAssignment.Type)
                    {
                        m_state.CurrentAssignment = ra;

                        // 0 files for a basic assignment means the user has yet to submit anything
                        MessageBox.Show("Assignment has yet to be submitted. You may save your work to OSBLE to " +
                                        "submit the first version for this assignment.");
                    }
                    else if (AssignmentTypes.CriticalReview == ra.ActualAssignment.Type)
                    {
                        // 0 files for a critical review means that no one has submitted files to review
                        MessageBox.Show("You have selected a critical review assignment for which there are " +
                                        "currently no files available. Files for this assignment will become available " +
                                        "after the individuals who you are assigned to review submit their files.");
                        return;
                    }
                    else
                    {
                        // Else we ignore it because they have to choose a child item
                        return;
                    }
                }
                else if (1 == (MainTreeView.SelectedItem as TreeViewItem).Items.Count)
                {
                    // If there's only one option under this node then just load that
                    MainTreeView.SelectItem((MainTreeView.SelectedItem as TreeViewItem).Items[0]);
                    OKButton_Click_Open(sender, e);
                    return;
                }
                else
                {
                    // Else we ignore it because they have to choose a child item
                    MessageBox.Show("You have selected a assignment that has multiple files within it. Please " +
                                    "select a specific file to open.");

                    return;
                }
            }
            this.DialogResult = true;
        }