[ios] Added bookmarks editing

This commit is contained in:
Alex Zolotarev 2012-04-11 18:45:36 +03:00 committed by Alex Zolotarev
parent b2e91cf67e
commit 55e917601a
4 changed files with 48 additions and 20 deletions

View file

@ -8,6 +8,8 @@ class Framework;
{
Framework * m_framework;
UITableView * m_table;
// Needed to change Edit/Cancel buttons
UINavigationItem * m_navItem;
}
- (id)initWithFramework:(Framework *)f;

View file

@ -7,6 +7,20 @@
@implementation BookmarksVC
- (void)onCancelEdit
{
[self setEditing:NO animated:NO];
[m_table setEditing:NO animated:NO];
m_navItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(onEdit)] autorelease];
}
- (void)onEdit
{
[self setEditing:YES animated:YES];
[m_table setEditing:YES animated:YES];
m_navItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancelEdit)] autorelease];
}
- (id)initWithFramework:(Framework *)f
{
if ((self = [super initWithNibName:nil bundle:nil]))
@ -21,15 +35,16 @@
UIView * parentView = [[[CustomNavigationView alloc] init] autorelease];
parentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
UINavigationBar * navBar = [[[UINavigationBar alloc] init] autorelease];
UINavigationItem * item = [[[UINavigationItem alloc] init] autorelease];
m_navItem = [[[UINavigationItem alloc] init] autorelease];
UIBarButtonItem * closeButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"Bookmarks - Close bookmarks button") style: UIBarButtonItemStyleDone
m_navItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Maps", @"Bookmarks - Close bookmarks button") style: UIBarButtonItemStyleDone
target:self action:@selector(onCloseButton:)] autorelease];
item.leftBarButtonItem = closeButton;
// Display Edit button only if table is not empty
if (m_framework->BookmarksCount())
m_navItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(onEdit)] autorelease];
[navBar pushNavigationItem:item animated:NO];
UINavigationBar * navBar = [[[UINavigationBar alloc] init] autorelease];
[navBar pushNavigationItem:m_navItem animated:NO];
[parentView addSubview:navBar];
@ -102,19 +117,17 @@
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
if (editingStyle == UITableViewCellEditingStyleDelete)
{
m_framework->RemoveBookmark(indexPath.row);
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
// else if (editingStyle == UITableViewCellEditingStyleInsert)
// {
// }
}
*/
/*
// Override to support rearranging the table view.

View file

@ -202,16 +202,28 @@ void Framework::AddBookmark(m2::PointD const & pt, string const & name)
m_bookmarks.push_back(Bookmark(pt, name));
}
void Framework::GetBookmark(size_t i, Bookmark & bm) const
void Framework::GetBookmark(size_t index, Bookmark & bm) const
{
ASSERT_LESS(i, BookmarksCount(), ());
ASSERT_LESS(index, BookmarksCount(), ());
list<Bookmark>::const_iterator it = m_bookmarks.begin();
advance(it, i); // not so fast ...
advance(it, index); // not so fast ...
bm = *it;
}
void Framework::RemoveBookmark(size_t index)
{
if (index >= m_bookmarks.size())
{
LOG(LWARNING, ("Trying to delete invalid bookmark with index", index));
return;
}
list<Bookmark>::iterator it = m_bookmarks.begin();
advance(it, index); // not so fast ...
m_bookmarks.erase(it);
}
void Framework::ClearBookmarks()
{
m_bookmarks.clear();

View file

@ -127,7 +127,8 @@ public:
void AddBookmark(m2::PointD const & pixelCoords);
void AddBookmark(m2::PointD const & pt, string const & name);
inline size_t BookmarksCount() const { return m_bookmarks.size(); }
void GetBookmark(size_t i, Bookmark & bm) const;
void GetBookmark(size_t index, Bookmark & bm) const;
void RemoveBookmark(size_t index);
void ClearBookmarks();
void LoadFromKML(ReaderPtr<Reader> const & reader);