mirror of
https://github.com/Airr/nim-cocoa.git
synced 2024-11-24 09:45:30 +00:00
Added new 'editor' example demonstrating new Edit and Format autogenerated menus
This commit is contained in:
parent
40311dab75
commit
7d2dc9b9c7
53
examples/editor.nim
Normal file
53
examples/editor.nim
Normal file
@ -0,0 +1,53 @@
|
||||
import Cocoa / [NSWindow,
|
||||
NSFunctions,
|
||||
NSMenu,
|
||||
NSTextedit,
|
||||
NSOpenDialog
|
||||
]
|
||||
|
||||
const
|
||||
winStyle = NSWindowStyleMaskTitled or
|
||||
NSWindowStyleMaskClosable or
|
||||
NSWindowStyleMaskMiniaturizable or
|
||||
NSWindowStyleMaskResizable
|
||||
|
||||
width = 800
|
||||
height = 600
|
||||
|
||||
type
|
||||
GUI = object
|
||||
window: ID
|
||||
editor: ID
|
||||
|
||||
var self: GUI
|
||||
|
||||
proc openClicked(sender:ID) {.cdecl.} =
|
||||
let fName = newOpenDialog(self.window, "nim")
|
||||
if fName.len > 0:
|
||||
let fText = readFile($fName)
|
||||
self.editor.text = fText
|
||||
|
||||
proc setupMenus() =
|
||||
var f = newMenu("File")
|
||||
newMenuItem(f, "New","n",nil)
|
||||
newMenuItem(f, "Open...","o", openClicked)
|
||||
newMenuSeparator(f)
|
||||
newMenuItem(f, "Close","w",nil)
|
||||
newMenuItem(f, "Save","s",nil)
|
||||
newMenuItem(f, "Save As...","S",nil)
|
||||
newMenuSeparator(f)
|
||||
newMenuItem(f, "Page Setup...","P",nil)
|
||||
newMenuItem(f, "Print...","p",nil)
|
||||
|
||||
newEditMenu()
|
||||
newFormatMenu()
|
||||
|
||||
|
||||
Cocoa_Init()
|
||||
|
||||
self.window = newWindow("Template", width, height, winStyle)
|
||||
self.editor = newTextEdit(self.window,"", 20, 20, width-40, height-40)
|
||||
setupMenus()
|
||||
|
||||
Cocoa_Run(self.window)
|
||||
|
Loading…
Reference in New Issue
Block a user