public bool Run (AddFileDialogData data) { var parent = data.TransientFor ?? MessageService.RootWindow; var dialog = new CommonOpenFileDialog (); SelectFileDialogHandler.SetCommonFormProperties (data, dialog); var buildActionCombo = new CommonFileDialogComboBox (); var group = new CommonFileDialogGroupBox ("overridebuildaction", "Override build action:"); buildActionCombo.Items.Add (new CommonFileDialogComboBoxItem (GettextCatalog.GetString ("Default"))); foreach (var ba in data.BuildActions) { if (ba == "--") continue; buildActionCombo.Items.Add (new CommonFileDialogComboBoxItem (ba)); } buildActionCombo.SelectedIndex = 0; group.Items.Add (buildActionCombo); dialog.Controls.Add (group); if (!GdkWin32.RunModalWin32Dialog (dialog, parent)) return false; SelectFileDialogHandler.GetCommonFormProperties (data, dialog); var idx = buildActionCombo.SelectedIndex; if (idx > 0) data.OverrideAction = buildActionCombo.Items [idx].Text; return true; }
/// <summary> /// Recursively searches for a given control id in the /// collection passed via the <paramref name="controlCollection"/> parameter. /// </summary> /// /// <param name="controlCollection">A Collection<CommonFileDialogControl></param> /// <param name="id">An int containing the identifier of the control /// being searched for.</param> /// /// <returns>A DialogControl who's Id matches the value of the /// <paramref name="id"/> parameter.</returns> /// public DialogControl GetSubControlbyId(IEnumerable <DialogControl> controlCollection, int id) { // if ctrlColl is null, it will throw in the foreach. if (controlCollection == null) { return(null); } foreach (DialogControl control in controlCollection) { if (control.Id == id) { return(control); } // Search GroupBox child items CommonFileDialogGroupBox groupBox = control as CommonFileDialogGroupBox; if (groupBox != null) { var temp = GetSubControlbyId(groupBox.Items, id); if (temp != null) { return(temp); } } } return(null); }
/// <summary> /// Recursively searches for a given control id in the /// collection passed via the <paramref name="ctrlColl"/> parameter. /// </summary> /// /// <param name="ctrlColl">A Collection<CommonFileDialogControl></param> /// <param name="id">An int containing the identifier of the control /// being searched for.</param> /// /// <returns>A DialogControl who's Id matches the value of the /// <paramref name="id"/> parameter.</returns> /// internal DialogControl GetSubControlbyId(IEnumerable ctrlColl, int id) { DialogControl foundControl = null; int iSubCtrlCount = 0; // if ctrlColl is null, it will throw in the foreach. if (ctrlColl == null) { return(null); } foreach (DialogControl control in ctrlColl) { // Match? if (control.Id == id) { return(control); } // Search GroupBox child items if (control is CommonFileDialogGroupBox) { CommonFileDialogGroupBox groupBox = control as CommonFileDialogGroupBox; // recurse and search the GroupBox iSubCtrlCount = ((CommonFileDialogGroupBox)control).Items.Count; if (iSubCtrlCount > 0) { foundControl = this.GetSubControlbyId( groupBox.Items as IEnumerable, id); // make sure something was actually found if (foundControl != null) { return(foundControl); } } } } // Control id not found - likely an error, but the calling // function should ultimately decide. return(null); }
private void AddOpenFileDialogCustomControls(CommonFileDialog openDialog) { // Add a RadioButtonList CommonFileDialogRadioButtonList list = new CommonFileDialogRadioButtonList("radioButtonOptions"); 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("chkOptionA", "Option A", false); CommonFileDialogCheckBox checkB = new CommonFileDialogCheckBox("chkOptionB", "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 openDialog.Controls.Add(new CommonFileDialogSeparator()); // Add groupbox to dialog openDialog.Controls.Add(groupBox); // Add a Menu CommonFileDialogMenu menu = new CommonFileDialogMenu("menu","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 ComboBox CommonFileDialogComboBox comboBox = new CommonFileDialogComboBox("comboBox"); 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); // Create and add a separator openDialog.Controls.Add(new CommonFileDialogSeparator()); // Add a TextBox openDialog.Controls.Add(new CommonFileDialogLabel("Name:")); openDialog.Controls.Add(new CommonFileDialogTextBox("textName", Environment.UserName)); // Create and add a button to this group CommonFileDialogButton btnCFDPushButton = new CommonFileDialogButton("Check Name"); btnCFDPushButton.Click += PushButton_Click; openDialog.Controls.Add(btnCFDPushButton); }
public bool Run (OpenFileDialogData data) { var parent = data.TransientFor ?? MessageService.RootWindow; CommonFileDialog dialog; if (data.Action == FileChooserAction.Open) dialog = new CustomCommonOpenFileDialog (); else dialog = new CommonSaveFileDialog (); SelectFileDialogHandler.SetCommonFormProperties (data, dialog); 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 (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; dialog.ApplyControlPropertyChange ("Items", viewerCombo); } catch (Exception ex) { LoggingService.LogError (e.ToString ()); } }; } if (!GdkWin32.RunModalWin32Dialog (dialog, parent)) return false; SelectFileDialogHandler.GetCommonFormProperties (data, dialog); if (encodingCombo != null) data.Encoding = ((EncodingComboItem)encodingCombo.Items [encodingCombo.SelectedIndex]).Encoding; if (viewerCombo != null) { if (closeSolution != null) data.CloseCurrentWorkspace = closeSolution.Visible && closeSolution.IsChecked; data.SelectedViewer = ((ViewerComboItem)viewerCombo.Items [viewerCombo.SelectedIndex]).Viewer; } return true; }
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 += delegate(object aSender, EventArgs aEventArgs) { 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; }