Skip to content

Commit

Permalink
fix profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Nov 18, 2014
1 parent 4afc19b commit b7586da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion AppProxyCap
6 changes: 6 additions & 0 deletions ShadowsocksX/ProfileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ + (Configuration *)configuration {
}

+ (void)saveConfiguration:(Configuration *)configuration {
if (configuration.profiles.count == 0) {
configuration.current = -1;
}
if (configuration.current != -1 && configuration.current >= configuration.profiles.count) {
configuration.current = 0;
}
[[NSUserDefaults standardUserDefaults] setObject:[configuration JSONData] forKey:CONFIG_DATA_KEY];
[ProfileManager reloadShadowsocksRunner];
}
Expand Down
24 changes: 14 additions & 10 deletions ShadowsocksX/SWBConfigWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row {
return YES;
}
if (row >= 0 && row < configuration.profiles.count) {
return [self validateCurrentProfile];
if ([self validateCurrentProfile]) {
[self saveCurrentProfile];
} else {
return NO;
}
}
// always allow selection to no selection
return YES;
}

- (void)tableViewSelectionIsChanging:(NSNotification *)notification {
if (self.tableView.selectedRow >= 0) {
[self saveCurrentProfile];
}
}

- (void)tableViewSelectionDidChange:(NSNotification *)notification {
if (self.tableView.selectedRow >= 0) {
[self loadCurrentProfile];
Expand Down Expand Up @@ -116,9 +114,14 @@ - (IBAction)remove:(id)sender {
[((NSMutableArray *) configuration.profiles) removeObjectAtIndex:selection];
[self.tableView reloadData];
[self updateSettingsBoxVisible:self];
}
if (configuration.profiles.count > 0) {
[self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:(configuration.profiles.count - 1)] byExtendingSelection:NO];
if (configuration.profiles.count > 0) {
[self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:(configuration.profiles.count - 1)] byExtendingSelection:NO];
}
[self loadCurrentProfile];
if (configuration.current > selection) {
// select the original profile
configuration.current = configuration.current - 1;
}
}
}

Expand Down Expand Up @@ -196,6 +199,7 @@ - (IBAction)OK:(id)sender {
if ([self saveCurrentProfile]) {
[self saveSettings];
[ShadowsocksRunner reloadConfig];
[self.delegate configurationDidChange];
[self.window performClose:self];
} else {
[self shakeWindow];
Expand Down

0 comments on commit b7586da

Please # to comment.