From 593153eebe3ce14a3f88ea995149d49c46ed4e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 30 Mar 2018 15:31:53 +0300 Subject: [PATCH] Adds a progress bar for non quick-format integration actions The progress percentage is based on the most recent transaction (or undeterminate if this is the first session transaction) Fix undefined function call error --- .../zotero-platform/mac/integration.css | 4 + .../content/zotero/integration/progressBar.js | 129 +++++++++++++++ .../zotero/integration/progressBar.xul | 51 ++++++ .../xpcom/connector/httpIntegrationClient.js | 6 +- .../xpcom/connector/server_connector.js | 12 +- chrome/content/zotero/xpcom/integration.js | 151 +++++++++++++++--- .../zotero/xpcom/utilities_internal.js | 12 ++ test/tests/integrationTest.js | 3 + 8 files changed, 339 insertions(+), 29 deletions(-) create mode 100644 chrome/content/zotero/integration/progressBar.js create mode 100644 chrome/content/zotero/integration/progressBar.xul diff --git a/chrome/content/zotero-platform/mac/integration.css b/chrome/content/zotero-platform/mac/integration.css index f33b75ad3a..d3f6ee46fb 100644 --- a/chrome/content/zotero-platform/mac/integration.css +++ b/chrome/content/zotero-platform/mac/integration.css @@ -14,6 +14,10 @@ body[multiline="true"] { width: 800px; } +#quick-format-dialog.progress-bar #quick-format-deck { + height: 37px; +} + #quick-format-search { background: white; -moz-appearance: searchfield; diff --git a/chrome/content/zotero/integration/progressBar.js b/chrome/content/zotero/integration/progressBar.js new file mode 100644 index 0000000000..d669cea467 --- /dev/null +++ b/chrome/content/zotero/integration/progressBar.js @@ -0,0 +1,129 @@ +/* + ***** BEGIN LICENSE BLOCK ***** + + Copyright © 2018 Center for History and New Media + George Mason University, Fairfax, Virginia, USA + http://zotero.org + + This file is part of Zotero. + + Zotero is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Zotero is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with Zotero. If not, see . + + ***** END LICENSE BLOCK ***** +*/ +Components.utils.import("resource://gre/modules/Services.jsm"); + +var Zotero_ProgressBar = new function () { + var initialized, io; + + /** + * Pre-initialization, when the dialog has loaded but has not yet appeared + */ + this.onDOMContentLoaded = function(event) { + if(event.target === document) { + initialized = true; + io = window.arguments[0].wrappedJSObject; + if (io.onLoad) { + io.onLoad(_onProgress); + } + + // Only hide chrome on Windows or Mac + if(Zotero.isMac) { + document.documentElement.setAttribute("drawintitlebar", true); + } else if(Zotero.isWin) { + document.documentElement.setAttribute("hidechrome", true); + } + + new WindowDraggingElement(document.getElementById("quick-format-dialog"), window); + + } + }; + + /** + * Initialize add citation dialog + */ + this.onLoad = function(event) { + if(event.target !== document) return; + // make sure we are visible + window.setTimeout(function() { + // window.resizeTo(window.outerWidth, window.outerHeight); + var screenX = window.screenX; + var screenY = window.screenY; + var xRange = [window.screen.availLeft, window.screen.width-window.outerWidth]; + var yRange = [window.screen.availTop, window.screen.height-window.outerHeight]; + if (screenX < xRange[0] || screenX > xRange[1] || screenY < yRange[0] || screenY > yRange[1]) { + var targetX = Math.max(Math.min(screenX, xRange[1]), xRange[0]); + var targetY = Math.max(Math.min(screenY, yRange[1]), yRange[0]); + Zotero.debug("Moving window to "+targetX+", "+targetY); + window.moveTo(targetX, targetY); + } + }, 0); + + window.focus(); + }; + + /** + * Called when progress changes + */ + function _onProgress(percent) { + var meter = document.getElementById("quick-format-progress-meter"); + if(percent === null) { + meter.mode = "undetermined"; + } else { + meter.mode = "determined"; + meter.value = Math.round(percent); + } + } + + /** + * Resizes windows + * @constructor + */ + var Resizer = function(panel, targetWidth, targetHeight, pixelsPerStep, stepsPerSecond) { + this.panel = panel; + this.curWidth = panel.clientWidth; + this.curHeight = panel.clientHeight; + this.difX = (targetWidth ? targetWidth - this.curWidth : 0); + this.difY = (targetHeight ? targetHeight - this.curHeight : 0); + this.step = 0; + this.steps = Math.ceil(Math.max(Math.abs(this.difX), Math.abs(this.difY))/pixelsPerStep); + this.timeout = (1000/stepsPerSecond); + + var me = this; + this._animateCallback = function() { me.animate() }; + }; + + /** + * Performs a step of the animation + */ + Resizer.prototype.animate = function() { + if(this.stopped) return; + this.step++; + this.panel.sizeTo(this.curWidth+Math.round(this.step*this.difX/this.steps), + this.curHeight+Math.round(this.step*this.difY/this.steps)); + if(this.step !== this.steps) { + window.setTimeout(this._animateCallback, this.timeout); + } + }; + + /** + * Halts resizing + */ + Resizer.prototype.stop = function() { + this.stopped = true; + }; +} + +window.addEventListener("DOMContentLoaded", Zotero_ProgressBar.onDOMContentLoaded, false); +window.addEventListener("load", Zotero_ProgressBar.onLoad, false); diff --git a/chrome/content/zotero/integration/progressBar.xul b/chrome/content/zotero/integration/progressBar.xul new file mode 100644 index 0000000000..abbc0ab644 --- /dev/null +++ b/chrome/content/zotero/integration/progressBar.xul @@ -0,0 +1,51 @@ + + + + + + + + + + + +