Commit d7bf288c authored by Alexandre Lision's avatar Alexandre Lision Committed by Alexandre Lision

smartlist: add more contextual choices

- choose number to call
- copy number

Tuleap: #57
Change-Id: I18317154af9c50cade4ee8b749d10ac54eb77064
parent 3a6ea30c
...@@ -345,6 +345,20 @@ NSInteger const TXT_BUTTON_TAG = 500; ...@@ -345,6 +345,20 @@ NSInteger const TXT_BUTTON_TAG = 500;
} }
} }
- (void) copyNumberToPasteboard:(id) sender
{
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
[pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pasteBoard setString:[sender representedObject] forType:NSStringPboardType];
}
- (void) callNumber:(id) sender
{
Call* c = CallModel::instance().dialingCall();
c->setDialNumber(QString::fromNSString([sender representedObject]));
c << Call::Action::ACCEPT;
}
#pragma NSTextFieldDelegate #pragma NSTextFieldDelegate
- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
...@@ -411,17 +425,49 @@ NSInteger const TXT_BUTTON_TAG = 500; ...@@ -411,17 +425,49 @@ NSInteger const TXT_BUTTON_TAG = 500;
if (contactmethods.isEmpty()) if (contactmethods.isEmpty())
return nil; return nil;
auto cm = contactmethods.first(); NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@""];
if (!cm->contact() || cm->contact()->isPlaceHolder()) {
NSMenu *theMenu = [[NSMenu alloc] if (contactmethods.size() == 1
initWithTitle:@""]; && !contactmethods.first()->contact()
|| contactmethods.first()->contact()->isPlaceHolder()) {
[theMenu insertItemWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action") [theMenu insertItemWithTitle:NSLocalizedString(@"Add to contacts", @"Contextual menu action")
action:@selector(addToContact) action:@selector(addToContact)
keyEquivalent:@"a" keyEquivalent:@"a"
atIndex:0]; atIndex:theMenu.itemArray.count];
return theMenu;
} }
return nil;
NSMenu* copySubmenu = [[NSMenu alloc] init];
NSMenu* callSubmenu = [[NSMenu alloc] init];
for(auto cm : contactmethods) {
NSMenuItem* tmpCopyItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString()
action:@selector(copyNumberToPasteboard:)
keyEquivalent:@""];
[tmpCopyItem setRepresentedObject:cm->uri().toNSString()];
[copySubmenu addItem:tmpCopyItem];
NSMenuItem* tmpCallItem = [[NSMenuItem alloc] initWithTitle:cm->uri().toNSString()
action:@selector(callNumber:)
keyEquivalent:@""];
[tmpCallItem setRepresentedObject:cm->uri().toNSString()];
[callSubmenu addItem:tmpCallItem];
}
NSMenuItem* copyItems = [[NSMenuItem alloc] init];
[copyItems setTitle:NSLocalizedString(@"Copy number", @"Contextual menu action")];
[copyItems setSubmenu:copySubmenu];
NSMenuItem* callItems = [[NSMenuItem alloc] init];
[callItems setTitle:NSLocalizedString(@"Call number", @"Contextual menu action")];
[callItems setSubmenu:callSubmenu];
[theMenu insertItem:copyItems atIndex:theMenu.itemArray.count];
[theMenu insertItem:[NSMenuItem separatorItem] atIndex:theMenu.itemArray.count];
[theMenu insertItem:callItems atIndex:theMenu.itemArray.count];
return theMenu;
} }
@end @end
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