/// <summary>
        /// Sets the page content based on existing material.
        /// </summary>
        public void ConstructPage()
        {
            gui = new PgCollectionGuiEdit();

            #region Collection name
            //Sets the collection name.
            if (string.IsNullOrWhiteSpace((string)collection.GetData("name")))
            {
                gui.TxtblkCollectionName.Text = GlobalStrings.NameUntitled;
            }
            else
            {
                gui.TxtblkCollectionName.Text = (string)collection.GetData("name");
            }

            //Handles changes to the database name.
            gui.TxtblkCollectionName.TextChanged += new TextChangedEventHandler((a, b) =>
            {
                if (!string.IsNullOrWhiteSpace(gui.TxtblkCollectionName.Text))
                {
                    collection.SetData("name", gui.TxtblkCollectionName.Text);
                }

                //If the textbox is empty, it will keep the last character.
                gui.TxtblkCollectionName.Text = (string)collection.GetData("name");

                DataNameChanged?.Invoke(this, null);
            });
            #endregion

            #region Template name
            gui.TxtblkTemplateName.Text = GlobalStrings.CollectionEditTemplate;
            //Sets the template name.
            if (string.IsNullOrWhiteSpace((string)project
                                          .GetCollectionTemplate(collection).GetData("name")))
            {
                gui.TxtblkTemplateName.Text += GlobalStrings.NameUntitled;
            }
            else
            {
                gui.TxtblkTemplateName.Text += (string)project
                                               .GetCollectionTemplate(collection).GetData("name");
            }
            #endregion

            #region Description
            //Sets the description.
            gui.TxtbxDescription.Text = (string)collection.GetData("description");

            //Handles changes to the collection description.
            gui.TxtbxDescription.TextChanged += new TextChangedEventHandler((a, b) =>
            {
                collection.SetData("description", gui.TxtbxDescription.Text);
            });
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the page content based on existing material.
        /// </summary>
        public void ConstructPage()
        {
            gui = new PgDatabaseGuiEdit();
            DataItem dat = Project.GetDatabase();

            #region Database name
            //Sets the database name.
            if (string.IsNullOrWhiteSpace((string)dat.GetData("name")))
            {
                gui.TxtblkDatabaseName.Text = GlobalStrings.NameUntitled;
            }
            else
            {
                gui.TxtblkDatabaseName.Text = (string)dat.GetData("name");
            }

            //Handles changes to the database name.
            gui.TxtblkDatabaseName.TextChanged += new TextChangedEventHandler((a, b) =>
            {
                if (!string.IsNullOrWhiteSpace(gui.TxtblkDatabaseName.Text))
                {
                    dat.SetData("name", gui.TxtblkDatabaseName.Text);
                }

                //If the textbox is empty, it will keep the last character.
                gui.TxtblkDatabaseName.Text = (string)dat.GetData("name");

                DataNameChanged?.Invoke(this, null);
            });
            #endregion

            #region Mode combobox
            //Sets the mode combobox.
            if ((bool)dat.GetData("defUseEditMode"))
            {
                gui.CmbxDefaultEditMode.SelectedValue =
                    GlobalStrings.DatabaseEditDefEditModeEdit;
            }
            else
            {
                gui.CmbxDefaultEditMode.SelectedValue =
                    GlobalStrings.DatabaseEditDefEditModeView;
            }

            //Handles changes to mode combobox.
            gui.CmbxDefaultEditMode.SelectionChanged +=
                new SelectionChangedEventHandler((a, b) =>
            {
                dat.SetData("defUseEditMode",
                            (string)gui.CmbxDefaultEditMode.SelectedValue ==
                            GlobalStrings.DatabaseEditDefEditModeEdit);
            });
            #endregion

            #region Description
            //Sets the description.
            gui.TxtbxDescription.Text = (string)dat.GetData("description");

            //Handles changes to the description.
            gui.TxtbxDescription.TextChanged += new TextChangedEventHandler((a, b) =>
            {
                dat.SetData("description", gui.TxtbxDescription.Text);
            });
            #endregion

            #region Background image
            //Sets the background image data.
            string bgUrl = (string)dat.GetData("imageUrl");
            if (!string.IsNullOrWhiteSpace(bgUrl))
            {
                if (File.Exists(bgUrl))
                {
                    gui.ImgDeleteBgImage.IsEnabled  = true;
                    gui.ImgDeleteBgImage.Visibility = Visibility.Visible;
                    gui.ImgBgImage.IsEnabled        = true;
                    gui.ImgBgImage.Visibility       = Visibility.Visible;
                    gui.ImgBgImage.Source           =
                        new BitmapImage(new Uri(bgUrl, UriKind.Absolute));
                }
                else
                {
                    gui.ImgDeleteBgImage.IsEnabled  = false;
                    gui.ImgDeleteBgImage.Visibility = Visibility.Collapsed;
                    gui.ImgBgImage.IsEnabled        = false;
                    gui.ImgBgImage.Visibility       = Visibility.Collapsed;
                }
            }
            else
            {
                gui.ImgDeleteBgImage.IsEnabled  = false;
                gui.ImgDeleteBgImage.Visibility = Visibility.Collapsed;
                gui.ImgBgImage.Visibility       = Visibility.Collapsed;
                gui.ImgBgImage.IsEnabled        = false;
            }

            //The deletion button responds to mouse interaction.
            gui.ImgDeleteBgImage.MouseEnter +=
                new System.Windows.Input.MouseEventHandler((a, b) =>
            {
                gui.ImgDeleteBgImage.Source = new BitmapImage(
                    new Uri(Assets.BttnDeleteHover));
            });

            gui.ImgDeleteBgImage.MouseLeave +=
                new System.Windows.Input.MouseEventHandler((a, b) =>
            {
                gui.ImgDeleteBgImage.Source = new BitmapImage(
                    new Uri(Assets.BttnDelete));
            });

            gui.ImgDeleteBgImage.MouseDown +=
                new System.Windows.Input.MouseButtonEventHandler((a, b) =>
            {
                dat.SetData("imageUrl", String.Empty);
                gui.ImgDeleteBgImage.IsEnabled  = false;
                gui.ImgDeleteBgImage.Visibility = Visibility.Collapsed;
                gui.ImgBgImage.IsEnabled        = false;
                gui.ImgBgImage.Visibility       = Visibility.Collapsed;

                BgImageChanged?.Invoke(this, null);
            });

            //Shows the background image in full size if clicked.
            gui.ImgBgImage.MouseDown +=
                new System.Windows.Input.MouseButtonEventHandler((a, b) =>
            {
                DlgImgDisplay gui = new DlgImgDisplay();
                gui.Add(bgUrl);
                gui.Show();
            });

            //Allows the user to browse to an image if selected.
            gui.BttnBrowseBgImage.Click +=
                new RoutedEventHandler((a, b) =>
            {
                OpenFileDialog dlg  = new OpenFileDialog();
                dlg.CheckPathExists = true;
                dlg.Filter          = GlobalStrings.FilterPictures;
                dlg.Title           = GlobalStrings.CaptionLoadDatabase;

                dlg.FileOk +=
                    new System.ComponentModel.CancelEventHandler((c, d) =>
                {
                    try
                    {
                        bgUrl = dlg.FileName;

                        gui.ImgBgImage.Source = new BitmapImage(
                            new Uri(bgUrl, UriKind.Absolute));

                        dat.SetData("imageUrl", bgUrl);

                        gui.ImgDeleteBgImage.IsEnabled  = true;
                        gui.ImgDeleteBgImage.Visibility = Visibility.Visible;
                        gui.ImgBgImage.IsEnabled        = true;
                        gui.ImgBgImage.Visibility       = Visibility.Visible;

                        BgImageChanged?.Invoke(this, null);
                    }
                    catch (NotSupportedException e)
                    {
                        Utils.Log("Uploaded non-image: " + e);
                        MessageBox.Show(GlobalStrings.DlgUploadImageError);
                    }
                });

                dlg.ShowDialog();
            });
            #endregion

            //Sets up delay between autosaves options.
            gui.TxtbxAutosaveNumSeconds.Text         = (((int)dat.GetData("autosaveDelay")) / 1000).ToString();
            gui.TxtbxAutosaveNumSeconds.TextChanged += TxtbxAutosaveNumSeconds_TextChanged;

            //Sets up delay between autosaves options.
            gui.TxtbxAutosaveNumBackups.Text         = ((int)dat.GetData("autosaveNumberofBackups")).ToString();
            gui.TxtbxAutosaveNumBackups.TextChanged += TxtbxAutosaveNumBackups_TextChanged;
        }
        /// <summary>
        /// Sets the page content based on existing material.
        /// </summary>
        public void ConstructPage()
        {
            gui = new PgGroupingGuiEdit();

            #region Grouping name
            //Sets the grouping name.
            if (string.IsNullOrWhiteSpace((string)grouping.GetData("name")))
            {
                gui.TxtblkGroupingName.Text = GlobalStrings.NameUntitled;
            }
            else
            {
                gui.TxtblkGroupingName.Text = (string)grouping.GetData("name");
            }

            //Handles changes to the grouping name.
            gui.TxtblkGroupingName.TextChanged += new TextChangedEventHandler((a, b) =>
            {
                if (!string.IsNullOrWhiteSpace(gui.TxtblkGroupingName.Text))
                {
                    grouping.SetData("name", gui.TxtblkGroupingName.Text);
                }

                //If the textbox is empty, it will keep the last character.
                gui.TxtblkGroupingName.Text = (string)grouping.GetData("name");

                DataNameChanged?.Invoke(this, null);
            });
            #endregion

            //All menu items are represented as entries for consistency.
            #region Menu Item Columns
            #region Menu item, move left/right
            var funcMenuItemMove = new Action(() =>
            {
                if (ActiveEntry == null)
                {
                    return;
                }

                //Moves the item in or out of the group (deletion/addition).
                if (gui.LstbxInGroup.Items.Contains(ActiveEntry))
                {
                    //Finds the entry reference for the current group that
                    //represents the entry, then removes the reference.
                    var refs = project.GetGroupingEntryRefs(grouping);
                    for (int i = 0; i < refs.Count; i++)
                    {
                        if ((ulong)refs[i].GetData("entryGuid") ==
                            ActiveEntry.GetItem().guid)
                        {
                            project.DeleteItemByGuid(refs[i].guid);
                        }
                    }

                    gui.LstbxInGroup.Items.Remove(ActiveEntry);
                    gui.LstbxOutGroup.Items.Add(ActiveEntry);
                }
                else
                {
                    project.AddGroupingEntryRef(
                        grouping.guid,
                        ActiveEntry.GetItem().guid);

                    gui.LstbxOutGroup.Items.Remove(ActiveEntry);
                    gui.LstbxInGroup.Items.Add(ActiveEntry);

                    EntryIncluded?.Invoke(this, null);
                }
            });
            #endregion

            #region Menuitem, selected
            var funcMenuItemSelected = new Action <LstbxDataItem>((newItem) =>
            {
                ActiveEntry = newItem;

                //Ensures only one item is selected at once.
                if (gui.LstbxInGroup.Items.Contains(ActiveEntry))
                {
                    gui.LstbxOutGroup.SelectedItem = null;
                }
                else
                {
                    gui.LstbxInGroup.SelectedItem = null;
                }
            });
            #endregion

            #region Populate menu items
            //Adds every menu item in its original order.
            var col        = project.GetGroupingCollection(grouping);
            var entries    = project.GetGroupingEntries(grouping);
            var colEntries = project.GetCollectionEntries(col);

            //Adds entries to their respective lists via group inclusiveness.
            for (int i = 0; i < colEntries.Count; i++)
            {
                var item = new LstbxDataItem(colEntries[i]);

                //Looks to see if this entry is in the group.
                var result = entries.Find(new Predicate <DataItem>((a) =>
                {
                    return(a.guid.Equals(colEntries[i].guid));
                }));

                //Adds the entry based on whether it's in the group.
                if (result != null)
                {
                    gui.LstbxInGroup.Items.Add(item);
                }
                else
                {
                    gui.LstbxOutGroup.Items.Add(item);
                }

                //Handles item selection.
                item.Selected += new RoutedEventHandler((a, b) =>
                {
                    funcMenuItemSelected(item);
                });
            }
            #endregion

            #region Keyboard event handling
            gui.LstbxInGroup.KeyDown += new KeyEventHandler((a, b) =>
            {
                //Right key pressed: Move to 2nd column
                if (b.Key == Key.Right && b.IsDown && ActiveEntry != null)
                {
                    funcMenuItemMove();
                }
            });

            gui.LstbxOutGroup.KeyDown += new KeyEventHandler((a, b) =>
            {
                //Left key pressed: Move to 1st column
                if (b.Key == Key.Left && b.IsDown &&
                    gui.LstbxOutGroup.SelectedItem != null)
                {
                    funcMenuItemMove();
                }
                #endregion
            });

            #endregion

            #region Left arrow key pressed
            gui.BttnMoveLeft.MouseDown += new MouseButtonEventHandler((a, b) =>
            {
                if (gui.LstbxOutGroup.SelectedItem != null)
                {
                    funcMenuItemMove();
                }
            });
            #endregion

            #region Right arrow key pressed
            gui.BttnMoveRight.MouseDown += new MouseButtonEventHandler((a, b) =>
            {
                if (gui.LstbxInGroup.SelectedItem != null)
                {
                    funcMenuItemMove();
                }
            });
            #endregion

            #region Grouping conditions
            gui.BttnCondAdd.Click   += BttnCondAdd_Click;
            gui.BttnCondApply.Click += BttnCondApply_Click;

            //Populates all grouping conditions.
            uint numConditions = (uint)grouping.GetData("numConditions");
            for (int i = 0; i < numConditions; i++)
            {
                var condType = (GroupingCondType)
                               grouping.GetData("conditionType" + i);

                switch (condType)
                {
                case (GroupingCondType.ByLetter):
                    string condFromLetter = (string)
                                            grouping.GetData("condAddFromLetter" + i);
                    string condToLetter = (string)
                                          grouping.GetData("condAddToLetter" + i);

                    gui.GroupConditions.Children.Add(
                        AddConditionByRange(condFromLetter, condToLetter, (uint)i));
                    break;
                }
            }
            #endregion
        }