Skip to content

Commit e17c60c

Browse files
committed
better context menu and Perl script settings check
1 parent 241e948 commit e17c60c

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

src/webengine-page.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public slots:
116116
}
117117

118118
if (settingsJsonObject["noLabel"].toString().length() > 0) {
119-
noLabel =settingsJsonObject["noLabel"].toString();
119+
noLabel = settingsJsonObject["noLabel"].toString();
120120
}
121121

122122
if (settingsJsonObject["cutLabel"].toString().length() > 0) {
@@ -230,11 +230,12 @@ public slots:
230230
QJsonDocument scriptJsonDocument =
231231
QJsonDocument::fromJson(
232232
scriptSettings.toString().toUtf8());
233-
QJsonObject scriptJsonObject = scriptJsonDocument.object();
234233

235-
scriptJsonObject["id"] = scriptObjectName;
236-
237-
qScriptStartedCheck(scriptJsonObject);
234+
if (!scriptJsonDocument.isEmpty()) {
235+
QJsonObject scriptJsonObject = scriptJsonDocument.object();
236+
scriptJsonObject["id"] = scriptObjectName;
237+
qScriptStartedCheck(scriptJsonObject);
238+
}
238239
});
239240
}
240241
}

src/webengine-view.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,22 @@ public slots:
7878
QWebEngineView::page()->contextMenuData();
7979
Q_ASSERT(contextMenuTest.isValid());
8080

81-
QMenu menu;
82-
8381
if (!contextMenuTest.isContentEditable() and
8482
contextMenuTest.selectedText().length() > 0) {
83+
QMenu menu;
84+
8585
QAction *copyAct = menu
8686
.addAction(qApp->property("copyLabel").toString());
8787
QObject::connect(copyAct, SIGNAL(triggered()),
8888
this, SLOT(qCopyAction()));
89+
90+
menu.exec(mapToGlobal(event->pos()));
91+
this->focusWidget();
8992
}
9093

9194
if (contextMenuTest.isContentEditable()) {
95+
QMenu menu;
96+
9297
QAction *cutAct = menu
9398
.addAction(qApp->property("cutLabel").toString());
9499
QObject::connect(cutAct, SIGNAL(triggered()),
@@ -108,10 +113,10 @@ public slots:
108113
.addAction(qApp->property("selectAllLabel").toString());
109114
QObject::connect(selectAllAct, SIGNAL(triggered()),
110115
this, SLOT(qSelectAllAction()));
111-
}
112116

113-
menu.exec(mapToGlobal(event->pos()));
114-
this->focusWidget();
117+
menu.exec(mapToGlobal(event->pos()));
118+
this->focusWidget();
119+
}
115120
}
116121
}
117122

src/webkit-page.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public slots:
9292
}
9393
}
9494

95+
// ==============================
96+
// Page settings handling:
97+
// ==============================
98+
9599
void qGetPageSettings(QVariant settingsJsResult) {
96100
QJsonDocument settingsJsonDocument =
97101
QJsonDocument::fromJson(settingsJsResult.toString().toUtf8());
@@ -121,7 +125,7 @@ public slots:
121125
}
122126

123127
if (settingsJsonObject["noLabel"].toString().length() > 0) {
124-
noLabel =settingsJsonObject["noLabel"].toString();
128+
noLabel = settingsJsonObject["noLabel"].toString();
125129
}
126130

127131
if (settingsJsonObject["cutLabel"].toString().length() > 0) {
@@ -227,17 +231,17 @@ public slots:
227231
{
228232
if (QPage::mainFrame()->url().scheme() == "file") {
229233
QVariant scriptSettings =
230-
mainFrame()->evaluateJavaScript("peb.getScriptSettings(" +
231-
scriptObjectName + ")");
234+
mainFrame()->evaluateJavaScript(
235+
"peb.getScriptSettings(" + scriptObjectName + ")");
232236

233237
QJsonDocument scriptJsonDocument =
234-
QJsonDocument::fromJson(
235-
scriptSettings.toString().toUtf8());
236-
QJsonObject scriptJsonObject = scriptJsonDocument.object();
237-
238-
scriptJsonObject["id"] = scriptObjectName;
238+
QJsonDocument::fromJson(scriptSettings.toString().toUtf8());
239239

240-
qScriptStartedCheck(scriptJsonObject);
240+
if (!scriptJsonDocument.isEmpty()) {
241+
QJsonObject scriptJsonObject = scriptJsonDocument.object();
242+
scriptJsonObject["id"] = scriptObjectName;
243+
qScriptStartedCheck(scriptJsonObject);
244+
}
241245
}
242246
}
243247

src/webkit-view.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ public slots:
7777
QWebHitTestResult contextMenuTest =
7878
mainPage->mainFrame()->hitTestContent(event->pos());
7979

80-
QMenu menu;
81-
8280
if (!contextMenuTest.isContentEditable() and
8381
contextMenuTest.isContentSelected()) {
82+
QMenu menu;
83+
8484
QAction *copyAct =
8585
menu.addAction(qApp->property("copyLabel").toString());
8686
QObject::connect(copyAct, SIGNAL(triggered()),
8787
this, SLOT(qCopyAction()));
88+
89+
menu.exec(mapToGlobal(event->pos()));
90+
this->focusWidget();
8891
}
8992

9093
if (contextMenuTest.isContentEditable()) {
94+
QMenu menu;
95+
9196
QAction *cutAct =
9297
menu.addAction(qApp->property("cutLabel").toString());
9398
QObject::connect(cutAct, SIGNAL(triggered()),
@@ -108,10 +113,10 @@ public slots:
108113
qApp->property("selectAllLabel").toString());
109114
QObject::connect(selectAllAct, SIGNAL(triggered()),
110115
this, SLOT(qSelectAllAction()));
111-
}
112116

113-
menu.exec(mapToGlobal(event->pos()));
114-
this->focusWidget();
117+
menu.exec(mapToGlobal(event->pos()));
118+
this->focusWidget();
119+
}
115120
}
116121
}
117122

0 commit comments

Comments
 (0)