Skip to content

Commit

Permalink
close #3: Merge branch 'issue/open-tab-3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tae Won Ha committed May 17, 2014
2 parents d362195 + 2a3a25d commit 221516e
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 24 deletions.
12 changes: 9 additions & 3 deletions VimR/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13C1021" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies>
Expand Down Expand Up @@ -81,11 +81,17 @@
<action selector="newTab:" target="-1" id="tf3-kd-LHX"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="39y-4Z-95L"/>
<menuItem title="Open…" keyEquivalent="o" id="72">
<connections>
<action selector="openDocument:" target="-1" id="374"/>
</connections>
</menuItem>
<menuItem title="Open in Tab…" keyEquivalent="T" id="IVZ-fS-c6G">
<connections>
<action selector="openDocumentInTab:" target="-1" id="3Wl-WW-K7l"/>
</connections>
</menuItem>
<menuItem title="Open Quickly…" keyEquivalent="O" id="Vim-gL-ViA">
<connections>
<action selector="openQuickly:" target="-1" id="dHw-5P-kf4"/>
Expand Down Expand Up @@ -491,7 +497,7 @@
<rect key="frame" x="1" y="1" width="0.0" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="37" horizontal="NO" id="q4w-GG-aqb">
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="q4w-GG-aqb">
<rect key="frame" x="-15" y="17" width="16" height="0.0"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand All @@ -505,7 +511,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" pullsDown="YES" selectedItem="bxY-vW-RK2" id="7o7-2J-1ip">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="tlq-VT-5ZL">
<items>
<menuItem title="Item 1" state="on" hidden="YES" id="bxY-vW-RK2"/>
Expand Down
1 change: 1 addition & 0 deletions VimR/VRAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- (IBAction)newDocument:(id)sender;
- (IBAction)newTab:(id)sender;
- (IBAction)openDocument:(id)sender;
- (IBAction)openDocumentInTab:(id)sender;
- (IBAction)showHelp:(id)sender;

#pragma mark NSObject
Expand Down
28 changes: 23 additions & 5 deletions VimR/VRAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "VRWorkspace.h"
#import "VROpenQuicklyWindowController.h"
#import "VRDefaultLogSetting.h"
#import "VRMainWindow.h"


static NSString *const qVimRHelpUrl = @"http://vimdoc.sourceforge.net/htmldoc/";
Expand Down Expand Up @@ -46,16 +47,33 @@ - (IBAction)newTab:(id)sender {
}

- (IBAction)openDocument:(id)sender {
NSArray *urls = [self urlsFromOpenPanel];

DDLogDebug(@"opening %@", urls);
[self application:self.application openFiles:urls];
}

- (NSArray *)urlsFromOpenPanel {
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
openPanel.allowsMultipleSelection = YES;

if ([openPanel runModal] != NSOKButton) {
DDLogDebug(@"no files selected");
return;
return nil;
}

DDLogDebug(@"opening %@", openPanel.URLs);
[self application:self.application openFiles:openPanel.URLs];
return openPanel.URLs;
}

- (IBAction)openDocumentInTab:(id)sender {
NSWindow *keyWindow = _application.keyWindow;
if (![keyWindow isKindOfClass:[VRMainWindow class]]) {
return;
}

NSArray *urls = [self urlsFromOpenPanel];
VRMainWindowController *controller = (VRMainWindowController *) keyWindow.windowController;
[controller.workspace openFilesWithUrls:urls];
}

