ecode: Fixes problematic default SDL menus.

This commit is contained in:
Martín Lucas Golini
2022-07-19 02:14:19 -03:00
parent 47e87f7d95
commit 146c173c1f
6 changed files with 109 additions and 4 deletions

View File

@@ -1168,10 +1168,10 @@ solution "eepp"
language "C++"
includedirs { "src/thirdparty/efsw/include", "src/thirdparty" }
if not os.is("windows") and not os.is("haiku") then
if not os.is_real("windows") and not os.is_real("haiku") then
links { "pthread" }
end
if os.is("macosx") then
if os.is_real("macosx") then
links { "CoreFoundation.framework", "CoreServices.framework" }
end
@@ -1179,6 +1179,27 @@ solution "eepp"
files { "src/tools/uieditor/*.cpp" }
build_link_configuration( "eepp-UIEditor", true )
if os.is("macosx") then
project "ecode-macos-helper-static"
kind "StaticLib"
language "C++"
files { "src/tools/ecode/macos/*.m" }
set_targetdir("libs/" .. os.get_real() .. "/thirdparty/")
configuration "debug"
defines { "DEBUG", "EE_DEBUG", "EE_MEMORY_MANAGER" }
flags { "Symbols" }
buildoptions{ "-Wall" }
buildoptions{ "-g3" }
targetname ( "ecode-macos-helper-static-debug" )
configuration "release"
defines { "NDEBUG" }
flags { "OptimizeSpeed" }
buildoptions{ "-O3" }
targetname ( "ecode-macos-helper-static" )
end
project "ecode"
set_kind()
language "C++"
@@ -1189,7 +1210,8 @@ solution "eepp"
links { "pthread" }
end
if os.is("macosx") then
links { "CoreFoundation.framework", "CoreServices.framework" }
links { "CoreFoundation.framework", "CoreServices.framework", "Cocoa.framework" }
links { "ecode-macos-helper-static" }
end
if os.is_real("linux") then
links { "util" }

View File

@@ -13,7 +13,7 @@
<key>CFBundleIconFile</key>
<string>ecode.icns</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<string>0.2</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>

View File

@@ -1139,6 +1139,8 @@
../../src/tools/ecode/globalsearchcontroller.hpp
../../src/tools/ecode/ignorematcher.cpp
../../src/tools/ecode/ignorematcher.hpp
../../src/tools/ecode/macos/macos.hpp
../../src/tools/ecode/macos/macos.m
../../src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp
../../src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp
../../src/tools/ecode/plugins/formatter/formatterplugin.cpp

View File

@@ -6,6 +6,10 @@
#include <algorithm>
#include <args/args.hxx>
#if EE_PLATFORM == EE_PLATFORM_MACOSX
#include "macos/macos.hpp"
#endif
namespace ecode {
Clock globalClock;
@@ -3277,6 +3281,10 @@ void App::init( std::string file, const Float& pidelDensity, const std::string&
ecode::Version::getCodename().c_str() );
if ( mWindow->isOpen() ) {
#if EE_PLATFORM == EE_PLATFORM_MACOSX
macOS_CreateApplicationMenus();
#endif
Log::info( "Window creation took: %.2f ms", globalClock.getElapsedTime().asMilliseconds() );
if ( mConfig.window.position != Vector2i( -1, -1 ) &&

View File

@@ -0,0 +1,14 @@
#ifndef ECODE_MACOS_MACOS
#define ECODE_MACOS_MACOS
#ifdef __cplusplus
extern "C" {
#endif
void macOS_CreateApplicationMenus();
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,59 @@
#include <Cocoa/Cocoa.h>
#include "macos.hpp"
/* setAppleMenu disappeared from the headers in 10.4 */
@interface NSApplication(NSAppleMenu)
- (void)setAppleMenu:(NSMenu *)menu;
@end
// Recreates the menubar replacing the default SDL menubar
void
macOS_CreateApplicationMenus(void)
{
NSString *appName;
NSString *title;
NSMenu *appleMenu;
NSMenu *windowMenu;
NSMenuItem *menuItem;
NSMenu *mainMenu;
if (NSApp == nil) {
return;
}
mainMenu = [[NSApplication sharedApplication] mainMenu];
[mainMenu removeAllItems];
appName = @"ecode";
appleMenu = [[NSMenu alloc] initWithTitle:@""];
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(performClose:) keyEquivalent:@"q"];
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
[NSApp setAppleMenu:appleMenu];
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
[windowMenu addItem:menuItem];
menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[menuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:menuItem];
[NSApp setWindowsMenu:windowMenu];
}