Skip to content

Commit

Permalink
Add keyboard shortcuts to copy and save the GIF (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 16, 2020
1 parent 708efde commit 8ff31b3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 56 deletions.
21 changes: 13 additions & 8 deletions Gifski/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -67,16 +67,21 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="TB9-2E-bka"/>
<menuItem title="Quick Look" keyEquivalent=" " id="Wfh-bM-KvX">
<modifierMask key="keyEquivalentModifierMask"/>
<menuItem title="Close" keyEquivalent="w" id="3u8-9s-Y0B">
<connections>
<action selector="quickLook:" target="-1" id="IQy-U1-llq"/>
<action selector="performClose:" target="-1" id="k0u-T6-LNm"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
<menuItem title="Close" keyEquivalent="w" id="3u8-9s-Y0B">
<menuItem title="Save As…" keyEquivalent="s" id="XiK-JX-sg6">
<connections>
<action selector="performClose:" target="-1" id="k0u-T6-LNm"/>
<action selector="saveDocumentAs:" target="-1" id="ul6-aX-8nE"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="zHJ-Sl-xt7"/>
<menuItem title="Quick Look" keyEquivalent=" " id="Wfh-bM-KvX">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="quickLook:" target="-1" id="IQy-U1-llq"/>
</connections>
</menuItem>
</items>
Expand Down
108 changes: 61 additions & 47 deletions Gifski/ConversionCompletedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class ConversionCompletedViewController: NSViewController {

setUpUI()
setUpDropView()
setUp(url: gifUrl)
setUp()

if !NSApp.isActive || view.window?.isVisible == false {
let notification = UNMutableNotificationContent()
Expand Down Expand Up @@ -92,64 +92,64 @@ final class ConversionCompletedViewController: NSViewController {
draggableFile.constrainEdgesToSuperview()
}

private func setUp(url: URL) {
draggableFile.fileUrl = url
fileNameLabel.text = url.filename
fileSizeLabel.text = url.fileSizeFormatted
private func setUp() {
draggableFile.fileUrl = gifUrl
fileNameLabel.text = gifUrl.filename
fileSizeLabel.text = gifUrl.fileSizeFormatted

copyButton.onAction = { [weak self] _ in
self?.copyGif()
}

shareButton.sendAction(on: .leftMouseDown)
shareButton.onAction = { [weak self] _ in
guard let self = self else {
return
}

NSSharingService.share(items: [url as NSURL], from: self.shareButton)
self?.shareGif()
}

copyButton.onAction = { [weak self] _ in
guard let self = self else {
return
}

NSPasteboard.general.with {
$0.writeObjects([url as NSURL])
$0.setString(url.filenameWithoutExtension, forType: .urlName)
}
saveAsButton.onAction = { [weak self] _ in
self?.saveGif()
}
}

self.copyButton.title = "Copied!"
self.copyButton.isEnabled = false
private func copyGif() {
NSPasteboard.general.with {
$0.writeObjects([gifUrl as NSURL])
$0.setString(gifUrl.filenameWithoutExtension, forType: .urlName)
}

SSApp.runOnce(identifier: "copyWarning") {
NSAlert.showModal(
for: self.copyButton.window,
message: "The GIF was copied to the clipboard.",
informativeText: "However…",
buttonTitles: ["Continue"]
)
copyButton.title = "Copied!"
copyButton.isEnabled = false

SSApp.runOnce(identifier: "copyWarning") {
NSAlert.showModal(
for: copyButton.window,
message: "The GIF was copied to the clipboard.",
informativeText: "However…",
buttonTitles: ["Continue"]
)

NSAlert.showModal(
for: copyButton.window,
message: "Please read!",
informativeText: "Many apps like Chrome and Slack do not properly handle copied animated GIFs and will paste them as non-animated PNG.\n\nInstead, drag and drop the GIF into such apps."
)
}

NSAlert.showModal(
for: self.copyButton.window,
message: "Please read!",
informativeText: "Many apps like Chrome and Slack do not properly handle copied animated GIFs and will paste them as non-animated PNG.\n\nInstead, drag and drop the GIF into such apps."
)
delay(seconds: 1) { [weak self] in
guard let self = self else {
return
}

delay(seconds: 1) { [weak self] in
guard let self = self else {
return
}

self.copyButton.title = "Copy"
self.copyButton.isEnabled = true
}
self.copyButton.title = "Copy"
self.copyButton.isEnabled = true
}
}

saveAsButton.onAction = { [weak self] _ in
self?.openSavePanel()
}
private func shareGif() {
NSSharingService.share(items: [gifUrl as NSURL], from: shareButton)
}

private func openSavePanel() {
private func saveGif() {
let inputUrl = conversion.video

let panel = NSSavePanel()
Expand All @@ -174,7 +174,7 @@ final class ConversionCompletedViewController: NSViewController {
try FileManager.default.copyItem(at: self.gifUrl, to: outputUrl, overwrite: true)
} catch {
error.presentAsModalSheet(for: self.view.window)
self.openSavePanel()
self.saveGif()
}
}
}
Expand All @@ -192,6 +192,19 @@ final class ConversionCompletedViewController: NSViewController {
}
}

// MARK: First responders
extension ConversionCompletedViewController {
@objc
func copy(_ sender: Any) {
copyGif()
}

@objc
func saveDocumentAs(_ sender: Any) {
saveGif()
}
}

extension ConversionCompletedViewController: QLPreviewPanelDataSource {
@IBAction
private func quickLook(_ sender: Any) {
Expand Down Expand Up @@ -239,13 +252,14 @@ extension ConversionCompletedViewController: QLPreviewPanelDelegate {
}
}

// TODO: This doesn't seem to be needed on macOS 10.15, so drop it when we target that.
extension ConversionCompletedViewController: NSMenuItemValidation {
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
switch menuItem.action {
case #selector(quickLook(_:))?:
return true
default:
return false
return true
}
}
}
4 changes: 4 additions & 0 deletions app-store-description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Gifski includes a system service that lets you quickly convert a video to GIF fr

■ Tips

‣ Quickly copy or save the GIF

After converting, press Command+C to copy the GIF or Command+S to save it.

‣ Change GIF dimensions with the keyboard

In the width/height input fields in the editor view, press the arrow up/down keys to change the value by 1. Hold the Option key meanwhile to change it by 10.
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ Gifski includes a share extension that lets you share videos to Gifski. Just sel

Gifski includes a [system service](https://www.computerworld.com/article/2476298/os-x-a-quick-guide-to-services-on-your-mac.html) that lets you quickly convert a video to GIF from the **Services** menu in any app that provides a compatible video file.

### Change GIF dimensions with the keyboard
## Tips

#### Quickly copy or save the GIF

After converting, press <kbd>Command+C</kbd> to copy the GIF or <kbd>Command+S</kbd> to save it.

#### Change GIF dimensions with the keyboard

<img src="https://user-images.githubusercontent.com/170270/59964494-b8519f00-952b-11e9-8d16-47c8bc103a61.gif" width="226" height="80" align="right">

Expand Down

0 comments on commit 8ff31b3

Please sign in to comment.