Commit 12946a72 authored by Alexandre Lision's avatar Alexandre Lision Committed by Guillaume Roguez

context menu: fix out of bound exception

index path was not calculated properly by the RingOutlineView

Change-Id: Idea0e90095a91b7737030cb201573d38024d5a0b
Tuleap: #447
parent 4baba4ca
......@@ -216,23 +216,26 @@ NSInteger const PHOTO_TAG = 400;
#pragma mark - ContextMenuDelegate
- (NSMenu*) contextualMenuForIndex:(NSIndexPath*) path
- (NSMenu*) contextualMenuForIndex:(NSTreeNode*) item
{
if([[treeController selectedNodes] count] > 0) {
QModelIndex qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
const auto& var = qIdx.data(static_cast<int>(Call::Role::Object));
if (qIdx.parent().isValid() && var.isValid()) {
if (auto call = var.value<Call *>()) {
auto contactmethod = call->peerContactMethod();
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];
return theMenu;
}
QModelIndex qIdx = [treeController toQIdx:item];
if (!qIdx.isValid()) {
return nil;
}
const auto& var = qIdx.data(static_cast<int>(Call::Role::Object));
if (qIdx.parent().isValid() && var.isValid()) {
if (auto call = var.value<Call *>()) {
auto contactmethod = call->peerContactMethod();
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];
return theMenu;
}
}
}
......
......@@ -397,9 +397,14 @@ NSInteger const TXT_BUTTON_TAG = 500;
#pragma mark - ContextMenuDelegate
- (NSMenu*) contextualMenuForIndex:(NSIndexPath*) path
- (NSMenu*) contextualMenuForIndex:(NSTreeNode*) item
{
auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
auto qIdx = [treeController toQIdx:item];
if (!qIdx.isValid()) {
return nil;
}
auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx);
auto contactmethods = RecentModel::instance().getContactMethods(originIdx);
if (contactmethods.isEmpty())
......
......@@ -24,7 +24,7 @@
@required
- (NSMenu*) contextualMenuForIndex:(NSIndexPath*) path;
- (NSMenu*) contextualMenuForIndex:(NSTreeNode*) path;
@end
......
......@@ -27,11 +27,8 @@
{
NSPoint pt = [self convertPoint:[evt locationInWindow] fromView:nil];
int rowIdx = [self rowAtPoint:pt];
int colIdx = [self columnAtPoint:pt];
if (self.contextMenuDelegate && rowIdx >= 0 && colIdx >= 0) {
NSUInteger indexes[2] = {static_cast<NSUInteger>(rowIdx), static_cast<NSUInteger>(colIdx)};
NSIndexPath* path = [NSIndexPath indexPathWithIndexes:indexes length:2];
return [self.contextMenuDelegate contextualMenuForIndex:path];
if (self.contextMenuDelegate && rowIdx >= 0) {
return [self.contextMenuDelegate contextualMenuForIndex:[self itemAtRow:rowIdx]];
}
return nil;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment