private string GetCustomControlValues() { string values = "Custom Cotnrols Values:" + Environment.NewLine; CommonFileDialogRadioButtonList list = currentFileDialog.Controls["radioButtonOptions"] as CommonFileDialogRadioButtonList; values += String.Format("Radio Button List: Total Options = {0}; Selected Option = \"{1}\"; Selected Option Index = {2}", list.Items.Count, list.Items[list.SelectedIndex].Text, list.SelectedIndex) + Environment.NewLine; CommonFileDialogComboBox combo = currentFileDialog.Controls["comboBox"] as CommonFileDialogComboBox; values += String.Format("Combo Box: Total Items = {0}; Selected Item = \"{1}\"; Selected Item Index = {2}", combo.Items.Count, combo.Items[combo.SelectedIndex].Text, combo.SelectedIndex) + Environment.NewLine; CommonFileDialogCheckBox checkBox = currentFileDialog.Controls["chkOptionA"] as CommonFileDialogCheckBox; values += String.Format("Check Box \"{0}\" is {1}", checkBox.Text, checkBox.IsChecked ? "Checked" : "Unchecked") + Environment.NewLine; checkBox = currentFileDialog.Controls["chkOptionB"] as CommonFileDialogCheckBox; values += String.Format("Check Box \"{0}\" is {1}", checkBox.Text, checkBox.IsChecked ? "Checked" : "Unchecked") + Environment.NewLine; CommonFileDialogTextBox textBox = currentFileDialog.Controls["textName"] as CommonFileDialogTextBox; values += String.Format("TextBox \"Name\" = {0}", textBox.Text); return(values); }
public bool ShowDialog(Window window) { var dialog = new CommonOpenFileDialog() { AllowNonFileSystemItems = false, EnsureFileExists = true, Multiselect = true, }; var checkbox = new CommonFileDialogCheckBox("SingleTabCheckbox", "Read into a single tab") { IsProminent = false, IsChecked = false, }; dialog.Controls.Add(checkbox); var filters = dialog.Filters; ParsedFilter.ForEach(f => filters.Add(f)); var result = dialog.ShowDialog(window) == CommonFileDialogResult.Ok; if (result) { FileNames = dialog.FileNames.ToArray(); FilterIndex = dialog.SelectedFileTypeIndex; SingleTab = checkbox.IsChecked; } return(result); }
public void File_SaveAs() { ExpressionEditor_AcceptEdit(); var defaultFileName = Handler.SourceType == ModelSourceType.Database ? "Model.bim" : File_Current; using (var fbd = new CommonSaveFileDialog()) { // Configure dialog: fbd.DefaultFileName = defaultFileName; fbd.Filters.Clear(); if (Handler.SourceType == ModelSourceType.Pbit) { fbd.Filters.Add(new CommonFileDialogFilter("Power BI Template", "*.pbit")); } fbd.Filters.Add(new CommonFileDialogFilter("Tabular Model Files", "*.bim")); fbd.Filters.Add(new CommonFileDialogFilter("All files", "*.*")); var useAnnotatedSerializationSettingsCheckBox = new CommonFileDialogCheckBox { Text = "Use serialization settings from annotations", IsChecked = true }; if (Handler.HasSerializeOptions) { fbd.Controls.Add(useAnnotatedSerializationSettingsCheckBox); } var res = fbd.ShowDialog(); if (res == CommonFileDialogResult.Ok && !string.IsNullOrWhiteSpace(fbd.FileName)) { using (new Hourglass()) { UI.StatusLabel.Text = "Saving..."; var fileType = fbd.Filters[fbd.SelectedFileTypeIndex - 1].Extensions.FirstOrDefault(); Handler.Save(fbd.FileName, fileType == "pbit" ? SaveFormat.PowerBiTemplate : SaveFormat.ModelSchemaOnly, Preferences.Current.GetSerializeOptions(false), Handler.HasSerializeOptions && useAnnotatedSerializationSettingsCheckBox.IsChecked); RecentFiles.Add(fbd.FileName); RecentFiles.Save(); UI.FormMain.PopulateRecentFilesList(); // If not connected to a database, change the current working file: if (Handler.SourceType != ModelSourceType.Database) { File_Current = fbd.FileName; File_SaveMode = ModelSourceType.File; } UpdateUIText(); } } } }
private void AddCustomControls(CommonFileDialog openDialog) { // Add a RadioButtonList CommonFileDialogRadioButtonList list = new CommonFileDialogRadioButtonList("Options"); list.Items.Add(new CommonFileDialogRadioButtonListItem("Option A")); list.Items.Add(new CommonFileDialogRadioButtonListItem("Option B")); list.SelectedIndexChanged += RBLOptions_SelectedIndexChanged; list.SelectedIndex = 1; openDialog.Controls.Add(list); // Create a groupbox CommonFileDialogGroupBox groupBox = new CommonFileDialogGroupBox("Options"); // Create and add two check boxes to this group CommonFileDialogCheckBox checkA = new CommonFileDialogCheckBox("Option A", true); CommonFileDialogCheckBox checkB = new CommonFileDialogCheckBox("Option B", true); checkA.CheckedChanged += ChkOptionA_CheckedChanged; checkB.CheckedChanged += ChkOptionB_CheckedChanged; groupBox.Items.Add(checkA); groupBox.Items.Add(checkB); // Create and add a separator to this group groupBox.Items.Add(new CommonFileDialogSeparator()); // Create and add a button to this group CommonFileDialogButton btnCFDPushButton = new CommonFileDialogButton("Push Button"); btnCFDPushButton.Click += PushButton_Click; groupBox.Items.Add(btnCFDPushButton); // Add groupbox to dialog openDialog.Controls.Add(groupBox); // Add a Menu CommonFileDialogMenu menu = new CommonFileDialogMenu("Sample Menu"); CommonFileDialogMenuItem itemA = new CommonFileDialogMenuItem("Menu Item 1"); CommonFileDialogMenuItem itemB = new CommonFileDialogMenuItem("Menu Item 2"); itemA.Click += MenuOptionA_Click; itemB.Click += MenuOptionA_Click; menu.Items.Add(itemA); menu.Items.Add(itemB); openDialog.Controls.Add(menu); // Add a TextBox openDialog.Controls.Add(new CommonFileDialogLabel("Enter name")); openDialog.Controls.Add(new CommonFileDialogTextBox("textBox", Environment.UserName)); // Add a ComboBox CommonFileDialogComboBox comboBox = new CommonFileDialogComboBox(); comboBox.SelectedIndexChanged += ComboEncoding_SelectedIndexChanged; comboBox.Items.Add(new CommonFileDialogComboBoxItem("Combobox Item 1")); comboBox.Items.Add(new CommonFileDialogComboBoxItem("Combobox Item 2")); comboBox.SelectedIndex = 1; openDialog.Controls.Add(comboBox); }
private void AddSfaCheckbox() { sfaCheck = new CommonFileDialogCheckBox { Text = "Use serialization settings from annotations", IsChecked = true }; dlg.Controls.Add(sfaCheck); }
private void Export(TreeNode node) { // OBJ for now var dlg = new CommonOpenFileDialog() { Title = "Select export folder" }; dlg.IsFolderPicker = true; AddOpenFileDialogCustomControls(dlg); if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { string exportMeshDirectory = dlg.FileName; CommonFileDialogComboBox geoComboBox = dlg.Controls["geoComboBox"] as CommonFileDialogComboBox; string modelExtension = geoComboBox.Items[geoComboBox.SelectedIndex].Text; CommonFileDialogComboBox texComboBox = dlg.Controls["texComboBox"] as CommonFileDialogComboBox; string texExtension = texComboBox.Items[texComboBox.SelectedIndex].Text; CommonFileDialogCheckBox worldSpaceCheckBox = dlg.Controls["worldSpaceCheckBox"] as CommonFileDialogCheckBox; bool transformToWorld = worldSpaceCheckBox.IsChecked; CommonFileDialogCheckBox mergeCheckBox = dlg.Controls["mergeCheckBox"] as CommonFileDialogCheckBox; bool mergeObjects = mergeCheckBox.IsChecked; exportMeshButton.Enabled = false; if (node.Nodes.Count > 0) { // TODO: if merging is desired, combine all the objects into one mesh with multiple buffers progressBar.Maximum = node.Nodes.Count; int instance = 0; foreach (RenderTreeNode rn in node.Nodes) { string instanceName = "_" + instance.ToString(); ExportNode(rn, exportMeshDirectory, modelExtension, texExtension, transformToWorld, instanceName); ++instance; progressBar.PerformStep(); } progressBar.Value = 0; } else { string instanceName = ""; ExportNode((RenderTreeNode)node, exportMeshDirectory, modelExtension, texExtension, transformToWorld, instanceName); } exportMeshButton.Enabled = true; } }
public bool LocalFile() { var startDir = FileSystemHelper.DirectoryFromPath(UIController.Current.File_Current) ?? Environment.CurrentDirectory; var sfd = new CommonOpenFileDialog("Open Rule File"); sfd.EnsureFileExists = true; sfd.InitialDirectory = startDir; sfd.DefaultExtension = "json"; sfd.Filters.Add(new CommonFileDialogFilter("JSON file", "*.json")); sfd.Filters.Add(new CommonFileDialogFilter("All files", "*.*")); var localPathCheckBox = new CommonFileDialogCheckBox("Use relative path", true) { Visible = false }; if (UIController.Current.File_Current != null) { sfd.Controls.Add(localPathCheckBox); localPathCheckBox.Visible = true; sfd.FolderChanging += (s, e) => { var relativePath = FileSystemHelper.GetRelativePath(startDir, e.Folder); if (relativePath.Length >= 2 && relativePath[1] == ':') { localPathCheckBox.Visible = false; } else { localPathCheckBox.Visible = true; } }; } parent.Enabled = false; if (sfd.ShowDialog() == CommonFileDialogResult.Ok) { parent.Enabled = true; var fileName = localPathCheckBox.Visible && localPathCheckBox.IsChecked ? FileSystemHelper.GetRelativePath(startDir, sfd.FileName) : sfd.FileName; if (!analyzer.ExternalRuleCollections.Any( rc => rc.FilePath != null && FileSystemHelper.GetAbsolutePath(analyzer.BasePath, rc.FilePath).EqualsI(sfd.FileName) )) { analyzer.ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromFile(analyzer.BasePath, fileName)); } return(true); } parent.Enabled = true; return(false); }
public void OnCheckButtonToggled(IFileDialogCustomize pfdc, int dwIDCtl, bool bChecked) { // Find control DialogControl control = this.parent.controls.GetControlbyId(dwIDCtl); CommonFileDialogCheckBox box = control as CommonFileDialogCheckBox; // Update control and call corresponding event if (box != null) { box.IsChecked = bChecked; box.RaiseCheckedChangedEvent(); } }
public void File_SaveAs_ToFolder() { using (var fbd = new CommonOpenFileDialog() { IsFolderPicker = true }) { var currentSerializeOptions = Handler.FolderSerializeOptions; var specialSerializeOptions = _file_SaveMode == ModelSourceType.Folder && currentSerializeOptions != null && !currentSerializeOptions.Equals(SerializeOptions.Default); var useAnnotatedSerializationSettingsCheckBox = new CommonFileDialogCheckBox { Text = "Use serialization settings from annotations", IsChecked = specialSerializeOptions }; if (currentSerializeOptions != null) { fbd.Controls.Add(useAnnotatedSerializationSettingsCheckBox); } var res = fbd.ShowDialog(); if (res == CommonFileDialogResult.Ok && !string.IsNullOrWhiteSpace(fbd.FileName)) { using (new Hourglass()) { UI.StatusLabel.Text = "Saving..."; Handler.Save(fbd.FileName, SaveFormat.TabularEditorFolder, Preferences.Current.GetSerializeOptions(true), useAnnotatedSerializationSettingsCheckBox.IsChecked); RecentFiles.Add(fbd.FileName); RecentFiles.Save(); UI.FormMain.PopulateRecentFilesList(); // If working with a file, change the current file pointer: if (Handler.SourceType != ModelSourceType.Database) { File_SaveMode = ModelSourceType.Folder; File_Current = fbd.FileName; } UpdateUIText(); } } } }
public static List <string> ShowDialog(string Title, bool IsFolderPicker = true, List <CommonFileDialogFilter> Filters = null) { CommonOpenFileDialog commonOpenFileDialog = new CommonOpenFileDialog(); commonOpenFileDialog.Title = Title; commonOpenFileDialog.NavigateToShortcut = true; commonOpenFileDialog.AddToMostRecentlyUsedList = true; if (Filters != null) { foreach (CommonFileDialogFilter cdf in Filters) { commonOpenFileDialog.Filters.Add(cdf); } } CommonFileDialogCheckBox cBox = null; if (IsFolderPicker) { cBox = new CommonFileDialogCheckBox("IsContainsubfolder ", "是否包含子文件夹", false); commonOpenFileDialog.IsFolderPicker = IsFolderPicker; commonOpenFileDialog.Controls.Add(cBox); } else { commonOpenFileDialog.Multiselect = true; } if (commonOpenFileDialog.ShowDialog() == CommonFileDialogResult.Ok) { if (cBox != null) { isContainSubfolder = cBox.IsChecked; } return(commonOpenFileDialog.FileNames.ToList()); } else { return(null); } }
private void OnClickImageSave(object sender, EventArgs e) { if (imageListView.SelectedIndices.Count < 1) { MessageBox.Show(Resources.DialogSelectImage, Resources.DialogInfo); return; } CommonFileDialogCheckBox correctColorCb = new CommonFileDialogCheckBox("correctColorCb", Resources.DialogCorrectColor, false); ImageFormat[] imageFormats = { ImageFormat.Png, ImageFormat.Jpeg }; CommonSaveFileDialog fileDialog = new CommonSaveFileDialog(Resources.DialogSaveImage) { Filters = { new CommonFileDialogFilter("PNG", "*.png"), new CommonFileDialogFilter("JPEG", "*.jpg;*.jpeg") }, Controls = { correctColorCb }, RestoreDirectory = true }; if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) { string filepath = fileDialog.FileName; int selected = imageListView.SelectedIndices[0]; byte[] imageData = originalImagesData[selected]; ImageFormat saveFormat = imageFormats[fileDialog.SelectedFileTypeIndex - 1]; ImageFormat imageFormat = originalImageFormats[selected]; if (!correctColorCb.IsChecked && saveFormat == imageFormat) { File.WriteAllBytes(filepath, imageData); } else { using (MemoryStream stream = new MemoryStream(imageData)) { Image imageSave = Image.FromStream(stream); if (correctColorCb.IsChecked) { ImageUtils.ReverseColorRB((Bitmap)imageSave); } imageSave.Save(filepath, saveFormat); imageSave.Dispose(); } } } fileDialog.Dispose(); }
public bool Run(OpenFileDialogData data) { var parent = data.TransientFor ?? MessageService.RootWindow; CommonFileDialog dialog; if (data.Action == FileChooserAction.Open) { dialog = new CustomCommonOpenFileDialog { EnsureFileExists = true }; } else { dialog = new CustomCommonSaveFileDialog(); } dialog.SetCommonFormProperties(data); CustomCommonFileDialogComboBox encodingCombo = null; if (data.ShowEncodingSelector) { var group = new CommonFileDialogGroupBox("encoding", "Encoding:"); encodingCombo = new CustomCommonFileDialogComboBox(); BuildEncodingsCombo(encodingCombo, data.Action != FileChooserAction.Save, data.Encoding); group.Items.Add(encodingCombo); dialog.Controls.Add(group); encodingCombo.SelectedIndexChanged += (sender, e) => { if (encodingCombo.SelectedIndex == encodingCombo.Items.Count - 1) { var dlg = new System.Windows.Window { Title = "Choose encodings", Content = new SelectEncodingControl(), SizeToContent = SizeToContent.WidthAndHeight }; if (dlg.ShowDialog().Value) { BuildEncodingsCombo(encodingCombo, data.Action != FileChooserAction.Save, data.Encoding); dialog.ApplyControlPropertyChange("Items", encodingCombo); } } }; } CustomCommonFileDialogComboBox viewerCombo = null; CommonFileDialogCheckBox closeSolution = null; if (data.ShowViewerSelector && data.Action == FileChooserAction.Open) { var group = new CommonFileDialogGroupBox("openWith", "Open with:"); viewerCombo = new CustomCommonFileDialogComboBox { Enabled = false }; group.Items.Add(viewerCombo); dialog.Controls.Add(group); if (encodingCombo != null || IdeApp.Workspace.IsOpen) { viewerCombo.SelectedIndexChanged += (o, e) => { bool solutionWorkbenchSelected = ((ViewerComboItem)viewerCombo.Items [viewerCombo.SelectedIndex]).Viewer == null; if (closeSolution != null) { closeSolution.Visible = solutionWorkbenchSelected; } if (encodingCombo != null) { encodingCombo.Enabled = !solutionWorkbenchSelected; } }; } if (IdeApp.Workspace.IsOpen) { var group2 = new CommonFileDialogGroupBox(); // "Close current workspace" is too long and splits the text on 2 lines. closeSolution = new CommonFileDialogCheckBox("Close workspace", true) { Visible = false }; group2.Items.Add(closeSolution); dialog.Controls.Add(group2); } dialog.SelectionChanged += (sender, e) => { try { var files = GetSelectedItems(dialog); var file = files.Count == 0 ? null : files[0]; bool hasBench = FillViewers(viewerCombo, file); if (closeSolution != null) { closeSolution.Visible = hasBench; } if (encodingCombo != null) { encodingCombo.Enabled = !hasBench; } dialog.ApplyControlPropertyChange("Items", viewerCombo); } catch (Exception ex) { LoggingService.LogInternalError(ex); } }; } if (!GdkWin32.RunModalWin32Dialog(dialog, parent)) { return(false); } dialog.GetCommonFormProperties(data); if (encodingCombo != null) { data.Encoding = ((EncodingComboItem)encodingCombo.Items [encodingCombo.SelectedIndex]).Encoding; } if (viewerCombo != null) { if (closeSolution != null) { data.CloseCurrentWorkspace = closeSolution.Visible && closeSolution.IsChecked; } int index = viewerCombo.SelectedIndex; if (index != -1) { data.SelectedViewer = ((ViewerComboItem)viewerCombo.Items [index]).Viewer; } } return(true); }
/// <summary> /// Called when a control currently in the collection /// has a property changed. /// </summary> /// <param name="propertyName">The name of the property changed.</param> /// <param name="control">The control whose property has changed.</param> public virtual void ApplyControlPropertyChange(string propertyName, DialogControl control) { if (control == null) { throw new ArgumentNullException("control"); } CommonFileDialogControl dialogControl = null; if (propertyName == "Text") { CommonFileDialogTextBox textBox = control as CommonFileDialogTextBox; if (textBox != null) { customize.SetEditBoxText(control.Id, textBox.Text); } else { customize.SetControlLabel(control.Id, textBox.Text); } } else if (propertyName == "Visible" && (dialogControl = control as CommonFileDialogControl) != null) { ShellNativeMethods.ControlState state; customize.GetControlState(control.Id, out state); if (dialogControl.Visible == true) { state |= ShellNativeMethods.ControlState.Visible; } else if (dialogControl.Visible == false) { state &= ~ShellNativeMethods.ControlState.Visible; } customize.SetControlState(control.Id, state); } else if (propertyName == "Enabled" && dialogControl != null) { ShellNativeMethods.ControlState state; customize.GetControlState(control.Id, out state); if (dialogControl.Enabled == true) { state |= ShellNativeMethods.ControlState.Enable; } else if (dialogControl.Enabled == false) { state &= ~ShellNativeMethods.ControlState.Enable; } customize.SetControlState(control.Id, state); } else if (propertyName == "SelectedIndex") { CommonFileDialogRadioButtonList list; CommonFileDialogComboBox box; if ((list = control as CommonFileDialogRadioButtonList) != null) { customize.SetSelectedControlItem(list.Id, list.SelectedIndex); } else if ((box = control as CommonFileDialogComboBox) != null) { customize.SetSelectedControlItem(box.Id, box.SelectedIndex); } } else if (propertyName == "IsChecked") { CommonFileDialogCheckBox checkBox = control as CommonFileDialogCheckBox; if (checkBox != null) { customize.SetCheckButtonState(checkBox.Id, checkBox.IsChecked); } } }
public void ShowFileOpenDialog() { string[] fileNames; List <Agent.KeyConstraint> constraints = new List <Agent.KeyConstraint>(); if (mAgent is PageantClient) { // Client Mode with Pageant - Show standard file dialog since we don't // need / can't use constraints using (var openFileDialog = new OpenFileDialog()) { openFileDialog.Multiselect = true; openFileDialog.Filter = string.Join("|", Strings.filterPuttyPrivateKeyFiles, "*.ppk", Strings.filterAllFiles, "*.*"); var result = openFileDialog.ShowDialog(); if (result != DialogResult.OK) { return; } fileNames = openFileDialog.FileNames; } } else if (CommonOpenFileDialog.IsPlatformSupported) { // Windows Vista/7/8 has new style file open dialog that can be extended // using the Windows API via the WindowsAPICodepack library var win7OpenFileDialog = new CommonOpenFileDialog(); win7OpenFileDialog.Multiselect = true; win7OpenFileDialog.EnsureFileExists = true; var confirmConstraintCheckBox = new CommonFileDialogCheckBox(cConfirmConstraintCheckBox, "Require user confirmation"); var lifetimeConstraintTextBox = new CommonFileDialogTextBox(cLifetimeConstraintTextBox, string.Empty); lifetimeConstraintTextBox.Visible = false; var lifetimeConstraintCheckBox = new CommonFileDialogCheckBox(cLifetimeConstraintCheckBox, "Set lifetime (in seconds)"); lifetimeConstraintCheckBox.CheckedChanged += (s, e) => { lifetimeConstraintTextBox.Visible = lifetimeConstraintCheckBox.IsChecked; }; var confirmConstraintGroupBox = new CommonFileDialogGroupBox(); var lifetimeConstraintGroupBox = new CommonFileDialogGroupBox(); confirmConstraintGroupBox.Items.Add(confirmConstraintCheckBox); lifetimeConstraintGroupBox.Items.Add(lifetimeConstraintCheckBox); lifetimeConstraintGroupBox.Items.Add(lifetimeConstraintTextBox); win7OpenFileDialog.Controls.Add(confirmConstraintGroupBox); win7OpenFileDialog.Controls.Add(lifetimeConstraintGroupBox); var filter = new CommonFileDialogFilter( Strings.filterPuttyPrivateKeyFiles, "*.ppk"); win7OpenFileDialog.Filters.Add(filter); filter = new CommonFileDialogFilter(Strings.filterAllFiles, "*.*"); win7OpenFileDialog.Filters.Add(filter); win7OpenFileDialog.FileOk += win7OpenFileDialog_FileOk; /* add help listeners to win7OpenFileDialog */ // declare variables here so that the GC does not eat them. WndProcDelegate newWndProc, oldWndProc = null; win7OpenFileDialog.DialogOpening += (sender, e) => { var hwnd = win7OpenFileDialog.GetWindowHandle(); // hook into WndProc to catch WM_HELP, i.e. user pressed F1 newWndProc = (hWnd, msg, wParam, lParam) => { const short shellHelpCommand = 0x7091; var win32Msg = (Win32Types.Msg)msg; switch (win32Msg) { case Win32Types.Msg.WM_HELP: var helpInfo = (HELPINFO)Marshal.PtrToStructure(lParam, typeof(HELPINFO)); // Ignore if we are on an unknown control or control 100. // These are the windows shell control. The help command is // issued by these controls so by not ignoring, we would call // the help method twice. if (helpInfo.iCtrlId != 0 && helpInfo.iCtrlId != 100) { OnAddFromFileHelpRequested(win7OpenFileDialog, EventArgs.Empty); } return((IntPtr)1); // TRUE case Win32Types.Msg.WM_COMMAND: var wParamBytes = BitConverter.GetBytes(wParam.ToInt32()); var highWord = BitConverter.ToInt16(wParamBytes, 0); var lowWord = BitConverter.ToInt16(wParamBytes, 2); if (lowWord == 0 && highWord == shellHelpCommand) { OnAddFromFileHelpRequested(win7OpenFileDialog, EventArgs.Empty); return((IntPtr)0); } break; } return(CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam)); }; var newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc); var oldWndProcPtr = SetWindowLongPtr(hwnd, WindowLongFlags.GWL_WNDPROC, newWndProcPtr); oldWndProc = (WndProcDelegate) Marshal.GetDelegateForFunctionPointer(oldWndProcPtr, typeof(WndProcDelegate)); }; var result = win7OpenFileDialog.ShowDialog(); if (result != CommonFileDialogResult.Ok) { return; } if (confirmConstraintCheckBox.IsChecked) { var constraint = new Agent.KeyConstraint(); constraint.Type = Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_CONFIRM; constraints.Add(constraint); } if (lifetimeConstraintCheckBox.IsChecked) { // error checking for parse done in fileOK event handler uint lifetime = uint.Parse(lifetimeConstraintTextBox.Text); var constraint = new Agent.KeyConstraint(); constraint.Type = Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_LIFETIME; constraint.Data = lifetime; constraints.Add(constraint); } fileNames = win7OpenFileDialog.FileNames.ToArray(); } else { using (var openFileDialog = new OpenFileDialog()) { openFileDialog.Multiselect = true; openFileDialog.Filter = string.Join("|", Strings.filterPuttyPrivateKeyFiles, "*.ppk", Strings.filterAllFiles, "*.*"); openFileDialog.FileOk += xpOpenFileDialog_FileOk; // Windows XP uses old style file open dialog that can be extended // using the Windows API via FileDlgExtenders library XPOpenFileDialog xpOpenFileDialog = null; if (Type.GetType("Mono.Runtime") == null) { xpOpenFileDialog = new XPOpenFileDialog(); xpOpenFileDialog.FileDlgStartLocation = AddonWindowLocation.Bottom; mOpenFileDialogMap.Add(openFileDialog, xpOpenFileDialog); } openFileDialog.HelpRequest += OnAddFromFileHelpRequested; // TODO: technically, a listener could be added after this openFileDialog.ShowHelp = AddFromFileHelpRequested != null; var result = xpOpenFileDialog == null? openFileDialog.ShowDialog() : openFileDialog.ShowDialog(xpOpenFileDialog, null); if (result != DialogResult.OK) { return; } if (xpOpenFileDialog == null) { // If dialog could not be extended, then we add constraints by holding // down the control key when clicking the Open button. if (Control.ModifierKeys.HasFlag(Keys.Control)) { var constraintDialog = new ConstraintsInputDialog(); constraintDialog.ShowDialog(); if (constraintDialog.DialogResult == DialogResult.OK) { if (constraintDialog.ConfirmConstraintChecked) { constraints.AddConfirmConstraint(); } if (constraintDialog.LifetimeConstraintChecked) { constraints.AddLifetimeConstraint(constraintDialog.LifetimeDuration); } } } } else { mOpenFileDialogMap.Remove(openFileDialog); if (xpOpenFileDialog.UseConfirmConstraintChecked) { constraints.AddConfirmConstraint(); } if (xpOpenFileDialog.UseLifetimeConstraintChecked) { constraints.AddLifetimeConstraint (xpOpenFileDialog.LifetimeConstraintDuration); } } fileNames = openFileDialog.FileNames; } } UseWaitCursor = true; mAgent.AddKeysFromFiles(fileNames, constraints); if (!(mAgent is Agent)) { ReloadKeyListView(); } UseWaitCursor = false; }
private void OnClickImageReplace(object sender, EventArgs e) { if (imageListView.SelectedIndices.Count < 1) { MessageBox.Show(Resources.DialogSelectImage, Resources.DialogInfo); return; } CommonFileDialogCheckBox correctColorCb = new CommonFileDialogCheckBox("correctColorCb", Resources.DialogCorrectColor, false); CommonOpenFileDialog fileDialog = new CommonOpenFileDialog(Resources.DialogReplaceImage) { Filters = { new CommonFileDialogFilter("PNG", "*.png"), new CommonFileDialogFilter("JPEG", "*.jpg;*.jpeg"), new CommonFileDialogFilter(Resources.DialogAllFiles, "*.*") }, Controls = { correctColorCb }, RestoreDirectory = true }; if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) { int selected = imageListView.SelectedIndices[0]; string filepath = fileDialog.FileName; byte[] filedata = File.ReadAllBytes(filepath); ImageFormat originalFormat = originalImageFormats[selected]; using (MemoryStream stream = new MemoryStream(filedata, false)) { Image imageLoaded = Image.FromStream(stream); if (!correctColorCb.IsChecked && originalFormat == imageLoaded.RawFormat) { originalImagesData[selected] = filedata; } else { if (correctColorCb.IsChecked) { ImageUtils.ReverseColorRB((Bitmap)imageLoaded); } MemoryStream saveStream = new MemoryStream(); imageLoaded.Save(saveStream, originalFormat); originalImagesData[selected] = saveStream.ToArray(); saveStream.Dispose(); } imageList.Images[selected].Dispose(); imageList.Images[selected] = ImageUtils.CreateThumbnail(imageLoaded, imageList.ImageSize); imageListView.Items[selected].Text = $"{imageLoaded.Width}x{imageLoaded.Height}"; imageLoaded.Dispose(); } shouldSaveFui = true; } }
private void ChkOptionB_CheckedChanged(object sender, EventArgs e) { CommonFileDialogCheckBox checkBox = currentFileDialog.Controls["chkOptionB"] as CommonFileDialogCheckBox; MessageBox.Show(String.Format("Check Box \"{0}\" has been {1}", checkBox.Text, checkBox.IsChecked ? "Checked" : "Unchecked")); }
public bool NewFile() { var sfd = new CommonSaveFileDialog("New Rule File"); sfd.EnsurePathExists = true; sfd.InitialDirectory = analyzer.BasePath; sfd.DefaultFileName = "BPARules.json"; sfd.DefaultExtension = "json"; sfd.Filters.Add(new CommonFileDialogFilter("JSON file", "*.json")); sfd.Filters.Add(new CommonFileDialogFilter("All files", "*.*")); var localPathCheckBox = new CommonFileDialogCheckBox("Use relative path", true) { Visible = false }; if (UIController.Current.File_Current != null) { sfd.Controls.Add(localPathCheckBox); localPathCheckBox.Visible = true; sfd.FolderChanging += (s, e) => { var relativePath = FileSystemHelper.GetRelativePath(analyzer.BasePath, e.Folder); if (relativePath.Length >= 2 && relativePath[1] == ':') { localPathCheckBox.Visible = false; } else { localPathCheckBox.Visible = true; } }; } parent.Enabled = false; if (sfd.ShowDialog() == CommonFileDialogResult.Ok) { parent.Enabled = true; try { File.WriteAllText(sfd.FileName, "[]"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Unable to create rule file", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } var fileName = localPathCheckBox.Visible && localPathCheckBox.IsChecked ? FileSystemHelper.GetRelativePath(analyzer.BasePath, sfd.FileName) : sfd.FileName; if (!analyzer.ExternalRuleCollections.Any( rc => rc.FilePath != null && FileSystemHelper.GetAbsolutePath(analyzer.BasePath, rc.FilePath).EqualsI(sfd.FileName) )) { analyzer.ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromFile(analyzer.BasePath, fileName)); } return(true); } parent.Enabled = true; return(false); }
private void OnClickImagesSave(object sender, EventArgs e) { Dictionary <ImageFormat, string> extensions = new Dictionary <ImageFormat, string>() { { ImageFormat.Png, ".png" }, { ImageFormat.Jpeg, ".jpg" } }; CommonFileDialogCheckBox correctColorCb = new CommonFileDialogCheckBox("correctColorCb", Resources.DialogCorrectColor, false); CommonOpenFileDialog fileDialog = new CommonOpenFileDialog(Resources.DialogSaveSelectedImages) { Controls = { correctColorCb }, IsFolderPicker = true, RestoreDirectory = true }; if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok) { string directorySelected = fileDialog.FileName; string filepathBase = Path.Combine( directorySelected, Path.GetFileNameWithoutExtension(currentOpenFui) + "_{0}{1}"); int[] selectedIndices = imageListView.SelectedIndices.Cast <int>().ToArray(); for (int i = 0; i < selectedIndices.Length; i++) { int selected = selectedIndices[i]; ImageFormat imageFormat = originalImageFormats[selected]; FuiImageInfo imageInfo = fuiImageInfo[selected]; byte[] filedata = originalImagesData[selected]; string filepath; if (extensions.ContainsKey(imageFormat)) { string extension = extensions[imageFormat]; filepath = string.Format(filepathBase, i, extension); } else { filepath = string.Format(filepathBase, i, ".unknown"); } if (!correctColorCb.IsChecked) { File.WriteAllBytes(filepath, filedata); } else { using (MemoryStream stream = new MemoryStream(filedata, false)) { Image imageSave = Image.FromStream(stream); ImageUtils.ReverseColorRB((Bitmap)imageSave); imageSave.Save(filepath, imageFormat); imageSave.Dispose(); } } } } }