diff options
| author | Pietro Gagliardi <[email protected]> | 2014-03-01 17:06:06 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-03-01 17:06:06 -0500 |
| commit | 8b497b2188bc735710a6ef83b0b05487a4b3ee83 (patch) | |
| tree | 3659194cf0fb903ebc2cc9ae40241bf5a03eb2af /sysdata_darwin.go | |
| parent | 56eb64429d64a7948ce8c40e823710a9ece876ec (diff) | |
Added the getSysData() hook. Now to clean up loose ends and apply the delegate to the window.
Diffstat (limited to 'sysdata_darwin.go')
| -rw-r--r-- | sysdata_darwin.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/sysdata_darwin.go b/sysdata_darwin.go index 33fd1e8..9cbbee9 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -4,6 +4,7 @@ package ui import ( "fmt" "unsafe" + "sync" ) // #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit @@ -96,6 +97,29 @@ var classTypes = [nctypes]*classData{ }, } +// I need to access sysData from appDelegate, but appDelegate doesn't store any data. So, this. +var ( + sysdatas = make(map[C.id]*sysData) + sysdatalock sync.Mutex +) + +func addSysData(key C.id, value *sysData) { + sysdatalock.Lock() + sysdatas[key] = value + sysdatalock.Unlock() +} + +func getSysData(key C.id) *sysData { + sysdatalock.Lock() + defer sysdatalock.Unlock() + + v, ok := sysdatas[key] + if !ok { + panic(fmt.Errorf("internal error: getSysData(%v) unknown", key)) + } + return v +} + func (s *sysData) make(initText string, window *sysData) error { var parentWindow C.id @@ -117,6 +141,7 @@ func (s *sysData) make(initText string, window *sysData) error { if err != nil { return fmt.Errorf("error setting initial text of new window/control: %v", err) } + addSysData(s.id, s) return nil } |
