Example #1
0
        private void SetContextMenuClickHandlers()
        {
            foreach (var textBox in Common.FindVisualChildren <TextBox>(this))
            {
                if (!Equals(textBox, TextBoxLogTPM))
                {
                    var contectMenu = (ContextMenu)Resources["TextBoxContextMenuTPM"];

                    if (!BipFactory.HasBips())
                    {
                        MenuItem bipMenuItem = null;
                        foreach (var item in contectMenu.Items)
                        {
                            if (((MenuItem)item).Name == "contextMenuItemEditBIP")
                            {
                                bipMenuItem = (MenuItem)item;
                                break;
                            }
                        }
                        if (bipMenuItem != null)
                        {
                            contectMenu.Items.Remove(bipMenuItem);
                        }
                    }
                    if (Common.NoDCSBIOSEnabled())
                    {
                        MenuItem dcsBIOSMenuItem = null;
                        foreach (var item in contectMenu.Items)
                        {
                            if (((MenuItem)item).Name == "contextMenuItemEditDCSBIOS")
                            {
                                dcsBIOSMenuItem = (MenuItem)item;
                                break;
                            }
                        }
                        if (dcsBIOSMenuItem != null)
                        {
                            contectMenu.Items.Remove(dcsBIOSMenuItem);
                        }
                    }
                    textBox.ContextMenu         = contectMenu;
                    textBox.ContextMenuOpening += TextBoxContextMenuOpening;
                }
            }
        }
        public DCSFPContextMenuVisibility GetVisibility(ref int objectCount, bool isEmpty, bool containsKeyStroke, bool containsKeySequence, bool containsDCSBIOS, bool containsBIPLink, bool containsOSCommand)
        {
            var result = new DCSFPContextMenuVisibility();

            try
            {
                CopyPackage copyPackage = null;
                var         dataObject  = Clipboard.GetDataObject();
                if (dataObject != null && dataObject.GetDataPresent("NonVisuals.CopyPackage"))
                {
                    copyPackage = (CopyPackage)dataObject.GetData("NonVisuals.CopyPackage");

                    /*
                     * 31052022
                     * In PZ70 you can paste into the same textbox under different knob positions like ALT VS IAS etc.
                     * if (copyPackage?.SourceName == TextBox.Name)
                     * {
                     *  copyPackage = null;
                     * }*/
                }

                objectCount  = 0;
                objectCount += containsKeyStroke ? 1 : 0;
                objectCount += containsKeySequence ? 1 : 0;
                objectCount += containsDCSBIOS ? 1 : 0;
                objectCount += containsBIPLink ? 1 : 0;
                objectCount += containsOSCommand ? 1 : 0;

                if (isEmpty)
                {
                    result.AddNullKeyVisible   = true;
                    result.EditSequenceVisible = true;
                    if (Common.FullDCSBIOSEnabled() || Common.PartialDCSBIOSEnabled())
                    {
                        result.EditDCSBIOSVisible = true;
                    }

                    if (BipFactory.HasBips())
                    {
                        result.EditBIPVisible = true;
                    }

                    result.EditOSCommandVisible = true;

                    if (copyPackage != null)
                    {
                        result.PasteVisible = true;
                    }
                }

                if (containsKeyStroke)
                {
                    if (BipFactory.HasBips())
                    {
                        result.EditBIPVisible = true;
                    }

                    if (objectCount > 1)
                    {
                        result.CopySubMenuVisible   = true;
                        result.CopyKeyStrokeVisible = true;
                    }
                    else
                    {
                        result.CopySingleVisible = true;
                    }

                    if (copyPackage != null && copyPackage.ContentType == CopyContentType.BIPLink)
                    {
                        result.PasteVisible = true;
                    }
                }

                if (containsKeySequence)
                {
                    result.EditSequenceVisible = true;
                    if (BipFactory.HasBips())
                    {
                        result.EditBIPVisible = true;
                    }

                    if (objectCount > 1)
                    {
                        result.CopySubMenuVisible     = true;
                        result.CopyKeySequenceVisible = true;
                    }
                    else
                    {
                        result.CopySingleVisible = true;
                    }

                    if (copyPackage != null && copyPackage.ContentType == CopyContentType.BIPLink)
                    {
                        result.PasteVisible = true;
                    }
                }

                if (containsDCSBIOS)
                {
                    if (!_keyboardEmulationOnly)
                    {
                        result.EditDCSBIOSVisible = true;

                        if (objectCount > 1)
                        {
                            result.CopySubMenuVisible = true;
                            result.CopyDCSBIOSVisible = true;
                        }
                        else
                        {
                            result.CopySingleVisible = true;
                        }
                    }

                    if (BipFactory.HasBips())
                    {
                        result.EditBIPVisible = true;
                    }

                    if (copyPackage != null && copyPackage.ContentType == CopyContentType.BIPLink)
                    {
                        result.PasteVisible = true;
                    }
                }

                if (containsBIPLink)
                {
                    result.EditBIPVisible = true;
                    if (objectCount > 1)
                    {
                        result.CopySubMenuVisible = true;
                        result.CopyBIPLinkVisible = true;
                    }
                    else
                    {
                        result.CopySingleVisible = true;
                    }

                    if (copyPackage != null)
                    {
                        switch (copyPackage.ContentType)
                        {
                        case CopyContentType.KeySequence:
                        {
                            if (!containsKeyStroke && !containsKeySequence && !containsDCSBIOS && !containsOSCommand)
                            {
                                result.PasteVisible = true;
                            }

                            break;
                        }

                        case CopyContentType.DCSBIOS:
                        {
                            if (!containsKeyStroke && !containsKeySequence && !containsDCSBIOS && !containsOSCommand)
                            {
                                result.PasteVisible = true;
                            }

                            break;
                        }

                        case CopyContentType.BIPLink:
                        {
                            //Cannot paste BIPLink on BIPLink
                            break;
                        }

                        case CopyContentType.OSCommand:
                        {
                            if (!containsKeyStroke && !containsKeySequence && !containsDCSBIOS && !containsOSCommand)
                            {
                                result.PasteVisible = true;
                            }

                            break;
                        }
                        }
                    }
                }

                if (containsOSCommand)
                {
                    result.EditOSCommandVisible = true;
                    if (objectCount > 1)
                    {
                        result.CopySubMenuVisible   = true;
                        result.CopyOSCommandVisible = true;
                    }
                    else
                    {
                        result.CopySingleVisible = true;
                    }

                    if (copyPackage != null && copyPackage.ContentType == CopyContentType.BIPLink)
                    {
                        result.PasteVisible = true;
                    }
                }

                if (!isEmpty)
                {
                    result.DeleteSettingsVisible = true;
                }
            }
            catch (Exception ex)
            {
                Common.ShowErrorMessageBox(ex);
            }

            return(result);
        }
