Skip to content

Commit

Permalink
UX / refactor: copy paths w/o quotes by default, add quotes modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksey-hoffman committed Jan 25, 2022
1 parent db906c0 commit d5ee9d2
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/components/Dialogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -949,12 +949,12 @@ Copyright © 2021 - present Aleksey Hoffman. All rights reserved.
<template v-slot:content>
<v-text-field
v-model="dialogs.userDirectoryEditorDialog.data.item.name"
label="Directory name"
label="Title"
></v-text-field>

<v-text-field
v-model="dialogs.userDirectoryEditorDialog.data.item.path"
label="Directory path"
label="Path to directory or file"
></v-text-field>

<v-layout align-center>
Expand Down
6 changes: 4 additions & 2 deletions src/components/InfoPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -746,15 +746,17 @@ export default {
text: params.item.value,
asPath: isPath,
pathSlashes: 'single-backward',
title
wrapWithQuotes: params.event.shiftKey,
title,
})
}
else if (params.event.ctrlKey && params.event.altKey) {
this.$utils.copyToClipboard({
text: params.item.value,
asPath: isPath,
pathSlashes: 'double-backward',
title
wrapWithQuotes: params.event.shiftKey,
title,
})
}
},
Expand Down
1 change: 0 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3351,7 +3351,6 @@ export default new Vuex.Store({
utils.copyToClipboard({
text: params.path,
title: 'Path was copied to clipboard',
message: params.path,
asPath: true,
pathSlashes: sharedUtils.platform === 'win32'
? 'single-backward'
Expand Down
22 changes: 22 additions & 0 deletions src/utils/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ const eventHub = require('./eventHub').eventHub
*/
function getNotification (params) {
let notifications = {
copyTextToClipboard: {
action: 'update-by-type',
type: 'copyTextToClipboard',
timeout: 2000,
closeButton: true,
icon: 'mdi-clipboard-text-multiple-outline',
title: params?.props?.title,
message: params?.props?.message,
},
copyTextToClipboardError: {
action: 'update-by-type',
type: 'copyTextToClipboardError',
timeout: 5000,
closeButton: true,
colorStatus: 'red',
icon: 'mdi-clipboard-text-multiple-outline',
title: 'Error during copying',
message: `
Cannot copy specified value as text.
<br>Data type: <span class="inline-code--light">${typeof params?.props?.text}</span>
`,
},
copyDirItemsInProgress: {
action: 'update-by-hash',
hashID: sharedUtils.getHash(),
Expand Down
75 changes: 52 additions & 23 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright © 2021 - present Aleksey Hoffman. All rights reserved.

import * as localize from './localize.js'
import * as notifications from './notifications.js'
const dayjsCustomParseFormat = require('dayjs/plugin/customParseFormat')
const dayjsDuration = require('dayjs/plugin/duration')
const dayjs = require('dayjs')
Expand Down Expand Up @@ -153,33 +154,61 @@ export default {
return array.reduce((a, b) => a + b, 0) / array.length
},
copyToClipboard (params) {
if (params.asPath) {
if (this.platform === 'win32') {
if (params.pathSlashes === 'single-backward') {
const processedPath = `"${params.text.replace(/\//g, '\\')}"`
params.text = processedPath
params.message = processedPath
let moduleScope = this
let data = {
title: getDataTitle(params),
text: getDataText(params),
message: getDataMessage(params),
}

function getDataTitle (params) {
return params.asPath
? 'Path was copied to clipboard'
: params.title ?? 'Text was copied to clipboard'
}

function getDataText (params) {
let text = ''
if (params.asPath) {
if (moduleScope.platform === 'win32') {
if (params.pathSlashes === 'single-backward') {
text = `${params.text.replace(/\//g, '\\')}`
}
else if (params.pathSlashes === 'double-backward') {
text = `${params.text.replace(/\//g, '\\\\')}`
}
}
else if (params.pathSlashes === 'double-backward') {
const processedPath = `"${params.text.replace(/\//g, '\\\\')}"`
params.text = processedPath
params.message = processedPath
else {
text = params.text
}
}
else {
params.message = `"${params.text}"`
}
return params.wrapWithQuotes ? `"${text}"` : text
}

function getDataMessage (params) {
return params.asPath
? params.text
: params.message
}

try {
electron.clipboard.writeText(data.text)
notifications.emit({
name: 'copyTextToClipboard',
props: {
title: data.title,
message: data.message ?? data.text,
},
})
}
catch (error) {
notifications.emit({
name: 'copyTextToClipboardError',
props: {
text: data.text,
},
})
}
electron.clipboard.writeText(params.text)
eventHub.$emit('notification', {
action: 'update-by-type',
type: 'copy-to-clipboard',
timeout: 2000,
closeButton: true,
icon: 'mdi-clipboard-text-multiple-outline',
title: params.title ?? 'Text was copied to clipboard',
message: params.message
})
},
/** Encode URL, replacing all URL-unsafe
* characters (except slash) with hex representation
Expand Down

0 comments on commit d5ee9d2

Please sign in to comment.