FindInFilesDialog(bool showReplace) { Build(); IdeTheme.ApplyTheme(this); properties = PropertyService.Get("MonoDevelop.FindReplaceDialogs.SearchOptions", new Properties()); SetButtonIcon(toggleReplaceInFiles, "gtk-find-and-replace"); SetButtonIcon(toggleFindInFiles, "gtk-find"); // If we have an active floating window, attach the dialog to it. Otherwise use the main IDE window. var current_toplevel = Gtk.Window.ListToplevels().FirstOrDefault(x => x.IsActive); if (current_toplevel is Components.DockNotebook.DockWindow) { TransientFor = current_toplevel; } else { TransientFor = IdeApp.Workbench.RootWindow; } toggleReplaceInFiles.Active = showReplace; toggleFindInFiles.Active = !showReplace; toggleFindInFiles.Toggled += delegate { if (toggleFindInFiles.Active) { Title = GettextCatalog.GetString("Find in Files"); HideReplaceUI(); } }; toggleReplaceInFiles.Toggled += delegate { if (toggleReplaceInFiles.Active) { Title = GettextCatalog.GetString("Replace in Files"); ShowReplaceUI(); } }; buttonSearch.Clicked += HandleSearchClicked; buttonClose.Clicked += (sender, e) => Destroy(); DeleteEvent += (o, args) => Destroy(); buttonSearch.GrabDefault(); buttonStop.Clicked += ButtonStopClicked; var scopeStore = new ListStore(typeof(string)); var workspace = IdeApp.Workspace; if (workspace != null && workspace.GetAllSolutions().Count() == 1) { scopeStore.AppendValues(GettextCatalog.GetString("Whole solution")); } else { scopeStore.AppendValues(GettextCatalog.GetString("All solutions")); } scopeStore.AppendValues(GettextCatalog.GetString("Current project")); scopeStore.AppendValues(GettextCatalog.GetString("All open files")); scopeStore.AppendValues(GettextCatalog.GetString("Directories")); scopeStore.AppendValues(GettextCatalog.GetString("Current document")); scopeStore.AppendValues(GettextCatalog.GetString("Selection")); comboboxScope.Model = scopeStore; comboboxScope.Changed += HandleScopeChanged; InitFromProperties(); if (showReplace) { toggleReplaceInFiles.Toggle(); } else { toggleFindInFiles.Toggle(); } if (IdeApp.Workbench.ActiveDocument != null) { var view = IdeApp.Workbench.ActiveDocument.Editor; if (view != null) { string selectedText = FormatPatternToSelectionOption(view.SelectedText, properties.Get("RegexSearch", false)); if (!string.IsNullOrEmpty(selectedText)) { if (selectedText.Any(c => c == '\n' || c == '\r')) { // comboboxScope.Active = ScopeSelection; } else { if (comboboxScope.Active == (int)SearchScope.Selection) { comboboxScope.Active = (int)SearchScope.CurrentDocument; } comboboxentryFind.Entry.Text = selectedText; } } else if (comboboxScope.Active == (int)SearchScope.Selection) { comboboxScope.Active = (int)SearchScope.CurrentDocument; } } } comboboxentryFind.Entry.SelectRegion(0, comboboxentryFind.ActiveText.Length); comboboxentryFind.GrabFocus(); DeleteEvent += delegate { Destroy(); }; UpdateStopButton(); UpdateSensitivity(); if (!buttonSearch.Sensitive) { comboboxScope.Active = (int)SearchScope.Directories; } Child.Show(); updateTimer = GLib.Timeout.Add(750, delegate { UpdateSensitivity(); return(true); }); }
public bool Run(AlertDialogData data) { using (var alert = new NSAlert()) { alert.Window.Title = data.Title ?? BrandingService.ApplicationName; IdeTheme.ApplyTheme(alert.Window); bool stockIcon; if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Error || data.Message.Icon == Gtk.Stock.DialogError) { alert.AlertStyle = NSAlertStyle.Critical; stockIcon = true; } else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning || data.Message.Icon == Gtk.Stock.DialogWarning) { alert.AlertStyle = NSAlertStyle.Critical; stockIcon = true; } else { alert.AlertStyle = NSAlertStyle.Informational; stockIcon = data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information; } if (!stockIcon && !string.IsNullOrEmpty(data.Message.Icon)) { var img = ImageService.GetIcon(data.Message.Icon, Gtk.IconSize.Dialog); // HACK: The icon is not rendered in dark mode (VibrantDark or DarkAqua) correctly. // Use light variant and reder it here. // TODO: Recheck rendering issues with DarkAqua on final Mojave if (IdeTheme.UserInterfaceTheme == Theme.Dark) { alert.Icon = img.WithStyles("-dark").ToBitmap(GtkWorkarounds.GetScaleFactor()).ToNSImage(); } else { alert.Icon = img.ToNSImage(); } } else { //for some reason the NSAlert doesn't pick up the app icon by default alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; } alert.MessageText = data.Message.Text; int accessoryViewItemsCount = data.Options.Count; string secondaryText = data.Message.SecondaryText ?? string.Empty; if (TryGetMessageView(secondaryText, out NSView messageView)) { accessoryViewItemsCount++; } else { alert.InformativeText = secondaryText; } var accessoryViews = accessoryViewItemsCount > 0 ? new NSView [accessoryViewItemsCount] : null; int accessoryViewsIndex = 0; if (messageView != null) { accessoryViews [accessoryViewsIndex++] = messageView; } 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; } } var wrappers = new List <AlertButtonWrapper> (buttons.Count); 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"); } var nsbutton = alert.AddButton(label); var wrapperButton = new AlertButtonWrapper(nsbutton, data.Message, button, alert); wrappers.Add(wrapperButton); nsbutton.Target = wrapperButton; nsbutton.Action = new ObjCRuntime.Selector("buttonActivatedAction"); } NSButton [] optionButtons = null; if (data.Options.Count > 0) { 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); button.SizeToFit(); optionButtons [i] = button; accessoryViews [accessoryViewsIndex++] = button; } } var accessoryView = ArrangeAccessoryViews(accessoryViews); if (accessoryView != null) { if (accessoryViews?[0] == messageView) { accessoryView.SetCustomSpacing(accessoryView.Spacing * 2, messageView); var size = accessoryView.Frame.Size; size.Height += accessoryView.Spacing; accessoryView.SetFrameSize(size); } alert.AccessoryView = accessoryView; } NSButton applyToAllCheck = null; if (data.Message.AllowApplyToAll) { alert.ShowsSuppressionButton = true; applyToAllCheck = alert.SuppressionButton; applyToAllCheck.Title = GettextCatalog.GetString("Apply to all"); } // Hack up a slightly wider than normal alert dialog. I don't know how to do this in a nicer way // as the min size constraints are apparently ignored. var frame = alert.Window.Frame; alert.Window.SetFrame(new CGRect(frame.X, frame.Y, NMath.Max(frame.Width, 600), frame.Height), true); alert.Layout(); bool completed = false; if (data.Message.CancellationToken.CanBeCanceled) { data.Message.CancellationToken.Register(delegate { alert.InvokeOnMainThread(() => { if (!completed) { if (alert.Window.IsSheet && alert.Window.SheetParent != null) { alert.Window.SheetParent.EndSheet(alert.Window); } else { NSApplication.SharedApplication.AbortModal(); } } }); }); } int response = -1000; var parent = data.TransientFor; if (parent == null && IdeApp.Workbench?.RootWindow?.Visible == true) { parent = IdeApp.Workbench?.RootWindow; } NSWindow nativeParent; try { nativeParent = parent; } catch (NotSupportedException) { nativeParent = null; } if (!data.Message.CancellationToken.IsCancellationRequested) { // sheeting is broken on High Sierra with dark NSAppearance var sheet = IdeTheme.UserInterfaceTheme != Theme.Dark || MacSystemInformation.OsVersion != MacSystemInformation.HighSierra; // We have an issue with accessibility when using sheets, so disable it here sheet &= !IdeServices.DesktopService.AccessibilityInUse; if (!sheet || nativeParent == null) { // Force the alert window to be focused for accessibility NSApplication.SharedApplication.AccessibilityFocusedWindow = alert.Window; alert.Window.AccessibilityFocused = true; if (nativeParent != null) { nativeParent.AccessibilityFocused = false; } alert.Window.ReleasedWhenClosed = true; response = (int)alert.RunModal(); // Focus the old window NSApplication.SharedApplication.AccessibilityFocusedWindow = nativeParent; } else { alert.BeginSheet(nativeParent, (modalResponse) => { response = (int)modalResponse; NSApplication.SharedApplication.StopModal(); }); NSApplication.SharedApplication.RunModalForWindow(alert.Window); } } var result = response - (long)(int)NSAlertButtonReturn.First; completed = true; if (result >= 0 && result < buttons.Count) { data.ResultButton = buttons [(int)result]; } else { data.ResultButton = null; } if (data.ResultButton == null || data.Message.CancellationToken.IsCancellationRequested) { data.SetResultToCancelled(); } if (optionButtons != null) { foreach (var button in optionButtons) { var option = data.Options[(int)button.Tag]; data.Message.SetOptionValue(option.Id, button.State != 0); } } if (applyToAllCheck != null && applyToAllCheck.State != 0) { data.ApplyToAll = true; } if (nativeParent != null) { nativeParent.MakeKeyAndOrderFront(nativeParent); } else { IdeServices.DesktopService.FocusWindow(parent); } } return(true); }
public bool Run(AlertDialogData data) { using (var alert = new NSAlert()) { alert.Window.Title = data.Title ?? BrandingService.ApplicationName; IdeTheme.ApplyTheme(alert.Window); bool stockIcon; if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Error || data.Message.Icon == Gtk.Stock.DialogError) { alert.AlertStyle = NSAlertStyle.Critical; stockIcon = true; } else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning || data.Message.Icon == Gtk.Stock.DialogWarning) { alert.AlertStyle = NSAlertStyle.Critical; stockIcon = true; } else { alert.AlertStyle = NSAlertStyle.Informational; stockIcon = data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information; } if (!stockIcon && !string.IsNullOrEmpty(data.Message.Icon)) { var img = ImageService.GetIcon(data.Message.Icon, Gtk.IconSize.Dialog); // HACK: VK The icon is not rendered in dark style correctly // Use light variant and reder it here // as long as NSAppearance.NameVibrantDark is broken if (IdeTheme.UserInterfaceTheme == Theme.Dark) { alert.Icon = img.WithStyles("-dark").ToBitmap(GtkWorkarounds.GetScaleFactor()).ToNSImage(); } else { alert.Icon = img.ToNSImage(); } } else { //for some reason the NSAlert doesn't pick up the app icon by default alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; } 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; } } var wrappers = new List <AlertButtonWrapper> (buttons.Count); 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"); } var nsbutton = alert.AddButton(label); var wrapperButton = new AlertButtonWrapper(nsbutton, data.Message, button, alert); wrappers.Add(wrapperButton); nsbutton.Target = wrapperButton; nsbutton.Action = new ObjCRuntime.Selector("buttonActivatedAction"); } 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"); } // Hack up a slightly wider than normal alert dialog. I don't know how to do this in a nicer way // as the min size constraints are apparently ignored. var frame = alert.Window.Frame; alert.Window.SetFrame(new CGRect(frame.X, frame.Y, NMath.Max(frame.Width, 600), frame.Height), true); alert.Layout(); bool completed = false; if (data.Message.CancellationToken.CanBeCanceled) { data.Message.CancellationToken.Register(delegate { alert.InvokeOnMainThread(() => { if (!completed) { if (alert.Window.IsSheet && alert.Window.SheetParent != null) { alert.Window.SheetParent.EndSheet(alert.Window); } else { NSApplication.SharedApplication.AbortModal(); } } }); }); } int response = -1000; if (!data.Message.CancellationToken.IsCancellationRequested) { NSWindow parent = null; if (IdeTheme.UserInterfaceTheme != Theme.Dark || MacSystemInformation.OsVersion < MacSystemInformation.HighSierra) // sheeting is broken on High Sierra with dark NSAppearance { parent = data.TransientFor ?? IdeApp.Workbench.RootWindow; } if (parent == null) { response = (int)alert.RunModal(); } else { alert.BeginSheet(parent, (modalResponse) => { response = (int)modalResponse; NSApplication.SharedApplication.StopModal(); }); NSApplication.SharedApplication.RunModalForWindow(alert.Window); } } var result = response - (long)(int)NSAlertButtonReturn.First; completed = true; if (result >= 0 && result < buttons.Count) { data.ResultButton = buttons [(int)result]; } else { data.ResultButton = null; } if (data.ResultButton == null || data.Message.CancellationToken.IsCancellationRequested) { data.SetResultToCancelled(); } if (optionButtons != null) { foreach (var button in optionButtons) { var option = data.Options[(int)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); }
public override void Initialize(Xwt.Backends.ApplicationContext actx) { base.Initialize(actx); IdeTheme.ApplyTheme(this.Window); }
public override void InitializeBackend(object frontend, Xwt.Backends.ApplicationContext context) { base.InitializeBackend(frontend, context); IdeTheme.ApplyTheme(this); }
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, }; IdeTheme.ApplyTheme(dialog); 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 ImageView(Stock.Add, IconSize.Button)); buttonBox.PackStart(addButton, false, false, 0); if (types [0].IsAbstract) { addButton.Sensitive = false; } Button removeButton = new Button(new ImageView(Stock.Remove, IconSize.Button)); buttonBox.PackStart(removeButton, false, false, 0); //sorting buttons Button upButton = new Button(new ImageView(Stock.GoUp, IconSize.Button)); buttonBox.PackStart(upButton, false, false, 0); Button downButton = new Button(new ImageView(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; } } } }