Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Applications/ycode/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
*/
- (NSString *) getProjectNameFromUser;

/**
* Saves the active project.
*/
- (IBAction) saveDocument: (id)sender;
- (IBAction) saveDocumentAs: (id)sender;
- (IBAction) saveDocumentTo: (id)sender;
- (IBAction) saveAllDocuments: (id)sender;

/**
* Determines whether the application should terminate.
*/
Expand All @@ -87,6 +95,12 @@
*/
- (IBAction) openProject: (id)sender;

/**
* Standard document menu entry points.
*/
- (IBAction) newDocument: (id)sender;
- (IBAction) openDocument: (id)sender;

@end

#endif
190 changes: 186 additions & 4 deletions Applications/ycode/AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ - (void) dealloc

- (void) awakeFromNib
{
[self updateApplicationMenuName];
[self connectDocumentMenuActions];
}

- (void) applicationDidFinishLaunching: (NSNotification *)aNotif
{
[self updateApplicationMenuName];
[self connectDocumentMenuActions];

// Create and show the main window
if (!windowController) {
windowController = [[YCodeWindowController alloc] init];
Expand All @@ -75,8 +80,9 @@ - (BOOL) applicationShouldTerminate: (id)sender
if (result == NSAlertThirdButtonReturn) {
return NO; // Cancel
} else if (result == NSAlertFirstButtonReturn) {
// Save before quitting
// TODO: Implement save functionality
if (![self saveActiveProjectShowingPanel:NO]) {
return NO;
}
}
}

Expand Down Expand Up @@ -112,6 +118,16 @@ - (IBAction) newProject: (id)sender
}
}

- (IBAction)newDocument:(id)sender
{
[self newProject:sender];
}

- (IBAction)openDocument:(id)sender
{
[self openProject:sender];
}

- (void) createNewProjectAtURL:(NSURL *)projectURL
{
// Show project type selection dialog
Expand Down Expand Up @@ -151,8 +167,7 @@ - (void) createNewProjectAtURL:(NSURL *)projectURL
[windowController setProject:newProject];
[windowController showWindow:self];

// Save the project immediately
[newProject saveProjectToPath:projectPath];
[[NSDocumentController sharedDocumentController] addDocument:newProject];
} else {
NSAlert *errorAlert = [[NSAlert alloc] init];
[errorAlert setMessageText:@"Project Creation Failed"];
Expand All @@ -163,6 +178,69 @@ - (void) createNewProjectAtURL:(NSURL *)projectURL
}
}

- (IBAction)saveDocument:(id)sender
{
[self saveActiveProjectShowingPanel:NO];
}

- (IBAction)saveDocumentAs:(id)sender
{
[self saveActiveProjectShowingPanel:YES];
}

- (IBAction)saveDocumentTo:(id)sender
{
[self saveActiveProjectShowingPanel:YES];
}

- (IBAction)saveAllDocuments:(id)sender
{
[self saveActiveProjectShowingPanel:NO];
}

- (BOOL)saveActiveProjectShowingPanel:(BOOL)showPanel
{
YCodeProject *project = [windowController project];
NSString *projectPath = [project projectPath];

if (project == nil) {
NSBeep();
return NO;
}

if (showPanel || projectPath == nil || [projectPath length] == 0) {
NSSavePanel *panel = [NSSavePanel savePanel];
NSString *name = @"Project.xcodeproj";

if (projectPath != nil && [projectPath length] > 0) {
name = [projectPath lastPathComponent];
}

[panel setTitle:@"Save Project"];
[panel setNameFieldStringValue:name];
[panel setAllowedFileTypes:[NSArray arrayWithObject:@"xcodeproj"]];

if ([panel runModal] != NSModalResponseOK) {
return NO;
}

projectPath = [[panel URL] path];
}

if (![project saveProjectToPath:projectPath]) {
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Unable to save project"];
[alert setInformativeText:@"The project could not be saved to the selected location."];
[alert addButtonWithTitle:@"OK"];
[alert runModal];
RELEASE(alert);
return NO;
}

[[windowController window] setTitle:[[project projectPath] lastPathComponent]];
return YES;
}

- (NSString *) getProjectNameFromUser
{
NSAlert *alert = [[NSAlert alloc] init];
Expand Down Expand Up @@ -212,6 +290,110 @@ - (BOOL) application: (NSApplication *)application
return NO;
}

