From e2150dcdbd3741a3316777d5b975bcd66fae8307 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Tue, 16 Oct 2012 15:27:36 +0300 Subject: [PATCH] [ios] Category name can be edited in Bookmarks Manager --- iphone/Maps/Bookmarks/BookmarksVC.h | 2 +- iphone/Maps/Bookmarks/BookmarksVC.mm | 61 ++++++++++++++++++++++++++-- iphone/Maps/Bookmarks/PlacePageVC.mm | 2 +- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/iphone/Maps/Bookmarks/BookmarksVC.h b/iphone/Maps/Bookmarks/BookmarksVC.h index 6fb629b6c5..0cee14a583 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.h +++ b/iphone/Maps/Bookmarks/BookmarksVC.h @@ -3,7 +3,7 @@ @class BalloonView; -@interface BookmarksVC : UITableViewController +@interface BookmarksVC : UITableViewController { LocationManager * m_locationManager; size_t m_categoryIndex; diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index 250054ffbd..195f608f67 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -9,6 +9,7 @@ #include "../../../geometry/distance_on_sphere.hpp" +#define TEXTFIELD_TAG 999 @implementation BookmarksVC @@ -60,6 +61,7 @@ UITableViewCell * cell = nil; if (indexPath.section == 0) { + // First section, contains info about current set if (indexPath.row == 0) { cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCSetNameCell"]; @@ -67,9 +69,31 @@ { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarksVCSetNameCell"] autorelease]; cell.textLabel.text = NSLocalizedString(@"name", @"Bookmarks dialog - Bookmark set cell"); - // @TODO insert text editor + cell.selectionStyle = UITableViewCellSelectionStyleNone; + // Temporary, to init font and color + cell.detailTextLabel.text = @"temp string"; + // Called to initialize frames and fonts + [cell layoutSubviews]; + CGRect const leftR = cell.textLabel.frame; + CGFloat const padding = leftR.origin.x; + CGRect r = CGRectMake(padding + leftR.size.width + padding, leftR.origin.y, + cell.contentView.frame.size.width - 3 * padding - leftR.size.width, leftR.size.height); + UITextField * f = [[[UITextField alloc] initWithFrame:r] autorelease]; + f.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + f.enablesReturnKeyAutomatically = YES; + f.returnKeyType = UIReturnKeyDone; + f.clearButtonMode = UITextFieldViewModeWhileEditing; + f.autocorrectionType = UITextAutocorrectionTypeNo; + f.textAlignment = UITextAlignmentRight; + f.textColor = cell.detailTextLabel.textColor; + f.font = [cell.detailTextLabel.font fontWithSize:[cell.detailTextLabel.font pointSize]]; + f.tag = TEXTFIELD_TAG; + f.delegate = self; + // Reset temporary font + cell.detailTextLabel.text = nil; + [cell.contentView addSubview:f]; } - cell.detailTextLabel.text = [NSString stringWithUTF8String:cat->GetName().c_str()]; + ((UITextField *)[cell.contentView viewWithTag:TEXTFIELD_TAG]).text = [NSString stringWithUTF8String:cat->GetName().c_str()]; } else { @@ -87,6 +111,7 @@ } else { + // Second section, contains bookmarks list cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCBookmarkItemCell"]; if (!cell) { @@ -281,15 +306,43 @@ [super viewWillAppear:animated]; } +- (void)renameBMCategoryIfChanged:(NSString *)newName +{ + // Update edited category name + BookmarkCategory * cat = GetFramework().GetBmCategory(m_categoryIndex); + char const * newCharName = [newName UTF8String]; + if (cat->GetName() != newCharName) + { + cat->SetName(newCharName); + cat->SaveToKMLFile(); + self.navigationController.title = newName; + } +} + - (void)viewWillDisappear:(BOOL)animated { [m_locationManager stop:self]; + // Save possibly edited set name + UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + NSString * newName = ((UITextField *)[cell.contentView viewWithTag:TEXTFIELD_TAG]).text; + [self renameBMCategoryIfChanged:newName]; [super viewWillDisappear:animated]; } -- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation +- (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation { [m_locationManager setOrientation:self.interfaceOrientation]; } -@end +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + if (textField.text.length == 0) + return YES; + + // Hide keyboard + [textField resignFirstResponder]; + [self renameBMCategoryIfChanged:textField.text]; + return NO; +} + +@end \ No newline at end of file diff --git a/iphone/Maps/Bookmarks/PlacePageVC.mm b/iphone/Maps/Bookmarks/PlacePageVC.mm index 8da111f319..d879f1146b 100644 --- a/iphone/Maps/Bookmarks/PlacePageVC.mm +++ b/iphone/Maps/Bookmarks/PlacePageVC.mm @@ -129,7 +129,7 @@ cell.textLabel.text = NSLocalizedString(@"name", @"Add bookmark dialog - bookmark name"); cell.selectionStyle = UITableViewCellSelectionStyleNone; // Temporary, to init font and color - cell.detailTextLabel.text = m_balloon.title; + cell.detailTextLabel.text = @"temp string"; // Called to initialize frames and fonts [cell layoutSubviews]; CGRect const leftR = cell.textLabel.frame;