- enhancement: auto load last open files at start

This commit is contained in:
royqh1979@gmail.com 2021-09-27 20:17:24 +08:00
parent 356db1349f
commit 0424f7cf45
5 changed files with 107 additions and 8 deletions

View File

@ -1,6 +1,7 @@
Version 0.2
- fix : header file completion stop work when input '.'
- change: continue to run / debug if there are compiling warnings (but no errors)
- enhancement: auto load last open files at start
- enhancement: class browser syntax colors and icons
- enhancement: function tips
- enhancement: project support

View File

@ -95,6 +95,8 @@ int main(int argc, char *argv[])
MainWindow mainWindow;
pMainWindow = &mainWindow;
if (pSettings->editor().autoLoadLastFiles())
pMainWindow->loadLastOpens();
mainWindow.show();
int retCode = app.exec();
// save settings

View File

@ -169,6 +169,7 @@ MainWindow::MainWindow(QWidget *parent)
buildContextMenus();
updateEditorColorSchemes();
}
MainWindow::~MainWindow()
@ -1447,12 +1448,96 @@ void MainWindow::scanActiveProject(bool parse)
void MainWindow::saveLastOpens()
{
QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_LASTOPENS_FILE;
if (fileExists(filename)) {
if (!QFile::remove(filename)) {
QMessageBox::critical(this,
tr("Save last open info error"),
tr("Can't remove old last open information file '%1'")
.arg(filename),
QMessageBox::Ok);
return;
}
}
SimpleIni lastOpenIni;
lastOpenIni.SetLongValue("LastOpens","Count", mEditorList->pageCount());
if (mProject) {
lastOpenIni.SetValue("LastOpens","Project",mProject->filename().toLocal8Bit());
}
for (int i=0;i<mEditorList->pageCount();i++) {
Editor * editor = (*mEditorList)[i];
QByteArray sectionName = QString("Editor_%1").arg(i).toLocal8Bit();
lastOpenIni.SetValue(sectionName,"FileName", editor->filename().toLocal8Bit());
lastOpenIni.SetBoolValue(sectionName, "OnLeft",editor->pageControl() != ui->EditorTabsRight);
lastOpenIni.SetBoolValue(sectionName, "Focused",editor->hasFocus());
lastOpenIni.SetLongValue(sectionName, "CursorCol", editor->caretX());
lastOpenIni.SetLongValue(sectionName, "CursorRow", editor->caretY());
lastOpenIni.SetLongValue(sectionName, "TopLine", editor->topLine());
lastOpenIni.SetLongValue(sectionName, "LeftChar", editor->leftChar());
}
if (lastOpenIni.SaveFile(filename.toLocal8Bit())!=SI_Error::SI_OK) {
QMessageBox::critical(this,
tr("Save last open info error"),
tr("Can't save last open info file '%1'")
.arg(filename),
QMessageBox::Ok);
return;
}
}
void MainWindow::loadLastOpens()
{
QString filename = includeTrailingPathDelimiter(pSettings->dirs().config()) + DEV_LASTOPENS_FILE;
if (!fileExists(filename))
return;
SimpleIni lastOpenIni;
if (lastOpenIni.LoadFile(filename.toLocal8Bit())!=SI_Error::SI_OK) {
QMessageBox::critical(this,
tr("Load last open info error"),
tr("Can't load last open info file '%1'")
.arg(filename),
QMessageBox::Ok);
return;
}
Editor * focusedEditor = nullptr;
int count = lastOpenIni.GetLongValue("LastOpens","Count",0);
for (int i=0;i<count;i++) {
QByteArray sectionName = QString("Editor_%1").arg(i).toLocal8Bit();
QString editorFilename = lastOpenIni.GetValue(sectionName,"FileName","");
if (!fileExists(editorFilename))
continue;
bool onLeft = lastOpenIni.GetBoolValue(sectionName,"OnLeft",true);
// if onLeft then
// page := EditorList.LeftPageControl
// else
// page := EditorList.RightPageControl;
Editor * editor = mEditorList->newEditor(editorFilename,ENCODING_AUTO_DETECT,false,false);
if (!editor)
continue;
BufferCoord pos;
pos.Char = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1);
pos.Line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1);
editor->setCaretXY(pos);
editor->setTopLine(
lastOpenIni.GetLongValue(sectionName,"TopLine", 1)
);
editor->setLeftChar(
lastOpenIni.GetLongValue(sectionName,"LeftChar", 1)
);
if (lastOpenIni.GetBoolValue(sectionName,"Focused",false))
focusedEditor = editor;
pSettings->history().removeFile(editorFilename);
}
QString projectFilename = lastOpenIni.GetValue("LastOpens", "Project","");
if (fileExists(projectFilename)) {
openProject(filename);
} else {
updateEditorActions();
updateForEncodingInfo();
}
if (!focusedEditor)
focusedEditor->activate();
}
void MainWindow::buildContextMenus()
@ -2240,8 +2325,13 @@ void MainWindow::closeEvent(QCloseEvent *event) {
settings.setLeftPanelOpenned(mLeftPanelOpenned);
settings.save();
if (mProject) {
closeProject(false);
if (pSettings->editor().autoLoadLastFiles()) {
saveLastOpens();
} else {
//if don't save last open files, close project before editors, to save project openned editors;
if (mProject) {
closeProject(false);
}
}
if (!mEditorList->closeAll(false)) {
@ -2249,6 +2339,12 @@ void MainWindow::closeEvent(QCloseEvent *event) {
return ;
}
if (pSettings->editor().autoLoadLastFiles()) {
if (mProject) {
closeProject(false);
}
}
mCompilerManager->stopCompile();
mCompilerManager->stopRun();

View File

@ -81,13 +81,14 @@ public:
void addDebugOutput(const QString& text);
void changeDebugOutputLastline(const QString& text);
void updateDebugEval(const QString& value);
void rebuildOpenedFileHisotryMenu();
void updateClassBrowserForEditor(Editor* editor);
void resetAutoSaveTimer();
void saveLastOpens();
void loadLastOpens();
QPlainTextEdit* txtLocals();
CPUDialog *cpuDialog() const;
@ -154,8 +155,6 @@ private:
QWidget* parent,
QKeySequence shortcut=QKeySequence());
void scanActiveProject(bool parse=false);
void saveLastOpens();
void loadLastOpens();
private slots:
void onAutoSaveTimeout();

View File

@ -29,6 +29,7 @@
#define ICON_EXT "ico"
#define TEMPLATE_EXT "template"
#define DEV_INTERNAL_OPEN "$__DEV_INTERNAL_OPEN"
#define DEV_LASTOPENS_FILE "lastopens.ini"
#ifdef Q_OS_WIN
# define PATH_SENSITIVITY Qt::CaseInsensitive