| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/cocoa/applescript/browsercrapplication+applescript.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #import "base/scoped_nsobject.h" |
| 9 #import "chrome/browser/app_controller_mac.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 #include "chrome/browser/browser_list.h" |
| 12 #import "chrome/browser/cocoa/applescript/bookmark_folder_applescript.h" |
| 13 #import "chrome/browser/cocoa/applescript/constants_applescript.h" |
| 14 #import "chrome/browser/cocoa/applescript/error_applescript.h" |
| 15 #import "chrome/browser/cocoa/applescript/window_applescript.h" |
| 16 #include "chrome/browser/profile.h" |
| 17 |
| 18 @implementation BrowserCrApplication (AppleScriptAdditions) |
| 19 |
| 20 - (NSArray*)appleScriptWindows { |
| 21 NSMutableArray* appleScriptWindows = [NSMutableArray |
| 22 arrayWithCapacity:BrowserList::size()]; |
| 23 // Iterate through all browsers and check if it closing, |
| 24 // if not add it to list. |
| 25 for (BrowserList::const_iterator browserIterator = BrowserList::begin(); |
| 26 browserIterator != BrowserList::end(); ++browserIterator) { |
| 27 if ((*browserIterator)->IsAttemptingToCloseBrowser()) |
| 28 continue; |
| 29 |
| 30 scoped_nsobject<WindowAppleScript> window( |
| 31 [[WindowAppleScript alloc] initWithBrowser:*browserIterator]); |
| 32 [appleScriptWindows addObject:window]; |
| 33 } |
| 34 // Windows sorted by their index value, which is obtained by calling |
| 35 // orderedIndex: on each window. |
| 36 [appleScriptWindows sortUsingSelector:@selector(windowComparator:)]; |
| 37 return appleScriptWindows; |
| 38 } |
| 39 |
| 40 - (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow { |
| 41 // This method gets called when a new window is created so |
| 42 // the container and property are set here. |
| 43 [aWindow setContainer:self |
| 44 property:AppleScript::kWindowsProperty]; |
| 45 } |
| 46 |
| 47 - (void)insertInAppleScriptWindows:(WindowAppleScript*)aWindow |
| 48 atIndex:(int)index { |
| 49 // This method gets called when a new window is created so |
| 50 // the container and property are set here. |
| 51 [aWindow setContainer:self |
| 52 property:AppleScript::kWindowsProperty]; |
| 53 // Note: AppleScript is 1-based. |
| 54 index--; |
| 55 [aWindow setOrderedIndex:[NSNumber numberWithInt:index]]; |
| 56 } |
| 57 |
| 58 - (void)removeFromAppleScriptWindowsAtIndex:(int)index { |
| 59 [[[self appleScriptWindows] objectAtIndex:index] |
| 60 handlesCloseScriptCommand:nil]; |
| 61 } |
| 62 |
| 63 - (NSScriptObjectSpecifier*)objectSpecifier { |
| 64 return nil; |
| 65 } |
| 66 |
| 67 - (BookmarkFolderAppleScript*)otherBookmarks { |
| 68 AppController* appDelegate = [NSApp delegate]; |
| 69 |
| 70 Profile* defaultProfile = [appDelegate defaultProfile]; |
| 71 if (!defaultProfile) { |
| 72 AppleScript::SetError(AppleScript::errGetProfile); |
| 73 return nil; |
| 74 } |
| 75 |
| 76 BookmarkModel* model = defaultProfile->GetBookmarkModel(); |
| 77 if (!model->IsLoaded()) { |
| 78 AppleScript::SetError(AppleScript::errBookmarkModelLoad); |
| 79 return nil; |
| 80 } |
| 81 |
| 82 BookmarkFolderAppleScript* otherBookmarks = |
| 83 [[[BookmarkFolderAppleScript alloc] |
| 84 initWithBookmarkNode:model->other_node()] autorelease]; |
| 85 [otherBookmarks setContainer:self |
| 86 property:AppleScript::kBookmarkFoldersProperty]; |
| 87 return otherBookmarks; |
| 88 } |
| 89 |
| 90 - (BookmarkFolderAppleScript*)bookmarksBar { |
| 91 AppController* appDelegate = [NSApp delegate]; |
| 92 |
| 93 Profile* defaultProfile = [appDelegate defaultProfile]; |
| 94 if (!defaultProfile) { |
| 95 AppleScript::SetError(AppleScript::errGetProfile); |
| 96 return nil; |
| 97 } |
| 98 |
| 99 BookmarkModel* model = defaultProfile->GetBookmarkModel(); |
| 100 if (!model->IsLoaded()) { |
| 101 AppleScript::SetError(AppleScript::errBookmarkModelLoad); |
| 102 return NULL; |
| 103 } |
| 104 |
| 105 BookmarkFolderAppleScript* bookmarksBar = |
| 106 [[[BookmarkFolderAppleScript alloc] |
| 107 initWithBookmarkNode:model->GetBookmarkBarNode()] autorelease]; |
| 108 [bookmarksBar setContainer:self |
| 109 property:AppleScript::kBookmarkFoldersProperty]; |
| 110 return bookmarksBar; |
| 111 } |
| 112 |
| 113 - (NSArray*)bookmarkFolders { |
| 114 BookmarkFolderAppleScript* otherBookmarks = [self otherBookmarks]; |
| 115 BookmarkFolderAppleScript* bookmarksBar = [self bookmarksBar]; |
| 116 NSArray* folderArray = [NSArray arrayWithObjects:otherBookmarks, |
| 117 bookmarksBar, |
| 118 nil]; |
| 119 return folderArray; |
| 120 } |
| 121 |
| 122 - (void)insertInBookmarksFolders:(id)aBookmarkFolder { |
| 123 NOTIMPLEMENTED(); |
| 124 } |
| 125 |
| 126 - (void)insertInBookmarksFolders:(id)aBookmarkFolder atIndex:(int)index { |
| 127 NOTIMPLEMENTED(); |
| 128 } |
| 129 |
| 130 - (void)removeFromBookmarksFoldersAtIndex:(int)index { |
| 131 NOTIMPLEMENTED(); |
| 132 } |
| 133 |
| 134 @end |
| OLD | NEW |