work save

This commit is contained in:
royqh1979@gmail.com 2021-09-17 13:35:50 +08:00
parent 5ab9c16039
commit b70144532e
6 changed files with 96 additions and 5 deletions

View File

@ -246,6 +246,15 @@ bool Editor::saveAs(){
return false; return false;
} }
QString newName = dialog.selectedFiles()[0]; QString newName = dialog.selectedFiles()[0];
// Update project information
if (mInProject && pMainWindow->project()) {
int unitIndex = pMainWindow->project()->indexInUnits(mFilename);
if (unitIndex>=0) {
pMainWindow->project()->saveUnitAs(unitIndex,newName);
}
}
pMainWindow->fileSystemWatcher()->removePath(mFilename); pMainWindow->fileSystemWatcher()->removePath(mFilename);
if (pSettings->codeCompletion().enabled() && mParser) if (pSettings->codeCompletion().enabled() && mParser)
mParser->invalidateFile(mFilename); mParser->invalidateFile(mFilename);
@ -281,6 +290,9 @@ bool Editor::saveAs(){
setUseCodeFolding(false); setUseCodeFolding(false);
} }
setHighlighter(newHighlighter); setHighlighter(newHighlighter);
if (!newHighlighter || newHighlighter->getName() != SYN_HIGHLIGHTER_CPP) {
mSyntaxIssues.clear();
}
applyColorScheme(pSettings->editor().colorScheme()); applyColorScheme(pSettings->editor().colorScheme());
reparse(); reparse();

View File

@ -1690,6 +1690,7 @@ void MainWindow::updateProjectView()
{ {
if (mProject) { if (mProject) {
ui->projectView->setModel(mProject->model()); ui->projectView->setModel(mProject->model());
ui->projectView->expandAll();
openCloseLeftPanel(true); openCloseLeftPanel(true);
ui->tabProject->setVisible(true); ui->tabProject->setVisible(true);
ui->tabInfos->setCurrentWidget(ui->tabProject); ui->tabInfos->setCurrentWidget(ui->tabProject);
@ -2979,6 +2980,70 @@ void MainWindow::on_actionNew_Project_triggered()
void MainWindow::on_actionSaveAll_triggered() void MainWindow::on_actionSaveAll_triggered()
{ {
// Pause the change notifier
bool oldBlock = mFileSystemWatcher.blockSignals(true);
auto action = finally([oldBlock,this] {
mFileSystemWatcher.blockSignals(oldBlock);
});
if (mProject) {
mProject->saveAll();
}
// Make changes to files
for (int i=0;i<mEditorList->pageCount();i++) {
Editor * e= (*mEditorList)[i];
if (e->modified() && !e->inProject()) {
if (!e->save())
break;
}
}
updateAppTitle();
}
void MainWindow::on_actionProject_New_File_triggered()
{
int idx = -1;
if (!mProject)
return;
QModelIndex current = ui->projectView->currentIndex();
FolderNode * node = nullptr;
if (current.isValid()) {
node = static_cast<FolderNode*>(current.internalPointer());
}
PProjectUnit newUnit = mProject->newUnit(
mProject->pointerToNode(node) );
idx = mProject->units().count()-1;
updateProjectView();
Editor * editor = mProject->openUnit(idx);
editor->setModified(true);
editor->activate();
}
void MainWindow::on_actionAdd_to_project_triggered()
{
if (!mProject)
return;
QFileDialog dialog(this,tr("Add to project"),
mProject->directory(),
pSystemConsts->defaultFileFilters().join(";;"));
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setOption(QFileDialog::DontConfirmOverwrite,true);
if (dialog.exec()) {
QModelIndex current = ui->projectView->currentIndex();
FolderNode * node = nullptr;
if (current.isValid()) {
node = static_cast<FolderNode*>(current.internalPointer());
}
PFolderNode folderNode = mProject->pointerToNode(node);
foreach (const QString& filename, dialog.selectedFiles()) {
mProject->addUnit(filename,folderNode,false);
mProject->cppParser()->addFileToScan(filename);
}
mProject->rebuildNodes();
parseFileList(mProject->cppParser());
updateProjectView();
}
} }

View File

@ -314,6 +314,10 @@ private slots:
void on_actionSaveAll_triggered(); void on_actionSaveAll_triggered();
void on_actionProject_New_File_triggered();
void on_actionAdd_to_project_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -873,7 +873,7 @@
<property name="title"> <property name="title">
<string>Project</string> <string>Project</string>
</property> </property>
<addaction name="actionNew_File"/> <addaction name="actionProject_New_File"/>
<addaction name="actionAdd_to_project"/> <addaction name="actionAdd_to_project"/>
<addaction name="actionRemove_from_project"/> <addaction name="actionRemove_from_project"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -1640,7 +1640,7 @@
<string>New Project...</string> <string>New Project...</string>
</property> </property>
</action> </action>
<action name="actionNew_File"> <action name="actionProject_New_File">
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/050-newsrc.png</normaloff>:/icons/images/newlook24/050-newsrc.png</iconset> <normaloff>:/icons/images/newlook24/050-newsrc.png</normaloff>:/icons/images/newlook24/050-newsrc.png</iconset>

View File

@ -274,7 +274,7 @@ Editor *Project::openUnit(int index)
} }
QByteArray encoding; QByteArray encoding;
encoding = unit->encoding(); encoding = unit->encoding();
editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, false); editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, unit->isNew());
editor->setInProject(true); editor->setInProject(true);
unit->setEditor(editor); unit->setEditor(editor);
unit->setEncoding(encoding); unit->setEncoding(encoding);
@ -531,7 +531,7 @@ bool Project::saveUnits()
case FileType::WindowsResourceSource: case FileType::WindowsResourceSource:
unit->setFolder("Resources"); unit->setFolder("Resources");
} }
unit->setNew(false);
ini.SetValue(groupName,"Folder", toByteArray(unit->folder())); ini.SetValue(groupName,"Folder", toByteArray(unit->folder()));
ini.SetLongValue(groupName,"Compile", unit->compile()); ini.SetLongValue(groupName,"Compile", unit->compile());
ini.SetLongValue(groupName,"Link", unit->link()); ini.SetLongValue(groupName,"Link", unit->link());
@ -578,6 +578,15 @@ void Project::updateNodeIndexes()
mUnits[idx]->node()->unitIndex = idx; mUnits[idx]->node()->unitIndex = idx;
} }
PFolderNode Project::pointerToNode(FolderNode *p)
{
foreach (const PFolderNode& node , mFolderNodes) {
if (node.get()==p)
return node;
}
return PFolderNode();
}
bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate) bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate)
{ {
if (!aTemplate) { if (!aTemplate) {

View File

@ -134,7 +134,7 @@ public:
PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent); PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent);
PFolderNode makeProjectNode(); PFolderNode makeProjectNode();
PProjectUnit newUnit(PFolderNode parentNode, PProjectUnit newUnit(PFolderNode parentNode,
const QString& customFileName); const QString& customFileName="");
Editor* openUnit(int index); Editor* openUnit(int index);
void rebuildNodes(); void rebuildNodes();
bool removeEditor(int index, bool doClose); bool removeEditor(int index, bool doClose);
@ -151,6 +151,7 @@ public:
void sortUnitsByAlpha(); void sortUnitsByAlpha();
void updateFolders(); void updateFolders();
void updateNodeIndexes(); void updateNodeIndexes();
PFolderNode pointerToNode(FolderNode * p);
//void showOptions(); //void showOptions();
bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate); bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate);