Attach a small menu to the preview windows, remove scrollbars on Windows

This commit is contained in:
Ben Gotow 2019-01-03 12:00:42 -08:00
parent 6b2546c71f
commit b7939d38bd
2 changed files with 93 additions and 0 deletions

View file

@ -53,6 +53,95 @@ const CrossplatformPreviewableExtensions = [
'xlsb',
];
const PreviewWindowMenuTemplate = [
{
label: 'File',
role: 'window',
submenu: [
{
label: 'Minimize Window',
accelerator: 'CmdOrCtrl+M',
role: 'minimize',
},
{
label: 'Close Window',
accelerator: 'CmdOrCtrl+W',
role: 'close',
},
],
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
role: 'undo',
},
{
label: 'Redo',
accelerator: 'Shift+CmdOrCtrl+Z',
role: 'redo',
},
{
type: 'separator',
},
{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
role: 'cut',
},
{
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
role: 'copy',
},
{
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste',
},
{
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
role: 'selectall',
},
],
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: function(item, focusedWindow) {
if (focusedWindow) focusedWindow.reload();
},
},
{
label: 'Toggle Full Screen',
accelerator: (function() {
if (process.platform === 'darwin') return 'Ctrl+Command+F';
else return 'F11';
})(),
click: function(item, focusedWindow) {
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
},
},
{
label: 'Toggle Developer Tools',
accelerator: (function() {
if (process.platform === 'darwin') return 'Alt+Command+I';
else return 'Ctrl+Shift+I';
})(),
click: function(item, focusedWindow) {
if (focusedWindow) focusedWindow.toggleDevTools();
},
},
],
},
];
export function canPossiblyPreviewExtension(file) {
if (file.size > FileSizeLimit) {
return false;
@ -92,6 +181,7 @@ export function displayQuickPreviewWindow(filePath) {
quickPreviewWindow.once('closed', () => {
quickPreviewWindow = null;
});
quickPreviewWindow.setMenu(remote.Menu.buildFromTemplate(PreviewWindowMenuTemplate));
} else {
quickPreviewWindow.show();
}

View file

@ -35,6 +35,9 @@ global.finishWithData = (previewPath, arrayBuffer) => {
};
global.finishWithWindowCapture = (previewPath, startedAt = Date.now()) => {
// Remove scroll bars or they appear in the capture on Windows
document.body.style.overflow = 'hidden';
// Wait up to 1 sec for images in the rendered HTML to finish loading
const waitingForImage = Array.from(document.querySelectorAll('img')).find(
i => i.complete === false