- (void)updateApplicationMenuName
{
NSString *applicationName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"ApplicationName"];
NSMenu *mainMenu = [NSApp mainMenu];
NSMenuItem *applicationItem = nil;
NSMenu *applicationMenu = nil;

if (applicationName == nil || [applicationName length] == 0) {
applicationName = [[NSProcessInfo processInfo] processName];
}

if (mainMenu == nil || [[mainMenu itemArray] count] == 0) {
return;
}

applicationItem = [[mainMenu itemArray] objectAtIndex:0];
applicationMenu = [applicationItem submenu];

[applicationItem setTitle:applicationName];
if (applicationMenu != nil) {
NSMenuItem *infoItem = nil;

[applicationMenu setTitle:applicationName];
if ([[applicationMenu itemArray] count] > 0) {
infoItem = [[applicationMenu itemArray] objectAtIndex:0];
if ([[infoItem title] isEqualToString:@"Info"]) {
[infoItem setTitle:applicationName];
[[infoItem submenu] setTitle:applicationName];
}
}

[self updateApplicationNameItemsInMenu:applicationMenu
appName:applicationName];
}
}

- (void)updateApplicationNameItemsInMenu:(NSMenu *)menu appName:(NSString *)applicationName
{
NSEnumerator *enumerator = nil;
NSMenuItem *item = nil;

if (menu == nil) {
return;
}

enumerator = [[menu itemArray] objectEnumerator];
while ((item = [enumerator nextObject]) != nil) {
if ([[item title] isEqualToString:@"Hide"]) {
[item setTitle:[NSString stringWithFormat:@"Hide %@", applicationName]];
} else if ([[item title] isEqualToString:@"Quit"]) {
[item setTitle:[NSString stringWithFormat:@"Quit %@", applicationName]];
}

[self updateApplicationNameItemsInMenu:[item submenu]
appName:applicationName];
}
}

- (void)connectDocumentMenuActions
{
NSMenu *mainMenu = [NSApp mainMenu];
NSEnumerator *enumerator = nil;
NSMenuItem *item = nil;

if (mainMenu == nil) {
return;
}

enumerator = [[mainMenu itemArray] objectEnumerator];
while ((item = [enumerator nextObject]) != nil) {
[self connectDocumentMenuActionsInMenu:[item submenu]];
}
}

- (void)connectDocumentMenuActionsInMenu:(NSMenu *)menu
{
NSEnumerator *enumerator = nil;
NSMenuItem *item = nil;

if (menu == nil) {
return;
}

enumerator = [[menu itemArray] objectEnumerator];
while ((item = [enumerator nextObject]) != nil) {
SEL action = [item action];

if (action == @selector(newDocument:)) {
[item setTarget:self];
[item setAction:@selector(newProject:)];
} else if (action == @selector(openDocument:)) {
[item setTarget:self];
[item setAction:@selector(openProject:)];
} else if (action == @selector(saveDocument:) ||
action == @selector(saveDocumentAs:) ||
action == @selector(saveDocumentTo:) ||
action == @selector(saveAllDocuments:)) {
[item setTarget:self];
}

[self connectDocumentMenuActionsInMenu:[item submenu]];
}
}

- (void) showPrefPanel: (id)sender
{
// TODO: Implement preferences panel
Expand Down
3 changes: 2 additions & 1 deletion Applications/ycode/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include $(GNUSTEP_MAKEFILES)/common.make
VERSION = 0.1
PACKAGE_NAME = Ycode
APP_NAME = Ycode
Ycode_APPLICATION_ICON =
Ycode_APPLICATION_ICON = Ycode.tiff

#
# Libraries and Frameworks
Expand All @@ -41,6 +41,7 @@ ADDITIONAL_INCLUDE_DIRS += -I../XCode
# Resource files
#
Ycode_RESOURCE_FILES = \
Resources/Ycode.tiff \
Resources/Ycode.gorm \


Expand Down
Binary file modified Applications/ycode/Resources/Ycode.tiff
Binary file not shown.
4 changes: 2 additions & 2 deletions Applications/ycode/YCodeBuildSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef enum {
/**
* Initialization
*/
- (instancetype)initWithProject:(YCodeProject *)project;
- (id)initWithProject:(YCodeProject *)project;

/**
* Project association
Expand Down Expand Up @@ -148,4 +148,4 @@ typedef enum {

@end

#endif // _YCODEBUILDSYSTEM_H_
#endif // _YCODEBUILDSYSTEM_H_
Loading
Loading