mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-21 01:13:37 +08:00
Improve clipboard functionality in web app
This commit is contained in:
parent
0e1098eae7
commit
c0718c2aef
@ -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')
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user