work save

This commit is contained in:
royqh1979 2021-09-11 11:42:20 +08:00
parent 668e42458e
commit 527fc3b634
7 changed files with 243 additions and 38 deletions

View File

@ -9,6 +9,7 @@
#include "debugger.h" #include "debugger.h"
#include "widgets/cpudialog.h" #include "widgets/cpudialog.h"
#include "widgets/filepropertiesdialog.h" #include "widgets/filepropertiesdialog.h"
#include "project.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QComboBox> #include <QComboBox>
@ -60,6 +61,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->EditorTabsRight, ui->EditorTabsRight,
ui->splitterEditorPanel, ui->splitterEditorPanel,
ui->EditorPanel); ui->EditorPanel);
mProject = nullptr;
setAcceptDrops(true); setAcceptDrops(true);
setupActions(); setupActions();
ui->EditorTabsRight->setVisible(false); ui->EditorTabsRight->setVisible(false);
@ -366,54 +368,96 @@ void MainWindow::updateAppTitle()
{ {
QString appName("Red Panda Dev-C++"); QString appName("Red Panda Dev-C++");
Editor *e = mEditorList->getEditor(); Editor *e = mEditorList->getEditor();
QString str;
QCoreApplication *app = QApplication::instance(); QCoreApplication *app = QApplication::instance();
if (e && !e->inProject()) { if (e && !e->inProject()) {
QString str;
if (e->modified()) if (e->modified())
str = e->filename() + " [*]"; str = e->filename() + " [*]";
else else
str = e->filename(); str = e->filename();
if (mDebugger->executing()) { if (mDebugger->executing()) {
setWindowTitle(QString("%1 - [%2] - %3 %4") setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(str,appName,tr("Debugging"),DEVCPP_VERSION)); .arg(str,tr("Debugging"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3") app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,appName,tr("Debugging"))); .arg(str,tr("Debugging"),appName));
} else if (mCompilerManager->running()) { } else if (mCompilerManager->running()) {
setWindowTitle(QString("%1 - [%2] - %3 %4") setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(str,appName,tr("Running"),DEVCPP_VERSION)); .arg(str,tr("Running"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3") app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,appName,tr("Running"))); .arg(str,tr("Running"),appName));
} else if (mCompilerManager->compiling()) { } else if (mCompilerManager->compiling()) {
setWindowTitle(QString("%1 - [%2] - %3 %4") setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(str,appName,tr("Compiling"),DEVCPP_VERSION)); .arg(str,tr("Compiling"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3") app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,appName,tr("Compiling"))); .arg(str,tr("Compiling"),appName));
} else { } else {
this->setWindowTitle(QString("%1 - %2 %3") this->setWindowTitle(QString("%1 - %2 %3")
.arg(str,appName,DEVCPP_VERSION)); .arg(str,appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2") app->setApplicationName(QString("%1 - %2")
.arg(str,appName)); .arg(str,appName));
} }
} else if (e && e->inProject() && mProject) {
QString str,str2;
if (mProject->modified())
str = mProject->name() + " [*]";
else
str = mProject->name();
if (e->modified())
str2 = extractFileName(e->filename()) + " [*]";
else
str2 = extractFileName(e->filename());
if (mDebugger->executing()) {
setWindowTitle(QString("%1 - %2 [%3] - %4 %5")
.arg(str,str2,
tr("Debugging"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Debugging"),appName));
} else if (mCompilerManager->running()) {
setWindowTitle(QString("%1 - %2 [%3] - %4 %5")
.arg(str,str2,
tr("Running"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Running"),appName));
} else if (mCompilerManager->compiling()) {
setWindowTitle(QString("%1 - %2 [%3] - %4 %5")
.arg(str,str2,
tr("Compiling"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Compiling"),appName));
} else {
setWindowTitle(QString("%1 - %2 %3")
.arg(str,appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2")
.arg(str,appName));
} }
// else if Assigned(fProject) then begin } else if (mProject) {
// if fDebugger.Executing then begin QString str,str2;
// Caption := Format('%s - [%s] - [Debugging] - %s %s', if (mProject->modified())
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); str = mProject->name() + " [*]";
// Application.Title := Format('%s - [Debugging] - %s', [fProject.Name, appName]); else
// end else if devExecutor.Running then begin str = mProject->name();
// Caption := Format('%s - [%s] - [Executing] - %s %s', if (mDebugger->executing()) {
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); setWindowTitle(QString("%1 - [%2] - %3 %4")
// Application.Title := Format('%s - [Executing] - %s', [fProject.Name, appName]); .arg(str,tr("Debugging"),appName,DEVCPP_VERSION));
// end else if fCompiler.Compiling then begin app->setApplicationName(QString("%1 - [%2] - %3")
// Caption := Format('%s - [%s] - [Compiling] - %s %s', .arg(str,tr("Debugging"),appName));
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); } else if (mCompilerManager->running()) {
// Application.Title := Format('%s - [Compiling] - %s', [fProject.Name, appName]); setWindowTitle(QString("%1 - [%2] - %3 %4")
// end else begin .arg(str,tr("Running"),appName,DEVCPP_VERSION));
// Caption := Format('%s - [%s] - %s %s', app->setApplicationName(QString("%1 - [%2] - %3")
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]); .arg(str,tr("Running"),appName));
// Application.Title := Format('%s - %s', [fProject.Name, appName]); } else if (mCompilerManager->compiling()) {
// end; setWindowTitle(QString("%1 - [%2] - %3 %4")
else { .arg(str,tr("Compiling"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Compiling"),appName));
} else {
this->setWindowTitle(QString("%1 - %2 %3")
.arg(str,appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2")
.arg(str,appName));
}
} else {
setWindowTitle(QString("%1 %2").arg(appName,DEVCPP_VERSION)); setWindowTitle(QString("%1 %2").arg(appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1").arg(appName)); app->setApplicationName(QString("%1").arg(appName));
} }
@ -576,6 +620,7 @@ void MainWindow::openFile(const QString &filename)
return; return;
} }
try { try {
pSettings->history().removeFile(filename);
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
false,false); false,false);
editor->activate(); editor->activate();
@ -585,6 +630,81 @@ void MainWindow::openFile(const QString &filename)
} }
} }
void MainWindow::openProject(const QString &filename)
{
if (!fileExists(filename)) {
return;
}
if (mProject) {
QString s;
if (mProject->name().isEmpty())
s = mProject->filename();
else
s = mProject->name();
if (QMessageBox::question(this,
tr("Close project"),
tr("Are you sure you want to close %1?")
.arg(s),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes) == QMessageBox::Yes) {
closeProject(false);
} else {
return;
}
}
ui->tabProject->setVisible(true);
ui->tabInfos->setCurrentWidget(ui->tabProject);
openCloseLeftPanel(true);
// {
// LeftPageControl.ActivePage := LeftProjectSheet;
// fLeftPageControlChanged := False;
// ClassBrowser.TabVisible:= False;
// }
// Only update class browser once
mClassBrowserModel.beginUpdate();
{
auto action = finally([this]{
mClassBrowserModel.endUpdate();
});
mProject = new Project(filename,DEV_INTERNAL_OPEN);
pSettings->history().removeFile(filename);
// // if project manager isn't open then open it
// if not devData.ShowLeftPages then
// actProjectManager.Execute;
checkForDllProfiling();
updateAppTitle();
updateCompilerSet();
//parse the project
// UpdateClassBrowsing;
scanActiveProject(true);
mProject->doAutoOpen();
//update editor's inproject flag
for (int i=0;i<mProject->units().count();i++) {
PProjectUnit unit = mProject->units()[i];
Editor* e = mEditorList->getOpenedEditorByFilename(unit->filename());
if (e) {
unit->setEditor(e);
unit->setEncoding(e->encodingOption());
e->setInProject(true);
} else {
unit->setEditor(nullptr);
e->setInProject(false);
}
}
Editor * e = mEditorList->getEditor();
if (e) {
checkSyntaxInBack(e);
}
updateClassBrowserForEditor(e);
}
updateForEncodingInfo();
}
void MainWindow::setupActions() { void MainWindow::setupActions() {
} }
@ -592,12 +712,18 @@ void MainWindow::setupActions() {
void MainWindow::updateCompilerSet() void MainWindow::updateCompilerSet()
{ {
mCompilerSet->clear(); mCompilerSet->clear();
int index=pSettings->compilerSets().defaultIndex();
for (size_t i=0;i<pSettings->compilerSets().list().size();i++) { for (size_t i=0;i<pSettings->compilerSets().list().size();i++) {
mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name());
} }
int index=pSettings->compilerSets().defaultIndex();
if (mProject) {
Editor *e = mEditorList->getEditor();
if ( !e || e->inProject()) {
index = mProject->options().compilerSet;
}
}
if (index < 0 || index>=mCompilerSet->count()) { if (index < 0 || index>=mCompilerSet->count()) {
index = 0; index = pSettings->compilerSets().defaultIndex();
} }
mCompilerSet->setCurrentIndex(index); mCompilerSet->setCurrentIndex(index);
} }
@ -614,6 +740,9 @@ void MainWindow::checkSyntaxInBack(Editor *e)
if (e==nullptr) if (e==nullptr)
return; return;
if (!pSettings->editor().syntaxCheck()) {
return;
}
// if not devEditor.AutoCheckSyntax then // if not devEditor.AutoCheckSyntax then
// Exit; // Exit;
//not c or cpp file //not c or cpp file

View File

@ -29,6 +29,7 @@ class Debugger;
class CPUDialog; class CPUDialog;
class QPlainTextEdit; class QPlainTextEdit;
class SearchDialog; class SearchDialog;
class Project;
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
@ -124,6 +125,7 @@ public slots:
private: private:
void openFiles(const QStringList& files); void openFiles(const QStringList& files);
void openFile(const QString& filename); void openFile(const QString& filename);
void openProject(const QString& filename);
CompileTarget getCompileTarget(); CompileTarget getCompileTarget();
bool debugInferiorhasBreakpoint(); bool debugInferiorhasBreakpoint();
void setupActions(); void setupActions();
@ -315,6 +317,7 @@ private:
bool mQuitting; bool mQuitting;
QElapsedTimer mParserTimer; QElapsedTimer mParserTimer;
QFileSystemWatcher mFileSystemWatcher; QFileSystemWatcher mFileSystemWatcher;
Project* mProject;
std::shared_ptr<CodeCompletionPopup> mCompletionPopup; std::shared_ptr<CodeCompletionPopup> mCompletionPopup;
std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup; std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup;

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum> <enum>QTabWidget::West</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<property name="usesScrollButtons"> <property name="usesScrollButtons">
<bool>true</bool> <bool>true</bool>
@ -94,6 +94,23 @@
<attribute name="title"> <attribute name="title">
<string>Project</string> <string>Project</string>
</attribute> </attribute>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="projectView"/>
</item>
</layout>
</widget> </widget>
<widget class="QWidget" name="tabWatch"> <widget class="QWidget" name="tabWatch">
<attribute name="title"> <attribute name="title">
@ -772,7 +789,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>946</width> <width>946</width>
<height>25</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">

View File

@ -466,9 +466,9 @@ bool Project::saveUnits()
for (int idx = 0; idx < mUnits.count(); idx++) { for (int idx = 0; idx < mUnits.count(); idx++) {
PProjectUnit unit = mUnits[idx]; PProjectUnit unit = mUnits[idx];
bool rd_only = false; bool rd_only = false;
mIniFile->beginGroup(QString("Unit%1").arg(count+1); mIniFile->beginGroup(QString("Unit%1").arg(count+1));
if (unit->modified() && fileExists(unit->fileName()) if (unit->modified() && fileExists(unit->fileName())
&& isReadonly(unit->fileName)) { && isReadOnly(unit->fileName())) {
// file is read-only // file is read-only
QMessageBox::critical(pMainWindow, QMessageBox::critical(pMainWindow,
tr("Can't save file"), tr("Can't save file"),
@ -1376,6 +1376,11 @@ void Project::updateFolderNode(PFolderNode node)
} }
} }
const QList<PProjectUnit> &Project::units() const
{
return mUnits;
}
const ProjectOptions &Project::options() const const ProjectOptions &Project::options() const
{ {
return mOptions; return mOptions;
@ -1386,6 +1391,11 @@ void Project::setOptions(const ProjectOptions &newOptions)
mOptions = newOptions; mOptions = newOptions;
} }
const ProjectModel *Project::model() const
{
return &mModel;
}
const PFolderNode &Project::node() const const PFolderNode &Project::node() const
{ {
return mNode; return mNode;
@ -1621,6 +1631,39 @@ void ProjectModel::endUpdate()
endResetModel(); endResetModel();
} }
QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) const
{
if (!parent.isValid()) {
return createIndex(row,column,mProject->node().get());
}
FolderNode* parentNode = static_cast<FolderNode*>(parent.internalPointer());
if (!parentNode) {
return QModelIndex();
}
return createIndex(row,column,parentNode->children[row].get());
}
QModelIndex ProjectModel::parent(const QModelIndex &child) const
{
if (!child.isValid())
return QModelIndex();
FolderNode * node = static_cast<FolderNode*>(child.internalPointer());
if (!node)
return QModelIndex();
PFolderNode parent = node->parent.lock();
if (!parent) // root node
return QModelIndex();
PFolderNode grand = parent->parent.lock();
if (!grand) {
return createIndex(0,0,parent.get());
}
int row = grand->children.indexOf(parent);
if (row<0)
return QModelIndex();
return createIndex(row,0,parent.get());
}
int ProjectModel::rowCount(const QModelIndex &parent) const int ProjectModel::rowCount(const QModelIndex &parent) const
{ {
if (!parent.isValid()) if (!parent.isValid())
@ -1645,10 +1688,8 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
FolderNode* p = static_cast<FolderNode*>(index.internalPointer()); FolderNode* p = static_cast<FolderNode*>(index.internalPointer());
if (!p) if (!p)
return QVariant(); return QVariant();
if (role == Qt::DisplayRole) {
return p->children.count(); return p->text;
} else {
return mProject->node()->children.count();
} }
return QVariant();
} }

View File

@ -225,6 +225,10 @@ public:
const ProjectOptions &options() const; const ProjectOptions &options() const;
void setOptions(const ProjectOptions &newOptions); void setOptions(const ProjectOptions &newOptions);
const ProjectModel* model() const;
const QList<PProjectUnit> &units() const;
signals: signals:
void nodesChanged(); void nodesChanged();
void modifyChanged(bool value); void modifyChanged(bool value);

View File

@ -2658,6 +2658,16 @@ bool Settings::History::addToOpenedFiles(const QString &filename)
} }
void Settings::History::removeFile(const QString &filename)
{
int index = mOpenedFiles.indexOf(filename);
if (index>=0) {
mOpenedFiles.removeAt(index);
}
save();
return;
}
void Settings::History::doSave() void Settings::History::doSave()
{ {
saveValue("opened_files", mOpenedFiles); saveValue("opened_files", mOpenedFiles);

View File

@ -680,6 +680,7 @@ public:
const QStringList& openedFiles() const; const QStringList& openedFiles() const;
const QStringList& openedProjects() const; const QStringList& openedProjects() const;
bool addToOpenedFiles(const QString& filename); bool addToOpenedFiles(const QString& filename);
void removeFile(const QString& filename);
private: private:
QStringList mOpenedFiles; QStringList mOpenedFiles;
QStringList mOpenedProjects; QStringList mOpenedProjects;