public bool Run (AddFileDialogData data)
		{
			using (var panel = new NSOpenPanel () {
				CanChooseDirectories = false,
				CanChooseFiles = true,
			}) {
				MacSelectFileDialogHandler.SetCommonPanelProperties (data, panel);
				
				var popup = new NSPopUpButton (new RectangleF (0, 0, 200, 28), false);
				var dropdownBox = new MDBox (LayoutDirection.Horizontal, 2, 0) {
					{ new MDLabel (GettextCatalog.GetString ("Override build action:")), true },
					{ new MDAlignment (popup, true) { MinWidth = 200 }  }
				};
				
				var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup (data, panel);
				if (filterPopup != null) {
					dropdownBox.Layout ();
					var box = new MDBox (LayoutDirection.Vertical, 2, 2) {
						dropdownBox.View,
						filterPopup,
					};
					box.Layout ();
					panel.AccessoryView = box.View;
					box.Layout (box.View.Superview.Frame.Size);
				} else {
					dropdownBox.Layout ();
					panel.AccessoryView = dropdownBox.View;
				}
				
				popup.AddItem (GettextCatalog.GetString ("(Default)"));
				popup.Menu.AddItem (NSMenuItem.SeparatorItem);
				
				foreach (var b in data.BuildActions) {
					if (b == "--")
						popup.Menu.AddItem (NSMenuItem.SeparatorItem);
					else
						popup.AddItem (b);
				}
				
				var action = MacSelectFileDialogHandler.RunPanel (data, panel);
				if (!action) {
					GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
					return false;
				}
				
				data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles (panel);
				
				var idx = popup.IndexOfSelectedItem - 2;
				if (idx >= 0)
					data.OverrideAction = data.BuildActions[idx];
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
				return true;
			}
		}
