aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPCustomQuery.m2
-rw-r--r--Source/SPFieldEditorController.h2
-rw-r--r--Source/SPFieldEditorController.m78
-rw-r--r--Source/SPGeometryDataView.h2
-rw-r--r--Source/SPGeometryDataView.m31
-rw-r--r--Source/SPTableContent.m2
6 files changed, 93 insertions, 24 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index ca045d92..097b5cd6 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -2309,8 +2309,6 @@
id originalData = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]];
if ([originalData isNSNull])
originalData = [NSString stringWithString:[prefs objectForKey:SPNullValue]];
- else if ([originalData isKindOfClass:[MCPGeometryData class]])
- originalData = [originalData wktString];
id editData = [[fieldEditor editWithObject:originalData
fieldName:[columnDefinition objectForKey:@"name"]
diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h
index 9817ac65..a5ad776f 100644
--- a/Source/SPFieldEditorController.h
+++ b/Source/SPFieldEditorController.h
@@ -23,6 +23,8 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
+#import <MCPKit/MCPKit.h>
+
/**
* @class SPExportFile SPExportFile.h
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index f9153a58..0362c430 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -33,6 +33,7 @@
#import "SPDataCellFormatter.h"
#import "SPTooltip.h"
#import "SPConstants.h"
+#import "SPGeometryDataView.h"
@implementation SPFieldEditorController
@@ -204,6 +205,8 @@
_isEditable = isEditable;
+ BOOL _isGeometry = ([[fieldType uppercaseString] isEqualToString:@"GEOMETRY"]) ? YES : NO;
+
// Set field label
NSMutableString *label = [NSMutableString string];
[label appendFormat:@"“%@”", fieldName];
@@ -298,9 +301,9 @@
[editTextView setHidden:YES];
[editTextScrollView setHidden:YES];
- // Hide QuickLook button and text/iamge/hex control for text data
- [editSheetQuickLookButton setHidden:(!_isBlob && !_isBINARY)];
- [editSheetSegmentControl setHidden:(!_isBlob && !_isBINARY)];
+ // Hide QuickLook button and text/image/hex control for text data
+ [editSheetQuickLookButton setHidden:(!_isBlob && !_isBINARY && _isGeometry)];
+ [editSheetSegmentControl setHidden:(!_isBlob && !_isBINARY && !_isGeometry)];
[editSheetSegmentControl setEnabled:YES forSegment:1];
@@ -337,6 +340,17 @@
[editTextView setHidden:YES];
[editTextScrollView setHidden:YES];
[editSheetSegmentControl setSelectedSegment:2];
+ } else if ([sheetEditData isKindOfClass:[MCPGeometryData class]]) {
+ SPGeometryDataView *v = [[[SPGeometryDataView alloc] initWithCoordinates:[sheetEditData coordinates] targetDimension:2000.0] autorelease];
+ image = [v thumbnailImage];
+ stringValue = [[sheetEditData wktString] retain];
+ [hexTextView setString:@""];
+ [hexTextView setHidden:YES];
+ [hexTextScrollView setHidden:YES];
+ [editSheetSegmentControl setEnabled:NO forSegment:2];
+ [editSheetSegmentControl setSelectedSegment:0];
+ [editTextView setHidden:NO];
+ [editTextScrollView setHidden:NO];
} else {
stringValue = [sheetEditData retain];
@@ -352,13 +366,14 @@
if (image) {
[editImage setImage:image];
-
[hexTextView setHidden:YES];
[hexTextScrollView setHidden:YES];
[editImage setHidden:NO];
- [editTextView setHidden:YES];
- [editTextScrollView setHidden:YES];
- [editSheetSegmentControl setSelectedSegment:1];
+ if(!_isGeometry) {
+ [editTextView setHidden:YES];
+ [editTextScrollView setHidden:YES];
+ [editSheetSegmentControl setSelectedSegment:1];
+ }
} else {
[editImage setImage:nil];
}
@@ -387,7 +402,7 @@
[editTextView setSelectedRange:NSMakeRange(0,[[editTextView string] length])];
// Set focus
- if(image == nil)
+ if(image == nil || _isGeometry)
[editSheet makeFirstResponder:editTextView];
else
[editSheet makeFirstResponder:editImage];
@@ -456,7 +471,7 @@
// Remember spell cheecker status
[prefs setBool:[editTextView isContinuousSpellCheckingEnabled] forKey:SPBlobTextEditorSpellCheckingEnabled];
- return ( editSheetReturnCode && _isEditable ) ? sheetEditData : nil;
+ return ( editSheetReturnCode && _isEditable ) ? (_isGeometry) ? [editTextView string] : sheetEditData : nil;
}
/**
@@ -577,12 +592,25 @@
*/
- (IBAction)saveEditSheet:(id)sender
{
- [[NSSavePanel savePanel] beginSheetForDirectory:nil
- file:@""
- modalForWindow:[self window]
- modalDelegate:self
- didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:)
- contextInfo:NULL];
+
+ NSSavePanel *panel = [NSSavePanel savePanel];
+ NSString *fileDefault = @"";
+
+ if([editSheetSegmentControl selectedSegment] == 1 && [sheetEditData isKindOfClass:[MCPGeometryData class]]) {
+ [panel setRequiredFileType:@"pdf"];
+ [panel setAllowsOtherFileTypes:NO];
+ } else {
+ [panel setAllowsOtherFileTypes:YES];
+ }
+ [panel setCanSelectHiddenExtension:YES];
+ [panel setExtensionHidden:NO];
+
+ [panel beginSheetForDirectory:nil
+ file:fileDefault
+ modalForWindow:[self window]
+ modalDelegate:self
+ didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:)
+ contextInfo:NULL];
}
/**
@@ -600,8 +628,26 @@
if ( [sheetEditData isKindOfClass:[NSData class]] ) {
[sheetEditData writeToFile:fileName atomically:YES];
- // Write other field types' representations to the file via the current encoding
}
+ else if ( [sheetEditData isKindOfClass:[MCPGeometryData class]] ) {
+
+ if ( [editSheetSegmentControl selectedSegment] == 0 || editImage == nil ) {
+
+ [[editTextView string] writeToFile:fileName
+ atomically:YES
+ encoding:encoding
+ error:NULL];
+
+ } else if (editImage != nil){
+
+ SPGeometryDataView *v = [[[SPGeometryDataView alloc] initWithCoordinates:[sheetEditData coordinates] targetDimension:2000.0] autorelease];
+ NSData *pdf = [v pdfData];
+ if(pdf)
+ [pdf writeToFile:fileName atomically:YES];
+
+ }
+ }
+ // Write other field types' representations to the file via the current encoding
else {
[[sheetEditData description] writeToFile:fileName
atomically:YES
diff --git a/Source/SPGeometryDataView.h b/Source/SPGeometryDataView.h
index fa1168c5..3ef066e5 100644
--- a/Source/SPGeometryDataView.h
+++ b/Source/SPGeometryDataView.h
@@ -43,9 +43,11 @@
}
+- (id)initWithCoordinates:(NSDictionary*)coord targetDimension:(CGFloat)targetDimension;
- (id)initWithCoordinates:(NSDictionary*)coord;
- (void)setMax:(NSArray*)bbox;
- (NSPoint)normalizePoint:(NSPoint)aPoint;
- (NSImage*)thumbnailImage;
+- (NSData*)pdfData;
@end
diff --git a/Source/SPGeometryDataView.m b/Source/SPGeometryDataView.m
index 95e6d2b7..95d9c7db 100644
--- a/Source/SPGeometryDataView.m
+++ b/Source/SPGeometryDataView.m
@@ -28,16 +28,22 @@
@implementation SPGeometryDataView
/**
- * Initialize SPGeometryDataView object
+ * Initialize SPGeometryDataView object with default targetDimension
*/
- (id)initWithCoordinates:(NSDictionary*)coord
{
+ return [self initWithCoordinates:coord targetDimension:400.0];
+}
+
+/**
+ * Initialize SPGeometryDataView object
+ */
+- (id)initWithCoordinates:(NSDictionary*)coord targetDimension:(CGFloat)targetDimension
+{
CGFloat maxDim;
- CGFloat targetDim = 400.0;
margin_offset = 10.0;
-
type = [coord objectForKey:@"type"];
coordinates = [coord objectForKey:@"coordinates"];
@@ -51,7 +57,7 @@
maxDim = (width > height) ? width : height;
if(maxDim != 0)
- zoom_factor = targetDim/maxDim;
+ zoom_factor = targetDimension/maxDim;
else
zoom_factor = 1.0;
@@ -224,6 +230,9 @@
}
}
+/**
+ * Return the geometry as NSImage by using targetDimension
+ */
- (NSImage*)thumbnailImage
{
@@ -244,6 +253,20 @@
}
/**
+ * Return PDF data of the geometry image
+ */
+- (NSData*)pdfData
+{
+ if(!type || ![type length] || !coordinates || ![coordinates count]) return nil;
+
+ NSSize mySize = self.bounds.size;
+ NSRect myBounds = [self bounds];
+
+ return [self dataWithPDFInsideRect:myBounds];
+
+}
+
+/**
* dealloc
*/
- (void)dealloc
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 760526c9..ab0a15c3 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -3909,8 +3909,6 @@
id cellValue = [tableValues cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]];
if ([cellValue isNSNull])
cellValue = [NSString stringWithString:[prefs objectForKey:SPNullValue]];
- else if ([cellValue isKindOfClass:[MCPGeometryData class]])
- cellValue = [cellValue wktString];
id editData = [[fieldEditor editWithObject:cellValue
fieldName:[[aTableColumn headerCell] stringValue]