Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Add Copy Image command, sort/fix Help
Browse files Browse the repository at this point in the history
  • Loading branch information
ESWAT committed Apr 13, 2020
1 parent a45c803 commit 1315a6f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "VoidView",
"version": "1.3.2",
"version": "1.4.0",
"description": "Stare into the endless void of your image collection.",
"main": "main.js",
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ const menuTemplate = [
window.webContents.send('shuffle')
}
},
{
label: 'Copy Image',
accelerator: 'Cmd+C',
enabled: false,
click: () => {
window.webContents.send('copy')
}
},
{
label: 'Show in Finder',
accelerator: 'Cmd+Shift+O',
Expand Down Expand Up @@ -258,10 +266,14 @@ function createWindow () {
menu.items[1].submenu.items[2].enabled = arg
})

ipcMain.on('enable-finder-command', (event, arg) => {
ipcMain.on('enable-copy-command', (event, arg) => {
menu.items[1].submenu.items[3].enabled = arg
})

ipcMain.on('enable-finder-command', (event, arg) => {
menu.items[1].submenu.items[4].enabled = arg
})

ipcMain.on('enable-columns-command', (event, arg) => {
menu.items[2].submenu.items[0].enabled = arg
menu.items[2].submenu.items[1].enabled = arg
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ body {
body.is-peeking .grid-command,
body:not(.can-shuffle) .shuffle-command,
body:not(.can-finder) .finder-command,
body:not(.can-fit) .fit-command {
body:not(.can-fit) .fit-command,
body:not(.can-copy) .copy-command {
opacity: 0.2;
}

Expand Down
20 changes: 19 additions & 1 deletion src/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import shuffle from 'fast-shuffle'
import Clusterize from 'clusterize.js'
import Store from 'electron-store'
import elementReady from 'element-ready'
import { ipcRenderer, shell } from 'electron'
import { clipboard, ipcRenderer, shell } from 'electron'
import { createFrag, readDir } from './utils'
import { gridStyle, help, layout, list, loader, peek, splash, titlebar } from './templates'
import { DEFAULT_COLUMNS, KEY_COMBO_COOLDOWN, SUPPORTED_EXTENSIONS, STORE_SCHEMA } from './constants'
Expand Down Expand Up @@ -94,6 +94,9 @@ function setupCommands () {
ipcRenderer.on('reveal', () => {
openExternally()
})
ipcRenderer.on('copy', () => {
copyImage()
})
ipcRenderer.on('help', () => {
if (files.length > 0) {
toggleHelp()
Expand Down Expand Up @@ -175,6 +178,7 @@ function handleKeyUp (event) {
case 'Tab':
currentItem = parseInt(document.activeElement.dataset.index, 10)
enableFinderCommand(true)
enableCopyCommand(true)
break
case 'Enter':
case ' ':
Expand Down Expand Up @@ -279,6 +283,7 @@ function renderFiles () {

function deselectItems () {
enableFinderCommand(false)
enableCopyCommand(false)
currentItem = -1
document.activeElement.blur()
}
Expand All @@ -293,6 +298,7 @@ function selectItem (newIndex) {

if (element) {
enableFinderCommand(true)
enableCopyCommand(true)
element.focus()
}
}
Expand Down Expand Up @@ -418,6 +424,7 @@ function readDesiredFiles (desiredFiles) {

function initialRender () {
enableFinderCommand(false)
enableCopyCommand(false)
enableShuffleCommand(true)
enableColumnChanging(true)

Expand Down Expand Up @@ -458,6 +465,12 @@ function getImages (path) {
})
}

function copyImage () {
const { image } = document.querySelector(`.js-item[data-index="${currentItem}"]`).dataset

clipboard.writeImage(decodeURI(image))
}

function isFilePathADirectory (filePath) {
if (fs.statSync(filePath).isFile()) {
const ext = nodePath.extname(filePath)
Expand Down Expand Up @@ -491,6 +504,7 @@ function openPeek (item) {
}, { capture: false, once: true })

enableFinderCommand(true)
enableCopyCommand(true)
enableShuffleCommand(false)
enableColumnChanging(false)
enableZoomCommand(true)
Expand Down Expand Up @@ -568,6 +582,10 @@ function toggleZoom () {
enableFitCommand(document.querySelector('.js-peek') && !store.get('contain'))
}

function enableCopyCommand (state) {
toggleCommand('copy', state)
}

function enableZoomCommand (state) {
toggleCommand('zoom', state)
}
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export const help = `
<span class="help-command grid-command"><span class="help-stroke">⇧G</span> Go to Bottom</span>
</div>
<div class="help-list">
<span class="help-command copy-command"><span class="help-stroke">⌘C</span> Copy Image</span>
<span class="help-command finder-command"><span class="help-stroke">⌘⇧O</span> Show in Finder</span>
<span class="help-command"><span class="help-stroke">F</span> Fit Image to Frame</span>
<span class="help-command shuffle-command"><span class="help-stroke">⌘=/⌘-</span> Add/Remove Columns</span>
<span class="help-command shuffle-command"><span class="help-stroke">⌘0</span> Reset Columns</span>
<span class="help-command shuffle-command"><span class="help-stroke">⌘=/⌘-/⌘0</span> Add/Remove/Reset Columns</span>
<span class="help-command fit-command"><span class="help-stroke">F</span> Fit Image to Frame</span>
</div>
<div class="help-list">
<span class="help-command"><span class="help-stroke">⌘⇧H</span> Help</span>
Expand Down

0 comments on commit 1315a6f

Please sign in to comment.