Added new 'editor' example demonstrating new Edit and Format autogenerated menus

dev
Armando Rivera 3 years ago
parent 40311dab75
commit 7d2dc9b9c7
  1. 53
      examples/editor.nim

@ -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…
Cancel
Save