- 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");
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);

View File

@ -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<Project>(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;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);
}
}
Editor * e = mEditorList->getEditor();
//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) {
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()
{
}

View File

@ -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;

View File

@ -873,6 +873,13 @@
<property name="title">
<string>Project</string>
</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"/>
</widget>
<addaction name="menuFile"/>
@ -991,10 +998,10 @@
</iconset>
</property>
<property name="text">
<string>New File</string>
<string>New Source File</string>
</property>
<property name="toolTip">
<string>New File</string>
<string>New Source File</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
@ -1633,6 +1640,47 @@
<string>New Project...</string>
</property>
</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>
<customwidgets>
<customwidget>

View File

@ -8,6 +8,7 @@
#include "utils.h"
#include "platform.h"
#include "projecttemplate.h"
#include "systemconsts.h"
#include <QDir>
#include <QFileDialog>
@ -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<ProjectTemplate> 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) {

View File

@ -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"

View File

@ -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());
}

View File

@ -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);