Inheritance: IDialogControlHost, IDisposable
        private void OpenFileDialogCustomizationClicked(object sender, RoutedEventArgs e)
        {
            CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog();
            currentFileDialog = openFileDialog;

            ApplyOpenDialogSettings(openFileDialog);
            
            // set the 'allow multi-select' flag
            openFileDialog.Multiselect = true;

            openFileDialog.EnsureFileExists = true;

            AddOpenFileDialogCustomControls(openFileDialog);

            CommonFileDialogResult result = openFileDialog.ShowDialog();
            if (result == CommonFileDialogResult.Ok)
            {
                string output = "";
                foreach (string fileName in openFileDialog.FileNames)
                {
                    output += fileName + Environment.NewLine;
                }
                
                output += Environment.NewLine + GetCustomControlValues();

                MessageBox.Show(output, "Files Chosen", MessageBoxButton.OK, MessageBoxImage.Information );
            }
        }
		static void SetDefaultExtension (SelectFileDialogData data, CommonFileDialog dialog)
		{
			var defExt = data.DefaultFilter == null ? null : data.DefaultFilter.Patterns.FirstOrDefault ();
			if (defExt == null)
				return;
			// FileDialog doesn't show the file extension when saving a file,
			// so we try to look for the precise filter if none was specified.
			if (!string.IsNullOrEmpty (data.InitialFileName) && data.Action == FileChooserAction.Save && defExt == "*") {
				string ext = Path.GetExtension (data.InitialFileName);
				if (!string.IsNullOrEmpty (ext)) {
					var pattern = "*" + ext;
					foreach (var f in data.Filters) {
						foreach (var p in f.Patterns) {
							if (string.Equals (p, pattern, StringComparison.OrdinalIgnoreCase)) {
								dialog.DefaultExtension = p.TrimStart ('*', '.');
								return;
							}
						}
					}
				}
			}

			defExt = defExt.Trim();
			defExt = defExt.Replace("*.", null);
			defExt = defExt.Replace(".", null);

			dialog.DefaultExtension = defExt;
		}
		public static bool RunModalWin32Dialog (CommonFileDialog dialog, Gtk.Window parent)
		{
			while (Gtk.Application.EventsPending ())
				Gtk.Application.RunIteration ();

			IntPtr ph = HgdiobjGet (parent.GdkWindow);

			IntPtr hdlg = IntPtr.Zero;
			dialog.DialogOpening += delegate {
				try {
					hdlg = GetDialogHandle (dialog);
					SetGtkDialogHook (hdlg);
				} catch (Exception ex) {
					LoggingService.LogError ("Failed to hook win32 dialog messages", ex);
				}
			};

			bool result;
			try {
				result = dialog.ShowDialog (ph) == CommonFileDialogResult.Ok;
			} finally {
				if (hdlg != IntPtr.Zero)
					ClearGtkDialogHook (hdlg);
			}
			return result;
		}
		internal static void GetCommonFormProperties (SelectFileDialogData data, CommonFileDialog dialog)
		{
			var fileDialog = dialog as CommonOpenFileDialog;
			if (fileDialog != null)
				data.SelectedFiles = fileDialog.FileNames.Select (f => (FilePath) f).ToArray ();
			else
				data.SelectedFiles = new[] {(FilePath) dialog.FileName};
		}
