diff --git a/.gitignore b/.gitignore index 4a8ad08..d146f14 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ mugi-grep .qmake.stash *.zip .vscode/ +bundle.cpp diff --git a/3rdparty/orderedmap.h b/3rdparty/orderedmap.h deleted file mode 100644 index eaf4caf..0000000 --- a/3rdparty/orderedmap.h +++ /dev/null @@ -1,630 +0,0 @@ -#ifndef ORDEREDMAP_H -#define ORDEREDMAP_H - -#include -#include -#include -#include -#include - -#ifdef Q_COMPILER_INITIALIZER_LISTS -#include -#endif - -template inline bool oMHashEqualToKey(const Key &key1, const Key &key2) -{ - // Key type must provide '==' operator - return key1 == key2; -} - -template inline bool oMHashEqualToKey(Ptr *key1, Ptr *key2) -{ - Q_ASSERT(sizeof(quintptr) == sizeof(Ptr *)); - return quintptr(key1) == quintptr(key2); -} - -template inline bool oMHashEqualToKey(const Ptr *key1, const Ptr *key2) -{ - Q_ASSERT(sizeof(quintptr) == sizeof(const Ptr *)); - return quintptr(key1) == quintptr(key2); -} - -template -class OrderedMap -{ - class OMHash; - - typedef typename QLinkedList::iterator QllIterator; - typedef typename QLinkedList::const_iterator QllConstIterator; - typedef QPair OMHashValue; - - typedef typename OMHash::iterator OMHashIterator; - typedef typename OMHash::const_iterator OMHashConstIterator; - -public: - - class iterator; - class const_iterator; - - typedef typename OrderedMap::iterator Iterator; - typedef typename OrderedMap::const_iterator ConstIterator; - - explicit OrderedMap(); - -#ifdef Q_COMPILER_INITIALIZER_LISTS - OrderedMap(std::initializer_list > list); -#endif - - OrderedMap(const OrderedMap& other); - -#if (QT_VERSION >= 0x050200) - OrderedMap(OrderedMap&& other); -#endif - - void clear(); - - bool contains(const Key &key) const; - - int count() const; - - bool empty() const; - - iterator insert(const Key &key, const Value &value); - - bool isEmpty() const; - - QList keys() const; - - int remove(const Key &key); - - int size() const; - - Value take(const Key &key); - - Value value(const Key &key) const; - - Value value(const Key &key, const Value &defaultValue) const; - - QList values() const; - - OrderedMap & operator=(const OrderedMap& other); - -#if (QT_VERSION >= 0x050200) - OrderedMap & operator=(OrderedMap&& other); -#endif - - bool operator==(const OrderedMap &other) const; - - bool operator!=(const OrderedMap &other) const; - - Value& operator[](const Key &key); - - const Value operator[](const Key &key) const; - - iterator begin(); - - const_iterator begin() const; - - iterator end(); - - const_iterator end() const; - - iterator erase(iterator pos); - - iterator find(const Key& key); - - const_iterator find(const Key& key) const; - - class const_iterator; - - class iterator - { - QllIterator qllIter; - OMHash *data; - friend class const_iterator; - friend class OrderedMap; - - public: - iterator() : data(NULL) {} - - iterator(const QllIterator &qllIter, OMHash *data) : - qllIter(qllIter), data(data) {} - - const Key & key() const - { - return *qllIter; - } - - Value & value() const - { - OMHashIterator hit = data->find(*qllIter); - OMHashValue &pair = hit.value(); - return pair.first; - } - - Value & operator*() const - { - return value(); - } - - iterator operator+(int i) const - { - QllIterator q = qllIter; - q += i; - - return iterator(q, data); - } - - iterator operator-(int i) const - { - return operator +(- i); - } - - iterator& operator+=(int i) - { - qllIter += i; - return *this; - } - - iterator& operator-=(int i) - { - qllIter -= i; - return *this; - } - - iterator& operator++() - { - ++qllIter; - return *this; - } - - iterator operator++(int) - { - iterator it = *this; - qllIter++; - return it; - } - - iterator operator--() - { - --qllIter; - return *this; - } - - iterator operator--(int) - { - iterator it = *this; - qllIter--; - return it; - } - - bool operator ==(const iterator &other) const - { - return (qllIter == other.qllIter); - } - - bool operator !=(const iterator &other) const - { - return (qllIter != other.qllIter); - } - }; - - class const_iterator - { - - QllConstIterator qllConstIter; - const OMHash *data; - - public: - const_iterator() : data(NULL) {} - - const_iterator(const iterator &i) : - qllConstIter(i.qllIter), data(i.data) {} - - const_iterator(const QllConstIterator &qllConstIter, const OMHash* data) : - qllConstIter(qllConstIter), data(data) {} - - const Key & key() const - { - return *qllConstIter; - } - - const Value & value() const - { - OMHashConstIterator hit = data->find(*qllConstIter); - const OMHashValue &pair = hit.value(); - return pair.first; - } - - const Value & operator*() const - { - return value(); - } - - const_iterator operator+(int i) const - { - QllConstIterator q = qllConstIter; - q += i; - - return const_iterator(q, data); - } - - const_iterator operator-(int i) const - { - return operator +(- i); - } - - const_iterator& operator+=(int i) - { - qllConstIter += i; - return *this; - } - - const_iterator& operator-=(int i) - { - qllConstIter -= i; - return *this; - } - - const_iterator& operator++() - { - ++qllConstIter; - return *this; - } - - const_iterator operator++(int) - { - const_iterator it = *this; - qllConstIter++; - return it; - } - - const_iterator operator--() - { - --qllConstIter; - return *this; - } - - const_iterator operator--(int) - { - const_iterator it = *this; - qllConstIter--; - return it; - } - - bool operator ==(const const_iterator &other) const - { - return (qllConstIter == other.qllConstIter); - } - - bool operator !=(const const_iterator &other) const - { - return (qllConstIter != other.qllConstIter); - } - }; - -private: - - class OMHash : public QHash - { - public: - bool operator == (const OMHash &other) const - { - if (size() != other.size()) { - return false; - } - - if (QHash::operator ==(other)) { - return true; - } - - typename QHash::const_iterator it1 = this->constBegin(); - typename QHash::const_iterator it2 = other.constBegin(); - - while(it1 != this->end()) { - OMHashValue v1 = it1.value(); - OMHashValue v2 = it2.value(); - - if ((v1.first != v2.first) || !oMHashEqualToKey(it1.key(), it2.key())) { - return false; - } - ++it1; - ++it2; - } - return true; - } - }; - -private: - void copy(const OrderedMap &other); - - OMHash data; - QLinkedList insertOrder; -}; - -template -OrderedMap::OrderedMap() {} - -#ifdef Q_COMPILER_INITIALIZER_LISTS -template -OrderedMap::OrderedMap(std::initializer_list > list) -{ - typedef typename std::initializer_list >::const_iterator const_initlist_iter; - for (const_initlist_iter it = list.begin(); it != list.end(); ++it) - insert(it->first, it->second); -} -#endif - - -template -OrderedMap::OrderedMap(const OrderedMap& other) -{ - copy(other); -} - -#if (QT_VERSION >= 0x050200) -template -OrderedMap::OrderedMap(OrderedMap&& other) -{ - data = std::move(other.data); - insertOrder = std::move(other.insertOrder); -} -#endif - -template -void OrderedMap::clear() -{ - data.clear(); - insertOrder.clear(); -} - -template -bool OrderedMap::contains(const Key &key) const -{ - return data.contains(key); -} - -template -int OrderedMap::count() const -{ - return data.count(); -} - -template -bool OrderedMap::empty() const -{ - return data.empty(); -} - -template -typename OrderedMap::iterator OrderedMap::insert(const Key &key, const Value &value) -{ - OMHashIterator it = data.find(key); - - if (it == data.end()) { - // New key - QllIterator ioIter = insertOrder.insert(insertOrder.end(), key); - OMHashValue pair(value, ioIter); - data.insert(key, pair); - return iterator(ioIter, &data); - } - - OMHashValue pair = it.value(); - // remove old reference - insertOrder.erase(pair.second); - // Add new reference - QllIterator ioIter = insertOrder.insert(insertOrder.end(), key); - pair.first = value; - pair.second = ioIter; - return iterator(ioIter, &data); -} - -template -bool OrderedMap::isEmpty() const -{ - return data.isEmpty(); -} - -template -QList OrderedMap::keys() const -{ - return QList::fromStdList(insertOrder.toStdList()); -} - -template -int OrderedMap::remove(const Key &key) -{ - OMHashIterator it = data.find(key); - if (it == data.end()) { - return 0; - } - OMHashValue pair = it.value(); - insertOrder.erase(pair.second); - data.erase(it); - return 1; -} - -template -int OrderedMap::size() const -{ - return data.size(); -} - -template -void OrderedMap::copy(const OrderedMap &other) -{ - /* Since I'm storing iterators of QLinkedList, I simply cannot make - * a trivial copy of the linked list. This is a limitation due to implicit - * sharing used in Qt containers, due to which iterator active on one - * QLL can change the data of another QLL even after creating a copy. - * - * Because of this, the old iterators have to be invalidated and new ones - * have to be generated. - */ - insertOrder.clear(); - // Copy hash - data = other.data; - - QllConstIterator cit = other.insertOrder.begin(); - for (; cit != other.insertOrder.end(); ++cit) { - Key key = *cit; - QllIterator ioIter = insertOrder.insert(insertOrder.end(), key); - OMHashIterator it = data.find(key); - (*it).second = ioIter; - } -} - -template -Value OrderedMap::take(const Key &key) -{ - OMHashIterator it = data.find(key); - if (it == data.end()) { - return Value(); - } - OMHashValue pair = it.value(); - insertOrder.erase(pair.second); - data.erase(it); - return pair.first; -} - -template -Value OrderedMap::value(const Key &key) const -{ - return data.value(key).first; -} - -template -Value OrderedMap::value(const Key &key, const Value &defaultValue) const -{ - OMHashConstIterator it = data.constFind(key); - if (it == data.end()) { - return defaultValue; - } - OMHashValue pair = it.value(); - return pair.first; -} - -template -QList OrderedMap::values() const -{ - QList values; - foreach (const Key &key, insertOrder.toStdList()) { - OMHashValue v = data.value(key); - values.append(v.first); - } - return values; -} - -template -OrderedMap & OrderedMap::operator=(const OrderedMap& other) -{ - if (this != &other) { - copy(other); - } - return *this; -} - -#if (QT_VERSION >= 0x050200) -template -OrderedMap & OrderedMap::operator=(OrderedMap&& other) -{ - if (this != &other) { - data = other.data; - insertOrder = other.insertOrder; - } - return *this; -} -#endif - -template -bool OrderedMap::operator==(const OrderedMap &other) const -{ - // 2 Ordered maps are equal if they have the same contents in the same order - return ((data == other.data) && (insertOrder == other.insertOrder)); -} - -template -bool OrderedMap::operator!=(const OrderedMap &other) const -{ - return ((data != other.data) || (insertOrder != other.insertOrder)); -} - -template -Value& OrderedMap::operator[](const Key &key) -{ - OMHashIterator it = data.find(key); - if (it == data.end()) { - insert(key, Value()); - it = data.find(key); - } - OMHashValue &pair = it.value(); - return pair.first; -} - -template -const Value OrderedMap::operator[](const Key &key) const -{ - return value(key); -} - -template -typename OrderedMap::iterator OrderedMap::begin() -{ - return iterator(insertOrder.begin(), &data); -} - -template -typename OrderedMap::const_iterator OrderedMap::begin() const -{ - return const_iterator(insertOrder.begin(), &data); -} - - -template -typename OrderedMap::iterator OrderedMap::end() -{ - return iterator(insertOrder.end(), &data); -} - -template -typename OrderedMap::const_iterator OrderedMap::end() const -{ - return const_iterator(insertOrder.end(), &data); -} - -template -typename OrderedMap::iterator OrderedMap::erase(iterator pos) -{ - OMHashIterator hit = data.find(*(pos.qllIter)); - if (hit == data.end()) { - return pos; - } - data.erase(hit); - QllIterator ioIter = insertOrder.erase(pos.qllIter); - - return iterator(ioIter, &data); -} - -template -typename OrderedMap::iterator OrderedMap::find(const Key& key) -{ - OMHashIterator hit = data.find(key); - if (hit == data.end()) { - return end(); - } - - return iterator(hit.value().second, &data); -} - -template -typename OrderedMap::const_iterator OrderedMap::find(const Key& key) const -{ - OMHashConstIterator hit = data.find(key); - if (hit == data.end()) { - return end(); - } - - return const_iterator(hit.value().second, &data); -} - -#endif // ORDEREDMAP_H diff --git a/README.md b/README.md index 9581dfb..0b0cffa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Problem -Suppose you don't have search utility in your editor that satisfies all your needs. But you're clever so at first you're like +Suppose you don't have search utility in your editor that satisfies all your needs. But you're clever so at first you `grep something *.cpp *.h` @@ -18,15 +18,21 @@ and then you `find . \( -iname '*.cpp' -or -iname '*.h' \) -exec grep -Hn something {} \; | grep -v butNotThat` -and then you need to repeat pre-previous search, but keep current results so you tmux (and then you can't easily scroll) or ctrl-shift-t and then you lost in ten tabs +and then you need to repeat previous search, but also keep current results so you open new tab or pane -and then you wish you could use results to click-junp to specific file on specific line in your editor of choice. +and then you wish you could use results to click-jump to specific file on specific line in your editor of choice + +and then you wish you could `sed -i` on results without breaking everything ## Solution Struggle no more, _mugi-grep_ is here to help. Look at that beauty! -![mugi-grep](https://mugiseyebrows.github.io/img/mugi-grep-1.0.1.png) +### Search action +![mugi-grep](https://mugiseyebrows.github.io/img/mugi-grep-search.png) + +### Replace action +![mugi-grep](https://mugiseyebrows.github.io/img/mugi-grep-replace.png) # Build diff --git a/desktop.py b/desktop.py old mode 100644 new mode 100755 index 9d77fc8..e6b4858 --- a/desktop.py +++ b/desktop.py @@ -1,4 +1,4 @@ - +#!/usr/bin/env python3 import os import shutil @@ -10,7 +10,9 @@ icons = os.path.expanduser('~/.local/share/icons/hicolor') for size in sizes: src = os.path.join('./icons',size,'%s.png' % name) - dst = os.path.join(icons,size,'apps','%s.png' % name) + dst_dir = os.path.join(icons,size,'apps') + os.makedirs(dst_dir,exist_ok = True) + dst = os.path.join(dst_dir,'%s.png' % name) shutil.copy(src,dst) icon = dst = os.path.join(icons,'256x256','apps','%s.png' % name) diff --git a/html.cpp b/html.cpp deleted file mode 100644 index 7cbef10..0000000 --- a/html.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "html.h" - -QString Html::span(const QString &text_, const QString &color) -{ - QString text = text_; - text.replace("<","<").replace(">",">"); - return QString("%2").arg(color).arg(text); -} - -QString Html::anchor(const QString &text, const QString& path, const QString& color) -{ - return QString("%3").arg(path).arg(color).arg(text); -} diff --git a/html.h b/html.h deleted file mode 100644 index 3ee6120..0000000 --- a/html.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HTML_H -#define HTML_H - -#include - -namespace Html -{ - - QString span(const QString &text_, const QString &color); - - QString anchor(const QString &text, const QString& path, const QString& color); - -} - -#endif // HTML_H diff --git a/icons.py b/icons.py index e4dfce9..02480c7 100644 --- a/icons.py +++ b/icons.py @@ -3,7 +3,7 @@ name = 'mugi-grep' sizes = ['128x128','16x16','256x256','32x32','48x48','512x512'] -ico = './mugi-grep.ico[1]' +ico = './src/mugi-grep.ico[1]' for size in sizes: d = os.path.join('./icons',size) diff --git a/mugi-grep.pro b/mugi-grep.pro index 21dae1f..8659a45 100644 --- a/mugi-grep.pro +++ b/mugi-grep.pro @@ -6,96 +6,98 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = mugi-grep TEMPLATE = app -RC_FILE = mugi-grep.rc +RC_FILE = src/mugi-grep.rc -HEADERS += \ - regexp.h \ - regexpinput.h \ - regexppath.h \ - rxcollector.h \ - searchcache.h \ - searchid.h \ - settings.h \ - version.h \ - worker.h \ - 3rdparty/orderedmap.h \ - model/editorsmodel.h \ - struct/editor.h \ - struct/searchdata.h \ - widget/intlineedit.h \ - widget/mainwindow.h \ - widget/regexpbaseinput.h \ - widget/regexppathinput.h \ - widget/regexpwidget.h \ - widget/rxbaseinput.h \ - widget/rxinput.h \ - widget/rxpathinput.h \ - widget/searchbrowser.h \ - widget/sessionwidget.h \ - widget/settingsdialog.h \ - utils/bl.h \ - utils/sl.h \ - utils/jsonhelper.h \ - widget/elidedlabel.h \ - version.h \ - widget/selectfilesdialog.h \ - html.h \ - anchorclickhandler.h \ - model/checkablestringlistmodel.h \ - utils/fileutils.h \ - widget/searchoptionswidget.h \ - widget/searchprogresswidget.h \ - filereader.h \ - utils/isbinext.h +INCLUDEPATH += src src/widget src/model +HEADERS += \ + src/searchdata.h \ + src/searchparams.h \ + src/searchcache.h \ + src/worker.h \ + src/utils.h \ + src/replacementline.h \ + src/replacement.h \ + src/regexppath.h \ + src/regexp.h \ + src/html.h \ + src/lit.h \ + src/rxcollector.h \ + src/completermodelmanager.h \ + src/version.h \ + src/settings.h \ + src/searchid.h \ + src/filereader.h \ + src/anchorclickhandler.h \ + src/jsonhelper.h \ + src/fileutils.h \ + src/editor.h \ + src/widget/sessionwidget.h \ + src/widget/searchprogresswidget.h \ + src/widget/searchoptionswidget.h \ + src/widget/searchbrowser.h \ + src/widget/mainwindow.h \ + src/widget/rxpathinput.h \ + src/widget/settingsdialog.h \ + src/widget/selectfilesdialog.h \ + src/widget/rxinput.h \ + src/widget/rxbaseinput.h \ + src/widget/regexpbaseinput.h \ + src/widget/intlineedit.h \ + src/widget/elidedlabel.h \ + src/model/editorsmodel.h \ + src/model/checkablestringlistmodel.h \ + src/widget/rxreplaceinput.h SOURCES += \ - main.cpp \ - regexp.cpp \ - regexppath.cpp \ - rxcollector.cpp \ - searchcache.cpp \ - searchid.cpp \ - settings.cpp \ - worker.cpp \ - model/editorsmodel.cpp \ - struct/editor.cpp \ - struct/searchdata.cpp \ - widget/intlineedit.cpp \ - widget/mainwindow.cpp \ - widget/regexpbaseinput.cpp \ - widget/regexpinput.cpp \ - widget/regexppathinput.cpp \ - widget/regexpwidget.cpp \ - widget/rxbaseinput.cpp \ - widget/rxinput.cpp \ - widget/rxpathinput.cpp \ - widget/searchbrowser.cpp \ - widget/sessionwidget.cpp \ - widget/settingsdialog.cpp \ - utils/bl.cpp \ - utils/sl.cpp \ - utils/jsonhelper.cpp \ - widget/elidedlabel.cpp \ - widget/selectfilesdialog.cpp \ - html.cpp \ - anchorclickhandler.cpp \ - model/checkablestringlistmodel.cpp \ - utils/fileutils.cpp \ - widget/searchoptionswidget.cpp \ - widget/searchprogresswidget.cpp \ - filereader.cpp \ - utils/isbinext.cpp + src/searchcache.cpp \ + src/searchparams.cpp \ + src/searchdata.cpp \ + src/worker.cpp \ + src/utils.cpp \ + src/filereader.cpp \ + src/replacementline.cpp \ + src/replacement.cpp \ + src/regexppath.cpp \ + src/regexp.cpp \ + src/html.cpp \ + src/anchorclickhandler.cpp \ + src/main.cpp \ + src/lit.cpp \ + src/rxcollector.cpp \ + src/completermodelmanager.cpp \ + src/settings.cpp \ + src/searchid.cpp \ + src/jsonhelper.cpp \ + src/fileutils.cpp \ + src/editor.cpp \ + src/widget/sessionwidget.cpp \ + src/widget/searchprogresswidget.cpp \ + src/widget/searchoptionswidget.cpp \ + src/widget/searchbrowser.cpp \ + src/widget/rxpathinput.cpp \ + src/widget/mainwindow.cpp \ + src/widget/rxinput.cpp \ + src/widget/settingsdialog.cpp \ + src/widget/selectfilesdialog.cpp \ + src/widget/rxbaseinput.cpp \ + src/widget/regexpbaseinput.cpp \ + src/widget/intlineedit.cpp \ + src/widget/elidedlabel.cpp \ + src/model/editorsmodel.cpp \ + src/model/checkablestringlistmodel.cpp \ + src/widget/rxreplaceinput.cpp FORMS += \ - widget/mainwindow.ui \ - widget/rxinput.ui \ - widget/rxpathinput.ui \ - widget/sessionwidget.ui \ - widget/settingsdialog.ui \ - widget/selectfilesdialog.ui \ - widget/searchoptionswidget.ui \ - widget/searchprogresswidget.ui + src/widget/sessionwidget.ui \ + src/widget/searchoptionswidget.ui \ + src/widget/mainwindow.ui \ + src/widget/settingsdialog.ui \ + src/widget/selectfilesdialog.ui \ + src/widget/searchprogresswidget.ui \ + src/widget/rxpathinput.ui \ + src/widget/rxinput.ui \ + src/widget/rxreplaceinput.ui target.path = /usr/local/bin INSTALLS += target diff --git a/regexpinput.h b/regexpinput.h deleted file mode 100644 index 0e84355..0000000 --- a/regexpinput.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef REGEXPINPUT_H -#define REGEXPINPUT_H - -#include -#include - -#include "regexp.h" -#include "widget/regexpbaseinput.h" - -class QLineEdit; -class QCheckBox; - -class RegExpInput : public RegExpBaseInput -{ - Q_OBJECT -public: - explicit RegExpInput(QWidget *parent = 0); - - RegExp value() const; - void setValue(const RegExp& value); - -protected: - - void modeChanged(); - -public slots: - -}; - -#endif // REGEXPINPUT_H diff --git a/rxcollector.cpp b/rxcollector.cpp deleted file mode 100644 index 00ca9fa..0000000 --- a/rxcollector.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "rxcollector.h" - -#include -#include -#include -#include -#include - -RXCollector *RXCollector::mInstance = nullptr; - -#define COLLECTION_SIZE 20 - -RXCollector *RXCollector::instance() -{ - if (!mInstance) { - mInstance = new RXCollector(); - } - return mInstance; -} - -void RXCollector::collect(const RegExpPath &exp) -{ - prependModels(mPathExps, exp.exps()); -} - -void RXCollector::collect(const RegExp &exp) -{ - prependModels(mExps, exp.exps()); -} - -void RXCollector::prependModels(const QList &models, const QStringList &exps) { - - qDebug() << "RXCollector::prependModels"; - for(int i=0;i(models[i]); - QString s = exps.value(i); - - QStringList items = m->stringList(); - int index = items.indexOf(s); - if (index > -1) { - items.removeAt(index); - } - - items.prepend(s); - m->setStringList(items); - if (m->rowCount() > COLLECTION_SIZE) { - m->removeRow(m->rowCount()-1); - } - } -} - -void RXCollector::load(RXPathInput *input) -{ - for(int i=0;iinput(i)->setModel(mPathExps[i]); - input->input(i)->setCurrentIndex(0); - } -} - -void RXCollector::load(RXInput *input) { - for(int i=0;iinput(i)->setModel(mExps[i]); - input->input(i)->setCurrentIndex(0); - } -} - - -void arrayOfArraysOfString(const QVariantList& src, QJsonArray& dst) { - for(QVariant v: src) { - dst.append(QJsonArray::fromStringList(v.toStringList())); - } -} - -void RXCollector::serialize(QJsonObject &j) -{ - QJsonArray pathexps; - arrayOfArraysOfString(modelsLists(mPathExps), pathexps); - QJsonArray exps; - arrayOfArraysOfString(modelsLists(mExps),exps); - j["pathexps"] = pathexps; - j["exps"] = exps; -} - -QVariantList RXCollector::modelsLists(const QList &models) { - QVariantList exps; - for(int i=0;istringList()); - } - return exps; -} - - - -QStringList toStringList(const QVariantList& vs) { - QStringList s; - std::transform(vs.begin(),vs.end(),std::back_inserter(s), - [&](QVariant v){return v.toString();}); - return s; -} - - -void RXCollector::deserialize(const QList &models, const QJsonArray& exps) { - - if (!exps.isEmpty()) { - for(int i=0;isetStringList(vs); - } - } - } -} - -void RXCollector::deserialize(const QJsonObject &j) -{ - deserialize(mPathExps,j.value("pathexps").toArray()); - deserialize(mExps,j.value("exps").toArray()); -} - -RXCollector::RXCollector() -{ - for(int i=0;i<4;i++) { - mPathExps << new QStringListModel(); - } - for(int i=0;i<2;i++) { - mExps << new QStringListModel(); - } - -} diff --git a/searchcache.cpp b/searchcache.cpp deleted file mode 100644 index 8a4e1f5..0000000 --- a/searchcache.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include "searchcache.h" - -#include -#include -#include - -#include "html.h" -#include "filereader.h" -#include "utils/isbinext.h" - -QStringList searchLines(const QStringList& mLines, const QString& mPath, const QString& mRelativePath, - const RegExp& exp, int linesBefore, int linesAfter) { - - QStringList res; - - QSet matched; - QSet siblings; - - // pass 1 - for(int i=0;itoUnicode(bytes).split("\n"); - *lineCount = lines.size(); - return searchLines(lines,path,relativePath,exp,linesBefore,linesAfter); -} - -QStringList searchBinary(const QByteArray& bytes, const QString& path, const QString& relativePath, - const RegExp& exp) { - - QTextCodec* codec = QTextCodec::codecForName("UTF-8"); // todo guess or chose encoding - QStringList lines = codec->toUnicode(bytes).split("\n"); - return searchBinary(lines,path,relativePath,exp); -} - -QString ext(const QString& path) { - if (path.indexOf(".")>-1) - return path.split(".").last().toLower(); - return QString(); -} - - -// todo: remove -QString relPath(const QString& path, const QString& base) { - if (path.startsWith(base)) { - if (path[base.size()] == QChar('\\') && path.size() > base.size()) - return path.mid(base.size()+1); - else - return path.mid(base.size()); - } - return path; -} - -SearchCache::SearchCache() { - -} - -QPair SearchCache::countMatchedFiles(QString path, RegExpPath filter, bool notBinary) { - - QMutexLocker locked(&mMutex); - - qDebug() << filter << notBinary; - - QStringList allFiles = getAllFiles(path, true); - int filesFiltered; - int dirsFiltered; - // todo optimize - QStringList files = filterFiles(allFiles,filter,notBinary,&filesFiltered,&dirsFiltered); - return QPair(files.size(),allFiles.size()); -} - -QStringList SearchCache::getAllFiles(QString path, bool cacheFileList) { - // todo skip directory entirely if filter matches if not cacheFileList - QString path_ = QDir(path).absolutePath(); - QStringList allFiles; - if (cacheFileList && mFileList.contains(path_)) { - allFiles = mFileList[path_]; - } else { - QDirIterator it(path, QDir::Files, QDirIterator::Subdirectories); - while (it.hasNext()) { - QString path = it.next(); - allFiles.append(path); - } - if (cacheFileList) { - mFileList[path_] = allFiles; - } - } - if (!cacheFileList) { - mFileList.remove(path_); - } - return allFiles; -} - - - -QStringList SearchCache::filterFiles(const QStringList& allFiles, RegExpPath filter, bool notBinary, int* filesFiltered, int* dirsFiltered) { - - int filesFiltered_ = 0; - int dirsFiltered_ = 0; - - QStringList files; - - foreach(const QString& path, allFiles) { - if (path.contains("/.git/")) { // todo skip settings - filesFiltered_++; - continue; - } - if (notBinary && isBinExt(path)) { - filesFiltered_++; - continue; - } - if (filter.match(path)) { - files << path; - } else { - filesFiltered_++; - } - } - - *filesFiltered = filesFiltered_; - *dirsFiltered = dirsFiltered_; - - return files; -} - -void SearchCache::add(int searchId, QString path, RegExpPath filter, - bool notBinary, RegExp search, - int linesBefore, int linesAfter, bool cacheFileList) { - - QMutexLocker locked(&mMutex); - - - QStringList allFiles = getAllFiles(path,cacheFileList); - int filesFiltered; - int dirsFiltered; - QStringList files = filterFiles(allFiles,filter,notBinary,&filesFiltered,&dirsFiltered); - - SearchData data = SearchData(path,filter,notBinary,search,files, - linesBefore,linesAfter, - filesFiltered,dirsFiltered); - - mSearchData.insert(searchId,data); -} - -void SearchCache::finish(int searchId) { - QMutexLocker locked(&mMutex); - mSearchData.remove(searchId); -} - -void SearchCache::search(int searchId, QString &data, int *complete, int *total, int *filtered, QString &file) { - QMutexLocker locked(&mMutex); - - if (!mSearchData.contains(searchId)) { - qDebug() << "!mSearchData.contains(searchId)"; - return; - } - - SearchData& sd = mSearchData[searchId]; - //int lim = qMin(sd.complete + 100, sd.files.size()); - QStringList res; - - int lineCount = 0; - int fileCount = 0; - - for (int i=sd.complete;ifile(path,sd.notBinary,&binary,&readOk); - QByteArray fileData = FileReader::read(path,sd.notBinary,&binary,&readOk,&tooBig); - QString relPath_ = relPath(path,sd.path); - - bool ok = true; - - if (!readOk) { - qDebug() << "!readOk" << path; - ok = false; - } - - if (tooBig) { // todo implement line by line search in big files - ok = false; - } - - int fileLineCount = 0; - - if (ok) { - if (binary) { - res << searchBinary(fileData, path, relPath_, sd.search); - } else { - res << searchLines(fileData, path, relPath_, sd.search, sd.linesBefore, sd.linesAfter, &fileLineCount); - } - } - - lineCount += fileLineCount; - fileCount += 1; - sd.complete = i + 1; - - if (res.size() > 100 || lineCount > 4000 || fileCount > 50) { - data = res.join("
"); - *complete = sd.complete; - *total = sd.files.size(); - *filtered = sd.filesFiltered; - file = relPath_; - return; - } - } - data = res.join("
"); - *complete = sd.complete; - *total = sd.files.size(); - *filtered = sd.filesFiltered; - file = QString(); -} - diff --git a/anchorclickhandler.cpp b/src/anchorclickhandler.cpp similarity index 91% rename from anchorclickhandler.cpp rename to src/anchorclickhandler.cpp index 3381d71..d02d184 100644 --- a/anchorclickhandler.cpp +++ b/src/anchorclickhandler.cpp @@ -8,10 +8,12 @@ #include #include #include -#include "utils/fileutils.h" +#include "fileutils.h" #include #include #include +#include +#include namespace { @@ -158,11 +160,19 @@ void AnchorClickHandler::onCustomContextMenuRequested(QPoint point) { show->setEnabled(!anchor.isEmpty()); menu->insertAction(menu->actions().value(1),show); + QAction* copyPath = new QAction("C&opy Path"); + copyPath->setEnabled(!anchor.isEmpty()); + menu->insertAction(menu->actions().value(1),copyPath); + QAction* result = menu->exec(browser->mapToGlobal(point)); if (result == show) { QString path = urlPath(QUrl(anchor)); FileUtils::showInGraphicalShell(qApp->activeWindow(),path); + } else if (result == copyPath) { + QString path = urlPath(QUrl(anchor)); + QClipboard* clipboard = qApp->clipboard(); + clipboard->setText(QDir::toNativeSeparators(path)); } delete show; diff --git a/anchorclickhandler.h b/src/anchorclickhandler.h similarity index 100% rename from anchorclickhandler.h rename to src/anchorclickhandler.h diff --git a/src/completermodelmanager.cpp b/src/completermodelmanager.cpp new file mode 100644 index 0000000..e0ffc7e --- /dev/null +++ b/src/completermodelmanager.cpp @@ -0,0 +1,32 @@ +#include "completermodelmanager.h" +#include "widget/sessionwidget.h" + +#include "rxcollector.h" +#include "widget/searchoptionswidget.h" + +CompleterModelManager::CompleterModelManager(QObject *parent) : QObject(parent) +{ + +} + +void CompleterModelManager::onCollect(SearchOptionsWidget* options, QTabWidget * tabs) +{ + QList models = RXCollector::instance()->models(); + options->collect(); + for(int index=0;indexcount();index++) { + SessionWidget* session = tab(tabs, index); + if (!session) { + qDebug() << "not SessionWidget at index" << index << tabs->widget(index); + return; + } + session->updateCompletions(); + } + foreach (QStringListModel* model, models) { + model->deleteLater(); + } +} + +SessionWidget *CompleterModelManager::tab(QTabWidget* tabs, int index) +{ + return qobject_cast(tabs->widget(index)); +} diff --git a/src/completermodelmanager.h b/src/completermodelmanager.h new file mode 100644 index 0000000..35dfe5b --- /dev/null +++ b/src/completermodelmanager.h @@ -0,0 +1,25 @@ +#ifndef COMPLETERMODELMANAGER_H +#define COMPLETERMODELMANAGER_H + +#include +#include +#include "widget/searchoptionswidget.h" + +class SessionWidget; +class QStringListModel; + +class CompleterModelManager : public QObject +{ + Q_OBJECT +public: + explicit CompleterModelManager(QObject *parent = nullptr); + SessionWidget *tab(QTabWidget *tabs, int index); + +protected: + +public slots: + + void onCollect(SearchOptionsWidget *options, QTabWidget *tabs); +}; + +#endif // COMPLETERMODELMANAGER_H diff --git a/struct/editor.cpp b/src/editor.cpp similarity index 97% rename from struct/editor.cpp rename to src/editor.cpp index 1c6372f..f35db6c 100644 --- a/struct/editor.cpp +++ b/src/editor.cpp @@ -1,4 +1,4 @@ -#include "struct/editor.h" +#include "editor.h" #include /*********************** CONSTRUCTORS ***********************/ diff --git a/struct/editor.h b/src/editor.h similarity index 100% rename from struct/editor.h rename to src/editor.h diff --git a/filereader.cpp b/src/filereader.cpp similarity index 94% rename from filereader.cpp rename to src/filereader.cpp index 463bada..75aae67 100644 --- a/filereader.cpp +++ b/src/filereader.cpp @@ -2,7 +2,7 @@ #include #include -#include "utils/isbinext.h" +#include "utils.h" #define FILESIZE_TOOBIG (128*1024*1024) #define DATASAMPLE_SIZE (2*1024) @@ -19,7 +19,7 @@ QByteArray FileReader::read(const QString &path, bool skipBinary, bool *binary, *binary = false; *tooBig = false; - if (skipBinary && isBinExt(path)) { + if (skipBinary && Utils::isBinExt(path)) { *binary = true; return QByteArray(); } diff --git a/filereader.h b/src/filereader.h similarity index 100% rename from filereader.h rename to src/filereader.h diff --git a/utils/fileutils.cpp b/src/fileutils.cpp similarity index 100% rename from utils/fileutils.cpp rename to src/fileutils.cpp diff --git a/utils/fileutils.h b/src/fileutils.h similarity index 100% rename from utils/fileutils.h rename to src/fileutils.h diff --git a/src/html.cpp b/src/html.cpp new file mode 100644 index 0000000..d9e41e9 --- /dev/null +++ b/src/html.cpp @@ -0,0 +1,33 @@ +#include "html.h" + + + +QString Html::span(const QString &text_, const QString &color, bool bold) +{ + QString text = text_; + text.replace("<","<").replace(">",">"); + if (bold) { + return QString("%2").arg(color).arg(text); + } + return QString("%2").arg(color).arg(text); +} + +QString Html::span(const QString &text_, const QString &color, const QString &background) { + QString text = text_; + text.replace("<","<").replace(">",">"); + return QString("%1").arg(text).arg(color).arg(background); +} + +QString Html::anchor(const QString &text, const QString& path, const QString& color) +{ + return QString("%3").arg(path).arg(color).arg(text); +} + +QString Html::spanZebra(const QStringList& text, const QString& color, const QString& background, const QString& altBackground) +{ + QStringList result; + for(int i=0;i + +namespace Html +{ + + QString span(const QString &text_, const QString &color, bool bold = false); + + QString span(const QString &text_, const QString &color, const QString &background); + + QString anchor(const QString &text, const QString& path, const QString& color); + + QString spanZebra(const QStringList& text, const QString& color, const QString& background, const QString& altBackground); + +} + +#endif // HTML_H diff --git a/utils/jsonhelper.cpp b/src/jsonhelper.cpp similarity index 100% rename from utils/jsonhelper.cpp rename to src/jsonhelper.cpp diff --git a/utils/jsonhelper.h b/src/jsonhelper.h similarity index 100% rename from utils/jsonhelper.h rename to src/jsonhelper.h diff --git a/src/lit.cpp b/src/lit.cpp new file mode 100644 index 0000000..553a9e2 --- /dev/null +++ b/src/lit.cpp @@ -0,0 +1,576 @@ +#include "lit.h" + +QList Lit::il() { + QList result; + return result; +} + +QList Lit::il(int v0) { + QList result; + result.append(v0); + return result; +} + +QList Lit::il(int v0, int v1) { + QList result; + result.append(v0); + result.append(v1); + return result; +} + +QList Lit::il(int v0, int v1, int v2) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + return result; +} + +QList Lit::il(int v0, int v1, int v2, int v3) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + return result; +} + +QList Lit::il(int v0, int v1, int v2, int v3, int v4) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + return result; +} + +QList Lit::il(int v0, int v1, int v2, int v3, int v4, int v5) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + return result; +} + +QList Lit::il(int v0, int v1, int v2, int v3, int v4, int v5, int v6) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + return result; +} + +QList Lit::il(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + return result; +} + +QList Lit::il(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + return result; +} + +QList Lit::il(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8, int v9) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + result.append(v9); + return result; +} + +QList Lit::bl() { + QList result; + return result; +} + +QList Lit::bl(bool v0) { + QList result; + result.append(v0); + return result; +} + +QList Lit::bl(bool v0, bool v1) { + QList result; + result.append(v0); + result.append(v1); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2, bool v3) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2, bool v3, bool v4) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6, bool v7) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6, bool v7, + bool v8) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + return result; +} + +QList Lit::bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6, bool v7, bool v8, + bool v9) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + result.append(v9); + return result; +} + +QList Lit::dl() { + QList result; + return result; +} + +QList Lit::dl(double v0) { + QList result; + result.append(v0); + return result; +} + +QList Lit::dl(double v0, double v1) { + QList result; + result.append(v0); + result.append(v1); + return result; +} + +QList Lit::dl(double v0, double v1, double v2) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + return result; +} + +QList Lit::dl(double v0, double v1, double v2, double v3) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + return result; +} + +QList Lit::dl(double v0, double v1, double v2, double v3, double v4) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + return result; +} + +QList Lit::dl(double v0, double v1, double v2, double v3, double v4, double v5) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + return result; +} + +QList Lit::dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + return result; +} + +QList Lit::dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6, + double v7) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + return result; +} + +QList Lit::dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6, + double v7, double v8) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + return result; +} + +QList Lit::dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6, + double v7, double v8, double v9) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + result.append(v9); + return result; +} + +QList Lit::sl() { + QList result; + return result; +} + +QList Lit::sl(const QString& v0) { + QList result; + result.append(v0); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1) { + QList result; + result.append(v0); + result.append(v1); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6, const QString& v7) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6, const QString& v7, + const QString& v8) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + return result; +} + +QList Lit::sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6, const QString& v7, + const QString& v8, const QString& v9) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + result.append(v9); + return result; +} + +QList Lit::vl() { + QList result; + return result; +} + +QList Lit::vl(const QVariant& v0) { + QList result; + result.append(v0); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1) { + QList result; + result.append(v0); + result.append(v1); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6, const QVariant& v7) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6, const QVariant& v7, const QVariant& v8) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + return result; +} + +QList Lit::vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6, const QVariant& v7, const QVariant& v8, + const QVariant& v9) { + QList result; + result.append(v0); + result.append(v1); + result.append(v2); + result.append(v3); + result.append(v4); + result.append(v5); + result.append(v6); + result.append(v7); + result.append(v8); + result.append(v9); + return result; +} diff --git a/src/lit.h b/src/lit.h new file mode 100644 index 0000000..e51b019 --- /dev/null +++ b/src/lit.h @@ -0,0 +1,88 @@ +#ifndef LIT_H +#define LIT_H +#include +#include +#include + +namespace Lit { + QList il(); + QList il(int v0); + QList il(int v0, int v1); + QList il(int v0, int v1, int v2); + QList il(int v0, int v1, int v2, int v3); + QList il(int v0, int v1, int v2, int v3, int v4); + QList il(int v0, int v1, int v2, int v3, int v4, int v5); + QList il(int v0, int v1, int v2, int v3, int v4, int v5, int v6); + QList il(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7); + QList il(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8); + QList il(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8, int v9); + QList bl(); + QList bl(bool v0); + QList bl(bool v0, bool v1); + QList bl(bool v0, bool v1, bool v2); + QList bl(bool v0, bool v1, bool v2, bool v3); + QList bl(bool v0, bool v1, bool v2, bool v3, bool v4); + QList bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5); + QList bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6); + QList bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6, bool v7); + QList bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6, bool v7, bool v8); + QList bl(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6, bool v7, bool v8, + bool v9); + QList dl(); + QList dl(double v0); + QList dl(double v0, double v1); + QList dl(double v0, double v1, double v2); + QList dl(double v0, double v1, double v2, double v3); + QList dl(double v0, double v1, double v2, double v3, double v4); + QList dl(double v0, double v1, double v2, double v3, double v4, double v5); + QList dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6); + QList dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6, + double v7); + QList dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6, + double v7, double v8); + QList dl(double v0, double v1, double v2, double v3, double v4, double v5, double v6, + double v7, double v8, double v9); + QList sl(); + QList sl(const QString& v0); + QList sl(const QString& v0, const QString& v1); + QList sl(const QString& v0, const QString& v1, const QString& v2); + QList sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3); + QList sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4); + QList sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5); + QList sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6); + QList sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6, const QString& v7); + QList sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6, const QString& v7, + const QString& v8); + QList sl(const QString& v0, const QString& v1, const QString& v2, const QString& v3, + const QString& v4, const QString& v5, const QString& v6, const QString& v7, + const QString& v8, const QString& v9); + QList vl(); + QList vl(const QVariant& v0); + QList vl(const QVariant& v0, const QVariant& v1); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6, const QVariant& v7); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6, const QVariant& v7, const QVariant& v8); + QList vl(const QVariant& v0, const QVariant& v1, const QVariant& v2, + const QVariant& v3, const QVariant& v4, const QVariant& v5, + const QVariant& v6, const QVariant& v7, const QVariant& v8, + const QVariant& v9); +} // namespace Lit +#endif // LIT_H diff --git a/main.cpp b/src/main.cpp similarity index 81% rename from main.cpp rename to src/main.cpp index 8646062..5347001 100644 --- a/main.cpp +++ b/src/main.cpp @@ -7,12 +7,16 @@ #include "regexppath.h" #include "version.h" +#include "searchcache.h" +#include "searchparams.h" + int main(int argc, char *argv[]) { //QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); QApplication a(argc, argv); a.setApplicationName(APP_NAME); @@ -23,6 +27,8 @@ int main(int argc, char *argv[]) MainWindow w; w.show(); + + //SearchCache::testTokenize(); return a.exec(); } diff --git a/model/checkablestringlistmodel.cpp b/src/model/checkablestringlistmodel.cpp similarity index 100% rename from model/checkablestringlistmodel.cpp rename to src/model/checkablestringlistmodel.cpp diff --git a/model/checkablestringlistmodel.h b/src/model/checkablestringlistmodel.h similarity index 100% rename from model/checkablestringlistmodel.h rename to src/model/checkablestringlistmodel.h diff --git a/model/editorsmodel.cpp b/src/model/editorsmodel.cpp similarity index 100% rename from model/editorsmodel.cpp rename to src/model/editorsmodel.cpp diff --git a/model/editorsmodel.h b/src/model/editorsmodel.h similarity index 100% rename from model/editorsmodel.h rename to src/model/editorsmodel.h diff --git a/mugi-grep.ico b/src/mugi-grep.ico similarity index 100% rename from mugi-grep.ico rename to src/mugi-grep.ico diff --git a/mugi-grep.rc b/src/mugi-grep.rc similarity index 100% rename from mugi-grep.rc rename to src/mugi-grep.rc diff --git a/regexp.cpp b/src/regexp.cpp similarity index 62% rename from regexp.cpp rename to src/regexp.cpp index 70959c7..52afd70 100644 --- a/regexp.cpp +++ b/src/regexp.cpp @@ -1,7 +1,6 @@ #include "regexp.h" -#include "utils/bl.h" -#include "utils/sl.h" +#include "lit.h" #include #include @@ -26,6 +25,11 @@ RegExp::RegExp(const QVariantMap &data) deserealize(data); } +bool RegExp::isEmpty() const +{ + return mInclude.isEmpty() && mExclude.isEmpty(); +} + QVariantMap RegExp::serialize() const { QVariantMap res; @@ -43,8 +47,8 @@ void RegExp::deserealize(const QVariantMap &data) void RegExp::init(const QString& inc, const QString& exc, bool case_) { mInclude = inc; mExclude = exc; - mInclude_ = QRegularExpression(inc, case_ ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); - mExclude_ = QRegularExpression(exc, case_ ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); + mIncludeExp = QRegularExpression(inc, case_ ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); + mExcludeExp = QRegularExpression(exc, case_ ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); mCase = case_; } @@ -53,6 +57,10 @@ QString RegExp::include() const return mInclude; } +QRegularExpression RegExp::includeExp() const { + return mIncludeExp; +} + QString RegExp::exclude() const { return mExclude; @@ -74,10 +82,7 @@ bool RegExp::match(const QString s, int* pos, int* len) const if (mInclude.isEmpty()) { inc = true; } else { - QRegularExpression e = mInclude_; - - QRegularExpressionMatch m = e.match(s); - + QRegularExpressionMatch m = mIncludeExp.match(s); if (m.hasMatch()) { int p = m.capturedStart(); if (pos) { @@ -91,13 +96,13 @@ bool RegExp::match(const QString s, int* pos, int* len) const inc = false; } } - return (inc) && (mExclude.isEmpty() || !mExclude_.match(s).hasMatch()); + return (inc) && (mExclude.isEmpty() || !mExcludeExp.match(s).hasMatch()); } QStringList RegExp::exps() const { - return sl(mInclude,mExclude); + return Lit::sl(mInclude,mExclude); } void RegExp::test(const QStringList &paths, const RegExp &exp, const QList &matched) @@ -113,12 +118,12 @@ void RegExp::test() QStringList paths; paths << "foo.bar" << "foo.bar.baz" << "foo"; - test(paths,RegExp("foo","",false),bl(true,true,true)); - test(paths,RegExp("bar","",false),bl(true,true,false)); - test(paths,RegExp("foo","baz",false),bl(true,false,true)); - test(paths,RegExp("","bar",false),bl(false,false,true)); + test(paths,RegExp("foo","",false),Lit::bl(true,true,true)); + test(paths,RegExp("bar","",false),Lit::bl(true,true,false)); + test(paths,RegExp("foo","baz",false),Lit::bl(true,false,true)); + test(paths,RegExp("","bar",false),Lit::bl(false,false,true)); - test(paths,RegExp("FOO","baz",true),bl(false,false,false)); + test(paths,RegExp("FOO","baz",true),Lit::bl(false,false,false)); qDebug() << "passed RegExp::test()"; @@ -127,6 +132,11 @@ void RegExp::test() RegExp e("b","",false); e.match(paths[0],&p,&l); Q_ASSERT(p == 4 && l == 1); +} - +QDebug operator <<(QDebug &debug, const RegExp &exp) +{ + QString exp_ = QString("RegExp(\"%1\", \"%2\", %3)").arg(exp.include()).arg(exp.exclude()).arg(exp.case_() ? "true" : "false"); + debug.nospace() << exp_.toStdString().c_str(); + return debug; } diff --git a/regexp.h b/src/regexp.h similarity index 81% rename from regexp.h rename to src/regexp.h index f95f198..48d6c96 100644 --- a/regexp.h +++ b/src/regexp.h @@ -13,6 +13,8 @@ class RegExp { RegExp(const QStringList& regExps, bool case_); RegExp(const QVariantMap& data); + bool isEmpty() const; + QString include() const; QString exclude() const; bool case_() const; @@ -26,17 +28,20 @@ class RegExp { void deserealize(const QVariantMap& data); QStringList exps() const; + QRegularExpression includeExp() const; protected: void init(const QString &inc, const QString &exc, bool case_); QString mInclude; QString mExclude; - QRegularExpression mInclude_; - QRegularExpression mExclude_; + QRegularExpression mIncludeExp; + QRegularExpression mExcludeExp; bool mCase; }; +QDebug operator <<(QDebug& debug, const RegExp& exp); + Q_DECLARE_METATYPE(RegExp) #endif // REGEXP_H diff --git a/regexppath.cpp b/src/regexppath.cpp similarity index 92% rename from regexppath.cpp rename to src/regexppath.cpp index e300584..583aa56 100644 --- a/regexppath.cpp +++ b/src/regexppath.cpp @@ -1,7 +1,6 @@ #include "regexppath.h" -#include "utils/sl.h" -#include "utils/bl.h" +#include "lit.h" #include RegExpPath::RegExpPath() @@ -42,6 +41,14 @@ RegExpPath::RegExpPath(const QVariantMap &data) deserealize(data); } +bool RegExpPath::isEmpty() const +{ + return mRegExps[PathInclude].isEmpty() && + mRegExps[ExtInclude].isEmpty() && + mRegExps[PathExclude].isEmpty() && + mRegExps[ExtExclude].isEmpty(); +} + QVariantMap RegExpPath::serialize() const { QVariantMap res; @@ -96,6 +103,7 @@ void RegExpPath::test() QStringList paths; paths << "foo.bar" << "foo.bar.baz" << "foo"; + using namespace Lit; test(paths,RegExpPath(sl("","bar","",""),false),bl(true,false,false)); test(paths,RegExpPath(sl("","foo","",""),false),bl(false,false,false)); diff --git a/regexppath.h b/src/regexppath.h similarity index 97% rename from regexppath.h rename to src/regexppath.h index d4669d4..f285d8e 100644 --- a/regexppath.h +++ b/src/regexppath.h @@ -18,6 +18,9 @@ class RegExpPath { RegExpPath(); RegExpPath(const QStringList& regExps, bool case_); RegExpPath(const QVariantMap& data); + + bool isEmpty() const; + bool match(const QString& path) const; QStringList exps() const; diff --git a/src/replacement.cpp b/src/replacement.cpp new file mode 100644 index 0000000..df5f1f4 --- /dev/null +++ b/src/replacement.cpp @@ -0,0 +1,18 @@ +#include "replacement.h" + +Replacement::Replacement() +{ + +} + +Replacement::Replacement(const QString &path, const QList &lines) : mPath(path), mLines(lines) { + +} + +QString Replacement::path() const { + return mPath; +} + +QList Replacement::lines() const { + return mLines; +} diff --git a/src/replacement.h b/src/replacement.h new file mode 100644 index 0000000..2113836 --- /dev/null +++ b/src/replacement.h @@ -0,0 +1,18 @@ +#ifndef REPLACEMENT_H +#define REPLACEMENT_H + +#include +#include "replacementline.h" + +class Replacement { +public: + Replacement(); + Replacement(const QString& path, const QList& lines); + QString path() const; + QList lines() const; +protected: + QString mPath; + QList mLines; +}; + +#endif // REPLACEMENT_H diff --git a/src/replacementline.cpp b/src/replacementline.cpp new file mode 100644 index 0000000..66b5d7a --- /dev/null +++ b/src/replacementline.cpp @@ -0,0 +1,21 @@ +#include "replacementline.h" + +ReplacementLine::ReplacementLine() { + +} + +ReplacementLine::ReplacementLine(int line, const QString &oldLine, const QString &newLine) : mLine(line), mOldLine(oldLine), mNewLine(newLine) { + +} + +int ReplacementLine::line() const { + return mLine; +} + +QString ReplacementLine::oldLine() const { + return mOldLine; +} + +QString ReplacementLine::newLine() const { + return mNewLine; +} diff --git a/src/replacementline.h b/src/replacementline.h new file mode 100644 index 0000000..c6ba515 --- /dev/null +++ b/src/replacementline.h @@ -0,0 +1,21 @@ +#ifndef REPLACEMENTLINE_H +#define REPLACEMENTLINE_H + +#include + +class ReplacementLine { +public: + ReplacementLine(); + ReplacementLine(int line, const QString& oldLine, const QString& newLine); + int line() const; + QString oldLine() const; + QString newLine() const; + +protected: + int mLine; + QString mOldLine; + QString mNewLine; +}; + + +#endif // REPLACEMENTLINE_H diff --git a/src/rxcollector.cpp b/src/rxcollector.cpp new file mode 100644 index 0000000..b17cd49 --- /dev/null +++ b/src/rxcollector.cpp @@ -0,0 +1,163 @@ +#include "rxcollector.h" + +#include +#include +#include +#include +#include +#include "utils.h" + +#include "rxreplaceinput.h" +#include "rxpathinput.h" +#include "rxinput.h" + + +RXCollector *RXCollector::mInstance = nullptr; + +#define COLLECTION_SIZE 20 + +RXCollector *RXCollector::instance() +{ + if (!mInstance) { + mInstance = new RXCollector(); + } + return mInstance; +} + +void RXCollector::collect(const RegExpPath &exp) +{ + mPathExps = prependModels(mPathExps, exp.exps()); +} + +void RXCollector::collect(const RegExp &exp) +{ + mExps = prependModels(mExps, exp.exps()); +} + +void RXCollector::collect(const QString& exp) { + QStringList exps; + exps << exp; + mReplacements = prependModels(mReplacements, exps); +} + +QList RXCollector::prependModels(const QList &models, const QStringList &exps) { + + //qDebug() << "prependModels" << models.size(); + QList models_; + for(int i=0;i(models[i]); + QString s = exps.value(i); + QStringList items = model->stringList(); + QStringList items_; + items_.append(s); + std::copy_if(items.begin(),items.end(),std::back_inserter(items_), + [&](const QString& item){return item != s;}); + if (items_.size() > COLLECTION_SIZE) { + items_.removeLast(); + } + //qDebug() << s << items << items_; + QStringListModel *model_ = new QStringListModel(); + model_->setStringList(items_); + models_ << model_; + } + return models_; +} + +void RXCollector::load(RXPathInput *input) +{ + for(int i=0;iinput(i); + QStringListModel* model = mPathExps[i]; + QString text = combo->currentText(); + combo->setModel(model); + combo->setCurrentText(text); + } +} + +void RXCollector::load(RXInput *input) { + for(int i=0;iinput(i); + QStringListModel* model = mExps[i]; + QString text = combo->currentText(); + combo->setModel(model); + combo->setCurrentText(text); + } +} + +void RXCollector::load(RXReplaceInput *input) { + for(int i=0;iinput(i); + QStringListModel* model = mReplacements[i]; + QString text = combo->currentText(); + combo->setModel(model); + combo->setCurrentText(text); + } +} + +void arrayOfArraysOfString(const QVariantList& src, QJsonArray& dst) { + for(QVariant v: src) { + dst.append(QJsonArray::fromStringList(v.toStringList())); + } +} + +void RXCollector::serialize(QJsonObject &j) +{ + QJsonArray pathexps; + arrayOfArraysOfString(modelsLists(mPathExps), pathexps); + QJsonArray exps; + arrayOfArraysOfString(modelsLists(mExps),exps); + QJsonArray replacements; + arrayOfArraysOfString(modelsLists(mReplacements),replacements); + j["pathexps"] = pathexps; + j["exps"] = exps; + j["replacements"] = replacements; +} + +QVariantList RXCollector::modelsLists(const QList &models) { + QVariantList exps; + for(int i=0;istringList()); + } + return exps; +} + +void RXCollector::deserialize(const QList &models, const QJsonArray& exps) { + + if (!exps.isEmpty()) { + for(int i=0;isetStringList(vs); + } + } + } +} + +void RXCollector::deserialize(const QJsonObject &j) +{ + deserialize(mPathExps,j.value("pathexps").toArray()); + deserialize(mExps,j.value("exps").toArray()); + deserialize(mReplacements,j.value("replacements").toArray()); +} + +QList RXCollector::models() +{ + QList result; + result << mPathExps << mExps; + return result; +} + +RXCollector::RXCollector() +{ + for(int i=0;i<4;i++) { + mPathExps << new QStringListModel(); + } + for(int i=0;i<2;i++) { + mExps << new QStringListModel(); + } + mReplacements << new QStringListModel(); +} diff --git a/rxcollector.h b/src/rxcollector.h similarity index 69% rename from rxcollector.h rename to src/rxcollector.h index 553e2bb..1dc3337 100644 --- a/rxcollector.h +++ b/src/rxcollector.h @@ -4,8 +4,9 @@ #include "regexppath.h" #include "regexp.h" -#include "widget/rxpathinput.h" -#include "widget/rxinput.h" +class RXInput; +class RXPathInput; +class RXReplaceInput; #include @@ -15,23 +16,30 @@ class RXCollector static RXCollector* instance(); void collect(const RegExpPath& exp); void collect(const RegExp& exp); + void collect(const QString &exp); void load(RXPathInput* input); - //void load(); + void load(RXInput *input); + void load(RXReplaceInput *input); void serialize(QJsonObject& json); - void prependModels(const QList &models, const QStringList &exps); - void load(RXInput *input); + QList prependModels(const QList &models, const QStringList &exps); + void deserialize(const QList &models, const QJsonArray &exps); QVariantList modelsLists(const QList &models); void deserialize(const QJsonObject &j); + QList models(); + + + protected: RXCollector(); static RXCollector* mInstance; QList mPathExps; QList mExps; + QList mReplacements; }; #endif // RXCOLLECTOR_H diff --git a/src/searchcache.cpp b/src/searchcache.cpp new file mode 100644 index 0000000..316e1c4 --- /dev/null +++ b/src/searchcache.cpp @@ -0,0 +1,552 @@ +#include "searchcache.h" + +#include +#include +#include + +#include "html.h" +#include "filereader.h" +#include "lit.h" +#include "worker.h" +#include "utils.h" + +QStringList bytesToLines(const QByteArray& bytes) { + QTextCodec* codec = QTextCodec::codecForName("UTF-8"); + QStringList lines = codec->toUnicode(bytes).split("\n"); + return lines; +} + +QByteArray linesToBytes(const QStringList& lines) { + QTextCodec* codec = QTextCodec::codecForName("UTF-8"); + return codec->fromUnicode(lines.join("\n")); +} + + +QStringList searchLines(const QStringList& mLines, const QString& mPath, const QString& mRelativePath, + const RegExp& exp, int linesBefore, int linesAfter) { + + QStringList res; + + QSet matched; + QSet siblings; + + // pass 1 + for(int i=0;i 0) { + if (i - prev > 0) { + QString part = replacement.mid(prev,i - prev); + result.append(part); + } + QString ref = replacement.mid(i+1,len-1); + result.append(ref.toInt()); + prev = i + len; + i += len; + } else { + i++; + } + } + if (prev < replacement.size()) { + QString part = replacement.mid(prev); + result.append(part); + } + return result; +} + +void compare(const QVariantList& e, const QVariantList& a) { + if (e == a) { + return; + } + QString e_ = "{" + Utils::toStringList(e).join("|") + "}"; + QString a_ = "{" + Utils::toStringList(a).join("|") + "}"; + qDebug() << "not equal, expected: " << e_.toStdString().c_str() << ", actual " << a_.toStdString().c_str(); +} + + +QString withBackreferences(const QRegularExpressionMatch& m, const QVariantList& replacement) { + QStringList result; + foreach(const QVariant& v, replacement) { + if (v.type() == QVariant::Int) { + result.append(m.captured(v.toInt())); + } else if (v.type() == QVariant::String) { + result.append(v.toString()); + } else { + qDebug() << "withBackreferences error:" << v; + } + } + return result.join(""); +} + +QStringList replacePreview(const QStringList& lines, const QString& path, const QString& mRelativePath, + const RegExp& exp, const QString& replacement, QList& replacements) { + + QStringList res; + + QList matched; + + for(int i=0;i replacementLines; + for(int i=0;itoUnicode(bytes).split("\n"); + *lineCount = lines.size(); + return searchLines(lines,path,relativePath,exp,linesBefore,linesAfter); +} + +QStringList replacePreview(const QByteArray& bytes, const QString& path, const QString& relativePath, + const RegExp& exp, int* lineCount, const QString& replacement, QList& replacements) { + + QTextCodec* codec = QTextCodec::codecForName("UTF-8"); + QStringList lines = codec->toUnicode(bytes).split("\n"); + *lineCount = lines.size(); + return replacePreview(lines,path,relativePath,exp,replacement,replacements); +} + +QStringList searchBinary(const QByteArray& bytes, const QString& path, const QString& relativePath, + const RegExp& exp) { + + QTextCodec* codec = QTextCodec::codecForName("UTF-8"); // todo guess or chose encoding + QStringList lines = codec->toUnicode(bytes).split("\n"); + return searchBinary(lines,path,relativePath,exp); +} + +SearchCache::SearchCache() { + +} + +QPair SearchCache::countMatchedFiles(QString path, RegExpPath filter, bool notBinary) { + + QMutexLocker locked(&mMutex); + + //qDebug() << filter << notBinary; + + QStringList allFiles = getAllFiles(path, true); + int filesFiltered; + int dirsFiltered; + // todo optimize + QStringList files = filterFiles(allFiles,filter,notBinary,&filesFiltered,&dirsFiltered); + return QPair(files.size(),allFiles.size()); +} + +QStringList SearchCache::getAllFiles(QString path, bool cacheFileList) { + // todo skip directory entirely if filter matches if not cacheFileList + QString path_ = QDir(path).absolutePath(); + QStringList allFiles; + if (cacheFileList && mFileList.contains(path_)) { + allFiles = mFileList[path_]; + } else { + QDirIterator it(path, QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) { + QString path = it.next(); + allFiles.append(path); + } + if (cacheFileList) { + mFileList[path_] = allFiles; + } + } + if (!cacheFileList) { + mFileList.remove(path_); + } + return allFiles; +} + + + +QStringList SearchCache::filterFiles(const QStringList& allFiles, RegExpPath filter, bool notBinary, int* filesFiltered, int* dirsFiltered) { + + int filesFiltered_ = 0; + int dirsFiltered_ = 0; + + QStringList files; + + foreach(const QString& path, allFiles) { + if (path.contains("/.git/")) { // todo skip settings + filesFiltered_++; + continue; + } + if (notBinary && Utils::isBinExt(path)) { + filesFiltered_++; + continue; + } + if (filter.match(path)) { + files << path; + } else { + filesFiltered_++; + } + } + + *filesFiltered = filesFiltered_; + *dirsFiltered = dirsFiltered_; + + return files; +} + + + +void SearchCache::add(SearchParams params) { + + QMutexLocker locked(&mMutex); + + QString path = params.path(); + bool cacheFileList = params.cacheFileList(); + RegExpPath filter = params.filter(); + bool notBinary = params.skipBinary(); + + int searchId = params.id(); + + QStringList allFiles = getAllFiles(path, cacheFileList); + int filesFiltered; + int dirsFiltered; + QStringList files = filterFiles(allFiles, filter, notBinary, &filesFiltered, &dirsFiltered); + + SearchData data(files, filesFiltered, dirsFiltered); + + mSearchParams.insert(searchId,params); + mSearchData.insert(searchId,data); + mReplacements.insert(searchId,QList()); +} + +void SearchCache::finish(int searchId) { + /* + QMutexLocker locked(&mMutex); + mSearchData.remove(searchId); + */ +} + +bool SearchCache::isPreview(int searchId) { + QMutexLocker locked(&mMutex); + return mSearchParams.contains(searchId) && mSearchParams[searchId].action() == Worker::Preview && mReplacements.contains(searchId); +} + +void SearchCache::search(int searchId, QString &data, int *complete, int *total, int *filtered, QString &file) { + + QMutexLocker locked(&mMutex); + + if (!mSearchParams.contains(searchId)) { + qDebug() << "!mSearchData.contains(searchId)"; + return; + } + + SearchParams& searchParams = mSearchParams[searchId]; + SearchData& searchData = mSearchData[searchId]; + QList& replacements = mReplacements[searchId]; + + //int lim = qMin(sd.complete + 100, sd.files.size()); + QStringList res; + + int lineCount = 0; + int fileCount = 0; + + for (int i=searchData.filesComplete();ifile(path,sd.notBinary,&binary,&readOk); + QByteArray fileData = FileReader::read(path,searchParams.skipBinary(),&binary,&readOk,&tooBig); + QString relPath = Utils::relPath(path,searchParams.path()); + + bool ok = true; + + if (!readOk) { + qDebug() << "!readOk" << path; + ok = false; + } + + if (tooBig) { // todo implement line by line search in big files + ok = false; + } + + int fileLineCount = 0; + + if (ok) { + if (searchParams.action() == Worker::Search) { + if (binary) { + res << searchBinary(fileData, path, relPath, searchParams.search()); + } else { + res << searchLines(fileData, path, relPath, searchParams.search(), searchParams.linesBefore(), searchParams.linesAfter(), &fileLineCount); + } + } else if (searchParams.action() == Worker::Preview) { + if (binary) { + + } else { + res << replacePreview(fileData, path, relPath, searchParams.search(), &fileLineCount, searchParams.replace(), replacements); + } + } + } + + lineCount += fileLineCount; + fileCount += 1; + searchData.setFilesComplete(i + 1); + + if (res.size() > 100 || lineCount > 4000 || fileCount > 50) { + data = res.join("
"); + *complete = searchData.filesComplete(); + *total = searchData.filesSize(); + *filtered = searchData.filesFiltered(); + file = relPath; + return; + } + } + data = res.join("
"); + *complete = searchData.filesComplete(); + *total = searchData.filesSize(); + *filtered = searchData.filesFiltered(); + file = QString(); +} + +void SearchCache::replace(int searchId, int* filesChanged, int* linesChanged, QStringList& notChanged) { + QMutexLocker locked(&mMutex); + if (!mReplacements.contains(searchId)) { + return; + } + + SearchParams params = mSearchParams[searchId]; + + *filesChanged = 0; + *linesChanged = 0; + + QList replacements = mReplacements[searchId]; + foreach(const Replacement& replacement, replacements) { + bool readOk, tooBig, binary; + QString path = replacement.path(); + QStringList lines = bytesToLines(FileReader::read(path,true,&binary,&readOk,&tooBig)); + if (!readOk) { + qDebug() << "cannot read" << path; + continue; + } + if (tooBig) { + qDebug() << "too big" << path; + continue; + } + bool ok = true; + QList replLines = replacement.lines(); + foreach (const ReplacementLine& replLine, replLines) { + int lineNum = replLine.line(); + if (lines[lineNum] == replLine.oldLine()) { + lines[lineNum] = replLine.newLine(); + } else { + qDebug() << lines[lineNum]; + qDebug() << replLine.oldLine(); + ok = false; + } + } + if (ok) { + *filesChanged += 1; + *linesChanged += replLines.size(); + } else { + notChanged << Utils::relPath(path,params.path()); + } + + if (!ok) { + qDebug() << "file changed" << path; + continue; + } + QFile file(path); + if (!file.open(QIODevice::WriteOnly)) { + qDebug() << "canot open file" << path; + continue; + } + file.write(linesToBytes(lines)); + file.close(); + } + + mReplacements.remove(searchId); +} + +void SearchCache::testTokenize() { + + qDebug() << "testTokenize() started"; + + QString t; + QVariantList a,e; + + t = "foo\\1bar\\2baz"; + e = Lit::vl("foo",1,"bar",2,"baz"); + a = tokenize(t); + compare(e,a); + + t = "foo\\1bar\\2baz\\3"; + e = Lit::vl("foo",1,"bar",2,"baz",3); + a = tokenize(t); + compare(e,a); + + t = "foo\\1bar\\2baz\\3a"; + e = Lit::vl("foo",1,"bar",2,"baz",3,"a"); + a = tokenize(t); + compare(e,a); + + t = "\\1bar\\2baz\\3"; + e = Lit::vl(1,"bar",2,"baz",3); + a = tokenize(t); + compare(e,a); + + t = "\\1bar\\2\\3baz\\52"; + e = Lit::vl(1,"bar",2,3,"baz",52); + a = tokenize(t); + compare(e,a); + + qDebug() << "testTokenize() finished"; +} + diff --git a/searchcache.h b/src/searchcache.h similarity index 77% rename from searchcache.h rename to src/searchcache.h index 62de24e..0109699 100644 --- a/searchcache.h +++ b/src/searchcache.h @@ -3,13 +3,14 @@ #include "regexp.h" #include "regexppath.h" -#include "struct/searchdata.h" #include #include #include +#include "searchparams.h" +#include "searchdata.h" +#include "replacement.h" -QString ext(const QString& path); QStringList searchLines(const QStringList &mLines, const QString& mPath, const QString& mRelativePath, const RegExp& exp, int linesBefore, int linesAfter); @@ -19,14 +20,14 @@ QStringList searchLines(const QByteArray& mLines, const QString& mPath, const QS QStringList fileLines(const QString& path, bool skipBinary, bool* binary = nullptr); -QString relPath(const QString& path, const QString& base); class SearchCache { public: SearchCache(); - void add(int searchId, QString path, RegExpPath filter, bool notBinary, RegExp search, - int linesBefore, int linesAfter, bool cacheFileList); + void add(SearchParams params); + + void replace(int searchId, int* filesChanged, int* linesChanged, QStringList& notChanged); void finish(int searchId); @@ -37,10 +38,16 @@ class SearchCache { QPair countMatchedFiles(QString path, RegExpPath filter, bool notBinary); QStringList getAllFiles(QString path, bool cacheFileList); static QStringList filterFiles(const QStringList &allFiles, RegExpPath filter, bool notBinary, int *filesFiltered, int *dirsFiltered); + static void testTokenize(); + + bool isPreview(int searchId); + protected: QMutex mMutex; + QMap mSearchParams; QMap mSearchData; + QMap > mReplacements; QMap mFileList; }; diff --git a/src/searchdata.cpp b/src/searchdata.cpp new file mode 100644 index 0000000..07f6abb --- /dev/null +++ b/src/searchdata.cpp @@ -0,0 +1,48 @@ +#include "searchdata.h" + +SearchData::SearchData() : mFilesComplete(-1), mFilesFiltered(-1), mDirsFiltered(-1) { +} + +SearchData::SearchData(const QStringList& files, int filesFiltered, int dirsFiltered) + : mFiles(files), mFilesComplete(0), mFilesFiltered(filesFiltered), mDirsFiltered(dirsFiltered) { +} + +QStringList SearchData::files() const { + return mFiles; +} + +void SearchData::setFiles(const QStringList& files) { + mFiles = files; +} + +int SearchData::filesComplete() const { + return mFilesComplete; +} + +void SearchData::setFilesComplete(int filesComplete) { + mFilesComplete = filesComplete; +} + +int SearchData::filesFiltered() const { + return mFilesFiltered; +} + +void SearchData::setFilesFiltered(int filesFiltered) { + mFilesFiltered = filesFiltered; +} + +int SearchData::dirsFiltered() const { + return mDirsFiltered; +} + +void SearchData::setDirsFiltered(int dirsFiltered) { + mDirsFiltered = dirsFiltered; +} + +int SearchData::filesSize() const { + return mFiles.size(); +} + +QString SearchData::file(int i) const { + return mFiles[i]; +} diff --git a/src/searchdata.h b/src/searchdata.h new file mode 100644 index 0000000..7418fc4 --- /dev/null +++ b/src/searchdata.h @@ -0,0 +1,27 @@ +#ifndef SEARCHDATA_H +#define SEARCHDATA_H +#include +#include + +class SearchData { +public: + SearchData(); + SearchData(const QStringList& files, int filesFiltered, int dirsFiltered); + QStringList files() const; + void setFiles(const QStringList& files); + int filesComplete() const; + void setFilesComplete(int filesComplete); + int filesFiltered() const; + void setFilesFiltered(int filesFiltered); + int dirsFiltered() const; + void setDirsFiltered(int dirsFiltered); + int filesSize() const; + QString file(int i) const; + +protected: + QStringList mFiles; + int mFilesComplete; + int mFilesFiltered; + int mDirsFiltered; +}; +#endif // SEARCHDATA_H diff --git a/searchid.cpp b/src/searchid.cpp similarity index 100% rename from searchid.cpp rename to src/searchid.cpp diff --git a/searchid.h b/src/searchid.h similarity index 100% rename from searchid.h rename to src/searchid.h diff --git a/src/searchparams.cpp b/src/searchparams.cpp new file mode 100644 index 0000000..24cf6e2 --- /dev/null +++ b/src/searchparams.cpp @@ -0,0 +1,94 @@ +#include "searchparams.h" + +SearchParams::SearchParams() + : mAction(-1), mId(-1), mSkipBinary(false), mLinesBefore(-1), mLinesAfter(-1), + mCacheFileList(false) { +} + +SearchParams::SearchParams(int action, int id, const QString& path, const RegExpPath& filter, + bool skipBinary, const RegExp& search, int linesBefore, int linesAfter, + bool cacheFileList, const QString& replace) + : mAction(action), mId(id), mPath(path), mFilter(filter), mSkipBinary(skipBinary), + mSearch(search), mLinesBefore(linesBefore), mLinesAfter(linesAfter), + mCacheFileList(cacheFileList), mReplace(replace) { +} + +int SearchParams::action() const { + return mAction; +} + +void SearchParams::setAction(int action) { + mAction = action; +} + +int SearchParams::id() const { + return mId; +} + +void SearchParams::setId(int id) { + mId = id; +} + +QString SearchParams::path() const { + return mPath; +} + +void SearchParams::setPath(const QString& path) { + mPath = path; +} + +RegExpPath SearchParams::filter() const { + return mFilter; +} + +void SearchParams::setFilter(const RegExpPath& filter) { + mFilter = filter; +} + +bool SearchParams::skipBinary() const { + return mSkipBinary; +} + +void SearchParams::setSkipBinary(bool skipBinary) { + mSkipBinary = skipBinary; +} + +RegExp SearchParams::search() const { + return mSearch; +} + +void SearchParams::setSearch(const RegExp& search) { + mSearch = search; +} + +int SearchParams::linesBefore() const { + return mLinesBefore; +} + +void SearchParams::setLinesBefore(int linesBefore) { + mLinesBefore = linesBefore; +} + +int SearchParams::linesAfter() const { + return mLinesAfter; +} + +void SearchParams::setLinesAfter(int linesAfter) { + mLinesAfter = linesAfter; +} + +bool SearchParams::cacheFileList() const { + return mCacheFileList; +} + +void SearchParams::setCacheFileList(bool cacheFileList) { + mCacheFileList = cacheFileList; +} + +QString SearchParams::replace() const { + return mReplace; +} + +void SearchParams::setReplace(const QString& replace) { + mReplace = replace; +} diff --git a/src/searchparams.h b/src/searchparams.h new file mode 100644 index 0000000..257ad71 --- /dev/null +++ b/src/searchparams.h @@ -0,0 +1,49 @@ +#ifndef SEARCHPARAMS_H +#define SEARCHPARAMS_H +#include "regexp.h" +#include "regexppath.h" +#include +#include + +class SearchParams { +public: + SearchParams(); + SearchParams(int action, int id, const QString& path, const RegExpPath& filter, bool skipBinary, + const RegExp& search, int linesBefore, int linesAfter, bool cacheFileList, + const QString& replace); + int action() const; + void setAction(int action); + int id() const; + void setId(int id); + QString path() const; + void setPath(const QString& path); + RegExpPath filter() const; + void setFilter(const RegExpPath& filter); + bool skipBinary() const; + void setSkipBinary(bool skipBinary); + RegExp search() const; + void setSearch(const RegExp& search); + int linesBefore() const; + void setLinesBefore(int linesBefore); + int linesAfter() const; + void setLinesAfter(int linesAfter); + bool cacheFileList() const; + void setCacheFileList(bool cacheFileList); + QString replace() const; + void setReplace(const QString& replace); + +protected: + int mAction; + int mId; + QString mPath; + RegExpPath mFilter; + bool mSkipBinary; + RegExp mSearch; + int mLinesBefore; + int mLinesAfter; + bool mCacheFileList; + QString mReplace; +}; +Q_DECLARE_METATYPE(SearchParams) + +#endif // SEARCHPARAMS_H diff --git a/settings.cpp b/src/settings.cpp similarity index 99% rename from settings.cpp rename to src/settings.cpp index 1125480..1b8572a 100644 --- a/settings.cpp +++ b/src/settings.cpp @@ -8,7 +8,7 @@ #include #include #include -#include "utils/jsonhelper.h" +#include "jsonhelper.h" #include "regexppath.h" /*static*/ diff --git a/settings.h b/src/settings.h similarity index 96% rename from settings.h rename to src/settings.h index abcde04..1596144 100644 --- a/settings.h +++ b/src/settings.h @@ -3,7 +3,7 @@ #include -#include "struct/editor.h" +#include "editor.h" #include #include #include diff --git a/utils/isbinext.cpp b/src/utils.cpp similarity index 58% rename from utils/isbinext.cpp rename to src/utils.cpp index b9fed4f..6cad1ca 100644 --- a/utils/isbinext.cpp +++ b/src/utils.cpp @@ -1,18 +1,12 @@ -#include "isbinext.h" +#include "utils.h" -#include - -namespace { - -QString ext(const QString& path) { +QString Utils::ext(const QString& path) { if (path.indexOf(".")>-1) return path.split(".").last().toLower(); return QString(); } -} - -bool isBinExt(const QString &path) +bool Utils::isBinExt(const QString &path) { static QStringList binaryExts; if (binaryExts.isEmpty()) { @@ -26,3 +20,22 @@ bool isBinExt(const QString &path) } return binaryExts.contains(ext(path)); } + +QString Utils::relPath(const QString& path, const QString& base) { + if (path.startsWith(base)) { + if ((path[base.size()] == QChar('\\') || path[base.size()] == QChar('/')) && path.size() > base.size()) + return path.mid(base.size()+1); + else + return path.mid(base.size()); + } + return path; +} + + +QStringList Utils::toStringList(const QVariantList& vs) { + QStringList res; + foreach(const QVariant& v, vs) { + res << v.toString(); + } + return res; +} diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..1acc27a --- /dev/null +++ b/src/utils.h @@ -0,0 +1,18 @@ +#ifndef UTLIS_H +#define UTLIS_H + +#include +#include + +namespace Utils { + +bool isBinExt(const QString& path); + +QString ext(const QString& path); + +QString relPath(const QString& path, const QString& base); + +QStringList toStringList(const QVariantList& vs); + +} +#endif // UTLIS_H diff --git a/version.h b/src/version.h similarity index 100% rename from version.h rename to src/version.h diff --git a/widget/elidedlabel.cpp b/src/widget/elidedlabel.cpp similarity index 96% rename from widget/elidedlabel.cpp rename to src/widget/elidedlabel.cpp index 0aa404d..a43844a 100644 --- a/widget/elidedlabel.cpp +++ b/src/widget/elidedlabel.cpp @@ -10,7 +10,7 @@ ElidedLabel::ElidedLabel(QWidget *parent) : QWidget(parent), mTextElideMode(Qt:: } -void ElidedLabel::paintEvent(QPaintEvent *event) +void ElidedLabel::paintEvent(QPaintEvent *) { QStyle *style = QWidget::style(); QPainter painter(this); diff --git a/widget/elidedlabel.h b/src/widget/elidedlabel.h similarity index 100% rename from widget/elidedlabel.h rename to src/widget/elidedlabel.h diff --git a/widget/intlineedit.cpp b/src/widget/intlineedit.cpp similarity index 100% rename from widget/intlineedit.cpp rename to src/widget/intlineedit.cpp diff --git a/widget/intlineedit.h b/src/widget/intlineedit.h similarity index 100% rename from widget/intlineedit.h rename to src/widget/intlineedit.h diff --git a/widget/mainwindow.cpp b/src/widget/mainwindow.cpp similarity index 73% rename from widget/mainwindow.cpp rename to src/widget/mainwindow.cpp index a9e3ec9..9972d46 100644 --- a/widget/mainwindow.cpp +++ b/src/widget/mainwindow.cpp @@ -10,18 +10,19 @@ #include #include -#include "widget/sessionwidget.h" - -#include "widget/settingsdialog.h" -#include "utils/jsonhelper.h" +#include "sessionwidget.h" +#include "settingsdialog.h" +#include "jsonhelper.h" #include "settings.h" #include "rxcollector.h" #include #include "anchorclickhandler.h" +#include "completermodelmanager.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow), mMapper(new QSignalMapper(this)), mClickHandler(new AnchorClickHandler()) + ui(new Ui::MainWindow), mMapper(new QSignalMapper(this)), + mClickHandler(new AnchorClickHandler(this)), mCompleterModelManager(new CompleterModelManager(this)) { ui->setupUi(this); @@ -55,10 +56,9 @@ void MainWindow::closeEvent(QCloseEvent * e) { for(int i=0;itabs->count();i++) { - QWidget* w = ui->tabs->widget(i); - SessionWidget* sw = qobject_cast(w); - if (sw) { - sw->onCanceled(); + SessionWidget* session = tab(i); + if (session) { + session->onCanceled(); } } @@ -76,6 +76,7 @@ void MainWindow::closeEvent(QCloseEvent * e) void MainWindow::addSession(const QJsonObject &v) { SessionWidget* session = new SessionWidget(ui->tabs); + session->setCacheFileList(ui->cacheFileList); //connect(session,SIGNAL(setEditor()),this,SLOT(onSetEditor())); //connect(this,SIGNAL(editorSet()),session,SLOT(onEditorSet())); @@ -86,28 +87,30 @@ void MainWindow::addSession(const QJsonObject &v) { if (!path.isEmpty()) { title = QFileInfo(path).baseName(); } - ui->tabs->addTab(session,title); mMapper->setMapping(session,session); - - if (!v.isEmpty()) + if (!v.isEmpty()) { session->deserialize(v); - + } + session->updateCompletions(); + connect(session,&SessionWidget::collect,[=](){ + mCompleterModelManager->onCollect(session->options(), ui->tabs); + }); } void MainWindow::removeSession() { - if (ui->tabs->count() == 0) + if (ui->tabs->count() == 0) { return; + } int currentIndex = ui->tabs->currentIndex(); - QWidget* w = ui->tabs->widget(currentIndex); - SessionWidget* sw = qobject_cast(w); - if (sw) { - sw->onCanceled(); + SessionWidget* session = tab(currentIndex); + if (session) { + session->onCanceled(); } ui->tabs->removeTab(currentIndex); - + session->deleteLater(); } SessionWidget *MainWindow::tab(int index) @@ -115,6 +118,10 @@ SessionWidget *MainWindow::tab(int index) return qobject_cast(ui->tabs->widget(index)); } +SessionWidget *MainWindow::currentTab() { + return tab(ui->tabs->currentIndex()); +} + void MainWindow::serializeSessions(QJsonArray& json) const { for(int i=0;itabs->count();i++) { @@ -155,23 +162,19 @@ void MainWindow::on_addSession_triggered() void MainWindow::on_removeSession_triggered() { - if (ui->tabs->count() == 0) + if (ui->tabs->count() == 0) { return; - - int currentIndex = ui->tabs->currentIndex(); - - QWidget* w = ui->tabs->widget(currentIndex); - SessionWidget* sw = qobject_cast(w); - if (!sw) + } + int index = ui->tabs->currentIndex(); + SessionWidget* session = tab(index); + if (!session) { return; - - sw->onCanceled(); - ui->tabs->removeTab(currentIndex); - + } + session->onCanceled(); + ui->tabs->removeTab(index); + session->deleteLater(); } - - void MainWindow::on_saveSessions_triggered() { QString path = QFileDialog::getSaveFileName(this,QString(),QString(),"json files (*.json)"); @@ -217,8 +220,6 @@ void MainWindow::on_loadSessions_triggered() { } } - - void MainWindow::on_setEditors_triggered() { mClickHandler->onSetEditor(); @@ -240,17 +241,16 @@ void MainWindow::onReadStarted(QWidget* w) { return; } ui->tabs->setTabText(index,name); - } -void MainWindow::on_tabs_currentChanged(int index) +void MainWindow::on_tabs_currentChanged(int) { - SessionWidget* widget = qobject_cast(ui->tabs->widget(index)); + /*SessionWidget* widget = tab(index); if (!widget) { qDebug() << "not SessionWidget at index" << index << ui->tabs->widget(index); return; } - widget->updateCollector(); + widget->updateCompletions();*/ } void MainWindow::on_removeAllSessions_triggered() @@ -259,3 +259,30 @@ void MainWindow::on_removeAllSessions_triggered() on_removeSession_triggered(); } } + +void MainWindow::setCurrentTabMode(SearchOptionsWidget::Mode mode) { + SessionWidget* tab = currentTab(); + if (!tab) { + return; + } + tab->setMode(mode); +} + +void MainWindow::on_search_triggered() +{ + setCurrentTabMode(SearchOptionsWidget::ModeSearch); +} + +void MainWindow::on_replace_triggered() +{ + setCurrentTabMode(SearchOptionsWidget::ModeReplace); +} + +void MainWindow::on_select_triggered() +{ + SessionWidget* tab = currentTab(); + if (!tab) { + return; + } + tab->select(); +} diff --git a/widget/mainwindow.h b/src/widget/mainwindow.h similarity index 80% rename from widget/mainwindow.h rename to src/widget/mainwindow.h index 2153257..cc75b45 100644 --- a/widget/mainwindow.h +++ b/src/widget/mainwindow.h @@ -5,10 +5,12 @@ #include #include #include +#include "searchoptionswidget.h" class SessionWidget; class QSignalMapper; class AnchorClickHandler; +class CompleterModelManager; namespace Ui { class MainWindow; @@ -28,15 +30,21 @@ class MainWindow : public QMainWindow void removeSession(); SessionWidget* tab(int index); + SessionWidget *currentTab(); void deserealizeSessions(const QJsonArray &vl); void serializeExps(QJsonObject &json) const; void deserealizeExps(const QJsonObject &exps); void serializeSessions(QJsonArray &json) const; + void setCurrentTabMode(SearchOptionsWidget::Mode mode); + + protected: Ui::MainWindow *ui; QSignalMapper* mMapper; AnchorClickHandler* mClickHandler; + CompleterModelManager* mCompleterModelManager; + signals: void editorSet(); @@ -49,17 +57,17 @@ protected slots: void on_saveSessions_triggered(); void on_loadSessions_triggered(); - void on_setEditors_triggered(); void onReadStarted(QWidget *); - -private slots: void on_tabs_currentChanged(int index); void on_removeAllSessions_triggered(); + void on_search_triggered(); + void on_replace_triggered(); + void on_select_triggered(); }; #endif // MAINWINDOW_H diff --git a/widget/mainwindow.ui b/src/widget/mainwindow.ui similarity index 70% rename from widget/mainwindow.ui rename to src/widget/mainwindow.ui index d671553..f57377d 100644 --- a/widget/mainwindow.ui +++ b/src/widget/mainwindow.ui @@ -40,12 +40,12 @@ 0 0 800 - 25 + 21 - Sessions + &Sessions @@ -55,11 +55,21 @@ - Settings + &Settings + + + + &Action + + + + + + @@ -73,7 +83,7 @@ - Add (Ctrl+T) + &Add Ctrl+T @@ -81,7 +91,7 @@ - Remove (Ctrl+W) + &Remove Ctrl+W @@ -89,7 +99,7 @@ - Save (Ctrl+S) + &Save Ctrl+S @@ -97,7 +107,7 @@ - Load (Ctrl+L) + &Load Ctrl+L @@ -113,6 +123,35 @@ Remove All + + + &Search + + + Ctrl+F + + + + + &Replace + + + Ctrl+H + + + + + S&elect + + + + + true + + + Cache file list + + diff --git a/widget/regexpbaseinput.cpp b/src/widget/regexpbaseinput.cpp similarity index 100% rename from widget/regexpbaseinput.cpp rename to src/widget/regexpbaseinput.cpp diff --git a/widget/regexpbaseinput.h b/src/widget/regexpbaseinput.h similarity index 100% rename from widget/regexpbaseinput.h rename to src/widget/regexpbaseinput.h diff --git a/src/widget/rxbaseinput.cpp b/src/widget/rxbaseinput.cpp new file mode 100644 index 0000000..4d72a91 --- /dev/null +++ b/src/widget/rxbaseinput.cpp @@ -0,0 +1,63 @@ +#include "widget/rxbaseinput.h" +#include + +RXBaseInput::RXBaseInput() : mValidated(false) +{ +} + +QStringList RXBaseInput::exps() const +{ + QStringList res; + QComboBox* input; + foreach(input,mInputs) { + res << input->currentText(); + } + return res; +} + +void RXBaseInput::setExps(const QStringList &exps) +{ + for(int i=0;ilineEdit()->setText(exps.value(i)); + } +} + +QComboBox *RXBaseInput::input(int index) +{ + return mInputs[index]; +} + +int RXBaseInput::count() const +{ + return mInputs.size(); +} + +bool RXBaseInput::validate(const QPalette& palette) +{ + QPalette paletteValid = palette; + QPalette paletteInvalid = paletteValid; + paletteInvalid.setColor(QPalette::Text,QColor(Qt::red)); + + bool ok = true; + foreach(QComboBox* input, mInputs) { + QString text = input->lineEdit()->text(); + bool valid = text.isEmpty() || QRegularExpression(text).isValid(); + ok = ok && valid; + input->setPalette(valid ? paletteValid : paletteInvalid); + } + mValidated = true; + return ok; +} + +void RXBaseInput::clearValidation(const QPalette &palette) +{ + if (!mValidated) { + return; + } + foreach(QComboBox* input, mInputs) { + input->setPalette(palette); + } + mValidated = false; +} + diff --git a/widget/rxbaseinput.h b/src/widget/rxbaseinput.h similarity index 73% rename from widget/rxbaseinput.h rename to src/widget/rxbaseinput.h index 31999ac..941fefe 100644 --- a/widget/rxbaseinput.h +++ b/src/widget/rxbaseinput.h @@ -12,8 +12,11 @@ class RXBaseInput virtual void setExps(const QStringList &exps); QComboBox* input(int index); int count() const; + virtual bool validate(const QPalette &palette); + void clearValidation(const QPalette &palette); protected: QList mInputs; + bool mValidated; }; #endif // RXBASEINPUT_H diff --git a/widget/rxinput.cpp b/src/widget/rxinput.cpp similarity index 60% rename from widget/rxinput.cpp rename to src/widget/rxinput.cpp index 42a7434..01c7a74 100644 --- a/widget/rxinput.cpp +++ b/src/widget/rxinput.cpp @@ -1,6 +1,9 @@ #include "widget/rxinput.h" #include "ui_rxinput.h" #include +#include +#include +#include RXInput::RXInput(QWidget *parent) : QWidget(parent), @@ -8,11 +11,16 @@ RXInput::RXInput(QWidget *parent) : { ui->setupUi(this); + QRect rect = qApp->primaryScreen()->geometry(); + int maximumWidth = rect.width() / 2; + mInputs << ui->include << ui->exclude; QComboBox* input; foreach(input,mInputs) { - QObject::connect(input->lineEdit(),SIGNAL(returnPressed()),this,SIGNAL(returnPressed())); + connect(input->lineEdit(),SIGNAL(returnPressed()),this,SIGNAL(returnPressed())); connect(input->lineEdit(),SIGNAL(textChanged(QString)),this,SIGNAL(textChanged())); + connect(input->lineEdit(),SIGNAL(textChanged(QString)),this,SLOT(onClearValidation())); + input->setMaximumWidth(maximumWidth); } connect(ui->matchCase,SIGNAL(clicked(bool)),this,SIGNAL(caseClicked(bool))); } @@ -31,4 +39,6 @@ void RXInput::setValue(const RegExp &value) { ui->matchCase->setChecked(value.case_()); } - +void RXInput::onClearValidation() { + RXBaseInput::clearValidation(palette()); +} diff --git a/widget/rxinput.h b/src/widget/rxinput.h similarity index 91% rename from widget/rxinput.h rename to src/widget/rxinput.h index 35c97c3..2926eb6 100644 --- a/widget/rxinput.h +++ b/src/widget/rxinput.h @@ -21,6 +21,7 @@ class RXInput : public QWidget, public RXBaseInput RegExp value() const; void setValue(const RegExp &value); + protected: Ui::RXInput *ui; @@ -29,6 +30,8 @@ class RXInput : public QWidget, public RXBaseInput void textChanged(); void caseClicked(bool); +protected slots: + void onClearValidation(); }; #endif // RXINPUT_H diff --git a/widget/rxinput.ui b/src/widget/rxinput.ui similarity index 100% rename from widget/rxinput.ui rename to src/widget/rxinput.ui diff --git a/widget/rxpathinput.cpp b/src/widget/rxpathinput.cpp similarity index 81% rename from widget/rxpathinput.cpp rename to src/widget/rxpathinput.cpp index 4f99087..30de54f 100644 --- a/widget/rxpathinput.cpp +++ b/src/widget/rxpathinput.cpp @@ -1,10 +1,9 @@ #include "widget/rxpathinput.h" #include "ui_rxpathinput.h" -#include "utils/sl.h" - #include #include +#include RXPathInput::RXPathInput(QWidget *parent) : QWidget(parent), @@ -13,6 +12,9 @@ RXPathInput::RXPathInput(QWidget *parent) : { ui->setupUi(this); + QRect rect = qApp->primaryScreen()->geometry(); + int maximumWidth = rect.width() / 4; + mInputs << ui->nameInclude << ui->extInclude << ui->nameExclude @@ -21,6 +23,8 @@ RXPathInput::RXPathInput(QWidget *parent) : foreach(input,mInputs) { connect(input->lineEdit(),SIGNAL(returnPressed()),this,SIGNAL(returnPressed())); connect(input->lineEdit(),SIGNAL(textChanged(QString)),this,SIGNAL(textChanged())); + connect(input->lineEdit(),SIGNAL(textChanged(QString)),this,SLOT(onClearValidation())); + input->setMaximumWidth(maximumWidth); } connect(ui->matchCase,SIGNAL(clicked(bool)),this,SIGNAL(caseClicked(bool))); } @@ -64,14 +68,6 @@ void RXPathInput::setExpludeExtValue(const QString &value) ui->extExclude->lineEdit()->setText(value); } -#if 0 -void RXPathInput::onTextChanged() -{ - if (!mEmitTextChanged) { - //qDebug() << "!mEmitTextChanged"; - return; - } - //qDebug() << "emit textChanged()"; - emit textChanged(); +void RXPathInput::onClearValidation() { + RXBaseInput::clearValidation(palette()); } -#endif diff --git a/widget/rxpathinput.h b/src/widget/rxpathinput.h similarity index 94% rename from widget/rxpathinput.h rename to src/widget/rxpathinput.h index 3bfa4fc..15b0a51 100644 --- a/widget/rxpathinput.h +++ b/src/widget/rxpathinput.h @@ -31,8 +31,10 @@ class RXPathInput : public QWidget, public RXBaseInput protected slots: //void onTextChanged(); + void onClearValidation(); protected: bool mEmitTextChanged; + QList mFocus; Ui::RXPathInput *ui; signals: diff --git a/widget/rxpathinput.ui b/src/widget/rxpathinput.ui similarity index 100% rename from widget/rxpathinput.ui rename to src/widget/rxpathinput.ui diff --git a/src/widget/rxreplaceinput.cpp b/src/widget/rxreplaceinput.cpp new file mode 100644 index 0000000..511e8b4 --- /dev/null +++ b/src/widget/rxreplaceinput.cpp @@ -0,0 +1,46 @@ +#include "rxreplaceinput.h" +#include "ui_rxreplaceinput.h" + +#include + +RXReplaceInput::RXReplaceInput(QWidget *parent) : + QWidget(parent), + ui(new Ui::RXReplaceInput) +{ + ui->setupUi(this); + mInputs << ui->replace; + QComboBox* input; + foreach(input,mInputs) { + connect(input->lineEdit(),SIGNAL(returnPressed()),this,SIGNAL(returnPressed())); + connect(input->lineEdit(),SIGNAL(textChanged(QString)),this,SIGNAL(textChanged(QString))); + connect(input->lineEdit(),SIGNAL(textChanged(QString)),this,SLOT(onClearValidation())); + } +} + +RXReplaceInput::~RXReplaceInput() +{ + delete ui; +} + +QString RXReplaceInput::value() const +{ + QStringList exps = this->exps(); + return exps[0]; +} + +void RXReplaceInput::setValue(const QString &value) +{ + QStringList exps; + exps << value; + setExps(exps); +} + +bool RXReplaceInput::validate(const QPalette &palette) +{ + return true; +} + + +void RXReplaceInput::onClearValidation() { + RXBaseInput::clearValidation(palette()); +} diff --git a/src/widget/rxreplaceinput.h b/src/widget/rxreplaceinput.h new file mode 100644 index 0000000..2674a27 --- /dev/null +++ b/src/widget/rxreplaceinput.h @@ -0,0 +1,35 @@ +#ifndef RXREPLACEINPUT_H +#define RXREPLACEINPUT_H + +#include + +#include "rxbaseinput.h" + +namespace Ui { +class RXReplaceInput; +} + +class RXReplaceInput : public QWidget, public RXBaseInput +{ + Q_OBJECT + +public: + explicit RXReplaceInput(QWidget *parent = 0); + ~RXReplaceInput(); + + QString value() const; + void setValue(const QString& value); + + bool validate(const QPalette &palette) override; + +signals: + void returnPressed(); + void textChanged(QString); + +protected slots: + void onClearValidation(); +private: + Ui::RXReplaceInput *ui; +}; + +#endif // RXREPLACEINPUT_H diff --git a/src/widget/rxreplaceinput.ui b/src/widget/rxreplaceinput.ui new file mode 100644 index 0000000..8ca53aa --- /dev/null +++ b/src/widget/rxreplaceinput.ui @@ -0,0 +1,40 @@ + + + RXReplaceInput + + + + 0 + 0 + 400 + 34 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + + + diff --git a/widget/searchbrowser.cpp b/src/widget/searchbrowser.cpp similarity index 79% rename from widget/searchbrowser.cpp rename to src/widget/searchbrowser.cpp index baed3d8..cb1b718 100644 --- a/widget/searchbrowser.cpp +++ b/src/widget/searchbrowser.cpp @@ -2,7 +2,7 @@ #include SearchBrowser::SearchBrowser(QWidget* parent) - : QTextBrowser(parent), mSearchId(-1), mLinesBefore(0), mLinesAfter(0), mCacheFileList(false), + : QTextBrowser(parent), mSearchId(-1), mLinesBefore(0), mLinesAfter(0), mNotBinary(false), mChanged(QDateTime::currentDateTime()) { setOpenLinks(false); //@todo external stylesheet @@ -16,7 +16,7 @@ SearchBrowser::SearchBrowser(QWidget* parent) } SearchBrowser::~SearchBrowser() { - qDebug() << "~SearchBrowser()"; + //qDebug() << "~SearchBrowser()"; } int SearchBrowser::searchId() const { return mSearchId; @@ -35,7 +35,6 @@ RegExp SearchBrowser::exp() const { void SearchBrowser::setExp(const RegExp& exp) { mExp = exp; mChanged = QDateTime::currentDateTime(); - qDebug() << "exp changed"; } RegExpPath SearchBrowser::filter() const { @@ -45,7 +44,6 @@ RegExpPath SearchBrowser::filter() const { void SearchBrowser::setFilter(const RegExpPath& filter) { mFilter = filter; mChanged = QDateTime::currentDateTime(); - qDebug() << "filter changed"; } int SearchBrowser::linesBefore() const { @@ -55,7 +53,6 @@ int SearchBrowser::linesBefore() const { void SearchBrowser::setLinesBefore(int linesBefore) { mLinesBefore = linesBefore; mChanged = QDateTime::currentDateTime(); - qDebug() << "linesBefore changed"; } int SearchBrowser::linesAfter() const { @@ -65,17 +62,6 @@ int SearchBrowser::linesAfter() const { void SearchBrowser::setLinesAfter(int linesAfter) { mLinesAfter = linesAfter; mChanged = QDateTime::currentDateTime(); - qDebug() << "linesAfter changed"; -} - -bool SearchBrowser::cacheFileList() const { - return mCacheFileList; -} - -void SearchBrowser::setCacheFileList(bool cacheFileList) { - mCacheFileList = cacheFileList; - mChanged = QDateTime::currentDateTime(); - qDebug() << "cacheFileList changed"; } bool SearchBrowser::notBinary() const { @@ -85,7 +71,6 @@ bool SearchBrowser::notBinary() const { void SearchBrowser::setNotBinary(bool notBinary) { mNotBinary = notBinary; mChanged = QDateTime::currentDateTime(); - qDebug() << "notBinary changed"; } QDateTime SearchBrowser::changed() const { @@ -105,7 +90,20 @@ void SearchBrowser::copy(SearchBrowser* dest) { dest->setFilter(mFilter); dest->setLinesBefore(mLinesBefore); dest->setLinesAfter(mLinesAfter); - dest->setCacheFileList(mCacheFileList); dest->setNotBinary(mNotBinary); dest->setChanged(mChanged); + dest->setReplacement(mReplacement); +} + +QString SearchBrowser::replacement() const { + return mReplacement; +} + +void SearchBrowser::setReplacement(const QString& value) { + mReplacement = value; +} + +SearchParams SearchBrowser::params(int action, int id, const QString &path, bool cacheFileList) +{ + return SearchParams(action, id, path, mFilter, mNotBinary, mExp, mLinesBefore, mLinesAfter, cacheFileList, mReplacement); } diff --git a/widget/searchbrowser.h b/src/widget/searchbrowser.h similarity index 81% rename from widget/searchbrowser.h rename to src/widget/searchbrowser.h index 582bfb7..74ca381 100644 --- a/widget/searchbrowser.h +++ b/src/widget/searchbrowser.h @@ -6,6 +6,8 @@ #include #include +#include "searchparams.h" + class QDebug; class SearchBrowser : public QTextBrowser { Q_OBJECT @@ -22,23 +24,28 @@ class SearchBrowser : public QTextBrowser { void setLinesBefore(int linesBefore); int linesAfter() const; void setLinesAfter(int linesAfter); - bool cacheFileList() const; - void setCacheFileList(bool cacheFileList); + bool notBinary() const; void setNotBinary(bool notBinary); QDateTime changed() const; void setChanged(const QDateTime& changed); bool isExecuted() const; void copy(SearchBrowser* dest); + QString replacement() const; + void setReplacement(const QString &value); + + SearchParams params(int action, int id, const QString& path, bool cacheFileList); protected: + int mMode; int mSearchId; RegExp mExp; RegExpPath mFilter; int mLinesBefore; int mLinesAfter; - bool mCacheFileList; + bool mNotBinary; QDateTime mChanged; + QString mReplacement; }; #endif // SEARCHBROWSER_H diff --git a/widget/searchoptionswidget.cpp b/src/widget/searchoptionswidget.cpp similarity index 65% rename from widget/searchoptionswidget.cpp rename to src/widget/searchoptionswidget.cpp index f0d9834..5ccdb6b 100644 --- a/widget/searchoptionswidget.cpp +++ b/src/widget/searchoptionswidget.cpp @@ -9,14 +9,16 @@ #include "worker.h" #include "anchorclickhandler.h" #include "selectfilesdialog.h" - +#include SearchOptionsWidget::SearchOptionsWidget(QWidget *parent) : QWidget(parent), + mMode(ModeSearch), + mCacheFileList(0), ui(new Ui::SearchOptionsWidget) { ui->setupUi(this); - + ui->search->setEnabled(false); } SearchOptionsWidget::~SearchOptionsWidget() @@ -26,22 +28,16 @@ SearchOptionsWidget::~SearchOptionsWidget() void SearchOptionsWidget::setBrowser(SearchBrowser *browser, bool setValues) { - qDebug() << "setBrowser" << browser << setValues; - mBrowser = browser; - mActive = false; - if (setValues) { - - RXCollector::instance()->load(ui->filter); - RXCollector::instance()->load(ui->exp); - + //updateCompletions(); + mActive = false; ui->filter->setValue(browser->filter()); ui->exp->setValue(browser->exp()); ui->linesBefore->setValue(browser->linesBefore()); ui->linesAfter->setValue(browser->linesAfter()); - ui->cacheFileList->setChecked(browser->cacheFileList()); ui->notBinary->setChecked(browser->notBinary()); + ui->replacement->setValue(browser->replacement()); ui->filter->hide(); ui->filter->show(); // force layout to recalculate @@ -50,6 +46,17 @@ void SearchOptionsWidget::setBrowser(SearchBrowser *browser, bool setValues) mActive = true; } +void SearchOptionsWidget::setMode(SearchOptionsWidget::Mode mode) +{ + mMode = mode; + QWidgetList widgets; + widgets << ui->replaceLabel << ui->replace << ui->preview << ui->replacement; + foreach(QWidget* widget, widgets) { + widget->setVisible(mode == ModeReplace); + } + ui->search->setVisible(mode == ModeSearch); +} + void SearchOptionsWidget::init(Worker *worker, AnchorClickHandler* clickHandler) { connect(ui->filter,SIGNAL(returnPressed()),this,SIGNAL(search())); @@ -58,10 +65,13 @@ void SearchOptionsWidget::init(Worker *worker, AnchorClickHandler* clickHandler) connect(ui->exp,SIGNAL(textChanged()),this,SLOT(onExpTextChanged())); connect(ui->linesAfter,SIGNAL(valueChanged(int)),this,SLOT(onLinesAfterValueChanged())); connect(ui->linesBefore,SIGNAL(valueChanged(int)),this,SLOT(onLinesBeforeValueChanged())); - connect(ui->cacheFileList,SIGNAL(clicked(bool)),this,SLOT(onCacheFileListClicked(bool))); connect(ui->notBinary,SIGNAL(clicked(bool)),this,SLOT(onNotBinaryClicked(bool))); connect(ui->filter,SIGNAL(caseClicked(bool)),this,SLOT(onFilterTextChanged())); connect(ui->exp,SIGNAL(caseClicked(bool)),this,SLOT(onExpTextChanged())); + connect(ui->linesBefore,SIGNAL(returnPressed()),this,SIGNAL(search())); + connect(ui->linesAfter,SIGNAL(returnPressed()),this,SIGNAL(search())); + connect(ui->replacement,SIGNAL(returnPressed()),this,SIGNAL(preview())); + connect(ui->replacement,SIGNAL(textChanged(QString)),this,SLOT(onReplacementTextChanged(QString))); mWorker = worker; mClickHandler = clickHandler; @@ -69,7 +79,8 @@ void SearchOptionsWidget::init(Worker *worker, AnchorClickHandler* clickHandler) mWorker,SLOT(onCountMatchedFiles(QString,RegExpPath,bool))); connect(mWorker,SIGNAL(count(int,int)),this,SLOT(onCountMatchedFiles(int,int))); - ui->fileCount->setText(QString()); + ui->fileCount->setText("? / ?"); + setMode(mMode); } @@ -83,40 +94,42 @@ void SearchOptionsWidget::setPath(const QString &path) ui->path->setText(path); } +bool SearchOptionsWidget::validate() +{ + QPalette palette = this->palette(); + + bool ok1 = ui->filter->validate(palette); + bool ok2 = ui->exp->validate(palette); + bool ok3 = mMode == ModeReplace ? ui->replacement->validate(palette) : true; + return ok1 && ok2 && ok3; +} + void SearchOptionsWidget::setBrowserValues() { mBrowser->setFilter(ui->filter->value()); mBrowser->setExp(ui->exp->value()); mBrowser->setLinesBefore(ui->linesBefore->value()); mBrowser->setLinesAfter(ui->linesAfter->value()); - mBrowser->setCacheFileList(ui->cacheFileList->isChecked()); mBrowser->setNotBinary(ui->notBinary->isChecked()); + mBrowser->setReplacement(ui->replacement->value()); } void SearchOptionsWidget::collect() { RXCollector* collector = RXCollector::instance(); - mActive = false; + //mActive = false; collector->collect(ui->exp->value()); collector->collect(ui->filter->value()); - collector->load(ui->exp); - collector->load(ui->filter); - mActive = true; + collector->collect(ui->replacement->value()); + //updateCollector(); } -void SearchOptionsWidget::updateCollector() { - RXCollector* collector = RXCollector::instance(); +void SearchOptionsWidget::updateCompletions() { mActive = false; - - RegExp exp = ui->exp->value(); - RegExpPath filter = ui->filter->value(); - + RXCollector* collector = RXCollector::instance(); collector->load(ui->exp); collector->load(ui->filter); - - ui->exp->setValue(exp); - ui->filter->setValue(filter); - + collector->load(ui->replacement); mActive = true; } @@ -141,8 +154,14 @@ void SearchOptionsWidget::on_search_clicked() void SearchOptionsWidget::countMatchedFiles() { // todo cache - if (!ui->cacheFileList->isChecked()) { - ui->fileCount->setText(QString()); + + if (!mCacheFileList) { + //qDebug() << "!mCacheFileList"; + return; + } + + if (!mCacheFileList->isChecked()) { + //ui->fileCount->setText(QString()); return; } ui->fileCount->setText("? / ?"); @@ -152,6 +171,11 @@ void SearchOptionsWidget::countMatchedFiles() { emit countMatchedFiles(path,filter,notBinary); } +void SearchOptionsWidget::setCanReplace(bool can) +{ + ui->replace->setEnabled(can); +} + void SearchOptionsWidget::onFilterTextChanged() { if (!mActive || !mBrowser) { return; @@ -165,6 +189,7 @@ void SearchOptionsWidget::onFilterTextChanged() { } void SearchOptionsWidget::onExpTextChanged() { + ui->search->setEnabled(!ui->exp->value().isEmpty()); if (!mActive || !mBrowser) { return; } @@ -177,7 +202,18 @@ void SearchOptionsWidget::onExpTextChanged() { } void SearchOptionsWidget::emitTabTitle() { - emit tabTitle(ui->exp->value().include(), mBrowser->isExecuted()); + + QString include = ui->exp->value().include(); + QString exclude = ui->exp->value().exclude(); + QString title; + if (include.isEmpty() && exclude.isEmpty()) { + title = ""; + } else if (!include.isEmpty()) { + title = include; + } else { + title = "~" + exclude; + } + emit tabTitle(title, mBrowser->isExecuted()); } void SearchOptionsWidget::onLinesAfterValueChanged() { @@ -202,21 +238,7 @@ void SearchOptionsWidget::onLinesBeforeValueChanged() { mBrowser->setLinesBefore(ui->linesBefore->value()); } -void SearchOptionsWidget::onCacheFileListClicked(bool value) { - if (!mActive || !mBrowser) { - return; - } - if (mBrowser->isExecuted()) { - emit clone(); - return; - } - mBrowser->setCacheFileList(value); -} - - - -void SearchOptionsWidget::on_selectFiles_clicked() -{ +void SearchOptionsWidget::select() { QString path = ui->path->text(); SelectFilesDialog dialog(path, ui->filter->value(), mWorker, mClickHandler, this); if (dialog.exec() == QDialog::Accepted) { @@ -224,12 +246,24 @@ void SearchOptionsWidget::on_selectFiles_clicked() } } +void SearchOptionsWidget::setCacheFileList(QAction *action) +{ + mCacheFileList = action; + ui->fileCount->setVisible(action->isChecked()); + connect(mCacheFileList,&QAction::toggled,[=](bool checked){ + ui->fileCount->setVisible(checked); + if (checked && !ui->filter->value().isEmpty()) { + emit countMatchedFiles(); + } + }); +} + void SearchOptionsWidget::onCountMatchedFiles(int matched, int total) { ui->fileCount->setText(QString("%1 / %2 files").arg(matched).arg(total)); } -void SearchOptionsWidget::on_path_textChanged(const QString &path) +void SearchOptionsWidget::on_path_textChanged(QString path) { emit pathChanged(path); } @@ -245,4 +279,24 @@ void SearchOptionsWidget::onNotBinaryClicked(bool value) { mBrowser->setNotBinary(value); } +void SearchOptionsWidget::on_replace_clicked() +{ + emit replace(); +} + +void SearchOptionsWidget::on_preview_clicked() +{ + emit preview(); +} +void SearchOptionsWidget::onReplacementTextChanged(QString value) +{ + if (!mActive || !mBrowser) { + return; + } + if (mBrowser->isExecuted()) { + emit clone(); + return; + } + mBrowser->setReplacement(value); +} diff --git a/widget/searchoptionswidget.h b/src/widget/searchoptionswidget.h similarity index 72% rename from widget/searchoptionswidget.h rename to src/widget/searchoptionswidget.h index 2e9b5da..edc76a4 100644 --- a/widget/searchoptionswidget.h +++ b/src/widget/searchoptionswidget.h @@ -7,6 +7,8 @@ class SearchBrowser; class Worker; class AnchorClickHandler; +class RXInput; +class RXPathInput; namespace Ui { class SearchOptionsWidget; @@ -17,24 +19,37 @@ class SearchOptionsWidget : public QWidget Q_OBJECT public: + enum Mode { + ModeSearch, + ModeReplace + }; explicit SearchOptionsWidget(QWidget *parent = nullptr); ~SearchOptionsWidget(); void setActive(bool active); void setBrowser(SearchBrowser* browser, bool setValues = true); + void setMode(Mode mode); QString path() const; void setPath(const QString& path); + bool validate(); + void collect(); void emitTabTitle(); void init(Worker *worker, AnchorClickHandler *clickHandler); void setBrowserValues(); - void updateCollector(); + void updateCompletions(); void countMatchedFiles(); + void setCanReplace(bool can); + + void select(); + void setCacheFileList(QAction* action); signals: void search(); + void preview(); + void replace(); void clone(); void tabTitle(QString, bool); void countMatchedFiles(QString,RegExpPath,bool); @@ -42,22 +57,25 @@ class SearchOptionsWidget : public QWidget protected slots: void onFilterTextChanged(); void onExpTextChanged(); - void on_selectPath_clicked(); - void on_search_clicked(); void onLinesAfterValueChanged(); void onLinesBeforeValueChanged(); - void onCacheFileListClicked(bool); void onCountMatchedFiles(int matched, int total); void onNotBinaryClicked(bool value); + void onReplacementTextChanged(QString path); + void on_selectPath_clicked(); + void on_search_clicked(); + void on_path_textChanged(QString path); + void on_replace_clicked(); + void on_preview_clicked(); + protected: Ui::SearchOptionsWidget *ui; bool mActive; SearchBrowser* mBrowser; Worker* mWorker; AnchorClickHandler* mClickHandler; -private slots: - void on_selectFiles_clicked(); - void on_path_textChanged(const QString &arg1); + Mode mMode; + QAction* mCacheFileList; }; #endif // SEARCHOPTIONSWIDGET_H diff --git a/widget/searchoptionswidget.ui b/src/widget/searchoptionswidget.ui similarity index 79% rename from widget/searchoptionswidget.ui rename to src/widget/searchoptionswidget.ui index 87acaa7..019f45a 100644 --- a/widget/searchoptionswidget.ui +++ b/src/widget/searchoptionswidget.ui @@ -6,8 +6,8 @@ 0 0 - 650 - 127 + 660 + 178 @@ -28,34 +28,28 @@ - - + + - Path + Lines - - - - - + + - select + fileCount - - + + - Files + select - - - - + not binary @@ -65,24 +59,44 @@ - + + + + Files + + + + Find - + + + + + + + Path + + + + + + + - - + + - Lines + Replace - + @@ -144,30 +158,30 @@ - + - fileCount + search + + + + - - - select - - + - + - cache file list + preview - + - search + replace @@ -195,6 +209,12 @@
widget/rxinput.h
1 + + RXReplaceInput + QWidget +
widget/rxreplaceinput.h
+ 1 +
diff --git a/widget/searchprogresswidget.cpp b/src/widget/searchprogresswidget.cpp similarity index 80% rename from widget/searchprogresswidget.cpp rename to src/widget/searchprogresswidget.cpp index 8fea0cf..6562453 100644 --- a/widget/searchprogresswidget.cpp +++ b/src/widget/searchprogresswidget.cpp @@ -48,3 +48,13 @@ void SearchProgressWidget::aborted() { ui->status2->setText(QString()); ui->status2->hide(); } + +void SearchProgressWidget::replaced(int files,int lines) { + ui->status1->setText(QString("%2 line%4 replaced in %1 file%3") + .arg(files) + .arg(lines) + .arg(files == 1 ? "" : "s") + .arg(lines == 1 ? "" : "s")); + ui->status2->setText(QString()); + ui->status2->hide(); +} diff --git a/widget/searchprogresswidget.h b/src/widget/searchprogresswidget.h similarity index 92% rename from widget/searchprogresswidget.h rename to src/widget/searchprogresswidget.h index ce0d314..6321fa7 100644 --- a/widget/searchprogresswidget.h +++ b/src/widget/searchprogresswidget.h @@ -19,6 +19,7 @@ class SearchProgressWidget : public QWidget void init(); void progress(int i, int t, int s, QString path); void aborted(); + void replaced(int files, int lines); signals: void canceled(); private: diff --git a/widget/searchprogresswidget.ui b/src/widget/searchprogresswidget.ui similarity index 100% rename from widget/searchprogresswidget.ui rename to src/widget/searchprogresswidget.ui diff --git a/widget/selectfilesdialog.cpp b/src/widget/selectfilesdialog.cpp similarity index 100% rename from widget/selectfilesdialog.cpp rename to src/widget/selectfilesdialog.cpp diff --git a/widget/selectfilesdialog.h b/src/widget/selectfilesdialog.h similarity index 100% rename from widget/selectfilesdialog.h rename to src/widget/selectfilesdialog.h diff --git a/widget/selectfilesdialog.ui b/src/widget/selectfilesdialog.ui similarity index 100% rename from widget/selectfilesdialog.ui rename to src/widget/selectfilesdialog.ui diff --git a/widget/sessionwidget.cpp b/src/widget/sessionwidget.cpp similarity index 66% rename from widget/sessionwidget.cpp rename to src/widget/sessionwidget.cpp index c94f9aa..be8505d 100644 --- a/widget/sessionwidget.cpp +++ b/src/widget/sessionwidget.cpp @@ -12,9 +12,9 @@ #include #include #include +#include #include "widget/searchbrowser.h" -#include "utils/sl.h" #include "worker.h" #include "rxcollector.h" @@ -23,6 +23,7 @@ #include #include "anchorclickhandler.h" #include "widget/selectfilesdialog.h" +#include "widget/mainwindow.h" #define RESULT_TAB_LIMIT 10 @@ -30,6 +31,7 @@ SessionWidget::SessionWidget(QWidget *parent) : QWidget(parent), ui(new Ui::SessionWidget), mClickHandler(new AnchorClickHandler()), + mCacheFileList(0), //mListenResultCurrentChanged(true), mSetValues(true) { @@ -42,19 +44,28 @@ SessionWidget::SessionWidget(QWidget *parent) : mWorker->moveToThread(mThread); - connect(this,SIGNAL(search(int,QString,RegExpPath,bool,RegExp,int,int,bool)), - mWorker,SLOT(onSearch(int,QString,RegExpPath,bool,RegExp,int,int,bool))); + /*connect(this,SIGNAL(search(int,int,QString,RegExpPath,bool,RegExp,int,int,bool,QString)), + mWorker,SLOT(onSearch(int,int,QString,RegExpPath,bool,RegExp,int,int,bool,QString)));*/ + + connect(this,SIGNAL(search(SearchParams)),mWorker,SLOT(onSearch(SearchParams))); + + connect(this,SIGNAL(replace(int)),mWorker,SLOT(onReplace(int))); connect(mWorker,SIGNAL(found(int,QString,int,int,int,QString)), this,SLOT(onFound(int,QString,int,int,int,QString))); connect(this,SIGNAL(searchMore(int)),mWorker,SLOT(onSearchMore(int))); connect(this,SIGNAL(finishSearch(int)),mWorker,SLOT(onFinishSearch(int))); connect(ui->options,SIGNAL(clone()),this,SLOT(onClone())); connect(ui->options,SIGNAL(search()),this,SLOT(onSearch())); + connect(ui->options,SIGNAL(preview()),this,SLOT(onPreview())); + connect(ui->options,SIGNAL(replace()),this,SLOT(onReplace())); connect(ui->options,SIGNAL(tabTitle(QString,bool)),this,SLOT(onTabTitle(QString,bool))); connect(ui->options,SIGNAL(pathChanged(QString)),this,SLOT(onPathChanged(QString))); - connect(ui->progress,SIGNAL(canceled()),this,SLOT(onCanceled())); + connect(this,SIGNAL(canReplace(int)),mWorker,SLOT(onCanReplace(int))); + connect(mWorker,SIGNAL(canReplace(int,bool)),this,SLOT(onCanReplace(int,bool))); + connect(mWorker,SIGNAL(replaced(int,int,int,QStringList)),this,SLOT(onReplaced(int,int,int,QStringList))); + mThread->start(); while(ui->results->count() > 0) { @@ -67,6 +78,8 @@ SessionWidget::SessionWidget(QWidget *parent) : SearchBrowser* browser_ = new SearchBrowser(); mClickHandler->connectBrowser(browser_); ui->results->addTab(browser_,QString()); + + ui->statusGroup->hide(); } SessionWidget::~SessionWidget() @@ -81,6 +94,12 @@ SessionWidget::~SessionWidget() delete ui; } +void SessionWidget::setCacheFileList(QAction *action) +{ + mCacheFileList = action; + ui->options->setCacheFileList(action); +} + void SessionWidget::onClone() { SearchBrowser* browser = currentTab(); SearchBrowser* browser_ = new SearchBrowser(); @@ -102,24 +121,61 @@ void SessionWidget::onClone() { } } -void SessionWidget::onSearch() { +SearchOptionsWidget* SessionWidget::options() const{ + return ui->options; +} + +void SessionWidget::setMode(SearchOptionsWidget::Mode mode) +{ + ui->options->setMode(mode); +} + +void SessionWidget::select() +{ + ui->options->select(); +} + + + +void SessionWidget::searchOrReplace(Worker::Action action) { SearchBrowser* browser = currentTab(); - if (browser->isExecuted()) { + if (browser->exp().isEmpty()) { return; } + + bool valid = ui->options->validate(); + if (!valid) { + return; + } + mCancel = false; + emit collect(); int searchId = SearchId::instance()->next(); + browser->setText(QString()); browser->setSearchId(searchId); - ui->options->collect(); ui->options->emitTabTitle(); - emit search(searchId,ui->options->path(),browser->filter(),browser->notBinary(),browser->exp(), - browser->linesBefore(),browser->linesAfter(),browser->cacheFileList()); + SearchParams params = browser->params(action, searchId, ui->options->path(), mCacheFileList->isChecked()); + emit search(params); ui->progress->started(); } +void SessionWidget::onSearch() { + searchOrReplace(Worker::Search); +} + +void SessionWidget::onPreview() { + searchOrReplace(Worker::Preview); +} + +void SessionWidget::onReplace() { + SearchBrowser* browser = currentTab(); + int searchId = browser->searchId(); + emit replace(searchId); +} + int SessionWidget::oldestTabIndex() { // todo test me int count = ui->results->count(); if (count < 1) { @@ -142,6 +198,8 @@ void SessionWidget::onTabTitle(QString title, bool isExecuted) { if (!isExecuted) { title = title + "*"; } + QFontMetrics fm(font()); + title = fm.elidedText(title,Qt::ElideMiddle,200); ui->results->setTabText(ui->results->currentIndex(),title); } @@ -160,9 +218,9 @@ void SessionWidget::deserialize(const QJsonObject &v) ui->options->setPath(v.value("path").toString()); } -void SessionWidget::updateCollector() +void SessionWidget::updateCompletions() { - ui->options->updateCollector(); + ui->options->updateCompletions(); } void SessionWidget::save(const QString &path, const QString &text) @@ -180,6 +238,18 @@ void SessionWidget::onCanceled() { mCancel = true; } +void SessionWidget::onCanReplace(int searchId, bool can) +{ + SearchBrowser* browser = currentTab(); + if (!browser) { + return; + } + if (browser->searchId() != searchId) { + return; + } + ui->options->setCanReplace(can); +} + void SessionWidget::on_saveText_clicked() { save(true); @@ -217,12 +287,12 @@ SearchBrowser* SessionWidget::find(int searchId) { void SessionWidget::onFound(int searchId, QString res, int i, int t, int s, QString path) { - qDebug() << searchId << res.size() << "chars" << i << t << s << path; + //qDebug() << searchId << res.size() << "chars" << i << t << s << path; SearchBrowser* browser = find(searchId); if (!browser) { - qDebug() << "onFound error no browser"; + //qDebug() << "onFound error no browser"; return; } @@ -230,6 +300,8 @@ void SessionWidget::onFound(int searchId, QString res, int i, int t, int s, QStr browser->append(res); } + ui->statusGroup->show(); + ui->progress->progress(i,t,s,path); if (i < t && !mCancel) { @@ -256,15 +328,22 @@ void SessionWidget::on_results_currentChanged(int index) { /*if (!mListenResultCurrentChanged) { return; }*/ - qDebug() << "on_results_currentChanged" << index; + //qDebug() << "on_results_currentChanged" << index << this; SearchBrowser* browser = tab(index); if (!browser) { - qDebug() << "not a browser at index" << index; + //qDebug() << "not a browser at index" << index; return; } ui->options->setBrowser(browser,mSetValues); ui->options->countMatchedFiles(); mSetValues = true; + + ui->options->setCanReplace(false); + int searchId = browser->searchId(); + if (searchId < 0) { + return; + } + emit canReplace(searchId); } void SessionWidget::onPathChanged(QString path) @@ -276,3 +355,15 @@ void SessionWidget::onPathChanged(QString path) mTabWidget->setTabText(mTabWidget->indexOf(this),QFileInfo(path).fileName()); } +void SessionWidget::onReplaced(int searchId,int files,int lines,QStringList notChanged) { + SearchBrowser* browser = currentTab(); + if (browser->searchId() != searchId) { + return; + } + onCanReplace(searchId,false); + ui->progress->replaced(files, lines); + if (notChanged.isEmpty()) { + return; + } + QMessageBox::critical(this,"Error",QString("Failed to replace text in files:\n%1").arg(notChanged.join("\n"))); +} diff --git a/widget/sessionwidget.h b/src/widget/sessionwidget.h similarity index 70% rename from widget/sessionwidget.h rename to src/widget/sessionwidget.h index b28d5bf..4d3f471 100644 --- a/widget/sessionwidget.h +++ b/src/widget/sessionwidget.h @@ -10,6 +10,8 @@ #include "regexppath.h" #include "widget/regexpbaseinput.h" #include "worker.h" +#include "searchparams.h" +#include "searchoptionswidget.h" namespace Ui { class SessionWidget; @@ -21,6 +23,7 @@ class SearchBrowser; class QTabWidget; class AnchorClickHandler; + /* Q_DECLARE_METATYPE(RegExp) Q_DECLARE_METATYPE(RegExpPath)*/ @@ -30,14 +33,17 @@ class SessionWidget : public QWidget Q_OBJECT public: + explicit SessionWidget(QWidget *parent = nullptr); ~SessionWidget(); + void setCacheFileList(QAction* action); + void cancelAll(); QString path() const; - void updateCollector(); + void updateCompletions(); void serialize(QJsonObject &json) const; void deserialize(const QJsonObject &v); @@ -46,6 +52,11 @@ class SessionWidget : public QWidget void countMatchedFiles(); SearchBrowser *currentTab(); int oldestTabIndex(); + SearchOptionsWidget *options() const; + void setMode(SearchOptionsWidget::Mode mode); + + void select(); + protected: Worker* mWorker; @@ -63,17 +74,29 @@ class SessionWidget : public QWidget bool mSetValues; void save(bool plain); + void searchOrReplace(Worker::Action action); + + QAction* mCacheFileList; + signals: - void search(int searchId, QString path, RegExpPath filter, bool notBinary, RegExp search, int linesBofore, int linesAfter,bool cacheFileList); + void search(SearchParams); + void search(int action, int searchId, QString path, RegExpPath filter, bool notBinary, RegExp search, int linesBofore, int linesAfter, bool cacheFileList, QString); void searchMore(int searchId); void finishSearch(int searchId); + //void collected(); + void collect(); + void replace(int); + + void canReplace(int); public slots: void onCanceled(); protected slots: + void onCanReplace(int,bool); + void on_saveText_clicked(); void on_saveHtml_clicked(); void on_results_currentChanged(int index); @@ -82,7 +105,9 @@ protected slots: void onSearch(); void onTabTitle(QString title, bool isExecuted); void onPathChanged(QString path); - + void onPreview(); + void onReplace(); + void onReplaced(int, int, int, QStringList); private: Ui::SessionWidget *ui; }; diff --git a/widget/sessionwidget.ui b/src/widget/sessionwidget.ui similarity index 98% rename from widget/sessionwidget.ui rename to src/widget/sessionwidget.ui index 8b2bacd..97179a9 100644 --- a/widget/sessionwidget.ui +++ b/src/widget/sessionwidget.ui @@ -15,7 +15,7 @@ - + Status diff --git a/widget/settingsdialog.cpp b/src/widget/settingsdialog.cpp similarity index 100% rename from widget/settingsdialog.cpp rename to src/widget/settingsdialog.cpp diff --git a/widget/settingsdialog.h b/src/widget/settingsdialog.h similarity index 100% rename from widget/settingsdialog.h rename to src/widget/settingsdialog.h diff --git a/widget/settingsdialog.ui b/src/widget/settingsdialog.ui similarity index 100% rename from widget/settingsdialog.ui rename to src/widget/settingsdialog.ui diff --git a/worker.cpp b/src/worker.cpp similarity index 58% rename from worker.cpp rename to src/worker.cpp index ee81245..bf48dc6 100644 --- a/worker.cpp +++ b/src/worker.cpp @@ -5,12 +5,18 @@ Worker::Worker(QObject *parent) : { } +void Worker::onSearch(SearchParams params) +{ + mCache.add(params); + emit found(params.id(),QString(),-1,0,0,QString()); +} -void Worker::onSearch(int searchId, QString path, RegExpPath filter, bool notBinary, - RegExp search, int linesBefore, int linesAfter, bool cacheFileList) +void Worker::onReplace(int searchId) { - mCache.add(searchId,path,filter,notBinary,search,linesBefore,linesAfter,cacheFileList); - emit found(searchId,QString(),-1,0,0,QString()); + int files,lines; + QStringList notChanged; + mCache.replace(searchId, &files, &lines, notChanged); + emit replaced(searchId, files, lines, notChanged); } void Worker::onCountMatchedFiles(QString path, RegExpPath filter, bool notBinary) { @@ -36,8 +42,11 @@ void Worker::onSearchMore(int id) emit found(id,data,complete,total,filtered,file); } -void Worker::onFinishSearch(int id) -{ - qDebug() << "onFinishSearch" << id; - mCache.finish(id); +void Worker::onFinishSearch(int id) { + emit canReplace(id, mCache.isPreview(id)); + //mCache.finish(id); +} + +void Worker::onCanReplace(int id) { + emit canReplace(id, mCache.isPreview(id)); } diff --git a/worker.h b/src/worker.h similarity index 61% rename from worker.h rename to src/worker.h index 818481c..b3ecfc0 100644 --- a/worker.h +++ b/src/worker.h @@ -12,14 +12,19 @@ #include #include - -#include "struct/searchdata.h" +#include "searchparams.h" #include "searchcache.h" class Worker : public QObject { Q_OBJECT public: + enum Action { + Search, + Preview, + Replace + }; + explicit Worker(QObject *parent = nullptr); protected: @@ -34,13 +39,20 @@ class Worker : public QObject void allFiles(QString, QStringList); + void canReplace(int, bool); + + void replaced(int,int,int,QStringList); + public slots: - void onSearch(int searchId, QString path, RegExpPath filter, bool notBinary, RegExp search, int linesBofore, int linesAfter, bool cacheFileList); + void onCanReplace(int); + void onReplace(int searchId); void onSearchMore(int); void onFinishSearch(int); void onCountMatchedFiles(QString path, RegExpPath filter, bool notBinary); void onGetAllFiles(QString path); + //void onSearch(int action, int searchId, QString path, RegExpPath filter, bool notBinary, RegExp search, int linesBefore, int linesAfter, bool cacheFileList, QString relpacement); + void onSearch(SearchParams); }; #endif // WORKER2_H diff --git a/struct/searchdata.cpp b/struct/searchdata.cpp deleted file mode 100644 index bc71cfe..0000000 --- a/struct/searchdata.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "struct/searchdata.h" - -SearchData::SearchData() { - -} - -SearchData::SearchData(QString path, RegExpPath filter, bool notBinary, RegExp search, - QStringList files, int linesBefore, int linesAfter, - int filesFiltered, int dirsFiltered) - : path(path), filter(filter), notBinary(notBinary), - search(search), files(files), complete(0), linesBefore(linesBefore), linesAfter(linesAfter), - filesFiltered(filesFiltered), dirsFiltered(dirsFiltered) -{ - -} diff --git a/struct/searchdata.h b/struct/searchdata.h deleted file mode 100644 index 5b108c6..0000000 --- a/struct/searchdata.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef SEARCHDATA_H -#define SEARCHDATA_H - -#include "regexppath.h" -#include "regexp.h" - -struct SearchData { - - SearchData(); - SearchData(QString path, RegExpPath filter, bool notBinary, RegExp search, - QStringList files, int linesBefore, int linesAfter, int filesFiltered, int dirsFiltered); - - QString path; - RegExpPath filter; - bool notBinary; - RegExp search; - QStringList files; - int complete; - int linesBefore; - int linesAfter; - int filesFiltered; - int dirsFiltered; -}; - - -#endif // SEARCHDATA_H diff --git a/todo.txt b/todo.txt index 704915a..3e8b35f 100644 --- a/todo.txt +++ b/todo.txt @@ -1,2 +1,6 @@ text browser context menu: show in explorer, copy path, copy name editors dialog: copy event filter +move tests to tests.cpp +implement line-by line search and replace +clean searchcache on tab remove +show context lines on preview(replace) diff --git a/utils/bl.cpp b/utils/bl.cpp deleted file mode 100644 index 75c1767..0000000 --- a/utils/bl.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "utils/bl.h" - -QList bl(bool b0) -{ -QList res; -res << b0; -return res; -} -QList bl(bool b0, bool b1) -{ -QList res; -res << b0; -res << b1; -return res; -} -QList bl(bool b0, bool b1, bool b2) -{ -QList res; -res << b0; -res << b1; -res << b2; -return res; -} -QList bl(bool b0, bool b1, bool b2, bool b3) -{ -QList res; -res << b0; -res << b1; -res << b2; -res << b3; -return res; -} -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4) -{ -QList res; -res << b0; -res << b1; -res << b2; -res << b3; -res << b4; -return res; -} -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5) -{ -QList res; -res << b0; -res << b1; -res << b2; -res << b3; -res << b4; -res << b5; -return res; -} -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6) -{ -QList res; -res << b0; -res << b1; -res << b2; -res << b3; -res << b4; -res << b5; -res << b6; -return res; -} -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7) -{ -QList res; -res << b0; -res << b1; -res << b2; -res << b3; -res << b4; -res << b5; -res << b6; -res << b7; -return res; -} -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7, bool b8) -{ -QList res; -res << b0; -res << b1; -res << b2; -res << b3; -res << b4; -res << b5; -res << b6; -res << b7; -res << b8; -return res; -} -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7, bool b8, bool b9) -{ -QList res; -res << b0; -res << b1; -res << b2; -res << b3; -res << b4; -res << b5; -res << b6; -res << b7; -res << b8; -res << b9; -return res; -} diff --git a/utils/bl.h b/utils/bl.h deleted file mode 100644 index 49b1ae0..0000000 --- a/utils/bl.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef BL_H -#define BL_H - -#include - -QList bl(bool b0); -QList bl(bool b0, bool b1); -QList bl(bool b0, bool b1, bool b2); -QList bl(bool b0, bool b1, bool b2, bool b3); -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4); -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5); -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6); -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7); -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7, bool b8); -QList bl(bool b0, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7, bool b8, bool b9); - -#endif // BL_H - diff --git a/utils/isbinext.h b/utils/isbinext.h deleted file mode 100644 index 48dd7d4..0000000 --- a/utils/isbinext.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef ISBINEXT_H -#define ISBINEXT_H - -#include - -bool isBinExt(const QString& path); - -#endif // ISBINEXT_H diff --git a/utils/sl.cpp b/utils/sl.cpp deleted file mode 100644 index 456806d..0000000 --- a/utils/sl.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "utils/sl.h" - -QStringList sl(const QString& s0) -{ -QStringList res; -res << s0; -return res; -} -QStringList sl(const QString& s0, const QString& s1) -{ -QStringList res; -res << s0; -res << s1; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -res << s5; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -res << s5; -res << s6; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -res << s5; -res << s6; -res << s7; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -res << s5; -res << s6; -res << s7; -res << s8; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8, const QString& s9) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -res << s5; -res << s6; -res << s7; -res << s8; -res << s9; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8, const QString& s9, const QString& s10) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -res << s5; -res << s6; -res << s7; -res << s8; -res << s9; -res << s10; -return res; -} -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8, const QString& s9, const QString& s10, const QString& s11) -{ -QStringList res; -res << s0; -res << s1; -res << s2; -res << s3; -res << s4; -res << s5; -res << s6; -res << s7; -res << s8; -res << s9; -res << s10; -res << s11; -return res; -} diff --git a/utils/sl.h b/utils/sl.h deleted file mode 100644 index fc99f71..0000000 --- a/utils/sl.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef SL_H -#define SL_H - -#include - -/* - -[ -"QStringList sl(", -["const QString& s%i"], ", ", -")\n{\nQStringList res;\n", -["res << s%i;\n"],"", -"return res;\n}\n" -] - -[ -"QStringList sl(", -["const QString& s%i"], ", ", -");\n" -] - -*/ - -QStringList sl(const QString& s0); -QStringList sl(const QString& s0, const QString& s1); -QStringList sl(const QString& s0, const QString& s1, const QString& s2); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8, const QString& s9); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8, const QString& s9, const QString& s10); -QStringList sl(const QString& s0, const QString& s1, const QString& s2, const QString& s3, const QString& s4, const QString& s5, const QString& s6, const QString& s7, const QString& s8, const QString& s9, const QString& s10, const QString& s11); - - -#endif // SL_H diff --git a/widget/regexpinput.cpp b/widget/regexpinput.cpp deleted file mode 100644 index 23dbcbb..0000000 --- a/widget/regexpinput.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "regexpinput.h" - -#include -#include -#include -#include - -#include "utils/sl.h" - -RegExpInput::RegExpInput(QWidget *parent) : - RegExpBaseInput(2,sl("include","exclude"),nullptr,parent) -{ - QList widgets; - for(int i=0;iaddWidget(widget); - } -} - -RegExp RegExpInput::value() const -{ - if (mMode == Simple) { - RegExp(mInputs[0]->text(),"",mCase->isChecked()); - } - return RegExp(mInputs[0]->text(),mInputs[1]->text(),mCase->isChecked()); -} - -void RegExpInput::setValue(const RegExp &value) -{ - mInputs[0]->setText(value.include()); - mInputs[1]->setText(value.exclude()); - mCase->setChecked(value.case_()); -} - -void RegExpInput::modeChanged() -{ - for(int i=0;isetVisible(i == 0 || mMode == Expert); - mLabels[i]->setVisible(mMode == Expert); - } -} diff --git a/widget/regexppathinput.cpp b/widget/regexppathinput.cpp deleted file mode 100644 index 9e1f1db..0000000 --- a/widget/regexppathinput.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "widget/regexppathinput.h" - -#include - -#include -#include -#include -#include - -#include "utils/sl.h" -#include "utils/bl.h" - -RegExpPathInput::RegExpPathInput(QWidget *parent) : - RegExpBaseInput(4,sl("include","exts","exclude","exts"),0,parent) -{ - QList widgets; - for(int i=0;iaddWidget(widget); - } -} - -RegExpPath RegExpPathInput::value() const -{ - return RegExpPath(exps(),mCase->isChecked()); -} - -void RegExpPathInput::setValue(const RegExpPath &value) -{ - setExps(value.exps()); - mCase->setChecked(value.case_()); -} - -void RegExpPathInput::modeChanged() -{ - for(int i=0;isetVisible(i == 1 || mMode == Expert); - mLabels[i]->setVisible(mMode == Expert); - } - -} diff --git a/widget/regexppathinput.h b/widget/regexppathinput.h deleted file mode 100644 index 29f11b2..0000000 --- a/widget/regexppathinput.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef REGEXPINPUTPATH_H -#define REGEXPINPUTPATH_H - -#include -#include -#include - -class QLineEdit; -class QCheckBox; -class QLabel; - -#include "widget/regexpbaseinput.h" -#include "regexppath.h" - -class RegExpPathInput : public RegExpBaseInput -{ - Q_OBJECT -public: - - explicit RegExpPathInput(QWidget *parent = 0); - RegExpPath value() const; - void setValue(const RegExpPath& value); - - void modeChanged(); - -protected: - - -signals: - - -public slots: - -}; - -#endif // REGEXPINPUTPATH_H diff --git a/widget/regexpwidget.cpp b/widget/regexpwidget.cpp deleted file mode 100644 index fef681c..0000000 --- a/widget/regexpwidget.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include "widget/regexpwidget.h" -#include "regexp.h" - - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -RegExpWidget::RegExpWidget(QWidget *parent) : - QWidget(parent) -{ - - QHBoxLayout* layout = new QHBoxLayout(); - - mInclude = new QLineEdit(); - mExclude = new QLineEdit(); - mSyntax = new QComboBox(); - mMode = new QComboBox(); - mMatchCase = new QCheckBox("case"); - mTest = new QToolButton(); - mIncludeLabel = new QLabel("inc"); - mExcludeLabel = new QLabel("exc"); - - mTest->setText("test"); - - { - QStringList items; - items << "regexp" << "wildcard" << "text"; - mSyntax->setModel(new QStringListModel(items,mSyntax)); - } - { - QStringList items; - items << "include" << "exclude" << "inc. and exc."; - mMode->setModel(new QStringListModel(items,mSyntax)); - } - - layout->addWidget(mIncludeLabel); - layout->addWidget(mInclude); - layout->addWidget(mExcludeLabel); - layout->addWidget(mExclude); - layout->addWidget(mSyntax); - layout->addWidget(mMode); - layout->addWidget(mMatchCase); - //layout->addWidget(mTest); - - setLayout(layout); - - layout->setMargin(0); - - connect(mInclude,SIGNAL(returnPressed()),this,SLOT(onReturnPressed())); - connect(mExclude,SIGNAL(returnPressed()),this,SLOT(onReturnPressed())); - connect(mTest,SIGNAL(clicked()),this,SLOT(onButtonClicked())); - connect(mMode,SIGNAL(currentIndexChanged(int)),this,SLOT(onIncludeChanged(int))); - onIncludeChanged(mMode->currentIndex()); -} - -QString RegExpWidget::include() const -{ - return mInclude->text(); -} - -QString RegExpWidget::exclude() const -{ - return mExclude->text(); -} - -int RegExpWidget::syntax() const -{ - return mSyntax->currentIndex(); -} - -int RegExpWidget::mode() const -{ - return mMode->currentIndex(); -} - -bool RegExpWidget::matchCase() const -{ - return mMatchCase->isChecked(); -} - -void RegExpWidget::setInclude(const QString value) -{ - mInclude->setText(value); -} - -void RegExpWidget::setExclude(const QString &value) -{ - mExclude->setText(value); -} - -void RegExpWidget::setSyntax(int value) -{ - mSyntax->setCurrentIndex(value); -} - -void RegExpWidget::setMode(int value) -{ - mMode->setCurrentIndex(value); -} - -void RegExpWidget::setMatchCase(bool value) -{ - mMatchCase->setChecked(value); -} - -QVariant RegExpWidget::serialize() const -{ - QVariantMap r; - r["include"] = include(); - r["exclude"] = exclude(); - r["syntax"] = syntax(); - r["mode"] = mode(); - r["matchCase"] = matchCase(); - return r; -} - -void RegExpWidget::deserialize(const QVariant &value) -{ - QVariantMap r = value.toMap(); - setInclude(r["include"].toString()); - setExclude(r["exclude"].toString()); - setSyntax(r["syntax"].toInt()); - setMode(r["mode"].toInt()); - setMatchCase(r["matchCase"].toBool()); -} - -void RegExpWidget::onIncludeChanged(int index) { - Q_UNUSED(index); -#if 0 - mIncludeLabel->setVisible(index == RegExp::IncludeAndExclude); - mExcludeLabel->setVisible(index == RegExp::IncludeAndExclude); - - mInclude->setVisible(index == RegExp::Include || index == RegExp::IncludeAndExclude); - mExclude->setVisible(index == RegExp::Exclude || index == RegExp::IncludeAndExclude); -#endif -} - -void RegExpWidget::onButtonClicked() -{ - emit buttonClicked(mInclude->text(), mExclude->text(), mSyntax->currentIndex(), mMode->currentIndex(), mMatchCase->isChecked()); -} - -void RegExpWidget::onReturnPressed() -{ - emit returnPressed(mInclude->text(), mExclude->text(), mSyntax->currentIndex(), mMode->currentIndex(), mMatchCase->isChecked()); -} diff --git a/widget/regexpwidget.h b/widget/regexpwidget.h deleted file mode 100644 index 6bbbc88..0000000 --- a/widget/regexpwidget.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef REGEXPWIDGET_H -#define REGEXPWIDGET_H - -#include - -class QLineEdit; -class QComboBox; -class QCheckBox; -class QPushButton; -class QToolButton; -class QLabel; - -class RegExpWidget : public QWidget -{ - Q_OBJECT -public: - explicit RegExpWidget(QWidget *parent = 0); - - /** @todo setters */ - QString include() const; - QString exclude() const; - int syntax() const; - int mode() const; - bool matchCase() const; - - void setInclude(const QString value); - void setExclude(const QString& value); - void setSyntax(int value); - void setMode(int value); - void setMatchCase(bool value); - - QVariant serialize() const; - void deserialize(const QVariant& value); - -protected: - QLineEdit* mInclude; - QLineEdit* mExclude; - QLabel* mIncludeLabel; - QLabel* mExcludeLabel; - QComboBox* mSyntax; - QComboBox* mMode; - QCheckBox* mMatchCase; - //QPushButton* mPushButton; - QToolButton* mTest; - -signals: - void returnPressed(QString, QString, int, int, bool); - void buttonClicked(QString, QString, int, int, bool); - -protected slots: - void onButtonClicked(); - void onReturnPressed(); - void onIncludeChanged(int index); -}; - -#endif // REGEXPWIDGET_H diff --git a/widget/rxbaseinput.cpp b/widget/rxbaseinput.cpp deleted file mode 100644 index e1e0f60..0000000 --- a/widget/rxbaseinput.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "widget/rxbaseinput.h" -#include - -RXBaseInput::RXBaseInput() -{ -} - -QStringList RXBaseInput::exps() const -{ - QStringList res; - QComboBox* input; - foreach(input,mInputs) { - res << input->currentText(); - } - return res; -} - -void RXBaseInput::setExps(const QStringList &exps) -{ - for(int i=0;ilineEdit()->setText(exps.value(i)); - } -} - -QComboBox *RXBaseInput::input(int index) -{ - return mInputs[index]; -} - -int RXBaseInput::count() const -{ - return mInputs.size(); -}