work save
This commit is contained in:
parent
5ab9c16039
commit
b70144532e
|
@ -246,6 +246,15 @@ bool Editor::saveAs(){
|
|||
return false;
|
||||
}
|
||||
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);
|
||||
if (pSettings->codeCompletion().enabled() && mParser)
|
||||
mParser->invalidateFile(mFilename);
|
||||
|
@ -281,6 +290,9 @@ bool Editor::saveAs(){
|
|||
setUseCodeFolding(false);
|
||||
}
|
||||
setHighlighter(newHighlighter);
|
||||
if (!newHighlighter || newHighlighter->getName() != SYN_HIGHLIGHTER_CPP) {
|
||||
mSyntaxIssues.clear();
|
||||
}
|
||||
applyColorScheme(pSettings->editor().colorScheme());
|
||||
|
||||
reparse();
|
||||
|
|
|
@ -1690,6 +1690,7 @@ void MainWindow::updateProjectView()
|
|||
{
|
||||
if (mProject) {
|
||||
ui->projectView->setModel(mProject->model());
|
||||
ui->projectView->expandAll();
|
||||
openCloseLeftPanel(true);
|
||||
ui->tabProject->setVisible(true);
|
||||
ui->tabInfos->setCurrentWidget(ui->tabProject);
|
||||
|
@ -2979,6 +2980,70 @@ void MainWindow::on_actionNew_Project_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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -314,6 +314,10 @@ private slots:
|
|||
|
||||
void on_actionSaveAll_triggered();
|
||||
|
||||
void on_actionProject_New_File_triggered();
|
||||
|
||||
void on_actionAdd_to_project_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
EditorList *mEditorList;
|
||||
|
|
|
@ -873,7 +873,7 @@
|
|||
<property name="title">
|
||||
<string>Project</string>
|
||||
</property>
|
||||
<addaction name="actionNew_File"/>
|
||||
<addaction name="actionProject_New_File"/>
|
||||
<addaction name="actionAdd_to_project"/>
|
||||
<addaction name="actionRemove_from_project"/>
|
||||
<addaction name="separator"/>
|
||||
|
@ -1640,7 +1640,7 @@
|
|||
<string>New Project...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionNew_File">
|
||||
<action name="actionProject_New_File">
|
||||
<property name="icon">
|
||||
<iconset resource="icons.qrc">
|
||||
<normaloff>:/icons/images/newlook24/050-newsrc.png</normaloff>:/icons/images/newlook24/050-newsrc.png</iconset>
|
||||
|
|
|
@ -274,7 +274,7 @@ Editor *Project::openUnit(int index)
|
|||
}
|
||||
QByteArray encoding;
|
||||
encoding = unit->encoding();
|
||||
editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, false);
|
||||
editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, unit->isNew());
|
||||
editor->setInProject(true);
|
||||
unit->setEditor(editor);
|
||||
unit->setEncoding(encoding);
|
||||
|
@ -531,7 +531,7 @@ bool Project::saveUnits()
|
|||
case FileType::WindowsResourceSource:
|
||||
unit->setFolder("Resources");
|
||||
}
|
||||
|
||||
unit->setNew(false);
|
||||
ini.SetValue(groupName,"Folder", toByteArray(unit->folder()));
|
||||
ini.SetLongValue(groupName,"Compile", unit->compile());
|
||||
ini.SetLongValue(groupName,"Link", unit->link());
|
||||
|
@ -578,6 +578,15 @@ void Project::updateNodeIndexes()
|
|||
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)
|
||||
{
|
||||
if (!aTemplate) {
|
||||
|
|
|
@ -134,7 +134,7 @@ public:
|
|||
PFolderNode makeNewFileNode(const QString& s, bool isFolder, PFolderNode newParent);
|
||||
PFolderNode makeProjectNode();
|
||||
PProjectUnit newUnit(PFolderNode parentNode,
|
||||
const QString& customFileName);
|
||||
const QString& customFileName="");
|
||||
Editor* openUnit(int index);
|
||||
void rebuildNodes();
|
||||
bool removeEditor(int index, bool doClose);
|
||||
|
@ -151,6 +151,7 @@ public:
|
|||
void sortUnitsByAlpha();
|
||||
void updateFolders();
|
||||
void updateNodeIndexes();
|
||||
PFolderNode pointerToNode(FolderNode * p);
|
||||
|
||||
//void showOptions();
|
||||
bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate);
|
||||
|
|
Loading…
Reference in New Issue