Пример #2
0
        public SelectEncodingPanel() : base()
        {
            var   size    = new SizeF(600, 400);
            float padding = 12;

            this.SetContentSize(size);

            var view     = new NSView(new RectangleF(0, 0, size.Width, size.Height));
            var okButton = new NSButton()
            {
                Title      = GettextCatalog.GetString("OK"),
                Bordered   = true,
                BezelStyle = NSBezelStyle.Rounded,
            };

            okButton.SetButtonType(NSButtonType.MomentaryPushIn);
            okButton.Activated += delegate {
                Dismiss(1);
            };
            this.DefaultButtonCell = okButton.Cell;

            var cancelButton = new NSButton()
            {
                Title      = GettextCatalog.GetString("Cancel"),
                Bordered   = true,
                BezelStyle = NSBezelStyle.Rounded,
            };

            cancelButton.Activated += delegate {
                Dismiss(0);
            };
            var buttonBox = new MDBox(LayoutDirection.Horizontal, padding, 0)
            {
                new MDAlignment(cancelButton, true)
                {
                    MinWidth = 96, MinHeight = 32
                },
                new MDAlignment(okButton, true)
                {
                    MinWidth = 96, MinHeight = 32
                },
            };

            buttonBox.Layout();
            var buttonView = buttonBox.View;
            var buttonRect = buttonView.Frame;

            buttonRect.Y     = 12;
            buttonRect.X     = size.Width - buttonRect.Width - padding;
            buttonView.Frame = buttonRect;
            view.AddSubview(buttonView);

            float buttonAreaTop = buttonRect.Height + padding * 2;

            var   label       = CreateLabel(GettextCatalog.GetString("Available encodings:"));
            var   labelSize   = label.Frame.Size;
            float labelBottom = size.Height - 12 - labelSize.Height;

            label.Frame = new RectangleF(12, labelBottom, labelSize.Width, labelSize.Height);
            view.AddSubview(label);

            var moveButtonWidth = 32;
            var tableHeight     = labelBottom - buttonAreaTop - padding;
            var tableWidth      = size.Width / 2 - padding * 3 - moveButtonWidth + padding / 2;

            allTable            = new NSTableView(new RectangleF(padding, buttonAreaTop, tableWidth, tableHeight));
            allTable.HeaderView = null;
            var allScroll = new NSScrollView(allTable.Frame)
            {
                BorderType          = NSBorderType.BezelBorder,
                AutohidesScrollers  = true,
                HasVerticalScroller = true,
                DocumentView        = allTable,
            };

            view.AddSubview(allScroll);

            float center = (size.Width + padding) / 2;

            var selectedLabel     = CreateLabel(GettextCatalog.GetString("Encodings shown in menu:"));
            var selectedLabelSize = selectedLabel.Frame.Size;

            selectedLabel.Frame = new RectangleF(center, labelBottom, selectedLabelSize.Width, selectedLabelSize.Height);
            view.AddSubview(selectedLabel);

            selectedTable            = new NSTableView(new RectangleF(center, buttonAreaTop, tableWidth, tableHeight));
            selectedTable.HeaderView = null;
            var selectedScroll = new NSScrollView(selectedTable.Frame)
            {
                BorderType          = NSBorderType.BezelBorder,
                AutohidesScrollers  = true,
                HasVerticalScroller = true,
                DocumentView        = selectedTable,
            };

            view.AddSubview(selectedScroll);

            float buttonLevel = tableHeight / 2 + buttonAreaTop;

            var goRightImage = NSImage.ImageNamed("NSGoRightTemplate");

            addButton = new NSButton(
                new RectangleF(tableWidth + padding * 2, buttonLevel + padding / 2,
                               moveButtonWidth, moveButtonWidth))
            {
                //Title = "\u2192",
                BezelStyle = NSBezelStyle.SmallSquare,
                Image      = goRightImage
            };
            addButton.Activated += Add;
            view.AddSubview(addButton);

            removeButton = new NSButton(
                new RectangleF(tableWidth + padding * 2, buttonLevel - padding / 2 - moveButtonWidth,
                               moveButtonWidth, moveButtonWidth))
            {
                //Title = "\u2190",
                BezelStyle = NSBezelStyle.SmallSquare,
                Image      = NSImage.ImageNamed("NSGoLeftTemplate"),
            };
            removeButton.Activated += Remove;
            view.AddSubview(removeButton);

            upButton = new NSButton(
                new RectangleF(center + tableWidth + padding, buttonLevel + padding / 2,
                               moveButtonWidth, moveButtonWidth))
            {
                //Title = "\u2191",
                BezelStyle = NSBezelStyle.SmallSquare,
                Image      = MakeRotatedCopy(goRightImage, 90),
            };
            upButton.Activated += MoveUp;
            view.AddSubview(upButton);

            downButton = new NSButton(
                new RectangleF(center + tableWidth + padding, buttonLevel - padding / 2 - moveButtonWidth,
                               moveButtonWidth, moveButtonWidth))
            {
                //Title = "\u2193",
                BezelStyle = NSBezelStyle.SmallSquare,
                Image      = MakeRotatedCopy(goRightImage, -90),
            };
            downButton.Activated += MoveDown;
            view.AddSubview(downButton);

            var allColumn = new NSTableColumn()
            {
                DataCell = new NSTextFieldCell()
                {
                    Wraps = true
                },
                Width = tableWidth
            };

            allTable.AddColumn(allColumn);
            allTable.DataSource = allSource = new EncodingSource(TextEncoding.SupportedEncodings);
            allTable.Delegate   = new EncodingAllDelegate(this);

            var selectedColumn = new NSTableColumn()
            {
                DataCell = new NSTextFieldCell()
                {
                    Wraps = true
                },
                Width = tableWidth
            };

            selectedTable.AddColumn(selectedColumn);
            selectedTable.DataSource = selectedSource = new EncodingSource(TextEncoding.ConversionEncodings);
            selectedTable.Delegate   = new EncodingSelectedDelegate(this);

            UpdateButtons();

            this.ContentView = view;
        }
		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 (AlertDialogData data)
		{
			using (var alert = new NSAlert ()) {
				
				if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
					alert.AlertStyle = NSAlertStyle.Critical;
				} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning) {
					alert.AlertStyle = NSAlertStyle.Warning;
				} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
					alert.AlertStyle = NSAlertStyle.Informational;
				}
				
				//FIXME: use correct size so we don't get horrible scaling?
				if (!string.IsNullOrEmpty (data.Message.Icon)) {
					var pix = ImageService.GetPixbuf (data.Message.Icon, Gtk.IconSize.Dialog);
					byte[] buf = pix.SaveToBuffer ("tiff");
					unsafe {
						fixed (byte* b = buf) {
							alert.Icon = new NSImage (NSData.FromBytes ((IntPtr)b, (uint)buf.Length));
						}
					}
				}
				
				alert.MessageText = data.Message.Text;
				alert.InformativeText = data.Message.SecondaryText ?? "";
				
				var buttons = data.Buttons.Reverse ().ToList ();
				
				for (int i = 0; i < buttons.Count - 1; i++) {
					if (i == data.Message.DefaultButton) {
						var next = buttons[i];
						for (int j = buttons.Count - 1; j >= i; j--) {
							var tmp = buttons[j];
							buttons[j] = next;
							next = tmp;
						}
						break;
					}
				}
				
				foreach (var button in buttons) {
					var label = button.Label;
					if (button.IsStockButton)
						label = Gtk.Stock.Lookup (label).Label;
					label = label.Replace ("_", "");
					
					//this message seems to be a standard Mac message since alert handles it specially
					if (button == AlertButton.CloseWithoutSave)
						label = GettextCatalog.GetString ("Don't Save");
					
					alert.AddButton (label);
				}
				
				
				NSButton[] optionButtons = null;
				if (data.Options.Count > 0) {
					var box = new MDBox (LayoutDirection.Vertical, 2, 2);
					optionButtons = new NSButton[data.Options.Count];
					
					for (int i = data.Options.Count - 1; i >= 0; i--) {
						var option = data.Options[i];
						var button = new NSButton () {
							Title = option.Text,
							Tag = i,
							State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
						};
						button.SetButtonType (NSButtonType.Switch);
						optionButtons[i] = button;
						box.Add (new MDAlignment (button, true) { XAlign = LayoutAlign.Begin });
					}
					
					box.Layout ();
					alert.AccessoryView = box.View;
				}
				
				NSButton applyToAllCheck = null;
				if (data.Message.AllowApplyToAll) {
					alert.ShowsSuppressionButton = true;
					applyToAllCheck = alert.SuppressionButton;
					applyToAllCheck.Title = GettextCatalog.GetString ("Apply to all");
				}
				
				alert.Layout ();
				
				int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
				
				data.ResultButton = buttons [result];
				
				if (optionButtons != null) {
					foreach (var button in optionButtons) {
						var option = data.Options[button.Tag];
						data.Message.SetOptionValue (option.Id, button.State != 0);
					}
				}
				
				if (applyToAllCheck != null && applyToAllCheck.State != 0)
					data.ApplyToAll = true;
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
Пример #5
0
		public SelectEncodingPanel () : base ()	
		{
			var size = new SizeF (600, 400);
			float padding = 12;
			this.SetContentSize (size);
			
			var view = new NSView (new RectangleF (0, 0, size.Width, size.Height));
			var okButton = new NSButton () {
				Title = GettextCatalog.GetString ("OK"),
				Bordered = true,
				BezelStyle = NSBezelStyle.Rounded,
			};
			okButton.SetButtonType (NSButtonType.MomentaryPushIn);
			okButton.Activated += delegate {
				Dismiss (1);
			};
			this.DefaultButtonCell = okButton.Cell;
			
			var cancelButton = new NSButton () {
				Title = GettextCatalog.GetString ("Cancel"),
				Bordered = true,
				BezelStyle = NSBezelStyle.Rounded,
			};
			cancelButton.Activated += delegate {
				Dismiss (0);
			};
			var buttonBox = new MDBox (LayoutDirection.Horizontal, padding, 0) {
				new MDAlignment (cancelButton, true) { MinWidth = 96, MinHeight = 32 },
				new MDAlignment (okButton, true) { MinWidth = 96, MinHeight = 32 },
			};
			buttonBox.Layout ();
			var buttonView = buttonBox.View;
			var buttonRect = buttonView.Frame;
			buttonRect.Y = 12;
			buttonRect.X = size.Width - buttonRect.Width - padding;
			buttonView.Frame = buttonRect;
			view.AddSubview (buttonView);
			
			float buttonAreaTop = buttonRect.Height + padding * 2;
			
			var label = CreateLabel (GettextCatalog.GetString ("Available encodings:"));
			var labelSize = label.Frame.Size;
			float labelBottom = size.Height - 12 - labelSize.Height;
			label.Frame = new RectangleF (12, labelBottom, labelSize.Width, labelSize.Height);
			view.AddSubview (label);
			
			var moveButtonWidth = 32;
			var tableHeight = labelBottom - buttonAreaTop - padding;
			var tableWidth = size.Width / 2 - padding * 3 - moveButtonWidth + padding / 2;
			
			allTable = new NSTableView (new RectangleF (padding, buttonAreaTop, tableWidth, tableHeight));
			allTable.HeaderView = null;
			var allScroll = new NSScrollView (allTable.Frame) {
				BorderType = NSBorderType.BezelBorder,
				AutohidesScrollers = true,
				HasVerticalScroller = true,
				DocumentView = allTable,
			};
			view.AddSubview (allScroll);
			
			float center = (size.Width + padding) / 2;
			
			var selectedLabel = CreateLabel (GettextCatalog.GetString ("Encodings shown in menu:"));
			var selectedLabelSize = selectedLabel.Frame.Size;
			selectedLabel.Frame = new RectangleF (center, labelBottom, selectedLabelSize.Width, selectedLabelSize.Height);
			view.AddSubview (selectedLabel);
			
			selectedTable = new NSTableView (new RectangleF (center, buttonAreaTop, tableWidth, tableHeight));
			selectedTable.HeaderView = null;
			var selectedScroll = new NSScrollView (selectedTable.Frame) {
				BorderType = NSBorderType.BezelBorder,
				AutohidesScrollers = true,
				HasVerticalScroller = true,
				DocumentView = selectedTable,
			};
			view.AddSubview (selectedScroll);
			
			float buttonLevel = tableHeight / 2 + buttonAreaTop;
			
			var goRightImage = NSImage.ImageNamed ("NSGoRightTemplate");
			
			addButton = new NSButton (
				new RectangleF (tableWidth + padding * 2, buttonLevel + padding / 2,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2192",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = goRightImage
			};
			addButton.Activated += Add;
			view.AddSubview (addButton);
			
			removeButton = new NSButton (
				new RectangleF (tableWidth + padding * 2, buttonLevel - padding / 2 - moveButtonWidth,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2190",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = NSImage.ImageNamed ("NSGoLeftTemplate"),
			};
			removeButton.Activated += Remove;
			view.AddSubview (removeButton);
			
			upButton = new NSButton (
				new RectangleF (center + tableWidth + padding, buttonLevel + padding / 2,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2191",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = MakeRotatedCopy (goRightImage, 90),
			};
			upButton.Activated += MoveUp;
			view.AddSubview (upButton);
			
			downButton = new NSButton (
				new RectangleF (center + tableWidth + padding, buttonLevel - padding / 2 - moveButtonWidth,
					moveButtonWidth, moveButtonWidth)) {
				//Title = "\u2193",
				BezelStyle = NSBezelStyle.SmallSquare,
				Image = MakeRotatedCopy (goRightImage, -90),
			};
			downButton.Activated += MoveDown;
			view.AddSubview (downButton);
			
			var allColumn = new NSTableColumn () {
				DataCell = new NSTextFieldCell () { Wraps = true },
				Width = tableWidth
			};
			allTable.AddColumn (allColumn);
			allTable.DataSource = allSource = new EncodingSource (TextEncoding.SupportedEncodings);
			allTable.Delegate = new EncodingAllDelegate (this);
			
			var selectedColumn = new NSTableColumn () {
				DataCell = new NSTextFieldCell () { Wraps = true },
				Width = tableWidth
			};
			selectedTable.AddColumn (selectedColumn);
			selectedTable.DataSource = selectedSource = new EncodingSource (TextEncoding.ConversionEncodings);
			selectedTable.Delegate = new EncodingSelectedDelegate (this);
			
			UpdateButtons ();
			
			this.ContentView = view;
		}
Пример #6
0
        public bool Run(AlertDialogData data)
        {
            using (var alert = new NSAlert()) {
                if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information)
                {
                    alert.AlertStyle = NSAlertStyle.Critical;
                }
                else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning)
                {
                    alert.AlertStyle = NSAlertStyle.Warning;
                }
                else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information)
                {
                    alert.AlertStyle = NSAlertStyle.Informational;
                }

                //FIXME: use correct size so we don't get horrible scaling?
                if (!string.IsNullOrEmpty(data.Message.Icon))
                {
                    var    pix = ImageService.GetPixbuf(data.Message.Icon, Gtk.IconSize.Dialog);
                    byte[] buf = pix.SaveToBuffer("tiff");
                    unsafe
                    {
                        fixed(byte *b = buf)
                        {
                            alert.Icon = new NSImage(NSData.FromBytes((IntPtr)b, (uint)buf.Length));
                        }
                    }
                }

                alert.MessageText     = data.Message.Text;
                alert.InformativeText = data.Message.SecondaryText ?? "";

                var buttons = data.Buttons.Reverse().ToList();

                for (int i = 0; i < buttons.Count - 1; i++)
                {
                    if (i == data.Message.DefaultButton)
                    {
                        var next = buttons[i];
                        for (int j = buttons.Count - 1; j >= i; j--)
                        {
                            var tmp = buttons[j];
                            buttons[j] = next;
                            next       = tmp;
                        }
                        break;
                    }
                }

                foreach (var button in buttons)
                {
                    var label = button.Label;
                    if (button.IsStockButton)
                    {
                        label = Gtk.Stock.Lookup(label).Label;
                    }
                    label = label.Replace("_", "");

                    //this message seems to be a standard Mac message since alert handles it specially
                    if (button == AlertButton.CloseWithoutSave)
                    {
                        label = GettextCatalog.GetString("Don't Save");
                    }

                    alert.AddButton(label);
                }


                NSButton[] optionButtons = null;
                if (data.Options.Count > 0)
                {
                    var box = new MDBox(LayoutDirection.Vertical, 2, 2);
                    optionButtons = new NSButton[data.Options.Count];

                    for (int i = data.Options.Count - 1; i >= 0; i--)
                    {
                        var option = data.Options[i];
                        var button = new NSButton()
                        {
                            Title = option.Text,
                            Tag   = i,
                            State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
                        };
                        button.SetButtonType(NSButtonType.Switch);
                        optionButtons[i] = button;
                        box.Add(new MDAlignment(button, true)
                        {
                            XAlign = LayoutAlign.Begin
                        });
                    }

                    box.Layout();
                    alert.AccessoryView = box.View;
                }

                NSButton applyToAllCheck = null;
                if (data.Message.AllowApplyToAll)
                {
                    alert.ShowsSuppressionButton = true;
                    applyToAllCheck       = alert.SuppressionButton;
                    applyToAllCheck.Title = GettextCatalog.GetString("Apply to all");
                }

                alert.Layout();

                int result = alert.RunModal() - (int)NSAlertButtonReturn.First;

                data.ResultButton = buttons [result];

                if (optionButtons != null)
                {
                    foreach (var button in optionButtons)
                    {
                        var option = data.Options[button.Tag];
                        data.Message.SetOptionValue(option.Id, button.State != 0);
                    }
                }

                if (applyToAllCheck != null && applyToAllCheck.State != 0)
                {
                    data.ApplyToAll = true;
                }

                GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow);
            }

            return(true);
        }
