From 5ab9c16039fdd2ad9e22a5b1ded507d230254ffa Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Fri, 17 Sep 2021 09:56:52 +0800 Subject: [PATCH] - new project done - update project actions enable state - add project unit actions --- RedPandaIDE/compiler/projectcompiler.cpp | 8 +- RedPandaIDE/mainwindow.cpp | 129 +++++++++++++---------- RedPandaIDE/mainwindow.h | 4 + RedPandaIDE/mainwindow.ui | 52 ++++++++- RedPandaIDE/project.cpp | 12 ++- RedPandaIDE/systemconsts.h | 1 + RedPandaIDE/utils.cpp | 4 +- RedPandaIDE/utils.h | 2 +- 8 files changed, 146 insertions(+), 66 deletions(-) diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 8729af3a..fdecb826 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -38,9 +38,9 @@ void ProjectCompiler::createStandardMakeFile() file.write("$(BIN): $(OBJ)\n"); if (!mOnlyCheckSyntax) { if (mProject->options().useGPP) { - writeln(file,"\t$(CPP) $(LINKOBJ) -o \"$(BIN)\" $(LIBS)"); + writeln(file,"\t$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)"); } else - writeln(file,"\t$(CC) $(LINKOBJ) -o \"$(BIN)\" $(LIBS)"); + writeln(file,"\t$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)"); } writeMakeObjFilesRules(file); } @@ -64,9 +64,9 @@ void ProjectCompiler::createDynamicMakeFile() file.write("$(BIN): $(LINKOBJ)"); if (!mOnlyCheckSyntax) { if (mProject->options().useGPP) { - file.write("\t$(CPP) -mdll $(LINKOBJ) -o \"$(BIN)\" $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)"); + file.write("\t$(CPP) -mdll $(LINKOBJ) -o $(BIN) $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)"); } else { - file.write("\t$(CC) -mdll $(LINKOBJ) -o \"$(BIN)\" $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)"); + file.write("\t$(CC) -mdll $(LINKOBJ) -o $(BIN) $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)"); } } writeMakeObjFilesRules(file); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 0e78646e..732a07c7 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -116,8 +116,9 @@ MainWindow::MainWindow(QWidget *parent) mCPUDialog = nullptr; + updateProjectView(); updateEditorActions(); - updateCaretActions(); + updateCaretActions(); applySettings(); applyUISettings(); @@ -202,26 +203,11 @@ void MainWindow::updateEditorActions() ui->actionRedo->setEnabled(false); ui->actionSave->setEnabled(false); ui->actionSaveAs->setEnabled(false); - ui->actionSaveAll->setEnabled(false); ui->actionSelectAll->setEnabled(false); ui->actionToggleComment->setEnabled(false); ui->actionUnIndent->setEnabled(false); ui->actionUndo->setEnabled(false); ui->actionUnfoldAll->setEnabled(false); - - ui->actionCompile->setEnabled(false); - ui->actionCompile_Run->setEnabled(false); - ui->actionRun->setEnabled(false); - ui->actionRebuild->setEnabled(false); - ui->actionStop_Execution->setEnabled(false); - - ui->actionDebug->setEnabled(false); - ui->actionStep_Over->setEnabled(false); - ui->actionStep_Into->setEnabled(false); - ui->actionStep_Out->setEnabled(false); - ui->actionContinue->setEnabled(false); - ui->actionRun_To_Cursor->setEnabled(false); - ui->actionFind->setEnabled(false); ui->actionReplace->setEnabled(false); ui->actionFind_Next->setEnabled(false); @@ -249,7 +235,6 @@ void MainWindow::updateEditorActions() ui->actionUndo->setEnabled(e->canUndo()); ui->actionSave->setEnabled(e->modified()); ui->actionSaveAs->setEnabled(true); - ui->actionSaveAll->setEnabled(true); ui->actionSelectAll->setEnabled(e->lines()->count()>0); ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0); ui->actionUnIndent->setEnabled(!e->readOnly() && e->lines()->count()>0); @@ -265,21 +250,33 @@ void MainWindow::updateEditorActions() ui->actionClose->setEnabled(true); ui->actionClose_All->setEnabled(true); + } - updateCompileActions(); - } + updateCompileActions(); } +void MainWindow::updateProjectActions() +{ + bool hasProject = (mProject != nullptr); + ui->actionProject_options->setEnabled(hasProject); + ui->actionClose_Project->setEnabled(hasProject); + updateCompileActions(); +} + void MainWindow::updateCompileActions() { + bool hasProject = (mProject!=nullptr); + bool editorCanCompile = false; Editor * e = mEditorList->getEditor(); - if (!e) - return; - FileType fileType = getFileType(e->filename()); + if (e) { + FileType fileType = getFileType(e->filename()); + if (fileType == FileType::CSource + || fileType == FileType::CppSource) + editorCanCompile = true; + } if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing() - || (fileType!= FileType::CSource - && fileType != FileType::CppSource) ) { + || (!hasProject && !editorCanCompile) ) { ui->actionCompile->setEnabled(false); ui->actionCompile_Run->setEnabled(false); ui->actionRun->setEnabled(false); @@ -293,12 +290,18 @@ void MainWindow::updateCompileActions() ui->actionDebug->setEnabled(true); } + ui->actionStep_Into->setEnabled(mDebugger->executing()); ui->actionStep_Out->setEnabled(mDebugger->executing()); ui->actionStep_Over->setEnabled(mDebugger->executing()); ui->actionContinue->setEnabled(mDebugger->executing()); ui->actionRun_To_Cursor->setEnabled(mDebugger->executing()); ui->actionStop_Execution->setEnabled(mCompilerManager->running() || mDebugger->executing()); + + //it's not a compile action, but put here for convinience + ui->actionSaveAll->setEnabled(mProject!=nullptr + || mEditorList->pageCount()>0); + } void MainWindow::updateEditorColorSchemes() @@ -675,39 +678,39 @@ void MainWindow::openProject(const QString &filename) mClassBrowserModel.endUpdate(); }); mProject = std::make_shared(filename,DEV_INTERNAL_OPEN); - ui->projectView->setModel(mProject->model()); + updateProjectView(); pSettings->history().removeProject(filename); // // if project manager isn't open then open it // if not devData.ShowLeftPages then // actProjectManager.Execute; //checkForDllProfiling(); - updateAppTitle(); - updateCompilerSet(); + updateAppTitle(); + updateCompilerSet(); - //parse the project - // UpdateClassBrowsing; - scanActiveProject(true); - mProject->doAutoOpen(); + //parse the project + // UpdateClassBrowsing; + scanActiveProject(true); + mProject->doAutoOpen(); - //update editor's inproject flag - for (int i=0;iunits().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); - } - } - - Editor * e = mEditorList->getEditor(); + //update editor's inproject flag + for (int i=0;iunits().count();i++) { + PProjectUnit unit = mProject->units()[i]; + Editor* e = mEditorList->getOpenedEditorByFilename(unit->fileName()); if (e) { - checkSyntaxInBack(e); + unit->setEditor(e); + unit->setEncoding(e->encodingOption()); + e->setInProject(true); + } else { + unit->setEditor(nullptr); } - updateClassBrowserForEditor(e); + } + + Editor * e = mEditorList->getEditor(); + if (e) { + checkSyntaxInBack(e); + } + updateClassBrowserForEditor(e); } updateForEncodingInfo(); } @@ -1676,17 +1679,28 @@ void MainWindow::closeProject(bool refreshEditor) } } if (!mQuitting) { - // Clear project browser - ui->projectView->setModel(nullptr); - // Clear error browser ui->tableIssues->clearIssues(); - - ui->tabProject->setVisible(false); + updateProjectView(); } } } +void MainWindow::updateProjectView() +{ + if (mProject) { + ui->projectView->setModel(mProject->model()); + openCloseLeftPanel(true); + ui->tabProject->setVisible(true); + ui->tabInfos->setCurrentWidget(ui->tabProject); + } else { + // Clear project browser + ui->projectView->setModel(nullptr); + ui->tabProject->setVisible(false); + } + updateProjectActions(); +} + void MainWindow::onFileChanged(const QString &path) { Editor *e = mEditorList->getOpenedEditorByFilename(path); @@ -2958,10 +2972,13 @@ void MainWindow::on_actionNew_Project_triggered() QMessageBox::Ok); } mProject->saveAll(); - ui->projectView->setModel(mProject->model()); - openCloseLeftPanel(true); - ui->tabProject->setVisible(true); - ui->tabInfos->setCurrentWidget(ui->tabProject); + updateProjectView(); } } + +void MainWindow::on_actionSaveAll_triggered() +{ + +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 8d8dcdfa..9c1e78e9 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -58,6 +58,7 @@ public: void updateStatusbarMessage(const QString& s); void updateEditorSettings(); void updateEditorActions(); + void updateProjectActions(); void updateCompileActions(); void updateEditorColorSchemes(); void updateCompilerSet(); @@ -125,6 +126,7 @@ public slots: private: void closeProject(bool refreshEditor); + void updateProjectView(); void openFiles(const QStringList& files); void openFile(const QString& filename); void openProject(const QString& filename); @@ -310,6 +312,8 @@ private slots: void on_actionNew_Project_triggered(); + void on_actionSaveAll_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 308375f4..200e7dc9 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -873,6 +873,13 @@ Project + + + + + + + @@ -991,10 +998,10 @@ - New File + New Source File - New File + New Source File Ctrl+N @@ -1633,6 +1640,47 @@ New Project... + + + + :/icons/images/newlook24/050-newsrc.png:/icons/images/newlook24/050-newsrc.png + + + New File + + + + + + :/icons/images/newlook24/004-addsrc.png:/icons/images/newlook24/004-addsrc.png + + + Add to project... + + + + + + :/icons/images/newlook24/064-remsrc.png:/icons/images/newlook24/064-remsrc.png + + + Remove from project + + + + + View Makefile + + + + + + :/icons/images/newlook24/011-clrhist.png:/icons/images/newlook24/011-clrhist.png + + + Clean + + diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 0aaa6a2d..ca86c6e8 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -8,6 +8,7 @@ #include "utils.h" #include "platform.h" #include "projecttemplate.h" +#include "systemconsts.h" #include #include @@ -251,6 +252,7 @@ PProjectUnit Project::newUnit(PFolderNode parentNode, const QString& customFileN newUnit->setOverrideBuildCmd(false); newUnit->setBuildCmd(""); newUnit->setModified(true); + newUnit->setEncoding(toByteArray(options().encoding)); return newUnit; } @@ -583,12 +585,13 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate) } mOptions = aTemplate->options(); + mOptions.icon = aTemplate->icon(); // Copy icon to project directory if (!mOptions.icon.isEmpty()) { QString originIcon = QDir(pSettings->dirs().templateDir()).absoluteFilePath(mOptions.icon); if (fileExists(originIcon)) { - QString destIcon = changeFileExt(mFilename,".ico"); + QString destIcon = changeFileExt(mFilename,ICON_EXT); QFile::copy(originIcon,destIcon); mOptions.icon = destIcon; } else { @@ -1255,7 +1258,12 @@ void Project::loadLayout() void Project::loadOptions(SimpleIni& ini) { mName = fromByteArray(ini.GetValue("Project","name", "")); - mOptions.icon = QDir(directory()).absoluteFilePath(fromByteArray(ini.GetValue("Project", "icon", ""))); + QString icon = fromByteArray(ini.GetValue("Project", "icon", "")); + if (icon.isEmpty()) { + mOptions.icon = ""; + } else { + mOptions.icon = QDir(directory()).absoluteFilePath(icon); + } mOptions.version = ini.GetLongValue("Project", "Ver", 0); if (mOptions.version > 0) { // ver > 0 is at least a v5 project if (mOptions.version < 2) { diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index b8d875cd..3dddfe98 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -26,6 +26,7 @@ #define DEF_EXT "def" #define LIB_EXT "a" #define GCH_EXT "gch" +#define ICON_EXT "ico" #define TEMPLATE_EXT "template" #define DEV_INTERNAL_OPEN "$__DEV_INTERNAL_OPEN" diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index af135df5..192a7443 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -456,12 +456,14 @@ int compareFileModifiedTime(const QString &filename1, const QString &filename2) return 0; } -QString changeFileExt(const QString& filename, const QString& ext) +QString changeFileExt(const QString& filename, QString ext) { QFileInfo fileInfo(filename); QString suffix = fileInfo.suffix(); QString name = fileInfo.fileName(); QString path; + if (ext.startsWith(".")) + ext.remove(0,1); if (fileInfo.path() != ".") { path = includeTrailingPathDelimiter(fileInfo.path()); } diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index 1a7cbee6..7596d414 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -128,7 +128,7 @@ bool directoryExists(const QString& file); QString includeTrailingPathDelimiter(const QString& path); QString excludeTrailingPathDelimiter(const QString& path); FileType getFileType(const QString& filename); -QString changeFileExt(const QString& filename, const QString& ext); +QString changeFileExt(const QString& filename, QString ext); QString extractRelativePath(const QString& base, const QString& dest); QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes); QString genMakePath1(const QString& fileName);