static void SetCommonPanelProperties(TData data, NSSavePanel panel) { if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) { IdeTheme.ApplyTheme(panel); } panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty(data.Title)) { panel.Title = data.Title; } if (!string.IsNullOrEmpty(data.InitialFileName)) { panel.NameFieldStringValue = data.InitialFileName; } if (!string.IsNullOrEmpty(data.CurrentFolder)) { panel.DirectoryUrl = new NSUrl(data.CurrentFolder, true); } panel.ParentWindow = NSApplication.SharedApplication.KeyWindow ?? NSApplication.SharedApplication.MainWindow; if (panel is NSOpenPanel openPanel) { openPanel.AllowsMultipleSelection = data.SelectMultiple; openPanel.ShowsHiddenFiles = data.ShowHidden; } }
internal override void SetMainWindowDecorations(Gtk.Window window) { NSWindow w = GtkQuartz.GetWindow(window); w.IsOpaque = true; w.StyleMask |= NSWindowStyle.UnifiedTitleAndToolbar; IdeTheme.ApplyTheme(w); }
void InitApp(CommandManager commandManager) { if (initedApp) { return; } commandManager.CommandActivating += OnCommandActivating; //mac-ify these command names commandManager.GetCommand(EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString("Preferences..."); commandManager.GetCommand(EditCommands.DefaultPolicies).Text = GettextCatalog.GetString("Policies..."); commandManager.GetCommand(HelpCommands.About).Text = GetAboutCommandText(); commandManager.GetCommand(MacIntegrationCommands.HideWindow).Text = GetHideWindowCommandText(); commandManager.GetCommand(ToolCommands.AddinManager).Text = GettextCatalog.GetString("Extensions..."); initedApp = true; IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent; if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) { IdeApp.Workbench.RootWindow.Realized += (sender, args) => { var win = GtkQuartz.GetWindow((Gtk.Window)sender); win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary; }; } PatchGtkTheme(); NSNotificationCenter.DefaultCenter.AddObserver(NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread( delegate { Styles.LoadStyle(); PatchGtkTheme(); })); Styles.Changed += (s, a) => { var colorPanel = NSColorPanel.SharedColorPanel; if (colorPanel.ContentView?.Superview?.Window == null) { LoggingService.LogWarning("Updating shared color panel appearance failed, no valid window."); } IdeTheme.ApplyTheme(colorPanel.ContentView.Superview.Window); var appearance = colorPanel.ContentView.Superview.Window.Appearance; if (appearance == null) { appearance = NSAppearance.GetAppearance(IdeApp.Preferences.UserInterfaceTheme == Theme.Light ? NSAppearance.NameAqua : NSAppearance.NameVibrantDark); } // The subviews of the shared NSColorPanel do not inherit the appearance of the main panel window // and need to be updated recursively. UpdateColorPanelSubviewsAppearance(colorPanel.ContentView.Superview, appearance); }; // FIXME: Immediate theme switching disabled, until NSAppearance issues are fixed //IdeApp.Preferences.UserInterfaceTheme.Changed += (s,a) => PatchGtkTheme (); }
public static Brainf_ckTheme AsBrainf_ckTheme(this IdeTheme theme) { return(theme switch { IdeTheme.VisualStudio => Brainf_ckThemes.VisualStudio, IdeTheme.VisualStudioCode => Brainf_ckThemes.VisualStudioCode, IdeTheme.Monokai => Brainf_ckThemes.Monokai, IdeTheme.Base16 => Brainf_ckThemes.Base16, IdeTheme.XCodeDark => Brainf_ckThemes.XCodeDark, IdeTheme.Dracula => Brainf_ckThemes.Dracula, IdeTheme.OneDark => Brainf_ckThemes.OneDark, IdeTheme.Vim => Brainf_ckThemes.Vim, _ => ThrowHelper.ThrowArgumentOutOfRangeException <Brainf_ckTheme>("Invalid requested theme") });
public TextEditorDialog() { Gtk.ScrolledWindow sc = new Gtk.ScrolledWindow(); sc.HscrollbarPolicy = Gtk.PolicyType.Automatic; sc.VscrollbarPolicy = Gtk.PolicyType.Automatic; sc.ShadowType = Gtk.ShadowType.In; sc.BorderWidth = 6; textview = new Gtk.TextView(); sc.Add(textview); dialog = new Gtk.Dialog(); IdeTheme.ApplyTheme(dialog); dialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); dialog.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok); dialog.VBox.Add(sc); }
public FlagsSelectorDialog(Gtk.Window parent, Type enumDesc, ulong flags, string title) { this.flags = flags; this.parent = parent; Gtk.ScrolledWindow sc = new Gtk.ScrolledWindow(); sc.HscrollbarPolicy = Gtk.PolicyType.Automatic; sc.VscrollbarPolicy = Gtk.PolicyType.Automatic; sc.ShadowType = Gtk.ShadowType.In; sc.BorderWidth = 6; treeView = new Gtk.TreeView(); sc.Add(treeView); dialog = new Gtk.Dialog(); IdeTheme.ApplyTheme(dialog); dialog.VBox.Add(sc); dialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel); dialog.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok); store = new Gtk.ListStore(typeof(bool), typeof(string), typeof(ulong)); treeView.Model = store; treeView.HeadersVisible = false; Gtk.TreeViewColumn col = new Gtk.TreeViewColumn(); Gtk.CellRendererToggle tog = new Gtk.CellRendererToggle(); tog.Toggled += new Gtk.ToggledHandler(OnToggled); col.PackStart(tog, false); col.AddAttribute(tog, "active", 0); Gtk.CellRendererText crt = new Gtk.CellRendererText(); col.PackStart(crt, true); col.AddAttribute(crt, "text", 1); treeView.AppendColumn(col); values = System.Enum.GetValues(enumDesc); foreach (object value in values) { ulong val = Convert.ToUInt64(value); store.AppendValues((flags == 0 && val == 0) || ((flags & val) != 0), value.ToString(), val); } }
static void SetCommonPanelProperties(TData data, NSSavePanel panel) { if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) { IdeTheme.ApplyTheme(panel); } panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty(data.Title)) { panel.Title = data.Title; } if (!string.IsNullOrEmpty(data.InitialFileName)) { panel.NameFieldStringValue = data.InitialFileName; } if (!string.IsNullOrEmpty(data.CurrentFolder)) { panel.DirectoryUrl = new NSUrl(data.CurrentFolder, true); } if (MacSystemInformation.OsVersion < MacSystemInformation.Catalina) { //set ParentWindow in NSSavePanel is broken in Catalina, we need a fix in cocoa var parentWindow = (NSWindow)IdeServices.DesktopService.GetFocusedTopLevelWindow(); if (parentWindow != null) { panel.ParentWindow = parentWindow; } } if (panel is NSOpenPanel openPanel) { openPanel.AllowsMultipleSelection = data.SelectMultiple; openPanel.ShowsHiddenFiles = data.ShowHidden; } }
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(ExceptionDialogData data) { using (var alert = new NSAlert { AlertStyle = NSAlertStyle.Critical }) { IdeTheme.ApplyTheme(alert.Window); alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; alert.MessageText = data.Title ?? GettextCatalog.GetString("Error"); if (!string.IsNullOrEmpty(data.Message)) { alert.InformativeText = data.Message; } List <AlertButton> buttons = null; if (data.Buttons != null && data.Buttons.Length > 0) { buttons = data.Buttons.Reverse().ToList(); } if (buttons != null) { foreach (var button in buttons) { var label = button.Label; if (button.IsStockButton) { label = Gtk.Stock.Lookup(label).Label; } label = label.Replace("_", ""); //this message seems to be a standard Mac message since alert handles it specially if (button == AlertButton.CloseWithoutSave) { label = GettextCatalog.GetString("Don't Save"); } alert.AddButton(label); } } if (data.Exception != null) { var scrollSize = new CGSize(400, 130); const float spacing = 4; string title = GettextCatalog.GetString("View details"); string altTitle = GettextCatalog.GetString("Hide details"); var buttonFrame = new CGRect(0, 0, 0, 0); var button = new NSButton(buttonFrame) { BezelStyle = NSBezelStyle.Disclosure, Title = "", AlternateTitle = "", }; button.SetButtonType(NSButtonType.OnOff); button.SizeToFit(); var label = new MDClickableLabel(title) { Alignment = NSTextAlignment.Left, }; label.SizeToFit(); button.SetFrameSize(new CGSize(button.Frame.Width, NMath.Max(button.Frame.Height, label.Frame.Height))); label.SetFrameOrigin(new CGPoint(button.Frame.Width + 5, button.Frame.Y)); var text = new MyTextView(new CGRect(0, 0, float.MaxValue, float.MaxValue)) { HorizontallyResizable = true, }; text.TextContainer.ContainerSize = new CGSize(float.MaxValue, float.MaxValue); text.TextContainer.WidthTracksTextView = true; text.InsertText(new NSString(data.Exception.ToString())); text.Editable = false; var scrollView = new NSScrollView(new CGRect(CGPoint.Empty, CGSize.Empty)) { HasHorizontalScroller = true, HasVerticalScroller = true, }; var accessory = new NSView(new CGRect(0, 0, scrollSize.Width, button.Frame.Height)); accessory.AddSubview(scrollView); accessory.AddSubview(button); accessory.AddSubview(label); alert.AccessoryView = accessory; button.Activated += delegate { nfloat change; if (button.State == NSCellStateValue.On) { change = scrollSize.Height + spacing; label.StringValue = altTitle; scrollView.Hidden = false; scrollView.Frame = new CGRect(CGPoint.Empty, scrollSize); scrollView.DocumentView = text; } else { change = -(scrollSize.Height + spacing); label.StringValue = title; scrollView.Hidden = true; scrollView.Frame = new CGRect(CGPoint.Empty, CGSize.Empty); } var f = accessory.Frame; f.Height += change; accessory.Frame = f; var lf = label.Frame; lf.Y += change; label.Frame = lf; var bf = button.Frame; bf.Y += change; button.Frame = bf; label.SizeToFit(); var panel = alert.Window; var pf = panel.Frame; pf.Height += change; pf.Y -= change; panel.SetFrame(pf, true, true); //unless we assign the icon again, it starts nesting old icon into the warning icon alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; alert.Layout(); }; label.OnMouseUp += (sender, e) => button.PerformClick(e.Event); } var result = (int)(nint)alert.RunModal() - (int)(long)NSAlertButtonReturn.First; data.ResultButton = buttons != null ? buttons [result] : null; GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); } return(true); }
int Run(MonoDevelopOptions options) { LoggingService.LogInfo("Starting {0} {1}", BrandingService.ApplicationLongName, IdeVersionInfo.MonoDevelopVersion); LoggingService.LogInfo("Build Information{0}{1}", Environment.NewLine, SystemInformation.GetBuildInformation()); LoggingService.LogInfo("Running on {0}", IdeVersionInfo.GetRuntimeInfo()); //ensure native libs initialized before we hit anything that p/invokes Platform.Initialize(); GettextCatalog.Initialize(); LoggingService.LogInfo("Operating System: {0}", SystemInformation.GetOperatingSystemDescription()); if (!Platform.IsWindows) { // The assembly resolver for MSBuild 15 assemblies needs to be defined early on. // Whilst Runtime.Initialize loads the MSBuild 15 assemblies from Mono this seems // to be too late to prevent the MEF composition and the static registrar from // failing to load the MonoDevelop.Ide assembly which now uses MSBuild 15 assemblies. ResolveMSBuildAssemblies(); } Counters.Initialization.BeginTiming(); if (options.PerfLog) { string logFile = Path.Combine(Environment.CurrentDirectory, "monodevelop.perf-log"); LoggingService.LogInfo("Logging instrumentation service data to file: " + logFile); InstrumentationService.StartAutoSave(logFile, 1000); } Counters.Initialization.Trace("Initializing GTK"); if (Platform.IsWindows && !CheckWindowsGtk()) { return(1); } SetupExceptionManager(); // explicit GLib type system initialization for GLib < 2.36 before any other type system access GLib.GType.Init(); IdeApp.Customizer = options.IdeCustomizer ?? new IdeCustomizer(); try { IdeApp.Customizer.Initialize(); } catch (UnauthorizedAccessException ua) { LoggingService.LogError("Unauthorized access: " + ua.Message); return(1); } try { GLibLogging.Enabled = true; } catch (Exception ex) { LoggingService.LogError("Error initialising GLib logging.", ex); } var args = options.RemainingArgs.ToArray(); IdeTheme.InitializeGtk(BrandingService.ApplicationName, ref args); LoggingService.LogInfo("Using GTK+ {0}", IdeVersionInfo.GetGtkVersion()); // XWT initialization FilePath p = typeof(IdeStartup).Assembly.Location; Runtime.LoadAssemblyFrom(p.ParentDirectory.Combine("Xwt.Gtk.dll")); Xwt.Application.InitializeAsGuest(Xwt.ToolkitType.Gtk); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarWindowBackend, GtkExtendedTitleBarWindowBackend> (); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarDialogBackend, GtkExtendedTitleBarDialogBackend> (); IdeTheme.SetupXwtTheme(); //default to Windows IME on Windows if (Platform.IsWindows && GtkWorkarounds.GtkMinorVersion >= 16) { var settings = Gtk.Settings.Default; var val = GtkWorkarounds.GetProperty(settings, "gtk-im-module"); if (string.IsNullOrEmpty(val.Val as string)) { GtkWorkarounds.SetProperty(settings, "gtk-im-module", new GLib.Value("ime")); } } string socket_filename = null; EndPoint ep = null; DispatchService.Initialize(); // Set a synchronization context for the main gtk thread SynchronizationContext.SetSynchronizationContext(DispatchService.SynchronizationContext); Runtime.MainSynchronizationContext = SynchronizationContext.Current; // Initialize Roslyn's synchronization context RoslynServices.RoslynService.Initialize(); AddinManager.AddinLoadError += OnAddinError; var startupInfo = new StartupInfo(args); // If a combine was specified, force --newwindow. if (!options.NewWindow && startupInfo.HasFiles) { Counters.Initialization.Trace("Pre-Initializing Runtime to load files in existing window"); Runtime.Initialize(true); foreach (var file in startupInfo.RequestedFileList) { if (MonoDevelop.Projects.Services.ProjectService.IsWorkspaceItemFile(file.FileName)) { options.NewWindow = true; break; } } } Counters.Initialization.Trace("Initializing Runtime"); Runtime.Initialize(true); IdeApp.Customizer.OnCoreInitialized(); Counters.Initialization.Trace("Initializing theme"); IdeTheme.SetupGtkTheme(); ProgressMonitor monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor(); monitor.BeginTask(GettextCatalog.GetString("Starting {0}", BrandingService.ApplicationName), 2); //make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events Counters.Initialization.Trace("Initializing Platform Service"); DesktopService.Initialize(); monitor.Step(1); if (options.IpcTcp) { listen_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); ep = new IPEndPoint(IPAddress.Loopback, ipcBasePort + HashSdbmBounded(Environment.UserName)); } else { socket_filename = "/tmp/md-" + Environment.GetEnvironmentVariable("USER") + "-socket"; listen_socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); ep = new UnixEndPoint(socket_filename); } // If not opening a combine, connect to existing monodevelop and pass filename(s) and exit if (!options.NewWindow && startupInfo.HasFiles) { try { StringBuilder builder = new StringBuilder(); foreach (var file in startupInfo.RequestedFileList) { builder.AppendFormat("{0};{1};{2}\n", file.FileName, file.Line, file.Column); } listen_socket.Connect(ep); listen_socket.Send(Encoding.UTF8.GetBytes(builder.ToString())); return(0); } catch { // Reset the socket if (null != socket_filename && File.Exists(socket_filename)) { File.Delete(socket_filename); } } } Counters.Initialization.Trace("Checking System"); CheckFileWatcher(); Exception error = null; int reportedFailures = 0; try { Counters.Initialization.Trace("Loading Icons"); //force initialisation before the workbench so that it can register stock icons for GTK before they get requested ImageService.Initialize(); LocalizationService.Initialize(); // If we display an error dialog before the main workbench window on OS X then a second application menu is created // which is then replaced with a second empty Apple menu. // XBC #33699 Counters.Initialization.Trace("Initializing IdeApp"); IdeApp.Initialize(monitor); if (errorsList.Count > 0) { using (AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), false)) { if (!dlg.Run()) { return(1); } } reportedFailures = errorsList.Count; } if (!CheckSCPlugin()) { return(1); } // Load requested files Counters.Initialization.Trace("Opening Files"); // load previous combine RecentFile openedProject = null; if (IdeApp.Preferences.LoadPrevSolutionOnStartup && !startupInfo.HasSolutionFile && !IdeApp.Workspace.WorkspaceItemIsOpening && !IdeApp.Workspace.IsOpen) { openedProject = DesktopService.RecentFiles.MostRecentlyUsedProject; if (openedProject != null) { var metadata = GetOpenWorkspaceOnStartupMetadata(); IdeApp.Workspace.OpenWorkspaceItem(openedProject.FileName, true, true, metadata).ContinueWith(t => IdeApp.OpenFiles(startupInfo.RequestedFileList, metadata), TaskScheduler.FromCurrentSynchronizationContext()); startupInfo.OpenedRecentProject = true; } } if (openedProject == null) { IdeApp.OpenFiles(startupInfo.RequestedFileList, GetOpenWorkspaceOnStartupMetadata()); startupInfo.OpenedFiles = startupInfo.HasFiles; } monitor.Step(1); } catch (Exception e) { error = e; } finally { monitor.Dispose(); } if (error != null) { string message = BrandingService.BrandApplicationName(GettextCatalog.GetString("MonoDevelop failed to start")); MessageService.ShowFatalError(message, null, error); return(1); } if (errorsList.Count > reportedFailures) { using (AddinLoadErrorDialog dlg = new AddinLoadErrorDialog((AddinError[])errorsList.ToArray(typeof(AddinError)), true)) dlg.Run(); } errorsList = null; AddinManager.AddinLoadError -= OnAddinError; // FIXME: we should probably track the last 'selected' one // and do this more cleanly try { listen_socket.Bind(ep); listen_socket.Listen(5); listen_socket.BeginAccept(new AsyncCallback(ListenCallback), listen_socket); } catch { // Socket already in use } initialized = true; MessageService.RootWindow = IdeApp.Workbench.RootWindow; Xwt.MessageDialog.RootWindow = Xwt.Toolkit.CurrentEngine.WrapWindow(IdeApp.Workbench.RootWindow); Thread.CurrentThread.Name = "GUI Thread"; Counters.Initialization.Trace("Running IdeApp"); Counters.Initialization.EndTiming(); AddinManager.AddExtensionNodeHandler("/MonoDevelop/Ide/InitCompleteHandlers", OnExtensionChanged); StartLockupTracker(); startupTimer.Stop(); CreateStartupMetadata(startupInfo); GLib.Idle.Add(OnIdle); IdeApp.Run(); IdeApp.Customizer.OnIdeShutdown(); // unloading services if (null != socket_filename) { File.Delete(socket_filename); } lockupCheckRunning = false; Runtime.Shutdown(); IdeApp.Customizer.OnCoreShutdown(); InstrumentationService.Stop(); MonoDevelop.Components.GtkWorkarounds.Terminate(); return(0); }
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.UserInterfaceSkin == Skin.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) { NSApplication.SharedApplication.AbortModal(); } }); }); } if (!data.Message.CancellationToken.IsCancellationRequested) { var result = (int)alert.RunModal() - (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); }
int Run(MonoDevelopOptions options) { LoggingService.LogInfo("Starting {0} {1}", BrandingService.ApplicationLongName, IdeVersionInfo.MonoDevelopVersion); LoggingService.LogInfo("Build Information{0}{1}", Environment.NewLine, SystemInformation.GetBuildInformation()); LoggingService.LogInfo("Running on {0}", RuntimeVersionInfo.GetRuntimeInfo()); //ensure native libs initialized before we hit anything that p/invokes Platform.Initialize(); IdeStartupTracker.StartupTracker.MarkSection("PlatformInitialization"); GettextCatalog.Initialize(); IdeStartupTracker.StartupTracker.MarkSection("GettextInitialization"); LoggingService.LogInfo("Operating System: {0}", SystemInformation.GetOperatingSystemDescription()); // The assembly resolver for MSBuild 15 assemblies needs to be defined early on. // Whilst Runtime.Initialize loads the MSBuild 15 assemblies from Mono this seems // to be too late to prevent the MEF composition and the static registrar from // failing to load the MonoDevelop.Ide assembly which now uses MSBuild 15 assemblies. ResolveMSBuildAssemblies(); Counters.InitializationTracker = Counters.Initialization.BeginTiming(); if (options.PerfLog) { string logFile = Path.Combine(Environment.CurrentDirectory, "monodevelop.perf-log"); LoggingService.LogInfo("Logging instrumentation service data to file: " + logFile); InstrumentationService.StartAutoSave(logFile, 1000); } Counters.InitializationTracker.Trace("Initializing GTK"); if (Platform.IsWindows && !CheckWindowsGtk()) { return(1); } SetupExceptionManager(); // explicit GLib type system initialization for GLib < 2.36 before any other type system access GLib.GType.Init(); var args = options.RemainingArgs.ToArray(); IdeTheme.InitializeGtk(BrandingService.ApplicationName, ref args); startupInfo = new StartupInfo(options, args); if (startupInfo.HasFiles) { // If files are present, consider started from the commandline as being the same as file manager. // On macOS, we need to wait until the DidFinishLaunching notification to find out we were launched from the Finder IdeApp.LaunchReason = IdeApp.LaunchType.LaunchedFromFileManager; } else if (!Platform.IsMac) { IdeApp.LaunchReason = IdeApp.LaunchType.Normal; } IdeApp.Customizer = options.IdeCustomizer ?? new IdeCustomizer(); try { IdeApp.Customizer.Initialize(startupInfo); } catch (UnauthorizedAccessException ua) { LoggingService.LogError("Unauthorized access: " + ua.Message); return(1); } try { GLibLogging.Enabled = true; } catch (Exception ex) { LoggingService.LogError("Error initialising GLib logging.", ex); } IdeStartupTracker.StartupTracker.MarkSection("GtkInitialization"); LoggingService.LogInfo("Using GTK+ {0}", IdeVersionInfo.GetGtkVersion()); // XWT initialization FilePath p = typeof(IdeStartup).Assembly.Location; Runtime.LoadAssemblyFrom(p.ParentDirectory.Combine("Xwt.Gtk.dll")); Xwt.Application.InitializeAsGuest(Xwt.ToolkitType.Gtk); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarWindowBackend, GtkExtendedTitleBarWindowBackend> (); Xwt.Toolkit.CurrentEngine.RegisterBackend <IExtendedTitleBarDialogBackend, GtkExtendedTitleBarDialogBackend> (); IdeTheme.SetupXwtTheme(); IdeStartupTracker.StartupTracker.MarkSection("XwtInitialization"); //default to Windows IME on Windows if (Platform.IsWindows && GtkWorkarounds.GtkMinorVersion >= 16) { var settings = Gtk.Settings.Default; var val = GtkWorkarounds.GetProperty(settings, "gtk-im-module"); if (string.IsNullOrEmpty(val.Val as string)) { GtkWorkarounds.SetProperty(settings, "gtk-im-module", new GLib.Value("ime")); } } DispatchService.Initialize(); // Set a synchronization context for the main gtk thread SynchronizationContext.SetSynchronizationContext(DispatchService.SynchronizationContext); Runtime.MainSynchronizationContext = SynchronizationContext.Current; IdeStartupTracker.StartupTracker.MarkSection("DispatchInitialization"); // Initialize Roslyn's synchronization context RoslynServices.RoslynService.Initialize(); IdeStartupTracker.StartupTracker.MarkSection("RoslynInitialization"); AddinManager.AddinLoadError += OnAddinError; Counters.InitializationTracker.Trace("Initializing Runtime"); Runtime.Initialize(true); // Register services used by the IDE RegisterServices(); // If a combine was specified, force --newwindow. if (!options.NewWindow && startupInfo.HasFiles) { foreach (var file in startupInfo.RequestedFileList) { if (MonoDevelop.Projects.Services.ProjectService.IsWorkspaceItemFile(file.FileName)) { options.NewWindow = true; break; } } } instanceConnection = new IdeInstanceConnection(options.IpcTcp); // If not opening a combine, connect to existing monodevelop and pass filename(s) and exit if (!options.NewWindow && startupInfo.HasFiles && instanceConnection.TryConnect(startupInfo)) { return(0); } IdeStartupTracker.StartupTracker.MarkSection("RuntimeInitialization"); bool restartRequested = PropertyService.Get("MonoDevelop.Core.RestartRequested", false); startupInfo.Restarted = restartRequested; PropertyService.Set("MonoDevelop.Core.RestartRequested", false); Counters.InitializationTracker.Trace("Initializing theme"); IdeTheme.SetupGtkTheme(); IdeApp.Customizer.OnCoreInitialized(); IdeStartupTracker.StartupTracker.MarkSection("ThemeInitialized"); IdeApp.IsRunning = true; // Load the main menu before running the main loop var commandService = Runtime.GetService <CommandManager> ().Result; var desktopService = Runtime.GetService <DesktopService> ().Result; desktopService.SetGlobalMenu(commandService, DefaultWorkbench.MainMenuPath, DefaultWorkbench.AppMenuPath); // Run the main loop Gtk.Application.Invoke((s, e) => { MainLoop(options, startupInfo).Ignore(); }); Gtk.Application.Run(); IdeApp.IsRunning = false; IdeApp.Customizer.OnIdeShutdown(); instanceConnection.Dispose(); lockupCheckRunning = false; Runtime.Shutdown(); IdeApp.Customizer.OnCoreShutdown(); InstrumentationService.Stop(); MonoDevelop.Components.GtkWorkarounds.Terminate(); return(0); }
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 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; } } } }
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); }
void UpdateCell() { Appearance = IdeTheme.GetAppearance(); NeedsDisplay = true; }