-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
void SetMyApplicationDelegate(); | ||
void SetMyApplicationDelegate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//go:build generate | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"text/template" | ||
) | ||
|
||
const objcbridgeH = `void SetMyApplicationDelegate();` | ||
|
||
const objcbridgeM = `#import <Cocoa/Cocoa.h> | ||
char *cFilename; | ||
// Forward declaration of the Go function to be called from C | ||
extern void GetOpeningFilepath(char* str); | ||
@interface MyApplicationDelegate : NSObject <NSApplicationDelegate> | ||
@end | ||
@implementation MyApplicationDelegate | ||
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app { | ||
return YES; | ||
} | ||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { | ||
char *utf8String = [filename UTF8String]; | ||
cFilename = strdup(utf8String); | ||
GetOpeningFilepath(cFilename); | ||
return YES; | ||
} | ||
@end | ||
void SetMyApplicationDelegate() { | ||
NSApplication *app = [NSApplication sharedApplication]; | ||
app.delegate = [[MyApplicationDelegate alloc] init]; | ||
[app activateIgnoringOtherApps:YES]; // make application foreground | ||
}` | ||
|
||
func main() { | ||
if runtime.GOOS != "darwin" { | ||
return | ||
} | ||
|
||
generateFile(filepath.Join("editor", "objcbridge.h"), objcbridgeH) | ||
generateFile(filepath.Join("editor", "objcbridge.m"), objcbridgeM) | ||
} | ||
|
||
func generateFile(filename, content string) { | ||
file, err := os.Create(filename) | ||
if err != nil { | ||
fmt.Println("Error creating file:", err) | ||
return | ||
} | ||
defer file.Close() | ||
|
||
tmpl, err := template.New("file").Parse(content) | ||
if err != nil { | ||
fmt.Println("Error parsing template:", err) | ||
return | ||
} | ||
|
||
err = tmpl.Execute(file, nil) | ||
if err != nil { | ||
fmt.Println("Error executing template:", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package goneovim | ||
|
||
//go:generate sh -c "printf %s $(git describe --tags) > editor/version.txt" | ||
//go:generate go run generate_objcbridge_darwin.go |