예제 #1
0
		public GtkAlertDialog (ApplicationContext actx, MessageDescription message)
		{
			this.actx = actx;
			Init ();
			this.buttons = message.Buttons.ToArray ();

			string primaryText = String.Empty;
			string secondaryText = String.Empty;

			if (string.IsNullOrEmpty (message.Text)) {
				if (!string.IsNullOrEmpty (message.SecondaryText))
					primaryText = message.SecondaryText;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			if (message.Icon == StockIcons.Information)
				base.MessageType = MessageType.Info;
			else if (message.Icon == StockIcons.Question)
				base.MessageType = MessageType.Question;
			else if (message.Icon == StockIcons.Warning)
				base.MessageType = MessageType.Warning;
			else if (message.Icon == StockIcons.Error)
				base.MessageType = MessageType.Error;
			else {
				var icon = message.Icon.ToImageDescription (actx);
				image.Image = icon.WithDefaultSize (Gtk.IconSize.Dialog);
				base.Image = image;
			}

			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");

			base.Markup = markup.ToString ();
			if (!String.IsNullOrEmpty (secondaryText)) {
				base.SecondaryText = GLib.Markup.EscapeText (secondaryText);
				base.SecondaryUseMarkup = true;
			}
			
			foreach (Command button in message.Buttons) {
				Gtk.Button newButton = (Gtk.Button)base.AddButton (button.Label, button.ToResponseType());
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (button.Icon != null) {
					var icon = button.Icon.ToImageDescription (actx);
					newButton.Image = new ImageBox (actx, icon.WithDefaultSize (Gtk.IconSize.Button));
				}
				newButton.Clicked += ButtonClicked;
			}
			
			foreach (var op in message.Options) {
				Gtk.CheckButton check = new Gtk.CheckButton (op.Text);
				check.Active = op.Value;
				this.AddContent (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				Gtk.CheckButton check = new Gtk.CheckButton ("Apply to all");
				this.AddContent (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
예제 #2
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.icon = GetIcon(message.Icon);
            if (string.IsNullOrEmpty(message.Title))
            {
                message.Title = transientFor?.Title ?? string.Empty;
            }

            if (ConvertButtons(message.Buttons, out buttons) && message.Options.Count == 0)
            {
                // Use a system message box
                if (message.SecondaryText == null)
                {
                    message.SecondaryText = string.Empty;
                }
                else
                {
                    message.Text          = message.Text + "\r\n\r\n" + message.SecondaryText;
                    message.SecondaryText = string.Empty;
                }
                var parent = context.Toolkit.GetNativeWindow(transientFor) as System.Windows.Window;
                if (parent != null)
                {
                    this.dialogResult = MessageBox.Show(parent, message.Text, message.Title,
                                                        this.buttons, this.icon, this.defaultResult, this.options);
                }
                else
                {
                    this.dialogResult = MessageBox.Show(message.Text, message.Title, this.buttons,
                                                        this.icon, this.defaultResult, this.options);
                }
                return(ConvertResultToCommand(this.dialogResult));
            }
            else
            {
                // Custom message box required
                Dialog dlg = new Dialog();
                dlg.Resizable = false;
                dlg.Padding   = 0;
                dlg.Title     = message.Title;
                HBox mainBox = new HBox {
                    Margin = 25
                };

                if (message.Icon != null)
                {
                    var image = new ImageView(message.Icon.WithSize(32, 32));
                    mainBox.PackStart(image, vpos: WidgetPlacement.Start);
                }
                VBox box = new VBox()
                {
                    Margin = 3, MarginLeft = 8, Spacing = 15
                };
                mainBox.PackStart(box, true);
                var text = new Label {
                    Text = message.Text ?? string.Empty
                };
                Label stext = null;
                box.PackStart(text);
                if (!string.IsNullOrEmpty(message.SecondaryText))
                {
                    stext = new Label {
                        Text = message.SecondaryText
                    };
                    box.PackStart(stext);
                }
                foreach (var option in message.Options)
                {
                    var check = new CheckBox(option.Text);
                    check.Active = option.Value;
                    box.PackStart(check);
                    check.Toggled += (sender, e) => message.SetOptionValue(option.Id, check.Active);
                }
                dlg.Buttons.Add(message.Buttons.ToArray());
                if (message.DefaultButton >= 0 && message.DefaultButton < message.Buttons.Count)
                {
                    dlg.DefaultCommand = message.Buttons[message.DefaultButton];
                }
                if (mainBox.Surface.GetPreferredSize(true).Width > 480)
                {
                    text.Wrap = WrapMode.Word;
                    if (stext != null)
                    {
                        stext.Wrap = WrapMode.Word;
                    }
                    mainBox.WidthRequest = 480;
                }
                var s = mainBox.Surface.GetPreferredSize(true);

                dlg.Content = mainBox;
                return(dlg.Run());
            }
        }
예제 #3
0
        public AlertDialog(MessageDescription message)
        {
            Init();
            this.buttons = message.buttons.ToArray();

            string primaryText;
            string secondaryText;

            if (string.IsNullOrEmpty(message.SecondaryText))
            {
                secondaryText = message.Text;
                primaryText   = null;
            }
            else
            {
                primaryText   = message.Text;
                secondaryText = message.SecondaryText;
            }

            image.Pixbuf = ImageService.GetPixbuf(message.Icon, IconSize.Dialog);

            StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">");

            markup.Append(GLib.Markup.EscapeText(primaryText));
            markup.Append("</span>");
            if (!String.IsNullOrEmpty(secondaryText))
            {
                if (!String.IsNullOrEmpty(primaryText))
                {
                    markup.AppendLine();
                    markup.AppendLine();
                }
                markup.Append(GLib.Markup.EscapeText(secondaryText));
            }
            label.Markup     = markup.ToString();
            label.Selectable = true;

            foreach (AlertButton button in message.buttons)
            {
                Button newButton = new Button();
                newButton.Label        = button.Label;
                newButton.UseUnderline = true;
                newButton.UseStock     = button.IsStockButton;
                if (!String.IsNullOrEmpty(button.Icon))
                {
                    newButton.Image = new Image(button.Icon, IconSize.Button);
                }
                newButton.Clicked += ButtonClicked;
                ActionArea.Add(newButton);
            }

            foreach (MessageDescription.Option op in message.Options)
            {
                CheckButton check = new CheckButton(op.Text);
                check.Active = op.Value;
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    message.SetOptionValue(op.Id, check.Active);
                };
            }

            if (message.AllowApplyToAll)
            {
                CheckButton check = new CheckButton(GettextCatalog.GetString("Apply to all"));
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    ApplyToAll = check.Active;
                };
            }

            this.ShowAll();
        }
예제 #4
0
		public GtkAlertDialog (ApplicationContext actx, MessageDescription message)
		{
			this.actx = actx;
			Init ();
			this.buttons = message.Buttons.ToArray ();
			
			string primaryText;
			string secondaryText;
			
			if (string.IsNullOrEmpty (message.SecondaryText)) {
				secondaryText = message.Text;
				primaryText = null;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			var icon = message.Icon.ToImageDescription (actx);
			image.Image = icon.WithDefaultSize (Gtk.IconSize.Dialog);
			
			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");
			if (!String.IsNullOrEmpty (secondaryText)) {
				if (!String.IsNullOrEmpty (primaryText)) {
					markup.AppendLine ();
					markup.AppendLine ();
				}
				markup.Append (GLib.Markup.EscapeText (secondaryText));
			}
			label.Markup = markup.ToString ();
			label.Selectable = true;
			label.CanFocus = false;
			
			foreach (Command button in message.Buttons) {
				Gtk.Button newButton = new Gtk.Button ();
				newButton.Label        = button.Label;
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (button.Icon != null) {
					icon = button.Icon.ToImageDescription (actx);
					newButton.Image = new ImageBox (actx, icon.WithDefaultSize (Gtk.IconSize.Button));
				}
				newButton.Clicked += ButtonClicked;
				ActionArea.Add (newButton);
			}
			
			foreach (var op in message.Options) {
				CheckButton check = new CheckButton (op.Text);
				check.Active = op.Value;
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				CheckButton check = new CheckButton ("Apply to all");
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
예제 #5
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.MessageText = message.Text ?? String.Empty;
            this.InformativeText = message.SecondaryText ?? String.Empty;

            if (message.Icon != null)
                Icon = message.Icon.ToImageDescription (Context).ToNSImage ();

            var sortedButtons = new Command [message.Buttons.Count];
            var j = 0;
            if (message.DefaultButton >= 0) {
                sortedButtons [0] = message.Buttons [message.DefaultButton];
                this.AddButton (message.Buttons [message.DefaultButton].Label);
                j = 1;
            }
            for (var i = 0; i < message.Buttons.Count; i++) {
                if (i == message.DefaultButton)
                    continue;
                sortedButtons [j++] = message.Buttons [i];
                this.AddButton (message.Buttons [i].Label);
            }
            for (var i = 0; i < sortedButtons.Length; i++) {
                if (sortedButtons [i].Icon != null) {
                    Buttons [i].Image = sortedButtons [i].Icon.WithSize (IconSize.Small).ToImageDescription (Context).ToNSImage ();
                    Buttons [i].ImagePosition = NSCellImagePosition.ImageLeft;
                }
            }

            if (message.AllowApplyToAll) {
                ShowsSuppressionButton = true;
                SuppressionButton.State = NSCellStateValue.Off;
                SuppressionButton.Activated += (sender, e) => ApplyToAll = SuppressionButton.State == NSCellStateValue.On;
            }

            if (message.Options.Count > 0) {
                AccessoryView = new NSView ();
                var optionsSize = new CGSize (0, 3);

                foreach (var op in message.Options) {
                    var chk = new NSButton ();
                    chk.SetButtonType (NSButtonType.Switch);
                    chk.Title = op.Text;
                    chk.State = op.Value ? NSCellStateValue.On : NSCellStateValue.Off;
                    chk.Activated += (sender, e) => message.SetOptionValue (op.Id, chk.State == NSCellStateValue.On);

                    chk.SizeToFit ();
                    chk.Frame = new CGRect (new CGPoint (0, optionsSize.Height), chk.FittingSize);

                    optionsSize.Height += chk.FittingSize.Height + 6;
                    optionsSize.Width = (float) Math.Max (optionsSize.Width, chk.FittingSize.Width);

                    AccessoryView.AddSubview (chk);
                    chk.NeedsDisplay = true;
                }

                AccessoryView.SetFrameSize (optionsSize);
            }

            var win = Toolkit.CurrentEngine.GetNativeWindow (transientFor) as NSWindow;
            if (win != null)
                return sortedButtons [(int)this.RunSheetModal (win) - 1000];
            return sortedButtons [(int)this.RunModal () - 1000];
        }
예제 #6
0
        public GtkAlertDialog(ApplicationContext actx, MessageDescription message)
        {
            this.actx = actx;
            Init();
            this.buttons = message.Buttons.ToArray();

            string primaryText   = String.Empty;
            string secondaryText = String.Empty;

            if (string.IsNullOrEmpty(message.Text))
            {
                if (!string.IsNullOrEmpty(message.SecondaryText))
                {
                    primaryText = message.SecondaryText;
                }
            }
            else
            {
                primaryText   = message.Text;
                secondaryText = message.SecondaryText;
            }

            if (message.Icon == StockIcons.Information)
            {
                base.MessageType = MessageType.Info;
            }
            else if (message.Icon == StockIcons.Question)
            {
                base.MessageType = MessageType.Question;
            }
            else if (message.Icon == StockIcons.Warning)
            {
                base.MessageType = MessageType.Warning;
            }
            else if (message.Icon == StockIcons.Error)
            {
                base.MessageType = MessageType.Error;
            }
            else
            {
                var icon = message.Icon.ToImageDescription(actx);
                image.Image = icon.WithDefaultSize(Gtk.IconSize.Dialog);
                base.Image  = image;
            }

            StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">");

            markup.Append(GLib.Markup.EscapeText(primaryText));
            markup.Append("</span>");

            base.Markup = markup.ToString();
            if (!String.IsNullOrEmpty(secondaryText))
            {
                base.SecondaryText      = GLib.Markup.EscapeText(secondaryText);
                base.SecondaryUseMarkup = true;
            }

            foreach (Command button in message.Buttons)
            {
                Gtk.Button newButton = (Gtk.Button)base.AddButton(button.Label, button.ToResponseType());
                newButton.UseUnderline = true;
                newButton.UseStock     = button.IsStockButton;
                if (button.Icon != null)
                {
                    var icon = button.Icon.ToImageDescription(actx);
                    newButton.Image = new ImageBox(actx, icon.WithDefaultSize(Gtk.IconSize.Button));
                }
                newButton.Clicked += ButtonClicked;
            }

            foreach (var op in message.Options)
            {
                Gtk.CheckButton check = new Gtk.CheckButton(op.Text);
                check.Active = op.Value;
                this.AddContent(check, false, false, 0);
                check.Toggled += delegate {
                    message.SetOptionValue(op.Id, check.Active);
                };
            }

            if (message.AllowApplyToAll)
            {
                Gtk.CheckButton check = new Gtk.CheckButton(Xwt.Application.TranslationCatalog.GetString("Apply to all"));
                this.AddContent(check, false, false, 0);
                check.Toggled += delegate {
                    ApplyToAll = check.Active;
                };
            }

            //don't show this yet, let the consumer decide when
            this.Child.ShowAll();
        }
예제 #7
0
        public GtkAlertDialog(MessageDescription message)
        {
            Init();
            this.buttons = message.Buttons.ToArray();
            this.message = message;

            Modal = true;

            string primaryText;
            string secondaryText;

            if (string.IsNullOrEmpty(message.SecondaryText))
            {
                secondaryText = message.Text;
                primaryText   = null;
            }
            else
            {
                primaryText   = message.Text;
                secondaryText = message.SecondaryText;
            }

            if (!message.UseMarkup)
            {
                primaryText   = GLib.Markup.EscapeText(primaryText);
                secondaryText = GLib.Markup.EscapeText(secondaryText);
            }

            if (!string.IsNullOrEmpty(message.Icon))
            {
                image        = new ImageView();
                image.Yalign = 0.00f;
                image.Image  = ImageService.GetIcon(message.Icon, IconSize.Dialog);
                hbox.PackStart(image, false, false, 0);
                hbox.ReorderChild(image, 0);
            }

            StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">");

            markup.Append(primaryText);
            markup.Append("</span>");
            if (!String.IsNullOrEmpty(secondaryText))
            {
                if (!String.IsNullOrEmpty(primaryText))
                {
                    markup.AppendLine();
                    markup.AppendLine();
                }
                markup.Append(secondaryText);
            }
            label.Markup     = markup.ToString();
            label.Selectable = true;
            label.CanFocus   = false;

            foreach (AlertButton button in message.Buttons)
            {
                Button newButton = new Button();
                newButton.Label        = button.Label;
                newButton.UseUnderline = true;
                newButton.UseStock     = button.IsStockButton;
                if (!String.IsNullOrEmpty(button.Icon))
                {
                    newButton.Image = new ImageView(button.Icon, IconSize.Button);
                }
                newButton.Clicked += ButtonClicked;
                ActionArea.Add(newButton);
            }

            foreach (var op in message.Options)
            {
                CheckButton check = new CheckButton(op.Text);
                check.Active = op.Value;
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    message.SetOptionValue(op.Id, check.Active);
                };
            }

            if (message.AllowApplyToAll)
            {
                CheckButton check = new CheckButton(GettextCatalog.GetString("Apply to all"));
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    ApplyToAll = check.Active;
                };
            }

            //don't show this yet, let the consumer decide when
            this.Child.ShowAll();
        }
