protected override void BuildUI() { base.BuildUI(); string title = Strings.Sharpen; dialog = new Gtk.Dialog(title, (Gtk.Window) this, DialogFlags.DestroyWithParent, new object[0]) { BorderWidth = 12 }; dialog.VBox.Spacing = 6; var table = new Gtk.Table(3, 2, false) { ColumnSpacing = 6, RowSpacing = 6 }; table.Attach(SetFancyStyle(new Gtk.Label(Strings.AmountColon)), 0, 1, 0, 1); table.Attach(SetFancyStyle(new Gtk.Label(Strings.RadiusColon)), 0, 1, 1, 2); table.Attach(SetFancyStyle(new Gtk.Label(Strings.ThresholdColon)), 0, 1, 2, 3); SetFancyStyle(amount_spin = new Gtk.SpinButton(0.00, 100.0, .01)); SetFancyStyle(radius_spin = new Gtk.SpinButton(1.0, 50.0, .01)); SetFancyStyle(threshold_spin = new Gtk.SpinButton(0.0, 50.0, .01)); amount_spin.Value = .5; radius_spin.Value = 5; threshold_spin.Value = 0.0; amount_spin.ValueChanged += HandleSettingsChanged; radius_spin.ValueChanged += HandleSettingsChanged; threshold_spin.ValueChanged += HandleSettingsChanged; table.Attach(amount_spin, 1, 2, 0, 1); table.Attach(radius_spin, 1, 2, 1, 2); table.Attach(threshold_spin, 1, 2, 2, 3); var cancel_button = new Gtk.Button(Gtk.Stock.Cancel); cancel_button.Clicked += HandleCancelClicked; dialog.AddActionWidget(cancel_button, Gtk.ResponseType.Cancel); var ok_button = new Gtk.Button(Gtk.Stock.Ok); ok_button.Clicked += HandleOkClicked; dialog.AddActionWidget(ok_button, Gtk.ResponseType.Cancel); dialog.DeleteEvent += HandleCancelClicked; Destroyed += HandleLoupeDestroyed; table.ShowAll(); dialog.VBox.PackStart(table); dialog.ShowAll(); }
protected override bool RunDefault() { Gtk.Dialog md = null; try { md = new Gtk.Dialog(Caption, TransientFor, DialogFlags.Modal | DialogFlags.DestroyWithParent) { HasSeparator = false, BorderWidth = 6, }; var questionLabel = new Label(Question) { UseMarkup = true, Xalign = 0.0F, }; md.VBox.PackStart(questionLabel, true, false, 6); var responseEntry = new Entry(Value ?? "") { Visibility = !IsPassword, }; responseEntry.Activated += (sender, e) => { md.Respond(ResponseType.Ok); }; md.VBox.PackStart(responseEntry, false, true, 6); md.AddActionWidget(new Button(Gtk.Stock.Cancel) { CanDefault = true }, ResponseType.Cancel); md.AddActionWidget(new Button(Gtk.Stock.Ok), ResponseType.Ok); md.DefaultResponse = ResponseType.Cancel; md.Child.ShowAll(); var response = (ResponseType)MonoDevelop.Ide.MessageService.RunCustomDialog(md, TransientFor); if (response == ResponseType.Ok) { Value = responseEntry.Text; return(true); } return(false); } finally { if (md != null) { md.Destroy(); md.Dispose(); } } }
public override void LaunchDialogue() { //dialogue and buttons Dialog dialog = new Dialog (); dialog.Title = "Expandable Object Editor "; dialog.Modal = true; dialog.AllowGrow = true; dialog.AllowShrink = true; dialog.Modal = true; dialog.AddActionWidget (new Button (Stock.Cancel), ResponseType.Cancel); dialog.AddActionWidget (new Button (Stock.Ok), ResponseType.Ok); //propGrid grid = new PropertyGrid (parentRow.ParentGrid.EditorManager); grid.CurrentObject = parentRow.PropertyValue; grid.WidthRequest = 200; grid.ShowHelp = false; dialog.VBox.PackStart (grid, true, true, 5); //show and get response dialog.ShowAll (); ResponseType response = (ResponseType) dialog.Run(); dialog.Destroy (); //if 'OK' put items back in collection if (response == ResponseType.Ok) { } //clean up so we start fresh if launched again }
public override void LaunchDialogue () { //the Type in the collection IList collection = (IList) Value; string displayName = Property.DisplayName; //populate list with existing items ListStore itemStore = new ListStore (typeof (object), typeof (int), typeof (string)); for (int i=0; i<collection.Count; i++) itemStore.AppendValues(collection [i], i, collection [i].ToString ()); #region Building Dialogue TreeView itemTree; PropertyGrid grid; TreeIter previousIter = TreeIter.Zero; //dialogue and buttons Dialog dialog = new Dialog () { Title = displayName + " Editor", Modal = true, AllowGrow = true, AllowShrink = true, }; var toplevel = this.Container.Toplevel as Window; if (toplevel != null) dialog.TransientFor = toplevel; dialog.AddActionWidget (new Button (Stock.Cancel), ResponseType.Cancel); dialog.AddActionWidget (new Button (Stock.Ok), ResponseType.Ok); //three columns for items, sorting, PropGrid HBox hBox = new HBox (); dialog.VBox.PackStart (hBox, true, true, 5); //propGrid at end grid = new PropertyGrid (base.EditorManager) { CurrentObject = null, WidthRequest = 200, ShowHelp = false }; hBox.PackEnd (grid, true, true, 5); //followed by a ButtonBox VBox buttonBox = new VBox (); buttonBox.Spacing = 6; hBox.PackEnd (buttonBox, false, false, 5); //add/remove buttons Button addButton = new Button (new Image (Stock.Add, IconSize.Button)); buttonBox.PackStart (addButton, false, false, 0); if (types [0].IsAbstract) addButton.Sensitive = false; Button removeButton = new Button (new Gtk.Image (Stock.Remove, IconSize.Button)); buttonBox.PackStart (removeButton, false, false, 0); //sorting buttons Button upButton = new Button (new Image (Stock.GoUp, IconSize.Button)); buttonBox.PackStart (upButton, false, false, 0); Button downButton = new Button (new Image (Stock.GoDown, IconSize.Button)); buttonBox.PackStart (downButton, false, false, 0); //Third column has list (TreeView) in a ScrolledWindow ScrolledWindow listScroll = new ScrolledWindow (); listScroll.WidthRequest = 200; listScroll.HeightRequest = 320; hBox.PackStart (listScroll, false, false, 5); itemTree = new TreeView (itemStore); itemTree.Selection.Mode = SelectionMode.Single; itemTree.HeadersVisible = false; listScroll.AddWithViewport (itemTree); //renderers and attribs for TreeView CellRenderer rdr = new CellRendererText (); itemTree.AppendColumn (new TreeViewColumn ("Index", rdr, "text", 1)); rdr = new CellRendererText (); itemTree.AppendColumn (new TreeViewColumn ("Object", rdr, "text", 2)); #endregion #region Events addButton.Clicked += delegate { //create the object object instance = System.Activator.CreateInstance (types[0]); //get existing selection and insert after it TreeIter oldIter, newIter; if (itemTree.Selection.GetSelected (out oldIter)) newIter = itemStore.InsertAfter (oldIter); //or append if no previous selection else newIter = itemStore.Append (); itemStore.SetValue (newIter, 0, instance); //select, set name and update all the indices itemTree.Selection.SelectIter (newIter); UpdateName (itemStore, newIter); UpdateIndices (itemStore); }; removeButton.Clicked += delegate { //get selected iter and the replacement selection TreeIter iter, newSelection; if (!itemTree.Selection.GetSelected (out iter)) return; newSelection = iter; if (!IterPrev (itemStore, ref newSelection)) { newSelection = iter; if (!itemStore.IterNext (ref newSelection)) newSelection = TreeIter.Zero; } //new selection. Zeroing previousIter prevents trying to update name of deleted iter. previousIter = TreeIter.Zero; if (itemStore.IterIsValid (newSelection)) itemTree.Selection.SelectIter (newSelection); //and the removal and index update itemStore.Remove (ref iter); UpdateIndices (itemStore); }; upButton.Clicked += delegate { TreeIter iter, prev; if (!itemTree.Selection.GetSelected (out iter)) return; //get previous iter prev = iter; if (!IterPrev (itemStore, ref prev)) return; //swap the two itemStore.Swap (iter, prev); //swap indices too object prevVal = itemStore.GetValue (prev, 1); object iterVal = itemStore.GetValue (iter, 1); itemStore.SetValue (prev, 1, iterVal); itemStore.SetValue (iter, 1, prevVal); }; downButton.Clicked += delegate { TreeIter iter, next; if (!itemTree.Selection.GetSelected (out iter)) return; //get next iter next = iter; if (!itemStore.IterNext (ref next)) return; //swap the two itemStore.Swap (iter, next); //swap indices too object nextVal = itemStore.GetValue (next, 1); object iterVal = itemStore.GetValue (iter, 1); itemStore.SetValue (next, 1, iterVal); itemStore.SetValue (iter, 1, nextVal); }; itemTree.Selection.Changed += delegate { TreeIter iter; if (!itemTree.Selection.GetSelected (out iter)) { removeButton.Sensitive = false; return; } removeButton.Sensitive = true; //update grid object obj = itemStore.GetValue (iter, 0); grid.CurrentObject = obj; //update previously selected iter's name UpdateName (itemStore, previousIter); //update current selection so we can update //name next selection change previousIter = iter; }; grid.Changed += delegate { TreeIter iter; if (itemTree.Selection.GetSelected (out iter)) UpdateName (itemStore, iter); }; TreeIter selectionIter; removeButton.Sensitive = itemTree.Selection.GetSelected (out selectionIter); dialog.ShowAll (); grid.ShowToolbar = false; #endregion //if 'OK' put items back in collection //if (MonoDevelop.Ide.MessageService.ShowCustomDialog (dialog, toplevel) == (int)ResponseType.Ok) { DesignerTransaction tran = CreateTransaction (Instance); object old = collection; try { collection.Clear(); foreach (object[] o in itemStore) collection.Add (o[0]); EndTransaction (Instance, tran, old, collection, true); } catch { EndTransaction (Instance, tran, old, collection, false); throw; } } }
protected override void BuildUI () { base.BuildUI (); string title = Catalog.GetString ("Sharpen"); dialog = new Gtk.Dialog (title, (Gtk.Window) this, DialogFlags.DestroyWithParent, new object [0]); dialog.BorderWidth = 12; dialog.VBox.Spacing = 6; Gtk.Table table = new Gtk.Table (3, 2, false); table.ColumnSpacing = 6; table.RowSpacing = 6; table.Attach (SetFancyStyle (new Gtk.Label (Catalog.GetString ("Amount:"))), 0, 1, 0, 1); table.Attach (SetFancyStyle (new Gtk.Label (Catalog.GetString ("Radius:"))), 0, 1, 1, 2); table.Attach (SetFancyStyle (new Gtk.Label (Catalog.GetString ("Threshold:"))), 0, 1, 2, 3); SetFancyStyle (amount_spin = new Gtk.SpinButton (0.00, 100.0, .01)); SetFancyStyle (radius_spin = new Gtk.SpinButton (1.0, 50.0, .01)); SetFancyStyle (threshold_spin = new Gtk.SpinButton (0.0, 50.0, .01)); amount_spin.Value = .5; radius_spin.Value = 5; threshold_spin.Value = 0.0; amount_spin.ValueChanged += HandleSettingsChanged; radius_spin.ValueChanged += HandleSettingsChanged; threshold_spin.ValueChanged += HandleSettingsChanged; table.Attach (amount_spin, 1, 2, 0, 1); table.Attach (radius_spin, 1, 2, 1, 2); table.Attach (threshold_spin, 1, 2, 2, 3); Gtk.Button cancel_button = new Gtk.Button (Gtk.Stock.Cancel); cancel_button.Clicked += HandleCancelClicked; dialog.AddActionWidget (cancel_button, Gtk.ResponseType.Cancel); Gtk.Button ok_button = new Gtk.Button (Gtk.Stock.Ok); ok_button.Clicked += HandleOkClicked; dialog.AddActionWidget (ok_button, Gtk.ResponseType.Cancel); Destroyed += HandleLoupeDestroyed; table.ShowAll (); dialog.VBox.PackStart (table); dialog.ShowAll (); }
public string GetTextResponse (string question, string caption, string initialValue, bool isPassword) { string returnValue = null; Dialog md = new Dialog (caption, rootWindow, DialogFlags.Modal | DialogFlags.DestroyWithParent); try { // add a label with the question Label questionLabel = new Label(question); questionLabel.UseMarkup = true; questionLabel.Xalign = 0.0F; md.VBox.PackStart(questionLabel, true, false, 6); // add an entry with initialValue Entry responseEntry = (initialValue != null) ? new Entry(initialValue) : new Entry(); md.VBox.PackStart(responseEntry, false, true, 6); responseEntry.Visibility = !isPassword; // add action widgets md.AddActionWidget(new Button(Gtk.Stock.Cancel), ResponseType.Cancel); md.AddActionWidget(new Button(Gtk.Stock.Ok), ResponseType.Ok); md.VBox.ShowAll(); md.ActionArea.ShowAll(); md.HasSeparator = false; md.BorderWidth = 6; PlaceDialog (md, rootWindow); int response = md.Run (); md.Hide (); if ((ResponseType) response == ResponseType.Ok) { returnValue = responseEntry.Text; } return returnValue; } finally { md.Destroy (); } }
/// <summary> /// Activated when the user clicks the "Configure" button. Opens a new dialog containing the configuration /// widget of the selected plugin /// </summary> /// <param name="sender"> /// A <see cref="System.Object"/> -- not used /// </param> /// <param name="e"> /// A <see cref="EventArgs"/> -- not used /// </param> void OnConfigureButtonClicked(object sender, EventArgs e) { LiveRadioPluginListModel model = plugin_view.Model as LiveRadioPluginListModel; ILiveRadioPlugin plugin = model[plugin_view.Model.Selection.FocusedIndex]; Dialog dialog = new Dialog (); dialog.Title = String.Format ("LiveRadio Plugin {0} configuration", plugin.Name); dialog.IconName = "gtk-preferences"; dialog.Resizable = false; dialog.BorderWidth = 6; dialog.ContentArea.Spacing = 12; dialog.ContentArea.PackStart (plugin.ConfigurationWidget, false, false, 0); Button save_button = new Button (Stock.Save); Button cancel_button = new Button (Stock.Cancel); dialog.AddActionWidget (cancel_button, 0); dialog.AddActionWidget (save_button, 0); cancel_button.Clicked += delegate { dialog.Destroy (); }; save_button.Clicked += delegate { plugin.SaveConfiguration (); dialog.Destroy (); }; dialog.ShowAll (); }
public override void LaunchDialogue() { //the Type in the collection IList collection = (IList)Value; string displayName = Property.DisplayName; //populate list with existing items ListStore itemStore = new ListStore(typeof(object), typeof(int), typeof(string)); for (int i = 0; i < collection.Count; i++) { itemStore.AppendValues(collection [i], i, collection [i].ToString()); } #region Building Dialogue TreeView itemTree; PropertyGrid grid; TreeIter previousIter = TreeIter.Zero; //dialogue and buttons var dialog = new Gtk.Dialog() { Title = displayName + " Editor", Modal = true, AllowGrow = true, AllowShrink = true, }; var toplevel = this.Container.GetNativeWidget <Gtk.Widget> ().Toplevel as Gtk.Window; if (toplevel != null) { dialog.TransientFor = toplevel; } dialog.AddActionWidget(new Button(Stock.Cancel), ResponseType.Cancel); dialog.AddActionWidget(new Button(Stock.Ok), ResponseType.Ok); //three columns for items, sorting, PropGrid HBox hBox = new HBox(); dialog.VBox.PackStart(hBox, true, true, 5); //propGrid at end grid = new PropertyGrid(base.EditorManager) { CurrentObject = null, WidthRequest = 200, ShowHelp = false }; hBox.PackEnd(grid, true, true, 5); //followed by a ButtonBox VBox buttonBox = new VBox(); buttonBox.Spacing = 6; hBox.PackEnd(buttonBox, false, false, 5); //add/remove buttons Button addButton = new Button(new Image(Stock.Add, IconSize.Button)); buttonBox.PackStart(addButton, false, false, 0); if (types [0].IsAbstract) { addButton.Sensitive = false; } Button removeButton = new Button(new Gtk.Image(Stock.Remove, IconSize.Button)); buttonBox.PackStart(removeButton, false, false, 0); //sorting buttons Button upButton = new Button(new Image(Stock.GoUp, IconSize.Button)); buttonBox.PackStart(upButton, false, false, 0); Button downButton = new Button(new Image(Stock.GoDown, IconSize.Button)); buttonBox.PackStart(downButton, false, false, 0); //Third column has list (TreeView) in a ScrolledWindow ScrolledWindow listScroll = new ScrolledWindow(); listScroll.WidthRequest = 200; listScroll.HeightRequest = 320; hBox.PackStart(listScroll, false, false, 5); itemTree = new TreeView(itemStore); itemTree.Selection.Mode = SelectionMode.Single; itemTree.HeadersVisible = false; listScroll.AddWithViewport(itemTree); //renderers and attribs for TreeView CellRenderer rdr = new CellRendererText(); itemTree.AppendColumn(new TreeViewColumn("Index", rdr, "text", 1)); rdr = new CellRendererText(); itemTree.AppendColumn(new TreeViewColumn("Object", rdr, "text", 2)); #endregion #region Events addButton.Clicked += delegate { //create the object object instance = System.Activator.CreateInstance(types[0]); //get existing selection and insert after it TreeIter oldIter, newIter; if (itemTree.Selection.GetSelected(out oldIter)) { newIter = itemStore.InsertAfter(oldIter); } //or append if no previous selection else { newIter = itemStore.Append(); } itemStore.SetValue(newIter, 0, instance); //select, set name and update all the indices itemTree.Selection.SelectIter(newIter); UpdateName(itemStore, newIter); UpdateIndices(itemStore); }; removeButton.Clicked += delegate { //get selected iter and the replacement selection TreeIter iter, newSelection; if (!itemTree.Selection.GetSelected(out iter)) { return; } newSelection = iter; if (!IterPrev(itemStore, ref newSelection)) { newSelection = iter; if (!itemStore.IterNext(ref newSelection)) { newSelection = TreeIter.Zero; } } //new selection. Zeroing previousIter prevents trying to update name of deleted iter. previousIter = TreeIter.Zero; if (itemStore.IterIsValid(newSelection)) { itemTree.Selection.SelectIter(newSelection); } //and the removal and index update itemStore.Remove(ref iter); UpdateIndices(itemStore); }; upButton.Clicked += delegate { TreeIter iter, prev; if (!itemTree.Selection.GetSelected(out iter)) { return; } //get previous iter prev = iter; if (!IterPrev(itemStore, ref prev)) { return; } //swap the two itemStore.Swap(iter, prev); //swap indices too object prevVal = itemStore.GetValue(prev, 1); object iterVal = itemStore.GetValue(iter, 1); itemStore.SetValue(prev, 1, iterVal); itemStore.SetValue(iter, 1, prevVal); }; downButton.Clicked += delegate { TreeIter iter, next; if (!itemTree.Selection.GetSelected(out iter)) { return; } //get next iter next = iter; if (!itemStore.IterNext(ref next)) { return; } //swap the two itemStore.Swap(iter, next); //swap indices too object nextVal = itemStore.GetValue(next, 1); object iterVal = itemStore.GetValue(iter, 1); itemStore.SetValue(next, 1, iterVal); itemStore.SetValue(iter, 1, nextVal); }; itemTree.Selection.Changed += delegate { TreeIter iter; if (!itemTree.Selection.GetSelected(out iter)) { removeButton.Sensitive = false; return; } removeButton.Sensitive = true; //update grid object obj = itemStore.GetValue(iter, 0); grid.CurrentObject = obj; //update previously selected iter's name UpdateName(itemStore, previousIter); //update current selection so we can update //name next selection change previousIter = iter; }; grid.Changed += delegate { TreeIter iter; if (itemTree.Selection.GetSelected(out iter)) { UpdateName(itemStore, iter); } }; TreeIter selectionIter; removeButton.Sensitive = itemTree.Selection.GetSelected(out selectionIter); dialog.ShowAll(); grid.ShowToolbar = false; #endregion //if 'OK' put items back in collection using (dialog) { if (MonoDevelop.Ide.MessageService.ShowCustomDialog(dialog, toplevel) == (int)ResponseType.Ok) { DesignerTransaction tran = CreateTransaction(Instance); object old = collection; try { collection.Clear(); foreach (object[] o in itemStore) { collection.Add(o [0]); } EndTransaction(Instance, tran, old, collection, true); } catch { EndTransaction(Instance, tran, old, collection, false); throw; } } } }
public override void LaunchDialogue() { //the Type in the collection IList collection = (IList) parentRow.PropertyValue; string displayName = parentRow.PropertyDescriptor.DisplayName; //populate list with existing items itemStore = new ListStore (typeof (object), typeof (int), typeof (string)); for (int i=0; i<collection.Count; i++) { itemStore.AppendValues(collection [i], i, collection [i].ToString ()); } #region Building Dialogue //dialogue and buttons Dialog dialog = new Dialog (); dialog.Title = displayName + " Editor"; dialog.Modal = true; dialog.AllowGrow = true; dialog.AllowShrink = true; dialog.Modal = true; dialog.AddActionWidget (new Button (Stock.Cancel), ResponseType.Cancel); dialog.AddActionWidget (new Button (Stock.Ok), ResponseType.Ok); //three columns for items, sorting, PropGrid HBox hBox = new HBox (); dialog.VBox.PackStart (hBox, true, true, 5); //propGrid at end grid = new PropertyGrid (parentRow.ParentGrid.EditorManager); grid.CurrentObject = null; grid.WidthRequest = 200; grid.ShowHelp = false; hBox.PackEnd (grid, true, true, 5); //followed by item sorting buttons in ButtonBox VButtonBox sortButtonBox = new VButtonBox (); sortButtonBox.LayoutStyle = ButtonBoxStyle.Start; Button upButton = new Button (); Image upImage = new Image (Stock.GoUp, IconSize.Button); upImage.Show (); upButton.Add (upImage); upButton.Show (); sortButtonBox.Add (upButton); Button downButton = new Button (); Image downImage = new Image (Stock.GoDown, IconSize.Button); downImage.Show (); downButton.Add (downImage); downButton.Show (); sortButtonBox.Add (downButton); hBox.PackEnd (sortButtonBox, false, false, 5); //Third column is a VBox VBox itemsBox = new VBox (); hBox.PackStart (itemsBox, false, false, 5); //which at bottom has add/remove buttons HButtonBox addRemoveButtons = new HButtonBox(); addRemoveButtons.LayoutStyle = ButtonBoxStyle.End; Button addButton = new Button (Stock.Add); addRemoveButtons.Add (addButton); if (types [0].IsAbstract) addButton.Sensitive = false; Button removeButton = new Button (Stock.Remove); addRemoveButtons.Add (removeButton); itemsBox.PackEnd (addRemoveButtons, false, false, 10); //and at top has list (TreeView) in a ScrolledWindow ScrolledWindow listScroll = new ScrolledWindow (); listScroll.WidthRequest = 200; listScroll.HeightRequest = 320; itemsBox.PackStart (listScroll, true, true, 0); itemTree = new TreeView (itemStore); itemTree.Selection.Mode = SelectionMode.Single; itemTree.HeadersVisible = false; listScroll.AddWithViewport (itemTree); //renderers and attribs for TreeView CellRenderer rdr = new CellRendererText (); itemTree.AppendColumn (new TreeViewColumn ("Index", rdr, "text", 1)); rdr = new CellRendererText (); itemTree.AppendColumn (new TreeViewColumn ("Object", rdr, "text", 2)); #endregion #region Events addButton.Clicked += new EventHandler (addButton_Clicked); removeButton.Clicked += new EventHandler (removeButton_Clicked); itemTree.Selection.Changed += new EventHandler (Selection_Changed); upButton.Clicked += new EventHandler (upButton_Clicked); downButton.Clicked += new EventHandler (downButton_Clicked); #endregion //show and get response dialog.ShowAll (); ResponseType response = (ResponseType) dialog.Run(); dialog.Destroy (); //if 'OK' put items back in collection if (response == ResponseType.Ok) { DesignerTransaction tran = CreateTransaction (parentRow.ParentGrid.CurrentObject); object old = collection; try { collection.Clear(); foreach (object[] o in itemStore) collection.Add (o[0]); EndTransaction (parentRow.ParentGrid.CurrentObject, tran, old, collection, true); } catch { EndTransaction (parentRow.ParentGrid.CurrentObject, tran, old, collection, false); throw; } } //clean up so we start fresh if launched again itemTree = null; itemStore = null; grid = null; previousIter = TreeIter.Zero; }
// call this method to show a dialog and get a response value // returns null if cancel is selected public string GetTextResponse(string question, string caption, string initialValue) { string returnValue = null; using (Gtk.Dialog md = new Gtk.Dialog (caption, (Gtk.Window) WorkbenchSingleton.Workbench, Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent)) { // add a label with the question Gtk.Label questionLabel = new Gtk.Label(question); questionLabel.UseMarkup = true; questionLabel.Xalign = 0.0F; md.VBox.PackStart(questionLabel, true, false, 6); // add an entry with initialValue Gtk.Entry responseEntry = (initialValue != null) ? new Gtk.Entry(initialValue) : new Gtk.Entry(); md.VBox.PackStart(responseEntry, false, true, 6); // add action widgets md.AddActionWidget(new Gtk.Button(Gtk.Stock.Cancel), Gtk.ResponseType.Cancel); md.AddActionWidget(new Gtk.Button(Gtk.Stock.Ok), Gtk.ResponseType.Ok); md.VBox.ShowAll(); md.ActionArea.ShowAll(); md.HasSeparator = false; md.BorderWidth = 6; int response = md.Run (); md.Hide (); if ((Gtk.ResponseType) response == Gtk.ResponseType.Ok) { returnValue = responseEntry.Text; } } return returnValue; }
protected override Gtk.Widget CreateWidget(WindowContext context) { Window win; if(HasAttribute("dialog")) { Dialog dialog = new Dialog(); dialog.AddAccelGroup(context.AccelGroup); SetWindowAttribs(dialog); if(Child != null) dialog.VBox.Add(Child.Build(context)); foreach(string s in GetAttribute<Array>("dialog")) { string[] bits = s.Split(':'); string text = bits[0]; int response = 0; if(bits.Length > 4) throw new Exception("Neplatný počet parametrů tlačítka v poli tlačítek dialogu"); if(bits.Length > 1) response = (int)IntLiteral.Parse(bits[1]); Label l = new Label(); l.Markup = text; Button btn; if(bits.Length > 2 && !String.IsNullOrEmpty(bits[2])) { HBox hbox = new HBox(false, 0); hbox.PackStart(ImageExpression.CreateImage(bits[2], IconSize.Button)); hbox.PackStart(l); btn = new Button(hbox); } else btn = new Button(l); btn.ShowAll(); dialog.AddActionWidget(btn, response); if(bits.Length > 3) { switch(bits[3].ToLower()) { case "default": btn.CanDefault = true; dialog.Default = btn; break; case "cancel": // set as cancel action - how? break; case "": case "none": break; default: throw new Exception("Neznámý příznak tlačítka dialogu"); } } } win = dialog; } else { win = new Window(Gtk.WindowType.Toplevel); win.AddAccelGroup(context.AccelGroup); if(Child != null) win.Add(Child.Build(context)); } if(HasAttribute("iconset")) { IconSet icons = IconFactory.LookupDefault(GetAttribute<string>("iconset")); List<Gdk.Pixbuf> list = new List<Gdk.Pixbuf>(); foreach(IconSize size in icons.Sizes) { list.Add(icons.RenderIcon(win.Style, TextDirection.Ltr, StateType.Normal, size, win, "")); } win.IconList = list.ToArray(); } return win; }
private static Gtk.ResponseType showErrDialog(Exception e, bool canContinue) { Gtk.Table pnlError; Gtk.Image pctError; Gtk.Label lblError; Gtk.ScrolledWindow scrError; Gtk.TextView txtError; Gtk.Button cmdReport; Gtk.Button cmdIgnore; Gtk.Button cmdExit; pnlError = new Gtk.Table(2, 2, false); pnlError.Name = "pnlError"; pnlError.RowSpacing = 6; pnlError.ColumnSpacing = 6; pctError = new Gtk.Image(); pctError.Name = "pctError"; pctError.Xpad = 8; pctError.Ypad = 8; if (CurrentOS.IsMac) { pctError.Pixbuf = Gdk.Pixbuf.LoadFromResource("RestrictionTrackerGTK.Resources.config.os_x.advanced_nettest_error.png"); } else { pctError.Pixbuf = Gdk.Pixbuf.LoadFromResource("RestrictionTrackerGTK.Resources.config.linux.advanced_nettest_error.png"); } pnlError.Attach(pctError, 0, 1, 0, 1, AttachOptions.Fill, AttachOptions.Fill, 0, 0); lblError = new Gtk.Label(); lblError.Name = "lblError"; lblError.Xalign = 0F; lblError.Yalign = 0.5F; if (e.TargetSite == null) { lblError.LabelProp = "<span size=\"12000\" weight=\"bold\">" + modFunctions.ProductName + " has Encountered an Error</span>"; } else { lblError.LabelProp = "<span size=\"12000\" weight=\"bold\">" + modFunctions.ProductName + " has Encountered an Error in " + e.TargetSite.Name + "</span>"; } var signal = GLib.Signal.Lookup(lblError, "size-allocate", typeof(SizeAllocatedArgs)); signal.AddDelegate(new EventHandler <SizeAllocatedArgs>(SizeAllocateLabel)); lblError.LineWrap = true; lblError.UseMarkup = true; pnlError.Attach(lblError, 1, 2, 0, 1, AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill, 0, 0); scrError = new Gtk.ScrolledWindow(); scrError.Name = "scrError"; scrError.VscrollbarPolicy = PolicyType.Automatic; scrError.HscrollbarPolicy = PolicyType.Never; scrError.ShadowType = ShadowType.In; txtError = new Gtk.TextView(); txtError.CanFocus = true; txtError.Name = "txtError"; txtError.Editable = false; txtError.AcceptsTab = false; txtError.WrapMode = WrapMode.Word; scrError.Add(txtError); pnlError.Attach(scrError, 1, 2, 1, 2, AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0); txtError.Buffer.Text = "Error: " + e.Message; if (!string.IsNullOrEmpty(e.StackTrace)) { if (e.StackTrace.Contains("\n")) { txtError.Buffer.Text += "\n" + e.StackTrace.Substring(0, e.StackTrace.IndexOf("\n")); } else { txtError.Buffer.Text += "\n" + e.StackTrace; } } else { if (!string.IsNullOrEmpty(e.Source)) { txtError.Buffer.Text += "\n @ " + e.Source; if (e.TargetSite != null) { txtError.Buffer.Text += "." + e.TargetSite.Name; } } else { if (e.TargetSite != null) { txtError.Buffer.Text += "\n @ " + e.TargetSite.Name; } } } cmdReport = new Gtk.Button(); cmdReport.CanDefault = true; cmdReport.CanFocus = true; cmdReport.Name = "cmdReport"; cmdReport.UseUnderline = false; cmdReport.Label = "Report Error"; if (canContinue) { cmdIgnore = new Gtk.Button(); cmdIgnore.CanDefault = true; cmdIgnore.CanFocus = true; cmdIgnore.Name = "cmdIgnore"; cmdIgnore.UseUnderline = false; cmdIgnore.Label = "Ignore and Continue"; } else { cmdIgnore = null; } cmdExit = new global::Gtk.Button(); cmdExit.CanFocus = true; cmdExit.Name = "cmdExit"; cmdExit.UseUnderline = true; cmdExit.Label = global::Mono.Unix.Catalog.GetString("Exit Application"); Gtk.Dialog dlgErr = new Gtk.Dialog("Error in " + modFunctions.ProductName, null, DialogFlags.Modal | DialogFlags.DestroyWithParent, cmdReport); dlgErr.TypeHint = Gdk.WindowTypeHint.Dialog; dlgErr.WindowPosition = WindowPosition.CenterAlways; dlgErr.SkipPagerHint = true; dlgErr.SkipTaskbarHint = true; dlgErr.AllowShrink = true; dlgErr.AllowGrow = true; VBox pnlErrorDialog = dlgErr.VBox; pnlErrorDialog.Name = "pnlErrorDialog"; pnlErrorDialog.BorderWidth = 2; pnlErrorDialog.Add(pnlError); Box.BoxChild pnlError_BC = (Box.BoxChild)pnlErrorDialog[pnlError]; pnlError_BC.Position = 0; Gtk.HButtonBox dlgErrorAction = dlgErr.ActionArea; dlgErrorAction.Name = "dlgErrorAction"; dlgErrorAction.Spacing = 10; dlgErrorAction.BorderWidth = 5; dlgErrorAction.LayoutStyle = ButtonBoxStyle.End; dlgErr.AddActionWidget(cmdReport, ResponseType.Ok); if (canContinue) { dlgErr.AddActionWidget(cmdIgnore, ResponseType.No); } dlgErr.AddActionWidget(cmdExit, ResponseType.Reject); dlgErr.ShowAll(); Gdk.Geometry minGeo = new Gdk.Geometry(); minGeo.MinWidth = dlgErr.Allocation.Width; minGeo.MinHeight = dlgErr.Allocation.Height; if (minGeo.MinWidth > 1 & minGeo.MinHeight > 1) { dlgErr.SetGeometryHints(null, minGeo, Gdk.WindowHints.MinSize); } Gtk.ResponseType dRet; do { dRet = (Gtk.ResponseType)dlgErr.Run(); } while (dRet == ResponseType.None); dlgErr.Hide(); dlgErr.Destroy(); dlgErr = null; return(dRet); }
private void OnSignupEvent( Hashtable form ) { if( ((string)form[ "action" ]).Equals( "msg" ) ) { new AlertDialog( this.MainWindow, AlertType.Info, (string)form[ "title" ], (string)form[ "msg" ] ); } else { this.signupdata = form; Dialog dlg = new Dialog(); dlg.Modal = true; dlg.Title = (string)form[ "title" ]; dlg.SetSizeRequest( 500, -1 ); HBox split = new HBox(); dlg.VBox.Add( split ); VBox left = new VBox( true, 0 ); VBox right = new VBox( true, 0 ); split.PackStart( left, false, false, 5 ); split.PackEnd( right, true, true, 10 ); NameValueCollection fields = (NameValueCollection)form[ "fields" ]; Hashtable data = (Hashtable)form[ "data" ]; foreach( string Key in fields.AllKeys ) { Hashtable fd = (Hashtable)data[ Key ]; string Name = Key.Substring( 0, 1 ).ToUpper() + Key.Substring( 1 ) + ":"; Label lbl = new Label( Name ); lbl.SetAlignment( 0, (float)0.5 ); left.PackStart( lbl, false, false, 5 ); if( fields[ Key ].Equals( "TextEditView" ) ) { Entry ent = new Entry(); ent.Name = Key; ent.ActivatesDefault = true; if( fd[ "isPassword" ] != null ) ent.Visibility = false; if( fd[ "value" ] != null ) ent.Text = (string)fd[ "value" ]; right.PackStart( ent, false, false, 5 ); } else if( fields[ Key ].Equals( "PopupButtonView" ) ) { ComboBox cbox = ComboBox.NewText(); cbox.WrapWidth = 5; cbox.Name = Key; if( fd[ "menuItems" ] != null ) { string menuItems = (string)fd[ "menuItems" ]; foreach( string Value in menuItems.Split( ',' ) ) cbox.AppendText( Value ); if( fd[ "value" ] != null && (string)fd[ "value" ] != String.Empty ) { cbox.Active = Convert.ToInt32( fd[ "value" ] ) - 1; } else { cbox.Active = 0; } } right.PackStart( cbox, false, false, 5 ); } else if( fields[ Key ].Equals( "ComboControlView" ) ) { ComboBoxEntry cboxe = ComboBoxEntry.NewText(); cboxe.WrapWidth = 5; cboxe.Name = Key; if( fd[ "menuItems" ] != null ) { string menuItems = (string)fd[ "menuItems" ]; foreach( string Value in menuItems.Split( ',' ) ) cboxe.AppendText( Value ); } if( fd[ "value" ] != null ) ((Entry)cboxe.Child).Text = (string)fd[ "value" ]; right.PackStart( cboxe, false, false, 5 ); } else if( fields[ Key ].Equals( "CheckboxView" ) ) { CheckButton cbtn = new CheckButton(); cbtn.Name = Key; if( fd[ "value" ] != null && (string)fd[ "value" ] != String.Empty ) { int v = Convert.ToInt32( (string)fd[ "value" ] ); cbtn.Active = v == 1; } right.PackStart( cbtn, false, false, 5 ); } } dlg.AddActionWidget( new Button( "Cancel" ), ResponseType.Cancel ); Button btn = new Button( "Next" ); btn.CanDefault = true; dlg.AddActionWidget( btn, ResponseType.Ok ); dlg.DefaultResponse = ResponseType.Ok; dlg.Response += new ResponseHandler( OnSignupResponse ); dlg.TransientFor = this.MainWindow; dlg.SetPosition( WindowPosition.CenterOnParent ); dlg.ShowAll(); if( form[ "redtext" ] != null ) new AlertDialog( dlg, AlertType.Warning, (string)form[ "title" ], (string)form[ "redtext" ] ); } }
private void OnPreferences( object o, EventArgs args ) { if( prefsdlg == null ) { Button btn; HBox split; VBox left, right; Button songdirbtn; prefsdlg = new Dialog(); prefsdlg.Modal = true; prefsdlg.Title = "SharpMusique Preferences"; prefsdlg.SetSizeRequest( 500, -1 ); split = new HBox(); prefsdlg.VBox.Add( split ); left = new VBox( true, 0 ); right = new VBox( true, 0 ); split.PackStart( left, false, false, 5 ); split.PackEnd( right, true, true, 10 ); songdirbtn = new Button( "Song Folder: " ); songdirbtn.Clicked += new EventHandler( OnSongDirSelected ); songdirentry = new Entry(); left.PackStart( songdirbtn, false, false, 10 ); right.PackStart( songdirentry, false, false, 10 ); btn = new Button( "Cancel" ); prefsdlg.AddActionWidget( btn, ResponseType.Cancel ); btn = new Button( "Save" ); prefsdlg.AddActionWidget( btn, ResponseType.Ok ); prefsdlg.Response += new ResponseHandler( OnPreferencesResponse ); } songdirentry.Text = strSongDir; prefsdlg.TransientFor = this.MainWindow; prefsdlg.SetPosition( WindowPosition.CenterOnParent ); prefsdlg.ShowAll(); prefsdlg.Run(); }