private void AddOpenFileDialogCustomControls(CommonFileDialog openDialog) { // Add a geometry type ComboBox CommonFileDialogGroupBox geoBox = new CommonFileDialogGroupBox("Geometry"); CommonFileDialogComboBox geoComboBox = new CommonFileDialogComboBox("geoComboBox"); geoComboBox.Items.Add(new CommonFileDialogComboBoxItem(".fbx")); geoComboBox.Items.Add(new CommonFileDialogComboBoxItem(".obj")); geoComboBox.SelectedIndex = 1; geoBox.Items.Add(geoComboBox); openDialog.Controls.Add(geoBox); // Add a texture ComboBox CommonFileDialogGroupBox texBox = new CommonFileDialogGroupBox("Texture"); CommonFileDialogComboBox texComboBox = new CommonFileDialogComboBox("texComboBox"); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".bmp")); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".jpg")); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".png")); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".tga")); texComboBox.SelectedIndex = 2; texBox.Items.Add(texComboBox); openDialog.Controls.Add(texBox); // Create and add a separator openDialog.Controls.Add(new CommonFileDialogSeparator()); // Add a world or local space option openDialog.Controls.Add(new CommonFileDialogCheckBox("worldSpaceCheckBox", "World Space", false)); // Add a multiple objects or single merged object openDialog.Controls.Add(new CommonFileDialogCheckBox("mergeCheckBox", "Merge", false)); }
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); }
protected override void OnPreviewShowDialog(InteractionNotification context, object dialog) { if (!(context is SaveFileNotificationEx contextEx) || !(dialog is CommonFileDialog fileDialog)) { return; } var encodingComboBox = FileActionExtensions.ConvertToComboBox(contextEx.Encoding); var encodingGroupBox = new CommonFileDialogGroupBox($"{Resources.Label_Encoding}(&E):"); encodingGroupBox.Items.Add(encodingComboBox); fileDialog.Controls.Add(encodingGroupBox); base.OnPreviewShowDialog(context, dialog); }
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> /// This code snippet demonstrates how to add custom controls in the Common File /// Dialog. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddCustomControls_Click(object sender, EventArgs e) { // Create a new common open file dialog CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog(); // Prepare the controls to be added and the relationship among // the controls CommonFileDialogGroupBox grp = new CommonFileDialogGroupBox( "grp", "Change Title to "); CommonFileDialogRadioButtonList radl = new CommonFileDialogRadioButtonList("radl"); grp.Items.Add(radl); radl.Items.Add(new CommonFileDialogRadioButtonListItem("Windows Vista")); radl.Items.Add(new CommonFileDialogRadioButtonListItem("Windows 7")); radl.SelectedIndexChanged += new EventHandler(radl_SelectedIndexChanged); // Add the firt-level control to the CommonFileDialog.Controls // collection to apply the changes of controls. openFileDialog.Controls.Add(grp); // Show the dialog if (openFileDialog.ShowDialog() == CommonFileDialogResult.OK) { // Get the value of the controls added to the dialog if (radl.SelectedIndex >= 0) { MessageBox.Show(radl.Items[radl.SelectedIndex].Text, "The selected Title is"); } else { MessageBox.Show("No Title was selected"); } } }
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); }
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; }
bool Save(SaveOperation operation) { if (!CanSave) { return(false); } var saveOperation = Session.CreateWorkbookSaveOperation(); var savePath = Session.Workbook.LogicalPath; if (savePath.IsNull || operation == SaveOperation.SaveAs) { var saveDialog = new CommonSaveFileDialog { Title = Catalog.GetString("Save Workbook"), DefaultFileName = Session.Title, AlwaysAppendDefaultExtension = true, DefaultExtension = ".workbook" }; if (!savePath.IsNull) { saveDialog.InitialDirectory = savePath.DirectoryExists ? savePath.ParentDirectory : savePath; } saveDialog.FolderChanging += (o, e) => { if (e.Folder.EndsWith(".workbook", StringComparison.OrdinalIgnoreCase)) { e.Cancel = true; } }; saveDialog.Filters.Add(new CommonFileDialogFilter("Xamarin Workbook", ".workbook")); CommonFileDialogComboBox formatComboBox = null; if (saveOperation.SupportedOptions.HasFlag(WorkbookSaveOptions.Archive)) { formatComboBox = new CommonFileDialogComboBox(); formatComboBox.Items.Add(new CommonFileDialogComboBoxItem( Catalog.GetString("Package Directory"))); formatComboBox.Items.Add(new CommonFileDialogComboBoxItem( Catalog.GetString("Archive"))); formatComboBox.SelectedIndex = saveOperation.Options.HasFlag( WorkbookSaveOptions.Archive) ? 1 : 0; var formatGroup = new CommonFileDialogGroupBox("Workbook Format:"); formatGroup.Items.Add(formatComboBox); saveDialog.Controls.Add(formatGroup); } if (saveDialog.ShowDialog(this) != CommonFileDialogResult.Ok) { return(false); } if (formatComboBox != null) { switch (formatComboBox.SelectedIndex) { case 0: saveOperation.Options &= ~WorkbookSaveOptions.Archive; break; case 1: saveOperation.Options |= WorkbookSaveOptions.Archive; break; default: throw new IndexOutOfRangeException(); } } savePath = saveDialog.FileName; saveOperation.Destination = savePath; } var success = false; try { Session.SaveWorkbook(saveOperation); NoteRecentDocument(); success = true; IsDirty = false; } catch (Exception e) { Log.Error(TAG, e); } return(success); }