Пример #7
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);

                    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();
                }
            }
        }
Пример #8
0
        public bool Run(AddFileDialogData data)
        {
            using (var panel = new NSOpenPanel()
            {
                CanChooseDirectories = false,
                CanChooseFiles = true,
            }) {
                MacSelectFileDialogHandler.SetCommonPanelProperties(data, panel);

                var popup       = new NSPopUpButton(new RectangleF(0, 0, 200, 28), false);
                var dropdownBox = new MDBox(LayoutDirection.Horizontal, 2, 0)
                {
                    { new MDLabel(GettextCatalog.GetString("Override build action:")), true },
                    { new MDAlignment(popup, true)
                      {
                          MinWidth = 200
                      } }
                };

                var filterPopup = MacSelectFileDialogHandler.CreateFileFilterPopup(data, panel);
                if (filterPopup != null)
                {
                    dropdownBox.Layout();
                    var box = new MDBox(LayoutDirection.Vertical, 2, 2)
                    {
                        dropdownBox.View,
                        filterPopup,
                    };
                    box.Layout();
                    panel.AccessoryView = box.View;
                    box.Layout(box.View.Superview.Frame.Size);
                }
                else
                {
                    dropdownBox.Layout();
                    panel.AccessoryView = dropdownBox.View;
                }

                popup.AddItem(GettextCatalog.GetString("(Default)"));
                popup.Menu.AddItem(NSMenuItem.SeparatorItem);

                foreach (var b in data.BuildActions)
                {
                    if (b == "--")
                    {
                        popup.Menu.AddItem(NSMenuItem.SeparatorItem);
                    }
                    else
                    {
                        popup.AddItem(b);
                    }
                }

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

                data.SelectedFiles = MacSelectFileDialogHandler.GetSelectedFiles(panel);

                var idx = popup.IndexOfSelectedItem - 2;
                if (idx >= 0)
                {
                    data.OverrideAction = data.BuildActions[idx];
                }

                GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow);
                return(true);
            }
        }