worker job update, cancel

This commit is contained in:
Zira project 2020-02-20 17:14:52 +05:00
parent 7b3c4839af
commit 60f2fc12db
7 changed files with 188 additions and 15 deletions

View file

@ -29,6 +29,7 @@ SOURCES += \
src/fileiconprovider.cpp \
src/mainwindow.cpp \
src/helper.cpp \
src/progressinfo.cpp \
src/progressline.cpp \
src/settings.cpp \
src/editor.cpp \
@ -76,6 +77,7 @@ HEADERS += \
include/fileiconprovider.h \
include/mainwindow.h \
include/helper.h \
include/progressinfo.h \
include/progressline.h \
include/settings.h \
include/editor.h \

View file

@ -27,6 +27,7 @@
#include "spellcheckerinterface.h"
#include "quickaccess.h"
#include "progressline.h"
#include "progressinfo.h"
#include "popup.h"
#include "tabslist.h"
#include "types.h"
@ -158,7 +159,7 @@ private slots:
void parseMixedFinished(int tabIndex, ParsePHP::ParseResult result);
void parseJSFinished(int tabIndex, ParseJS::ParseResult result);
void parseCSSFinished(int tabIndex, ParseCSS::ParseResult result);
void parseProjectFinished();
void parseProjectFinished(bool success = true);
void projectCreateRequested(QString name, QString path, bool lintEnabled, bool csEnabled);
void projectEditRequested(QString name, QString path, bool lintEnabled, bool csEnabled);
void projectOpenRequested(QString path);
@ -207,6 +208,9 @@ private slots:
void outputActionTriggered(bool checked);
void activateProgressLine();
void deactivateProgressLine();
void activateProgressInfo(QString text);
void updateProgressInfo(QString text);
void deactivateProgressInfo();
void editorTabsResize();
void tabsListTriggered();
void tabsListSelected(int index);
@ -251,6 +255,7 @@ private:
QuickAccess * qa;
Popup * popup;
ProgressLine * progressLine;
ProgressInfo * progressInfo;
TabsList * tabsList;
QStringList args;
bool tmpDisableParser;

View file

@ -43,13 +43,14 @@ private:
bool isBusy;
int quickResultsCount;
bool quickBreaked;
bool wantStop;
signals:
void lintFinished(int tabIndex, QStringList errorTexts, QStringList errorLines, QString output);
void phpcsFinished(int tabIndex, QStringList errorTexts, QStringList errorLines);
void parseMixedFinished(int tabIndex, ParsePHP::ParseResult result);
void parseJSFinished(int tabIndex, ParseJS::ParseResult result);
void parseCSSFinished(int tabIndex, ParseCSS::ParseResult result);
void parseProjectFinished();
void parseProjectFinished(bool success = true);
void parseProjectProgress(int v);
void searchInFilesFound(QString file, QString lineText, int line, int symbol);
void searchInFilesFinished();
@ -60,6 +61,9 @@ signals:
void quickFound(QString text, QString info, QString file, int line);
void activateProgress();
void deactivateProgress();
void activateProgressInfo(QString text);
void deactivateProgressInfo();
void updateProgressInfo(QString text);
public slots:
void disable();
void lint(int tabIndex, QString path);
@ -73,6 +77,7 @@ public slots:
void serversCommand(QString command, QString pwd);
void sassCommand(QString src, QString dst);
void quickFind(QString dir, QString text, WordsMapList words, QStringList wordPrefixes);
void cancelRequested();
};
#endif // PARSERWORKER_H

29
include/progressinfo.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef PROGRESSINFO_H
#define PROGRESSINFO_H
#include <QWidget>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include "settings.h"
class ProgressInfo : public QWidget
{
Q_OBJECT
public:
explicit ProgressInfo(Settings * settings, QWidget *parent = nullptr);
void setText(QString text);
void activate();
void deactivate();
void updateGeometry(int x, int y, int w, int h);
private:
QHBoxLayout * layout;
QLabel * label;
QToolButton * btn;
signals:
void cancelTriggered();
public slots:
void cancelPressed();
};
#endif // PROGRESSINFO_H

View file

