Commit 61db3557 authored by Alexandre Lision's avatar Alexandre Lision Committed by Alexandre Lision

smartlist: add contact creation

Same feature as in the history, possibility to link/create contacts
with ContactMethods

Tuleap: #57
Change-Id: I54061fa7b41c77aca371f9ef501400ded24286fb
parent e1cf4465
......@@ -37,18 +37,21 @@
#import "QNSTreeController.h"
#import "delegates/ImageManipulationDelegate.h"
#import "views/HoverTableRowView.h"
#import "PersonLinkerVC.h"
#import "views/RingOutlineView.h"
#import "views/ContextualTableCellView.h"
@interface SmartViewVC () <NSOutlineViewDelegate> {
@interface SmartViewVC () <NSOutlineViewDelegate, NSPopoverDelegate, ContextMenuDelegate, ContactLinkedDelegate, KeyboardShortcutDelegate> {
BOOL isShowingContacts;
QNSTreeController *treeController;
NSPopover* addToContactPopover;
//UI elements
__unsafe_unretained IBOutlet NSOutlineView *smartView;
__unsafe_unretained IBOutlet NSSearchField *searchField;
__unsafe_unretained IBOutlet NSButton *showContactsButton;
__unsafe_unretained IBOutlet NSButton *showHistoryButton;
__unsafe_unretained IBOutlet NSTabView *tabbar;
__unsafe_unretained IBOutlet RingOutlineView* smartView;
__unsafe_unretained IBOutlet NSSearchField* searchField;
__unsafe_unretained IBOutlet NSButton* showContactsButton;
__unsafe_unretained IBOutlet NSButton* showHistoryButton;
__unsafe_unretained IBOutlet NSTabView* tabbar;
}
@end
......@@ -78,6 +81,9 @@ NSInteger const TXT_BUTTON_TAG = 500;
[smartView setTarget:self];
[smartView setDoubleAction:@selector(placeCall:)];
[smartView setContextMenuDelegate:self];
[smartView setShortcutsDelegate:self];
QObject::connect(RecentModel::instance().peopleProxy(),
&QAbstractItemModel::dataChanged,
[self](const QModelIndex &topLeft, const QModelIndex &bottomRight) {
......@@ -297,6 +303,36 @@ NSInteger const TXT_BUTTON_TAG = 500;
setFilterRegExp(QRegExp(QString::fromNSString([searchField stringValue]), Qt::CaseInsensitive, QRegExp::FixedString));
}
- (void) addToContact
{
if ([treeController selectedNodes].count == 0)
return;
auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx);
auto contactmethod = RecentModel::instance().getContactMethods(originIdx);
if (contactmethod.isEmpty())
return;
if (addToContactPopover != nullptr) {
[addToContactPopover performClose:self];
addToContactPopover = NULL;
} else if (contactmethod.first()) {
auto* editorVC = [[PersonLinkerVC alloc] initWithNibName:@"PersonLinker" bundle:nil];
[editorVC setMethodToLink:contactmethod.first()];
[editorVC setContactLinkedDelegate:self];
addToContactPopover = [[NSPopover alloc] init];
[addToContactPopover setContentSize:editorVC.view.frame.size];
[addToContactPopover setContentViewController:editorVC];
[addToContactPopover setAnimates:YES];
[addToContactPopover setBehavior:NSPopoverBehaviorTransient];
[addToContactPopover setDelegate:self];
[addToContactPopover showRelativeToRect:[smartView frameOfCellAtColumn:0 row:[smartView selectedRow]]
ofView:smartView preferredEdge:NSMaxXEdge];
}
}
#pragma NSTextFieldDelegate
- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
......@@ -311,10 +347,69 @@ NSInteger const TXT_BUTTON_TAG = 500;
return NO;
}
#pragma mark - NSPopOverDelegate
- (void)popoverDidClose:(NSNotification *)notification
{
if (addToContactPopover != nullptr) {
[addToContactPopover performClose:self];
addToContactPopover = NULL;
}
}
- (void)controlTextDidChange:(NSNotification *) notification
{
RecentModel::instance().peopleProxy()->
setFilterRegExp(QRegExp(QString::fromNSString([searchField stringValue]), Qt::CaseInsensitive, QRegExp::FixedString));
}
#pragma mark - ContactLinkedDelegate
- (void)contactLinked
{
if (addToContactPopover != nullptr) {
[addToContactPopover performClose:self];
addToContactPopover = NULL;
}
}
#pragma mark - KeyboardShortcutDelegate
- (void) onAddShortcut
{
auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx);
auto contactmethods = RecentModel::instance().getContactMethods(originIdx);
if (contactmethods.isEmpty())
return;
auto contactmethod = contactmethods.first();
if (contactmethod && (!contactmethod->contact() || contactmethod->contact()->isPlaceHolder())) {
[self addToContact];
}
}
#pragma mark - ContextMenuDelegate
- (NSMenu*) contextualMenuForIndex:(NSIndexPath*) path
{
auto qIdx = [treeController toQIdx:[treeController selectedNodes][0]];
auto originIdx = RecentModel::instance().peopleProxy()->mapToSource(qIdx);
auto contactmethods = RecentModel::instance().getContactMethods(originIdx);
if (contactmethods.isEmpty())
return nil;
auto cm = contactmethods.first();
if (!cm->contact() || cm->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;
}
return nil;
}
@end
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="PersonLinkerVC">
......@@ -20,11 +20,12 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="1" width="308" height="452"/>
<rect key="frame" x="0.0" y="0.0" width="308" height="452"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8pP-Sy-Vkd">
<rect key="frame" x="18" y="415" width="184" height="22"/>
<animations/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" sendsActionOnEndEditing="YES" alignment="right" title="Contact Method" usesSingleLineMode="YES" id="a9R-r5-K3w">
<font key="font" size="18" name="HelveticaNeue-Thin"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
......@@ -35,7 +36,8 @@
<rect key="frame" x="0.0" y="-21" width="308" height="428"/>
<subviews>
<searchField wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZJY-k3-gHh">
<rect key="frame" x="30" y="406" width="249" height="22"/>
<rect key="frame" x="20" y="406" width="268" height="22"/>
<animations/>
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" sendsSearchStringImmediately="YES" id="sS1-2Z-ZWi">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
......@@ -48,6 +50,7 @@
</searchField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cfj-u3-ErF">
<rect key="frame" x="9" y="24" width="291" height="30"/>
<animations/>
<buttonCell key="cell" type="squareTextured" title="Add new contact" bezelStyle="texturedSquare" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="had-9Y-eza">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
......@@ -57,26 +60,27 @@
<outlet property="nextKeyView" destination="MFf-kv-pz3" id="ptg-Li-e6T"/>
</connections>
</button>
<scrollView fixedFrame="YES" autohidesScrollers="YES" horizontalLineScroll="42" horizontalPageScroll="10" verticalLineScroll="42" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" scrollerKnobStyle="light" translatesAutoresizingMaskIntoConstraints="NO" id="sue-LK-DlA">
<scrollView fixedFrame="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="42" horizontalPageScroll="10" verticalLineScroll="42" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" scrollerKnobStyle="light" translatesAutoresizingMaskIntoConstraints="NO" id="sue-LK-DlA">
<rect key="frame" x="0.0" y="61" width="308" height="337"/>
<clipView key="contentView" misplaced="YES" drawsBackground="NO" copiesOnScroll="NO" id="bpD-gC-mEn">
<rect key="frame" x="1" y="17" width="238" height="117"/>
<clipView key="contentView" ambiguous="YES" drawsBackground="NO" copiesOnScroll="NO" id="bpD-gC-mEn">
<rect key="frame" x="0.0" y="0.0" width="308" height="337"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="40" viewBased="YES" indentationPerLevel="16" autoresizesOutlineColumn="YES" outlineTableColumn="02n-X5-Zug" id="eKe-7i-c79">
<rect key="frame" x="0.0" y="0.0" width="303" height="0.0"/>
<rect key="frame" x="0.0" y="0.0" width="308" height="337"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" white="0.66666666669999997" alpha="0.0" colorSpace="deviceWhite"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="NameColumn" width="303" minWidth="40" maxWidth="1000" id="02n-X5-Zug">
<tableColumn identifier="NameColumn" width="305" minWidth="40" maxWidth="1000" id="02n-X5-Zug">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
<font key="font" metaFont="system"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="M4f-N4-msh" customClass="PersonCell">
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="M4f-N4-msh">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
......@@ -84,11 +88,12 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="MainCell" wantsLayer="YES" id="nIU-iD-8vh">
<rect key="frame" x="1" y="1" width="300" height="60"/>
<rect key="frame" x="1" y="1" width="305" height="60"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField wantsLayer="YES" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" tag="200" translatesAutoresizingMaskIntoConstraints="NO" id="Vix-1z-ceH">
<rect key="frame" x="60" y="20" width="219" height="23"/>
<animations/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Display Role" id="Jcn-cg-rbR">
<font key="font" size="16" name="HelveticaNeue-Light"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
......@@ -97,9 +102,11 @@
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" tag="100" translatesAutoresizingMaskIntoConstraints="NO" id="XdL-zf-7dn">
<rect key="frame" x="10" y="11" width="40" height="40"/>
<animations/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="27s-no-TQR"/>
</imageView>
</subviews>
<animations/>
<connections>
<outlet property="textField" destination="Vix-1z-ceH" id="Abp-mU-zH1"/>
</connections>
......@@ -113,21 +120,27 @@
</connections>
</outlineView>
</subviews>
<animations/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<animations/>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="4Sk-mY-PsD">
<rect key="frame" x="1" y="117.99886953830719" width="238" height="16"/>
<rect key="frame" x="1" y="117" width="238" height="16"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="awN-qf-qb2">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<rect key="frame" x="-16" y="0.0" width="16" height="0.0"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</scroller>
</scrollView>
</subviews>
<animations/>
</customView>
<comboBox verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="MFf-kv-pz3">
<rect key="frame" x="208" y="415" width="84" height="26"/>
<animations/>
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" usesDataSource="YES" numberOfVisibleItems="5" id="Msw-lx-k0J">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
......@@ -140,6 +153,7 @@
</connections>
</comboBox>
</subviews>
<animations/>
<point key="canvasLocation" x="578" y="354"/>
</customView>
<customView wantsLayer="YES" id="6M0-sm-haN">
......@@ -148,6 +162,7 @@
<subviews>
<textField verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="m4N-gI-w8E">
<rect key="frame" x="12" y="112" width="245" height="27"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="First name..." drawsBackground="YES" id="vyb-95-XaF">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
......@@ -160,6 +175,7 @@
</textField>
<textField verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="j0A-7O-Bvj">
<rect key="frame" x="12" y="75" width="245" height="27"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="Last name..." drawsBackground="YES" id="cGT-nu-sPa">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
......@@ -172,6 +188,7 @@
</textField>
<textField wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GgO-mM-nnz">
<rect key="frame" x="24" y="186" width="221" height="30"/>
<animations/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="New Contact" id="v7b-de-MVd">
<font key="font" metaFont="system" size="20"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
......@@ -180,13 +197,14 @@
</textField>
<scrollView ambiguous="YES" misplaced="YES" borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vzn-cW-Vtm">
<rect key="frame" x="26" y="146" width="217" height="32"/>
<clipView key="contentView" ambiguous="YES" misplaced="YES" drawsBackground="NO" copiesOnScroll="NO" id="2yu-GN-mus">
<rect key="frame" x="1" y="1" width="223" height="133"/>
<clipView key="contentView" ambiguous="YES" drawsBackground="NO" copiesOnScroll="NO" id="2yu-GN-mus">
<rect key="frame" x="0.0" y="0.0" width="217" height="32"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView ambiguous="YES" editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" usesFontPanel="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="TQq-By-akw">
<rect key="frame" x="0.0" y="0.0" width="223" height="133"/>
<rect key="frame" x="0.0" y="0.0" width="217" height="32"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="217" height="32"/>
<size key="maxSize" width="463" height="10000000"/>
......@@ -203,19 +221,24 @@
<size key="maxSize" width="463" height="10000000"/>
</textView>
</subviews>
<animations/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<animations/>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="XUh-Co-vZc">
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="C83-CS-odD">
<rect key="frame" x="224" y="1" width="15" height="133"/>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="C83-CS-odD">
<rect key="frame" x="-16" y="0.0" width="16" height="0.0"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</scroller>
</scrollView>
<button verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="N0T-7S-TCW">
<rect key="frame" x="12" y="38" width="245" height="30"/>
<animations/>
<buttonCell key="cell" type="squareTextured" title="Create" bezelStyle="texturedSquare" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="qZc-Z2-TpP">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
......@@ -235,6 +258,7 @@
<constraint firstItem="N0T-7S-TCW" firstAttribute="leading" secondItem="6M0-sm-haN" secondAttribute="leading" constant="12" id="xWn-BX-TdQ"/>
<constraint firstAttribute="centerX" secondItem="GgO-mM-nnz" secondAttribute="centerX" id="zLf-OH-9nF"/>
</constraints>
<animations/>
<point key="canvasLocation" x="949.5" y="317"/>
</customView>
</objects>
......
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