work save: open project

This commit is contained in:
royqh1979@gmail.com 2021-09-11 18:42:49 +08:00
parent 527fc3b634
commit 85e9b4d697
15 changed files with 255 additions and 98 deletions

View File

@ -28,6 +28,7 @@
#include "debugger.h"
#include "editorlist.h"
#include <QDebug>
#include "project.h"
using namespace std;

View File

@ -142,6 +142,7 @@ public:
void checkSyntaxInBack();
void gotoDeclaration(const BufferCoord& pos);
void gotoDefinition(const BufferCoord& pos);
void reparse();
const PCppParser &parser();
@ -173,7 +174,6 @@ private:
void initParser();
void undoSymbolCompletion(int pos);
QuoteStatus getQuoteStatus();
void reparse();
void showCompletion(bool autoComplete);
void showHeaderCompletion(bool autoComplete);

View File

@ -667,13 +667,14 @@ void MainWindow::openProject(const QString &filename)
auto action = finally([this]{
mClassBrowserModel.endUpdate();
});
mProject = new Project(filename,DEV_INTERNAL_OPEN);
pSettings->history().removeFile(filename);
mProject = std::make_shared<Project>(filename,DEV_INTERNAL_OPEN);
ui->projectView->setModel(mProject->model());
pSettings->history().removeProject(filename);
// // if project manager isn't open then open it
// if not devData.ShowLeftPages then
// actProjectManager.Execute;
checkForDllProfiling();
//checkForDllProfiling();
updateAppTitle();
updateCompilerSet();
@ -685,14 +686,13 @@ void MainWindow::openProject(const QString &filename)
//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());
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);
}
}
@ -1261,6 +1261,21 @@ QAction* MainWindow::createActionFor(
parent->addAction(action);
return action;
}
void MainWindow::scanActiveProject(bool parse)
{
if (!mProject)
return;
//UpdateClassBrowsing;
if (parse) {
resetCppParser(mProject->cppParser());
mProject->resetParserProjectFiles();
parseFileList(mProject->cppParser());
} else {
mProject->resetParserProjectFiles();
};
}
void MainWindow::buildContextMenus()
{
@ -1550,6 +1565,90 @@ void MainWindow::onEditorTabContextMenu(const QPoint &pos)
menu.exec(tabBar->mapToGlobal(pos));
}
void MainWindow::closeProject(bool refreshEditor)
{
// Stop executing program
on_actionStop_Execution_triggered();
// Only update file monitor once (and ignore updates)
bool oldBlock= mFileSystemWatcher.blockSignals(true);
{
auto action = finally([&,this]{
mFileSystemWatcher.blockSignals(oldBlock);
});
// TODO: should we save watches?
if (mProject->modified()) {
QString s;
if (mProject->name().isEmpty()) {
s = mProject->filename();
} else {
s = mProject->name();
}
if (mSystemTurnedOff) {
mProject->saveAll();
} else {
int answer = QMessageBox::question(
this,
tr("Save project"),
tr("The project '%1' has modifications.").arg(s)
+ "<br />"
+ tr("Do you want to save it?"),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
QMessageBox::Yes);
switch (answer) {
case QMessageBox::Yes:
mProject->saveAll();
break;
case QMessageBox::No:
mProject->setModified(false);
mProject->saveLayout();
break;
case QMessageBox::Cancel:
mProject->saveLayout();
return;
}
}
} else
mProject->saveLayout(); // always save layout, but not when SaveAll has been called
mClassBrowserModel.beginUpdate();
{
auto action2 = finally([this]{
mClassBrowserModel.endUpdate();
});
// Remember it
pSettings->history().addToOpenedProjects(mProject->filename());
mEditorList->beginUpdate();
{
auto action3 = finally([this]{
mEditorList->endUpdate();
});
mProject.reset();
if (!mQuitting && refreshEditor) {
//reset Class browsing
ui->tabInfos->setCurrentWidget(ui->tabStructure);
Editor * e = mEditorList->getEditor();
updateClassBrowserForEditor(e);
} else {
mClassBrowserModel.setParser(nullptr);
mClassBrowserModel.setCurrentFile("");
}
}
}
if (!mQuitting) {
// Clear project browser
ui->projectView->setModel(nullptr);
// Clear error browser
ui->tableIssues->clearIssues();
ui->tabProject->setVisible(false);
}
}
}
void MainWindow::onFileChanged(const QString &path)
{
Editor *e = mEditorList->getOpenedEditorByFilename(path);
@ -1637,11 +1736,7 @@ void MainWindow::on_actionOpen_triggered()
{
try {
QString selectedFileFilter;
if (pSettings->editor().defaultFileCpp()){
selectedFileFilter = pSystemConsts->defaultCPPFileFilter();
} else {
selectedFileFilter = pSystemConsts->defaultCFileFilter();
}
selectedFileFilter = pSystemConsts->defaultAllFileFilter();
QStringList files = QFileDialog::getOpenFileNames(pMainWindow,
tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
&selectedFileFilter);
@ -1738,8 +1833,20 @@ void MainWindow::on_actionSaveAs_triggered()
void MainWindow::on_actionOptions_triggered()
{
bool oldCodeCompletion = pSettings->codeCompletion().enabled();
SettingsDialog settingsDialog;
settingsDialog.exec();
bool newCodeCompletion = pSettings->codeCompletion().enabled();
if (!oldCodeCompletion && newCodeCompletion) {
Editor *e = mEditorList->getEditor();
if (mProject && !e) {
scanActiveProject(true);
} else if (mProject && e && e->inProject()) {
scanActiveProject(true);
} else if (e) {
e->reparse();
}
}
}
void MainWindow::onCompilerSetChanged(int index)
@ -2703,3 +2810,8 @@ void MainWindow::on_tblBreakpoints_doubleClicked(const QModelIndex &index)
}
}
std::shared_ptr<Project> MainWindow::project()
{
return mProject;
}

View File

@ -105,6 +105,8 @@ public:
CaretList &caretList();
void updateCaretActions();
std::shared_ptr<Project> project();
public slots:
void onCompileLog(const QString& msg);
void onCompileIssue(PCompileIssue issue);
@ -123,6 +125,7 @@ public slots:
void onEditorTabContextMenu(const QPoint& pos);
private:
void closeProject(bool refreshEditor);
void openFiles(const QStringList& files);
void openFile(const QString& filename);
void openProject(const QString& filename);
@ -139,6 +142,7 @@ private:
QAction* createActionFor(const QString& text,
QWidget* parent,
QKeySequence shortcut=QKeySequence());
void scanActiveProject(bool parse=false);
private slots:
void onAutoSaveTimeout();
@ -317,7 +321,7 @@ private:
bool mQuitting;
QElapsedTimer mParserTimer;
QFileSystemWatcher mFileSystemWatcher;
Project* mProject;
std::shared_ptr<Project> mProject;
std::shared_ptr<CodeCompletionPopup> mCompletionPopup;
std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup;

View File

@ -11,7 +11,9 @@
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QTextCodec>
#include "settings.h"
#include <QDebug>
Project::Project(const QString &filename, const QString &name, QObject *parent) :
QObject(parent),
@ -19,6 +21,7 @@ Project::Project(const QString &filename, const QString &name, QObject *parent)
{
mFilename = filename;
mIniFile = std::make_shared<QSettings>(filename,QSettings::IniFormat);
mIniFile->setIniCodec(QTextCodec::codecForLocale());
mParser = std::make_shared<CppParser>();
mParser->setOnGetFileStream(
std::bind(
@ -37,6 +40,15 @@ Project::Project(const QString &filename, const QString &name, QObject *parent)
}
}
Project::~Project()
{
foreach (const PProjectUnit& unit, mUnits) {
if (unit->editor()) {
unit->editor()->setInProject(false);
}
}
}
QString Project::directory() const
{
QFileInfo fileInfo(mFilename);
@ -100,34 +112,18 @@ void Project::open()
mModel.endUpdate();
});
QFile fileInfo(mFilename);
if (fileInfo.exists()
&& !fileInfo.isWritable()) {
if (QMessageBox::question(pMainWindow,
tr("Remove Readonly Attribute"),
tr("Project file '%1' is readonly.<br /> Remove the readonly attribute?")
.arg(mFilename),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes) == QMessageBox::Yes) {
fileInfo.setPermissions(
QFileDevice::WriteOwner
| QFileDevice::WriteGroup
| QFileDevice::WriteUser
);
}
}
loadOptions();
mNode = makeProjectNode();
checkProjectFileForUpdate();
mIniFile->beginGroup("Project");
qDebug()<<"ini filename:"<<mIniFile->fileName();
int uCount = mIniFile->value("UnitCount",0).toInt();
mIniFile->endGroup();
//createFolderNodes;
QDir dir(directory());
for (int i=0;i<uCount;i++) {
PProjectUnit newUnit = std::make_shared<ProjectUnit>();
PProjectUnit newUnit = std::make_shared<ProjectUnit>(this);
mIniFile->beginGroup(QString("Unit%1").arg(i));
newUnit->setFileName(dir.filePath(mIniFile->value("FileName","").toString()));
if (!QFileInfo(newUnit->fileName()).exists()) {
@ -170,6 +166,7 @@ void Project::setFileName(const QString &value)
mFilename = value;
setModified(true);
mIniFile = std::make_shared<QSettings>(mFilename, QSettings::IniFormat);
mIniFile->setIniCodec(QTextCodec::codecForLocale());
}
}
@ -187,6 +184,7 @@ void Project::setModified(bool value)
PFolderNode Project::makeNewFileNode(const QString &s, bool isFolder, PFolderNode newParent)
{
PFolderNode node = std::make_shared<FolderNode>();
newParent->children.append(node);
node->parent = newParent;
node->text = s;
if (newParent) {
@ -194,6 +192,7 @@ PFolderNode Project::makeNewFileNode(const QString &s, bool isFolder, PFolderNod
}
if (isFolder)
node->unitIndex = -1;
return node;
}
PFolderNode Project::makeProjectNode()
@ -201,11 +200,12 @@ PFolderNode Project::makeProjectNode()
PFolderNode node = std::make_shared<FolderNode>();
node->text = mName;
node->level = 0;
return node;
}
int Project::newUnit(PFolderNode parentNode, const QString customFileName)
{
PProjectUnit newUnit = std::make_shared<ProjectUnit>();
PProjectUnit newUnit = std::make_shared<ProjectUnit>(this);
// Select folder to add unit to
if (!parentNode)
@ -271,6 +271,7 @@ Editor *Project::openUnit(int index)
loadUnitLayout(editor,index);
return editor;
}
return nullptr;
}
void Project::rebuildNodes()
@ -372,6 +373,18 @@ bool Project::removeFolder(PFolderNode node)
return true;
}
void Project::resetParserProjectFiles()
{
mParser->clearProjectFiles();
mParser->clearProjectIncludePaths();
foreach (const PProjectUnit& unit, mUnits) {
mParser->addFileToScan(unit->fileName());
}
foreach (const QString& s, mOptions.includes) {
mParser->addProjectIncludePath(s);
}
}
void Project::saveAll()
{
if (!saveUnits())
@ -978,7 +991,7 @@ void Project::checkProjectFileForUpdate()
if (!oldRes.isEmpty()) {
QFile::copy(mFilename,mFilename+".bak");
QStringList sl;
sl = oldRes.split(';');
sl = oldRes.split(';',Qt::SkipEmptyParts);
for (int i=0;i<sl.count();i++){
const QString& s = sl[i];
mIniFile->beginGroup(QString("Unit%1").arg(uCount+i));
@ -1156,7 +1169,7 @@ void Project::loadLayout()
//TopRight := layIni.ReadInteger('Editors', 'FocusedRight', -1);
QString temp =layIni.value("Order", "").toString();
layIni.endGroup();
QStringList sl = temp.split(",");
QStringList sl = temp.split(",",Qt::SkipEmptyParts);
foreach (const QString& s,sl) {
bool ok;
@ -1177,6 +1190,7 @@ void Project::loadOptions()
mName = mIniFile->value("name", "").toString();
mOptions.icon = mIniFile->value("icon", "").toString();
mOptions.version = mIniFile->value("Ver", 0).toInt();
mIniFile->endGroup();
if (mOptions.version > 0) { // ver > 0 is at least a v5 project
if (mOptions.version < 2) {
mOptions.version = 2;
@ -1188,16 +1202,17 @@ void Project::loadOptions()
QMessageBox::Ok);
}
mIniFile->beginGroup("Project");
mOptions.type = static_cast<ProjectType>(mIniFile->value("type", 0).toInt());
mOptions.compilerCmd = mIniFile->value("Compiler", "").toString();
mOptions.cppCompilerCmd = mIniFile->value("CppCompiler", "").toString();
mOptions.linkerCmd = mIniFile->value("Linker", "").toString();
mOptions.objFiles = mIniFile->value("ObjFiles", "").toString().split(";");
mOptions.libs = mIniFile->value("Libs", "").toString().split(";");
mOptions.includes = mIniFile->value("Includes", "").toString().split(";");
mOptions.objFiles = mIniFile->value("ObjFiles", "").toString().split(";",Qt::SkipEmptyParts);
mOptions.libs = mIniFile->value("Libs", "").toString().split(";",Qt::SkipEmptyParts);
mOptions.includes = mIniFile->value("Includes", "").toString().split(";",Qt::SkipEmptyParts);
mOptions.privateResource = mIniFile->value("PrivateResource", "").toString();
mOptions.resourceIncludes = mIniFile->value("ResourceIncludes", "").toString().split(";");
mOptions.makeIncludes = mIniFile->value("MakeIncludes","").toString().split(";");
mOptions.resourceIncludes = mIniFile->value("ResourceIncludes", "").toString().split(";",Qt::SkipEmptyParts);
mOptions.makeIncludes = mIniFile->value("MakeIncludes","").toString().split(";",Qt::SkipEmptyParts);
mOptions.useGPP = mIniFile->value("IsCpp", false).toBool();
mOptions.exeOutput = mIniFile->value("ExeOutput", "").toString();
mOptions.objectOutput = mIniFile->value("ObjectOutput", "").toString();
@ -1211,7 +1226,7 @@ void Project::loadOptions()
mOptions.usePrecompiledHeader = mIniFile->value("UsePrecompiledHeader", false).toBool();
mOptions.precompiledHeader = mIniFile->value("PrecompiledHeader","").toString();
mOptions.cmdLineArgs = mIniFile->value("CommandLine","").toString();
mFolders = mIniFile->value("Folders","").toString().split(";");
mFolders = mIniFile->value("Folders","").toString().split(";",Qt::SkipEmptyParts);
mOptions.includeVersionInfo = mIniFile->value("IncludeVersionInfo", false).toBool();
mOptions.supportXPThemes = mIniFile->value("SupportXPThemes", false).toBool();
mOptions.compilerSet = mIniFile->value("CompilerSet", pSettings->compilerSets().defaultIndex()).toInt();
@ -1238,6 +1253,9 @@ void Project::loadOptions()
} else {
mOptions.encoding = mIniFile->value("Encoding", ENCODING_UTF8).toString();
}
mIniFile->endGroup();
mIniFile->beginGroup("VersionInfo");
mOptions.versionInfo.major = mIniFile->value("Major", 0).toInt();
mOptions.versionInfo.minor = mIniFile->value("Minor", 1).toInt();
mOptions.versionInfo.release = mIniFile->value("Release", 1).toInt();
@ -1257,8 +1275,10 @@ void Project::loadOptions()
mOptions.versionInfo.productVersion = mIniFile->value("ProductVersion", "0.1.1.1").toString();
mOptions.versionInfo.autoIncBuildNr = mIniFile->value("AutoIncBuildNr", false).toBool();
mOptions.versionInfo.syncProduct = mIniFile->value("SyncProduct", false).toBool();
mIniFile->endGroup();
} else { // dev-c < 4
mOptions.version = -1;
mOptions.version = 2;
mIniFile->beginGroup("Project");
if (!mIniFile->value("NoConsole", true).toBool())
mOptions.type = ProjectType::Console;
else if (mIniFile->value("IsDLL", false).toBool())
@ -1267,9 +1287,9 @@ void Project::loadOptions()
mOptions.type = ProjectType::GUI;
mOptions.privateResource = mIniFile->value("PrivateResource","").toString();
mOptions.resourceIncludes = mIniFile->value("ResourceIncludes","").toString().split(";");
mOptions.objFiles = mIniFile->value("ObjFiles","").toString().split(";");
mOptions.includes = mIniFile->value("IncludeDirs","").toString().split(";");
mOptions.resourceIncludes = mIniFile->value("ResourceIncludes","").toString().split(";",Qt::SkipEmptyParts);
mOptions.objFiles = mIniFile->value("ObjFiles","").toString().split(";",Qt::SkipEmptyParts);
mOptions.includes = mIniFile->value("IncludeDirs","").toString().split(";",Qt::SkipEmptyParts);
mOptions.compilerCmd = mIniFile->value("CompilerOptions","").toString();
mOptions.useGPP = mIniFile->value("Use_GPP", false).toBool();
mOptions.exeOutput = mIniFile->value("ExeOutput","").toString();
@ -1277,6 +1297,7 @@ void Project::loadOptions()
mOptions.overrideOutput = mIniFile->value("OverrideOutput", false).toBool();
mOptions.overridenOutput = mIniFile->value("OverrideOutputName","").toString();
mOptions.hostApplication = mIniFile->value("HostApplication","").toString();
mIniFile->endGroup();
}
}
@ -1391,7 +1412,7 @@ void Project::setOptions(const ProjectOptions &newOptions)
mOptions = newOptions;
}
const ProjectModel *Project::model() const
ProjectModel *Project::model()
{
return &mModel;
}

