Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen: Improve identifier naming, quality of generated code #122

Merged
merged 13 commits into from
Jul 6, 2023
25 changes: 4 additions & 21 deletions cocoa/NSApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ type NSApplication struct {
}

func NSApplication_New() NSApplication {
return NSApplication_alloc().Init_asNSApplication()
return NSApplication_Alloc().Init_AsNSApplication()
}

func NSApp() NSApplication {
return NSApplication_sharedApplication()
return NSApplication_SharedApplication()
}

func NSApp_WithDidLaunch(cb func(notification objc.Object)) NSApplication {
Expand All @@ -49,25 +49,8 @@ func NSApp_WithDidLaunch(cb func(notification objc.Object)) NSApplication {
}

func (app NSApplication) Terminate() {
app.Terminate_(nil)
app.gen_NSApplication.Terminate(nil)
}

func (app NSApplication) SetDelegate(delegate objc.Object) {
app.SetDelegate_(delegate)
}

func (app NSApplication) Delegate() objc.Object {
return app.gen_NSApplication.Delegate()
}

func (app NSApplication) SetMainMenu(menu NSMenu) {
app.SetMainMenu_(menu)
}

func (app NSApplication) SetActivationPolicy(policy int) {
app.SetActivationPolicy_(core.NSInteger(policy))
}

func (app NSApplication) ActivateIgnoringOtherApps(flag bool) {
app.ActivateIgnoringOtherApps_(flag)
app.gen_NSApplication.SetActivationPolicy(core.NSInteger(policy))
}
2 changes: 1 addition & 1 deletion cocoa/NSBundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package cocoa
type NSBundle struct{ gen_NSBundle }

func NSBundle_Main() NSBundle {
return NSBundle_mainBundle()
return NSBundle_MainBundle()
}
4 changes: 2 additions & 2 deletions cocoa/NSColor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "github.com/progrium/macdriver/core"
type NSColor struct{ gen_NSColor }

func NSColor_Init(r, g, b, a float64) NSColor {
return NSColor_colorWithRed_green_blue_alpha_(core.CGFloat(r), core.CGFloat(g), core.CGFloat(b), core.CGFloat(a))
return NSColor_ColorWithRedGreenBlueAlpha(core.CGFloat(r), core.CGFloat(g), core.CGFloat(b), core.CGFloat(a))
}

func NSColor_Clear() NSColor {
return NSColor_clearColor()
return NSColor_ClearColor()
}
2 changes: 1 addition & 1 deletion cocoa/NSControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ type NSControl struct {
}

func NSControl_Init(frame core.NSRect) NSControl {
return NSControl_alloc().InitWithFrame__asNSControl(frame)
return NSControl_Alloc().InitWithFrame_AsNSControl(frame)
}
4 changes: 2 additions & 2 deletions cocoa/NSEvent_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func monitorGlobalReentry(event unsafe.Pointer) {
}
obj := objc.ObjectPtr(uintptr(event))
obj.Retain()
monitorCh <- NSEvent_fromRef(obj)
monitorCh <- NSEvent_FromRef(obj)
}

//export monitorLocalReentry
Expand All @@ -32,6 +32,6 @@ func monitorLocalReentry(event unsafe.Pointer) unsafe.Pointer {
}
obj := objc.ObjectPtr(uintptr(event))
obj.Retain()
monitorCh <- NSEvent_fromRef(obj)
monitorCh <- NSEvent_FromRef(obj)
return event
}
2 changes: 1 addition & 1 deletion cocoa/NSFont.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type NSFont struct{ gen_NSFont }

