- new project done

- update project actions enable state
 - add project unit actions
This commit is contained in:
royqh1979@gmail.com 2021-09-17 09:56:52 +08:00
parent f2156919e0
commit 5ab9c16039
8 changed files with 146 additions and 66 deletions

View File

@ -38,9 +38,9 @@ void ProjectCompiler::createStandardMakeFile()
file.write("$(BIN): $(OBJ)\n"); file.write("$(BIN): $(OBJ)\n");
if (!mOnlyCheckSyntax) { if (!mOnlyCheckSyntax) {
if (mProject->options().useGPP) { if (mProject->options().useGPP) {
writeln(file,"\t$(CPP) $(LINKOBJ) -o \"$(BIN)\" $(LIBS)"); writeln(file,"\t$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)");
} else } else
writeln(file,"\t$(CC) $(LINKOBJ) -o \"$(BIN)\" $(LIBS)"); writeln(file,"\t$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)");
} }
writeMakeObjFilesRules(file); writeMakeObjFilesRules(file);
} }
@ -64,9 +64,9 @@ void ProjectCompiler::createDynamicMakeFile()
file.write("$(BIN): $(LINKOBJ)"); file.write("$(BIN): $(LINKOBJ)");
if (!mOnlyCheckSyntax) { if (!mOnlyCheckSyntax) {
if (mProject->options().useGPP) { 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 { } 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); writeMakeObjFilesRules(file);

View File

@ -116,6 +116,7 @@ MainWindow::MainWindow(QWidget *parent)
mCPUDialog = nullptr; mCPUDialog = nullptr;
updateProjectView();
updateEditorActions(); updateEditorActions();
updateCaretActions(); updateCaretActions();
applySettings(); applySettings();
@ -202,26 +203,11 @@ void MainWindow::updateEditorActions()
ui->actionRedo->setEnabled(false); ui->actionRedo->setEnabled(false);
ui->actionSave->setEnabled(false); ui->actionSave->setEnabled(false);
ui->actionSaveAs->setEnabled(false); ui->actionSaveAs->setEnabled(false);
ui->actionSaveAll->setEnabled(false);
ui->actionSelectAll->setEnabled(false); ui->actionSelectAll->setEnabled(false);
ui->actionToggleComment->setEnabled(false); ui->actionToggleComment->setEnabled(false);
ui->actionUnIndent->setEnabled(false); ui->actionUnIndent->setEnabled(false);
ui->actionUndo->setEnabled(false); ui->actionUndo->setEnabled(false);
ui->actionUnfoldAll->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->actionFind->setEnabled(false);
ui->actionReplace->setEnabled(false); ui->actionReplace->setEnabled(false);
ui->actionFind_Next->setEnabled(false); ui->actionFind_Next->setEnabled(false);
@ -249,7 +235,6 @@ void MainWindow::updateEditorActions()
ui->actionUndo->setEnabled(e->canUndo()); ui->actionUndo->setEnabled(e->canUndo());
ui->actionSave->setEnabled(e->modified()); ui->actionSave->setEnabled(e->modified());
ui->actionSaveAs->setEnabled(true); ui->actionSaveAs->setEnabled(true);
ui->actionSaveAll->setEnabled(true);
ui->actionSelectAll->setEnabled(e->lines()->count()>0); ui->actionSelectAll->setEnabled(e->lines()->count()>0);
ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0); ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0);
ui->actionUnIndent->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->setEnabled(true);
ui->actionClose_All->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() void MainWindow::updateCompileActions()
{ {
bool hasProject = (mProject!=nullptr);
bool editorCanCompile = false;
Editor * e = mEditorList->getEditor(); Editor * e = mEditorList->getEditor();
if (!e) if (e) {
return;
FileType fileType = getFileType(e->filename()); FileType fileType = getFileType(e->filename());
if (fileType == FileType::CSource
|| fileType == FileType::CppSource)
editorCanCompile = true;
}
if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing() if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing()
|| (fileType!= FileType::CSource || (!hasProject && !editorCanCompile) ) {
&& fileType != FileType::CppSource) ) {
ui->actionCompile->setEnabled(false); ui->actionCompile->setEnabled(false);
ui->actionCompile_Run->setEnabled(false); ui->actionCompile_Run->setEnabled(false);
ui->actionRun->setEnabled(false); ui->actionRun->setEnabled(false);
@ -293,12 +290,18 @@ void MainWindow::updateCompileActions()
ui->actionDebug->setEnabled(true); ui->actionDebug->setEnabled(true);
} }
ui->actionStep_Into->setEnabled(mDebugger->executing()); ui->actionStep_Into->setEnabled(mDebugger->executing());
ui->actionStep_Out->setEnabled(mDebugger->executing()); ui->actionStep_Out->setEnabled(mDebugger->executing());
ui->actionStep_Over->setEnabled(mDebugger->executing()); ui->actionStep_Over->setEnabled(mDebugger->executing());
ui->actionContinue->setEnabled(mDebugger->executing()); ui->actionContinue->setEnabled(mDebugger->executing());
ui->actionRun_To_Cursor->setEnabled(mDebugger->executing()); ui->actionRun_To_Cursor->setEnabled(mDebugger->executing());
ui->actionStop_Execution->setEnabled(mCompilerManager->running() || 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() void MainWindow::updateEditorColorSchemes()
@ -675,7 +678,7 @@ void MainWindow::openProject(const QString &filename)
mClassBrowserModel.endUpdate(); mClassBrowserModel.endUpdate();
}); });
mProject = std::make_shared<Project>(filename,DEV_INTERNAL_OPEN); mProject = std::make_shared<Project>(filename,DEV_INTERNAL_OPEN);
ui->projectView->setModel(mProject->model()); updateProjectView();
pSettings->history().removeProject(filename); pSettings->history().removeProject(filename);
// // if project manager isn't open then open it // // if project manager isn't open then open it
@ -1676,15 +1679,26 @@ void MainWindow::closeProject(bool refreshEditor)
} }
} }
if (!mQuitting) { if (!mQuitting) {
// Clear project browser
ui->projectView->setModel(nullptr);
// Clear error browser // Clear error browser
ui->tableIssues->clearIssues(); ui->tableIssues->clearIssues();
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); ui->tabProject->setVisible(false);
} }
} updateProjectActions();
} }
void MainWindow::onFileChanged(const QString &path) void MainWindow::onFileChanged(const QString &path)
@ -2958,10 +2972,13 @@ void MainWindow::on_actionNew_Project_triggered()
QMessageBox::Ok); QMessageBox::Ok);
} }
mProject->saveAll(); mProject->saveAll();
ui->projectView->setModel(mProject->model()); updateProjectView();
openCloseLeftPanel(true);
ui->tabProject->setVisible(true);
ui->tabInfos->setCurrentWidget(ui->tabProject);
} }
} }
void MainWindow::on_actionSaveAll_triggered()
{
}