View File

@ -160,6 +160,7 @@ class Project : public QObject
Q_OBJECT
public:
explicit Project(const QString& filename, const QString& name,QObject *parent = nullptr);
~Project();
QString directory() const;
QString executable() const;
QString makeFileName();
@ -194,6 +195,7 @@ public:
void rebuildNodes();
bool removeEditor(int index, bool doClose);
bool removeFolder(PFolderNode node);
void resetParserProjectFiles();
void saveAll(); // save [Project] and all [UnitX]
void saveLayout(); // save all [UnitX]
void saveOptions();
@ -225,7 +227,7 @@ public:
const ProjectOptions &options() const;
void setOptions(const ProjectOptions &newOptions);
const ProjectModel* model() const;
ProjectModel* model() ;
const QList<PProjectUnit> &units() const;

View File

@ -5,20 +5,20 @@
#include <algorithm>
#include <QDebug>
int MinMax(int x, int mi, int ma)
int minMax(int x, int mi, int ma)
{
x = std::min(x, ma );
return std::max( x, mi );
}
void SwapInt(int &l, int &r)
void swapInt(int &l, int &r)
{
int tmp = r;
r = l;
l = tmp;
}
QPoint MaxPoint(const QPoint &P1, const QPoint &P2)
QPoint maxPoint(const QPoint &P1, const QPoint &P2)
{
if ( (P2.y() > P1.y()) || ( (P2.y() == P1.y()) && (P2.x() > P1.x())) ) {
return P2;
@ -27,7 +27,7 @@ QPoint MaxPoint(const QPoint &P1, const QPoint &P2)
}
}
QPoint MinPoint(const QPoint &P1, const QPoint &P2)
QPoint minPoint(const QPoint &P1, const QPoint &P2)
{
if ( (P2.y() < P1.y()) || ( (P2.y() == P1.y()) && (P2.x() < P1.x())) ) {
return P2;
@ -36,12 +36,12 @@ QPoint MinPoint(const QPoint &P1, const QPoint &P2)
}
}
PIntArray GetIntArray(size_t Count, int InitialValue)
PIntArray getIntArray(size_t Count, int InitialValue)
{
return std::make_shared<IntArray>(Count,InitialValue);
}
void InternalFillRect(QPainter *painter, const QRect &rcPaint, const QColor& color)
void internalFillRect(QPainter *painter, const QRect &rcPaint, const QColor& color)
{
painter->fillRect(rcPaint,color);
}
@ -527,13 +527,11 @@ void SynDrawGradient(QPaintDevice *ACanvas, const QColor &AStartColor, const QCo
}
}
#ifndef Q_OS_WIN
int MulDiv(int a, int b, int c)
int mulDiv(int a, int b, int c)
{
//todo: handle overflow?
return a*b/c;
}
#endif
SynFontStyles getFontStyles(const QFont &font)
{
@ -615,7 +613,7 @@ void ensureNotAfter(BufferCoord &cord1, BufferCoord &cord2)
}
}
BufferCoord MinBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
BufferCoord minBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
{
if ( (P2.Line < P1.Line) || ( (P2.Line == P1.Line) && (P2.Char < P1.Char)) ) {
return P2;
@ -624,7 +622,7 @@ BufferCoord MinBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
}
}
BufferCoord MaxBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
BufferCoord maxBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
{
if ( (P2.Line > P1.Line) || ( (P2.Line == P1.Line) && (P2.Char > P1.Char)) ) {
return P2;

View File

@ -20,19 +20,17 @@ class QColor;
using IntArray = QVector<int>;
using PIntArray = std::shared_ptr<IntArray>;
int MinMax(int x, int mi, int ma);
#ifndef Q_OS_WIN
int MulDiv(int a, int b, int c);
#endif
void SwapInt(int& l, int &r);
BufferCoord MaxBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
BufferCoord MinBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
QPoint MaxPoint(const QPoint& P1, const QPoint& P2);
QPoint MinPoint(const QPoint& P1, const QPoint& P2);
int minMax(int x, int mi, int ma);
int mulDiv(int a, int b, int c);
void swapInt(int& l, int &r);
BufferCoord maxBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
BufferCoord minBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
QPoint maxPoint(const QPoint& P1, const QPoint& P2);
QPoint minPoint(const QPoint& P1, const QPoint& P2);
PIntArray GetIntArray(size_t Count, int InitialValue);
PIntArray getIntArray(size_t Count, int InitialValue);
void InternalFillRect(QPainter* painter, const QRect& rcPaint, const QColor& color);
void internalFillRect(QPainter* painter, const QRect& rcPaint, const QColor& color);
// Converting tabs to spaces: To use the function several times it's better
// to use a function pointer that is set to the fastest conversion function.

View File

@ -1304,7 +1304,7 @@ void SynEdit::SetWordBlock(BufferCoord Value)
// Value.Char =
// else
// Value.Char = std::max(Value.Char, 1);
Value.Line = MinMax(Value.Line, 1, mLines->count());
Value.Line = minMax(Value.Line, 1, mLines->count());
Value.Char = std::max(Value.Char, 1);
QString TempString = mLines->getString(Value.Line - 1); //needed for CaretX = LineLength +1
if (Value.Char > TempString.length()) {
@ -2114,7 +2114,7 @@ void SynEdit::clearAreaList(SynEditingAreaList areaList)
void SynEdit::computeCaret(int X, int Y)
{
DisplayCoord vCaretNearestPos = pixelsToNearestRowColumn(X, Y);
vCaretNearestPos.Row = MinMax(vCaretNearestPos.Row, 1, displayLineCount());
vCaretNearestPos.Row = minMax(vCaretNearestPos.Row, 1, displayLineCount());
setInternalDisplayXY(vCaretNearestPos);
}
@ -2611,8 +2611,8 @@ void SynEdit::updateScrollbars()
} else {
nMin = 0;
nMax = MAX_SCROLL;
nPage = MulDiv(MAX_SCROLL, mCharsInWindow, nMaxScroll);
nPos = MulDiv(MAX_SCROLL, mLeftChar, nMaxScroll);
nPage = mulDiv(MAX_SCROLL, mCharsInWindow, nMaxScroll);
nPos = mulDiv(MAX_SCROLL, mLeftChar, nMaxScroll);
}
horizontalScrollBar()->setMinimum(nMin);
horizontalScrollBar()->setMaximum(nMax);
@ -2632,8 +2632,8 @@ void SynEdit::updateScrollbars()
} else {
nMin = 0;
nMax = MAX_SCROLL;
nPage = MulDiv(MAX_SCROLL, mLinesInWindow, nMaxScroll);
nPos = MulDiv(MAX_SCROLL, mTopLine, nMaxScroll);
nPage = mulDiv(MAX_SCROLL, mLinesInWindow, nMaxScroll);
nPos = mulDiv(MAX_SCROLL, mTopLine, nMaxScroll);
}
verticalScrollBar()->setMinimum(nMin);
verticalScrollBar()->setMaximum(nMax);
@ -3559,7 +3559,7 @@ void SynEdit::doUndoItem()
std::min(Item->changeStartPos().Line, Item->changeEndPos().Line)};
} else {
TmpPos = BufferCoord{
MinBufferCoord(
minBufferCoord(
Item->changeStartPos(),
Item->changeEndPos())};
}
@ -5220,8 +5220,8 @@ void SynEdit::paintEvent(QPaintEvent *event)
nC2 = mLeftChar +
(rcClip.right() - mGutterWidth - 2 + mCharWidth - 1) / mCharWidth;
// lines
nL1 = MinMax(mTopLine + rcClip.top() / mTextHeight, mTopLine, displayLineCount());
nL2 = MinMax(mTopLine + (rcClip.bottom() + mTextHeight - 1) / mTextHeight, 1, displayLineCount());
nL1 = minMax(mTopLine + rcClip.top() / mTextHeight, mTopLine, displayLineCount());
nL2 = minMax(mTopLine + (rcClip.bottom() + mTextHeight - 1) / mTextHeight, 1, displayLineCount());
//qDebug()<<"Paint:"<<nL1<<nL2<<nC1<<nC2;
@ -5432,7 +5432,7 @@ void SynEdit::mouseMoveEvent(QMouseEvent *event)
// should we begin scrolling?
computeScroll(X, Y);
DisplayCoord P = pixelsToNearestRowColumn(X, Y);
P.Row = MinMax(P.Row, 1, displayLineCount());
P.Row = minMax(P.Row, 1, displayLineCount());
if (mScrollDeltaX != 0)
P.Column = displayX();
if (mScrollDeltaY != 0)
@ -5682,8 +5682,8 @@ void SynEdit::setBlockEnd(BufferCoord Value)
{
setActiveSelectionMode(mSelectionMode);
if (!mOptions.testFlag(eoNoSelection)) {
Value.Line = MinMax(Value.Line, 1, mLines->count());
Value.Char = MinMax(Value.Char, 1, mLines->lengthOfLongestLine()+1);
Value.Line = minMax(Value.Line, 1, mLines->count());
Value.Char = minMax(Value.Char, 1, mLines->lengthOfLongestLine()+1);
if (mActiveSelectionMode == SynSelectionMode::smNormal) {
if (Value.Line >= 1 && Value.Line <= mLines->count())
Value.Char = std::min(Value.Char, mLines->getString(Value.Line - 1).length() + 1);
@ -5771,8 +5771,8 @@ void SynEdit::setBlockBegin(BufferCoord value)
int nInval1, nInval2;
bool SelChanged;
setActiveSelectionMode(mSelectionMode);
value.Char = MinMax(value.Char, 1, mLines->lengthOfLongestLine()+1);
value.Line = MinMax(value.Line, 1, mLines->count());
value.Char = minMax(value.Char, 1, mLines->lengthOfLongestLine()+1);
value.Line = minMax(value.Line, 1, mLines->count());
if (mActiveSelectionMode == SynSelectionMode::smNormal) {
if (value.Line >= 1 && value.Line <= mLines->count())
value.Char = std::min(value.Char, mLines->getString(value.Line - 1).length() + 1);
@ -5876,7 +5876,7 @@ void SynEdit::onScrollTimeout()
iMousePos = QCursor::pos();
iMousePos = mapFromGlobal(iMousePos);
C = pixelsToRowColumn(iMousePos.x(), iMousePos.y());
C.Row = MinMax(C.Row, 1, displayLineCount());
C.Row = minMax(C.Row, 1, displayLineCount());
if (mScrollDeltaX != 0) {
setLeftChar(leftChar() + mScrollDeltaX);
X = leftChar();
@ -5892,7 +5892,7 @@ void SynEdit::onScrollTimeout()
Y = mTopLine;
if (mScrollDeltaY > 0) // scrolling down?
Y+=mLinesInWindow - 1;
C.Row = MinMax(Y, 1, displayLineCount());
C.Row = minMax(Y, 1, displayLineCount());
}
BufferCoord vCaret = displayToBufferPos(C);
if ((caretX() != vCaret.Char) || (caretY() != vCaret.Line)) {

View File

@ -2668,6 +2668,32 @@ void Settings::History::removeFile(const QString &filename)
return;
}
bool Settings::History::addToOpenedProjects(const QString &filename)
{
if (!QFile(filename).exists())
return false;
int index = mOpenedProjects.indexOf(filename);
if (index>=0) {
mOpenedProjects.removeAt(index);
}
if (mOpenedProjects.size()>=15) {
mOpenedProjects.pop_back();
}
mOpenedProjects.push_front(filename);
save();
return true;
}
void Settings::History::removeProject(const QString &filename)
{
int index = mOpenedProjects.indexOf(filename);
if (index>=0) {
mOpenedProjects.removeAt(index);
}
save();
return;
}
void Settings::History::doSave()
{
saveValue("opened_files", mOpenedFiles);

View File

@ -681,6 +681,8 @@ public:
const QStringList& openedProjects() const;
bool addToOpenedFiles(const QString& filename);
void removeFile(const QString& filename);
bool addToOpenedProjects(const QString& filename);
void removeProject(const QString& filename);
private:
QStringList mOpenedFiles;
QStringList mOpenedProjects;

View File

@ -7,12 +7,11 @@ SystemConsts* pSystemConsts;
SystemConsts::SystemConsts(): mDefaultFileFilters()
{
addDefaultFileFilter(QObject::tr("All files"),"*");
addDefaultFileFilter(QObject::tr("Dev C++ Project files"),"*.dev");
addDefaultFileFilter(QObject::tr("C files"),"*.c");
addDefaultFileFilter(QObject::tr("C++ files"),"*.cpp *.cc *.cxx");
addDefaultFileFilter(QObject::tr("Header files"),"*.h *.hh");
addDefaultFileFilter(QObject::tr("Text files"),"*.txt");
addDefaultFileFilter(QObject::tr("HTML files"),"*.html *.htm");
addDefaultFileFilter(QObject::tr("All files"),"*");
}
const QStringList &SystemConsts::defaultFileFilters() const noexcept
@ -22,22 +21,17 @@ const QStringList &SystemConsts::defaultFileFilters() const noexcept
const QString &SystemConsts::defaultCFileFilter() const noexcept
{
return mDefaultFileFilters[0];
return mDefaultFileFilters[2];
}
const QString &SystemConsts::defaultCPPFileFilter() const noexcept
{
return mDefaultFileFilters[1];
return mDefaultFileFilters[3];
}
const QString &SystemConsts::defaultAllFileFilter() const noexcept
{
return mDefaultFileFilters.back();
}
const QString &SystemConsts::defaultHTMLFileFilter() const noexcept
{
return mDefaultFileFilters[4];
return mDefaultFileFilters[0];
}
void SystemConsts::addDefaultFileFilter(const QString &name, const QString &fileExtensions)

View File

@ -52,7 +52,6 @@ public:
const QString& defaultCFileFilter() const noexcept;
const QString& defaultCPPFileFilter() const noexcept;
const QString& defaultAllFileFilter() const noexcept;
const QString& defaultHTMLFileFilter() const noexcept;
void addDefaultFileFilter(const QString& name, const QString& fileExtensions);
private:
QStringList mDefaultFileFilters;

View File

@ -126,7 +126,7 @@ bool isNonPrintableAsciiChar(char ch)
bool fileExists(const QString &file)
{
return fileExists(file);
return QFile(file).exists();
}
bool fileExists(const QString &dir, const QString &fileName)
@ -202,7 +202,7 @@ FileType getFileType(const QString &filename)
QString getCompiledExecutableName(const QString& filename)
{
return changeFileExt(filename,EXECUTABE_EXT);
return changeFileExt(filename,EXECUTABLE_EXT);
}
void splitStringArguments(const QString &arguments, QStringList &argumentList)

View File

@ -343,7 +343,7 @@ void ClassBrowserModel::endUpdate()
{
mUpdateCount--;
if (mUpdateCount == 0) {
if (!mParser->parsing()) {
if (mParser && !mParser->parsing()) {
this->fillStatements();
}
}