func NSFont_Init(fontName string, size float64) NSFont {
return NSFont_fontWithName_size_(
return NSFont_FontWithNameSize(
core.String(fontName),
core.CGFloat(size),
)
Expand Down
14 changes: 3 additions & 11 deletions cocoa/NSImage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@ type NSImage struct {
}

func NSImage_InitWithData(data core.NSDataRef) NSImage {
return NSImage_alloc().InitWithData__asNSImage(data)
return NSImage_Alloc().InitWithData_AsNSImage(data)
}

func NSImage_InitWithURL(url core.NSURL) NSImage {
return NSImage_alloc().InitWithContentsOfURL__asNSImage(url)
return NSImage_Alloc().InitWithContentsOfURL_AsNSImage(url)
}

func NSImage_ImageNamed(name string) NSImage {
return NSImage_fromRef(NSImage_alloc().Send("imageNamed:", core.String(name)))
}

func (i NSImage) SetSize(size core.NSSize) {
i.SetSize_(size)
}

func (i NSImage) SetTemplate(b bool) {
i.SetTemplate_(b)
return NSImage_FromRef(NSImage_Alloc().Send("imageNamed:", core.String(name)))
}

func (i NSImage) SetValueForKey(value, key interface{}) {
Expand Down
6 changes: 1 addition & 5 deletions cocoa/NSImageView.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@ type NSImageView struct {
}

func NSImageView_New() NSImageView {
return NSImageView_alloc().Init_asNSImageView()
}

func (imgView NSImageView) SetImage(img NSImageRef) {
imgView.gen_NSImageView.SetImage_(img)
return NSImageView_Alloc().Init_AsNSImageView()
}
2 changes: 1 addition & 1 deletion cocoa/NSImage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestNSImageSize(t *testing.T) {
img := NSImage_alloc().InitWithSize__asNSImage(core.Size(100, 200))
img := NSImage_Alloc().InitWithSize_AsNSImage(core.Size(100, 200))
size := img.Size()
assert.EqualValues(t, 100, size.Width)
assert.EqualValues(t, 200, size.Height)
Expand Down
12 changes: 0 additions & 12 deletions cocoa/NSLayoutManager.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package cocoa

import (
"github.com/progrium/macdriver/core"
)

type NSLayoutManager struct {
gen_NSLayoutManager
}

func (lm NSLayoutManager) EnsureLayoutForTextContainer(tc NSTextContainerRef) {
lm.EnsureLayoutForTextContainer_(tc)
}

func (lm NSLayoutManager) UsedRectForTextContainer(tc NSTextContainerRef) (rect core.NSRect) {
return lm.UsedRectForTextContainer_(tc)
}
25 changes: 2 additions & 23 deletions cocoa/NSMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,20 @@ package cocoa

import (
"github.com/progrium/macdriver/core"
"github.com/progrium/macdriver/objc"
)

type NSMenu struct {
gen_NSMenu
}

func NSMenu_New() NSMenu {
return NSMenu_alloc().Init_asNSMenu()
return NSMenu_Alloc().Init_AsNSMenu()
}

func NSMenu_Init(title string) NSMenu {
return NSMenu_alloc().InitWithTitle__asNSMenu(core.String(title))
}

func (menu NSMenu) SetTitle(title string) {
menu.SetTitle_(core.String(title))
return NSMenu_Alloc().InitWithTitle_AsNSMenu(core.String(title))
}

func (menu NSMenu) Title() string {
return menu.gen_NSMenu.Title().String()
}

func (menu NSMenu) AddItem(item NSMenuItemRef) {
menu.AddItem_(item)
}

func (menu NSMenu) RemoveItem(item NSMenuItemRef) {
menu.RemoveItem_(item)
}

func (menu NSMenu) SetAutoenablesItems(b bool) {
menu.SetAutoenablesItems_(b)
}

func (menu NSMenu) SetDelegate(delegate objc.Object) {
menu.SetDelegate_(delegate)
}
54 changes: 7 additions & 47 deletions cocoa/NSMenuItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@ type NSMenuItem struct {
// NSMenuItem_Init returns an initialized instance of NSMenuItem.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514858-initwithtitle?language=objc
func NSMenuItem_Init(itemName string, action objc.Selector, keyEquivalent string) NSMenuItem {
return NSMenuItem_alloc().InitWithTitle_action_keyEquivalent__asNSMenuItem(
return NSMenuItem_Alloc().InitWithTitleActionKeyEquivalent_AsNSMenuItem(
core.String(itemName), action, core.String(keyEquivalent))
}

// NSMenuItem_New returns an initialized instance of NSMenuItem.
func NSMenuItem_New() NSMenuItem {
return NSMenuItem_alloc().Init_asNSMenuItem()
return NSMenuItem_Alloc().Init_AsNSMenuItem()
}

// NSMenuItem_Separator returns a menu item that is used to separate logical groups of menu commands.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514838-separatoritem?language=objc
func NSMenuItem_Separator() NSMenuItem {
return NSMenuItem_separatorItem()
}

// SetSubmenu sets the submenu of the menu item.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514845-submenu?language=objc
func (i NSMenuItem) SetSubmenu(submenu NSMenuRef) {
i.SetSubmenu_(submenu)
return NSMenuItem_SeparatorItem()
}

// Hidden returns a boolean value that indicates whether the menu item is hidden.
Expand All @@ -41,24 +35,12 @@ func (i NSMenuItem) Hidden() bool {
return i.IsHidden()
}

// SetHidden sets a boolean value that indicates whether the menu item is hidden.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514846-hidden?language=objc
func (i NSMenuItem) SetHidden(b bool) {
i.SetHidden_(b)
}

// Enabled returns a boolean value that indicates whether the menu item is enabled.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514863-enabled?language=objc
func (i NSMenuItem) Enabled() bool {
return i.IsEnabled()
}

// SetEnabled sets a boolean value that indicates whether the menu item is enabled.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514863-enabled?language=objc
func (i NSMenuItem) SetEnabled(b bool) {
i.SetEnabled_(b)
}

// Title returns the menu item's title.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514805-title?language=objc
func (i NSMenuItem) Title() string {
Expand All @@ -68,19 +50,13 @@ func (i NSMenuItem) Title() string {
// SetTitle sets the menu item's title.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514805-title?language=objc
func (i NSMenuItem) SetTitle(s string) {
i.SetTitle_(core.String(s))
i.gen_NSMenuItem.SetTitle(core.String(s))
}

// SetAttributedTitle sets a custom string for the menu item's title.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514860-attributedtitle?language=objc
func (i NSMenuItem) SetAttributedTitle(s string) {
i.SetAttributedTitle_(core.NSAttributedString_FromString(s))
}

// SetImage sets the menu item’s image.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514819-image?language=objc
func (i NSMenuItem) SetImage(obj NSImage) {
i.SetImage_(obj)
i.gen_NSMenuItem.SetAttributedTitle(core.NSAttributedString_FromString(s))
}

// ToolTip returns a help tag for the menu item.
Expand All @@ -92,7 +68,7 @@ func (i NSMenuItem) ToolTip() string {
// SetToolTip sets a help tag for the menu item.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514848-tooltip?language=objc
func (i NSMenuItem) SetToolTip(s string) {
i.SetToolTip_(core.String(s))
i.gen_NSMenuItem.SetToolTip(core.String(s))
}

// Target returns the menu item's target.
Expand All @@ -101,32 +77,16 @@ func (i NSMenuItem) Target() objc.Object {
return i.gen_NSMenuItem.Target()
}

// SetTarget sets the menu item's target.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514843-target?language=objc
func (i NSMenuItem) SetTarget(obj objc.Object) {
i.SetTarget_(obj)
}

func (i NSMenuItem) SetView(obj NSViewRef) {
i.SetView_(obj)
}

// Action returns the menu item's action-method selector.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514825-action?language=objc
func (i NSMenuItem) Action() objc.Selector {
return objc.Sel(i.Get("action").String())
}

// SetAction sets the menu item's action-method selector.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514825-action?language=objc
func (i NSMenuItem) SetAction(sel objc.Selector) {
i.SetAction_(sel)
}

// SetState sets the state of the menu item.
// https://developer.apple.com/documentation/appkit/nsmenuitem/1514804-state?language=objc
func (i NSMenuItem) SetState(state int) {
i.SetState_(core.NSInteger(state))
i.gen_NSMenuItem.SetState(core.NSInteger(state))
}

// State returns the state of the menu item.
Expand Down
6 changes: 3 additions & 3 deletions cocoa/NSNib.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ type NSNib struct {
}

func NSNib_InitWithNibNamed_Bundle(name string, bundle NSBundle) NSNib {
return NSNib_fromRef(NSNib_alloc().Send("initWithNibNamed:bundle:", core.String(name), bundle))
return NSNib_FromRef(NSNib_Alloc().Send("initWithNibNamed:bundle:", core.String(name), bundle))
}

func NSNib_InitWithNibData_Bundle(data core.NSDataRef, bundle NSBundleRef) NSNib {
return NSNib_alloc().InitWithNibData_bundle__asNSNib(data, bundle)
return NSNib_Alloc().InitWithNibDataBundle_AsNSNib(data, bundle)
}

func (nib NSNib) InstantiateWithOwner_TopLevelObjects(owner objc.Object) (core.NSArray, bool) {
var ptr uintptr
ok := nib.Send("instantiateWithOwner:topLevelObjects:", owner, &ptr).Bool()
return core.NSArray_fromPointer(unsafe.Pointer(ptr)), ok
return core.NSArray_FromPointer(unsafe.Pointer(ptr)), ok
}

// Deprecated: use InstantiateWithOwner_TopLevelObjects
Expand Down
15 changes: 1 addition & 14 deletions cocoa/NSPasteboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ type NSPasteboard struct {
gen_NSPasteboard
}

// NSPasteboard_GeneralPasteboard is the shared pasteboard object to use for general content.
// https://developer.apple.com/documentation/appkit/nspasteboard/1530091-generalpasteboard?language=objc
func NSPasteboard_GeneralPasteboard() NSPasteboard {
return NSPasteboard_generalPasteboard()
}

// ClearContents clears the existing contents of the pasteboard.
// https://developer.apple.com/documentation/appkit/nspasteboard/1533599-clearcontents?language=objc
func (pb NSPasteboard) ClearContents() {
// TODO this returns an int, should we add that to this wrapper?
pb.gen_NSPasteboard.ClearContents()
}

// SetStringForType sets the given string as the representation for the specified type for the first item on the receiver.
// https://developer.apple.com/documentation/appkit/nspasteboard/1528225-setstring?language=objc
func (pb NSPasteboard) SetStringForType(s string, t NSPasteboardType) {
Expand All @@ -79,7 +66,7 @@ func (pb NSPasteboard) StringForType(t NSPasteboardType) string {
// DataForType returns the data for the specified type from the first item in the receiver that contains the type.
// https://developer.apple.com/documentation/appkit/nspasteboard/1531810-datafortype?language=objc
func (pb NSPasteboard) DataForType(t NSPasteboardType) core.NSData {
return core.NSData_fromRef(pb.Send("dataForType:", core.String(string(t))))
return core.NSData_FromRef(pb.Send("dataForType:", core.String(string(t))))
}

// Types is an array of the receiver’s supported data types.
Expand Down
8 changes: 2 additions & 6 deletions cocoa/NSPopover.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ const (
)

func NSPopover_Init() NSPopover {
return NSPopover_alloc().Init_asNSPopover()
return NSPopover_Alloc().Init_AsNSPopover()
}

func (p NSPopover) SetContentSize(s core.NSSize) {
p.Send("setContentSize:", s)
}

func (p NSPopover) SetBehavior(b int) {
p.SetBehavior_(core.NSInteger(b))
}

func (p NSPopover) SetAnimates(b bool) {
p.SetAnimates_(b)
p.gen_NSPopover.SetBehavior(core.NSInteger(b))
}

func (p NSPopover) SetDelegate(delegate objc.Object) {
Expand Down
Loading
Loading