mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-05 21:41:11 +02:00
Fix occasional crash on creating overlay tool windows
This commit is contained in:
parent
091e34e792
commit
28f25489f8
2 changed files with 39 additions and 32 deletions
|
@ -17,7 +17,6 @@ Windows.Window {
|
||||||
visible: false
|
visible: false
|
||||||
width: 384; height: 640;
|
width: 384; height: 640;
|
||||||
title: "Tools"
|
title: "Tools"
|
||||||
property string newTabSource
|
|
||||||
property alias tabView: tabView
|
property alias tabView: tabView
|
||||||
onParentChanged: {
|
onParentChanged: {
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
@ -32,26 +31,21 @@ Windows.Window {
|
||||||
property alias y: toolWindow.y
|
property alias y: toolWindow.y
|
||||||
}
|
}
|
||||||
|
|
||||||
property var webTabCreator: Component {
|
|
||||||
Controls.WebView {
|
|
||||||
id: webView
|
|
||||||
property string originalUrl;
|
|
||||||
|
|
||||||
// Both toolWindow.newTabSource and url can change, so we need
|
|
||||||
// to store the original url here, without creating any bindings
|
|
||||||
Component.onCompleted: {
|
|
||||||
originalUrl = toolWindow.newTabSource;
|
|
||||||
url = originalUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TabView {
|
TabView {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
id: tabView;
|
id: tabView;
|
||||||
onCountChanged: {
|
Repeater {
|
||||||
if (0 == count) {
|
model: 4
|
||||||
toolWindow.visible = false
|
Tab {
|
||||||
|
active: true
|
||||||
|
enabled: false;
|
||||||
|
// we need to store the original url here for future identification
|
||||||
|
property string originalUrl: "";
|
||||||
|
onEnabledChanged: toolWindow.updateVisiblity();
|
||||||
|
Controls.WebView {
|
||||||
|
id: webView;
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,8 +62,7 @@ Windows.Window {
|
||||||
function findIndexForUrl(source) {
|
function findIndexForUrl(source) {
|
||||||
for (var i = 0; i < tabView.count; ++i) {
|
for (var i = 0; i < tabView.count; ++i) {
|
||||||
var tab = tabView.getTab(i);
|
var tab = tabView.getTab(i);
|
||||||
if (tab && tab.item && tab.item.originalUrl &&
|
if (tab.originalUrl === source) {
|
||||||
tab.item.originalUrl === source) {
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,21 +94,32 @@ Windows.Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findFreeTab() {
|
||||||
|
for (var i = 0; i < tabView.count; ++i) {
|
||||||
|
var tab = tabView.getTab(i);
|
||||||
|
if (tab && !tab.originalUrl || tab.originalUrl === "") {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.warn("Could not find free tab");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
function removeTabForUrl(source) {
|
function removeTabForUrl(source) {
|
||||||
var index = findIndexForUrl(source);
|
var index = findIndexForUrl(source);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tab = tabView.getTab(index);
|
var tab = tabView.getTab(index);
|
||||||
tab.enabledChanged.disconnect(updateVisiblity);
|
tab.title = "";
|
||||||
tabView.removeTab(index);
|
tab.originalUrl = "";
|
||||||
console.log("Updating visibility based on child tab removed");
|
tab.enabled = false;
|
||||||
updateVisiblity();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addWebTab(properties) {
|
function addWebTab(properties) {
|
||||||
if (!properties.source) {
|
if (!properties.source) {
|
||||||
console.warn("Attempted to open Web Tool Pane without URl")
|
console.warn("Attempted to open Web Tool Pane without URL")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,11 +129,17 @@ Windows.Window {
|
||||||
return tabView.getTab(existingTabIndex);
|
return tabView.getTab(existingTabIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
var title = properties.title || "Unknown";
|
var freeTabIndex = findFreeTab();
|
||||||
newTabSource = properties.source;
|
if (freeTabIndex === -1) {
|
||||||
var newTab = tabView.addTab(title, webTabCreator);
|
console.warn("Unable to add new tab");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newTab = tabView.getTab(freeTabIndex);
|
||||||
|
newTab.title = properties.title || "Unknown";
|
||||||
|
newTab.originalUrl = properties.source;
|
||||||
|
newTab.item.url = properties.source;
|
||||||
newTab.active = true;
|
newTab.active = true;
|
||||||
newTab.enabled = false;
|
|
||||||
|
|
||||||
if (properties.width) {
|
if (properties.width) {
|
||||||
tabView.width = Math.min(Math.max(tabView.width, properties.width),
|
tabView.width = Math.min(Math.max(tabView.width, properties.width),
|
||||||
|
|
|
@ -172,7 +172,6 @@ QScriptValue QmlWindowClass::internalConstructor(const QString& qmlSource,
|
||||||
setupServer();
|
setupServer();
|
||||||
retVal = builder(newTab);
|
retVal = builder(newTab);
|
||||||
retVal->_toolWindow = true;
|
retVal->_toolWindow = true;
|
||||||
offscreenUi->getRootContext()->engine()->setObjectOwnership(retVal->_qmlWindow, QQmlEngine::CppOwnership);
|
|
||||||
registerObject(url.toLower(), retVal);
|
registerObject(url.toLower(), retVal);
|
||||||
return QVariant();
|
return QVariant();
|
||||||
});
|
});
|
||||||
|
@ -330,10 +329,8 @@ void QmlWindowClass::close() {
|
||||||
if (_qmlWindow) {
|
if (_qmlWindow) {
|
||||||
if (_toolWindow) {
|
if (_toolWindow) {
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
auto qmlWindow = _qmlWindow;
|
|
||||||
offscreenUi->executeOnUiThread([=] {
|
offscreenUi->executeOnUiThread([=] {
|
||||||
auto toolWindow = offscreenUi->getToolWindow();
|
auto toolWindow = offscreenUi->getToolWindow();
|
||||||
offscreenUi->getRootContext()->engine()->setObjectOwnership(qmlWindow, QQmlEngine::JavaScriptOwnership);
|
|
||||||
auto invokeResult = QMetaObject::invokeMethod(toolWindow, "removeTabForUrl", Qt::DirectConnection,
|
auto invokeResult = QMetaObject::invokeMethod(toolWindow, "removeTabForUrl", Qt::DirectConnection,
|
||||||
Q_ARG(QVariant, _source));
|
Q_ARG(QVariant, _source));
|
||||||
Q_ASSERT(invokeResult);
|
Q_ASSERT(invokeResult);
|
||||||
|
|
Loading…
Reference in a new issue