public MenuItem(Command command) : this() { Label = command.Label; if (!string.IsNullOrEmpty (command.Icon)) Image = Image.FromIcon (command.Icon, IconSize.Small); }
public void SetCommand(Command command, Action action) { Action oldAction; if (_commandMap.TryGetValue (command, out oldAction)) { _commandMap [command] = action; } else { _commandMap.Add (command, action); } }
public Windows() { Button b = new Button ("Show borderless window"); PackStart (b); b.Clicked += delegate { Window w = new Window (); w.Decorated = false; Button c = new Button ("This is a window"); // c.Margin.SetAll (10); w.Content = c; c.Clicked += delegate { w.Dispose (); }; var bpos = b.ScreenBounds; w.Bounds = new Rectangle (bpos.X, bpos.Y + b.Size.Height, w.Bounds.Width, w.Bounds.Height); w.Show (); }; b = new Button ("Show message dialog"); PackStart (b); b.Clicked += delegate { MessageDialog.ShowMessage (ParentWindow, "Hi there!"); }; Button db = new Button ("Show custom dialog"); PackStart (db); db.Clicked += delegate { Dialog d = new Dialog (); d.Title = "This is a dialog"; Table t = new Table (); t.Attach (new Label ("Some field:"), 0, 1, 0, 1); t.Attach (new TextEntry (), 1, 2, 0, 1); t.Attach (new Label ("Another field:"), 0, 1, 1, 2); t.Attach (new TextEntry (), 1, 2, 1, 2); d.Content = t; Command custom = new Command ("Custom"); d.Buttons.Add (new DialogButton (custom)); d.Buttons.Add (new DialogButton ("Custom OK", Command.Ok)); d.Buttons.Add (new DialogButton (Command.Cancel)); d.Buttons.Add (new DialogButton (Command.Ok)); var r = d.Run (this.ParentWindow); db.Label = "Result: " + r.Label; d.Dispose (); }; }
/// <summary> /// Called when a dialog button is clicked /// </summary> /// <param name="cmd">The command</param> protected virtual void OnCommandActivated (Command cmd) { Respond (cmd); }
public DialogButton (string label, Image icon, Command cmd) { this.label = label; this.command = cmd; this.image = icon; }
public void HideCommand (Command cmd) { var btn = Buttons.GetCommandButton (cmd); if (btn != null) btn.Visible = false; }
public void DisableCommand (Command cmd) { var btn = Buttons.GetCommandButton (cmd); if (btn != null) btn.Sensitive = false; }
bool RequestClose () { requestingClose = true; try { if (OnCloseRequested ()) { if (!responding) resultCommand = null; loopEnded = true; return true; } else return false; } finally { responding = false; requestingClose = false; } }
public void Respond(Command cmd) { resultCommand = cmd; if (!loopEnded) { loopEnded = true; Backend.EndLoop (); } }
public RadioButtonMenuItem(Command command) : base(command) { }
public ConfirmationMessage(string primaryText, Command button) : this(button) { Text = primaryText; }
public ConfirmationMessage(Command button) : this() { ConfirmButton = button; }
public static bool Confirm(string primaryText, string secondaryText, Command button, bool confirmIsDefault) { return GenericAlert (RootWindow, StockIcons.Question, primaryText, secondaryText, confirmIsDefault ? 0 : 1, Command.Cancel, button) == button; }
public static bool Confirm(string primaryText, Command button, bool confirmIsDefault) { return Confirm (primaryText, null, button, confirmIsDefault); }
public static bool Confirm(string primaryText, Command button) { return Confirm (primaryText, null, button); }
public RadioButtonMenuItem (Command command) { VerifyConstructorCall (this); LoadCommandProperties (command); }
public ConfirmationMessage(string primaryText, string secondaryText, Command button) : this(primaryText, button) { SecondaryText = secondaryText; }
public CheckBoxMenuItem(Command command) : base(command) { }
/// <summary> /// Called when a dialog button is clicked /// </summary> /// <param name="cmd">The command</param> protected virtual void OnCommandActivated(Command cmd) { var args = new DialogCommandActivatedEventArgs (cmd); if (CommandActivated != null) CommandActivated (this, args); if (!args.Handled) Respond (cmd); }
public void Respond (Command cmd) { resultCommand = cmd; responding = true; if (!loopEnded && !requestingClose) { Backend.EndLoop (); } }
public DialogCommandActivatedEventArgs(Command command) { Command = command; }
public void EnableCommand (Command cmd) { var btn = Buttons.GetCommandButton (cmd); if (btn != null) btn.Sensitive = true; }
void OnAddConfiguration (object sender, EventArgs e) { var okCommand = new Command (GettextCatalog.GetString ("Create")); using (var dlg = new RunConfigurationNameDialog (ParentWindow, "", okCommand, panel.Configurations.Select (c => c.EditedConfig.Name))) { dlg.Title = GettextCatalog.GetString ("New Configuration"); if (dlg.Run () == okCommand) { var config = new MultiItemSolutionRunConfiguration (dlg.NewName, dlg.NewName); panel.AddConfiguration (config); Fill (); } } }
public void ShowCommand (Command cmd) { var btn = Buttons.GetCommandButton (cmd); if (btn != null) btn.Visible = true; }
void OnRenameConfiguration (object sender, EventArgs e) { var config = (MultiItemSolutionRunConfiguration)list.SelectedConfiguration; var okCommand = new Command (GettextCatalog.GetString ("Rename")); using (var dlg = new RunConfigurationNameDialog (ParentWindow, config.Name, okCommand, panel.Configurations.Select (c => c.EditedConfig.Name))) { dlg.Title = GettextCatalog.GetString ("Rename Configuration"); if (dlg.Run () != Command.Cancel) { var copy = new MultiItemSolutionRunConfiguration (config, dlg.NewName); panel.ReplaceConfiguration (config, copy); Fill (); } } }
public DialogButton (string label, Command cmd) { this.label = label; this.command = cmd; }
protected override void OnCommandActivated (Command cmd) { if (cmd == runButton.Command) editor.Save (); base.OnCommandActivated (cmd); }
public DialogButton (Command cmd) { this.command = cmd; }
public Windows() { Button bp = new Button ("Show borderless window"); PackStart (bp); bp.Clicked += delegate { Window w = new Window (); w.Decorated = false; Button c = new Button ("This is a window"); // c.Margin.SetAll (10); w.Content = c; c.Clicked += delegate { w.Dispose (); }; var bpos = bp.ScreenBounds; w.ScreenBounds = new Rectangle (bpos.X, bpos.Y + bp.Size.Height, w.Width, w.Height); w.Show (); }; Button b = new Button ("Show message dialog"); PackStart (b); b.Clicked += delegate { MessageDialog.ShowMessage (ParentWindow, "Hi there!"); }; Button db = new Button ("Show custom dialog"); PackStart (db); db.Clicked += delegate { Dialog d = new Dialog (); d.Title = "This is a dialog"; Table t = new Table (); t.Add (new Label ("Some field:"), 0, 0); t.Add (new TextEntry (), 1, 0); t.Add (new Label ("Another field:"), 0, 1); t.Add (new TextEntry (), 1, 1); d.Content = t; d.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) { args.AllowClose = MessageDialog.Confirm ("Really close?", Command.Close); }; Command custom = new Command ("Custom"); d.Buttons.Add (new DialogButton (custom)); d.Buttons.Add (new DialogButton ("Custom OK", Command.Ok)); d.Buttons.Add (new DialogButton (Command.Cancel)); d.Buttons.Add (new DialogButton (Command.Ok)); var r = d.Run (this.ParentWindow); db.Label = "Result: " + (r != null ? r.Label : "(Closed)"); d.Dispose (); }; b = new Button ("Show Open File dialog"); PackStart (b); b.Clicked += delegate { OpenFileDialog dlg = new OpenFileDialog ("Select a file"); dlg.InitialFileName = "Some file"; dlg.Multiselect = true; dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt")); dlg.Filters.Add (new FileDialogFilter ("All files", "*.*")); if (dlg.Run ()) MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames)); }; b = new Button ("Show Save File dialog"); PackStart (b); b.Clicked += delegate { SaveFileDialog dlg = new SaveFileDialog ("Select a file"); dlg.InitialFileName = "Some file"; dlg.Multiselect = true; dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt")); dlg.Filters.Add (new FileDialogFilter ("All files", "*.*")); if (dlg.Run ()) MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames)); }; b = new Button ("Show Select Folder dialog (Multi select)"); PackStart (b); b.Clicked += delegate { SelectFolderDialog dlg = new SelectFolderDialog ("Select some folder"); dlg.Multiselect = true; if (dlg.Run ()) MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders)); }; b = new Button ("Show Select Folder dialog (Single select)"); PackStart (b); b.Clicked += delegate { SelectFolderDialog dlg = new SelectFolderDialog ("Select a folder"); dlg.Multiselect = false; if (dlg.Run ()) MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders)); }; b = new Button ("Show Select Folder dialog (Single select, allow creation)"); PackStart (b); b.Clicked += delegate { SelectFolderDialog dlg = new SelectFolderDialog ("Select or create a folder"); dlg.Multiselect = false; dlg.CanCreateFolders = true; if (dlg.Run ()) MessageDialog.ShowMessage ("Folders have been selected/created!", string.Join ("\n", dlg.Folders)); }; b = new Button ("Show Select Color dialog"); PackStart (b); b.Clicked += delegate { SelectColorDialog dlg = new SelectColorDialog ("Select a color"); dlg.SupportsAlpha = true; dlg.Color = Xwt.Drawing.Colors.AliceBlue; if (dlg.Run (ParentWindow)) MessageDialog.ShowMessage ("A color has been selected!", dlg.Color.ToString ()); }; b = new Button("Show window shown event"); PackStart(b); b.Clicked += delegate { Window w = new Window(); w.Decorated = false; Button c = new Button("This is a window with events on"); w.Content = c; c.Clicked += delegate { w.Dispose(); }; w.Shown += (sender, args) => MessageDialog.ShowMessage("My Parent has been shown"); w.Hidden += (sender, args) => MessageDialog.ShowMessage("My Parent has been hidden"); w.Show(); }; b = new Button("Show dialog with dynamically updating content"); PackStart(b); b.Clicked += delegate { var dialog = new Dialog (); dialog.Content = new Label ("Hello World"); Xwt.Application.TimeoutInvoke (TimeSpan.FromSeconds (2), () => { dialog.Content = new Label ("Goodbye World"); return false; }); dialog.Run (); }; }
public Windows() { Button b = new Button ("Show borderless window"); PackStart (b); b.Clicked += delegate { Window w = new Window (); w.Decorated = false; Button c = new Button ("This is a window"); // c.Margin.SetAll (10); w.Content = c; c.Clicked += delegate { w.Dispose (); }; var bpos = b.ScreenBounds; w.ScreenBounds = new Rectangle (bpos.X, bpos.Y + b.Size.Height, w.Width, w.Height); w.Show (); }; b = new Button ("Show message dialog"); PackStart (b); b.Clicked += delegate { MessageDialog.ShowMessage (ParentWindow, "Hi there!"); }; Button db = new Button ("Show custom dialog"); PackStart (db); db.Clicked += delegate { Dialog d = new Dialog (); d.Title = "This is a dialog"; Table t = new Table (); t.Attach (new Label ("Some field:"), 0, 1, 0, 1); t.Attach (new TextEntry (), 1, 2, 0, 1); t.Attach (new Label ("Another field:"), 0, 1, 1, 2); t.Attach (new TextEntry (), 1, 2, 1, 2); d.Content = t; Command custom = new Command ("Custom"); d.Buttons.Add (new DialogButton (custom)); d.Buttons.Add (new DialogButton ("Custom OK", Command.Ok)); d.Buttons.Add (new DialogButton (Command.Cancel)); d.Buttons.Add (new DialogButton (Command.Ok)); var r = d.Run (this.ParentWindow); db.Label = "Result: " + r.Label; d.Dispose (); }; b = new Button ("Show Open File dialog"); PackStart (b); b.Clicked += delegate { OpenFileDialog dlg = new OpenFileDialog ("Select a file"); dlg.InitialFileName = "Some file"; dlg.Multiselect = true; dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt")); dlg.Filters.Add (new FileDialogFilter ("All files", "*.*")); if (dlg.Run ()) MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames)); }; b = new Button ("Show Save File dialog"); PackStart (b); b.Clicked += delegate { SaveFileDialog dlg = new SaveFileDialog ("Select a file"); dlg.InitialFileName = "Some file"; dlg.Multiselect = true; dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt")); dlg.Filters.Add (new FileDialogFilter ("All files", "*.*")); if (dlg.Run ()) MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames)); }; b = new Button ("Show Select Folder dialog (Multi select)"); PackStart (b); b.Clicked += delegate { SelectFolderDialog dlg = new SelectFolderDialog ("Select some folder"); dlg.Multiselect = true; if (dlg.Run ()) MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders)); }; b = new Button ("Show Select Folder dialog (Single select)"); PackStart (b); b.Clicked += delegate { SelectFolderDialog dlg = new SelectFolderDialog ("Select a folder"); dlg.Multiselect = false; if (dlg.Run ()) MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders)); }; b = new Button ("Show Select Color dialog"); PackStart (b); b.Clicked += delegate { SelectColorDialog dlg = new SelectColorDialog ("Select a color"); dlg.SupportsAlpha = true; dlg.Color = Xwt.Drawing.Colors.AliceBlue; if (dlg.Run (ParentWindow)) MessageDialog.ShowMessage ("A color has been selected!", dlg.Color.ToString ()); }; b = new Button("Show window shown event"); PackStart(b); b.Clicked += delegate { Window w = new Window(); w.Decorated = false; Button c = new Button("This is a window with events on"); w.Content = c; c.Clicked += delegate { w.Dispose(); }; w.Shown += (sender, args) => MessageDialog.ShowMessage("My Parent has been shown"); w.Hidden += (sender, args) => MessageDialog.ShowMessage("My Parent has been hidden"); w.Show(); }; }
public DialogButton GetCommandButton(Command cmd) { return(this.FirstOrDefault(b => b.Command == cmd)); }