blob: f20e15776c2af8109d76b112ffc16f99ca27d4f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h"
#import <Cocoa/Cocoa.h>
#include "base/string16.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/encoding_menu_controller.h"
#include "chrome/browser/profile.h"
namespace {
void AddSeparatorToMenu(NSMenu *parent_menu) {
NSMenuItem* separator = [NSMenuItem separatorItem];
[parent_menu addItem:separator];
}
void AppendMenuItem(NSMenu *parent_menu, int tag, NSString *title) {
NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
action:nil
keyEquivalent:@""] autorelease];
[parent_menu addItem:item];
[item setAction:@selector(commandDispatch:)];
[item setTag:tag];
}
} // namespace
// static
void EncodingMenuControllerDelegate::BuildEncodingMenu(Profile *profile,
NSMenu* encoding_menu) {
DCHECK(profile);
typedef EncodingMenuController::EncodingMenuItemList EncodingMenuItemList;
EncodingMenuItemList menuItems;
EncodingMenuController controller;
controller.GetEncodingMenuItems(profile, &menuItems);
for (EncodingMenuItemList::iterator it = menuItems.begin();
it != menuItems.end();
++it) {
int item_id = it->first;
string16 &localized_title_string16 = it->second;
if (item_id == 0) {
AddSeparatorToMenu(encoding_menu);
} else {
using base::SysWideToNSString;
NSString *localized_title = SysUTF16ToNSString(localized_title_string16);
AppendMenuItem(encoding_menu, item_id, localized_title);
}
}
}
|