Ejemplo n.º 1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Variable" <see
        /// cref="Button"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnVariableAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed
        /// by a <see cref="Dialog.ChangeVariable"/> dialog, allowing the user to define a new
        /// variable. The new variable copies the properties of the first selected item in the
        /// "Variable" list view, if any; otherwise, it is created with default properties.
        /// </para><para>
        /// If the user confirmed both dialogs, <b>OnVariableAdd</b> adds the new variable to the
        /// "Variable" list view and to the <see cref="CurrentVariables"/> collection, and sets the
        /// <see cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

        private void OnVariableAdd(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // ask user for new variable ID
            var variables = CurrentVariables;
            var dialog    = new Dialog.ChangeIdentifier(CurrentDefaultId,
                                                        Global.Strings.TitleVariableIdEnter, variables.ContainsKey, false);

            dialog.Owner = MainWindow.Instance;
            if (dialog.ShowDialog() != true)
            {
                return;
            }

            // retrieve new variable ID
            string id = String.Intern(dialog.Identifier);

            // create new variable based on selected variable, if any
            VariableClass variable, selection = VariableList.SelectedItem as VariableClass;

            if (selection == null)
            {
                variable = VariableClass.Create(id, CurrentCategory);
            }
            else
            {
                variable    = (VariableClass)selection.Clone();
                variable.Id = id;
            }

            // let user make changes to new variable
            var variableDialog = new Dialog.ChangeVariable(variable)
            {
                Owner = MainWindow.Instance
            };

            if (variableDialog.ShowDialog() != true)
            {
                return;
            }

            // add variable to section table
            variables.Add(id, variable);

            // update list view and select new item
            VariableList.Items.Refresh();
            VariableList.SelectAndShow(variable);

            // broadcast data changes
            EnableListButtons();
            SectionTab.DataChanged = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the user to change the specified <see cref="VariableClass"/>.</summary>
        /// <param name="variable">
        /// The <see cref="VariableClass"/> to change.</param>
        /// <remarks><para>
        /// <b>ChangeVariable</b> displays a <see cref="Dialog.ChangeVariable"/> dialog for the
        /// specified <paramref name="variable"/>.
        /// </para><para>
        /// If the user made any changes, <b>ChangeVariable</b> propagates them to the <see
        /// cref="CurrentVariables"/> collection and sets the <see
        /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

        private void ChangeVariable(VariableClass variable)
        {
            if (variable == null)
            {
                return;
            }

            // show dialog and let user make changes
            var dialog = new Dialog.ChangeVariable(variable)
            {
                Owner = MainWindow.Instance
            };

            dialog.ShowDialog();

            // broadcast data changes, if any
            if (dialog.DataChanged)
            {
                VariableList.Items.Refresh();
                SectionTab.DataChanged = true;
            }
        }