Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions JSONModeler/ViewControllers/MainWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#import <Cocoa/Cocoa.h>

@class GenerateFilesButton, InvalidDataButton;
@class GenerateFilesButton, InvalidDataButton, JSONTextView;

@interface MainWindowController : NSWindowController

@property (weak) IBOutlet NSButton *getDataButton;
@property (unsafe_unretained) IBOutlet NSTextView *JSONTextView;
@property (unsafe_unretained) IBOutlet JSONTextView *JSONTextView;
@property (weak) IBOutlet NSProgressIndicator *progressView;
@property (weak) IBOutlet NSButton *optionsButton;
@property (weak) IBOutlet NSScrollView *scrollView;
Expand Down
1 change: 1 addition & 0 deletions JSONModeler/ViewControllers/MainWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "GenerateFilesButton.h"
#import "InvalidDataButton.h"
#import "MAAttachedWindow.h"
#import "JSONTextView.h"

#import "OutputLanguageWriterObjectiveC.h"
#import "OutputLanguageWriterJava.h"
Expand Down
4 changes: 2 additions & 2 deletions JSONModeler/ViewControllers/MainWindowController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="JSON Modeler" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" texturedBackground="YES"/>
<windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/>
Expand All @@ -41,7 +41,7 @@
<rect key="frame" x="0.0" y="0.0" width="761" height="485"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" richText="NO" findStyle="panel" allowsUndo="YES" usesRuler="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" smartInsertDelete="YES" id="440">
<textView importsGraphics="NO" richText="NO" findStyle="panel" allowsUndo="YES" usesRuler="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" smartInsertDelete="YES" id="440" customClass="JSONTextView">
<rect key="frame" x="0.0" y="0.0" width="754" height="485"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
Expand Down
12 changes: 12 additions & 0 deletions JSONModeler/Views/JSONTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@

@interface JSONTextView : NSTextView

/**
* @author Toshiro Sugii, 16-03-10 17:03:03
*
* Parses the current self.string text and Returns a
* NSJSONWritingPrettyPrinted JSON String.
*
* @return A pretty printed version of the current string
*
* @since 1.0.10
*/
- (NSString *)prettyPrintedString;

@end
26 changes: 26 additions & 0 deletions JSONModeler/Views/JSONTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,31 @@ -(BOOL)performDragOperation:(id<NSDraggingInfo>)sender {

}

#pragma mark Override Methods

- (void)paste:(id)sender
{
[super paste:sender];
self.string = [self prettyPrintedString] ?: self.string;
}

#pragma mark Public Methods

- (NSString *)prettyPrintedString
{
NSError *error = nil;
NSData *data = [self.string dataUsingEncoding:NSUTF8StringEncoding];
id object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
if (!error && object)
{
id output = [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:&error];
if (!error)
{
NSString *outputString = [[NSString alloc] initWithData:output encoding:NSUTF8StringEncoding];
return outputString;
}
}
return nil;
}

@end