Skip to content

Commit a2dab3c

Browse files
committed
feat: Main menubar with CMD+q exit menu item for OSX.
refs: sciter-sdk#227 closes: sciter-sdk#232
2 parents 8dc7dc0 + 26dd283 commit a2dab3c

File tree

6 files changed

+49
-5
lines changed

6 files changed

+49
-5
lines changed

examples/demoes/09/Contents/MacOS/.gitkeep

Whitespace-only changes.

examples/demoes/09/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go build -o Contents/MacOS/09

examples/demoes/09/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"github.com/sciter-sdk/go-sciter"
5+
"github.com/sciter-sdk/go-sciter/window"
6+
)
7+
8+
func main() {
9+
win, _ := window.New(sciter.DefaultWindowCreateFlag, sciter.DefaultRect)
10+
win.AddQuitMenu()
11+
win.Show()
12+
win.Run()
13+
}

window/window_darwin.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,28 @@ package window
1010
#include <stdlib.h>
1111
1212
int Run(void) {
13-
[NSApplication sharedApplication];
14-
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
13+
[NSApplication sharedApplication];
14+
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
1515
16-
[NSApp activateIgnoringOtherApps:YES];
17-
[NSApp run];
18-
return 0;
16+
[NSApp activateIgnoringOtherApps:YES];
17+
[NSApp run];
18+
return 0;
19+
}
20+
21+
void MinimalMenu(void) {
22+
id menubar = [[NSMenu new] autorelease];
23+
id appMenuItem = [[NSMenuItem new] autorelease];
24+
[menubar addItem:appMenuItem];
25+
[NSApp setMainMenu:menubar];
26+
id appMenu = [[NSMenu new] autorelease];
27+
id appName = [[NSProcessInfo processInfo] processName];
28+
id quitTitle = [@"Quit " stringByAppendingString:appName];
29+
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle
30+
action:@selector(terminate:) keyEquivalent:@"q"]
31+
autorelease];
32+
33+
[appMenu addItem:quitMenuItem];
34+
[appMenuItem setSubmenu:appMenu];
1935
}
2036
2137
void SetWindowTitle(void * w, char * title) {
@@ -58,11 +74,17 @@ func (s *Window) SetTitle(title string) {
5874
C.free(unsafe.Pointer(t))
5975
}
6076

77+
// Add a simple menu with a Quit item in it.
78+
func (s *Window) AddQuitMenu() {
79+
C.MinimalMenu()
80+
}
81+
6182
func (s *Window) Show() {
6283
C.ShowWindow(unsafe.Pointer(s.GetHwnd()))
6384
}
6485

6586
func (s *Window) Run() {
6687
s.run()
88+
6789
C.Run()
6890
}

window/window_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (s *Window) SetTitle(title string) {
5050
C.free(unsafe.Pointer(t))
5151
}
5252

53+
func (s *Window) AddQuitMenu() {
54+
// Define behaviour for linux
55+
}
56+
5357
func (s *Window) Show() {
5458
w := (*C.GtkWidget)(unsafe.Pointer(s.GetHwnd()))
5559
C.gshow(w)

window/window_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func (s *Window) SetTitle(title string) {
4949
C.SetWindowTextW(hwnd, (*C.WCHAR)(unsafe.Pointer(sciter.StringToWcharPtr(title))))
5050
}
5151

52+
func (s *Window) AddQuitMenu() {
53+
// Define behaviour for windows
54+
}
55+
5256
func (s *Window) Run() {
5357
// for system drag-n-drop
5458
// win.OleInitialize()

0 commit comments

Comments
 (0)