private void Load(string filename) { TabsManager.Load(filename); Filename = filename; DlgSearch.SearchReset(); try { string programFilesX64 = Environment.ExpandEnvironmentVariables("%ProgramW6432%"); string programFilesX86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); bool isProg = filename.StartsWith(programFilesX64, StringComparison.InvariantCultureIgnoreCase) || filename.StartsWith(programFilesX86, StringComparison.InvariantCultureIgnoreCase); bool isAdmin = (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator); if (isProg && !isAdmin) { DlgMessage.Show("This file is located under 'program files' and hence protected by Windows.\n" + "So KML will not be able to overwrite it, when you choose to save your changes.\n\n" + "Please run KML as administrator or manually pick the changed file from 'program data'\n" + "and put it back to original place.", "Permission warning", (new GuiIcons16()).Warning); } } catch { ; // something went wrong with reading env-var or admin flag } }
/// <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)); }
private void ButtonPrevious_Click(object sender, RoutedEventArgs e) { KmlItem search = DlgSearch.SearchPrevious(); if (search != null) { TabsManager.TreeManager.Select(search); } else { TabsManager.Previous(); } }
private void ButtonOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.FileName = System.IO.Path.GetFileName(Filename); dlg.InitialDirectory = System.IO.Path.GetDirectoryName(Filename); dlg.AddExtension = true; dlg.DefaultExt = ".sfs"; dlg.CheckFileExists = true; dlg.Filter = "KSP persistence file|*.sfs;*.craft"; if (dlg.ShowDialog() == true) { Load(dlg.FileName); DlgSearch.SearchReset(); } }
/// <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)); }
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; }