Skip to content

Commit

Permalink
probably better to copy documents in 10.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Lebel committed Apr 13, 2015
1 parent 5092a30 commit a00da40
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
17 changes: 17 additions & 0 deletions Sources/ConnectionWindow/MHConnectionWindowController.m
Expand Up @@ -215,6 +215,23 @@ - (void)windowDidLoad
[self.databaseCollectionOutlineView setDoubleAction:@selector(sidebarDoubleAction:)];
}

// REMOVE when 10.9 is not supported anymore
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
{
return [self.tabViewController.selectedTabItemViewController respondsToSelector:@selector(canPerformCopy)]
&& [(id)self.tabViewController.selectedTabItemViewController canPerformCopy];
}

// REMOVE when 10.9 is not supported anymore
- (void)copy:(id)sender
{
if ([self.tabViewController.selectedTabItemViewController respondsToSelector:@selector(canPerformCopy)]
&& [(id)self.tabViewController.selectedTabItemViewController canPerformCopy]
&& [self.tabViewController.selectedTabItemViewController respondsToSelector:@selector(performCopy)]) {
[(id)self.tabViewController.selectedTabItemViewController performCopy];
}
}

- (void)sidebarDoubleAction:(id)sender
{
[self query:sender];
Expand Down
30 changes: 13 additions & 17 deletions Sources/ConnectionWindow/MHDocumentOutlineViewController.m
Expand Up @@ -251,10 +251,17 @@ - (BOOL)canCopyDocuments
return (id)self.view.window.firstResponder == self.outlineView && self.selectedDocumentCount > 0;
}

// Code to add when 10.9 will not be supported anymore
// BEGIN-COPY-PASTE-OUTLINEVIEW
// 3 parts
/*
- (void)copyDocuments
{
if ((id)self.view.window.firstResponder == self.outlineView && self.selectedDocumentCount > 0) {
NSPasteboard *pasteboard;

pasteboard = NSPasteboard.generalPasteboard;
[pasteboard clearContents];
[self outlineView:self.outlineView writeItems:self.selectedDocuments toPasteboard:pasteboard];
}
}

- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
{
if (anItem.action == @selector(copy:)) {
Expand All @@ -265,19 +272,8 @@ - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem

- (void)copy:(id)sender
{
[self copyDocuments];
}
*/
// END

- (void)copyDocuments
{
if ((id)self.view.window.firstResponder == self.outlineView && self.selectedDocumentCount > 0) {
NSPasteboard *pasteboard;

pasteboard = NSPasteboard.generalPasteboard;
[pasteboard clearContents];
[self outlineView:self.outlineView writeItems:self.selectedDocuments toPasteboard:pasteboard];
if ([self canCopyDocuments]) {
[self copyDocuments];
}
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/ConnectionWindow/MHQueryViewController.h
Expand Up @@ -78,6 +78,9 @@
- (IBAction)segmentedControlAction:(id)sender;

- (void)jsonWindowWillClose:(id)sender;
- (BOOL)canPerformCopy;
- (void)performCopy;

@end

@interface MHQueryViewController (InsertTab)
Expand Down
30 changes: 11 additions & 19 deletions Sources/ConnectionWindow/MHQueryViewController.m
Expand Up @@ -449,37 +449,29 @@ - (void)selectBestTextField
[self.findQueryTextField.window makeFirstResponder:self.tabView.selectedTabViewItem.initialFirstResponder ];
}

- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem
// REMOVE when 10.9 is not supported anymore
- (BOOL)canPerformCopy
{
// Code to remove when 10.9 will not be supported anymore
// BEGIN-COPY-PASTE-OUTLINEVIEW
// 3 parts
if (anItem.action == @selector(copy:)) {
if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"find"]) {
return self.findDocumentOutlineViewController.canCopyDocuments;
} else if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"aggregation"]) {
return self.aggregationDocumentOutlineViewController.canCopyDocuments;
} else if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"mapreduce"]) {
return self.mrDocumentOutlineViewController.canCopyDocuments;
}
if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"find"]) {
return self.findDocumentOutlineViewController.canCopyDocuments;
} else if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"aggregation"]) {
return self.aggregationDocumentOutlineViewController.canCopyDocuments;
} else if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"mapreduce"]) {
return self.mrDocumentOutlineViewController.canCopyDocuments;
}
// END
return [self respondsToSelector:anItem.action];
return NO;
}

- (void)copy:(id)sender
// REMOVE when 10.9 is not supported anymore
- (void)performCopy
{
// Code to remove when 10.9 will not be supported anymore
// BEGIN-COPY-PASTE-OUTLINEVIEW
// 3 parts
if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"find"] && self.findDocumentOutlineViewController.canCopyDocuments) {
[self.findDocumentOutlineViewController copyDocuments];
} else if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"aggregation"] && self.aggregationDocumentOutlineViewController.canCopyDocuments) {
[self.aggregationDocumentOutlineViewController copyDocuments];
} else if ([[self.tabView selectedTabViewItem].identifier isEqualToString:@"mapreduce"] && self.mrDocumentOutlineViewController.canCopyDocuments) {
[self.mrDocumentOutlineViewController copyDocuments];
}
// END
}

@end
Expand Down
12 changes: 12 additions & 0 deletions Sources/ConnectionWindow/MHStatusViewController.m
Expand Up @@ -120,4 +120,16 @@ - (MODQuery *)showCollectionStatusWithCollectionItem:(MHCollectionItem *)collect
return result;
}

// REMOVE when 10.9 is not supported anymore
- (BOOL)canPerformCopy
{
return self.documentOutlineViewController.canCopyDocuments;
}

// REMOVE when 10.9 is not supported anymore
- (void)performCopy
{
[self.documentOutlineViewController copyDocuments];
}

@end

0 comments on commit a00da40

Please sign in to comment.