Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: chrome/browser/cocoa/keyword_editor_cocoa_controller.mm

Issue 207027: [Mac] Polish the search engine manager (Closed)
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h" 10 #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h"
11 #import "chrome/browser/cocoa/nswindow_local_state.h"
10 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" 12 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h"
11 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
12 #include "chrome/browser/search_engines/template_url_table_model.h" 14 #include "chrome/browser/search_engines/template_url_table_model.h"
15 #include "chrome/common/pref_names.h"
16 #include "chrome/common/pref_service.h"
13 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
14 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 18 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
15 19
16 @interface KeywordEditorCocoaController (Private) 20 @interface KeywordEditorCocoaController (Private)
17 - (void)adjustEditingButtons; 21 - (void)adjustEditingButtons;
18 - (void)editKeyword:(id)sender; 22 - (void)editKeyword:(id)sender;
19 @end 23 @end
20 24
21 // KeywordEditorModelObserver ------------------------------------------------- 25 // KeywordEditorModelObserver -------------------------------------------------
22 26
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 73 }
70 74
71 - (void)awakeFromNib { 75 - (void)awakeFromNib {
72 // Make sure the button fits its label, but keep it the same height as the 76 // Make sure the button fits its label, but keep it the same height as the
73 // other two buttons. 77 // other two buttons.
74 [GTMUILocalizerAndLayoutTweaker sizeToFitView:makeDefaultButton_]; 78 [GTMUILocalizerAndLayoutTweaker sizeToFitView:makeDefaultButton_];
75 NSSize size = [makeDefaultButton_ frame].size; 79 NSSize size = [makeDefaultButton_ frame].size;
76 size.height = NSHeight([addButton_ frame]); 80 size.height = NSHeight([addButton_ frame]);
77 [makeDefaultButton_ setFrameSize:size]; 81 [makeDefaultButton_ setFrameSize:size];
78 82
83 // Restore the window position.
84 if (g_browser_process && g_browser_process->local_state()) {
85 PrefService* prefs = g_browser_process->local_state();
86 NSWindow* window = [self window];
87 [window restoreWindowPositionFromPrefs:prefs
88 withPath:prefs::kKeywordEditorWindowPlacement];
89 }
90
79 [self adjustEditingButtons]; 91 [self adjustEditingButtons];
80 [tableView_ setDoubleAction:@selector(editKeyword:)]; 92 [tableView_ setDoubleAction:@selector(editKeyword:)];
81 [tableView_ setTarget:self]; 93 [tableView_ setTarget:self];
82 } 94 }
83 95
84 // When the window closes, clean ourselves up. 96 // When the window closes, clean ourselves up.
85 - (void)windowWillClose:(NSNotification*)notif { 97 - (void)windowWillClose:(NSNotification*)notif {
86 [self autorelease]; 98 [self autorelease];
87 } 99 }
88 100
101 // The last page info window that was moved will determine the location of the
102 // next new one.
103 - (void)windowDidMove:(NSNotification*)notif {
104 if (g_browser_process && g_browser_process->local_state()) {
105 NSWindow* window = [self window];
106 [window saveWindowPositionToPrefs:g_browser_process->local_state()
107 withPath:prefs::kKeywordEditorWindowPlacement];
108 }
109 }
110
89 - (void)modelChanged { 111 - (void)modelChanged {
90 [tableView_ reloadData]; 112 [tableView_ reloadData];
91 } 113 }
92 114
93 - (KeywordEditorController*)controller { 115 - (KeywordEditorController*)controller {
94 return controller_.get(); 116 return controller_.get();
95 } 117 }
96 118
119 - (void)sheetDidEnd:(NSWindow*)sheet
120 returnCode:(NSInteger)code
121 context:(void*)context {
122 [sheet orderOut:self];
123 }
124
97 - (IBAction)addKeyword:(id)sender { 125 - (IBAction)addKeyword:(id)sender {
98 // The controller will release itself when the window closes. 126 // The controller will release itself when the window closes.
99 EditSearchEngineCocoaController* editor = 127 EditSearchEngineCocoaController* editor =
100 [[EditSearchEngineCocoaController alloc] initWithProfile:profile_ 128 [[EditSearchEngineCocoaController alloc] initWithProfile:profile_
101 delegate:observer_.get() 129 delegate:observer_.get()
102 templateURL:NULL]; 130 templateURL:NULL];
103 [[editor window] makeKeyAndOrderFront:self]; 131 [NSApp beginSheet:[editor window]
132 modalForWindow:[self window]
133 modalDelegate:self
134 didEndSelector:@selector(sheetDidEnd:returnCode:context:)
135 contextInfo:NULL];
104 } 136 }
105 137
106 - (void)editKeyword:(id)sender { 138 - (void)editKeyword:(id)sender {
107 const NSInteger clickedRow = [tableView_ clickedRow]; 139 const NSInteger clickedRow = [tableView_ clickedRow];
108 if (clickedRow == -1) 140 if (clickedRow == -1)
109 return; 141 return;
110 const TemplateURL* url = controller_->GetTemplateURL(clickedRow); 142 const TemplateURL* url = controller_->GetTemplateURL(clickedRow);
111 // The controller will release itself when the window closes. 143 // The controller will release itself when the window closes.
112 EditSearchEngineCocoaController* editor = 144 EditSearchEngineCocoaController* editor =
113 [[EditSearchEngineCocoaController alloc] initWithProfile:profile_ 145 [[EditSearchEngineCocoaController alloc] initWithProfile:profile_
114 delegate:observer_.get() 146 delegate:observer_.get()
115 templateURL:url]; 147 templateURL:url];
116 [[editor window] makeKeyAndOrderFront:self]; 148 [NSApp beginSheet:[editor window]
149 modalForWindow:[self window]
150 modalDelegate:self
151 didEndSelector:@selector(sheetDidEnd:returnCode:context:)
152 contextInfo:NULL];
117 } 153 }
118 154
119 - (IBAction)deleteKeyword:(id)sender { 155 - (IBAction)deleteKeyword:(id)sender {
120 NSIndexSet* selection = [tableView_ selectedRowIndexes]; 156 NSIndexSet* selection = [tableView_ selectedRowIndexes];
121 DCHECK_GT([selection count], 0U); 157 DCHECK_GT([selection count], 0U);
122 NSUInteger index = [selection lastIndex]; 158 NSUInteger index = [selection lastIndex];
123 while (index != NSNotFound) { 159 while (index != NSNotFound) {
124 controller_->RemoveTemplateURL(index); 160 controller_->RemoveTemplateURL(index);
125 index = [selection indexLessThanIndex:index]; 161 index = [selection indexLessThanIndex:index];
126 } 162 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if ([selection count] != 1) { 233 if ([selection count] != 1) {
198 [makeDefaultButton_ setEnabled:NO]; 234 [makeDefaultButton_ setEnabled:NO];
199 } else { 235 } else {
200 const TemplateURL& url = 236 const TemplateURL& url =
201 controller_->table_model()->GetTemplateURL([selection firstIndex]); 237 controller_->table_model()->GetTemplateURL([selection firstIndex]);
202 [makeDefaultButton_ setEnabled:controller_->CanMakeDefault(&url)]; 238 [makeDefaultButton_ setEnabled:controller_->CanMakeDefault(&url)];
203 } 239 }
204 } 240 }
205 241
206 @end 242 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698