View File

@ -58,6 +58,7 @@ public:
void updateStatusbarMessage(const QString& s); void updateStatusbarMessage(const QString& s);
void updateEditorSettings(); void updateEditorSettings();
void updateEditorActions(); void updateEditorActions();
void updateProjectActions();
void updateCompileActions(); void updateCompileActions();
void updateEditorColorSchemes(); void updateEditorColorSchemes();
void updateCompilerSet(); void updateCompilerSet();
@ -125,6 +126,7 @@ public slots:
private: private:
void closeProject(bool refreshEditor); void closeProject(bool refreshEditor);
void updateProjectView();
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); void openProject(const QString& filename);
@ -310,6 +312,8 @@ private slots:
void on_actionNew_Project_triggered(); void on_actionNew_Project_triggered();
void on_actionSaveAll_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -873,6 +873,13 @@
<property name="title"> <property name="title">
<string>Project</string> <string>Project</string>
</property> </property>
<addaction name="actionNew_File"/>
<addaction name="actionAdd_to_project"/>
<addaction name="actionRemove_from_project"/>
<addaction name="separator"/>
<addaction name="actionView_Makefile"/>
<addaction name="actionMakeClean"/>
<addaction name="separator"/>
<addaction name="actionProject_options"/> <addaction name="actionProject_options"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
@ -991,10 +998,10 @@
</iconset> </iconset>
</property> </property>
<property name="text"> <property name="text">
<string>New File</string> <string>New Source File</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>New File</string> <string>New Source File</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+N</string> <string>Ctrl+N</string>
@ -1633,6 +1640,47 @@
<string>New Project...</string> <string>New Project...</string>
</property> </property>
</action> </action>
<action name="actionNew_File">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/050-newsrc.png</normaloff>:/icons/images/newlook24/050-newsrc.png</iconset>
</property>
<property name="text">
<string>New File</string>
</property>
</action>
<action name="actionAdd_to_project">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/004-addsrc.png</normaloff>:/icons/images/newlook24/004-addsrc.png</iconset>
</property>
<property name="text">
<string>Add to project...</string>
</property>
</action>
<action name="actionRemove_from_project">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/064-remsrc.png</normaloff>:/icons/images/newlook24/064-remsrc.png</iconset>
</property>
<property name="text">
<string>Remove from project</string>
</property>
</action>
<action name="actionView_Makefile">
<property name="text">
<string>View Makefile</string>
</property>
</action>
<action name="actionMakeClean">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/011-clrhist.png</normaloff>:/icons/images/newlook24/011-clrhist.png</iconset>
</property>
<property name="text">
<string>Clean</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -8,6 +8,7 @@
#include "utils.h" #include "utils.h"
#include "platform.h" #include "platform.h"
#include "projecttemplate.h" #include "projecttemplate.h"
#include "systemconsts.h"
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
@ -251,6 +252,7 @@ PProjectUnit Project::newUnit(PFolderNode parentNode, const QString& customFileN
newUnit->setOverrideBuildCmd(false); newUnit->setOverrideBuildCmd(false);
newUnit->setBuildCmd(""); newUnit->setBuildCmd("");
newUnit->setModified(true); newUnit->setModified(true);
newUnit->setEncoding(toByteArray(options().encoding));
return newUnit; return newUnit;
} }
@ -583,12 +585,13 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate)
} }
mOptions = aTemplate->options(); mOptions = aTemplate->options();
mOptions.icon = aTemplate->icon();
// Copy icon to project directory // Copy icon to project directory
if (!mOptions.icon.isEmpty()) { if (!mOptions.icon.isEmpty()) {
QString originIcon = QDir(pSettings->dirs().templateDir()).absoluteFilePath(mOptions.icon); QString originIcon = QDir(pSettings->dirs().templateDir()).absoluteFilePath(mOptions.icon);
if (fileExists(originIcon)) { if (fileExists(originIcon)) {
QString destIcon = changeFileExt(mFilename,".ico"); QString destIcon = changeFileExt(mFilename,ICON_EXT);
QFile::copy(originIcon,destIcon); QFile::copy(originIcon,destIcon);
mOptions.icon = destIcon; mOptions.icon = destIcon;
} else { } else {
@ -1255,7 +1258,12 @@ void Project::loadLayout()
void Project::loadOptions(SimpleIni& ini) void Project::loadOptions(SimpleIni& ini)
{ {
mName = fromByteArray(ini.GetValue("Project","name", "")); 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); mOptions.version = ini.GetLongValue("Project", "Ver", 0);
if (mOptions.version > 0) { // ver > 0 is at least a v5 project if (mOptions.version > 0) { // ver > 0 is at least a v5 project
if (mOptions.version < 2) { if (mOptions.version < 2) {

View File

@ -26,6 +26,7 @@
#define DEF_EXT "def" #define DEF_EXT "def"
#define LIB_EXT "a" #define LIB_EXT "a"
#define GCH_EXT "gch" #define GCH_EXT "gch"
#define ICON_EXT "ico"
#define TEMPLATE_EXT "template" #define TEMPLATE_EXT "template"
#define DEV_INTERNAL_OPEN "$__DEV_INTERNAL_OPEN" #define DEV_INTERNAL_OPEN "$__DEV_INTERNAL_OPEN"

View File

@ -456,12 +456,14 @@ int compareFileModifiedTime(const QString &filename1, const QString &filename2)
return 0; return 0;
} }
QString changeFileExt(const QString& filename, const QString& ext) QString changeFileExt(const QString& filename, QString ext)
{ {
QFileInfo fileInfo(filename); QFileInfo fileInfo(filename);
QString suffix = fileInfo.suffix(); QString suffix = fileInfo.suffix();
QString name = fileInfo.fileName(); QString name = fileInfo.fileName();
QString path; QString path;
if (ext.startsWith("."))
ext.remove(0,1);
if (fileInfo.path() != ".") { if (fileInfo.path() != ".") {
path = includeTrailingPathDelimiter(fileInfo.path()); path = includeTrailingPathDelimiter(fileInfo.path());
} }

View File

@ -128,7 +128,7 @@ bool directoryExists(const QString& file);
QString includeTrailingPathDelimiter(const QString& path); QString includeTrailingPathDelimiter(const QString& path);
QString excludeTrailingPathDelimiter(const QString& path); QString excludeTrailingPathDelimiter(const QString& path);
FileType getFileType(const QString& filename); 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 extractRelativePath(const QString& base, const QString& dest);
QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes); QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes);
QString genMakePath1(const QString& fileName); QString genMakePath1(const QString& fileName);