bool RunDialog (OpenFileDialogData data)
		{			
			Application.EnableVisualStyles ();
			
			FileDialog fileDlg = null;
			if (data.Action == Gtk.FileChooserAction.Open)
				fileDlg = new OpenFileDialog ();
			else
				fileDlg = new SaveFileDialog ();
			
			var dlg = new CustomOpenFileDialog (fileDlg, data);
				
			SelectFileDialogHandler.SetCommonFormProperties (data, dlg.FileDialog);
			
			using (dlg) {
				rootForm = new WinFormsRoot ();
				if (dlg.ShowDialog (rootForm) == DialogResult.Cancel) {
					return false;
				}
	
				FilePath[] paths = new FilePath [fileDlg.FileNames.Length];
				for (int n = 0; n < fileDlg.FileNames.Length; n++)	
					paths [n] = fileDlg.FileNames [n];
				data.SelectedFiles = paths;
				
				if (dlg.SelectedEncodingId != null)
					data.Encoding = dlg.SelectedEncodingId > 0 ? Encoding.GetEncoding (dlg.SelectedEncodingId) : null;
				if (dlg.SelectedViewer != null)
					data.SelectedViewer = dlg.SelectedViewer;
				
				data.CloseCurrentWorkspace = dlg.CloseCurrentWorkspace;
			}
			
			return true;
		}
		const int DialogWidth = 460; // predefined/desired width
		
		public CustomOpenFileDialog (FileDialog dialog, OpenFileDialogData data)
			: base (dialog)
		{
			Initialize (data);
			
			StartLocation = AddonWindowLocation.Bottom;
		}
		public bool Run (OpenFileDialogData data)
		{
			var parentWindow = data.TransientFor ?? MessageService.RootWindow;
			parentWindow.FocusInEvent += OnParentFocusIn;

			bool result = SelectFileDialogHandler.RunWinUIMethod (RunDialog, data);

			parentWindow.FocusInEvent -= OnParentFocusIn;
			parentWindow.Present ();

			return result;
		}
		public CustomOpenFileDialog (FileDialog dialog, OpenFileDialogData data)
			: base (dialog)
		{
			Initialize (data);
			
			StartLocation = AddonWindowLocation.Bottom;

			// Use the classic dialogs, as the new ones (WPF based) can't handle child controls.
			if (data.ShowEncodingSelector || data.ShowViewerSelector) {
				dialog.AutoUpgradeEnabled = false;
			}
		}
		public bool Run (OpenFileDialogData data)
		{			
			Application.EnableVisualStyles ();
			
			var parentWindow = data.TransientFor ?? MessageService.RootWindow;
			FileDialog fileDlg = null;
			if (data.Action == Gtk.FileChooserAction.Open)
				fileDlg = new OpenFileDialog ();
			else
				fileDlg = new SaveFileDialog ();
			
			var dlg = new CustomOpenFileDialog (fileDlg, data);
				
			SelectFileDialogHandler.SetCommonFormProperties (data, dlg.FileDialog);
			
			using (dlg) {
                if (dlg.ShowDialog () == DialogResult.Cancel) {
					parentWindow.Present ();
                    return false;
				}
	
				FilePath[] paths = new FilePath [fileDlg.FileNames.Length];
				for (int n = 0; n < fileDlg.FileNames.Length; n++)	
					paths [n] = fileDlg.FileNames [n];
				data.SelectedFiles = paths;
				
				if (dlg.SelectedEncodingId != null)
					data.Encoding = dlg.SelectedEncodingId;
				if (dlg.SelectedViewer != null)
					data.SelectedViewer = dlg.SelectedViewer;
				
				data.CloseCurrentWorkspace = dlg.CloseCurrentWorkspace;
			}
			
			parentWindow.Present ();
			return true;
		}
		public bool Run (OpenFileDialogData data)
		{
			NSSavePanel panel = null;
			
			try {
				bool directoryMode = data.Action != Gtk.FileChooserAction.Open
						&& data.Action != Gtk.FileChooserAction.Save;
				
				if (data.Action == Gtk.FileChooserAction.Save) {
					panel = new NSSavePanel ();
				} else {
					panel = new NSOpenPanel () {
						CanChooseDirectories = directoryMode,
						CanChooseFiles = !directoryMode,
					};
				}
				
				MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel);
				
				SelectEncodingPopUpButton encodingSelector = null;
				NSPopUpButton viewerSelector = null;
				NSButton closeSolutionButton = null;
				
				var box = new MDBox (LayoutDirection.Vertical, 2, 2);
				
				List<FileViewer> currentViewers = null;
				List<MDAlignment> labels = new List<MDAlignment> ();
				
				if (!directoryMode) {
					var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel);

					if (filterPopup != null) {
						var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true);
						var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ filterLabel },
							{ new MDAlignment (filterPopup, true) { MinWidth = 200 } }
						};
						labels.Add (filterLabel);
						box.Add (filterBox);
					}

					if (data.ShowEncodingSelector) {
						encodingSelector = new SelectEncodingPopUpButton (data.Action != Gtk.FileChooserAction.Save);
						encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0;
						
						var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true);
						var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ encodingLabel },
							{ new MDAlignment (encodingSelector, true) { MinWidth = 200 }  }
						};
						labels.Add (encodingLabel);
						box.Add (encodingBox);
					}
					
					if (data.ShowViewerSelector && panel is NSOpenPanel) {
						currentViewers = new List<FileViewer> ();
						viewerSelector = new NSPopUpButton () {
							Enabled = false,
						};
						
						if (encodingSelector != null) {
							viewerSelector.Activated += delegate {
								var idx = viewerSelector.IndexOfSelectedItem;
								encodingSelector.Enabled = ! (idx == 0 && currentViewers [0] == null);
							};
						}
						
						var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:"));
						var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ viewSelLabel, true },
							{ new MDAlignment (viewerSelector, true) { MinWidth = 200 }  }
						};
						
						if (IdeApp.Workspace.IsOpen) {
							closeSolutionButton = new NSButton () {
								Title = GettextCatalog.GetString ("Close current workspace"),
								Hidden = true,
								State = NSCellStateValue.On,
							};
							
							closeSolutionButton.SetButtonType (NSButtonType.Switch);
							closeSolutionButton.SizeToFit ();
							
							viewSelBox.Add (closeSolutionButton, true);
						}
						
						box.Add (viewSelBox);
					}
				}
				
				if (labels.Count > 0) {
					float w = labels.Max (l => l.MinWidth);
					foreach (var l in labels) {
						l.MinWidth = w;
						l.XAlign = LayoutAlign.Begin;
					}
				}
				
				if (box.Count > 0) {
					box.Layout ();
					panel.AccessoryView = box.View;
				}
				
				panel.SelectionDidChange += delegate(object sender, EventArgs e) {
					var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel);
					bool slnViewerSelected = false;
					if (viewerSelector != null) {
						FillViewers (currentViewers, viewerSelector, closeSolutionButton, selection);
						if (currentViewers.Count == 0 || currentViewers [0] != null) {
							if (closeSolutionButton != null)
								closeSolutionButton.Hidden = true;
							slnViewerSelected = false;
						} else {
							if (closeSolutionButton != null)
								closeSolutionButton.Hidden = false;
							slnViewerSelected = true;
						}
						box.Layout ();
						
						//re-center the accessory view in its parent, Cocoa does this for us initially and after
						//resizing the window, but we need to do it again after altering its layout
						var superFrame = box.View.Superview.Frame;
						var frame = box.View.Frame;
						//not sure why it's ceiling, but this matches the Cocoa layout
						frame.X = (float)Math.Ceiling ((superFrame.Width - frame.Width) / 2);
						frame.Y = (float)Math.Ceiling ((superFrame.Height - frame.Height) / 2);
						box.View.Frame = frame;
					} 
					if (encodingSelector != null)
						encodingSelector.Enabled = !slnViewerSelected;
				};

				var action = MacSelectFileDialogHandler.RunPanel (data, panel);
				if (!action) {
					GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
					return false;
				}

				data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel);
				
				if (encodingSelector != null)
					data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding (encodingSelector.SelectedEncodingId) : null;
				
				if (viewerSelector != null ) {
					if (closeSolutionButton != null)
						data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off;
					data.SelectedViewer = currentViewers[viewerSelector.IndexOfSelectedItem];
				}
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			} catch (Exception ex) {
				LoggingService.LogError ("Error in Open File dialog", ex);
				MessageService.ShowException (ex);
			} finally {
				if (panel != null)
					panel.Dispose ();
			}
			return true;
		}
		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;
		}
		void Initialize (OpenFileDialogData data)
		{
			SuspendLayout ();
			
			Point location = new Point (10, 5); // start location for controls.
			int padding = 5;
			int height = padding * 2; // initial/minimum height.
			
			int labelWidth = GetMaxLabelWidth (data.ShowEncodingSelector, data.ShowViewerSelector);
			
			if (data.ShowEncodingSelector) {
				encodingLabel = new Label () {
					Text = GettextCatalog.GetString (EncodingText),
					Location = location,
					AutoSize = true
				};
				
				encodingBox = new EncodingBox (data.Action != Gtk.FileChooserAction.Save) {
					Location = new Point (labelWidth + 20, location.Y),
					Width = DialogWidth - (labelWidth + 20 + padding),
					SelectedEncodingId = data.Encoding,
					Enabled = false
				};
				
				Controls.AddRange (new Control [] { encodingLabel, encodingBox });
								
				location.Y = encodingLabel.Bottom + padding;
				height += encodingBox.Height + padding;
			}
			
			if (data.ShowViewerSelector && FileDialog is OpenFileDialog) {
				viewerLabel = new Label () {
					Text = GettextCatalog.GetString (ViewerText),
					Location = location,
					AutoSize = true
				};
				
				viewerBox = new ComboBox () {
					Location = new Point (labelWidth + 20, location.Y),
					Width = DialogWidth - (labelWidth + 20 + padding),
					DropDownStyle = ComboBoxStyle.DropDownList,
					Enabled = false
				};
				
				location.Y = viewerBox.Bottom + padding;
				height += viewerBox.Height + padding;
				
				if (IdeApp.Workspace.IsOpen) {
					closeSolutionBox = new CheckBox () {
						Text = GettextCatalog.GetString ("Close current workspace"),
						Location = location,
						AutoSize = true,
						Checked = true,
						Enabled = false
					};
					
					height += closeSolutionBox.Height + padding;
				}
				
				if (encodingBox != null) {
					viewerBox.SelectedIndexChanged += delegate {
						int idx = viewerBox.SelectedIndex;
						encodingBox.Enabled = !(idx == 0 && currentViewers [0] == null);	
					};
				}
				
				Controls.AddRange (new Control [] { viewerLabel, viewerBox });
				if (closeSolutionBox != null)
					Controls.Add (closeSolutionBox);
			}
			
			AutoScaleDimensions = new SizeF (6F, 13F);
			AutoScaleMode = AutoScaleMode.Font;
			Size = new Size (DialogWidth, height);
			
			ResumeLayout ();
		}
		public bool Run (OpenFileDialogData data)
		{
			NSSavePanel panel = null;
			
			try {
				bool directoryMode = data.Action != Gtk.FileChooserAction.Open
					&& data.Action != Gtk.FileChooserAction.Save;
				
				if (data.Action == Gtk.FileChooserAction.Save) {
					panel = new NSSavePanel ();
				} else {
					panel = new NSOpenPanel () {
						CanChooseDirectories = directoryMode,
						CanChooseFiles = !directoryMode,
					};
				}
				
				MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel);
				
				SelectEncodingPopUpButton encodingSelector = null;
				NSPopUpButton viewerSelector = null;
				NSButton closeSolutionButton = null;
				
				var box = new MDBox (LayoutDirection.Vertical, 2, 2);
				
				List<FileViewer> currentViewers = null;
				List<MDAlignment> labels = new List<MDAlignment> ();
				
				if (!directoryMode) {
					var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel);
					
					var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true);
					var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
						{ filterLabel },
						{ new MDAlignment (filterPopup, true) { MinWidth = 200 } }
					};
					labels.Add (filterLabel);
					box.Add (filterBox);
					
					if (data.ShowEncodingSelector) {
						encodingSelector = new SelectEncodingPopUpButton (data.Action != Gtk.FileChooserAction.Save);
						encodingSelector.SelectedEncodingId = data.Encoding;
						
						var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true);
						var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ encodingLabel },
							{ new MDAlignment (encodingSelector, true) { MinWidth = 200 }  }
						};
						labels.Add (encodingLabel);
						box.Add (encodingBox);
					}
					
					if (data.ShowViewerSelector && panel is NSOpenPanel) {
						currentViewers = new List<FileViewer> ();
						viewerSelector = new NSPopUpButton () {
							Enabled = false,
						};
						
						if (encodingSelector != null) {
							viewerSelector.Activated += delegate {
								var idx = viewerSelector.IndexOfSelectedItem;
								encodingSelector.Enabled = ! (idx == 0 && currentViewers[0] == null);
							};
						}
						
						var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:"));
						var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ viewSelLabel, true },
							{ new MDAlignment (viewerSelector, true) { MinWidth = 200 }  }
						};
						
						if (IdeApp.Workspace.IsOpen) {
							closeSolutionButton = new NSButton () {
								Title = GettextCatalog.GetString ("Close current workspace"),
								Hidden = true,
								State = NSCellStateValue.On,
							};
							
							closeSolutionButton.SetButtonType (NSButtonType.Switch);
							closeSolutionButton.SizeToFit ();
							
							viewSelBox.Add (closeSolutionButton, true);
						}
						
						box.Add (viewSelBox);
					}
				}
				
				if (labels.Count > 0) {
					float w = labels.Max (l => l.MinWidth);
					foreach (var l in labels) {
						l.MinWidth = w;
						l.XAlign = LayoutAlign.Begin;
					}
				}
				
				if (box.Count > 0) {
					box.Layout ();
					panel.AccessoryView = box.View;
					box.Layout (box.View.Superview.Frame.Size);
				}
				
				panel.SelectionDidChange += delegate(object sender, EventArgs e) {
					var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel);
					bool slnViewerSelected = false;
					if (viewerSelector != null) {
						FillViewers (currentViewers, viewerSelector, selection);
						if (currentViewers.Count == 0 || currentViewers[0] != null) {
							if (closeSolutionButton != null)
								closeSolutionButton.Hidden = true;
							slnViewerSelected = false;
						} else {
							if (closeSolutionButton != null)
								closeSolutionButton.Hidden = false;
							slnViewerSelected = true;
						}
						box.Layout (box.View.Superview.Frame.Size);
					} 
					if (encodingSelector != null)
						encodingSelector.Enabled = !slnViewerSelected;
				};
				
				try {
					var action = MacSelectFileDialogHandler.RunPanel (data, panel);
					if (!action) {
						GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
						return false;
					}
				} catch (Exception ex) {
					System.Console.WriteLine (ex);
					throw;
				}
				
				data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel);
				
				if (encodingSelector != null)
					data.Encoding = encodingSelector.SelectedEncodingId;
				
				if (viewerSelector != null ) {
					if (closeSolutionButton != null)
						data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off;
					data.SelectedViewer = currentViewers[viewerSelector.IndexOfSelectedItem];
				}
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
				return true;
			} finally {
				if (panel != null)
					panel.Dispose ();
			}
		}
		public bool Run (OpenFileDialogData data)
		{
			NSSavePanel panel = null;
			
			try {
				if (data.Action == FileChooserAction.Save) {
					panel = new NSSavePanel ();
				} else {
					panel = new NSOpenPanel {
						CanChooseDirectories = (data.Action & FileChooserAction.FolderFlags) != 0,
						CanChooseFiles = (data.Action & FileChooserAction.FileFlags) != 0,
					};
				}

				MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel);
				
				SelectEncodingPopUpButton encodingSelector = null;
				NSPopUpButton viewerSelector = null;
				NSButton closeSolutionButton = null;
				
				var box = new MDBox (LayoutDirection.Vertical, 2, 2);
				
				List<FileViewer> currentViewers = null;
				var labels = new List<MDAlignment> ();
				
				if ((data.Action & FileChooserAction.FileFlags) != 0) {
					var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel);

					if (filterPopup != null) {
						var filterLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Show files:")), true);
						var filterBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ filterLabel },
							{ new MDAlignment (filterPopup, true) { MinWidth = 200 } }
						};
						labels.Add (filterLabel);
						box.Add (filterBox);
					}

					if (data.ShowEncodingSelector) {
						encodingSelector = new SelectEncodingPopUpButton (data.Action != FileChooserAction.Save);
						encodingSelector.SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0;
						
						var encodingLabel = new MDAlignment (new MDLabel (GettextCatalog.GetString ("Encoding:")), true);
						var encodingBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ encodingLabel },
							{ new MDAlignment (encodingSelector, true) { MinWidth = 200 }  }
						};
						labels.Add (encodingLabel);
						box.Add (encodingBox);
					}
					
					if (data.ShowViewerSelector && panel is NSOpenPanel) {
						currentViewers = new List<FileViewer> ();
						viewerSelector = new NSPopUpButton {
							Enabled = false,
						};

						if (encodingSelector != null || IdeApp.Workspace.IsOpen) {
							viewerSelector.Activated += delegate {
								var idx = viewerSelector.IndexOfSelectedItem;
								bool workbenchViewerSelected = idx == 0 && currentViewers [0] == null;
								if (encodingSelector != null)
									encodingSelector.Enabled = !workbenchViewerSelected;
								if (closeSolutionButton != null) {
									if (closeSolutionButton.Hidden == workbenchViewerSelected) {
										closeSolutionButton.Hidden = !workbenchViewerSelected;
										CenterAccessoryView (box);
									}
								}
							};
						}
						
						var viewSelLabel = new MDLabel (GettextCatalog.GetString ("Open with:"));
						var viewSelBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
							{ viewSelLabel, true },
							{ new MDAlignment (viewerSelector, true) { MinWidth = 200 }  }
						};
						
						if (IdeApp.Workspace.IsOpen) {
							closeSolutionButton = new NSButton {
								Title = GettextCatalog.GetString ("Close current workspace"),
								Hidden = true,
								State = NSCellStateValue.On,
							};
							
							closeSolutionButton.SetButtonType (NSButtonType.Switch);
							closeSolutionButton.SizeToFit ();
							
							viewSelBox.Add (closeSolutionButton, true);
						}
						
						box.Add (viewSelBox);
					}
				}
				
				if (labels.Count > 0) {
					float w = labels.Max (l => l.MinWidth);
					foreach (var l in labels) {
						l.MinWidth = w;
						l.XAlign = LayoutAlign.Begin;
					}
				}
				
				if (box.Count > 0) {
					box.Layout ();
					panel.AccessoryView = box.View;
				}
				
				panel.SelectionDidChange += delegate {
					var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel);
					bool slnViewerSelected = false;
					if (viewerSelector != null) {
						slnViewerSelected = FillViewers (currentViewers, viewerSelector, closeSolutionButton, selection);
						if (closeSolutionButton != null)
							closeSolutionButton.Hidden = !slnViewerSelected;
						CenterAccessoryView (box);
					} 
					if (encodingSelector != null)
						encodingSelector.Enabled = !slnViewerSelected;
				};

				if (panel.RunModal () == 0) {
					GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
					return false;
				}

				data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel);
				
				if (encodingSelector != null)
					data.Encoding = encodingSelector.SelectedEncodingId > 0 ? Encoding.GetEncoding (encodingSelector.SelectedEncodingId) : null;
				
				if (viewerSelector != null ) {
					if (closeSolutionButton != null)
						data.CloseCurrentWorkspace = closeSolutionButton.State != NSCellStateValue.Off;
					data.SelectedViewer = viewerSelector.IndexOfSelectedItem >= 0 ?
						currentViewers[(int)viewerSelector.IndexOfSelectedItem] : null;
				}
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			} catch (Exception ex) {
				LoggingService.LogInternalError ("Error in Open File dialog", ex);
			} finally {
				if (panel != null)
					panel.Dispose ();
			}
			return true;
		}
		// We are required to compute the needed height to contain our controls
		// *before* the dialog is shown, thus we do it here as well as the vertical layout.
		// The X coords for our controls are set as soon as we get access to the native
		// dialog's controls, which happens to be when the OnShown event is fired.
		void Initialize (OpenFileDialogData data)
		{
			SuspendLayout ();

			int padding = 6;
			int y = padding;
			
			labelsWidth = GetMaxLabelWidth (data.ShowEncodingSelector, data.ShowViewerSelector);
			
			if (data.ShowEncodingSelector) {
				encodingLabel = new Label () {
					Text = GettextCatalog.GetString (EncodingText),
					Top = y,
					AutoSize = true
				};
				
				encodingBox = new EncodingBox (data.Action != Gtk.FileChooserAction.Save) {
					Top = y,
					SelectedEncodingId = data.Encoding != null ? data.Encoding.CodePage : 0,
				};
				encodingBox.Anchor = AnchorStyles.Left | AnchorStyles.Right;
				
				Controls.AddRange (new Control [] { encodingLabel, encodingBox });

				y += Math.Max (encodingLabel.Height, encodingBox.Height) + padding;
			}
			
			if (data.ShowViewerSelector && FileDialog is OpenFileDialog) {
				viewerLabel = new Label () {
					Text = GettextCatalog.GetString (ViewerText),
					Top = y,
					AutoSize = true
				};
				
				viewerBox = new ComboBox () {
					Top = y,
					DropDownStyle = ComboBoxStyle.DropDownList,
					Enabled = false
				};
				viewerBox.Anchor = AnchorStyles.Left | AnchorStyles.Right;
				
				y += Math.Max (viewerLabel.Height, viewerBox.Height) + padding;
				
				if (IdeApp.Workspace.IsOpen) {
					closeSolutionBox = new CheckBox () {
						Text = GettextCatalog.GetString ("Close current workspace"),
						Top = y,
						AutoSize = true,
						Checked = true,
						Enabled = false
					};
					
					y += closeSolutionBox.Height + padding;
				}
				
				if (encodingBox != null) {
					viewerBox.SelectedIndexChanged += delegate {
						int idx = viewerBox.SelectedIndex;
						encodingBox.Enabled = !(idx == 0 && currentViewers [0] == null);	
					};
				}
				
				Controls.AddRange (new Control [] { viewerLabel, viewerBox });
				if (closeSolutionBox != null)
					Controls.Add (closeSolutionBox);
			}
			
			AutoScaleDimensions = new SizeF (6F, 13F);
			AutoScaleMode = AutoScaleMode.Font;
			ClientSize = new Size (ClientSize.Width, y);
			
			ResumeLayout ();
		}
		public bool Run (OpenFileDialogData data)
		{
			throw new NotImplementedException ();
		}