OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/ui/bookmarks/undo_manager_wrapper.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "components/undo/bookmark_undo_service.h" |
| 10 #include "components/undo/undo_manager.h" |
| 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 12 #include "ios/chrome/browser/ui/bookmarks/undo_manager_bridge_observer.h" |
| 13 #include "ios/chrome/browser/undo/bookmark_undo_service_factory.h" |
| 14 |
| 15 @interface UndoManagerWrapper ()<UndoManagerBridgeObserver> { |
| 16 std::unique_ptr<bookmarks::UndoManagerBridge> _bridge; |
| 17 } |
| 18 @property(nonatomic, assign) UndoManager* undoManager; |
| 19 @property(nonatomic, assign) BOOL hasUndoManagerChanged; |
| 20 @end |
| 21 |
| 22 @implementation UndoManagerWrapper |
| 23 @synthesize hasUndoManagerChanged = _hasUndoManagerChanged; |
| 24 @synthesize undoManager = _undoManager; |
| 25 |
| 26 - (id)init { |
| 27 NOTREACHED(); |
| 28 return nil; |
| 29 } |
| 30 |
| 31 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
| 32 self = [super init]; |
| 33 if (self) { |
| 34 _undoManager = |
| 35 ios::BookmarkUndoServiceFactory::GetForBrowserState(browserState) |
| 36 ->undo_manager(); |
| 37 _bridge.reset(new bookmarks::UndoManagerBridge(self)); |
| 38 _undoManager->AddObserver(_bridge.get()); |
| 39 } |
| 40 return self; |
| 41 } |
| 42 |
| 43 - (void)dealloc { |
| 44 _undoManager->RemoveObserver(_bridge.get()); |
| 45 [super dealloc]; |
| 46 } |
| 47 |
| 48 #pragma mark - Public Methods |
| 49 |
| 50 - (void)startGroupingActions { |
| 51 self.undoManager->StartGroupingActions(); |
| 52 } |
| 53 |
| 54 - (void)stopGroupingActions { |
| 55 self.undoManager->EndGroupingActions(); |
| 56 } |
| 57 |
| 58 - (void)resetUndoManagerChanged { |
| 59 self.hasUndoManagerChanged = NO; |
| 60 } |
| 61 |
| 62 - (void)undo { |
| 63 self.undoManager->Undo(); |
| 64 } |
| 65 |
| 66 #pragma mark - UndoManagerBridgeObserver |
| 67 |
| 68 - (void)undoManagerChanged { |
| 69 self.hasUndoManagerChanged = YES; |
| 70 } |
| 71 |
| 72 @end |
OLD | NEW |