Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSAlert Test


Required plugins for this example: MBS MacBase Plugin, MBS MacControls Plugin, MBS MacCocoa Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSAlert Test

This example is the version from Wed, 13th Sep 2022.

Project "NSAlert Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control messageText Inherits TextField
ControlInstance messageText Inherits TextField
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control informativeText Inherits TextField
ControlInstance informativeText Inherits TextField
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control rightButton Inherits TextField
ControlInstance rightButton Inherits TextField
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control middleButton Inherits TextField
ControlInstance middleButton Inherits TextField
End Control
Control leftButton Inherits TextField
ControlInstance leftButton Inherits TextField
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control ShowsSuppressionButton Inherits CheckBox
ControlInstance ShowsSuppressionButton Inherits CheckBox
End Control
Control suppressionButton Inherits TextField
ControlInstance suppressionButton Inherits TextField
End Control
Control RunDialogButton Inherits PushButton
ControlInstance RunDialogButton Inherits PushButton
EventHandler Sub Action() prepare dim resultCode as integer = a.runModal result.Text = str(resultCode)+": "+a.TextForReturnCode(resultCode)+": "+a.buttonText(resultCode) End EventHandler
End Control
Control RunSheetButton Inherits PushButton
ControlInstance RunSheetButton Inherits PushButton
EventHandler Sub Action() prepare a.beginSheetModalForWindow(Self) End EventHandler
End Control
Control result Inherits TextField
ControlInstance result Inherits TextField
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
Control ShowsHelp Inherits CheckBox
ControlInstance ShowsHelp Inherits CheckBox
End Control
Control Label7 Inherits Label
ControlInstance Label7 Inherits Label
End Control
Control PopupStyle Inherits PopupMenu
ControlInstance PopupStyle Inherits PopupMenu
End Control
Control CustomIcon Inherits CheckBox
ControlInstance CustomIcon Inherits CheckBox
End Control
Sub Prepare() a = new MyNSAlertMBS a.messageText = messageText.Text a.informativeText = informativeText.Text a.showsHelp = ShowsHelp.Value a.ShowsSuppressionButton = ShowsSuppressionButton.Value if rightButton.Text.len>0 then call a.addButtonWithTitle(rightButton.Text) end if if middleButton.Text.len>0 then call a.addButtonWithTitle(middleButton.Text) end if if leftButton.Text.len>0 then call a.addButtonWithTitle(leftButton.Text) end if Dim b As NSButtonMBS = a.suppressionButton If suppressionButton.Text.Len > 0 Then // custom text b.title = suppressionButton.Text End If a.alertStyle = PopupStyle.ListIndex if CustomIcon.Value then SetIcon end if End Sub
Sub SetIcon() dim pic as Picture = LogoMBS(500) dim g as Graphics = pic.mask.Graphics g.ForeColor = &cFFFFFF g.FillRect 0, 0, g.Width, g.Height g.ForeColor = &c000000 g.FillOval 0, 0, g.Width, g.Height a.icon = new NSImageMBS(pic) End Sub
Property a As MyNSAlertMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyNSAlertMBS Inherits NSAlertMBS
EventHandler Sub SheetDidEnd(returnCode as integer) MainWindow.result.Text = str(returnCode) + ": " + TextForReturnCode(returnCode)+": "+buttonText(returnCode) End EventHandler
EventHandler Function ShowHelp() As boolean MsgBox "Show my help" Return true End EventHandler
Shared Function TextForReturnCode(n as integer) As string Select case n case NSAlertMBS.NSAlertFirstButtonReturn Return "First Button" case NSAlertMBS.NSAlertSecondButtonReturn Return "Second Button" case NSAlertMBS.NSAlertThirdButtonReturn Return "Third Button" else Return "?" end Select End Function
Function buttonText(n as integer) As string dim buttons() as Variant = me.buttons Select case n case NSAlertMBS.NSAlertFirstButtonReturn dim b as NSButtonMBS = buttons(0) Return b.title case NSAlertMBS.NSAlertSecondButtonReturn dim b as NSButtonMBS = buttons(1) Return b.title case NSAlertMBS.NSAlertThirdButtonReturn dim b as NSButtonMBS = buttons(2) Return b.title else Return "?" end Select End Function
End Class
End Project

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...