- (IBAction)showHelp:(id)sender {
Expand Down Expand Up @@ -97,7 +115,7 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames {
*/

if ([filenames[0] isKindOfClass:[NSURL class]]) {
[self.workspaceController openFiles:filenames];
[self.workspaceController openFilesInNewWorkspace:filenames];
return;
}

Expand All @@ -106,7 +124,7 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames {
[urls addObject:[[NSURL alloc] initFileURLWithPath:filename]];
}

[self.workspaceController openFiles:urls];
[self.workspaceController openFilesInNewWorkspace:urls];
}

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
Expand Down
2 changes: 1 addition & 1 deletion VimR/VRFileBrowserView.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ - (void)fileOutlineViewDoubleClicked:(id)sender {
id clickedItem = [_fileOutlineView itemAtRow:_fileOutlineView.clickedRow];

if (![_fileItemManager isItemDir:clickedItem]) {
[(VRMainWindowController *) self.window.windowController openFileWithUrl:[_fileItemManager urlForItem:clickedItem]];
[(VRMainWindowController *) self.window.windowController openFilesWithUrls:@[[_fileItemManager urlForItem:clickedItem]]];
return;
}

Expand Down
2 changes: 1 addition & 1 deletion VimR/VRFileItemManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ - (void)unregisterUrl:(NSURL *)url {
@synchronized (self) {
VRCachedFileItemRecord *record = _url2CacheRecord[url];
if (!record) {
DDLogWarn(@"%@ was not registered");
DDLogWarn(@"%@ was not registered", url);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion VimR/VRMainWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- (void)updateWorkingDirectory;
- (void)openFilesWithArgs:(NSDictionary *)args;
- (void)cleanUpAndClose;
- (void)openFileWithUrl:(NSURL *)url;
- (void)openFilesWithUrls:(NSArray *)url;

#pragma mark IBActions
- (IBAction)newTab:(id)sender;
Expand Down
27 changes: 27 additions & 0 deletions VimR/VRMainWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "VRDefaultLogSetting.h"
#import "VRWorkspaceView.h"
#import "VRFileBrowserView.h"
#import "NSArray+VR.h"


#define CONSTRAINT(fmt, ...) [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat: fmt, ##__VA_ARGS__] options:0 metrics:nil views:views]];
Expand Down Expand Up @@ -78,6 +79,32 @@ - (void)openFileWithUrl:(NSURL *)url {
if (!alreadyOpened) {
[_vimController sendMessage:OpenWithArgumentsMsgID data:[self vimArgsFromFileUrls:@[url]].dictionaryAsData];
}
}

- (void)openFilesWithUrls:(NSArray *)urls {
NSArray *tabs = _vimController.tabs;
if (urls.count == 1) {
[self openFileWithUrl:urls[0]];

[self.window makeFirstResponder:_vimView.textView];
return;
}

NSMutableArray *urlsToOpen = [[NSMutableArray alloc] initWithArray:urls];

for (NSURL *url in urls) {
for (MMTabPage *tab in tabs) {
if ([tab.buffer.fileName isEqualToString:url.path]) {
[urlsToOpen removeObject:url];
}
}
}

if (urlsToOpen.isEmpty) {
[self openFileWithUrl:urlsToOpen.lastObject];
} else {
[_vimController sendMessage:OpenWithArgumentsMsgID data:[self vimArgsFromFileUrls:urlsToOpen].dictionaryAsData];
}

[self.window makeFirstResponder:_vimView.textView];
}
Expand Down
2 changes: 1 addition & 1 deletion VimR/VROpenQuicklyWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBy
if (selector == @selector(insertNewline:)) {
@synchronized (_filteredFileItems) {
VRScoredPath *scoredPath = _filteredFileItems[(NSUInteger) _fileItemTableView.selectedRow];
[_targetWindowController.workspace openFileWithUrl:[NSURL fileURLWithPath:scoredPath.path]];
[_targetWindowController.workspace openFilesWithUrls:@[[NSURL fileURLWithPath:scoredPath.path]]];
[self reset];
return YES;
}
Expand Down
2 changes: 1 addition & 1 deletion VimR/VRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ OBJC_EXTERN inline double measure_time(dispatch_block_t block);
OBJC_EXTERN inline void dispatch_to_main_thread(dispatch_block_t block);
OBJC_EXTERN inline void dispatch_to_global_queue(dispatch_block_t block);
OBJC_EXTERN inline void dispatch_loop(size_t count, void (^block)(size_t));
OBJC_EXTERN NSURL *common_parent_url(NSArray *fileUrls);
OBJC_EXTERN inline NSURL *common_parent_url(NSArray *fileUrls);
OBJC_EXTERN inline NSValue *vsize(CGSize size);
OBJC_EXTERN inline NSValue *vrect(CGRect rect);
OBJC_EXTERN inline NSValue *vpoint(CGPoint point);
2 changes: 1 addition & 1 deletion VimR/VRWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@property (copy) NSURL *workingDirectory;

#pragma mark Public
- (void)openFileWithUrl:(NSURL *)url;
- (void)openFilesWithUrls:(NSArray *)url;
- (BOOL)hasModifiedBuffer;
- (void)setUpWithVimController:(MMVimController *)vimController;
- (void)setUpInitialBuffers;
Expand Down
4 changes: 2 additions & 2 deletions VimR/VRWorkspace.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ @interface VRWorkspace ()
@implementation VRWorkspace

#pragma mark Public
- (void)openFileWithUrl:(NSURL *)url {
[_mainWindowController openFileWithUrl:url];
- (void)openFilesWithUrls:(NSArray *)urls {
[_mainWindowController openFilesWithUrls:urls];
}

- (BOOL)hasModifiedBuffer {
Expand Down
2 changes: 1 addition & 1 deletion VimR/VRWorkspaceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern NSString *const qVimArgOpenFilesLayout;

#pragma mark Public
- (void)newWorkspace;
- (void)openFiles:(NSArray *)fileUrls;
- (void)openFilesInNewWorkspace:(NSArray *)fileUrls;
- (void)cleanUp;

#pragma mark NSObject
Expand Down
2 changes: 1 addition & 1 deletion VimR/VRWorkspaceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)newWorkspace {
[self createNewVimControllerWithWorkingDir:[[NSURL alloc] initFileURLWithPath:NSHomeDirectory()] args:nil];
}

- (void)openFiles:(NSArray *)fileUrls {
- (void)openFilesInNewWorkspace:(NSArray *)fileUrls {
NSDictionary *args = [self vimArgsFromFileUrls:fileUrls];
NSURL *commonParentDir = common_parent_url(fileUrls);

Expand Down
8 changes: 4 additions & 4 deletions VimRTests/VRAppDelegateTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void)testOpenDocument {

[appDelegate openDocument:nil];
[verify(openPanel) setAllowsMultipleSelection:YES];
[verify(workspaceController) openFiles:@[
[verify(workspaceController) openFilesInNewWorkspace:@[
[NSURL fileURLWithPath:@"/tmp"],
[NSURL fileURLWithPath:@"/usr"]
]];
Expand All @@ -88,7 +88,7 @@ - (void)testOpenDocumentCancelled {

[appDelegate openDocument:nil];
[verify(openPanel) setAllowsMultipleSelection:YES];
[verifyCount(workspaceController, never()) openFiles:anything()];
[verifyCount(workspaceController, never()) openFilesInNewWorkspace:anything()];
}

- (void)testApplicationOpenUntitledFile {
Expand All @@ -98,15 +98,15 @@ - (void)testApplicationOpenUntitledFile {

- (void)testAppliationOpenFile {
[appDelegate application:nil openFile:@"/tmp"];
[verify(workspaceController) openFiles:@[
[verify(workspaceController) openFilesInNewWorkspace:@[
[NSURL fileURLWithPath:@"/tmp"],
]];
}

- (void)testAppliationOpenFiles {
NSArray *filenames = @[@"/tmp", @"/usr"];
[appDelegate application:nil openFiles:filenames];
[verify(workspaceController) openFiles:@[
[verify(workspaceController) openFilesInNewWorkspace:@[
[NSURL fileURLWithPath:@"/tmp"],
[NSURL fileURLWithPath:@"/usr"]
]];
Expand Down
4 changes: 2 additions & 2 deletions VimRTests/VRWorkspaceControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (void)testOpenFiles {
];
[given([vimManager pidOfNewVimControllerWithArgs:nil]) willReturnInt:123];

[workspaceController openFiles:urls];
[workspaceController openFilesInNewWorkspace:urls];
[verify(vimManager) pidOfNewVimControllerWithArgs:@{
qVimArgFileNamesToOpen : @[
@"/some/folder/is/1.txt",
Expand All @@ -75,7 +75,7 @@ - (void)notTestManagerVimControllerCreated {
[NSURL URLWithString:@"file:///some/folder/is/not/there/4.txt"],
];
[given([vimManager pidOfNewVimControllerWithArgs:nil]) willReturnInt:123];
[workspaceController openFiles:urls];
[workspaceController openFilesInNewWorkspace:urls];

[workspaceController manager:vimManager vimControllerCreated:vimController];

Expand Down

0 comments on commit 221516e

Please sign in to comment.