Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
            public HResult OnFileOk(IFileDialog pfd)
            {
                CancelEventArgs args = new CancelEventArgs();

                parent.OnFileOk(args);

                if (!args.Cancel)
                {
                    // Make sure all custom properties are sync'ed
                    if (parent.Controls != null)
                    {
                        foreach (CommonFileDialogControl control in parent.Controls)
                        {
                            CommonFileDialogTextBox  textBox;
                            CommonFileDialogGroupBox groupBox;
                            ;

                            if ((textBox = control as CommonFileDialogTextBox) != null)
                            {
                                textBox.SyncValue();
                                textBox.Closed = true;
                            }
                            // Also check subcontrols
                            else if ((groupBox = control as CommonFileDialogGroupBox) != null)
                            {
                                foreach (CommonFileDialogControl subcontrol in groupBox.Items)
                                {
                                    CommonFileDialogTextBox textbox = subcontrol as CommonFileDialogTextBox;
                                    if (textbox != null)
                                    {
                                        textbox.SyncValue();
                                        textbox.Closed = true;
                                    }
                                }
                            }
                        }
                    }
                }

                return(args.Cancel ? HResult.False : HResult.Ok);
            }
Ejemplo n.º 3
0
        private void ButtonItem_ExportToFile_Click(object sender, EventArgs e)
        {
            var isMultiselect = IsMultiselect();
            CommonFileDialog sfd_SM64RM_ExportCustomObjectToFile;
            var tbxName      = new CommonFileDialogTextBox("rmobj.name", customObject.Name);
            var btnAddScript = new CommonFileDialogButton("rmobj.script", "Setup Script")
            {
                IsProminent = true
            };

            btnAddScript.Click  += BtnAddScript_Click;
            export_EmbeddedFiles = new EmbeddedFilesContainer();
            export_Script        = new PatchScript();

            if (isMultiselect && MessageBoxEx.Show(this, "You are going to export multiple custom objects. Do you want to save all objects to one single file (Yes) or do you want to save every single object to one file (No)?", "Export Custom Objects", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                sfd_SM64RM_ExportCustomObjectToFile = new CommonOpenFileDialog()
                {
                    IsFolderPicker = true
                }
            }
            ;
            else
            {
                isMultiselect = false;
                sfd_SM64RM_ExportCustomObjectToFile = new CommonSaveFileDialog()
                {
                    DefaultExtension = FILTER_CUSTOM_OBJECT_EXTENSIONS
                };
                sfd_SM64RM_ExportCustomObjectToFile.Filters.Add(new CommonFileDialogFilter(FILTER_CUSTOM_OBJECT_NAMES, FILTER_CUSTOM_OBJECT_EXTENSIONS));
            }

            sfd_SM64RM_ExportCustomObjectToFile.Controls.Add(tbxName);
            sfd_SM64RM_ExportCustomObjectToFile.Controls.Add(btnAddScript);

            if (sfd_SM64RM_ExportCustomObjectToFile.ShowDialog(Handle) == CommonFileDialogResult.Ok)
            {
                ExportObjects(sfd_SM64RM_ExportCustomObjectToFile.FileName, isMultiselect, tbxName.Text);
            }
        }
Ejemplo n.º 4
0
        /// <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);
                }
            }
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        private void PushButton_Click(object sender, EventArgs e)
        {
            CommonFileDialogTextBox textBox = currentFileDialog.Controls["textName"] as CommonFileDialogTextBox;

            MessageBox.Show(String.Format("\"Check Name\" Button Clicked; Name = {0}", textBox.Text));
        }