- feature: file properties dialog

- fix: included file's using namespace list not correctly handled
This commit is contained in:
royqh1979@gmail.com 2021-09-04 00:13:42 +08:00
parent 156913a3ca
commit cda37802ae
10 changed files with 536 additions and 12 deletions

View File

@ -2516,7 +2516,7 @@ void Editor::reformat()
selectAll(); selectAll();
setSelText(QString::fromUtf8(newContent)); setSelText(QString::fromUtf8(newContent));
reparse(); reparse();
pMainWindow->updateEditorActions();
} }
void Editor::checkSyntaxInBack() void Editor::checkSyntaxInBack()

View File

@ -8,6 +8,7 @@
#include "qsynedit/Constants.h" #include "qsynedit/Constants.h"
#include "debugger.h" #include "debugger.h"
#include "widgets/cpudialog.h" #include "widgets/cpudialog.h"
#include "widgets/filepropertiesdialog.h"
#include <QCloseEvent> #include <QCloseEvent>
@ -1207,8 +1208,8 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
menu.addAction(ui->actionAdd_Watch); menu.addAction(ui->actionAdd_Watch);
menu.addAction(ui->actionToggle_Breakpoint); menu.addAction(ui->actionToggle_Breakpoint);
menu.addAction(ui->actionClear_all_breakpoints); menu.addAction(ui->actionClear_all_breakpoints);
menu.addSeparator();
menu.addAction(ui->actionFile_Properties);
//these actions needs parser //these actions needs parser
ui->actionGoto_Declaration->setEnabled(!editor->parser()->parsing()); 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);
}

View File

@ -281,6 +281,8 @@ private slots:
void on_actionOpen_Terminal_triggered(); void on_actionOpen_Terminal_triggered();
void on_actionFile_Properties_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -1575,6 +1575,11 @@
<string>Open a terminal here</string> <string>Open a terminal here</string>
</property> </property>
</action> </action>
<action name="actionFile_Properties">
<property name="text">
<string>File Properties...</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -526,15 +526,26 @@ QSet<QString> CppParser::getFileIncludes(const QString &filename)
QSet<QString> CppParser::getFileUsings(const QString &filename) QSet<QString> CppParser::getFileUsings(const QString &filename)
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
QSet<QString> result;
if (filename.isEmpty()) if (filename.isEmpty())
return QSet<QString>(); return result;
if (mParsing) if (mParsing)
return QSet<QString>(); return result;
PFileIncludes fileIncludes= mPreprocessor.includesList().value(filename,PFileIncludes()); PFileIncludes fileIncludes= mPreprocessor.includesList().value(filename,PFileIncludes());
if (fileIncludes) { 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<QString>(); return result;
} }
QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &line) QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &line)

View File

@ -3244,6 +3244,31 @@ void SynEdit::onScrolled(int)
invalidate(); 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 const QColor &SynEdit::selectedBackground() const
{ {
return mSelectedBackground; return mSelectedBackground;

View File

@ -342,6 +342,12 @@ public:
const QColor &selectedBackground() const; const QColor &selectedBackground() const;
void setSelectedBackground(const QColor &newSelectedBackground); void setSelectedBackground(const QColor &newSelectedBackground);
int rightEdge() const;
void setRightEdge(int newRightEdge);
const QColor &rightEdgeColor() const;
void setRightEdgeColor(const QColor &newRightEdgeColor);
signals: signals:
void linesDeleted(int FirstLine, int Count); void linesDeleted(int FirstLine, int Count);
void linesInserted(int FirstLine, int Count); void linesInserted(int FirstLine, int Count);

View File

@ -1,14 +1,145 @@
#include "filepropertiesdialog.h" #include "filepropertiesdialog.h"
#include "ui_filepropertiesdialog.h" #include "ui_filepropertiesdialog.h"
#include "../mainwindow.h"
#include "../editorlist.h"
#include "../editor.h"
#include "../qsynedit/Constants.h"
#include <QFileInfo>
FilePropertiesDialog::FilePropertiesDialog(QWidget *parent) : FilePropertiesDialog::FilePropertiesDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::FilePropertiesDialog) ui(new Ui::FilePropertiesDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cbFiles->setModel(&mModel);
} }
FilePropertiesDialog::~FilePropertiesDialog() FilePropertiesDialog::~FilePropertiesDialog()
{ {
delete ui; 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;i<editor->lines()->count();i++) {
QString line = editor->lines()->getString(i);
int j=0;
while (j<line.length() && (line[j]=='\t' || line[i]==' '))
j++;
QString token;
PSynHighlighterAttribute attr;
if (editor->GetHighlighterAttriAtRowCol(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;i<pMainWindow->editorList()->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();
}

View File

@ -1,12 +1,24 @@
#ifndef FILEPROPERTIESDIALOG_H #ifndef FILEPROPERTIESDIALOG_H
#define FILEPROPERTIESDIALOG_H #define FILEPROPERTIESDIALOG_H
#include <QAbstractListModel>
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui {
class FilePropertiesDialog; 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 class FilePropertiesDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -14,9 +26,24 @@ class FilePropertiesDialog : public QDialog
public: public:
explicit FilePropertiesDialog(QWidget *parent = nullptr); explicit FilePropertiesDialog(QWidget *parent = nullptr);
~FilePropertiesDialog(); ~FilePropertiesDialog();
private:
void calcFile(Editor* editor,
int& totalLines,
int &commentLines,
int &emptyLines,
int &codeLines,
int &includeLines);
private:
FilePropertiesModel mModel;
private: private:
Ui::FilePropertiesDialog *ui; 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 #endif // FILEPROPERTIESDIALOG_H

View File

@ -1,17 +1,325 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>FilePropertiesDialog</class> <class>FilePropertiesDialog</class>
<widget name="FilePropertiesDialog" class="QDialog"> <widget class="QDialog" name="FilePropertiesDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>726</width>
<height>300</height> <height>444</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>File Properties</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbFiles">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtProject">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Path:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Project:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtPath">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Relative to Project:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="txtRelativeToProject">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QFrame" name="frame_4">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Comment lines:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtCommentLines">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="1">
<widget class="QFrame" name="frame_5">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Code lines:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtCodeLines">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Total lines:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtLines">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QFrame" name="frame_7">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Including files:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtIncludes">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QFrame" name="frame_3">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Empty lines:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtEmptyLines">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QFrame" name="frame_6">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>File size:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtFileSize">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QFrame" name="frame_8">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>File date:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtFileDate">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnOK">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>