Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Added autocomplete to client combobox (mac), closes #1962
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrekV committed Feb 1, 2018
1 parent 614628f commit fe946e3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
78 changes: 57 additions & 21 deletions src/ui/osx/TogglDesktop/TimeEntryEditViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,7 @@ - (void)displayClientSelect:(NSMutableArray *)clients
{
self.fullClientList = clients;
self.workspaceClientList = [self findWorkspaceClientList];
}

self.clientSelect.usesDataSource = YES;
if (self.clientSelect.dataSource == nil)
{
self.clientSelect.dataSource = self;
self.filteredClients = [NSMutableArray arrayWithArray:self.workspaceClientList];
}
[self.clientSelect reloadData];
}
Expand Down Expand Up @@ -925,7 +920,7 @@ - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
if (self.clientSelect == aComboBox)
{
return [self.workspaceClientList count];
return [self.filteredClients count];
}
NSAssert(false, @"Invalid combo box");
return 0;
Expand All @@ -935,11 +930,11 @@ - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)row
{
if (self.clientSelect == aComboBox)
{
if (row >= self.workspaceClientList.count)
if (row >= self.filteredClients.count)
{
return nil;
}
ViewItem *client = [self.workspaceClientList objectAtIndex:row];
ViewItem *client = [self.filteredClients objectAtIndex:row];
return client.Name;
}

Expand All @@ -961,20 +956,41 @@ - (NSUInteger)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSStr
}
return NSNotFound;
}
if (self.workspaceSelect == aComboBox)

NSAssert(false, @"Invalid combo box");
return NSNotFound;
}

/*
* - (void)comboBoxWillPopUp:(NSNotification *)notification
* {
* [self resultsInComboForString:((NSComboBox *)[notification object]).stringValue];
* }
*/

- (NSArray *)resultsInComboForString:(NSString *)string
{
[self.filteredClients removeAllObjects];

if (string.length == 0 || [string isEqualToString:@""] || [string isEqualToString:@" "])
{
for (int i = 0; i < self.workspaceList.count; i++)
[self.filteredClients addObjectsFromArray:self.workspaceClientList];
}
else
{
for (int i = 0; i < self.workspaceClientList.count; i++)
{
ViewItem *workspace = [self.workspaceList objectAtIndex:i];
if ([workspace.Name isEqualToString:aString])
ViewItem *client = self.workspaceClientList[i];
if ([client.Name rangeOfString:string options:NSCaseInsensitiveSearch].location != NSNotFound)
{
return i;
[self.filteredClients addObject:self.workspaceClientList[i]];
}
}
return NSNotFound;
}
NSAssert(false, @"Invalid combo box");
return NSNotFound;

[self.clientSelect reloadData];

return self.filteredClients;
}

- (void)controlTextDidEndEditing:(NSNotification *)aNotification
Expand All @@ -988,13 +1004,25 @@ - (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
// If enter was pressed then close editpopup
if ([[[aNotification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement &&
(![[aNotification object] isKindOfClass:[NSCustomComboBox class]] ||
((![[aNotification object] isKindOfClass:[NSCustomComboBox class]] && ![[aNotification object] isKindOfClass:[NSComboBox class]] ) ||
![[aNotification object] isExpanded]))
{
[self closeEdit];
}

if ([[aNotification object] isKindOfClass:[NSComboBox class]])
{
NSCustomComboBox *comboBox = [aNotification object];
// Reset client if entered text doesn't match any clients
if (comboBox == self.clientSelect && !self.filteredClients.count)
{
[self workspaceSelectChanged:nil];
}
}
return;
}


[self applyTags];
}

Expand Down Expand Up @@ -1023,10 +1051,17 @@ - (void)controlTextDidChange:(NSNotification *)aNotification
{
dataSource = self.descriptionComboboxDataSource;
}
if (comboBox == self.clientSelect)
{
[self resultsInComboForString:comboBox.stringValue];
}

[dataSource setFilter:filter];
if (dataSource != nil)
{
[dataSource setFilter:filter];
}

if (!filter || ![filter length] || !dataSource.count)
if (!filter || ![filter length] || (dataSource != nil && !dataSource.count))
{
if ([comboBox isExpanded] == YES)
{
Expand Down Expand Up @@ -1071,8 +1106,9 @@ - (IBAction)workspaceSelectChanged:(id)sender
NSLog(@"workspaceSelectChanged");
// Changing workspace should render the clients
// of the selected workspace in the client select combobox.
self.clientSelect.stringValue = @"";
self.workspaceClientList = [self findWorkspaceClientList];
self.filteredClients = [NSMutableArray arrayWithArray:self.workspaceClientList];
self.clientSelect.stringValue = @"";
}

- (IBAction)clientSelectChanged:(id)sender
Expand Down
3 changes: 2 additions & 1 deletion src/ui/osx/TogglDesktop/TimeEntryEditViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@
</textField>
<comboBox verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Kdc-c6-b4n" userLabel="Client Combo Box">
<rect key="frame" x="118" y="26" width="200" height="26"/>
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="" drawsBackground="YES" usesDataSource="YES" numberOfVisibleItems="10" id="kia-Yb-YgV">
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="" drawsBackground="YES" completes="NO" usesDataSource="YES" numberOfVisibleItems="10" id="kia-Yb-YgV">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</comboBoxCell>
<connections>
<action selector="clientSelectChanged:" target="-2" id="ZbN-uM-M6d"/>
<outlet property="dataSource" destination="-2" id="Xh6-Xt-IpP"/>
<outlet property="delegate" destination="-2" id="FtJ-G7-COO"/>
<outlet property="nextKeyView" destination="sRN-Rb-j5x" id="T35-U5-0Gm"/>
</connections>
Expand Down

0 comments on commit fe946e3

Please sign in to comment.