예제 #1
0
        public void AddControl(NSControl control, string text)
        {
            int minWidth       = string.IsNullOrEmpty(text) ? 0 : 200;
            var labelAlignment = new MDAlignment(new MDLabel(text)
            {
                Alignment = NSTextAlignment.Right
            }, true);

            labels.Add(labelAlignment);

            var controlAlignment = new MDAlignment(control, true)
            {
                MinWidth = minWidth
            };

            controls.Add(controlAlignment);

            Add(new MDBox(LayoutDirection.Horizontal, 2, 0)
            {
                { labelAlignment },
                { controlAlignment },
            });
        }
예제 #2
0
        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;
                    }
                };

                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 = 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)
		{
			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;
		}
예제 #4
0
        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,
                    };
                }
                bool pathAlreadySet = false;
                panel.DidChangeToDirectory += (sender, e) => {
                    var directoryPath = e.NewDirectoryUrl?.AbsoluteString;
                    if (string.IsNullOrEmpty(directoryPath))
                    {
                        return;
                    }
                    var selectedPath = data.OnDirectoryChanged(this, directoryPath);
                    if (selectedPath.IsNull)
                    {
                        return;
                    }
                    data.SelectedFiles = new FilePath [] { selectedPath };
                    pathAlreadySet     = true;

                    // We need to call Cancel on 1ms delay so it's executed after DidChangeToDirectory event handler is finished
                    // this is needed because it's possible that DidChangeToDirectory event is executed while dialog is opening
                    // in that case calling .Cancel() leaves dialog in weird state...
                    // Fun fact: DidChangeToDirectory event is called from Open on 10.12 but not on 10.13
                    System.Threading.Tasks.Task.Delay(1).ContinueWith(delegate { panel.Cancel(panel); }, Runtime.MainTaskScheduler);
                };
                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> ();
                var controls = 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:"))
                        {
                            Alignment = NSTextAlignment.Right
                        }, true);
                        var filterPopupAlignment = new MDAlignment(filterPopup, true)
                        {
                            MinWidth = 200
                        };
                        var filterBox = new MDBox(LayoutDirection.Horizontal, 2, 0)
                        {
                            { filterLabel },
                            { filterPopupAlignment }
                        };
                        labels.Add(filterLabel);
                        controls.Add(filterPopupAlignment);
                        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:"))
                        {
                            Alignment = NSTextAlignment.Right
                        }, true);
                        var encodingSelectorAlignment = new MDAlignment(encodingSelector, true)
                        {
                            MinWidth = 200
                        };
                        var encodingBox = new MDBox(LayoutDirection.Horizontal, 2, 0)
                        {
                            { encodingLabel },
                            { encodingSelectorAlignment }
                        };
                        labels.Add(encodingLabel);
                        controls.Add(encodingSelectorAlignment);
                        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.Enabled != workbenchViewerSelected)
                                    {
                                        closeSolutionButton.Enabled = workbenchViewerSelected;
                                        closeSolutionButton.State   = workbenchViewerSelected ? NSCellStateValue.On : NSCellStateValue.Off;
                                    }
                                }
                            };
                        }

                        if (IdeApp.Workspace.IsOpen)
                        {
                            closeSolutionButton = new NSButton {
                                Title   = GettextCatalog.GetString("Close current workspace"),
                                Enabled = false,
                                State   = NSCellStateValue.Off,
                            };

                            closeSolutionButton.SetButtonType(NSButtonType.Switch);
                            closeSolutionButton.SizeToFit();

                            var closeSolutionLabelBox        = new MDAlignment(new MDLabel(string.Empty), true);
                            var closeSolutionButtonAlignment = new MDAlignment(closeSolutionButton, true);
                            var closeSolutionBox             = new MDBox(LayoutDirection.Horizontal, 2, 0)
                            {
                                { closeSolutionLabelBox },
                                { closeSolutionButtonAlignment }
                            };

                            labels.Add(closeSolutionLabelBox);
                            controls.Add(closeSolutionButtonAlignment);
                            box.Add(closeSolutionBox);
                        }

                        var viewSelLabel = new MDAlignment(new MDLabel(GettextCatalog.GetString("Open With:"))
                        {
                            Alignment = NSTextAlignment.Right
                        }, true);
                        var viewSelectorAlignemnt = new MDAlignment(viewerSelector, true)
                        {
                            MinWidth = 200
                        };
                        var viewSelBox = new MDBox(LayoutDirection.Horizontal, 2, 0)
                        {
                            { viewSelLabel },
                            { viewSelectorAlignemnt }
                        };

                        labels.Add(viewSelLabel);
                        controls.Add(viewSelectorAlignemnt);
                        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 (controls.Count > 0)
                {
                    float w = controls.Max(c => c.MinWidth);
                    foreach (var c in controls)
                    {
                        c.MinWidth = w;
                        c.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.Enabled = slnViewerSelected;
                            closeSolutionButton.State   = slnViewerSelected ? NSCellStateValue.On : NSCellStateValue.Off;
                        }
                    }
                    if (encodingSelector != null)
                    {
                        encodingSelector.Enabled = !slnViewerSelected;
                    }
                };

                if (panel.RunModal() == 0 && !pathAlreadySet)
                {
                    GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow);
                    return(false);
                }
                if (!pathAlreadySet)
                {
                    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);
        }
		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;
		}
        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);
        }
		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;
				}
				
				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 ();
					} 
					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 {
                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;
                }

                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();
                    }
                    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);
            } catch (Exception ex) {
                MessageService.ShowException(ex);
            } finally {
                if (panel != null)
                {
                    panel.Dispose();
                }
            }
            return(true);
        }