mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
ARC: Update HTMLOutput framework
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
#import <oak/debug.h>
|
||||
#import <oak/misc.h>
|
||||
|
||||
@class HOStatusBar;
|
||||
@class HOWebViewDelegateHelper;
|
||||
|
||||
@interface HOBrowserView : NSView
|
||||
{
|
||||
OBJC_WATCH_LEAKS(HOBrowserView);
|
||||
WebView* webView;
|
||||
HOStatusBar* statusBar;
|
||||
HOWebViewDelegateHelper* webViewDelegateHelper;
|
||||
}
|
||||
@property (nonatomic, readonly) WebView* webView;
|
||||
@property (nonatomic, readonly) HOStatusBar* statusBar;
|
||||
@property (nonatomic, retain) NSString* projectUUID;
|
||||
- (void)setUpdatesProgress:(BOOL)flag;
|
||||
@end
|
||||
|
||||
@@ -4,9 +4,13 @@
|
||||
#import <OakAppKit/OakAppKit.h>
|
||||
#import <OakAppKit/NSColor Additions.h>
|
||||
|
||||
@implementation HOBrowserView
|
||||
@synthesize webView;
|
||||
@interface HOBrowserView ()
|
||||
@property (nonatomic, readwrite) WebView* webView;
|
||||
@property (nonatomic, readwrite) HOStatusBar* statusBar;
|
||||
@property (nonatomic, retain) HOWebViewDelegateHelper* webViewDelegateHelper;
|
||||
@end
|
||||
|
||||
@implementation HOBrowserView
|
||||
+ (BOOL)requiresConstraintBasedLayout
|
||||
{
|
||||
return YES;
|
||||
@@ -21,52 +25,50 @@
|
||||
{
|
||||
if(self = [super initWithFrame:frame])
|
||||
{
|
||||
webView = [[WebView alloc] initWithFrame:NSZeroRect];
|
||||
_webView = [[WebView alloc] initWithFrame:NSZeroRect];
|
||||
|
||||
statusBar = [[HOStatusBar alloc] initWithFrame:NSZeroRect];
|
||||
statusBar.delegate = webView;
|
||||
_statusBar = [[HOStatusBar alloc] initWithFrame:NSZeroRect];
|
||||
_statusBar.delegate = _webView;
|
||||
|
||||
webViewDelegateHelper = [HOWebViewDelegateHelper new];
|
||||
webViewDelegateHelper.delegate = statusBar;
|
||||
webView.policyDelegate = webViewDelegateHelper;
|
||||
webView.resourceLoadDelegate = webViewDelegateHelper;
|
||||
webView.UIDelegate = webViewDelegateHelper;
|
||||
webView.frameLoadDelegate = self;
|
||||
_webViewDelegateHelper = [HOWebViewDelegateHelper new];
|
||||
_webViewDelegateHelper.delegate = _statusBar;
|
||||
_webView.policyDelegate = _webViewDelegateHelper;
|
||||
_webView.resourceLoadDelegate = _webViewDelegateHelper;
|
||||
_webView.UIDelegate = _webViewDelegateHelper;
|
||||
_webView.frameLoadDelegate = self;
|
||||
|
||||
NSBox* divider = OakCreateViewWithColor([NSColor colorWithString:@"#9d9d9d"]);
|
||||
NSDictionary* views = @{
|
||||
@"webView" : _webView,
|
||||
@"divider" : OakCreateViewWithColor([NSColor colorWithString:@"#9d9d9d"]),
|
||||
@"statusBar" : _statusBar
|
||||
};
|
||||
|
||||
NSDictionary* views = NSDictionaryOfVariableBindings(webView, divider, statusBar);
|
||||
for(NSView* view in [views allValues])
|
||||
{
|
||||
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
[self addSubview:view];
|
||||
}
|
||||
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[webView(==statusBar,==divider)]|" options:NSLayoutFormatAlignAllTop metrics:nil views:views]];
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[webView(==statusBar,==divider)]|" options:NSLayoutFormatAlignAllTop metrics:nil views:views]];
|
||||
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[webView(>=10)][divider(==1)][statusBar]|" options:NSLayoutFormatAlignAllLeading metrics:nil views:views]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString*)projectUUID { return webViewDelegateHelper.projectUUID; }
|
||||
- (void)setProjectUUID:(NSString*)aProjectUUID { webViewDelegateHelper.projectUUID = aProjectUUID; }
|
||||
- (NSString*)projectUUID { return _webViewDelegateHelper.projectUUID; }
|
||||
- (void)setProjectUUID:(NSString*)aProjectUUID { _webViewDelegateHelper.projectUUID = aProjectUUID; }
|
||||
|
||||
- (void)webViewProgressEstimateChanged:(NSNotification*)notification
|
||||
{
|
||||
statusBar.progress = webView.estimatedProgress;
|
||||
_statusBar.progress = _webView.estimatedProgress;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self setUpdatesProgress:NO];
|
||||
[webView setResourceLoadDelegate:nil];
|
||||
[webView setFrameLoadDelegate:nil];
|
||||
[[webView mainFrame] stopLoading];
|
||||
|
||||
[webView release];
|
||||
[webViewDelegateHelper release];
|
||||
[statusBar release];
|
||||
[super dealloc];
|
||||
[_webView setResourceLoadDelegate:nil];
|
||||
[_webView setFrameLoadDelegate:nil];
|
||||
[[_webView mainFrame] stopLoading];
|
||||
}
|
||||
|
||||
- (BOOL)isOpaque
|
||||
@@ -76,25 +78,25 @@
|
||||
|
||||
- (void)swipeWithEvent:(NSEvent*)anEvent
|
||||
{
|
||||
if([anEvent deltaX] == +1 && webView.canGoBack)
|
||||
[webView goBack:self];
|
||||
else if([anEvent deltaX] == -1 && webView.canGoForward)
|
||||
[webView goForward:self];
|
||||
if([anEvent deltaX] == +1 && _webView.canGoBack)
|
||||
[_webView goBack:self];
|
||||
else if([anEvent deltaX] == -1 && _webView.canGoForward)
|
||||
[_webView goForward:self];
|
||||
}
|
||||
|
||||
- (void)setUpdatesProgress:(BOOL)flag
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewProgressEstimateChanged:) name:WebViewProgressFinishedNotification object:webView];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewProgressEstimateChanged:) name:WebViewProgressEstimateChangedNotification object:webView];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewProgressEstimateChanged:) name:WebViewProgressStartedNotification object:webView];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewProgressEstimateChanged:) name:WebViewProgressFinishedNotification object:_webView];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewProgressEstimateChanged:) name:WebViewProgressEstimateChangedNotification object:_webView];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(webViewProgressEstimateChanged:) name:WebViewProgressStartedNotification object:_webView];
|
||||
}
|
||||
else
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:WebViewProgressStartedNotification object:webView];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:WebViewProgressEstimateChangedNotification object:webView];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:WebViewProgressFinishedNotification object:webView];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:WebViewProgressStartedNotification object:_webView];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:WebViewProgressEstimateChangedNotification object:_webView];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:WebViewProgressFinishedNotification object:_webView];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,15 +106,15 @@
|
||||
|
||||
- (void)webView:(WebView*)sender didStartProvisionalLoadForFrame:(WebFrame*)frame
|
||||
{
|
||||
statusBar.isBusy = YES;
|
||||
_statusBar.isBusy = YES;
|
||||
[self setUpdatesProgress:YES];
|
||||
}
|
||||
|
||||
- (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame
|
||||
{
|
||||
statusBar.canGoBack = webView.canGoBack;
|
||||
statusBar.canGoForward = webView.canGoForward;
|
||||
statusBar.isBusy = NO;
|
||||
statusBar.progress = 0;
|
||||
_statusBar.canGoBack = _webView.canGoBack;
|
||||
_statusBar.canGoForward = _webView.canGoForward;
|
||||
_statusBar.isBusy = NO;
|
||||
_statusBar.progress = 0;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
@end
|
||||
|
||||
@interface HOStatusBar : NSView
|
||||
@property (nonatomic, assign) BOOL isBusy;
|
||||
@property (nonatomic, assign) CGFloat progress;
|
||||
@property (nonatomic, retain) NSString* statusText;
|
||||
@property (nonatomic, assign) BOOL canGoBack;
|
||||
@property (nonatomic, assign) BOOL canGoForward;
|
||||
@property (nonatomic, weak) id delegate;
|
||||
|
||||
@property (nonatomic, assign) id delegate;
|
||||
@property (nonatomic) NSString* statusText;
|
||||
@property (nonatomic) CGFloat progress;
|
||||
@property (nonatomic) BOOL isBusy;
|
||||
@property (nonatomic) BOOL canGoBack;
|
||||
@property (nonatomic) BOOL canGoForward;
|
||||
@end
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
static NSButton* OakCreateImageButton (NSString* imageName)
|
||||
{
|
||||
NSButton* res = [[NSButton new] autorelease];
|
||||
NSButton* res = [NSButton new];
|
||||
[res setButtonType:NSMomentaryChangeButton];
|
||||
[res setBezelStyle:NSSmallSquareBezelStyle];
|
||||
[res setBordered:NO];
|
||||
|
||||
NSImage* image = [[[NSImage imageNamed:imageName] copy] autorelease];
|
||||
NSImage* image = [[NSImage imageNamed:imageName] copy];
|
||||
[image setSize:NSMakeSize(13, 13)];
|
||||
[res setImage:image];
|
||||
[res setImagePosition:NSImageOnly];
|
||||
@@ -18,7 +18,7 @@ static NSButton* OakCreateImageButton (NSString* imageName)
|
||||
|
||||
static NSTextField* OakCreateTextField ()
|
||||
{
|
||||
NSTextField* res = [[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease];
|
||||
NSTextField* res = [[NSTextField alloc] initWithFrame:NSZeroRect];
|
||||
[res setBordered:NO];
|
||||
[res setEditable:NO];
|
||||
[res setSelectable:NO];
|
||||
@@ -30,22 +30,22 @@ static NSTextField* OakCreateTextField ()
|
||||
|
||||
static NSImageView* OakCreateImageView (NSImage* image)
|
||||
{
|
||||
NSImageView* res = [[[NSImageView alloc] initWithFrame:NSZeroRect] autorelease];
|
||||
NSImageView* res = [[NSImageView alloc] initWithFrame:NSZeroRect];
|
||||
[res setImage:image];
|
||||
return res;
|
||||
}
|
||||
|
||||
@interface HOStatusBar ()
|
||||
@property (nonatomic, retain) NSImage* backgroundImage;
|
||||
@property (nonatomic, retain) NSImageView* firstSeparatorImageView;
|
||||
@property (nonatomic, retain) NSImageView* secondSeparatorImageView;
|
||||
@property (nonatomic, retain) NSButton* goBackButton;
|
||||
@property (nonatomic, retain) NSButton* goForwardButton;
|
||||
@property (nonatomic, retain) NSTextField* statusTextField;
|
||||
@property (nonatomic, retain) NSProgressIndicator* progressIndicator;
|
||||
@property (nonatomic, retain) NSProgressIndicator* spinner;
|
||||
@property (nonatomic, retain) NSMutableArray* layoutConstraints;
|
||||
@property (nonatomic, assign) BOOL indeterminateProgress;
|
||||
@property (nonatomic) NSImage* backgroundImage;
|
||||
@property (nonatomic) NSImageView* firstSeparatorImageView;
|
||||
@property (nonatomic) NSImageView* secondSeparatorImageView;
|
||||
@property (nonatomic) NSButton* goBackButton;
|
||||
@property (nonatomic) NSButton* goForwardButton;
|
||||
@property (nonatomic) NSTextField* statusTextField;
|
||||
@property (nonatomic) NSProgressIndicator* progressIndicator;
|
||||
@property (nonatomic) NSProgressIndicator* spinner;
|
||||
@property (nonatomic) NSMutableArray* layoutConstraints;
|
||||
@property (nonatomic) BOOL indeterminateProgress;
|
||||
@end
|
||||
|
||||
@implementation HOStatusBar
|
||||
@@ -55,25 +55,25 @@ static NSImageView* OakCreateImageView (NSImage* image)
|
||||
{
|
||||
_indeterminateProgress = YES;
|
||||
|
||||
self.backgroundImage = [NSImage imageNamed:@"Statusbar Background" inSameBundleAsClass:NSClassFromString(@"OakStatusBar")];
|
||||
self.firstSeparatorImageView = OakCreateImageView([NSImage imageNamed:@"Statusbar Separator" inSameBundleAsClass:NSClassFromString(@"OakStatusBar")]);
|
||||
self.secondSeparatorImageView = OakCreateImageView([NSImage imageNamed:@"Statusbar Separator" inSameBundleAsClass:NSClassFromString(@"OakStatusBar")]);
|
||||
_backgroundImage = [NSImage imageNamed:@"Statusbar Background" inSameBundleAsClass:NSClassFromString(@"OakStatusBar")];
|
||||
_firstSeparatorImageView = OakCreateImageView([NSImage imageNamed:@"Statusbar Separator" inSameBundleAsClass:NSClassFromString(@"OakStatusBar")]);
|
||||
_secondSeparatorImageView = OakCreateImageView([NSImage imageNamed:@"Statusbar Separator" inSameBundleAsClass:NSClassFromString(@"OakStatusBar")]);
|
||||
|
||||
self.goBackButton = OakCreateImageButton(NSImageNameGoLeftTemplate);
|
||||
self.goBackButton.toolTip = @"Show the previous page";
|
||||
self.goBackButton.enabled = NO;
|
||||
self.goBackButton.target = self;
|
||||
self.goBackButton.action = @selector(goBack:);
|
||||
_goBackButton = OakCreateImageButton(NSImageNameGoLeftTemplate);
|
||||
_goBackButton.toolTip = @"Show the previous page";
|
||||
_goBackButton.enabled = NO;
|
||||
_goBackButton.target = self;
|
||||
_goBackButton.action = @selector(goBack:);
|
||||
|
||||
self.goForwardButton = OakCreateImageButton(NSImageNameGoRightTemplate);
|
||||
self.goForwardButton.toolTip = @"Show the next page";
|
||||
self.goForwardButton.enabled = NO;
|
||||
self.goForwardButton.target = self;
|
||||
self.goForwardButton.action = @selector(goForward:);
|
||||
_goForwardButton = OakCreateImageButton(NSImageNameGoRightTemplate);
|
||||
_goForwardButton.toolTip = @"Show the next page";
|
||||
_goForwardButton.enabled = NO;
|
||||
_goForwardButton.target = self;
|
||||
_goForwardButton.action = @selector(goForward:);
|
||||
|
||||
self.statusTextField = OakCreateTextField();
|
||||
[self.statusTextField setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||
[self.statusTextField.cell setLineBreakMode:NSLineBreakByTruncatingMiddle];
|
||||
_statusTextField = OakCreateTextField();
|
||||
[_statusTextField setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||
[_statusTextField.cell setLineBreakMode:NSLineBreakByTruncatingMiddle];
|
||||
|
||||
_progressIndicator = [NSProgressIndicator new];
|
||||
_progressIndicator.controlSize = NSSmallControlSize;
|
||||
@@ -99,31 +99,16 @@ static NSImageView* OakCreateImageView (NSImage* image)
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.backgroundImage = nil;
|
||||
self.firstSeparatorImageView = nil;
|
||||
self.secondSeparatorImageView = nil;
|
||||
self.goBackButton = nil;
|
||||
self.goForwardButton = nil;
|
||||
self.statusTextField = nil;
|
||||
self.progressIndicator = nil;
|
||||
self.spinner = nil;
|
||||
self.layoutConstraints = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSSize)intrinsicContentSize
|
||||
{
|
||||
return NSMakeSize(NSViewNoInstrinsicMetric, self.backgroundImage.size.height);
|
||||
return NSMakeSize(NSViewNoInstrinsicMetric, _backgroundImage.size.height);
|
||||
}
|
||||
|
||||
- (void)updateConstraints
|
||||
{
|
||||
if(self.layoutConstraints)
|
||||
[self removeConstraints:self.layoutConstraints];
|
||||
self.layoutConstraints = [NSMutableArray array];
|
||||
if(_layoutConstraints)
|
||||
[self removeConstraints:_layoutConstraints];
|
||||
_layoutConstraints = [NSMutableArray array];
|
||||
|
||||
[super updateConstraints];
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
@protocol HOWebViewDelegateHelperProtocol
|
||||
- (NSString*)statusText;
|
||||
- (void)setStatusText:(NSString*)text;
|
||||
@property (nonatomic, retain) NSString* statusText;
|
||||
@end
|
||||
|
||||
@interface HOWebViewDelegateHelper : NSObject
|
||||
{
|
||||
id delegate;
|
||||
NSString* projectUUID;
|
||||
}
|
||||
@property (nonatomic, assign) id delegate;
|
||||
@property (nonatomic, weak) id /*<HOWebViewDelegateHelperProtocol>*/ delegate;
|
||||
@property (nonatomic, retain) NSString* projectUUID;
|
||||
@end
|
||||
|
||||
@@ -4,26 +4,18 @@
|
||||
#import <OakFoundation/NSString Additions.h>
|
||||
|
||||
@implementation HOWebViewDelegateHelper
|
||||
@synthesize delegate, projectUUID;
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[projectUUID release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// =====================
|
||||
// = WebViewUIDelegate =
|
||||
// =====================
|
||||
|
||||
- (void)webView:(WebView*)sender setStatusText:(NSString*)text
|
||||
{
|
||||
[delegate setStatusText:(text ?: @"")];
|
||||
[_delegate setStatusText:(text ?: @"")];
|
||||
}
|
||||
|
||||
- (NSString*)webViewStatusText:(WebView*)sender
|
||||
{
|
||||
return [delegate statusText];
|
||||
return [_delegate statusText];
|
||||
}
|
||||
|
||||
- (void)webView:(WebView*)sender mouseDidMoveOverElement:(NSDictionary*)elementInformation modifierFlags:(NSUInteger)modifierFlags
|
||||
@@ -56,7 +48,7 @@
|
||||
NSPoint origin = [sender.window cascadeTopLeftFromPoint:NSMakePoint(NSMinX(sender.window.frame), NSMaxY(sender.window.frame))];
|
||||
origin.y -= NSHeight(sender.window.frame);
|
||||
|
||||
HOBrowserView* view = [[HOBrowserView new] autorelease];
|
||||
HOBrowserView* view = [HOBrowserView new];
|
||||
NSWindow* window = [[NSWindow alloc] initWithContentRect:(NSRect){origin, NSMakeSize(750, 800)}
|
||||
styleMask:(NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask)
|
||||
backing:NSBackingStoreBuffered
|
||||
@@ -96,8 +88,8 @@
|
||||
NSURL* url = request.URL;
|
||||
if([[url scheme] isEqualToString:@"txmt"])
|
||||
{
|
||||
if(projectUUID)
|
||||
url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"&project=%@", projectUUID]];
|
||||
if(_projectUUID)
|
||||
url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"&project=%@", _projectUUID]];
|
||||
[NSApp sendAction:@selector(handleTxMtURL:) to:nil from:url];
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user