Permalink
Browse files

Added support for opening (supported) document types in external edit…

…ors/viewers.
  • Loading branch information...
1 parent fee102d commit dc0d29090899ba2bad49bbf563b7aff33c7f0343 Jim Dovey committed May 11, 2010
@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
-@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate, UITableViewDataSource, UITableViewDelegate> {
+@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate, UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate> {
UIPopoverController *popoverController;
UIToolbar *toolbar;
@@ -19,11 +19,15 @@
UITableView *detailTableView;
NSMutableArray * _tableData;
+
+ UIDocumentInteractionController * _documentController;
}
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;
@property (nonatomic, retain) IBOutlet UIBarItem *titleBarItem;
@property (nonatomic, copy) NSDictionary * detailItem;
@property (nonatomic, retain) IBOutlet UITableView *detailTableView;
+@property (nonatomic, retain) UIDocumentInteractionController * documentInteractionController;
+
@end
@@ -9,6 +9,7 @@
#import "DetailViewController.h"
#import "RootViewController.h"
#import "CustomFormatters.h"
+#import "DocumentInteractionView.h"
enum
{
@@ -41,6 +42,7 @@ - (void)configureView;
@implementation DetailViewController
@synthesize toolbar, popoverController, detailItem, detailTableView, titleBarItem;
+@synthesize documentInteractionController=_documentController;
+ (void) initialize
{
@@ -120,7 +122,7 @@ - (void) configureView
[_tableData addObject: [NSMutableArray arrayWithCapacity: [PermissionDetailKeys count]]];
[_tableData addObject: [NSMutableArray arrayWithCapacity: [FinderInfoKeys count]]];
- if ( detailItem == [NSNull null] )
+ if ( (id)detailItem == [NSNull null] )
{
[self.detailTableView reloadData];
return;
@@ -171,10 +173,19 @@ - (void) configureView
}
}
+ if ( self.documentInteractionController != nil )
+ {
+ self.documentInteractionController.delegate = self;
+
+ DocumentInteractionView * header = [[DocumentInteractionView alloc] initWithFrame: CGRectMake(0.0, 0.0, self.detailTableView.bounds.size.width, 128.0)];
+ header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ header.documentInteractionController = self.documentInteractionController;
+ self.detailTableView.tableHeaderView = header;
+ }
+
[self.detailTableView reloadData];
}
-
#pragma mark -
#pragma mark Split view support
@@ -266,13 +277,27 @@ - (NSString *) tableView: (UITableView *) tableView titleForHeaderInSection: (NS
- (NSString *) tableView: (UITableView *) tableView titleForFooterInSection: (NSInteger) section
{
- if ( (section == kNumSections-1) && (detailItem == [NSNull null]) )
+ if ( (section == kNumSections-1) && ((id)detailItem == [NSNull null]) )
return ( NSLocalizedString(@"No Information Available", @"") );
return ( nil );
}
#pragma mark -
+#pragma mark Document Interaction Controller Delegate
+
+- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
+{
+ return ( self );
+}
+
+- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
+{
+ DocumentInteractionView * aView = (DocumentInteractionView *)self.detailTableView.tableHeaderView;
+ return ( aView.previewStartView );
+}
+
+#pragma mark -
#pragma mark View lifecycle
- (void) setTitle: (NSString *) aTitle
@@ -330,6 +355,7 @@ - (void) dealloc
[detailItem release];
[detailTableView release];
[_tableData release];
+ [_documentController release];
[super dealloc];
}
@@ -0,0 +1,21 @@
+//
+// DocumentInteractionView.h
+// iPad Filesystem
+//
+// Created by Jim Dovey on 10-05-11.
+// Copyright 2010 Kobo Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+
+@interface DocumentInteractionView : UIView
+{
+ UIDocumentInteractionController * _controller;
+ UIImageView * _iconView;
+}
+
+@property (nonatomic, retain) UIDocumentInteractionController * documentInteractionController;
+@property (nonatomic, readonly) UIView * previewStartView;
+
+@end
@@ -0,0 +1,62 @@
+//
+// DocumentInteractionView.m
+// iPad Filesystem
+//
+// Created by Jim Dovey on 10-05-11.
+// Copyright 2010 Kobo Inc. All rights reserved.
+//
+
+#import "DocumentInteractionView.h"
+
+
+@implementation DocumentInteractionView
+
+@synthesize documentInteractionController=_controller, previewStartView=_iconView;
+
+- (id) initWithFrame: (CGRect) frame
+{
+ self = [super initWithFrame: frame];
+ if ( self == nil )
+ return ( nil );
+
+ _iconView = [[UIImageView alloc] initWithFrame: CGRectZero];
+ _iconView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
+ _iconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
+ _iconView.userInteractionEnabled = YES;
+ [self addSubview: _iconView];
+
+ self.backgroundColor = [UIColor groupTableViewBackgroundColor];
+
+ return ( self );
+}
+
+- (void) dealloc
+{
+ [_controller dealloc];
+ [super dealloc];
+}
+
+- (void) layoutSubviews
+{
+ [super layoutSubviews];
+
+ CGRect aFrame = _iconView.frame;
+ aFrame.size = _iconView.image.size;
+ _iconView.frame = aFrame;
+
+ _iconView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
+}
+
+- (void) setDocumentInteractionController: (UIDocumentInteractionController *) controller
+{
+ [_controller release];
+ _controller = [controller retain];
+
+ _iconView.gestureRecognizers = _controller.gestureRecognizers;
+
+ _iconView.image = [_controller.icons objectAtIndex: 0];
+ _iconView.opaque = NO;
+ _iconView.backgroundColor = [UIColor clearColor];
+}
+
+@end
@@ -139,8 +139,9 @@ - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath
/*
When a row is selected, set the detail view controller's detail item to the item associated with the selected row.
*/
- self.detailViewController.detailItem = [_attributes objectAtIndex: indexPath.row];
+ self.detailViewController.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL: [NSURL fileURLWithPath: [self.folderPath stringByAppendingPathComponent: [_folderContents objectAtIndex: indexPath.row]]]];
self.detailViewController.title = [_folderContents objectAtIndex: indexPath.row];
+ self.detailViewController.detailItem = [_attributes objectAtIndex: indexPath.row];
}
- (void) tableView: (UITableView *) aTableView accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *) indexPath
@@ -18,6 +18,7 @@
28AD73600D9D9599002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD735F0D9D9599002E5188 /* MainWindow.xib */; };
382EA9EB11985F4F004DA8F9 /* UIAlertView+NSError.m in Sources */ = {isa = PBXBuildFile; fileRef = 382EA9EA11985F4F004DA8F9 /* UIAlertView+NSError.m */; };
382EAA061198700C004DA8F9 /* CustomFormatters.m in Sources */ = {isa = PBXBuildFile; fileRef = 382EAA051198700C004DA8F9 /* CustomFormatters.m */; };
+ 382EAE20119A0116004DA8F9 /* DocumentInteractionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 382EAE1F119A0116004DA8F9 /* DocumentInteractionView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -39,6 +40,8 @@
382EA9EA11985F4F004DA8F9 /* UIAlertView+NSError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+NSError.m"; sourceTree = "<group>"; };
382EAA041198700C004DA8F9 /* CustomFormatters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomFormatters.h; sourceTree = "<group>"; };
382EAA051198700C004DA8F9 /* CustomFormatters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomFormatters.m; sourceTree = "<group>"; };
+ 382EAE1E119A0116004DA8F9 /* DocumentInteractionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentInteractionView.h; sourceTree = "<group>"; };
+ 382EAE1F119A0116004DA8F9 /* DocumentInteractionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DocumentInteractionView.m; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* iPad_Filesystem-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "iPad_Filesystem-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -65,6 +68,8 @@
28042008108E984D000629CD /* RootViewController.m */,
28042009108E984D000629CD /* DetailViewController.h */,
2804200A108E984D000629CD /* DetailViewController.m */,
+ 382EAE1E119A0116004DA8F9 /* DocumentInteractionView.h */,
+ 382EAE1F119A0116004DA8F9 /* DocumentInteractionView.m */,
382EA9E911985F4F004DA8F9 /* UIAlertView+NSError.h */,
382EA9EA11985F4F004DA8F9 /* UIAlertView+NSError.m */,
382EAA041198700C004DA8F9 /* CustomFormatters.h */,
@@ -189,6 +194,7 @@
2804200C108E984D000629CD /* DetailViewController.m in Sources */,
382EA9EB11985F4F004DA8F9 /* UIAlertView+NSError.m in Sources */,
382EAA061198700C004DA8F9 /* CustomFormatters.m in Sources */,
+ 382EAE20119A0116004DA8F9 /* DocumentInteractionView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit dc0d290

Please sign in to comment.