Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/TokenField/TokenField with data class
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS MacFrameworks Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/TokenField/TokenField with data class
This example is the version from Wed, 24th Mar 2015.
Project "TokenField with data class.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class TestWindow Inherits Window
Control CocoaControlMBS1 Inherits CocoaControlMBS
ControlInstance CocoaControlMBS1 Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS n=new MyNSTokenFieldMBS(0,0,me.Width,me.Height) n.tokenStyle = n.NSRoundedTokenStyle // tell it how the resize is going n.autoresizingMask=n.NSViewHeightSizable+n.NSViewWidthSizable Return n End EventHandler
End Control
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
EventHandler Sub Open() // in this example we use Data class for our objects instead of simply numbers for i as integer = 0 to 4 dim d as new DataClass(me.Cell(i,1)) if i = 1 then d.hasMenu = true // Mickey has a menu end if me.RowTag(i) = d next End EventHandler
End Control
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action() MsgBox n.StringValue End EventHandler
End Control
Control BevelButton2 Inherits BevelButton
ControlInstance BevelButton2 Inherits BevelButton
EventHandler Sub Action() dim v() as Variant = n.objects dim a() as string for each vv as Variant in v if vv isa DataClass then dim d as DataClass = vv a.Append d.item else Break // error end if next MsgBox Join(a,EndOfLine) End EventHandler
End Control
Control BevelButton3 Inherits BevelButton
ControlInstance BevelButton3 Inherits BevelButton
EventHandler Sub Action() dim v() as Variant v.Append Listbox1.RowTag(2) v.Append Listbox1.RowTag(4) n.setObjects v End EventHandler
End Control
Control BevelButton4 Inherits BevelButton
ControlInstance BevelButton4 Inherits BevelButton
EventHandler Sub Action() n.StringValue = "" End EventHandler
End Control
EventHandler Sub Open() if not CocoaControlMBS1.Available then MsgBox "This example requires Mac OS X 10.5." quit end if End EventHandler
Property n As NSTokenFieldMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyNSTokenFieldMBS Inherits NSTokenFieldMBS
EventHandler Sub Action() // this event does nothing in NSTokenFieldMBS End EventHandler
EventHandler Function completionsForSubstring(substring as string, tokenIndex as integer, byref selectedIndex as integer) As variant() dim answers() as Variant dim list as listbox = TestWindow.Listbox1 dim u as integer = list.ListCount-1 for i as integer = 0 to u if instr(list.Cell(i,1), substring)>0 or instr(list.Cell(i,2), substring)>0 then answers.Append list.Cell(i,2) end if next Return answers End EventHandler
EventHandler Function displayStringForRepresentedObject(representedObject as variant) As string if representedObject isa DataClass then dim id as DataClass = representedObject Return id.item end if End EventHandler
EventHandler Function editingStringForRepresentedObject(representedObject as variant) As string dim id as DataClass = representedObject Return id.item End EventHandler
EventHandler Function hasMenuForRepresentedObject(representedObject as variant) As boolean if representedObject isa DataClass then dim id as DataClass = representedObject Return id.hasMenu end if End EventHandler
EventHandler Function menuForRepresentedObject(representedObject as variant) As NSMenuMBS if representedObject isa DataClass then dim d as DataClass = representedObject if d.hasMenu then LastMenu = new NSMenuMBS LastMenuItem = new MyNSMenuItemMBS LastMenuItem.CreateMenuItem "Hello World" LastMenu.addItem LastMenuItem Return LastMenu end if end if End EventHandler
EventHandler Function representedObjectForEditingString(editingString as string) As variant dim list as listbox = TestWindow.Listbox1 dim u as integer = list.ListCount-1 for i as integer = 0 to u if list.Cell(i,1) = editingString or list.Cell(i,2) = editingString then Return list.RowTag(i) end if next End EventHandler
EventHandler Function shouldAddObjects(tokens() as variant, index as Integer) As variant() // add all Return tokens End EventHandler
EventHandler Function textShouldBeginEditing(fieldEditor as NSTextMBS) As boolean // this event does nothing in NSTokenFieldMBS End EventHandler
EventHandler Function textShouldEndEditing(fieldEditor as NSTextMBS) As boolean // this event does nothing in NSTokenFieldMBS End EventHandler
EventHandler Sub tokenFieldAction() System.DebugLog CurrentMethodName End EventHandler
EventHandler Function tokenFieldTextShouldBeginEditing(fieldEditor as NSTextMBS) As boolean System.DebugLog CurrentMethodName Return true End EventHandler
EventHandler Function tokenFieldTextShouldEndEditing(fieldEditor as NSTextMBS) As boolean System.DebugLog CurrentMethodName Return true End EventHandler
Property LastMenu As NSMenuMBS
Property LastMenuItem As MyNSMenuItemMBS
End Class
Class MyNSMenuItemMBS Inherits NSMenuItemMBS
EventHandler Sub Action() MsgBox "You selected menu item." End EventHandler
End Class
Class DataClass
Sub Constructor(s as string) item = s End Sub
Property hasMenu As Boolean
Property item As string
End Class
End Project

Feedback, Comments & Corrections

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





Links
MBS FileMaker Plugins