blob: c75abe52e9c1309477b0144c408445ab79f814c0 (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// Copyright (c) 2012 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.
#import "chrome/browser/ui/cocoa/applescript/browsercrapplication+applescript.h"
#include "base/logging.h"
#import "base/mac/scoped_nsobject.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_iterator.h"
#import "chrome/browser/ui/cocoa/applescript/bookmark_folder_applescript.h"
#import "chrome/browser/ui/cocoa/applescript/constants_applescript.h"
#import "chrome/browser/ui/cocoa/applescript/error_applescript.h"
#import "chrome/browser/ui/cocoa/applescript/window_applescript.h"
#include "components/bookmarks/browser/bookmark_model.h"
@implementation BrowserCrApplication (AppleScriptAdditions)
- (NSArray*)appleScriptWindows {
NSMutableArray* appleScriptWindows = [NSMutableArray
arrayWithCapacity:chrome::GetTotalBrowserCount()];
// Iterate through all browsers and check if it closing,
// if not add it to list.
for (chrome::BrowserIterator browserIterator; !browserIterator.done();
browserIterator.Next()) {
if ((*browserIterator)->IsAttemptingToCloseBrowser())
continue;
base::scoped_nsobject<WindowAppleScript> window(
[[WindowAppleScript alloc] initWithBrowser:*browserIterator]);
[window setContainer:NSApp
property:AppleScript::kWindowsProperty];
[appleScriptWindows addObject:window];
}
// Windows sorted by their index value, which is obtained by calling
// orderedIndex: on each window.
[appleScriptWindows sortUsingSelector:@selector(windowComparator:)];
return appleScriptWindows;
}
- (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow {
// This method gets called when a new window is created so
// the container and property are set here.
[aWindow setContainer:self
property:AppleScript::kWindowsProperty];
}
- (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow
atIndex:(int)index {
// This method gets called when a new window is created so
// the container and property are set here.
[aWindow setContainer:self
property:AppleScript::kWindowsProperty];
// Note: AppleScript is 1-based.
index--;
[aWindow setOrderedIndex:[NSNumber numberWithInt:index]];
}
- (void)removeFromAppleScriptWindowsAtIndex:(int)index {
[[[self appleScriptWindows] objectAtIndex:index]
handlesCloseScriptCommand:nil];
}
- (NSScriptObjectSpecifier*)objectSpecifier {
return nil;
}
- (BookmarkFolderAppleScript*)otherBookmarks {
AppController* appDelegate = [NSApp delegate];
Profile* lastProfile = [appDelegate lastProfile];
if (!lastProfile) {
AppleScript::SetError(AppleScript::errGetProfile);
return nil;
}
BookmarkModel* model = BookmarkModelFactory::GetForProfile(lastProfile);
if (!model->loaded()) {
AppleScript::SetError(AppleScript::errBookmarkModelLoad);
return nil;
}
BookmarkFolderAppleScript* otherBookmarks =
[[[BookmarkFolderAppleScript alloc]
initWithBookmarkNode:model->other_node()] autorelease];
[otherBookmarks setContainer:self
property:AppleScript::kBookmarkFoldersProperty];
return otherBookmarks;
}
- (BookmarkFolderAppleScript*)bookmarksBar {
AppController* appDelegate = [NSApp delegate];
Profile* lastProfile = [appDelegate lastProfile];
if (!lastProfile) {
AppleScript::SetError(AppleScript::errGetProfile);
return nil;
}
BookmarkModel* model = BookmarkModelFactory::GetForProfile(lastProfile);
if (!model->loaded()) {
AppleScript::SetError(AppleScript::errBookmarkModelLoad);
return NULL;
}
BookmarkFolderAppleScript* bookmarksBar =
[[[BookmarkFolderAppleScript alloc]
initWithBookmarkNode:model->bookmark_bar_node()] autorelease];
[bookmarksBar setContainer:self
property:AppleScript::kBookmarkFoldersProperty];
return bookmarksBar;
}
- (NSArray*)bookmarkFolders {
BookmarkFolderAppleScript* otherBookmarks = [self otherBookmarks];
BookmarkFolderAppleScript* bookmarksBar = [self bookmarksBar];
NSArray* folderArray = [NSArray arrayWithObjects:otherBookmarks,
bookmarksBar,
nil];
return folderArray;
}
- (void)insertInBookmarksFolders:(id)aBookmarkFolder {
NOTIMPLEMENTED();
}
- (void)insertInBookmarksFolders:(id)aBookmarkFolder atIndex:(int)index {
NOTIMPLEMENTED();
}
- (void)removeFromBookmarksFoldersAtIndex:(int)index {
NOTIMPLEMENTED();
}
@end
|