Scripts menu added to Mac OS X version
parent
fb9520d47a
commit
807f551214
|
@ -18,6 +18,7 @@
|
|||
@class SplashWindow;
|
||||
@class SplashWindowController;
|
||||
@class EclipseFinderController;
|
||||
@class ScriptsController;
|
||||
|
||||
@interface CelestiaController : NSWindowController
|
||||
{
|
||||
|
@ -34,6 +35,7 @@
|
|||
NSWindow *origWindow;
|
||||
IBOutlet FavoritesDrawerController *favoritesDrawerController;
|
||||
IBOutlet RenderPanelController *renderPanelController;
|
||||
IBOutlet ScriptsController *scriptsController;
|
||||
BrowserWindowController *browserWindowController;
|
||||
EclipseFinderController *eclipseFinderController;
|
||||
NSWindowController *helpWindowController;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#import "SplashScreen.h"
|
||||
#import "SplashWindowController.h"
|
||||
#import "EclipseFinderController.h"
|
||||
#import "ScriptsController.h"
|
||||
#import <Carbon/Carbon.h>
|
||||
#import <OpenGL/gl.h>
|
||||
#import "CGLInfo.h"
|
||||
|
@ -57,6 +58,7 @@ NSString* fatalErrorMessage;
|
|||
lastScript = nil;
|
||||
|
||||
[self setupResourceDirectory];
|
||||
[scriptsController buildScriptMenu];
|
||||
|
||||
// hide main window until ready
|
||||
[[glView window] setAlphaValue: 0.0f]; // not [[glView window] orderOut: nil];
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
glInfoPanel = NSPanel;
|
||||
glView = NSOpenGLView;
|
||||
renderPanelController = RenderPanelController;
|
||||
scriptsController = ScriptsController;
|
||||
splashWindowController = SplashWindowController;
|
||||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
|
@ -89,6 +90,12 @@
|
|||
OUTLETS = {renderPathCautionIcon = NSImageView; renderPathWarning = NSTextField; };
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{
|
||||
CLASS = ScriptsController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {scriptMenu = NSMenu; };
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {setTime = id; showWindow = id; };
|
||||
CLASS = SetTimeWindowController;
|
||||
|
|
|
@ -94,8 +94,8 @@
|
|||
<integer>2</integer>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>29</integer>
|
||||
<integer>1566</integer>
|
||||
<integer>29</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8P135</string>
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// ScriptsController.h
|
||||
// celestia
|
||||
//
|
||||
// Created by Da Woon Jung on 2007-05-30.
|
||||
// Copyright 2007 Da Woon Jung. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface ScriptsController : NSObject
|
||||
{
|
||||
IBOutlet NSMenu *scriptMenu;
|
||||
}
|
||||
- (void)buildScriptMenu;
|
||||
@end
|
|
@ -0,0 +1,115 @@
|
|||
//
|
||||
// ScriptsController.mm
|
||||
// celestia
|
||||
//
|
||||
// Created by Da Woon Jung on 2007-05-30.
|
||||
// Copyright 2007 Da Woon Jung. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ScriptsController.h"
|
||||
#import "CelestiaAppCore.h"
|
||||
#import "NSString_ObjCPlusPlus.h"
|
||||
#import "celestiacore.h"
|
||||
#import "scriptmenu.h"
|
||||
|
||||
#define CEL_SCRIPTS_FOLDER @"scripts"
|
||||
|
||||
|
||||
@interface ScriptsController(Private)
|
||||
- (void)runScript: (id)aSender;
|
||||
- (void)addItems: (NSDictionary *)aItems
|
||||
toMenu: (NSMenu *)aMenu;
|
||||
@end
|
||||
|
||||
@implementation ScriptsController
|
||||
|
||||
- (void)buildScriptMenu
|
||||
{
|
||||
std::vector<ScriptMenuItem> *scripts = ScanScriptsDirectory([CEL_SCRIPTS_FOLDER stdString], true);
|
||||
int count = [scriptMenu numberOfItems];
|
||||
while (count-- > 0)
|
||||
[scriptMenu removeItemAtIndex: 0];
|
||||
|
||||
NSMutableDictionary *itemDict = [NSMutableDictionary dictionary];
|
||||
unsigned baseDirLevel = [[CEL_SCRIPTS_FOLDER pathComponents] count];
|
||||
NSString *title;
|
||||
id path;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < scripts->size(); ++i)
|
||||
{
|
||||
title = [NSString stringWithStdString: (*scripts)[i].title];
|
||||
path = [NSString stringWithStdString: (*scripts)[i].filename];
|
||||
// Build submenus for nested directories
|
||||
NSArray *subPaths = [[path stringByDeletingLastPathComponent] pathComponents];
|
||||
if (subPaths && [subPaths count] > baseDirLevel)
|
||||
{
|
||||
id parentDict = itemDict;
|
||||
id childDict = nil;
|
||||
NSString *subDir;
|
||||
for (unsigned j = baseDirLevel; j < [subPaths count]; ++j)
|
||||
{
|
||||
subDir = [subPaths objectAtIndex: j];
|
||||
childDict = [parentDict objectForKey: subDir];
|
||||
if (nil == childDict)
|
||||
childDict = [NSMutableDictionary dictionary];
|
||||
[parentDict setObject: childDict forKey: subDir];
|
||||
parentDict = childDict;
|
||||
}
|
||||
if (childDict) [childDict setObject: path forKey: title];
|
||||
continue;
|
||||
}
|
||||
[itemDict setObject: path forKey: title];
|
||||
}
|
||||
|
||||
[self addItems: itemDict toMenu: scriptMenu];
|
||||
|
||||
delete scripts;
|
||||
}
|
||||
|
||||
- (void)addItems: (NSDictionary *)aItems
|
||||
toMenu: (NSMenu *)aMenu
|
||||
{
|
||||
NSMenuItem *mi;
|
||||
id item;
|
||||
NSString *title;
|
||||
NSArray *titles = [[aItems allKeys] sortedArrayUsingSelector: @selector(localizedCaseInsensitiveCompare:)];
|
||||
|
||||
for (unsigned i = 0; i < [titles count]; ++i)
|
||||
{
|
||||
title = [titles objectAtIndex: i];
|
||||
mi = [aMenu addItemWithTitle: title
|
||||
action: @selector(runScript:)
|
||||
keyEquivalent: @""];
|
||||
if (mi)
|
||||
{
|
||||
item = [aItems objectForKey: title];
|
||||
if ([item respondsToSelector: @selector(objectForKey:)])
|
||||
{
|
||||
[mi setAction: nil];
|
||||
NSMenu *subMenu = [[[NSMenu alloc] initWithTitle: title] autorelease];
|
||||
[self addItems: item toMenu: subMenu];
|
||||
[mi setSubmenu: subMenu];
|
||||
}
|
||||
else
|
||||
{
|
||||
[mi setTarget: self];
|
||||
[mi setRepresentedObject: item];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)runScript: (id)aSender
|
||||
{
|
||||
if (aSender && [aSender respondsToSelector: @selector(representedObject)])
|
||||
{
|
||||
CelestiaCore *appCore = (CelestiaCore*) [[CelestiaAppCore sharedAppCore] appCore];
|
||||
id filename = [aSender representedObject];
|
||||
if (filename)
|
||||
{
|
||||
appCore->runScript([(NSString *)filename stdString]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@end
|
|
@ -15,6 +15,8 @@
|
|||
E532F4F30933331800D7D5B3 /* dsoname.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E532F4EA0933331800D7D5B3 /* dsoname.cpp */; };
|
||||
E532F4F50933331800D7D5B3 /* dsooctree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E532F4EC0933331800D7D5B3 /* dsooctree.cpp */; };
|
||||
E532F4F80933331800D7D5B3 /* staroctree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E532F4EF0933331800D7D5B3 /* staroctree.cpp */; };
|
||||
E53E619B0C0CA105003CD767 /* scriptmenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E53E61990C0CA105003CD767 /* scriptmenu.cpp */; };
|
||||
E53E61AD0C0CA444003CD767 /* ScriptsController.mm in Sources */ = {isa = PBXBuildFile; fileRef = E53E61AB0C0CA444003CD767 /* ScriptsController.mm */; };
|
||||
E54343120783C3F200053094 /* BrowserWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = E54343100783C3F200053094 /* BrowserWindow.nib */; };
|
||||
E54343170783C42500053094 /* BrowserWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = E54343150783C42500053094 /* BrowserWindowController.mm */; };
|
||||
E54742D009631D3600E89E09 /* defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = E54742CF09631D3600E89E09 /* defaults.plist */; };
|
||||
|
@ -491,6 +493,10 @@
|
|||
E532F4EE0933331800D7D5B3 /* name.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = name.h; path = ../src/celengine/name.h; sourceTree = SOURCE_ROOT; };
|
||||
E532F4EF0933331800D7D5B3 /* staroctree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = staroctree.cpp; path = ../src/celengine/staroctree.cpp; sourceTree = SOURCE_ROOT; };
|
||||
E532F4F00933331800D7D5B3 /* staroctree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = staroctree.h; path = ../src/celengine/staroctree.h; sourceTree = SOURCE_ROOT; };
|
||||
E53E61990C0CA105003CD767 /* scriptmenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = scriptmenu.cpp; path = ../src/celestia/scriptmenu.cpp; sourceTree = SOURCE_ROOT; };
|
||||
E53E619A0C0CA105003CD767 /* scriptmenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = scriptmenu.h; path = ../src/celestia/scriptmenu.h; sourceTree = SOURCE_ROOT; };
|
||||
E53E61AA0C0CA444003CD767 /* ScriptsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptsController.h; sourceTree = "<group>"; };
|
||||
E53E61AB0C0CA444003CD767 /* ScriptsController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScriptsController.mm; sourceTree = "<group>"; };
|
||||
E54343110783C3F200053094 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/BrowserWindow.nib; sourceTree = "<group>"; };
|
||||
E54343140783C42500053094 /* BrowserWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrowserWindowController.h; sourceTree = "<group>"; };
|
||||
E54343150783C42500053094 /* BrowserWindowController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BrowserWindowController.mm; sourceTree = "<group>"; };
|
||||
|
@ -964,6 +970,7 @@
|
|||
E56A3DB70848C19800A21D7E /* MacDirectory.mm */,
|
||||
F55C817602AF55890100020A /* GotoWindowController.m */,
|
||||
F565A8B202EB418701000006 /* RenderPanelController.m */,
|
||||
E53E61AB0C0CA444003CD767 /* ScriptsController.mm */,
|
||||
F5EDC6BA0456666601000002 /* SetTimeWindowController.m */,
|
||||
E5E365AB095C11B500B14224 /* SplashScreen.m */,
|
||||
E5D956DF096651DF00CB02B2 /* SplashWindowController.m */,
|
||||
|
@ -978,6 +985,7 @@
|
|||
F578B7B302B3E4DB0100020A /* FavoritesDrawerController.h */,
|
||||
F55C817702AF55890100020A /* GotoWindowController.h */,
|
||||
F565A8B102EB418701000006 /* RenderPanelController.h */,
|
||||
E53E61AA0C0CA444003CD767 /* ScriptsController.h */,
|
||||
F5EDC6B90456666601000002 /* SetTimeWindowController.h */,
|
||||
E5E365AA095C11B500B14224 /* SplashScreen.h */,
|
||||
E5D956DE096651DF00CB02B2 /* SplashWindowController.h */,
|
||||
|
@ -1313,6 +1321,7 @@
|
|||
E50CCA370C065BF900E9C76A /* eclipsefinder.cpp */,
|
||||
F51C6D8E02959960014901DC /* favorites.cpp */,
|
||||
0C76BFCF08537EDB00D31A90 /* qtcapture.cpp */,
|
||||
E53E61990C0CA105003CD767 /* scriptmenu.cpp */,
|
||||
F53036BB03D908CE01000002 /* url.cpp */,
|
||||
F51C6D9A02959960014901DC /* celestiacore.h */,
|
||||
E56431460776D52D00E2C4A3 /* celx.h */,
|
||||
|
@ -1322,6 +1331,7 @@
|
|||
F51C6D9D02959960014901DC /* favorites.h */,
|
||||
0C76BFC0085215B100D31A90 /* moviecapture.h */,
|
||||
0C76BFD008537EDB00D31A90 /* qtcapture.h */,
|
||||
E53E619A0C0CA105003CD767 /* scriptmenu.h */,
|
||||
F53036BC03D908CE01000002 /* url.h */,
|
||||
);
|
||||
name = celestia;
|
||||
|
@ -1859,6 +1869,8 @@
|
|||
E561FC300B47910800668CFE /* CelestiaLocation.mm in Sources */,
|
||||
E50CCA390C065BF900E9C76A /* eclipsefinder.cpp in Sources */,
|
||||
E50CCA6A0C06632A00E9C76A /* EclipseFinderController.mm in Sources */,
|
||||
E53E619B0C0CA105003CD767 /* scriptmenu.cpp in Sources */,
|
||||
E53E61AD0C0CA444003CD767 /* ScriptsController.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
glInfoPanel = NSPanel;
|
||||
glView = NSOpenGLView;
|
||||
renderPanelController = RenderPanelController;
|
||||
scriptsController = ScriptsController;
|
||||
splashWindowController = SplashWindowController;
|
||||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
|
@ -84,6 +85,12 @@
|
|||
OUTLETS = {renderPathCautionIcon = NSImageView; renderPathWarning = NSTextField; };
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{
|
||||
CLASS = ScriptsController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {scriptMenu = NSMenu; };
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {setTime = id; showWindow = id; };
|
||||
CLASS = SetTimeWindowController;
|
||||
|
|
Binary file not shown.
|
@ -27,6 +27,7 @@
|
|||
glInfoPanel = NSPanel;
|
||||
glView = NSOpenGLView;
|
||||
renderPanelController = RenderPanelController;
|
||||
scriptsController = ScriptsController;
|
||||
splashWindowController = SplashWindowController;
|
||||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
|
@ -84,6 +85,12 @@
|
|||
OUTLETS = {renderPathCautionIcon = NSImageView; renderPathWarning = NSTextField; };
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{
|
||||
CLASS = ScriptsController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {scriptMenu = NSMenu; };
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {setTime = id; showWindow = id; };
|
||||
CLASS = SetTimeWindowController;
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>1662</integer>
|
||||
<integer>29</integer>
|
||||
<integer>1662</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8P135</string>
|
||||
|
|
Binary file not shown.
|
@ -27,6 +27,7 @@
|
|||
glInfoPanel = NSPanel;
|
||||
glView = NSOpenGLView;
|
||||
renderPanelController = RenderPanelController;
|
||||
scriptsController = ScriptsController;
|
||||
splashWindowController = SplashWindowController;
|
||||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
|
@ -89,6 +90,12 @@
|
|||
OUTLETS = {renderPathCautionIcon = NSImageView; renderPathWarning = NSTextField; };
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{
|
||||
CLASS = ScriptsController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {scriptMenu = NSMenu; };
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {setTime = id; showWindow = id; };
|
||||
CLASS = SetTimeWindowController;
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>1566</integer>
|
||||
<integer>29</integer>
|
||||
<integer>1566</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8P135</string>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue