コード例 #1
0
        // handle events associated with the Quick Add Popup
        private void QuickAddButton_Click(object sender, EventArgs e)
        {
            RenderItemTypes();

            // open the popup, disable folder selection bug, and transfer focus to the popup text box
            QuickAddPopup.IsOpen = true;
            QuickAddPopupTextBox.Focus();
        }
コード例 #2
0
        private void QuickAddPopup_AddButton_Click(object sender, RoutedEventArgs e)
        {
            string name = QuickAddPopupTextBox.Text;

            // don't add empty items
            if (name == null || name == "")
            {
                return;
            }

            int itemTypeIndex = QuickAddPopupItemTypePicker.SelectedIndex;

            if (itemTypeIndex < 0)
            {
                MessageBox.Show("item type must be set");
                return;
            }
            ItemType itemType = App.ViewModel.ItemTypes[itemTypeIndex];

            // get the value of the IsList checkbox
            bool isChecked = (QuickAddPopupIsListCheckbox.IsChecked == null) ? false : (bool)QuickAddPopupIsListCheckbox.IsChecked;

            // figure out the sort value
            Guid? parentID  = (list.ID == Guid.Empty) ? null : (Guid?)list.ID;
            float sortOrder = 1000f;
            var   listItems = folder.Items.Where(it => it.ParentID == parentID).ToList();

            if (listItems.Count > 0)
            {
                sortOrder += listItems.Max(it => it.SortOrder);
            }

            // create the new item
            Item item = new Item()
            {
                Name       = name,
                FolderID   = folder.ID,
                ItemTypeID = itemType.ID,
                ParentID   = list.ID,
                IsList     = isChecked,
                SortOrder  = sortOrder
            };

            // hack: special case processing for item types that have a Complete field
            // if it exists, set it to false
            if (itemType.HasField("Complete"))
            {
                item.Complete = false;
            }

            // enqueue the Web Request Record
            RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                                              new RequestQueue.RequestRecord()
            {
                ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                Body    = item
            });

            // add the new item to the list
            list.Items.Add(item);
            ListHelper.AddItem(list, item);

            // add the item to the folder and list and re-render list
            folder.Items.Add(item);

            // save the changes to local storage
            StorageHelper.WriteFolder(folder);

            // trigger a sync with the Service
            App.ViewModel.SyncWithService();

            // clear the textbox and focus back to it
            QuickAddPopupTextBox.Text = "";
            QuickAddPopupTextBox.Focus();
        }