Improve clipboard functionality in web app

This commit is contained in:
JannisX11 2021-01-16 23:37:58 +01:00
parent 0e1098eae7
commit c0718c2aef
3 changed files with 38 additions and 11 deletions

View File

@ -36,7 +36,7 @@ const Clipbench = {
if ((p == 'uv' || p == 'preview') && Modes.edit) {
return Clipbench.types.face;
}
if (p == 'textures' && isApp && (Texture.selected || mode === 2)) {
if (p == 'textures' && (Texture.selected || mode === 2)) {
return Clipbench.types.texture;
}
if (p == 'outliner' && Modes.edit) {
@ -138,6 +138,8 @@ const Clipbench = {
setText(text) {
if (isApp) {
clipboard.writeText(text)
} else if (navigator.clipboard) {
navigator.clipboard.writeText(text);
} else {
document.execCommand('copy')
}

View File

@ -1094,12 +1094,26 @@ class Preview {
}
}, 'image', false)
}},
{icon: 'fa-clipboard', name: 'menu.preview.background.clipboard', condition: isApp, click: function(preview) {
var image = clipboard.readImage().toDataURL();
if (image.length > 32) {
preview.background.image = image;
preview.loadBackground();
Settings.saveLocalStorages()
{icon: 'fa-clipboard', name: 'menu.preview.background.clipboard', click: function(preview) {
function loadImage(image) {
if (image.length > 32) {
preview.background.image = image;
preview.loadBackground();
Settings.saveLocalStorages()
}
}
if (isApp) {
var image = clipboard.readImage().toDataURL();
loadImage(image);
} else {
navigator.clipboard.read().then(content => {
if (content && content[0] && content[0].types.includes('image/png')) {
content[0].getType('image/png').then(blob => {
let url = URL.createObjectURL(blob);
loadImage(url);
})
}
})
}
}},
{icon: 'photo_size_select_large', name: 'menu.preview.background.position', condition: has_background, click: function(preview) {

View File

@ -1158,15 +1158,25 @@ Clipbench.setTexture = function(texture) {
clipboard.writeImage(img)
}
Clipbench.pasteTextures = function() {
if (!isApp) return;
var img = clipboard.readImage()
if (img) {
var dataUrl = img.toDataURL()
function loadImage(dataUrl) {
var texture = new Texture({name: 'pasted', folder: 'block' }).fromDataURL(dataUrl).fillParticle().add(true)
setTimeout(function() {
texture.openMenu()
}, 40)
}
if (isApp) {
var image = clipboard.readImage().toDataURL();
loadImage(image);
} else {
navigator.clipboard.read().then(content => {
if (content && content[0] && content[0].types.includes('image/png')) {
content[0].getType('image/png').then(blob => {
let url = URL.createObjectURL(blob);
loadImage(url);
})
}
}).catch(() => {})
}
}
Object.defineProperty(textures, selected, {
@ -1511,6 +1521,7 @@ Interface.definePanels(function() {
}
},
menu: new Menu([
'paste',
'import_texture',
'create_texture',
'reload_textures',