Exemple #5
0
            public HResult OnFolderChanging(IFileDialog pfd, IShellItem psiFolder)
            {
                CommonFileDialogFolderChangeEventArgs args = new CommonFileDialogFolderChangeEventArgs(
                    CommonFileDialog.GetFileNameFromShellItem(psiFolder));

                if (!firstFolderChanged) { parent.OnFolderChanging(args); }

                return (args.Cancel ? HResult.False : HResult.Ok);
            }
		internal static void SetCommonFormProperties (SelectFileDialogData data, CommonFileDialog dialog)
		{
			if (!string.IsNullOrEmpty (data.Title))
				dialog.Title = data.Title;

			dialog.InitialDirectory = data.CurrentFolder;

			var fileDialog = dialog as CommonOpenFileDialog;
			if (fileDialog != null) {
				fileDialog.Multiselect = data.SelectMultiple;
				if (data.Action == FileChooserAction.SelectFolder) {
					fileDialog.IsFolderPicker = true;
					return;
				}
			}

			SetFilters (data, dialog);

			dialog.DefaultFileName = data.InitialFileName;
		}
        private void SaveFileDialogCustomizationXamlClicked(object sender, RoutedEventArgs e)
        {
            CommonSaveFileDialog saveFileDialog = FindSaveFileDialog("CustomSaveFileDialog");
            saveFileDialog.CookieIdentifier = saveDialogGuid;

            saveFileDialog.Filters.Add(new CommonFileDialogFilter("My App Type", "*.xyz"));
            saveFileDialog.DefaultExtension = "xyz";
            saveFileDialog.AlwaysAppendDefaultExtension = true;

            saveFileDialog.Controls["textName"].Text = Environment.UserName;

            currentFileDialog = saveFileDialog;

            CommonFileDialogResult result = saveFileDialog.ShowDialog();
            if (result == CommonFileDialogResult.Ok)
            {
                string output = "File Selected: " + saveFileDialog.FileName + Environment.NewLine;
                output += Environment.NewLine + GetCustomControlValues();

                MessageBox.Show(output, "Save File Dialog Result", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
        private void ApplyOpenDialogSettings(CommonFileDialog openFileDialog)
        {
            openFileDialog.Title = "Custom Open File Dialog";

            openFileDialog.CookieIdentifier = openDialogGuid;
            
            // Add some standard filters.
            openFileDialog.Filters.Add(CommonFileDialogStandardFilters.TextFiles);
            openFileDialog.Filters.Add(CommonFileDialogStandardFilters.OfficeFiles);
            openFileDialog.Filters.Add(CommonFileDialogStandardFilters.PictureFiles);
        }
		//for some reason, the API pack doesn't expose this method from the COM interface
		static List<string> GetSelectedItems (CommonFileDialog dialog)
		{
			var filenames = new List<string> ();
			var nativeDialog = (IFileOpenDialog)dialog.nativeDialog;
			IShellItemArray resultsArray;
			uint count;

			try {
				nativeDialog.GetSelectedItems (out resultsArray);
			} catch (Exception ex) {
				//we get E_FAIL when there is no selection
				var ce = ex.InnerException as COMException;
				if (ce != null && ce.ErrorCode == -2147467259)
					return filenames;
				throw;
			}

			var hr = (int)resultsArray.GetCount (out count);
			if (hr != 0)
				throw Marshal.GetExceptionForHR (hr);

			for (int i = 0; i < count; ++i) {
				var item = CommonFileDialog.GetShellItemAt (resultsArray, i);
				string val = CommonFileDialog.GetFileNameFromShellItem (item);
				filenames.Add (val);
			}

			return filenames;
		}
 public NativeDialogEventSink(CommonFileDialog commonDialog)
 {
     this.parent = commonDialog;
 }
		static void SetFilters (SelectFileDialogData data, CommonFileDialog dialog)
		{
			foreach (var f in data.Filters)
				dialog.Filters.Add (new CommonFileDialogFilter (f.Name, string.Join (",", f.Patterns)));

			SetDefaultExtension (data, dialog);
		}
Exemple #12
0
		static IntPtr GetDialogHandle (CommonFileDialog dialog)
		{
			var f = typeof (CommonFileDialog).GetField ("nativeDialog", BindingFlags.NonPublic | BindingFlags.Instance);
			var obj = f.GetValue (dialog);
			var ow = (IOleWindow) obj;
			IntPtr handle;
			var hr = ow.GetWindow (out handle);
			if (hr != 0)
				throw Marshal.GetExceptionForHR (hr);
			return handle;
		}
		static IntPtr GetDialogHandle (CommonFileDialog dialog)
		{
			var ow = (IOleWindow)dialog.nativeDialog;
			IntPtr handle;
			var hr = ow.GetWindow (out handle);
			if (hr != 0)
				throw Marshal.GetExceptionForHR (hr);
			return handle;
		}
Exemple #14
0
 /// <summary>
 /// Determines if changes to a specific property are allowed.
 /// </summary>
 /// <param name="propertyName">The name of the property.</param>
 /// <param name="control">The control propertyName applies to.</param>
 /// <returns>true if the property change is allowed.</returns>
 public virtual bool IsControlPropertyChangeAllowed(string propertyName, DialogControl control)
 {
     CommonFileDialog.GenerateNotImplementedException();
     return false;
 }
Exemple #15
0
 public NativeDialogEventSink(CommonFileDialog commonDialog)
 {
     this.parent = commonDialog;
 }
        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 DirJunctionViewModel()
        {
            Deserialize();
            if(_model == null)
            {
                _model = new DirJunctionModel()
                {
                    LinkName = "NewLink",
                    LinkDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                    OutputReady = false,
                    CmdLineFeedback = "",
                };
            }

            _folderDialog = new CommonOpenFileDialog()
            {
                IsFolderPicker = true,
                DefaultDirectory = TargetPath,
            };

            CreateSelectTargetCommand();
            CreateSelectLinkDirectoryCommand();
            CreateCreateJunctionCommand();
            CreatePopupClickedCommand();
        }