Exemple #1
0
        /// <summary>
        /// Show a search dialog.
        /// </summary>
        /// <param name="left">The left coordinate for the dialog</param>
        /// <param name="top">The top coordinate for the dialog</param>
        /// <param name="selectedItem">Out: Returns the selected KmlItem if "Ok" was clicked, null otherwise</param>
        /// <param name="presetText">The preset text to search for</param>
        /// <returns>True if "Ok" was clicked, false otherwise</returns>
        public static bool Show(double left, double top, out KmlItem selectedItem, string presetText = null)
        {
            DlgSearch dlg = new DlgSearch(presetText);

            dlg.Left = left;
            dlg.Top  = top;
            return(dlg.Show(out selectedItem));
        }
Exemple #2
0
        /// <summary>
        /// Show a search dialog.
        /// </summary>
        /// <param name="elementToShowBelow">A FrameworkElement to get the position from where the dialog will be placed under</param>
        /// <param name="selectedItem">Out: Returns the selected KmlItem if "Ok" was clicked, null otherwise</param>
        /// <param name="presetText">The preset text to search for</param>
        /// <returns>True if "Ok" was clicked, false otherwise</returns>
        public static bool Show(FrameworkElement elementToShowBelow, out KmlItem selectedItem, string presetText = null)
        {
            DlgSearch dlg = new DlgSearch(presetText);

            if (elementToShowBelow != null)
            {
                // Get the screen position of the button
                GeneralTransform transform = elementToShowBelow.TransformToAncestor(dlg.Owner);
                // Matrix is Identity on my PC but scaled on my notebook, maybe DPI settings
                Matrix m         = PresentationSource.FromVisual(dlg.Owner).CompositionTarget.TransformFromDevice;
                Point  rootPoint = transform.Transform(new Point(-9, elementToShowBelow.ActualHeight + 3));
                // Now get the point of the button in the screen
                Point point = dlg.Owner.PointToScreen(rootPoint);
                point    = m.Transform(point);
                dlg.Left = point.X;
                dlg.Top  = point.Y;
            }
            return(dlg.Show(out selectedItem));
        }
Exemple #3
0
        private void ButtonSearch_Click(object sender, RoutedEventArgs e)
        {
            ButtonSearch.IsChecked = true;
            KmlItem selectedItem;

            if (DlgSearch.Show(ButtonSearch, out selectedItem))
            {
                bool        isVessel = selectedItem is KmlVessel && (selectedItem as KmlVessel).Origin == KmlVessel.VesselOrigin.Flightstate;
                bool        isKerbal = selectedItem is KmlKerbal && (selectedItem as KmlKerbal).Origin == KmlKerbal.KerbalOrigin.Roster;
                IGuiManager manager;
                if (isVessel && Tabs.SelectedItem == VesselsTab)
                {
                    manager = TabsManager.VesselsManager;
                }
                else if (isKerbal && Tabs.SelectedItem == KerbalsTab)
                {
                    manager = TabsManager.KerbalsManager;
                }
                else
                {
                    manager = TabsManager;
                    // Select once opens in tree view (cases with opening vessels while in vessel view handled above).
                    // We want now: Open vessels in vessel view when not in tree view (e.g. in kerbal view).
                    // Same for kerbals.
                    // We can call Select twice, so it will switch views.
                    if (isVessel || isKerbal)
                    {
                        manager.Select(selectedItem);
                    }
                }
                manager.Select(selectedItem);
            }
            // Being a ToggleButton keeps it highlighted during the popup window is open
            // But we don't want it to stay highlighted, so we uncheck afterwards
            ButtonSearch.IsChecked = false;
        }