예제 #8
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.MessageText     = message.Text ?? String.Empty;
            this.InformativeText = message.SecondaryText ?? String.Empty;

            if (message.Icon != null)
            {
                Icon = message.Icon.ToImageDescription(Context).ToNSImage();
            }

            var sortedButtons = new Command [message.Buttons.Count];
            var j             = 0;

            if (message.DefaultButton >= 0)
            {
                sortedButtons [0] = message.Buttons [message.DefaultButton];
                this.AddButton(message.Buttons [message.DefaultButton].Label);
                j = 1;
            }
            for (var i = 0; i < message.Buttons.Count; i++)
            {
                if (i == message.DefaultButton)
                {
                    continue;
                }
                sortedButtons [j++] = message.Buttons [i];
                this.AddButton(message.Buttons [i].Label);
            }
            for (var i = 0; i < sortedButtons.Length; i++)
            {
                if (sortedButtons [i].Icon != null)
                {
                    Buttons [i].Image         = sortedButtons [i].Icon.WithSize(IconSize.Small).ToImageDescription(Context).ToNSImage();
                    Buttons [i].ImagePosition = NSCellImagePosition.ImageLeft;
                }
            }

            if (message.AllowApplyToAll)
            {
                ShowsSuppressionButton       = true;
                SuppressionButton.State      = NSCellStateValue.Off;
                SuppressionButton.Activated += (sender, e) => ApplyToAll = SuppressionButton.State == NSCellStateValue.On;
            }

            if (message.Options.Count > 0)
            {
                AccessoryView = new NSView();
                var optionsSize = new CGSize(0, 3);

                foreach (var op in message.Options)
                {
                    var chk = new NSButton();
                    chk.SetButtonType(NSButtonType.Switch);
                    chk.Title      = op.Text;
                    chk.State      = op.Value ? NSCellStateValue.On : NSCellStateValue.Off;
                    chk.Activated += (sender, e) => message.SetOptionValue(op.Id, chk.State == NSCellStateValue.On);

                    chk.SizeToFit();
                    chk.Frame = new CGRect(new CGPoint(0, optionsSize.Height), chk.FittingSize);

                    optionsSize.Height += chk.FittingSize.Height + 6;
                    optionsSize.Width   = (float)Math.Max(optionsSize.Width, chk.FittingSize.Width);

                    AccessoryView.AddSubview(chk);
                    chk.NeedsDisplay = true;
                }

                AccessoryView.SetFrameSize(optionsSize);
            }

            var win = Context.Toolkit.GetNativeWindow(transientFor) as NSWindow;

            Window.ReleasedWhenClosed = true;
            if (win != null)
            {
                return(sortedButtons [(int)this.RunSheetModal(win) - 1000]);
            }
            return(sortedButtons [(int)this.RunModal() - 1000]);
        }
