mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-03 19:44:22 +00:00
Tests: Fix ControlsKitchenSink build, add menus, and rename from ThemeKitchenSinkA3
Fix plain builds: updateApplicationSize() read ENV["CONFIGURATION"] (only set by debug and release tasks) and now accounts for the Aristo3 theme, and RuleDelegate is now declared before its first use. Add standard menus in standard order: an application menu with the About panel, View > Appearance with Light, Dark, and Auto options, and a Window menu listing the application's windows. Rename ThemeKitchenSinkA3 to ControlsKitchenSink so the name reflects what the application displays rather than a single theme.
This commit is contained in:
1 parent
bd79633fe2
commit
5c9aed0e27
6 files changed
+124
-17
No files matched your search
+100
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* AppController.j
|
||||
* KitchenSink in Code
|
||||
* ControlsKitchenSink
|
||||
*
|
||||
* Created by Daniel Böhringer 2026.
|
||||
* Refactored: Fixed RuleEditor action handling.
|
||||
@@ -21,6 +21,11 @@
|
||||
@import <Foundation/Foundation.j>
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
/*
|
||||
RuleDelegate is defined below the window controller that holds one, so it is declared here.
|
||||
*/
|
||||
@class RuleDelegate
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// KitchenSinkWindowController
|
||||
// --------------------------------------------------------------------------------
|
||||
@@ -1426,6 +1431,16 @@
|
||||
// AppController
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
The application's appearance: Light, Dark, or Auto, which follows the system. The choice
|
||||
is made in View > Appearance, kept in the user defaults under KitchenSinkAppearanceKey as
|
||||
the index of the choice, and applied at launch before any window shows.
|
||||
*/
|
||||
var KitchenSinkAppearanceKey = @"KitchenSinkAppearance",
|
||||
KitchenSinkAppearanceNames = [CPAppearanceNameAqua, CPAppearanceNameDarkAqua, nil],
|
||||
KitchenSinkAppearanceTitles = [@"Light", @"Dark", @"Auto"],
|
||||
KitchenSinkAutoAppearance = 2;
|
||||
|
||||
@implementation AppController : CPObject
|
||||
{
|
||||
CPArray windows;
|
||||
@@ -1440,6 +1455,20 @@
|
||||
{
|
||||
windows = [];
|
||||
|
||||
[self applyAppearanceChoice:[self savedAppearanceChoice]];
|
||||
|
||||
/*
|
||||
The Window menu is made before the windows, so that AppKit lists each window in it as
|
||||
the window is ordered front.
|
||||
*/
|
||||
var windowMenu = [[CPMenu alloc] initWithTitle:@"Window"];
|
||||
|
||||
[windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
||||
[windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
|
||||
[windowMenu addItem:[CPMenuItem separatorItem]];
|
||||
[windowMenu addItemWithTitle:@"Bring All to Front" action:@selector(arrangeInFront:) keyEquivalent:@""];
|
||||
[CPApp setWindowsMenu:windowMenu];
|
||||
|
||||
var winWidth = 480.0,
|
||||
winHeight = 450.0,
|
||||
padding = 20.0;
|
||||
@@ -1480,7 +1509,7 @@
|
||||
[mainMenu setSubmenu:editMenu forItem:item];
|
||||
|
||||
// Format Menu
|
||||
item = [mainMenu insertItemWithTitle:@"Format" action:nil keyEquivalent:nil atIndex:0];
|
||||
item = [mainMenu insertItemWithTitle:@"Format" action:nil keyEquivalent:nil atIndex:[mainMenu numberOfItems]];
|
||||
var formatMenu = [[CPMenu alloc] initWithTitle:@"Format Menu"];
|
||||
|
||||
[formatMenu addItemWithTitle:@"Font panel" action:@selector(orderFrontFontPanel:) keyEquivalent:@"t"];
|
||||
@@ -1501,7 +1530,76 @@
|
||||
|
||||
[mainMenu setSubmenu:formatMenu forItem:item];
|
||||
|
||||
// View Menu
|
||||
item = [mainMenu insertItemWithTitle:@"View" action:nil keyEquivalent:nil atIndex:[mainMenu numberOfItems]];
|
||||
|
||||
var viewMenu = [[CPMenu alloc] initWithTitle:@"View Menu"],
|
||||
appearanceItem = [viewMenu addItemWithTitle:@"Appearance" action:nil keyEquivalent:@""],
|
||||
appearanceMenu = [[CPMenu alloc] initWithTitle:@"Appearance"],
|
||||
savedChoice = [self savedAppearanceChoice];
|
||||
|
||||
for (var i = 0; i < KitchenSinkAppearanceTitles.length; i++)
|
||||
{
|
||||
var choiceItem = [appearanceMenu addItemWithTitle:KitchenSinkAppearanceTitles[i] action:@selector(chooseAppearance:) keyEquivalent:@""];
|
||||
|
||||
[choiceItem setTarget:self];
|
||||
[choiceItem setTag:i];
|
||||
[choiceItem setState:i === savedChoice ? CPOnState : CPOffState];
|
||||
}
|
||||
|
||||
[viewMenu setSubmenu:appearanceMenu forItem:appearanceItem];
|
||||
[mainMenu setSubmenu:viewMenu forItem:item];
|
||||
|
||||
// Window Menu
|
||||
item = [mainMenu insertItemWithTitle:@"Window" action:nil keyEquivalent:nil atIndex:[mainMenu numberOfItems]];
|
||||
[mainMenu setSubmenu:windowMenu forItem:item];
|
||||
|
||||
/*
|
||||
The application menu comes first and is named after the application. About opens the
|
||||
standard About panel, which takes its name and version from Info.plist.
|
||||
*/
|
||||
var applicationName = [[CPBundle mainBundle] objectForInfoDictionaryKey:@"CPBundleName"],
|
||||
applicationMenu = [[CPMenu alloc] initWithTitle:applicationName];
|
||||
|
||||
[applicationMenu addItemWithTitle:@"About " + applicationName action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
||||
|
||||
item = [mainMenu insertItemWithTitle:applicationName action:nil keyEquivalent:nil atIndex:0];
|
||||
[mainMenu setSubmenu:applicationMenu forItem:item];
|
||||
|
||||
[CPMenu setMenuBarVisible:YES];
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the index of the appearance kept in the user defaults, or Auto when none is kept.
|
||||
*/
|
||||
- (int)savedAppearanceChoice
|
||||
{
|
||||
var choice = [[CPUserDefaults standardUserDefaults] objectForKey:KitchenSinkAppearanceKey];
|
||||
|
||||
return choice == nil ? KitchenSinkAutoAppearance : choice;
|
||||
}
|
||||
|
||||
/*
|
||||
Light and Dark set the application's appearance. Auto sets none, so the application takes
|
||||
the system appearance and follows it when it changes.
|
||||
*/
|
||||
- (void)applyAppearanceChoice:(int)aChoice
|
||||
{
|
||||
var name = KitchenSinkAppearanceNames[aChoice];
|
||||
|
||||
[CPApp setAppearance:name ? [CPAppearance appearanceNamed:name] : nil];
|
||||
}
|
||||
|
||||
- (void)chooseAppearance:(id)sender
|
||||
{
|
||||
var choice = [sender tag],
|
||||
items = [[sender menu] itemArray];
|
||||
|
||||
for (var i = 0; i < items.length; i++)
|
||||
[items[i] setState:[items[i] tag] === choice ? CPOnState : CPOffState];
|
||||
|
||||
[[CPUserDefaults standardUserDefaults] setObject:choice forKey:KitchenSinkAppearanceKey];
|
||||
[self applyAppearanceChoice:choice];
|
||||
}
|
||||
|
||||
@end
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<key>CPApplicationDelegateClass</key>
|
||||
<string>AppController</string>
|
||||
<key>CPBundleName</key>
|
||||
<string>KitchenSink Aristo3</string>
|
||||
<string>Controls Kitchen Sink</string>
|
||||
<key>CPPrincipalClass</key>
|
||||
<string>CPApplication</string>
|
||||
</dict>
|
||||
+23
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Jakefile
|
||||
* ThemeKitchenSinkA3
|
||||
* ControlsKitchenSink
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@ var ENV = process.env,
|
||||
app = CAPPUCCINO.Jake.applicationtask.app,
|
||||
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
|
||||
OS = require("os"),
|
||||
projectName = "ThemeKitchenSinkA3";
|
||||
projectName = "ControlsKitchenSink";
|
||||
|
||||
app (projectName, function(task)
|
||||
{
|
||||
@@ -22,15 +22,15 @@ app (projectName, function(task)
|
||||
if (configuration === "Debug")
|
||||
ENV["OBJJ_INCLUDE_PATHS"] = path.join(ENV["OBJJ_INCLUDE_PATHS"], configuration);
|
||||
|
||||
task.setBuildIntermediatesPath(path.join("Build", "ThemeKitchenSinkA3.build", configuration));
|
||||
task.setBuildIntermediatesPath(path.join("Build", "ControlsKitchenSink.build", configuration));
|
||||
task.setBuildPath(path.join("Build", configuration));
|
||||
|
||||
task.setProductName("ThemeKitchenSinkA3");
|
||||
task.setIdentifier("com.yourcompany.ThemeKitchenSinkA3");
|
||||
task.setProductName("ControlsKitchenSink");
|
||||
task.setIdentifier("dev.cappuccino.ControlsKitchenSink");
|
||||
task.setVersion("1.0");
|
||||
task.setAuthor("SlevenBits, Ltd.");
|
||||
task.setEmail("feedback @nospam@ yourcompany.com");
|
||||
task.setSummary("ThemeKitchenSinkA3");
|
||||
task.setSummary("ControlsKitchenSink");
|
||||
task.setSources(new FileList("**/*.j").exclude(path.join("Build", "**")).exclude(path.join("Frameworks", "Source", "**")));
|
||||
task.setResources(new FileList("Resources/**"));
|
||||
task.setIndexFilePath("index.html");
|
||||
@@ -84,13 +84,13 @@ task ("deploy", ["release"], function()
|
||||
task ("desktop", ["release"], function()
|
||||
{
|
||||
fs.mkdirSync(path.join("Build", "Desktop", projectName), { recursive: true });
|
||||
require("@objj/nativehost").buildNativeHost(path.join("Build", "Release", projectName), path.join("Build", "Desktop", projectName, "ThemeKitchenSinkA3.app"));
|
||||
require("@objj/nativehost").buildNativeHost(path.join("Build", "Release", projectName), path.join("Build", "Desktop", projectName, "ControlsKitchenSink.app"));
|
||||
printResults("Desktop")
|
||||
});
|
||||
|
||||
task ("run-desktop", ["desktop"], function()
|
||||
{
|
||||
cp.execSync([path.join("Build", "Desktop", projectName, "ThemeKitchenSinkA3.app", "Contents", "MacOS", "NativeHost"), "-i"].join(" "), { stdio: "inherit" });
|
||||
cp.execSync([path.join("Build", "Desktop", projectName, "ControlsKitchenSink.app", "Contents", "MacOS", "NativeHost"), "-i"].join(" "), { stdio: "inherit" });
|
||||
});
|
||||
|
||||
function printResults(configuration)
|
||||
@@ -100,11 +100,16 @@ function printResults(configuration)
|
||||
console.log("----------------------------");
|
||||
}
|
||||
|
||||
/*
|
||||
Records the application's size in its built Info.plist. It read the configuration from
|
||||
configuration, which only the debug and release tasks set, so a plain build
|
||||
failed with an undefined path. It now uses the configuration the Jakefile resolved.
|
||||
*/
|
||||
function updateApplicationSize()
|
||||
{
|
||||
console.log("Calculating application file sizes...");
|
||||
|
||||
var contents = fs.readFileSync(path.join("Build", ENV["CONFIGURATION"], projectName, "Info.plist"), { encoding: "utf8" }),
|
||||
var contents = fs.readFileSync(path.join("Build", configuration, projectName, "Info.plist"), { encoding: "utf8" }),
|
||||
format = CFPropertyList.sniffedFormatOfString(contents),
|
||||
plist = CFPropertyList.propertyListFromString(contents),
|
||||
totalBytes = {executable:0, data:0, mhtml:0};
|
||||
@@ -112,7 +117,7 @@ function updateApplicationSize()
|
||||
// Get the size of all framework executables and sprite data
|
||||
var frameworksDir = "Frameworks";
|
||||
|
||||
if (ENV["CONFIGURATION"] === "Debug")
|
||||
if (configuration === "Debug")
|
||||
frameworksDir = path.join(frameworksDir, "Debug");
|
||||
|
||||
var frameworks = fs.existsSync(frameworksDir) ? fs.readdirSync(frameworksDir) : [];
|
||||
@@ -124,10 +129,14 @@ function updateApplicationSize()
|
||||
});
|
||||
|
||||
// Read in the default theme name, and attempt to get its size
|
||||
var themeName = plist.valueForKey("CPDefaultTheme") || "Aristo2",
|
||||
/*
|
||||
Aristo3 is the default theme, and it is built into AppKit like Aristo and Aristo2, so
|
||||
its size was not counted.
|
||||
*/
|
||||
var themeName = plist.valueForKey("CPDefaultTheme") || "Aristo3",
|
||||
themePath = nil;
|
||||
|
||||
if (themeName === "Aristo" || themeName === "Aristo2")
|
||||
if (themeName === "Aristo" || themeName === "Aristo2" || themeName === "Aristo3")
|
||||
themePath = path.join(frameworksDir, "AppKit", "Resources", themeName + ".blend");
|
||||
else
|
||||
themePath = path.join("Frameworks", "Resources", themeName + ".blend");
|
||||
@@ -136,7 +145,7 @@ function updateApplicationSize()
|
||||
addBundleFileSizes(themePath, totalBytes);
|
||||
|
||||
// Add sizes for the app
|
||||
addBundleFileSizes(path.join("Build", ENV["CONFIGURATION"], projectName), totalBytes);
|
||||
addBundleFileSizes(path.join("Build", configuration, projectName), totalBytes);
|
||||
|
||||
console.log("Executables: " + totalBytes.executable + ", sprite data: " + totalBytes.data + ", total: " + (totalBytes.executable + totalBytes.data));
|
||||
|
||||
@@ -148,7 +157,7 @@ function updateApplicationSize()
|
||||
|
||||
plist.setValueForKey("CPApplicationSize", dict);
|
||||
|
||||
fs.writeFileSync(path.join("Build", ENV["CONFIGURATION"], projectName, "Info.plist"), CFPropertyList.stringFromPropertyList(plist, format), { encoding: "utf8" });
|
||||
fs.writeFileSync(path.join("Build", configuration, projectName, "Info.plist"), CFPropertyList.stringFromPropertyList(plist, format), { encoding: "utf8" });
|
||||
}
|
||||
|
||||
function addBundleFileSizes(bundlePath, totalBytes)
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user