void Add_Click(object sender, RoutedEventArgs e)
        {
            var  sel      = SelectedCat;
            long?parentId = null;

            if (sel != null)
            {
                var kindOfAdd = MessageBox.Show("Create a sub-item of the selected category? (If No, it will be created at the root level.)", "Add Category", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (kindOfAdd == MessageBoxResult.Yes)
                {
                    parentId = sel.RowId;
                }
                else if (kindOfAdd != MessageBoxResult.No)
                {
                    return; //canceled
                }
            }
            string s = StringDialog.GetInput("New category name", "", 40);

            if (s == null)
            {
                return;
            }
            Globals.UI.ModifyCat(0, cat =>
            {
                cat.ParentId = parentId;
                cat.Name     = s;
            });
            DataContext = new VM();
        }
示例#2
0
        /// <summary>
        /// Get input; return null on cancel
        /// </summary>
        public static string GetInput(string caption, string initialValue, int maxLength)
        {
            var dialog = new StringDialog
            {
                Owner = App.Current.MainWindow
            };

            dialog.eCaption.Text    = caption;
            dialog.eValue.MaxLength = maxLength;
            dialog.eValue.Text      = initialValue;
            if (dialog.ShowDialog() != true)
            {
                return(null);
            }
            return(dialog.eValue.Text);
        }
示例#3
0
        void AddCat_Click(object sender, RoutedEventArgs e)
        {
            var prevSelectedCatIds = _VM.GetEditedSelectedIds();

            //get whether root or child
            long?parentId = null;
            var  sel      = SelectedItem;

            if (sel != null)
            {
                var answer = MessageBox.Show($"Add as sub-category of {sel.Name}? (If No, it will be created at the root level.)", "New Category", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (answer == MessageBoxResult.Yes)
                {
                    parentId = sel.RowId;
                }
                else if (answer != MessageBoxResult.No)
                {
                    return;
                }
            }

            //get name
            var name = StringDialog.GetInput("Category name", "", 40);

            if (name == null)
            {
                return;
            }
            name = name.Trim();
            if (name.Length == 0)
            {
                return;
            }

            //save
            Globals.UI.ModifyCat(0, c =>
            {
                c.Name     = name;
                c.ParentId = parentId;
            });

            //reload
            _VM         = new VM(prevSelectedCatIds);
            DataContext = _VM;
        }
        void Rename_Click(object sender, RoutedEventArgs e)
        {
            var sel = SelectedCat;

            if (sel == null)
            {
                return;
            }
            string s = StringDialog.GetInput("New name", sel.Name, 40);

            if (s == null)
            {
                return;
            }
            Globals.UI.ModifyCat(sel.RowId, cat =>
            {
                cat.Name = s;
            });
            DataContext = new VM();
        }