@ -216,6 +216,7 @@ MainWindow::MainWindow(QWidget *parent) :
// progress line
progressLine = new ProgressLine(settings, this);
progressInfo = new ProgressInfo(settings, this);
// enable php lint & cs
parsePHPLintEnabled = false;
@ -261,12 +262,13 @@ MainWindow::MainWindow(QWidget *parent) :
connect(this, SIGNAL(serversCommand(QString, QString)), parserWorker, SLOT(serversCommand(QString,QString)));
connect(this, SIGNAL(sassCommand(QString, QString)), parserWorker, SLOT(sassCommand(QString,QString)));
connect(this, SIGNAL(quickFind(QString, QString, WordsMapList, QStringList)), parserWorker, SLOT(quickFind(QString, QString, WordsMapList, QStringList)));
connect(progressInfo, SIGNAL(cancelTriggered()), parserWorker, SLOT(cancelRequested()));
connect(parserWorker, SIGNAL(lintFinished(int,QStringList,QStringList,QString)), this, SLOT(parseLintFinished(int,QStringList,QStringList,QString)));
connect(parserWorker, SIGNAL(phpcsFinished(int,QStringList,QStringList)), this, SLOT(parsePHPCSFinished(int,QStringList,QStringList)));
connect(parserWorker, SIGNAL(parseMixedFinished(int,ParsePHP::ParseResult)), this, SLOT(parseMixedFinished(int,ParsePHP::ParseResult)));
connect(parserWorker, SIGNAL(parseJSFinished(int,ParseJS::ParseResult)), this, SLOT(parseJSFinished(int,ParseJS::ParseResult)));
connect(parserWorker, SIGNAL(parseCSSFinished(int,ParseCSS::ParseResult)), this, SLOT(parseCSSFinished(int,ParseCSS::ParseResult)));
connect(parserWorker, SIGNAL(parseProjectFinished()), this, SLOT(parseProjectFinished()));
connect(parserWorker, SIGNAL(parseProjectFinished(bool)), this, SLOT(parseProjectFinished(bool)));
connect(parserWorker, SIGNAL(parseProjectProgress(int)), this, SLOT(sidebarProgressChanged(int)));
connect(parserWorker, SIGNAL(searchInFilesFound(QString,QString,int,int)), this, SLOT(searchInFilesFound(QString,QString,int,int)));
connect(parserWorker, SIGNAL(searchInFilesFinished()), this, SLOT(searchInFilesFinished()));
@ -277,6 +279,9 @@ MainWindow::MainWindow(QWidget *parent) :
connect(parserWorker, SIGNAL(quickFound(QString,QString,QString,int)), qa, SLOT(quickFound(QString,QString,QString,int)));
connect(parserWorker, SIGNAL(activateProgress()), this, SLOT(activateProgressLine()));
connect(parserWorker, SIGNAL(deactivateProgress()), this, SLOT(deactivateProgressLine()));
connect(parserWorker, SIGNAL(activateProgressInfo(QString)), this, SLOT(activateProgressInfo(QString)));
connect(parserWorker, SIGNAL(deactivateProgressInfo()), this, SLOT(deactivateProgressInfo()));
connect(parserWorker, SIGNAL(updateProgressInfo(QString)), this, SLOT(updateProgressInfo(QString)));
parserThread.start();
tmpDisableParser = false;
@ -1445,6 +1450,7 @@ void MainWindow::resizeEvent(QResizeEvent *event)
{
hideQAPanel();
progressLine->updateGeometry(ui->menuBar->geometry().x(), ui->menuBar->geometry().y() + ui->menuBar->geometry().height(), ui->menuBar->geometry().width());
progressInfo->updateGeometry(ui->statusBar->geometry().x(), ui->statusBar->geometry().y(), ui->statusBar->width(), ui->statusBar->height());
updateTabsListButton();
QMainWindow::resizeEvent(event);
}
@ -1726,15 +1732,17 @@ void MainWindow::parseCSSFinished(int tabIndex, ParseCSS::ParseResult result)
qa->setParseResult(result, textEditor->getFileName());
}
void MainWindow::parseProjectFinished()
void MainWindow::parseProjectFinished(bool success)
{
setStatusBarText(tr("Loading project..."));
reloadWords();
project->loadWords(completeWords, highlightWords, helpWords);
if (success) {
setStatusBarText(tr("Loading project..."));
reloadWords();
project->loadWords(completeWords, highlightWords, helpWords);
}
setStatusBarText(tr(""));
if (ui->sidebarProgressBarWrapperWidget->isVisible()) ui->sidebarProgressBarWrapperWidget->hide();
editorTabs->initHighlighters();
showPopupText(tr("Project '%1' updated").arg(project->getName()));
if (success) showPopupText(tr("Project '%1' updated").arg(project->getName()));
}
void MainWindow::projectCreateRequested(QString name, QString path, bool lintEnabled, bool csEnabled)
@ -2177,6 +2185,22 @@ void MainWindow::deactivateProgressLine()
progressLine->deactivate();
}
void MainWindow::activateProgressInfo(QString text)
{
progressInfo->setText(text);
progressInfo->activate();
}
void MainWindow::deactivateProgressInfo()
{
progressInfo->deactivate();
}
void MainWindow::updateProgressInfo(QString text)
{
progressInfo->setText(text);
}
void MainWindow::updateTabsListButton()
{
if (ui->tabWidget->count() > 1) tabsListButton->show();

View file

@ -96,6 +96,7 @@ ParserWorker::ParserWorker(Settings * settings, QObject *parent) : QObject(paren
isBusy = false;
quickResultsCount = 0;
quickBreaked = false;
wantStop = false;
}
void ParserWorker::disable()
@ -201,26 +202,37 @@ void ParserWorker::parseProject(QString path)
return;
}
isBusy = true;
wantStop = false;
QStringList files;
emit activateProgress();
emit activateProgressInfo(tr("Scanning")+": "+path);
parseProjectDir(path, files);
QVariantMap map = Project::createPHPResultMap();
QVariantMap data = Project::loadPHPDataMap(path);
Project::checkParsePHPFilesModified(files, data, map);
bool isBreaked = false;
for (int i=0; i<files.size(); i++) {
if (!enabled) break;
if (!enabled || wantStop) {
isBreaked = true;
break;
}
QString file = files.at(i);
parseProjectFile(file, map);
int v = (i + 1) * 100 / files.size();
emit parseProjectProgress(v);
}
Project::savePHPResults(path, map);
if (!isBreaked) {
emit updateProgressInfo(tr("Updating project")+"...");
Project::savePHPResults(path, map);
}
map.clear();
data.clear();
files.clear();
emit parseProjectFinished();
emit parseProjectFinished(!isBreaked);
emit deactivateProgress();
emit deactivateProgressInfo();
isBusy = false;
wantStop = false;
}
void ParserWorker::parseProjectDir(QString dir, QStringList & files)
@ -242,6 +254,7 @@ void ParserWorker::parseProjectFile(QString file, QVariantMap & map)
{
QCoreApplication::processEvents();
if (!Helper::fileExists(file)) return;
emit updateProgressInfo(tr("Scanning")+": "+file);
QString content = Helper::loadTextFile(file, encoding, encodingFallback, true);
ParsePHP parser;
ParsePHP::ParseResult result = parser.parse(content);
@ -258,8 +271,10 @@ void ParserWorker::searchInFiles(QString searchDirectory, QString searchText, QS
return;
}
isBusy = true;
wantStop = false;
if (!Helper::folderExists(searchDirectory) || searchText.size() == 0) return;
emit activateProgress();
emit activateProgressInfo(tr("Searching in")+": "+searchDirectory);
QString allowedExtensions = "";
QStringList searchExtensionsList = searchExtensions.split(",");
for (int i=0; i<searchExtensionsList.size(); i++) {
@ -276,7 +291,9 @@ void ParserWorker::searchInFiles(QString searchDirectory, QString searchText, QS
searchInDir(searchDirectory, searchText, allowedExtensions, searchOptionCase, searchOptionWord, searchOptionRegexp, excludeDirs);
emit searchInFilesFinished();
emit deactivateProgress();
emit deactivateProgressInfo();
isBusy = false;
wantStop = false;
}
void ParserWorker::searchInDir(QString searchDirectory, QString searchText, QString searchExtensions, bool searchOptionCase, bool searchOptionWord, bool searchOptionRegexp, QStringList excludeDirs)
@ -284,7 +301,7 @@ void ParserWorker::searchInDir(QString searchDirectory, QString searchText, QStr
QDirIterator it(searchDirectory, QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
while (it.hasNext()) {
if (!enabled) break;
if (searchBreaked) break;
if (searchBreaked || wantStop) break;
QString path = it.next();
QFileInfo fInfo(path);
if (!fInfo.exists() || !fInfo.isReadable()) continue;
@ -309,6 +326,7 @@ void ParserWorker::searchInFile(QString file, QString searchText, bool searchOpt
{
QCoreApplication::processEvents();
if (!Helper::fileExists(file) || searchText.size() == 0) return;
emit updateProgressInfo(tr("Searching in")+": "+file);
QString content = Helper::loadTextFile(file, encoding, encodingFallback, true);
Parse parser;
if (!searchOptionWord && !searchOptionRegexp) {
@ -316,7 +334,7 @@ void ParserWorker::searchInFile(QString file, QString searchText, bool searchOpt
int p = -1, offset = 0;
Qt::CaseSensitivity cs = searchOptionCase ? Qt::CaseSensitive : Qt::CaseInsensitive;
do {
if (searchBreaked) break;
if (searchBreaked || wantStop) break;
p = content.indexOf(searchText, offset, cs);
if (p >= 0) {
offset = p + searchText.size();
@ -333,7 +351,7 @@ void ParserWorker::searchInFile(QString file, QString searchText, bool searchOpt
QRegularExpression regexp = QRegularExpression("\\b"+QRegularExpression::escape(searchText)+"\\b", opt);
if (!regexp.isValid()) return;
do {
if (searchBreaked) break;
if (searchBreaked || wantStop) break;
QRegularExpressionMatch match = regexp.match(content, offset);
p = match.capturedStart();
if (p >= 0) {
@ -351,7 +369,7 @@ void ParserWorker::searchInFile(QString file, QString searchText, bool searchOpt
QRegularExpression regexp = QRegularExpression(searchText, opt);
if (!regexp.isValid()) return;
do {
if (searchBreaked) break;
if (searchBreaked || wantStop) break;
QRegularExpressionMatch match = regexp.match(content, offset);
p = match.capturedStart();
if (p >= 0) {
@ -554,3 +572,8 @@ void ParserWorker::quickFindInDir(QString startDir, QString dir, QString text)
}
}
}
void ParserWorker::cancelRequested()
{
wantStop = true;
}

85
src/progressinfo.cpp Normal file
View file

@ -0,0 +1,85 @@
#include "progressinfo.h"
#include <QFontDatabase>
const int BORDER = 1;
const int PADDING = 5;
ProgressInfo::ProgressInfo(Settings * settings, QWidget *parent) : QWidget(parent)
{
std::string bgColorStr = settings->get("popup_bg_color");
std::string colorStr = settings->get("popup_color");
QFont popupFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
std::string fontFamily = settings->get("editor_font_family");
std::string fontSize = settings->get("editor_tooltip_font_size");
if (fontFamily.size() > 0) {
popupFont.setStyleHint(QFont::Monospace);
popupFont.setFamily(QString::fromStdString(fontFamily));
}
popupFont.setPointSize(std::stoi(fontSize));
popupFont.setStyleName("");
QFontMetrics fm(popupFont);
int height = fm.height();
setMinimumHeight(height);
layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setMargin(0);
layout->setSpacing(0);
layout->setSizeConstraint(QLayout::SetMaximumSize);
label = new QLabel();
label->setWordWrap(false);
label->setMinimumHeight(height);
label->setTextFormat(Qt::PlainText);
label->setFont(popupFont);
label->setContentsMargins(PADDING, 0, PADDING, 0);
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
label->setStyleSheet("background:"+QString::fromStdString(bgColorStr)+";color:"+QString::fromStdString(colorStr)+";");
layout->addWidget(label);
btn = new QToolButton();
btn->setIcon(QIcon(":/icons/close.png"));
btn->setMinimumWidth(height);
btn->setMinimumHeight(height);
btn->setToolTip(tr("Cancel"));
btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
layout->addWidget(btn);
setLayout(layout);
connect(btn, SIGNAL(pressed()), this, SLOT(cancelPressed()));
setStyleSheet("background:"+QString::fromStdString(bgColorStr)+";border:"+QString::number(BORDER)+"px solid "+QString::fromStdString(bgColorStr)+";");
hide();
}
void ProgressInfo::setText(QString text)
{
label->setText(text);
}
void ProgressInfo::activate()
{
show();
raise();
}
void ProgressInfo::deactivate()
{
hide();
}
void ProgressInfo::cancelPressed()
{
emit cancelTriggered();
}
void ProgressInfo::updateGeometry(int x, int y, int w, int h)
{
setGeometry(x, y, w, h);
}