Example #3
0
        private void TextBoxContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            try
            {
                var textBox     = (TextBox)sender;
                var contextMenu = textBox.ContextMenu;
                if (!(textBox.IsFocused && Equals(textBox.Background, Brushes.Yellow)))
                {
                    //UGLY Must use this to get around problems having different color for BIPLink and Right Clicks
                    foreach (MenuItem item in contextMenu.Items)
                    {
                        item.Visibility = Visibility.Collapsed;
                    }
                    return;
                }
                foreach (MenuItem item in contextMenu.Items)
                {
                    item.Visibility = Visibility.Collapsed;
                }

                if (((TagDataClassTPM)textBox.Tag).ContainsDCSBIOS())
                {
                    // 1) If Contains DCSBIOS, show Edit DCS-BIOS Control & BIP
                    foreach (MenuItem item in contextMenu.Items)
                    {
                        if (Common.FullDCSBIOSEnabled() && item.Name.Contains("EditDCSBIOS"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        if (BipFactory.HasBips() && item.Name.Contains("EditBIP"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                    }
                }
                else if (((TagDataClassTPM)textBox.Tag).ContainsKeySequence())
                {
                    // 2)
                    foreach (MenuItem item in contextMenu.Items)
                    {
                        if (item.Name.Contains("EditSequence"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        if (BipFactory.HasBips() && item.Name.Contains("EditBIP"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                    }
                }
                else if (((TagDataClassTPM)textBox.Tag).IsEmpty())
                {
                    // 4)
                    foreach (MenuItem item in contextMenu.Items)
                    {
                        if (item.Name.Contains("EditSequence"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        else if (Common.FullDCSBIOSEnabled() && item.Name.Contains("EditDCSBIOS"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        else if (BipFactory.HasBips() && item.Name.Contains("EditBIP"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            item.Visibility = Visibility.Collapsed;
                        }
                    }
                }
                else if (((TagDataClassTPM)textBox.Tag).ContainsSingleKey())
                {
                    // 5)
                    foreach (MenuItem item in contextMenu.Items)
                    {
                        if (!(item.Name.Contains("EditSequence") || item.Name.Contains("EditDCSBIOS")))
                        {
                            if (item.Name.Contains("EditBIP"))
                            {
                                if (BipFactory.HasBips())
                                {
                                    item.Visibility = Visibility.Visible;
                                }
                            }
                            else
                            {
                                item.Visibility = Visibility.Visible;
                            }
                        }
                    }
                }
                else if (((TagDataClassTPM)textBox.Tag).ContainsBIPLink())
                {
                    // 3)
                    foreach (MenuItem item in contextMenu.Items)
                    {
                        if (Common.FullDCSBIOSEnabled() && item.Name.Contains("EditDCSBIOS"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        if (BipFactory.HasBips() && item.Name.Contains("EditBIP"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                        if (item.Name.Contains("EditSequence"))
                        {
                            item.Visibility = Visibility.Visible;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Common.ShowErrorMessageBox(2081, ex);
            }
        }