aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-12 18:25:08 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-12 18:25:08 +0000
commit65e4e8b589aa102be41b2aed6d019b9951bd3c54 (patch)
treed3a5c28b49dce847ad9993aa7f713711145de592 /Source
parentf6da47de43fce8af785dfdc4672ebbb18f7ff118 (diff)
downloadsequelpro-65e4e8b589aa102be41b2aed6d019b9951bd3c54.tar.gz
sequelpro-65e4e8b589aa102be41b2aed6d019b9951bd3c54.tar.bz2
sequelpro-65e4e8b589aa102be41b2aed6d019b9951bd3c54.zip
• rewrote editSheet for editing and displaying BLOB or TEXT data completely
• added the possibility to QuickLook the current data by choosing a data format
Diffstat (limited to 'Source')
-rw-r--r--Source/TableContent.h111
-rw-r--r--Source/TableContent.m209
2 files changed, 300 insertions, 20 deletions
diff --git a/Source/TableContent.h b/Source/TableContent.h
index ddae12df..0e5aad67 100644
--- a/Source/TableContent.h
+++ b/Source/TableContent.h
@@ -28,6 +28,97 @@
#import <Cocoa/Cocoa.h>
#import <MCPKit_bundled/MCPKit_bundled.h>
+@interface QLPreviewPanel : NSPanel
+{
+}
+
++ (id)sharedPreviewPanel;
++ (id)_previewPanel;
++ (BOOL)isSharedPreviewPanelLoaded;
+- (id)initWithContentRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24 backing:(unsigned int)fp28 defer:(BOOL)fp32;
+- (id)initWithCoder:(id)fp8;
+- (void)dealloc;
+- (BOOL)isOpaque;
+- (BOOL)canBecomeKeyWindow;
+- (BOOL)canBecomeMainWindow;
+- (BOOL)shouldIgnorePanelFrameChanges;
+- (BOOL)isOpen;
+- (void)setFrame:(struct _NSRect)fp8 display:(BOOL)fp24 animate:(BOOL)fp28;
+- (id)_subEffectsForWindow:(id)fp8 itemFrame:(struct _NSRect)fp12 transitionWindow:(id *)fp28;
+- (id)_scaleEffectForItemFrame:(struct _NSRect)fp8 transitionWindow:(id *)fp24;
+- (void)_invertCurrentEffect;
+- (struct _NSRect)_currentItemFrame;
+- (void)setAutosizesAndCenters:(BOOL)fp8;
+- (BOOL)autosizesAndCenters;
+- (void)makeKeyAndOrderFront:(id)fp8;
+- (void)makeKeyAndOrderFrontWithEffect:(int)fp8;
+- (void)makeKeyAndGoFullscreenWithEffect:(int)fp8;
+- (void)makeKeyAndOrderFrontWithEffect:(int)fp8 canClose:(BOOL)fp12;
+- (void)_makeKeyAndOrderFrontWithEffect:(int)fp8 canClose:(BOOL)fp12 willOpen:(BOOL)fp16 toFullscreen:(BOOL)fp20;
+- (int)openingEffect;
+- (void)closePanel;
+- (void)close;
+- (void)closeWithEffect:(int)fp8;
+- (void)closeWithEffect:(int)fp8 canReopen:(BOOL)fp12;
+- (void)_closeWithEffect:(int)fp8 canReopen:(BOOL)fp12;
+- (void)windowEffectDidTerminate:(id)fp8;
+- (void)_close:(id)fp8;
+- (void)sendEvent:(id)fp8;
+- (void)selectNextItem;
+- (void)selectPreviousItem;
+- (void)setURLs:(id)fp8 currentIndex:(unsigned int)fp12 preservingDisplayState:(BOOL)fp16;
+- (void)setURLs:(id)fp8 preservingDisplayState:(BOOL)fp12;
+- (void)setURLs:(id)fp8;
+- (id)URLs;
+- (unsigned int)indexOfCurrentURL;
+- (void)setIndexOfCurrentURL:(unsigned int)fp8;
+- (void)setDelegate:(id)fp8;
+- (id)sharedPreviewView;
+- (void)setSharedPreviewView:(id)fp8;
+- (void)setCyclesSelection:(BOOL)fp8;
+- (BOOL)cyclesSelection;
+- (void)setShowsAddToiPhotoButton:(BOOL)fp8;
+- (BOOL)showsAddToiPhotoButton;
+- (void)setShowsiChatTheaterButton:(BOOL)fp8;
+- (BOOL)showsiChatTheaterButton;
+- (void)setShowsFullscreenButton:(BOOL)fp8;
+- (BOOL)showsFullscreenButton;
+- (void)setShowsIndexSheetButton:(BOOL)fp8;
+- (BOOL)showsIndexSheetButton;
+- (void)setAutostarts:(BOOL)fp8;
+- (BOOL)autostarts;
+- (void)setPlaysDuringPanelAnimation:(BOOL)fp8;
+- (BOOL)playsDuringPanelAnimation;
+- (void)setDeferredLoading:(BOOL)fp8;
+- (BOOL)deferredLoading;
+- (void)setEnableDragNDrop:(BOOL)fp8;
+- (BOOL)enableDragNDrop;
+- (void)start:(id)fp8;
+- (void)stop:(id)fp8;
+- (void)setShowsIndexSheet:(BOOL)fp8;
+- (BOOL)showsIndexSheet;
+- (void)setShareWithiChat:(BOOL)fp8;
+- (BOOL)shareWithiChat;
+- (void)setPlaysSlideShow:(BOOL)fp8;
+- (BOOL)playsSlideShow;
+- (void)setIsFullscreen:(BOOL)fp8;
+- (BOOL)isFullscreen;
+- (void)setMandatoryClient:(id)fp8;
+- (id)mandatoryClient;
+- (void)setForcedContentTypeUTI:(id)fp8;
+- (id)forcedContentTypeUTI;
+- (void)setDocumentURLs:(id)fp8;
+- (void)setDocumentURLs:(id)fp8 preservingDisplayState:(BOOL)fp12;
+- (void)setDocumentURLs:(id)fp8 itemFrame:(struct _NSRect)fp12;
+- (void)setURLs:(id)fp8 itemFrame:(struct _NSRect)fp12;
+- (void)setAutoSizeAndCenterOnScreen:(BOOL)fp8;
+- (void)setShowsAddToiPhoto:(BOOL)fp8;
+- (void)setShowsiChatTheater:(BOOL)fp8;
+- (void)setShowsFullscreen:(BOOL)fp8;
+
+@end
+
+
@class CMMCPConnection, CMMCPResult, CMCopyTable;
@interface TableContent : NSObject
@@ -36,13 +127,18 @@
IBOutlet id tablesListInstance;
IBOutlet id tableDataInstance;
+ IBOutlet id editSheetProgressBar;
+
IBOutlet id tableWindow;
IBOutlet CMCopyTable *tableContentView;
IBOutlet id editSheet;
- IBOutlet id editSheetTabView;
+ IBOutlet id editSheetSegmentControl;
+ IBOutlet id editSheetQuickLookButton;
IBOutlet id editImage;
IBOutlet id editTextView;
IBOutlet id hexTextView;
+ IBOutlet id editTextScrollView;
+ IBOutlet id hexTextScrollView;
IBOutlet id fieldField;
IBOutlet id compareField;
IBOutlet id argumentField;
@@ -68,6 +164,8 @@
NSUserDefaults *prefs;
int numRows, currentlyEditingRow, maxNumRowsOfCurrentTable;
bool areShowingAllRows;
+
+ int qlPane;
}
//table methods
@@ -89,6 +187,17 @@
- (IBAction)closeEditSheet:(id)sender;
- (IBAction)openEditSheet:(id)sender;
- (IBAction)saveEditSheet:(id)sender;
+- (IBAction)segmentControllerChanged:(id)sender;
+- (IBAction)quickLookAsMovie:(id)sender;
+- (IBAction)quickLookAsSoundLinear:(id)sender;
+- (IBAction)quickLookAsSoundM4A:(id)sender;
+- (IBAction)quickLookAsSoundMP3:(id)sender;
+- (IBAction)quickLookAsImage:(id)sender;
+- (IBAction)quickLookAsPDF:(id)sender;
+- (IBAction)quickLookAsWordDoc:(id)sender;
+- (IBAction)quickLookAsRTF:(id)sender;
+- (IBAction)quickLookAsHTML:(id)sender;
+- (void)invokeQuickLookOfType:(NSString *)type;
- (void)processUpdatedImageData:(NSData *)data;
- (IBAction)dropImage:(id)sender;
- (void)textDidChange:(NSNotification *)notification;
diff --git a/Source/TableContent.m b/Source/TableContent.m
index a6c297b2..62737a5c 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -69,6 +69,9 @@
{
// Set the table content view's vertical gridlines if required
[tableContentView setGridStyleMask:([prefs boolForKey:@"DisplayTableViewVerticalGridlines"]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+ // if([[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load])
+ // NSLog(@"Quick Look loaded!");
+
}
/*
@@ -856,7 +859,9 @@
if ( [panel runModal] == NSOKButton ) {
NSString *fileName = [panel filename];
-
+
+ [editSheetProgressBar startAnimation:self];
+
// free old data
if ( editData != nil ) {
[editData release];
@@ -866,7 +871,7 @@
editData = [[NSData alloc] initWithContentsOfFile:fileName];
NSImage *image = [[NSImage alloc] initWithData:editData];
NSString *contents = [NSString stringWithContentsOfFile:fileName];
-
+
// set the image preview, string contents and hex representation
[editImage setImage:image];
[editTextView setString:contents];
@@ -874,15 +879,53 @@
// If the image cell now contains a valid image, select the image tab
if (image) {
- [editSheetTabView selectTabViewItemAtIndex:1];
+ [editSheetSegmentControl setSelectedSegment:1];
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:NO];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
// Otherwise deselect the image tab if it's selected but now not showing anything
} else {
- if ([editSheetTabView indexOfTabViewItem:[editSheetTabView selectedTabViewItem]] == 1)
- [editSheetTabView selectTabViewItemAtIndex:0];
+ [editSheetSegmentControl setSelectedSegment:0];
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [editTextView setHidden:NO];
+ [editTextScrollView setHidden:NO];
}
[image release];
+
+ [editSheetProgressBar stopAnimation:self];
+ }
+}
+
+- (IBAction)segmentControllerChanged:(id)sender
+{
+ switch([sender selectedSegment]){
+ case 0:
+ [editTextView setHidden:NO];
+ [editTextScrollView setHidden:NO];
+ [editImage setHidden:YES];
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ break;
+ case 1:
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+ [editImage setHidden:NO];
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ break;
+ case 2:
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [hexTextView setHidden:NO];
+ [hexTextScrollView setHidden:NO];
+ break;
}
}
@@ -894,6 +937,9 @@
NSSavePanel *panel = [NSSavePanel savePanel];
if ( [panel runModal] == NSOKButton ) {
+
+ [editSheetProgressBar startAnimation:self];
+
NSString *fileName = [panel filename];
// Write binary field types directly to the file
@@ -907,9 +953,110 @@
encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]
error:NULL];
}
+
+ [editSheetProgressBar stopAnimation:self];
+
+ }
+}
+
+- (IBAction)quickLookAsWordDoc:(id)sender
+{
+ [self invokeQuickLookOfType:@"doc"];
+}
+- (IBAction)quickLookAsRTF:(id)sender
+{
+ [self invokeQuickLookOfType:@"rtf"];
+}
+- (IBAction)quickLookAsMovie:(id)sender
+{
+ [self invokeQuickLookOfType:@"mov"];
+}
+- (IBAction)quickLookAsSoundM4A:(id)sender
+{
+ [self invokeQuickLookOfType:@"m4a"];
+}
+- (IBAction)quickLookAsSoundMP3:(id)sender
+{
+ [self invokeQuickLookOfType:@"mp3"];
+}
+- (IBAction)quickLookAsSoundLinear:(id)sender
+{
+ [self invokeQuickLookOfType:@"wav"];
+}
+- (IBAction)quickLookAsImage:(id)sender
+{
+ [self invokeQuickLookOfType:@"pict"];
+}
+- (IBAction)quickLookAsPDF:(id)sender
+{
+ [self invokeQuickLookOfType:@"pdf"];
+}
+- (IBAction)quickLookAsHTML:(id)sender
+{
+ [self invokeQuickLookOfType:@"html"];
+}
+
+- (void)invokeQuickLookOfType:(NSString *)type
+{
+
+ if([[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load]) {
+
+ [editSheetProgressBar startAnimation:self];
+
+ NSString *tmpFileName = [NSString stringWithFormat:@"/tmp/SequelProQuickLook.%@", type];
+
+ if ( [editData isKindOfClass:[NSData class]] ) {
+ [editData writeToFile:tmpFileName atomically:YES];
+
+ // Write other field types' representations to the file via the current encoding
+ } else {
+ [[editData description] writeToFile:tmpFileName
+ atomically:YES
+ encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]
+ error:NULL];
+ }
+
+ [[[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] delegate] setDelegate:self];
+ [[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] setURLs:[NSArray arrayWithObject:
+ [NSURL fileURLWithPath:tmpFileName]] currentIndex:0 preservingDisplayState:YES];
+ [[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] setShowsAddToiPhotoButton:NO];
+ [[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] setShowsiChatTheaterButton:NO];
+ [[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] setShowsFullscreenButton:NO];
+ [[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] setEnableDragNDrop:NO];
+ [[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] makeKeyAndOrderFrontWithEffect:2 canClose:YES]; // 1 = fade in
+
+ qlPane = 0;
+
+ [editSheetProgressBar stopAnimation:self];
+
+ NSModalSession session = [NSApp beginModalSessionForWindow:[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel]];
+ for (;;) {
+ if ([NSApp runModalSession:session] != NSRunContinuesResponse || qlPane == 1 || ![[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] isVisible])
+ break;
+ }
+ [NSApp endModalSession:session];
+
}
+
+}
+
+// This is the delegate method
+// It should return the frame for the item represented by the URL
+// If an empty frame is returned then the panel will fade in/out instead
+- (NSRect)previewPanel:(NSPanel*)panel frameForURL:(NSURL*)URL
+{
+
+ // Close modal session defined in invokeQuickLookOfType:
+ // if user closes the QuickLook view
+ qlPane = 1;
+
+ NSRect r = [editSheetQuickLookButton convertRectToBase:[editSheetQuickLookButton frame]];
+ // NSLog(@"%@ %@", r, [[NSApp mainWindow] frame]);
+ r.origin.y=400;
+ return r;
}
+
/*
* Invoked when the imageView in the connection sheet has the contents deleted
* or a file dragged and dropped onto it.
@@ -2053,47 +2200,70 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
// Open the sheet if the multipleLineEditingButton is enabled or the column was a blob or a text.
if ( [multipleLineEditingButton state] == NSOnState || [tableDataInstance columnIsBlobOrText:[aTableColumn identifier]] ) {
+
theValue = [[filteredResult objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]];
NSImage *image = nil;
editData = [theValue retain];
-
+
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+
+ [NSApp beginSheet:editSheet modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
+
+ [editSheetProgressBar startAnimation:self];
+
if ( [theValue isKindOfClass:[NSData class]] ) {
image = [[[NSImage alloc] initWithData:theValue] autorelease];
[hexTextView setString:[self dataToHex:theValue]];
stringValue = [[NSString alloc] initWithData:theValue encoding:[mySQLConnection encoding]];
if (stringValue == nil)
stringValue = [[NSString alloc] initWithData:theValue encoding:NSASCIIStringEncoding];
+ [hexTextView setHidden:NO];
+ [hexTextScrollView setHidden:NO];
+ [editImage setHidden:YES];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+ [editSheetSegmentControl setSelectedSegment:2];
} else {
[hexTextView setString:@""];
stringValue = [[NSString alloc] initWithString:[theValue description]];
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:YES];
+ [editTextView setHidden:NO];
+ [editTextScrollView setHidden:NO];
+ [editSheetSegmentControl setSelectedSegment:0];
}
if (image) {
[editImage setImage:image];
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editImage setHidden:NO];
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+ [editSheetSegmentControl setSelectedSegment:1];
} else {
- [editImage setImage:nil];
+ [editImage setImage:nil];
}
if (stringValue) {
[editTextView setString:stringValue];
- [editTextView setSelectedRange:NSMakeRange(0,[[editTextView string] length])];
+ //[editTextView setSelectedRange:NSMakeRange(0,[[editTextView string] length])];
[stringValue release];
}
- // If the cell contains a valid image, select the image tab
- if (image) {
- [editSheetTabView selectTabViewItemAtIndex:1];
+ [editSheetProgressBar stopAnimation:self];
- // Otherwise default to text tab
- } else {
- [editSheetTabView selectTabViewItemAtIndex:0];
- }
-
- [NSApp beginSheet:editSheet modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
code = [NSApp runModalForWindow:editSheet];
[NSApp endSheet:editSheet];
[editSheet orderOut:nil];
+ qlPane = 1;
+
if ( code ) {
if ( !isEditingRow ) {
[oldRow setDictionary:[filteredResult objectAtIndex:rowIndex]];
@@ -2102,7 +2272,6 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
}
[[filteredResult objectAtIndex:rowIndex] setObject:[editData copy] forKey:[aTableColumn identifier]];
-
// Clean up
[editImage setImage:nil];
[editTextView setString:@""];
@@ -2110,8 +2279,11 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
if ( editData ) {
[editData release];
}
+
}
+
return NO;
+
} else {
return YES;
}
@@ -2241,7 +2413,6 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
[tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
}
}
-
// Last but not least
- (void)dealloc
{