| 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/singleton.h" | 8 #include "base/singleton.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h" | 11 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h" |
| 12 #import "chrome/browser/cocoa/nswindow_local_state.h" | |
| 13 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" | 12 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" |
| 13 #import "chrome/browser/cocoa/window_size_autosaver.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/search_engines/template_url_table_model.h" | 15 #include "chrome/browser/search_engines/template_url_table_model.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/pref_service.h" | 17 #include "chrome/common/pref_service.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "skia/ext/skia_utils_mac.h" | 19 #include "skia/ext/skia_utils_mac.h" |
| 20 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 20 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 21 | 21 |
| 22 @interface KeywordEditorCocoaController (Private) | 22 @interface KeywordEditorCocoaController (Private) |
| 23 - (void)adjustEditingButtons; | 23 - (void)adjustEditingButtons; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 NSString* nibpath = [mac_util::MainAppBundle() | 137 NSString* nibpath = [mac_util::MainAppBundle() |
| 138 pathForResource:@"KeywordEditor" | 138 pathForResource:@"KeywordEditor" |
| 139 ofType:@"nib"]; | 139 ofType:@"nib"]; |
| 140 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 140 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 141 profile_ = profile; | 141 profile_ = profile; |
| 142 controller_.reset(new KeywordEditorController(profile_)); | 142 controller_.reset(new KeywordEditorController(profile_)); |
| 143 observer_.reset(new KeywordEditorModelObserver(self)); | 143 observer_.reset(new KeywordEditorModelObserver(self)); |
| 144 controller_->table_model()->SetObserver(observer_.get()); | 144 controller_->table_model()->SetObserver(observer_.get()); |
| 145 controller_->url_model()->AddObserver(observer_.get()); | 145 controller_->url_model()->AddObserver(observer_.get()); |
| 146 groupCell_.reset([[NSTextFieldCell alloc] init]); | 146 groupCell_.reset([[NSTextFieldCell alloc] init]); |
| 147 |
| 148 if (g_browser_process && g_browser_process->local_state()) { |
| 149 sizeSaver_.reset([[WindowSizeAutosaver alloc] |
| 150 initWithWindow:[self window] |
| 151 prefService:g_browser_process->local_state() |
| 152 path:prefs::kKeywordEditorWindowPlacement |
| 153 state:kSaveWindowRect]); |
| 154 } |
| 147 } | 155 } |
| 148 return self; | 156 return self; |
| 149 } | 157 } |
| 150 | 158 |
| 151 - (void)dealloc { | 159 - (void)dealloc { |
| 152 controller_->table_model()->SetObserver(NULL); | 160 controller_->table_model()->SetObserver(NULL); |
| 153 controller_->url_model()->RemoveObserver(observer_.get()); | 161 controller_->url_model()->RemoveObserver(observer_.get()); |
| 154 [tableView_ setDataSource:nil]; | 162 [tableView_ setDataSource:nil]; |
| 155 observer_.reset(); | 163 observer_.reset(); |
| 156 [super dealloc]; | 164 [super dealloc]; |
| 157 } | 165 } |
| 158 | 166 |
| 159 - (void)awakeFromNib { | 167 - (void)awakeFromNib { |
| 160 // Make sure the button fits its label, but keep it the same height as the | 168 // Make sure the button fits its label, but keep it the same height as the |
| 161 // other two buttons. | 169 // other two buttons. |
| 162 [GTMUILocalizerAndLayoutTweaker sizeToFitView:makeDefaultButton_]; | 170 [GTMUILocalizerAndLayoutTweaker sizeToFitView:makeDefaultButton_]; |
| 163 NSSize size = [makeDefaultButton_ frame].size; | 171 NSSize size = [makeDefaultButton_ frame].size; |
| 164 size.height = NSHeight([addButton_ frame]); | 172 size.height = NSHeight([addButton_ frame]); |
| 165 [makeDefaultButton_ setFrameSize:size]; | 173 [makeDefaultButton_ setFrameSize:size]; |
| 166 | 174 |
| 167 // Restore the window position. | |
| 168 if (g_browser_process && g_browser_process->local_state()) { | |
| 169 PrefService* prefs = g_browser_process->local_state(); | |
| 170 NSWindow* window = [self window]; | |
| 171 [window restoreWindowPositionFromPrefs:prefs | |
| 172 withPath:prefs::kKeywordEditorWindowPlacement]; | |
| 173 } | |
| 174 | |
| 175 [self adjustEditingButtons]; | 175 [self adjustEditingButtons]; |
| 176 [tableView_ setDoubleAction:@selector(editKeyword:)]; | 176 [tableView_ setDoubleAction:@selector(editKeyword:)]; |
| 177 [tableView_ setTarget:self]; | 177 [tableView_ setTarget:self]; |
| 178 } | 178 } |
| 179 | 179 |
| 180 // When the window closes, clean ourselves up. | 180 // When the window closes, clean ourselves up. |
| 181 - (void)windowWillClose:(NSNotification*)notif { | 181 - (void)windowWillClose:(NSNotification*)notif { |
| 182 [self autorelease]; | 182 [self autorelease]; |
| 183 | 183 |
| 184 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); | 184 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); |
| 185 ProfileControllerMap::iterator it = map->find(profile_); | 185 ProfileControllerMap::iterator it = map->find(profile_); |
| 186 // It should not be possible for this to be missing. | 186 // It should not be possible for this to be missing. |
| 187 // TODO(shess): Except that the unit test reaches in directly. | 187 // TODO(shess): Except that the unit test reaches in directly. |
| 188 // Consider circling around and refactoring that. | 188 // Consider circling around and refactoring that. |
| 189 //DCHECK(it != map->end()); | 189 //DCHECK(it != map->end()); |
| 190 if (it != map->end()) { | 190 if (it != map->end()) { |
| 191 map->erase(it); | 191 map->erase(it); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Remeber the position of the keyword editor. | |
| 196 - (void)windowDidMove:(NSNotification*)notif { | |
| 197 if (g_browser_process && g_browser_process->local_state()) { | |
| 198 NSWindow* window = [self window]; | |
| 199 [window saveWindowPositionToPrefs:g_browser_process->local_state() | |
| 200 withPath:prefs::kKeywordEditorWindowPlacement]; | |
| 201 } | |
| 202 } | |
| 203 | |
| 204 - (void)modelChanged { | 195 - (void)modelChanged { |
| 205 [tableView_ reloadData]; | 196 [tableView_ reloadData]; |
| 206 [self adjustEditingButtons]; | 197 [self adjustEditingButtons]; |
| 207 } | 198 } |
| 208 | 199 |
| 209 - (KeywordEditorController*)controller { | 200 - (KeywordEditorController*)controller { |
| 210 return controller_.get(); | 201 return controller_.get(); |
| 211 } | 202 } |
| 212 | 203 |
| 213 - (void)sheetDidEnd:(NSWindow*)sheet | 204 - (void)sheetDidEnd:(NSWindow*)sheet |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 controller_->table_model()->last_search_engine_index() + 1; | 395 controller_->table_model()->last_search_engine_index() + 1; |
| 405 DCHECK_NE(row, otherGroupId); | 396 DCHECK_NE(row, otherGroupId); |
| 406 if (row >= otherGroupId) { | 397 if (row >= otherGroupId) { |
| 407 return row - 2; // Other group. | 398 return row - 2; // Other group. |
| 408 } else { | 399 } else { |
| 409 return row - 1; // Default group. | 400 return row - 1; // Default group. |
| 410 } | 401 } |
| 411 } | 402 } |
| 412 | 403 |
| 413 @end | 404 @end |
| OLD | NEW |