Skip to content

Commit

Permalink
under review
Browse files Browse the repository at this point in the history
  • Loading branch information
elgiano committed Oct 23, 2020
1 parent 2a4937a commit 8fbbb3a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
3 changes: 2 additions & 1 deletion QtCollider/widgets/QcWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ bool WebView::event(QEvent* ev) {

void WebView::pageLoaded(bool ok) { this->focusProxy()->installEventFilter(this); }

void WebView::updateEditable() {
void WebView::setEditable(bool b) {
_editable = b;
if (_editable) {
page()->runJavaScript("document.documentElement.contentEditable = true");
} else {
Expand Down
12 changes: 4 additions & 8 deletions QtCollider/widgets/QcWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ public Q_SLOTS:

Q_PROPERTY(bool editable READ editable WRITE setEditable);
bool editable() const { return _editable; }
void setEditable(bool b) {
_editable = b;
updateEditable();
}
void setEditable(bool b);

// QWebEnginePage properties
Q_PROPERTY(QString requestedUrl READ requestedUrl)
Expand Down Expand Up @@ -135,15 +132,14 @@ public Q_SLOTS:
inline static QUrl urlFromString(const QString& str) { return QUrl::fromUserInput(str); }

protected:
virtual void contextMenuEvent(QContextMenuEvent*);
virtual bool event(QEvent* ev);
virtual bool eventFilter(QObject* obj, QEvent* event);
void contextMenuEvent(QContextMenuEvent*) override;
bool event(QEvent* ev) override;
bool eventFilter(QObject* obj, QEvent* event) override;

public Q_SLOTS:
void onPageReload();
void onRenderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus, int);
void onLinkClicked(const QUrl&, QWebEnginePage::NavigationType, bool);
void updateEditable();
void pageLoaded(bool);

private:
Expand Down
23 changes: 12 additions & 11 deletions SCClassLibrary/Common/GUI/Base/QWebView.sc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ WebView : View {
classvar urlHandlers;

var <onLoadFinished, <onLoadFailed, <onLoadProgress, <onLoadStarted, <onLinkActivated, <onLinkHovered, <onReloadTriggered, <onJavaScriptMsg,
<onSelectionChanged, <onTitleChanged, <onUrlChanged, <onScrollPositionChanged, <onContentsSizeChanged, <onAudioMutedChanged,
<onRecentlyAudibleChanged, <enterInterpretsSelection;
<onSelectionChanged, <onTitleChanged, <onUrlChanged, <onScrollPositionChanged, <onContentsSizeChanged, <onAudioMutedChanged,
<onRecentlyAudibleChanged, <enterInterpretsSelection = false;

*qtClass { ^'QtCollider::WebView'; }

Expand Down Expand Up @@ -226,23 +226,24 @@ WebView : View {

enterInterpretsSelection_ { |b|
enterInterpretsSelection = b;
if(enterInterpretsSelection){
this.keyDownAction = { arg view, char, mods, u, keycode, key;
if(enterInterpretsSelection) {
this.keyDownAction = { |view, char, mods, u, keycode, key|
// 01000004 is Qt's keycode for Enter, needed on Mac
if((char.ascii==13).or(key.asHexString == "01000004")){
if(mods.isShift){
view.runJavaScript("selectLine()",this.onInterpret(_));
}{
if(mods.isCtrl || mods.isCmd) {
view.runJavaScript("selectRegion()",this.onInterpret(_));
};
if((char == Char.ret).or(key == 0x01000004)){
case
{ mods.isShift } {
view.runJavaScript("selectLine()", this.onInterpret(_));
}
{ mods.isCtrl || mods.isCmd }{
view.runJavaScript("selectRegion()", this.onInterpret(_));
}
}
};
}{
this.keyDownAction = {}
}
}

editable { ^this.getProperty('editable') }
editable_ { |b| this.setProperty('editable', b) }

Expand Down
23 changes: 9 additions & 14 deletions editors/sc-ide/widgets/help_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ HelpBrowser::HelpBrowser(QWidget* parent): QWidget(parent) {
setLayout(layout);

connect(mWebView, SIGNAL(loadStarted()), mLoadProgressIndicator, SLOT(start()));
connect(mWebView, SIGNAL(loadFinished(bool)), mLoadProgressIndicator, SLOT(stop()));
connect(mWebView, SIGNAL(loadFinished(bool)), this, SLOT(onPageLoad()));
connect(mWebView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenuRequest(QPoint)));

Expand All @@ -99,7 +98,7 @@ HelpBrowser::HelpBrowser(QWidget* parent): QWidget(parent) {

// Delete the help browser's page to avoid an assert/crash during shutdown. See QTBUG-56441, QTBUG-50160.
// Note that putting this in the destructor doesn't work.
connect(QApplication::instance(), &QApplication::aboutToQuit, [=]() { delete mWebView->page(); });
connect(QApplication::instance(), &QApplication::aboutToQuit, [this]() { delete mWebView->page(); });

createActions();

Expand All @@ -109,14 +108,10 @@ HelpBrowser::HelpBrowser(QWidget* parent): QWidget(parent) {
}

void HelpBrowser::onPageLoad() {
mLoadProgressIndicator->stop();
// add these actions to weview's renderer, to capture shift+enter and possibly other swallowed shortcuts
((OverridingAction*)mActions[EvaluateRegion])->addToWidget(mWebView->focusProxy());
((OverridingAction*)mActions[Evaluate])->addToWidget(mWebView->focusProxy());

// unused: see HelpSource/scdoc.js and HelpSource/editor.js
if (mServerPort) {
mWebView->page()->runJavaScript(QString("setUpWebChannel(%1)").arg(mServerPort));
}
static_cast<OverridingAction*>(mActions[EvaluateRegion])->addToWidget(mWebView->focusProxy());
static_cast<OverridingAction*>(mActions[Evaluate])->addToWidget(mWebView->focusProxy());
}

void HelpBrowser::createActions() {
Expand All @@ -143,9 +138,9 @@ void HelpBrowser::createActions() {
ovrAction->addToWidget(this);

// eval actions are added to mWebView->focusProxy() in onPageLoad()
mActions[Evaluate] = ovrAction = new OverridingAction(tr("Evaluate as Code"), this);
mActions[Evaluate] = new OverridingAction(tr("Evaluate as Code"), this);
connect(ovrAction, SIGNAL(triggered()), this, SLOT(evaluateSelection()));
mActions[EvaluateRegion] = ovrAction = new OverridingAction(tr("Evaluate as Code Region"), this);
mActions[EvaluateRegion] = new OverridingAction(tr("Evaluate as Code Region"), this);
connect(mActions[EvaluateRegion], &OverridingAction::triggered, this, [=]() { this->evaluateSelection(true); });

// For the sake of display:
Expand Down Expand Up @@ -376,10 +371,10 @@ void HelpBrowser::onContextMenuRequest(const QPoint& pos) {
menu.addAction(mWebView->pageAction(QWebEnginePage::Forward));
menu.addAction(mWebView->pageAction(QWebEnginePage::Reload));

if (!contextData.selectedText().isEmpty())
menu.addAction(mActions[Evaluate]);
else
if (contextData.selectedText().isEmpty())
menu.addAction(mActions[EvaluateRegion]);
else
menu.addAction(mActions[Evaluate]);

menu.addSeparator();

Expand Down

0 comments on commit 8fbbb3a

Please sign in to comment.