mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-06-07 11:29:29 +00:00
Added delete warning sheet
This commit is contained in:
parent
f99332cc12
commit
819e72e9ee
|
@ -56,6 +56,7 @@
|
|||
#pragma unused( application )
|
||||
// bug: check if application was an external editor (e.g. Iconographer) and update existing open file instead
|
||||
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfFile:file display:YES];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
|
||||
|
|
|
@ -41,3 +41,12 @@ enum Attributes
|
|||
+ (id)sharedInfoWindowController;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSWindowController (InfoWindowAdditions)
|
||||
|
||||
/*! @function resource
|
||||
@discussion Your plug-in should override this method to return the resource it's editing. Default implementation returns nil.
|
||||
*/
|
||||
- (Resource *)resource;
|
||||
|
||||
@end
|
|
@ -134,4 +134,13 @@
|
|||
return sharedInfoWindowController;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSWindowController (InfoWindowAdditions)
|
||||
|
||||
- (Resource *)resource
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
|
@ -54,20 +54,6 @@
|
|||
return [resource autorelease];
|
||||
}
|
||||
|
||||
+ (NSArray *)getAllResourcesOfType:(NSString *)typeValue inDocument:(NSDocument *)document
|
||||
{
|
||||
NSMutableArray *array = [NSMutableArray array];
|
||||
NSDocument *doc;
|
||||
NSEnumerator *enumerator = [[[NSDocumentController sharedDocumentController] documents] objectEnumerator];
|
||||
while( doc = [enumerator nextObject] )
|
||||
{
|
||||
// parse document for resources
|
||||
if( document == nil || document == doc )
|
||||
[array addObjectsFromArray:[[(ResourceDocument *)doc dataSource] allResourcesOfType:typeValue]];
|
||||
}
|
||||
return [NSArray arrayWithArray:array];
|
||||
}
|
||||
|
||||
+ (Resource *)getResourceOfType:(NSString *)typeValue andID:(NSNumber *)resIDValue inDocument:(NSDocument *)document
|
||||
{
|
||||
NSDocument *doc;
|
||||
|
@ -84,6 +70,22 @@
|
|||
return nil;
|
||||
}
|
||||
|
||||
/* ResKnifeResourceProtocol implementation */
|
||||
|
||||
+ (NSArray *)allResourcesOfType:(NSString *)typeValue inDocument:(NSDocument *)document
|
||||
{
|
||||
NSMutableArray *array = [NSMutableArray array];
|
||||
NSDocument *doc;
|
||||
NSEnumerator *enumerator = [[[NSDocumentController sharedDocumentController] documents] objectEnumerator];
|
||||
while( doc = [enumerator nextObject] )
|
||||
{
|
||||
// parse document for resources
|
||||
if( document == nil || document == doc )
|
||||
[array addObjectsFromArray:[[(ResourceDocument *)doc dataSource] allResourcesOfType:typeValue]];
|
||||
}
|
||||
return [NSArray arrayWithArray:array];
|
||||
}
|
||||
|
||||
+ (Resource *)resourceOfType:(NSString *)typeValue withName:(NSString *)nameValue inDocument:(NSDocument *)document
|
||||
{
|
||||
NSDocument *doc;
|
||||
|
@ -100,6 +102,22 @@
|
|||
return nil;
|
||||
}
|
||||
|
||||
+ (id)resourceOfType:(NSString *)typeValue andID:(NSNumber *)resIDValue inDocument:(NSDocument *)document
|
||||
{
|
||||
NSDocument *doc;
|
||||
NSEnumerator *enumerator = [[[NSDocumentController sharedDocumentController] documents] objectEnumerator];
|
||||
while( doc = [enumerator nextObject] )
|
||||
{
|
||||
if( document == nil || document == doc )
|
||||
{
|
||||
// parse document for correct resource
|
||||
Resource *resource = [[(ResourceDocument *)doc dataSource] resourceOfType:typeValue andID:resIDValue];
|
||||
if( resource ) return resource;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[name release];
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finished;
|
||||
|
||||
- (IBAction)clear:(id)sender;
|
||||
- (void)deleteResourcesSheetDidDismiss:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
|
||||
- (void)deleteSelectedResources;
|
||||
|
||||
- (void)resourceNameWillChange:(NSNotification *)notification;
|
||||
- (void)resourceIDWillChange:(NSNotification *)notification;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#import "ResourceDataSource.h"
|
||||
#import "ResourceNameCell.h"
|
||||
#import "Resource.h"
|
||||
#import "PrefsWindowController.h"
|
||||
#import "CreateResourceSheetController.h"
|
||||
#import "NSOutlineView-SelectedItems.h"
|
||||
|
||||
|
@ -309,8 +310,8 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh
|
|||
if( tmpl && [[templateEditor principalClass] respondsToSelector:@selector(initWithResources:)] )
|
||||
{
|
||||
// bug: I alloc a plug instance here, but have no idea where I should dealloc it, perhaps the plug ought to call [self autorelease] when it's last window is closed?
|
||||
id plug = [(id <ResKnifePluginProtocol>)[[templateEditor principalClass] alloc] initWithResources:resource, tmpl, nil];
|
||||
if( plug ) return;
|
||||
NSWindowController *plugController = [(id <ResKnifePluginProtocol>)[[templateEditor principalClass] alloc] initWithResources:resource, tmpl, nil];
|
||||
if( plugController ) return;
|
||||
}
|
||||
|
||||
// if no template exists, or template editor is broken, open as hex
|
||||
|
@ -382,6 +383,22 @@ static NSString *RKShowInfoItemIdentifier = @"com.nickshanks.resknife.toolbar.sh
|
|||
#pragma mark -
|
||||
|
||||
- (IBAction)clear:(id)sender
|
||||
{
|
||||
if( [prefs boolForKey:@"DeleteResourceWarning"] )
|
||||
{
|
||||
NSBeginCriticalAlertSheet( @"Delete Resource", @"Delete", @"Cancel", nil, [self mainWindow], self, nil, @selector(deleteResourcesSheetDidDismiss:returnCode:contextInfo:), nil, @"Please confirm you wish to delete the selected resources." );
|
||||
}
|
||||
else [self deleteSelectedResources];
|
||||
}
|
||||
|
||||
- (void)deleteResourcesSheetDidDismiss:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
|
||||
{
|
||||
#pragma unused( contextInfo )
|
||||
if( returnCode == NSOKButton )
|
||||
[self deleteSelectedResources];
|
||||
}
|
||||
|
||||
- (void)deleteSelectedResources
|
||||
{
|
||||
Resource *resource;
|
||||
NSEnumerator *enumerator;
|
||||
|
|
Loading…
Reference in New Issue
Block a user