Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/CocoaBase/NSAttributedString document attributes
Function: You find this example project in your Plugins Download as a Xojo (Real Studio) project file within the examples folder: /CocoaBase/NSAttributedString document attributes
Project "NSAttributedString document attributes.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() dim f as FolderItem = SpecialFolder.Desktop.Child("test.doc") dim b as BinaryStream = f.OpenAsBinaryFile(false) dim s as string = b.Read(b.Length) dim d as Dictionary dim n as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithDocFormat(s,d) list.AddRow "Title", d.lookup(n.NSTitleDocumentAttribute, "") list.AddRow "Company", d.lookup(n.NSCompanyDocumentAttribute, "") list.AddRow "Copyright", d.lookup(n.NSCopyrightDocumentAttribute, "") list.AddRow "Subject", d.lookup(n.NSSubjectDocumentAttribute, "") list.AddRow "Author", d.lookup(n.NSAuthorDocumentAttribute, "") list.AddRow "Keywords", getstringArray(d, n.NSKeywordsDocumentAttribute) list.AddRow "Comment", d.lookup(n.NSCommentDocumentAttribute, "") list.AddRow "Editor", d.lookup(n.NSEditorDocumentAttribute, "") list.AddRow "CreationTime", getdate(d, n.NSCreationTimeDocumentAttribute) list.AddRow "ModificationTime", getdate(d, n.NSModificationTimeDocumentAttribute) // last save date End EventHandler
Function getdate(d as Dictionary, key as Variant) As string dim v as Variant = d.Lookup(key, nil) if v isa date then dim da as date = v Return da.SQLDateTime end if End Function
Function getstringArray(d as Dictionary, key as Variant) As string dim v as Variant = d.Lookup(key, nil) if v.IsArray then dim a(-1) as Variant = v dim s(-1) as string for each n as string in a s.Append n next Return Join(s, ", ") end if End Function
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
Module Module1
Sub AddRow(extends l as listbox, n1 as string, n2 as string) // only for older RB Version l.AddRow n1 l.Cell(l.LastIndex,1) = n2 End Sub
End Module
End Project

Feedback, Comments & Corrections

MBS Xojo Plugins