1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

[sourceviewer] Option to load edited source code in page.

Also fixed showing AdBlock css rules when reloading source.
This commit is contained in:
nowrep 2013-02-05 15:17:36 +01:00
parent dfb69be90e
commit fc41e1516d
3 changed files with 29 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -68,6 +68,7 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml)
QzTools::centerWidgetToParent(this, frame->page()->view());
QMenu* menuFile = new QMenu(tr("File"));
menuFile->addAction(tr("Load in page"), this, SLOT(loadInPage()));
menuFile->addAction(QIcon::fromTheme("document-save"), tr("Save as..."), this, SLOT(save()))->setShortcut(QKeySequence("Ctrl+S"));
menuFile->addSeparator();
menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close"), this, SLOT(close()))->setShortcut(QKeySequence("Ctrl+W"));
@ -130,6 +131,17 @@ void SourceViewer::pasteAvailable()
m_actionPaste->setEnabled(m_sourceEdit->canPaste());
}
void SourceViewer::loadInPage()
{
if (m_frame) {
m_frame.data()->setHtml(m_sourceEdit->toPlainText(), m_frame.data()->baseUrl());
m_statusBar->showMessage(tr("Source loaded in page"));
}
else {
m_statusBar->showMessage(tr("Cannot load in page. Page has been closed."));
}
}
void SourceViewer::loadSource()
{
m_actionUndo->setEnabled(false);
@ -143,7 +155,7 @@ void SourceViewer::loadSource()
html.remove(QRegExp("<style type=\"text/css\">\n/\\* AdBlock for QupZilla \\*/\n.*\\{display: none !important;\\}\n</style>"));
m_sourceEdit->setPlainText(html);
//Highlight selectedHtml
// Highlight selectedHtml
if (!m_selectedHtml.isEmpty()) {
m_sourceEdit->find(m_selectedHtml, QTextDocument::FindWholeWords);
}
@ -187,7 +199,7 @@ void SourceViewer::reload()
{
if (m_frame) {
m_sourceEdit->clear();
m_sourceEdit->setPlainText(m_frame.data()->toHtml());
loadSource();
m_statusBar->showMessage(tr("Source reloaded"));
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -42,6 +42,7 @@ private slots:
void undoAvailable(bool available);
void pasteAvailable();
void loadInPage();
void loadSource();
void save();
void findText();

View File

@ -4198,6 +4198,18 @@ After adding or removing certificate paths, it is neccessary to restart QupZilla
<source>Enter line number</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Load in page</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Source loaded in page</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Cannot load in page. Page has been closed.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SourceViewerSearch</name>