diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index d6c3ac8c..e6b7a595 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -2516,7 +2516,7 @@ void Editor::reformat() selectAll(); setSelText(QString::fromUtf8(newContent)); reparse(); - + pMainWindow->updateEditorActions(); } void Editor::checkSyntaxInBack() diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 6fef59ee..b3f3f7db 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -8,6 +8,7 @@ #include "qsynedit/Constants.h" #include "debugger.h" #include "widgets/cpudialog.h" +#include "widgets/filepropertiesdialog.h" #include @@ -1207,8 +1208,8 @@ void MainWindow::onEditorContextMenu(const QPoint &pos) menu.addAction(ui->actionAdd_Watch); menu.addAction(ui->actionToggle_Breakpoint); menu.addAction(ui->actionClear_all_breakpoints); - - + menu.addSeparator(); + menu.addAction(ui->actionFile_Properties); //these actions needs parser ui->actionGoto_Declaration->setEnabled(!editor->parser()->parsing()); @@ -2309,3 +2310,11 @@ void MainWindow::on_actionOpen_Terminal_triggered() } + +void MainWindow::on_actionFile_Properties_triggered() +{ + FilePropertiesDialog dialog(this); + dialog.exec(); + dialog.setParent(nullptr); +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 7661f0af..665a4df0 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -281,6 +281,8 @@ private slots: void on_actionOpen_Terminal_triggered(); + void on_actionFile_Properties_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 10005b9e..48f65cff 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -1575,6 +1575,11 @@ Open a terminal here + + + File Properties... + + diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 0513151a..4d1746c9 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -526,15 +526,26 @@ QSet CppParser::getFileIncludes(const QString &filename) QSet CppParser::getFileUsings(const QString &filename) { QMutexLocker locker(&mMutex); + QSet result; if (filename.isEmpty()) - return QSet(); + return result; if (mParsing) - return QSet(); + return result; PFileIncludes fileIncludes= mPreprocessor.includesList().value(filename,PFileIncludes()); if (fileIncludes) { - return fileIncludes->usings; + foreach (const QString& usingName, fileIncludes->usings) { + result.insert(usingName); + } + foreach (const QString& subFile,fileIncludes->includeFiles.keys()){ + PFileIncludes subIncludes = mPreprocessor.includesList().value(subFile,PFileIncludes()); + if (subIncludes) { + foreach (const QString& usingName, subIncludes->usings) { + result.insert(usingName); + } + } + } } - return QSet(); + return result; } QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &line) diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 8e500bd9..7d2a904c 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -3244,6 +3244,31 @@ void SynEdit::onScrolled(int) invalidate(); } +const QColor &SynEdit::rightEdgeColor() const +{ + return mRightEdgeColor; +} + +void SynEdit::setRightEdgeColor(const QColor &newRightEdgeColor) +{ + if (newRightEdgeColor!=mRightEdgeColor) { + mRightEdgeColor = newRightEdgeColor; + } +} + +int SynEdit::rightEdge() const +{ + return mRightEdge; +} + +void SynEdit::setRightEdge(int newRightEdge) +{ + if (mRightEdge != newRightEdge) { + mRightEdge = newRightEdge; + invalidate(); + } +} + const QColor &SynEdit::selectedBackground() const { return mSelectedBackground; diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index e08689b6..b78c1a69 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -342,6 +342,12 @@ public: const QColor &selectedBackground() const; void setSelectedBackground(const QColor &newSelectedBackground); + int rightEdge() const; + void setRightEdge(int newRightEdge); + + const QColor &rightEdgeColor() const; + void setRightEdgeColor(const QColor &newRightEdgeColor); + signals: void linesDeleted(int FirstLine, int Count); void linesInserted(int FirstLine, int Count); diff --git a/RedPandaIDE/widgets/filepropertiesdialog.cpp b/RedPandaIDE/widgets/filepropertiesdialog.cpp index efa020d9..8a349ca8 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.cpp +++ b/RedPandaIDE/widgets/filepropertiesdialog.cpp @@ -1,14 +1,145 @@ #include "filepropertiesdialog.h" #include "ui_filepropertiesdialog.h" +#include "../mainwindow.h" +#include "../editorlist.h" +#include "../editor.h" +#include "../qsynedit/Constants.h" + +#include FilePropertiesDialog::FilePropertiesDialog(QWidget *parent) : QDialog(parent), ui(new Ui::FilePropertiesDialog) { ui->setupUi(this); + ui->cbFiles->setModel(&mModel); } FilePropertiesDialog::~FilePropertiesDialog() { delete ui; } + +void FilePropertiesDialog::calcFile(Editor *editor, + int &totalLines, + int &commentLines, + int &emptyLines, + int &codeLines, + int &includeLines) +{ + totalLines = editor->lines()->count(); + codeLines = 0; + commentLines = 0; + emptyLines = 0; + includeLines = 0; + // iterate through all lines of file + for (int i=0;ilines()->count();i++) { + QString line = editor->lines()->getString(i); + int j=0; + while (jGetHighlighterAttriAtRowCol(BufferCoord{j+1,i+1}, + token,attr)) { + // if it is preprocessor... + if (attr->name() == SYNS_AttrPreprocessor) { + // check for includes + token.remove(0,1); + token=token.trimmed(); + if (token.startsWith("include")) + includeLines++; + + // preprocessor directives are considered as code + codeLines++; + } else if (attr->name() == SYNS_AttrComment) { + commentLines++; + } else { + codeLines++; + } + } else { + // if we don't get a token type, this line is empty or contains only spaces + emptyLines++; + } + + } +} + +void FilePropertiesDialog::showEvent(QShowEvent *) +{ + Editor* activeEditor = pMainWindow->editorList()->getEditor(); + for (int i=0;ieditorList()->pageCount();i++) { + Editor * editor = (*(pMainWindow->editorList()))[i]; + if (editor == activeEditor) { + ui->cbFiles->setCurrentIndex(i); + break; + } + } +} + +FilePropertiesModel::FilePropertiesModel(QObject *parent):QAbstractListModel(parent) +{ + +} + +int FilePropertiesModel::rowCount(const QModelIndex &) const +{ + return pMainWindow->editorList()->pageCount(); +} + +QVariant FilePropertiesModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + int row = index.row(); + if (role == Qt::DisplayRole) { + if (row>=0 && row < pMainWindow->editorList()->pageCount()) { + Editor *editor = (*(pMainWindow->editorList()))[row]; + if (editor) { + return baseFileName(editor->filename()); + } + } + } + return QVariant(); +} + +void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index) +{ + Editor *editor = (*(pMainWindow->editorList()))[index]; + if (editor) { + QFileInfo info(editor->filename()); + + int fileSize = info.size(); + // Pretty print total file size + if (fileSize < 1024) { + ui->txtFileSize->setText(QString("%1 ").arg(fileSize)+tr("bytes")); + } else if (fileSize < 1024 * 1024) { + ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0)+tr("KB")); + } else if (fileSize < 1024 * 1024 * 1024) { + ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0 / 1024.0)+tr("MB")); + } else { + ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0 / 1024.0 / 1024.0)+tr("GB")); + } + ui->txtFileDate->setText( info.lastModified().toString(Qt::DateFormat::LocaleDate)); + ui->txtProject->setText("-"); + ui->txtPath->setText(editor->filename()); + ui->txtRelativeToProject->setText("_"); + ui->txtLines->setText(QString("%1").arg(editor->lines()->count())); + + int totalLines, codeLines,emptyLines,commentLines,includeLines; + calcFile(editor,totalLines,commentLines,emptyLines,codeLines,includeLines); + + ui->txtLines->setText(QString("%1").arg(totalLines)); + ui->txtEmptyLines->setText(QString("%1").arg(emptyLines)); + ui->txtCodeLines->setText(QString("%1").arg(codeLines)); + ui->txtCommentLines->setText(QString("%1").arg(commentLines)); + ui->txtIncludes->setText(QString("%1").arg(includeLines)); + } +} + + +void FilePropertiesDialog::on_btnOK_clicked() +{ + hide(); +} + diff --git a/RedPandaIDE/widgets/filepropertiesdialog.h b/RedPandaIDE/widgets/filepropertiesdialog.h index ed613c26..d5effca7 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.h +++ b/RedPandaIDE/widgets/filepropertiesdialog.h @@ -1,12 +1,24 @@ #ifndef FILEPROPERTIESDIALOG_H #define FILEPROPERTIESDIALOG_H +#include #include namespace Ui { class FilePropertiesDialog; } +class FilePropertiesModel: public QAbstractListModel { + Q_OBJECT +public: + explicit FilePropertiesModel(QObject* parent=nullptr); + + // QAbstractItemModel interface +public: + int rowCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; +}; +class Editor; class FilePropertiesDialog : public QDialog { Q_OBJECT @@ -14,9 +26,24 @@ class FilePropertiesDialog : public QDialog public: explicit FilePropertiesDialog(QWidget *parent = nullptr); ~FilePropertiesDialog(); - +private: + void calcFile(Editor* editor, + int& totalLines, + int &commentLines, + int &emptyLines, + int &codeLines, + int &includeLines); +private: + FilePropertiesModel mModel; private: Ui::FilePropertiesDialog *ui; + + // QWidget interface +protected: + void showEvent(QShowEvent *event) override; +private slots: + void on_cbFiles_currentIndexChanged(int index); + void on_btnOK_clicked(); }; #endif // FILEPROPERTIESDIALOG_H diff --git a/RedPandaIDE/widgets/filepropertiesdialog.ui b/RedPandaIDE/widgets/filepropertiesdialog.ui index 1a84f4a8..63020b95 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.ui +++ b/RedPandaIDE/widgets/filepropertiesdialog.ui @@ -1,17 +1,325 @@ + FilePropertiesDialog - + 0 0 - 400 - 300 + 726 + 444 - Dialog + File Properties + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + File name: + + + + + + + + 0 + 0 + + + + + + + + true + + + + + + + Path: + + + + + + + Project: + + + + + + + true + + + + + + + Relative to Project: + + + + + + + true + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Comment lines: + + + + + + + true + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Code lines: + + + + + + + true + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Total lines: + + + + + + + true + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Including files: + + + + + + + true + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Empty lines: + + + + + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + File size: + + + + + + + true + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + File date: + + + + + + + true + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + +