Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "base/mac_util.h" | 7 #import "base/mac_util.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h" | 10 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 [iconImages_ setCount:count]; | 62 [iconImages_ setCount:count]; |
| 63 [controller_ modelChanged]; | 63 [controller_ modelChanged]; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void KeywordEditorModelObserver::OnItemsChanged(int start, int length) { | 66 void KeywordEditorModelObserver::OnItemsChanged(int start, int length) { |
| 67 InvalidateIconCache(start, length); | 67 InvalidateIconCache(start, length); |
| 68 [controller_ modelChanged]; | 68 [controller_ modelChanged]; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void KeywordEditorModelObserver::OnItemsAdded(int start, int length) { | 71 void KeywordEditorModelObserver::OnItemsAdded(int start, int length) { |
| 72 DCHECK_LE(start, static_cast<int>([iconImages_ count])); | 72 const NSUInteger count([iconImages_ count]); |
| 73 DCHECK_LE(start, static_cast<int>(count)); | |
| 74 [iconImages_ setCount:count + length]; | |
|
Scott Hess - ex-Googler
2009/10/09 02:20:43
This will add length items to iconImages_ and the
pink (ping after 24hrs)
2009/10/09 14:50:38
i don't follow why you need to do this.
Scott Hess - ex-Googler
2009/10/09 14:54:16
-[NSPointerArray insertPointer:atIndex:] requires
| |
| 73 for (int i = 0; i < length; ++i) { | 75 for (int i = 0; i < length; ++i) { |
| 74 [iconImages_ insertPointer:NULL atIndex:start]; // Values slide down. | 76 [iconImages_ insertPointer:NULL atIndex:start]; // Values slide down. |
| 75 } | 77 } |
| 76 [controller_ modelChanged]; | 78 [controller_ modelChanged]; |
| 77 } | 79 } |
| 78 | 80 |
| 79 void KeywordEditorModelObserver::OnItemsRemoved(int start, int length) { | 81 void KeywordEditorModelObserver::OnItemsRemoved(int start, int length) { |
| 80 DCHECK_LE(start + length, static_cast<int>([iconImages_ count])); | 82 DCHECK_LE(start + length, static_cast<int>([iconImages_ count])); |
| 81 for (int i = 0; i < length; ++i) { | 83 for (int i = 0; i < length; ++i) { |
| 82 [iconImages_ removePointerAtIndex:start]; // Values slide up. | 84 [iconImages_ removePointerAtIndex:start]; // Values slide up. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 observer_.reset(new KeywordEditorModelObserver(self)); | 123 observer_.reset(new KeywordEditorModelObserver(self)); |
| 122 controller_->table_model()->SetObserver(observer_.get()); | 124 controller_->table_model()->SetObserver(observer_.get()); |
| 123 controller_->url_model()->AddObserver(observer_.get()); | 125 controller_->url_model()->AddObserver(observer_.get()); |
| 124 } | 126 } |
| 125 return self; | 127 return self; |
| 126 } | 128 } |
| 127 | 129 |
| 128 - (void)dealloc { | 130 - (void)dealloc { |
| 129 controller_->table_model()->SetObserver(NULL); | 131 controller_->table_model()->SetObserver(NULL); |
| 130 controller_->url_model()->RemoveObserver(observer_.get()); | 132 controller_->url_model()->RemoveObserver(observer_.get()); |
| 133 [tableView_ setTarget:nil]; | |
|
Scott Hess - ex-Googler
2009/10/09 02:20:43
If you're going to clear target, clear dataSource,
| |
| 134 observer_.reset(); | |
| 131 [super dealloc]; | 135 [super dealloc]; |
| 132 } | 136 } |
| 133 | 137 |
| 134 - (void)awakeFromNib { | 138 - (void)awakeFromNib { |
| 135 // Make sure the button fits its label, but keep it the same height as the | 139 // Make sure the button fits its label, but keep it the same height as the |
| 136 // other two buttons. | 140 // other two buttons. |
| 137 [GTMUILocalizerAndLayoutTweaker sizeToFitView:makeDefaultButton_]; | 141 [GTMUILocalizerAndLayoutTweaker sizeToFitView:makeDefaultButton_]; |
| 138 NSSize size = [makeDefaultButton_ frame].size; | 142 NSSize size = [makeDefaultButton_ frame].size; |
| 139 size.height = NSHeight([addButton_ frame]); | 143 size.height = NSHeight([addButton_ frame]); |
| 140 [makeDefaultButton_ setFrameSize:size]; | 144 [makeDefaultButton_ setFrameSize:size]; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 160 // The last page info window that was moved will determine the location of the | 164 // The last page info window that was moved will determine the location of the |
| 161 // next new one. | 165 // next new one. |
| 162 - (void)windowDidMove:(NSNotification*)notif { | 166 - (void)windowDidMove:(NSNotification*)notif { |
| 163 if (g_browser_process && g_browser_process->local_state()) { | 167 if (g_browser_process && g_browser_process->local_state()) { |
| 164 NSWindow* window = [self window]; | 168 NSWindow* window = [self window]; |
| 165 [window saveWindowPositionToPrefs:g_browser_process->local_state() | 169 [window saveWindowPositionToPrefs:g_browser_process->local_state() |
| 166 withPath:prefs::kKeywordEditorWindowPlacement]; | 170 withPath:prefs::kKeywordEditorWindowPlacement]; |
| 167 } | 171 } |
| 168 } | 172 } |
| 169 | 173 |
| 170 - (void)modelChanged { | 174 - (void)modelChanged { |
|
Scott Hess - ex-Googler
2009/10/09 14:54:16
To help catch out-of-sync issues (which is what ha
| |
| 171 [tableView_ reloadData]; | 175 [tableView_ reloadData]; |
| 176 [self adjustEditingButtons]; | |
| 172 } | 177 } |
| 173 | 178 |
| 174 - (KeywordEditorController*)controller { | 179 - (KeywordEditorController*)controller { |
| 175 return controller_.get(); | 180 return controller_.get(); |
| 176 } | 181 } |
| 177 | 182 |
| 178 - (void)sheetDidEnd:(NSWindow*)sheet | 183 - (void)sheetDidEnd:(NSWindow*)sheet |
| 179 returnCode:(NSInteger)code | 184 returnCode:(NSInteger)code |
| 180 context:(void*)context { | 185 context:(void*)context { |
| 181 [sheet orderOut:self]; | 186 [sheet orderOut:self]; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 if ([selection count] != 1) { | 319 if ([selection count] != 1) { |
| 315 [makeDefaultButton_ setEnabled:NO]; | 320 [makeDefaultButton_ setEnabled:NO]; |
| 316 } else { | 321 } else { |
| 317 const TemplateURL& url = | 322 const TemplateURL& url = |
| 318 controller_->table_model()->GetTemplateURL([selection firstIndex]); | 323 controller_->table_model()->GetTemplateURL([selection firstIndex]); |
| 319 [makeDefaultButton_ setEnabled:controller_->CanMakeDefault(&url)]; | 324 [makeDefaultButton_ setEnabled:controller_->CanMakeDefault(&url)]; |
| 320 } | 325 } |
| 321 } | 326 } |
| 322 | 327 |
| 323 @end | 328 @end |
| OLD | NEW |