Skip to content

Commit

Permalink
Added new menu items for open in browser(CMD+O), copy URL(CMD+SHIFT+C…
Browse files Browse the repository at this point in the history
…) and copying image URL(CMD+C). Also works when selecting multiple posts
  • Loading branch information
DrabWeb committed Aug 23, 2016
1 parent 6970391 commit 606af29
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Booru-chan/Booru-chan/BCAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class BCAppDelegate: NSObject, NSApplicationDelegate {
/// File/Save Selected Images (⌘S)
@IBOutlet weak var menuItemSaveSelectedImages: NSMenuItem!

/// File/Open Selected Posts In Browser
@IBOutlet weak var menuItemOpenSelectedPostsInBrowser: NSMenuItem!

/// File/Copy URLs of Selected Posts
@IBOutlet weak var menuItemCopyUrlsOfSelectedPosts: NSMenuItem!

/// File/Copy Image URLs of Selected Posts (⌘C)
@IBOutlet weak var menuItemCopyImageUrlsOfSelectedPosts: NSMenuItem!

/// Image/Zoom In (⌘=)
@IBOutlet weak var menuItemZoomIn: NSMenuItem!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import Cocoa

class BCBooruCollectionViewCollectionViewItem: NSCollectionViewItem {

/// Returns the URL to this post
var getUrl : String {
return (self.representedObject as! BCBooruCollectionViewItem).representedPost!.url;
}

/// Returns the URL to this post's image
var getImageUrl : String {
return (self.representedObject as! BCBooruCollectionViewItem).representedPost!.imageUrl;
}

override func rightMouseDown(theEvent: NSEvent) {
/// The menu to show when the user right clicks this item
let menu : NSMenu = NSMenu();
Expand All @@ -31,7 +41,7 @@ class BCBooruCollectionViewCollectionViewItem: NSCollectionViewItem {
/// Opens this post in the browser
func openInBrowser() {
// Open this item's post's URL in the browser
NSWorkspace.sharedWorkspace().openURL(NSURL(string: (self.representedObject as! BCBooruCollectionViewItem).representedPost!.url)!);
NSWorkspace.sharedWorkspace().openURL(NSURL(string: getUrl)!);
}

/// Copys the URL of this post to the clipboard
Expand All @@ -40,7 +50,7 @@ class BCBooruCollectionViewCollectionViewItem: NSCollectionViewItem {
NSPasteboard.generalPasteboard().declareTypes([NSStringPboardType], owner: nil);

// Set the string of the general pasteboard to this item's post's URL
NSPasteboard.generalPasteboard().setString((self.representedObject as! BCBooruCollectionViewItem).representedPost!.url, forType: NSStringPboardType);
NSPasteboard.generalPasteboard().setString(getUrl, forType: NSStringPboardType);
}

/// Copys the URL of this post to the clipboard
Expand All @@ -49,7 +59,7 @@ class BCBooruCollectionViewCollectionViewItem: NSCollectionViewItem {
NSPasteboard.generalPasteboard().declareTypes([NSStringPboardType], owner: nil);

// Set the string of the general pasteboard to this item's post's image's URL
NSPasteboard.generalPasteboard().setString((self.representedObject as! BCBooruCollectionViewItem).representedPost!.imageUrl, forType: NSStringPboardType);
NSPasteboard.generalPasteboard().setString(getImageUrl, forType: NSStringPboardType);
}

override func viewDidLoad() {
Expand Down
66 changes: 66 additions & 0 deletions Booru-chan/Booru-chan/BCViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,69 @@ class BCViewController: NSViewController, NSWindowDelegate {
saveBooruItems(gridStyleController.getSelectedBooruItems());
}

/// Opens the selected posts in the browser
func openSelectedPostsInBrowser() {
// For every selected post...
for(_, currentSelectedPost) in gridStyleController.getSelectedBooruItems().enumerate() {
// Open the selected post in the browser
NSWorkspace.sharedWorkspace().openURL(NSURL(string: currentSelectedPost.representedPost!.url)!);
}
}

/// Copys the URLs of the selected posts
func copyUrlsOfSelectedPosts() {
/// The string to copy to the pasteboard
var copyString : String = "";

// For every selected post...
for(currentIndex, currentSelectedPost) in gridStyleController.getSelectedBooruItems().enumerate() {
// If this isnt the last item...
if(currentIndex != (gridStyleController.getSelectedBooruItems().count - 1)) {
// Add the current item's post's URL to the end of copyString, with a trailing new line
copyString += currentSelectedPost.representedPost!.url + "\n";
}
// If ths is the last item...
else {
// Add the current item's post's URL to the end of copyString
copyString += currentSelectedPost.representedPost!.url;
}
}

// Copy copyString
// Add the string type to the general pasteboard
NSPasteboard.generalPasteboard().declareTypes([NSStringPboardType], owner: nil);

// Set the string of the general pasteboard to copyString
NSPasteboard.generalPasteboard().setString(copyString, forType: NSStringPboardType);
}

/// Copys the image URLs of the selected posts
func copyImageUrlsOfSelectedPosts() {
/// The string to copy to the pasteboard
var copyString : String = "";

// For every selected post...
for(currentIndex, currentSelectedPost) in gridStyleController.getSelectedBooruItems().enumerate() {
// If this isnt the last item...
if(currentIndex != (gridStyleController.getSelectedBooruItems().count - 1)) {
// Add the current item's post's image URL to the end of copyString, with a trailing new line
copyString += currentSelectedPost.representedPost!.imageUrl + "\n";
}
// If ths is the last item...
else {
// Add the current item's post's image URL to the end of copyString
copyString += currentSelectedPost.representedPost!.imageUrl;
}
}

// Copy copyString
// Add the string type to the general pasteboard
NSPasteboard.generalPasteboard().declareTypes([NSStringPboardType], owner: nil);

// Set the string of the general pasteboard to copyString
NSPasteboard.generalPasteboard().setString(copyString, forType: NSStringPboardType);
}

/// Updates currentSelectedSearchingBooru to match the selected item in titlebarBooruPickerPopupButton
func updateSelectedSearchingBooru() {
// Clear the current searching Booru's last search
Expand Down Expand Up @@ -400,6 +463,9 @@ class BCViewController: NSViewController, NSWindowDelegate {
// Setup the menu items
// Set the actions
(NSApplication.sharedApplication().delegate as! BCAppDelegate).menuItemSaveSelectedImages.action = Selector("saveSelectedImages");
(NSApplication.sharedApplication().delegate as! BCAppDelegate).menuItemOpenSelectedPostsInBrowser.action = Selector("openSelectedPostsInBrowser");
(NSApplication.sharedApplication().delegate as! BCAppDelegate).menuItemCopyUrlsOfSelectedPosts.action = Selector("copyUrlsOfSelectedPosts");
(NSApplication.sharedApplication().delegate as! BCAppDelegate).menuItemCopyImageUrlsOfSelectedPosts.action = Selector("copyImageUrlsOfSelectedPosts");
(NSApplication.sharedApplication().delegate as! BCAppDelegate).menuItemToggleTitlebar.action = Selector("toggleTitlebar");
(NSApplication.sharedApplication().delegate as! BCAppDelegate).menuItemSelectSearchField.action = Selector("selectSearchField");
(NSApplication.sharedApplication().delegate as! BCAppDelegate).menuItemSelectPostBrowser.action = Selector("selectPostBrowser");
Expand Down
9 changes: 8 additions & 1 deletion Booru-chan/Booru-chan/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@
</connections>
</menuItem>
<menuItem title="Save Selected Images" keyEquivalent="s" id="BHx-14-SHv"/>
<menuItem isSeparatorItem="YES" id="PiA-mG-5PH"/>
<menuItem title="Open Selected Posts In Browser" keyEquivalent="o" id="fvh-hQ-1hD"/>
<menuItem title="Copy URLs of Selected Posts" keyEquivalent="C" id="hRr-pn-fLj"/>
<menuItem title="Copy Image URLs of Selected Posts" keyEquivalent="c" id="N4M-Fe-uaM"/>
</items>
</menu>
</menuItem>
Expand Down Expand Up @@ -617,6 +621,9 @@
</application>
<customObject id="Voe-Tx-rLC" customClass="BCAppDelegate" customModule="Booru_chan" customModuleProvider="target">
<connections>
<outlet property="menuItemCopyImageUrlsOfSelectedPosts" destination="N4M-Fe-uaM" id="Upt-zn-bdA"/>
<outlet property="menuItemCopyUrlsOfSelectedPosts" destination="hRr-pn-fLj" id="Pa1-ep-JYT"/>
<outlet property="menuItemOpenSelectedPostsInBrowser" destination="fvh-hQ-1hD" id="Db4-4P-env"/>
<outlet property="menuItemResetZoom" destination="f9y-iU-uVu" id="E24-Kl-DLl"/>
<outlet property="menuItemSaveSelectedImages" destination="BHx-14-SHv" id="4c4-Hp-LZr"/>
<outlet property="menuItemSelectPostBrowser" destination="OuU-Ru-VLE" id="3sY-SF-IjS"/>
Expand Down Expand Up @@ -921,7 +928,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="ZrN-SC-BsJ">
<rect key="frame" x="277" y="0.0" width="15" height="363"/>
<rect key="frame" x="276" y="0.0" width="16" height="363"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down

0 comments on commit 606af29

Please sign in to comment.