Skip to content

Commit

Permalink
Make resources framework ready
Browse files Browse the repository at this point in the history
  • Loading branch information
swisspol committed Aug 19, 2015
1 parent 5824584 commit 1cb2193
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
28 changes: 21 additions & 7 deletions Components/GIDiffContentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ - (void)keyDown:(NSEvent*)event {
static NSColor* _renamedBackgroundColor = nil;
static NSColor* _untrackedBackgroundColor = nil;

static NSImage* _conflictImage = nil;
static NSImage* _addedImage = nil;
static NSImage* _modifiedImage = nil;
static NSImage* _deletedImage = nil;
static NSImage* _renamedImage = nil;
static NSImage* _untrackedImage = nil;

@implementation GIDiffContentsViewController {
NSMutableArray* _data;
CGFloat _headerViewHeight;
Expand All @@ -209,6 +216,13 @@ + (void)initialize {
_deletedBackgroundColor = _DimColor([NSColor colorWithDeviceRed:(241.0 / 255.0) green:(115.0 / 255.0) blue:(116.0 / 255.0) alpha:1.0]);
_renamedBackgroundColor = _DimColor([NSColor colorWithDeviceRed:(133.0 / 255.0) green:(96.0 / 255.0) blue:(168.0 / 255.0) alpha:1.0]);
_untrackedBackgroundColor = [NSColor colorWithDeviceRed:0.75 green:0.75 blue:0.75 alpha:1.0];

_conflictImage = [[NSBundle bundleForClass:[GIDiffContentsViewController class]] imageForResource:@"icon_file_conflict"];
_addedImage = [[NSBundle bundleForClass:[GIDiffContentsViewController class]] imageForResource:@"icon_file_a"];
_modifiedImage = [[NSBundle bundleForClass:[GIDiffContentsViewController class]] imageForResource:@"icon_file_m"];
_deletedImage = [[NSBundle bundleForClass:[GIDiffContentsViewController class]] imageForResource:@"icon_file_d"];
_renamedImage = [[NSBundle bundleForClass:[GIDiffContentsViewController class]] imageForResource:@"icon_file_r"];
_untrackedImage = [[NSBundle bundleForClass:[GIDiffContentsViewController class]] imageForResource:@"icon_file_u"];
}

- (instancetype)initWithRepository:(GCLiveRepository*)repository {
Expand Down Expand Up @@ -533,30 +547,30 @@ - (NSView*)tableView:(NSTableView*)tableView viewForTableColumn:(NSTableColumn*)
NSString* label = data.delta.canonicalPath;
if (data.conflict) {
view.backgroundColor = _conflictBackgroundColor;
view.imageView.image = [NSImage imageNamed:@"icon_file_conflict"];
view.imageView.image = _conflictImage;
} else {
switch (delta.change) {

case kGCFileDiffChange_Added:
view.backgroundColor = _addedBackgroundColor;
view.imageView.image = [NSImage imageNamed:@"icon_file_a"];
view.imageView.image = _addedImage;
break;

case kGCFileDiffChange_Deleted:
view.backgroundColor = _deletedBackgroundColor;
view.imageView.image = [NSImage imageNamed:@"icon_file_d"];
view.imageView.image = _deletedImage;
break;

case kGCFileDiffChange_Modified:
view.backgroundColor = _modifiedBackgroundColor;
view.imageView.image = [NSImage imageNamed:@"icon_file_m"];
view.imageView.image = _modifiedImage;
break;

case kGCFileDiffChange_Renamed: {
NSString* oldPath = delta.oldFile.path;
NSString* newPath = delta.newFile.path;
view.backgroundColor = _renamedBackgroundColor;
view.imageView.image = [NSImage imageNamed:@"icon_file_r"];
view.imageView.image = _renamedImage;
label = [NSString stringWithFormat:@"%@%@", oldPath, newPath]; // TODO: Handle truncation
GIComputeModifiedRanges(oldPath, &oldPathRange, newPath, &newPathRange);
newPathRange.location += oldPath.length + 3;
Expand All @@ -566,10 +580,10 @@ - (NSView*)tableView:(NSTableView*)tableView viewForTableColumn:(NSTableColumn*)
case kGCFileDiffChange_Untracked:
if (_showsUntrackedAsAdded) {
view.backgroundColor = _addedBackgroundColor;
view.imageView.image = [NSImage imageNamed:@"icon_file_a"];
view.imageView.image = _addedImage;
} else {
view.backgroundColor = _untrackedBackgroundColor;
view.imageView.image = [NSImage imageNamed:@"icon_file_u"];
view.imageView.image = _untrackedImage;
}
break;

Expand Down
30 changes: 23 additions & 7 deletions Components/GIDiffFilesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,26 @@ - (void)updateDraggingItemsForDrag:(id<NSDraggingInfo>)sender {

@end

static NSImage* _conflictImage = nil;
static NSImage* _addedImage = nil;
static NSImage* _modifiedImage = nil;
static NSImage* _deletedImage = nil;
static NSImage* _renamedImage = nil;
static NSImage* _untrackedImage = nil;

@implementation GIDiffFilesViewController {
NSMutableArray* _data;
}

+ (void)initialize {
_conflictImage = [[NSBundle bundleForClass:[GIDiffFilesViewController class]] imageForResource:@"icon_file_conflict"];
_addedImage = [[NSBundle bundleForClass:[GIDiffFilesViewController class]] imageForResource:@"icon_file_a"];
_modifiedImage = [[NSBundle bundleForClass:[GIDiffFilesViewController class]] imageForResource:@"icon_file_m"];
_deletedImage = [[NSBundle bundleForClass:[GIDiffFilesViewController class]] imageForResource:@"icon_file_d"];
_renamedImage = [[NSBundle bundleForClass:[GIDiffFilesViewController class]] imageForResource:@"icon_file_r"];
_untrackedImage = [[NSBundle bundleForClass:[GIDiffFilesViewController class]] imageForResource:@"icon_file_u"];
}

- (void)loadView {
[super loadView];

Expand Down Expand Up @@ -284,31 +300,31 @@ - (NSView*)tableView:(NSTableView*)tableView viewForTableColumn:(NSTableColumn*)
GIFileCellView* view = [_tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
view.textField.stringValue = data.delta.canonicalPath;
if (data.conflict) {
view.imageView.image = [NSImage imageNamed:@"icon_file_conflict"];
view.imageView.image = _conflictImage;
} else {
switch (data.delta.change) {

case kGCFileDiffChange_Added:
view.imageView.image = [NSImage imageNamed:@"icon_file_a"];
view.imageView.image = _addedImage;
break;

case kGCFileDiffChange_Deleted:
view.imageView.image = [NSImage imageNamed:@"icon_file_d"];
view.imageView.image = _deletedImage;
break;

case kGCFileDiffChange_Modified:
view.imageView.image = [NSImage imageNamed:@"icon_file_m"];
view.imageView.image = _modifiedImage;
break;

case kGCFileDiffChange_Renamed:
view.imageView.image = [NSImage imageNamed:@"icon_file_r"];
view.imageView.image = _renamedImage;
break;

case kGCFileDiffChange_Untracked:
if (_showsUntrackedAsAdded) {
view.imageView.image = [NSImage imageNamed:@"icon_file_a"];
view.imageView.image = _addedImage;
} else {
view.imageView.image = [NSImage imageNamed:@"icon_file_u"];
view.imageView.image = _untrackedImage;
}
break;

Expand Down
6 changes: 3 additions & 3 deletions Utilities/GIAppKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ - (void)beginSheetModalForWindow:(NSWindow*)window withCompletionHandler:(void (

- (void)setType:(GIAlertType)type {
switch (type) {
case kGIAlertType_Note: self.icon = [NSImage imageNamed:@"icon_alert_note"]; break;
case kGIAlertType_Caution: self.icon = [NSImage imageNamed:@"icon_alert_caution"]; break;
case kGIAlertType_Stop: self.icon = [NSImage imageNamed:@"icon_alert_stop"]; break;
case kGIAlertType_Note: self.icon = [[NSBundle bundleForClass:[GILayoutManager class]] imageForResource:@"icon_alert_note"]; break; // TODO: Image is not cached
case kGIAlertType_Caution: self.icon = [[NSBundle bundleForClass:[GILayoutManager class]] imageForResource:@"icon_alert_caution"]; break; // TODO: Image is not cached
case kGIAlertType_Stop: self.icon = [[NSBundle bundleForClass:[GILayoutManager class]] imageForResource:@"icon_alert_stop"]; break; // TODO: Image is not cached
}
}

Expand Down
2 changes: 1 addition & 1 deletion Utilities/GIViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ @implementation GIViewController {
@dynamic view;

- (instancetype)initWithRepository:(GCLiveRepository*)repository {
if ((self = [super initWithNibName:NSStringFromClass([self class]) bundle:[NSBundle mainBundle]])) {
if ((self = [super initWithNibName:NSStringFromClass(self.class) bundle:[NSBundle bundleForClass:self.class]])) {
_repository = repository;
_textViewUndoManager = [[NSUndoManager alloc] init];

Expand Down
2 changes: 1 addition & 1 deletion Utilities/GIWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void _TimerCallBack(CFRunLoopTimerRef timer, void* info) {

- (instancetype)initWithWindow:(NSWindow*)window {
if ((self = [super initWithWindow:window])) {
[[NSBundle mainBundle] loadNibNamed:@"GIWindowController" owner:self topLevelObjects:NULL];
[[NSBundle bundleForClass:[GIWindowController class]] loadNibNamed:@"GIWindowController" owner:self topLevelObjects:NULL];
XLOG_DEBUG_CHECK(_overlayView);

_area = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingInVisibleRect | NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited) owner:self userInfo:nil];
Expand Down
2 changes: 1 addition & 1 deletion Views/GIConfigViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ + (void)initialize {
#endif
_directHelp = [[NSMutableDictionary alloc] init];
_patternHelp = [[NSMutableDictionary alloc] init];
NSString* string = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"GIConfigViewController-Help" ofType:@"txt"] encoding:NSUTF8StringEncoding error:NULL];
NSString* string = [[NSString alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[GIConfigViewController class]] pathForResource:@"GIConfigViewController-Help" ofType:@"txt"] encoding:NSUTF8StringEncoding error:NULL];
XLOG_DEBUG_CHECK(string);
string = [string stringByReplacingOccurrencesOfString:@"linkgit:" withString:@""]; // TODO: Handle links
for (NSString* section in [string componentsSeparatedByString:@"\n\n\n"]) {
Expand Down
2 changes: 1 addition & 1 deletion Views/GIMapViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ @implementation GIMapViewController {
}

+ (void)initialize {
_patternColor = [NSColor colorWithPatternImage:[NSImage imageNamed:@"background_pattern"]];
_patternColor = [NSColor colorWithPatternImage:[[NSBundle bundleForClass:[GIMapViewController class]] imageForResource:@"background_pattern"]];
}

- (instancetype)initWithRepository:(GCLiveRepository*)repository {
Expand Down

0 comments on commit 1cb2193

Please sign in to comment.