Skip to content

Commit

Permalink
saving
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmachine committed Aug 28, 2012
1 parent a878bca commit ea01a12
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
2 changes: 2 additions & 0 deletions WorkMode/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

#import <Cocoa/Cocoa.h>
#define FILE_LOCATION @"app_groups"


@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
Expand Down
36 changes: 27 additions & 9 deletions WorkMode/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,51 @@ @implementation AppDelegate
@synthesize appGroups;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
appGroups = [[NSMutableArray alloc] init];
if ([[NSFileManager defaultManager] fileExistsAtPath:FILE_LOCATION]) {
appGroups = [NSArray arrayWithContentsOfFile:FILE_LOCATION];
} else {
appGroups = [[NSMutableArray alloc] init];
}
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(addAppGroup:)
name: @"addAppGroup"
object: nil];
[self setEmptyWindow];

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(saveAppGroups)
name: @"addApp"
object: nil];

[self setFreshWindow];
}

- (void) setEmptyWindow {
- (void) setFreshWindow {
NSView * v = self.window.contentView;
int adjust = 50 - v.frame.size.height;
[self resize:adjust animate:NO];
for(NSDictionary *appGroup in appGroups) {
[self displayAppGroup:appGroup];
}
}

- (void)addAppGroup:(NSNotification *)notification
{
NSDictionary* group = [notification userInfo];
[appGroups addObject:group];
AppGroupController* controller = [[AppGroupController alloc] init];
[self displayAppGroup:group];
}

- (void)displayAppGroup:(NSDictionary *)group {
AppGroupController* controller = [[AppGroupController alloc] initWithAppGroup:group];
[self resize:controller.rootView.frame.size.height animate:YES];

NSView* mainView = self.window.contentView;
[mainView addSubview: controller.rootView];

if([group valueForKey:@"apps"] != nil){
[controller addApps:[group valueForKey:@"apps"]];
}
}

- (void)saveAppGroups {
NSLog(@"save");
[appGroups writeToFile:FILE_LOCATION atomically:YES];
}

- (void)resize: (int) heightAdjust animate:(BOOL)animate{
Expand Down
3 changes: 2 additions & 1 deletion WorkMode/AppGroupController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

@interface AppGroupController : NSViewController

@property (strong) NSMutableOrderedSet* apps;
@property (strong) NSDictionary* appGroup;
@property (assign) IBOutlet DragReceiver* dragReceiver;
@property (assign) IBOutlet IconListView* iconListView;
@property (assign) IBOutlet NSView* rootView;

- (void) addApps: (NSArray *) app;
- (AppGroupController *) initWithAppGroup: (NSDictionary *) appGroup;

@end
13 changes: 8 additions & 5 deletions WorkMode/AppGroupController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@
#import "IconListView.h"

@implementation AppGroupController
@synthesize apps;
@synthesize appGroup;
@synthesize iconListView;

- (id)init
- (id)initWithAppGroup:(NSDictionary *)appG
{
self = [super init];
self = [self init];
if (self) {
apps = [[NSMutableOrderedSet alloc] init];
appGroup = appG;
NSLog(@"%@", appGroup);
[NSBundle loadNibNamed:@"AppGroupView" owner:self];
}

return self;
}

- (void) addApps:(NSArray *)appsToAdd {
[apps addObjectsFromArray: appsToAdd];

[[appGroup valueForKey:@"apps"] addObjectsFromArray: appsToAdd];
[iconListView showAppIcons];
[[NSNotificationCenter defaultCenter] postNotificationName:@"addApp" object:self userInfo:NULL];
}

- (void) startApp:(NSString *)app {
Expand Down
3 changes: 2 additions & 1 deletion WorkMode/IconListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ - (void)showAppIcons
NSMutableArray* newSubViews = [[NSMutableArray alloc] init];
float sideLength = 50.0;
float leftMargin = -1 * sideLength;
for(NSString* app in self.controller.apps) {
NSLog(@"%@", self.controller.appGroup);
for(NSString* app in [self.controller.appGroup valueForKey:@"apps"]) {
leftMargin += sideLength;
NSImageView* imgView = [[NSImageView alloc] initWithFrame:NSMakeRect(leftMargin, 0, sideLength, sideLength)];
NSImage* img = [[NSWorkspace sharedWorkspace] iconForFile:app];
Expand Down

0 comments on commit ea01a12

Please sign in to comment.