Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/IKImageBrowser/IKImageBrowser Groups
Function:
Required plugins for this example: MBS AVFoundation Plugin, MBS MacBase Plugin, MBS MacCG Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS MacFrameworks Plugin, MBS MacOSX Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/IKImageBrowser/IKImageBrowser Groups
This example is the version from Tue, 15th Apr 2013.
Project "IKImageBrowser Groups.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control MyCocoaControl Inherits CocoaControlMBS
ControlInstance MyCocoaControl Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS scrollview=new NSScrollViewMBS(0,0,me.Width,me.Height) scrollview.backgroundColor = NSColorMBS.colorWithCalibratedRGB(0.54, 0.54, 0.54, 1.0) Imagebrowser = new MyIKImageBrowserViewMBS(0, 0, me.Width, me.Height) Imagebrowser.allowsReordering = false Imagebrowser.allowsMultipleSelection = true Imagebrowser.allowsEmptySelection = true Imagebrowser.animates = true Imagebrowser.allowsDroppingOnItems=false Imagebrowser.zoomValue = 0.43 Imagebrowser.autoresizesSubviews = true Imagebrowser.cellsStyleMask = Imagebrowser.IKCellsStyleShadowed + Imagebrowser.IKCellsStyleTitled Imagebrowser.isHidden = false Imagebrowser.setValue(Imagebrowser.IKImageBrowserBackgroundColorKey, NSColorMBS.colorWithCalibratedRGB(0.54, 0.54, 0.54, 1.0)) Imagebrowser.autoresizingMask=Imagebrowser.NSViewHeightSizable+Imagebrowser.NSViewWidthSizable scrollview.documentView=Imagebrowser scrollview.hasVerticalScroller=true scrollview.hasHorizontalScroller=false //Imagebrowser.needsDisplay=true dim size as NSSizeMBS = NSMakeSizeMBS(1,1) Imagebrowser.scaleUnitSquareToSize(size) dim folder as FolderItem = SpecialFolder.Desktop.Child("test") dim files() as FolderItem = readfolder(folder) Imagebrowser.setfiles files Imagebrowser.reloadData Return scrollview End EventHandler
End Control
Control Slider1 Inherits Slider
ControlInstance Slider1 Inherits Slider
EventHandler Sub ValueChanged() Imagebrowser.zoomValue=me.value/100 End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() for x as integer = 0 to Imagebrowser.items.Ubound msgbox Imagebrowser.items(x).imageRepresentation next x End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim folder as FolderItem = SpecialFolder.Desktop.Child("photos") dim files() as FolderItem = readfolder(folder) Imagebrowser.setfiles files Imagebrowser.reloadData End EventHandler
End Control
Function readfolder(folder as FolderItem) As FolderItem() dim files() as FolderItem dim c as integer = folder.Count for i as integer = 1 to c dim item as FolderItem = folder.TrueItem(i) if item <> nil and item.Visible then if item.Directory then dim items() as FolderItem = readfolder(item) for each it as FolderItem in items files.Append it next else files.Append item end if end if next Return files End Function
Property Imagebrowser As MyIKImageBrowserViewMBS
Property scale_factor As double
Property scrollview As nsscrollViewMBS
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 MyIKImageBrowserViewMBS Inherits IKImageBrowserViewMBS
EventHandler Sub cellWasDoubleClickedAtIndex(index as integer) msgbox "double clicked on photo "+str(index) msgbox window1.Imagebrowser.items(index).imageTitle End EventHandler
EventHandler Function groupAtIndex(index as integer) As Dictionary dim d as new Dictionary dim u as integer = UBound(items) dim m as integer = u/2+1 if index = 0 then dim range as new NSRangeMBS(0, m) d.Value(me.IKImageBrowserGroupTitleKey) = "First Group" d.Value(me.IKImageBrowserGroupRangeKey) = range elseif index = 1 then dim range as new NSRangeMBS(m, u-m+1) d.Value(me.IKImageBrowserGroupTitleKey) = "Second Group" d.Value(me.IKImageBrowserGroupRangeKey) = range end if d.Value(me.IKImageBrowserGroupBackgroundColorKey) = NSColorMBS.redColor d.Value(me.IKImageBrowserGroupStyleKey) = me.IKGroupDisclosureStyle Return d End EventHandler
EventHandler Function itemAtIndex(index as integer) As IKImageBrowserItemMBS if items(index) = nil then // we auto generate here an ID for each new item we create static counter as integer counter = counter + 1 dim uid as string = str(counter) dim path as string = files(index).UnixpathMBS dim version as integer = 1 dim title as string = files(index).DisplayName items(index) = IKImageBrowserItemMBS.ItemWithPath(uid, path, version, title) end if Return items(index) End EventHandler
EventHandler Function numberOfGroups() As integer Return 2 End EventHandler
EventHandler Function numberOfItems() As integer Return UBound(files)+1 End EventHandler
EventHandler Sub removeItemsAtIndexes(indexes as NSIndexSetMBS) dim values() as integer = indexes.Values for a as integer = values.Ubound downto 0 items.Remove(values(a)) files.Remove(values(a)) next a End EventHandler
Sub setFiles(files() as FolderItem) self.files = files redim items(-1) redim items(UBound(files)) End Sub
Property files() As FolderItem
Property items() As IKImageBrowserItemMBS
End Class
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo Plugins