예제 #9
0
		public GtkAlertDialog (MessageDescription message)
		{
			Init ();
			this.buttons = message.Buttons.ToArray ();

			Modal = true;

			string primaryText;
			string secondaryText;
			
			if (string.IsNullOrEmpty (message.SecondaryText)) {
				secondaryText = message.Text;
				primaryText = null;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			if (!message.UseMarkup) {
				primaryText = GLib.Markup.EscapeText (primaryText);
				secondaryText = GLib.Markup.EscapeText (secondaryText);
			}

			if (!string.IsNullOrEmpty (message.Icon)) {
				image = new ImageView ();
				image.Yalign   = 0.00f;
				image.Image = ImageService.GetIcon (message.Icon, IconSize.Dialog);
				hbox.PackStart (image, false, false, 0);
				hbox.ReorderChild (image, 0);
			}
			
			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (primaryText);
			markup.Append ("</span>");
			if (!String.IsNullOrEmpty (secondaryText)) {
				if (!String.IsNullOrEmpty (primaryText)) {
					markup.AppendLine ();
					markup.AppendLine ();
				}
				markup.Append (secondaryText);
			}
			label.Markup = markup.ToString ();
			label.Selectable = true;
			label.CanFocus = false;
			
			foreach (AlertButton button in message.Buttons) {
				Button newButton = new Button ();
				newButton.Label        = button.Label;
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (!String.IsNullOrEmpty (button.Icon))
					newButton.Image = new Image (button.Icon, IconSize.Button);
				newButton.Clicked += ButtonClicked;
				ActionArea.Add (newButton);
			}
			
			foreach (var op in message.Options) {
				CheckButton check = new CheckButton (op.Text);
				check.Active = op.Value;
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				CheckButton check = new CheckButton (GettextCatalog.GetString ("Apply to all"));
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
예제 #10
0
        public GtkAlertDialog(MessageDescription message)
        {
            Init();
            this.buttons = message.Buttons.ToArray();

            string primaryText;
            string secondaryText;

            if (string.IsNullOrEmpty(message.SecondaryText))
            {
                secondaryText = message.Text;
                primaryText   = null;
            }
            else
            {
                primaryText   = message.Text;
                secondaryText = message.SecondaryText;
            }

            image.SetFromStock(Util.ToGtkStock(message.Icon), Gtk.IconSize.Dialog);

            StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">");

            markup.Append(GLib.Markup.EscapeText(primaryText));
            markup.Append("</span>");
            if (!String.IsNullOrEmpty(secondaryText))
            {
                if (!String.IsNullOrEmpty(primaryText))
                {
                    markup.AppendLine();
                    markup.AppendLine();
                }
                markup.Append(GLib.Markup.EscapeText(secondaryText));
            }
            label.Markup     = markup.ToString();
            label.Selectable = true;
            label.CanFocus   = false;

            foreach (Command button in message.Buttons)
            {
                Gtk.Button newButton = new Gtk.Button();
                newButton.Label        = button.Label;
                newButton.UseUnderline = true;
                newButton.UseStock     = button.IsStockButton;
                if (!String.IsNullOrEmpty(button.Icon))
                {
                    newButton.Image = new Gtk.Image(Util.ToGtkStock(button.Icon), Gtk.IconSize.Button);
                }
                newButton.Clicked += ButtonClicked;
                ActionArea.Add(newButton);
            }

            foreach (var op in message.Options)
            {
                CheckButton check = new CheckButton(op.Text);
                check.Active = op.Value;
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    message.SetOptionValue(op.Id, check.Active);
                };
            }

            if (message.AllowApplyToAll)
            {
                CheckButton check = new CheckButton("Apply to all");
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    ApplyToAll = check.Active;
                };
            }

            //don't show this yet, let the consumer decide when
            this.Child.ShowAll();
        }
