Smart View: contextual menu for not selected row

Contextual menu item - "add contact" works only when row is selected.
This patch change it and now contact could be added regardless of row
selection.

Change-Id: I1f0ec195c478faf46de031c8b4ac38a0469116ba
Reviewed-by: Anthony LĂ©onard <anthony.leonard@savoirfairelinux.com>
diff --git a/src/HistoryVC.mm b/src/HistoryVC.mm
index 5fae480..514a389 100644
--- a/src/HistoryVC.mm
+++ b/src/HistoryVC.mm
@@ -230,10 +230,12 @@
             if (!contactmethod->contact() || contactmethod->contact()->isPlaceHolder()) {
                 NSMenu *theMenu = [[NSMenu alloc]
                                    initWithTitle:@""];
-                [theMenu insertItemWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action")
-                                      action:@selector(addToContact)
-                               keyEquivalent:@"a"
-                                     atIndex:0];
+                NSMenuItem* addContactItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action")
+                                                                        action:@selector(addContactForRow:)
+                                                                 keyEquivalent:@""];
+
+                [addContactItem setRepresentedObject:item];
+                [theMenu addItem:addContactItem];
                 return theMenu;
             }
         }
@@ -272,6 +274,16 @@
     }
 }
 
+- (void) addContactForRow:(id) sender
+{
+    NSInteger row = [historyView rowForItem:[sender representedObject]];
+    if(row < 0) {
+        return;
+    }
+    [historyView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
+    [self addToContact];
+}
+
 #pragma mark - NSPopOverDelegate
 
 - (void)popoverDidClose:(NSNotification *)notification