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 "widgets/cpudialog.h"
#include "widgets/filepropertiesdialog.h"
#include "project.h"
#include <QCloseEvent>
#include <QComboBox>
@ -60,6 +61,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->EditorTabsRight,
ui->splitterEditorPanel,
ui->EditorPanel);
mProject = nullptr;
setAcceptDrops(true);
setupActions();
ui->EditorTabsRight->setVisible(false);
@ -366,54 +368,96 @@ void MainWindow::updateAppTitle()
{
QString appName("Red Panda Dev-C++");
Editor *e = mEditorList->getEditor();
QString str;
QCoreApplication *app = QApplication::instance();
if (e && !e->inProject()) {
QString str;
if (e->modified())
str = e->filename() + " [*]";
else
str = e->filename();
if (mDebugger->executing()) {
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")
.arg(str,appName,tr("Debugging")));
.arg(str,tr("Debugging"),appName));
} else if (mCompilerManager->running()) {
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")
.arg(str,appName,tr("Running")));
.arg(str,tr("Running"),appName));
} else if (mCompilerManager->compiling()) {
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")
.arg(str,appName,tr("Compiling")));
.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 if Assigned(fProject) then begin
// if fDebugger.Executing then begin
// Caption := Format('%s - [%s] - [Debugging] - %s %s',
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]);
// Application.Title := Format('%s - [Debugging] - %s', [fProject.Name, appName]);
// end else if devExecutor.Running then begin
// Caption := Format('%s - [%s] - [Executing] - %s %s',
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]);
// Application.Title := Format('%s - [Executing] - %s', [fProject.Name, appName]);
// end else if fCompiler.Compiling then begin
// Caption := Format('%s - [%s] - [Compiling] - %s %s',
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]);
// Application.Title := Format('%s - [Compiling] - %s', [fProject.Name, appName]);
// end else begin
// Caption := Format('%s - [%s] - %s %s',
// [fProject.Name, ExtractFilename(fProject.Filename), appName, DEVCPP_VERSION]);
// Application.Title := Format('%s - %s', [fProject.Name, appName]);
// end;
else {
} 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 (mProject) {
QString str,str2;
if (mProject->modified())
str = mProject->name() + " [*]";
else
str = mProject->name();
if (mDebugger->executing()) {
setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(str,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")
.arg(str,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")
.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));
app->setApplicationName(QString("%1").arg(appName));
}
@ -576,6 +620,7 @@ void MainWindow::openFile(const QString &filename)
return;
}
try {
pSettings->history().removeFile(filename);
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
false,false);
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() {
}
@ -592,12 +712,18 @@ void MainWindow::setupActions() {
void MainWindow::updateCompilerSet()
{
mCompilerSet->clear();
int index=pSettings->compilerSets().defaultIndex();
for (size_t i=0;i<pSettings->compilerSets().list().size();i++) {
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()) {
index = 0;
index = pSettings->compilerSets().defaultIndex();
}
mCompilerSet->setCurrentIndex(index);
}
@ -614,6 +740,9 @@ void MainWindow::checkSyntaxInBack(Editor *e)
if (e==nullptr)
return;
if (!pSettings->editor().syntaxCheck()) {
return;
}
// if not devEditor.AutoCheckSyntax then
// Exit;
//not c or cpp file

View File

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

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -94,6 +94,23 @@
<attribute name="title">
<string>Project</string>
</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 class="QWidget" name="tabWatch">
<attribute name="title">
@ -772,7 +789,7 @@
<x>0</x>
<y>0</y>
<width>946</width>
<height>25</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

View File

@ -466,9 +466,9 @@ bool Project::saveUnits()
for (int idx = 0; idx < mUnits.count(); idx++) {
PProjectUnit unit = mUnits[idx];
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())
&& isReadonly(unit->fileName)) {
&& isReadOnly(unit->fileName())) {
// file is read-only
QMessageBox::critical(pMainWindow,
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
{
return mOptions;
@ -1386,6 +1391,11 @@ void Project::setOptions(const ProjectOptions &newOptions)
mOptions = newOptions;
}
const ProjectModel *Project::model() const
{
return &mModel;
}
const PFolderNode &Project::node() const
{
return mNode;
@ -1621,6 +1631,39 @@ void ProjectModel::endUpdate()
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
{
if (!parent.isValid())
@ -1645,10 +1688,8 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
FolderNode* p = static_cast<FolderNode*>(index.internalPointer());
if (!p)
return QVariant();
return p->children.count();
} else {
return mProject->node()->children.count();
if (role == Qt::DisplayRole) {
return p->text;
}
return QVariant();
}

View File

@ -225,6 +225,10 @@ public:
const ProjectOptions &options() const;
void setOptions(const ProjectOptions &newOptions);
const ProjectModel* model() const;
const QList<PProjectUnit> &units() const;
signals:
void nodesChanged();
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()
{
saveValue("opened_files", mOpenedFiles);

View File

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