예제 #11
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.icon = GetIcon (message.Icon);
            if (ConvertButtons (message.Buttons, out buttons) && message.Options.Count == 0) {
                // Use a system message box
                if (message.SecondaryText == null)
                    message.SecondaryText = String.Empty;
                else {
                    message.Text = message.Text + "\r\n\r\n" + message.SecondaryText;
                    message.SecondaryText = String.Empty;
                }
                var parent =  Toolkit.CurrentEngine.GetNativeWindow(transientFor) as System.Windows.Window;
                if (parent != null) {
                    this.dialogResult = MessageBox.Show (parent, message.Text, message.SecondaryText,
                                                        this.buttons, this.icon, this.defaultResult, this.options);
                }
                else {
                    this.dialogResult = MessageBox.Show (message.Text, message.SecondaryText, this.buttons,
                                                        this.icon, this.defaultResult, this.options);
                }
                return ConvertResultToCommand (this.dialogResult);
            }
            else {
                // Custom message box required
                Dialog dlg = new Dialog ();
                dlg.Resizable = false;
                dlg.Padding = 0;
                HBox mainBox = new HBox { Margin = 25 };

                if (message.Icon != null) {
                    var image = new ImageView (message.Icon.WithSize (32,32));
                    mainBox.PackStart (image, vpos: WidgetPlacement.Start);
                }
                VBox box = new VBox () { Margin = 3, MarginLeft = 8, Spacing = 15 };
                mainBox.PackStart (box, true);
                var text = new Label {
                    Text = message.Text ?? ""
                };
                Label stext = null;
                box.PackStart (text);
                if (!string.IsNullOrEmpty (message.SecondaryText)) {
                    stext = new Label {
                        Text = message.SecondaryText
                    };
                    box.PackStart (stext);
                }
                foreach (var option in message.Options) {
                    var check = new CheckBox (option.Text);
                    check.Active = option.Value;
                    box.PackStart(check);
                    check.Toggled += (sender, e) => message.SetOptionValue(option.Id, check.Active);
                }
                dlg.Buttons.Add (message.Buttons.ToArray ());
                if (message.DefaultButton >= 0 && message.DefaultButton < message.Buttons.Count)
                    dlg.DefaultCommand = message.Buttons[message.DefaultButton];
                if (mainBox.Surface.GetPreferredSize (true).Width > 480) {
                    text.Wrap = WrapMode.Word;
                    if (stext != null)
                        stext.Wrap = WrapMode.Word;
                    mainBox.WidthRequest = 480;
                }
                var s = mainBox.Surface.GetPreferredSize (true);

                dlg.Content = mainBox;
                return dlg.Run ();
            }
        }
		public AlertDialog (MessageDescription message)
		{
			Init ();
			this.buttons = message.buttons.ToArray ();
			
			string primaryText;
			string secondaryText;
			
			if (string.IsNullOrEmpty (message.SecondaryText)) {
				secondaryText = message.Text;
				primaryText = null;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}
			
			image.Pixbuf = ImageService.GetPixbuf (message.Icon, IconSize.Dialog);
			
			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");
			if (!String.IsNullOrEmpty (secondaryText)) {
				if (!String.IsNullOrEmpty (primaryText)) {
					markup.AppendLine ();
					markup.AppendLine ();
				}
				markup.Append (GLib.Markup.EscapeText (secondaryText));
			}
			label.Markup = markup.ToString ();
			label.Selectable = true;
			
			foreach (AlertButton button in message.buttons) {
				Button newButton = new Button ();
				newButton.Label        = button.Label;
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (!String.IsNullOrEmpty (button.Icon))
					newButton.Image = new Image (button.Icon, IconSize.Button);
				newButton.Clicked += ButtonClicked;
				ActionArea.Add (newButton);
			}
			
			foreach (MessageDescription.Option op in message.Options) {
				CheckButton check = new CheckButton (op.Text);
				check.Active = op.Value;
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				CheckButton check = new CheckButton (GettextCatalog.GetString ("Apply to all"));
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			this.ShowAll ();
		}