Introduce OakTextViewDelegate

This commit is contained in:
Allan Odgaard
2012-09-18 01:13:11 +02:00
parent 4ad00f7797
commit dabcad588d
4 changed files with 38 additions and 4 deletions

View File

@@ -1,14 +1,13 @@
#import "DocumentOpenHelper.h"
#import <OakFileBrowser/OakFileBrowser.h>
#import <OakAppKit/OakTabBarView.h>
#import <OakTextView/OakDocumentView.h>
#import <oak/debug.h>
#import <plist/uuid.h>
#import <command/runner.h>
#import <scm/scm.h>
@class ProjectLayoutView;
@class OakDocumentView;
@class OakTextView;
@class OakFilterWindowController;
@class OakHTMLOutputView;
@@ -17,7 +16,7 @@ typedef std::shared_ptr<document_tab_t> document_tab_ptr;
namespace bundles { struct item_t; typedef std::shared_ptr<item_t> item_ptr; }
PUBLIC @interface DocumentController : NSWindowController <NSWindowDelegate, OakFileBrowserDelegate, OakTabBarViewDelegate, OakTabBarViewDataSource, DocumentOpenHelperDelegate>
PUBLIC @interface DocumentController : NSWindowController <NSWindowDelegate, OakFileBrowserDelegate, OakTabBarViewDelegate, OakTabBarViewDataSource, DocumentOpenHelperDelegate, OakTextViewDelegate>
{
OBJC_WATCH_LEAKS(DocumentController);

View File

@@ -20,7 +20,6 @@ namespace find_tags
#import <OakAppKit/NSMenuItem Additions.h>
#import <OakAppKit/OakSubmenuController.h>
#import <OakAppKit/OakSavePanel.h>
#import <OakTextView/OakDocumentView.h>
#import <OakFoundation/OakFoundation.h>
#import <OakFoundation/NSArray Additions.h>
#import <OakFoundation/NSString Additions.h>
@@ -487,6 +486,7 @@ OAK_DEBUG_VAR(DocumentController);
layoutView.documentView = documentView;
textView = documentView.textView;
textView.delegate = self;
tabBarView.delegate = self;
tabBarView.dataSource = self;
@@ -614,6 +614,22 @@ OAK_DEBUG_VAR(DocumentController);
[self goToFileCounterpart:self];
}
// ========================
// = OakTextView Delegate =
// ========================
- (NSString*)scopeAttributes
{
if(selectedTabIndex >= documentTabs.size())
{
fprintf(stderr, "*** error: selected tab out of bounds: %zu >= %zu\n", selectedTabIndex, documentTabs.size());
return nil;
}
document::document_ptr doc = [self selectedDocument];
return doc ? [NSString stringWithCxxString:doc->path_attributes()] : nil;
}
// =============================
// = OakTabBarView Data Source =
// =============================

View File

@@ -20,6 +20,11 @@ struct buffer_refresh_callback_t;
enum folding_state_t { kFoldingNone, kFoldingTop, kFoldingCollapsed, kFoldingBottom };
@protocol OakTextViewDelegate <NSObject>
@optional
- (NSString*)scopeAttributes;
@end
PUBLIC @interface OakTextView : OakView <NSTextInput, NSTextFieldDelegate>
{
document::document_ptr document;
@@ -91,6 +96,7 @@ PUBLIC @interface OakTextView : OakView <NSTextInput, NSTextFieldDelegate>
}
- (void)setDocument:(document::document_ptr const&)aDocument;
@property (nonatomic, assign) id <OakTextViewDelegate> delegate;
@property (nonatomic, assign) theme_ptr const& theme;
@property (nonatomic, retain) NSCursor* ibeamCursor;
@property (nonatomic, retain) NSFont* font;

View File

@@ -299,6 +299,19 @@ static std::string shell_quote (std::vector<std::string> paths)
@synthesize refreshNestCount;
@synthesize liveSearchViewController, liveSearchString, liveSearchRanges;
// =================================
// = OakTextView Delegate Wrappers =
// =================================
- (NSString*)scopeAttributes
{
if([self.delegate respondsToSelector:@selector(scopeAttributes)])
return [self.delegate scopeAttributes];
return nil;
}
// =================================
- (NSImage*)imageForRanges:(ng::ranges_t const&)ranges imageRect:(NSRect*)outRect
{
NSRect srcRect = NSZeroRect, visibleRect = [self visibleRect];