+++ /dev/null
-#-------------------------------------------------
-#
-# Project created by QtCreator 2015-06-03T20:56:48
-#
-#-------------------------------------------------
-
-QT += core gui
-
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-
-TARGET = ReEditor
-TEMPLATE = app
-
-INCLUDEPATH += ../..
-
-SOURCES += main.cpp\
- ../../gui/ReEdit.cpp \
- ../../base/ReFile.cpp \
- mainwindow.cpp
-
-
-HEADERS += mainwindow.hpp \
- ../../gui/ReEdit \
- ../../gui/ReEdit.hpp \
- ../../base/rebase.hpp \
- ../../gui/regui.hpp
-
-FORMS += mainwindow.ui
-
-RESOURCES += \
- editor.qrc
#include "gui/regui.hpp"
#include "../reditor/mainwindow.hpp"
#include "ui_mainwindow.h"
+#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow){
edit->setLines(m_file);
edit->setCursorLine(0);
edit->paragraphs().load(0, 5, edit);
+ connect(ui->actionOpen, SIGNAL(triggered()), this,
+ SLOT(openFile()));
}
MainWindow::~MainWindow(){
delete ui;
}
+
+/**
+ * Calls the file selection dialog.
+ */
+void MainWindow::openFile(){
+ QString name = m_file == NULL ? "" : m_file->filename();
+ name = QFileDialog::getOpenFileName(this, tr("Select File"),
+ name);
+ if (!name.isEmpty()){
+ delete m_file;
+ m_file = new ReFile(name, false);
+ ui->widget->setLines(m_file);
+ }
+
+}
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
+protected slots:
+ void openFile();
private:
Ui::MainWindow *ui;
ReFile* m_file;
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2015-06-03T20:56:48
+#
+#-------------------------------------------------
+
+QT += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = ReEditor
+TEMPLATE = app
+
+INCLUDEPATH += ../..
+
+SOURCES += main.cpp\
+ ../../gui/ReEdit.cpp \
+ ../../base/ReFile.cpp \
+ mainwindow.cpp
+
+
+HEADERS += mainwindow.hpp \
+ ../../gui/ReEdit \
+ ../../gui/ReEdit.hpp \
+ ../../base/rebase.hpp \
+ ../../gui/regui.hpp
+
+FORMS += mainwindow.ui
+
+RESOURCES += \
+ editor.qrc
#include "base/rebase.hpp"
+#if defined __linux__ || defined WIN32
+void* memichr(void* heap, int cc, size_t length){
+ const char* heap2 = reinterpret_cast<const char*>(heap);
+ int cc2 = tolower(cc);
+ void* rc = NULL;
+ while(length > 0){
+ if (cc2 == tolower(*heap2++)){
+ rc = (void*)(heap2 - 1);
+ break;
+ }
+ }
+ return rc;
+}
+
+int memicmp(const void* str1, const void* str2, size_t length){
+ const char* str12 = reinterpret_cast<const char*>(str1);
+ const char* str22 = reinterpret_cast<const char*>(str2);
+ int rc = 0;
+ for (size_t ix = 0; ix < length; ix++){
+ int diff = tolower(*str12++) - tolower(*str22++);
+ if (diff != 0){
+ rc = diff;
+ break;
+ }
+ }
+ return rc;
+}
+#endif /* __linux__ */
+
/**
* Constructor.
*/
clear();
m_file.close();
}
-#if defined __linux__ || defined WIN32
-void* memichr(void* heap, int cc, size_t length){
- const char* heap2 = reinterpret_cast<const char*>(heap);
- int cc2 = tolower(cc);
- void* rc = NULL;
- while(length > 0){
- if (cc2 == tolower(*heap2++)){
- rc = (void*)(heap2 - 1);
- break;
- }
- }
- return rc;
-}
-int memicmp(const void* str1, const void* str2, size_t length){
- const char* str12 = reinterpret_cast<const char*>(str1);
- const char* str22 = reinterpret_cast<const char*>(str2);
- int rc = 0;
- for (size_t ix = 0; ix < length; ix++){
- int diff = tolower(*str12++) - tolower(*str22++);
- if (diff != 0){
- rc = diff;
- break;
- }
- }
- return rc;
+/**
+ * Returns the current filename.
+ *
+ * @return the filename (with path)
+ */
+QString ReFile::filename() const
+{
+ return m_filename;
}
-#endif /* __linux__ */
-
/**
* Finds the next line with the string.
*
}
return rc;
}
+
+int ReFile::hasMoreLines(int index){
+ bool rc = false;
+#if 0
+ if (m_countLines >= 0){
+ rc = index < m_countLines - 1;
+ } else{
+ seek(m_lastLineNo);
+ while (index > m_lastLineNo + 1){
+ if (! nextLine()){
+ break;
+ }
+ }
+ rc = index < m_lastLineNo;
+ }
+#endif
+ return rc;
+}
+
/**
* @brief Gets the line behind the current line.
*
m_startOfLine = NULL;
}
-int ReFile::hasMoreLines(int index){
- bool rc = false;
-#if 0
- if (m_countLines >= 0){
- rc = index < m_countLines - 1;
- } else{
- seek(m_lastLineNo);
- while (index > m_lastLineNo + 1){
- if (! nextLine()){
- break;
- }
- }
- rc = index < m_lastLineNo;
- }
-#endif
- return rc;
-}
-
/**
* Sets the internal blocksize.
*
m_maxLineLength = blocksize / 2;
}
+/**
+ * Sets the current filename.
+ *
+ * @param filename the new filename
+ */
+void ReFile::setFilename(const QString &filename)
+{
+ m_filename = filename;
+}
+
/**
* @brief Returns the name of a directory in the temp dir.
*
}
}
+
public:
int64_t blocksize() const;
void close();
- bool findLine(const char* toFind, bool ignoreCase, int& lineNo,
- QString* line);
- bool findLine(const QString& includePattern, bool includeIsRegExpr,
+ /**
+ * Returns the current line number.
+ * @return the current line number
+ */
+ inline uint32_t currentLineNo() const{
+ return m_currentLineNo;
+ }
+ /** Returns the end of line separator.
+ * @return the end of line separator. Default: windows: "\r\n" linux: "\n"
+ */
+ const QByteArray& endOfLine() const{
+ return m_endOfLine;
+ }
+ QString filename() const;
+ bool findLine(const char* toFind, bool ignoreCase, int& lineNo,
+ QString* line);
+ bool findLine(const QString& includePattern, bool includeIsRegExpr,
bool includeIgnoreCase, const QString& excludePattern,
bool excludeIsRegExpr, bool excludeIgnoreCase, int& lineNo,
QString* line);
virtual int hasMoreLines(int index);
- /**
- * Returns the current line number.
- * @return the current line number
- */
- inline uint32_t currentLineNo() const{
- return m_currentLineNo;
- }
char* nextLine(int& length);
char* previousLine(int& length);
bool read(const QString& filename = "");
char* remap(int64_t offset, int size, int& length);
void rewind();
void setBlocksize(const int64_t& blocksize);
- bool write(const QString& filename = "");
+ /**Sets the end of line separator.
+ * @param endOfLine the end of line separator, usually "\n" or "\r\n"
+ */
+ void setEndOfLine(const char* endOfLine){
+ m_endOfLine = endOfLine;
+ }
+ void setFilename(const QString &filename);
+ bool write(const QString& filename = "");
public:
static QByteArray tempDir(const char* node, const char* parent = NULL,
static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
static void writeToFile(const char* filename, const char* content,
size_t contentLength = (size_t) - 1, const char* mode = "w");
- /** Returns the end of line separator.
- * @return the end of line separator. Default: windows: "\r\n" linux: "\n"
- */
- const QByteArray& endOfLine() const{
- return m_endOfLine;
- }
- /**Sets the end of line separator.
- * @param endOfLine the end of line separator, usually "\n" or "\r\n"
- */
- void setEndOfLine(const char* endOfLine){
- m_endOfLine = endOfLine;
- }
private:
- QByteArray m_endOfLine;
- QString m_filename;
- QFile m_file;
+ QByteArray m_endOfLine;
+ QString m_filename;
+ QFile m_file;
char* m_block;
int64_t m_blocksize;
int64_t m_blockOffset;