work save: rename in file system view
This commit is contained in:
parent
dd1bb88733
commit
5e1becc2e4
|
@ -537,6 +537,77 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
|||
return true;
|
||||
}
|
||||
|
||||
void Editor::setFilename(const QString &newName)
|
||||
{
|
||||
if (mFilename == newName)
|
||||
return;
|
||||
if (pMainWindow->editorList()->getOpenedEditorByFilename(newName)) {
|
||||
return;
|
||||
}
|
||||
QString oldName = mFilename;
|
||||
// Update project information
|
||||
if (mProject) {
|
||||
PProjectUnit unit = mProject->findUnit(oldName);
|
||||
if (unit) {
|
||||
mProject->renameUnit(unit, newName);
|
||||
}
|
||||
}
|
||||
|
||||
clearSyntaxIssues();
|
||||
pMainWindow->fileSystemWatcher()->removePath(oldName);
|
||||
if (pSettings->codeCompletion().enabled() && mParser && !inProject()) {
|
||||
mParser->invalidateFile(oldName);
|
||||
}
|
||||
|
||||
mFilename = newName;
|
||||
if (mProject) {
|
||||
mProject->associateEditor(this);
|
||||
}
|
||||
pMainWindow->fileSystemWatcher()->addPath(mFilename);
|
||||
switch(getFileType(mFilename)) {
|
||||
case FileType::CppSource:
|
||||
mUseCppSyntax = true;
|
||||
break;
|
||||
case FileType::CSource:
|
||||
mUseCppSyntax = false;
|
||||
break;
|
||||
default:
|
||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||
}
|
||||
|
||||
//update (reassign syntaxer)
|
||||
QSynedit::PSyntaxer newSyntaxer = syntaxerManager.getSyntaxer(mFilename);
|
||||
if (newSyntaxer) {
|
||||
setUseCodeFolding(true);
|
||||
setFormatter(syntaxerManager.getFormatter(newSyntaxer->language()));
|
||||
} else {
|
||||
setUseCodeFolding(false);
|
||||
setFormatter(syntaxerManager.getFormatter(QSynedit::ProgrammingLanguage::Unknown));
|
||||
}
|
||||
setSyntaxer(newSyntaxer);
|
||||
|
||||
if (!newSyntaxer || newSyntaxer->language() != QSynedit::ProgrammingLanguage::CPP) {
|
||||
mSyntaxIssues.clear();
|
||||
}
|
||||
applyColorScheme(pSettings->editor().colorScheme());
|
||||
|
||||
if (!inProject()) {
|
||||
initParser();
|
||||
reparse(false);
|
||||
reparseTodo();
|
||||
}
|
||||
|
||||
if (pSettings->editor().syntaxCheckWhenSave())
|
||||
checkSyntaxInBack();
|
||||
|
||||
updateCaption();
|
||||
|
||||
emit renamed(oldName, newName , true);
|
||||
|
||||
initAutoBackup();
|
||||
return;
|
||||
}
|
||||
|
||||
void Editor::activate()
|
||||
{
|
||||
if (mParentPageControl)
|
||||
|
|
|
@ -149,6 +149,7 @@ public:
|
|||
void saveFile(QString filename);
|
||||
bool save(bool force=false, bool reparse=true);
|
||||
bool saveAs(const QString& name="", bool fromProject = false);
|
||||
void setFilename(const QString& newName);
|
||||
void activate();
|
||||
|
||||
QTabWidget* pageControl() noexcept;
|
||||
|
|
|
@ -399,6 +399,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
delete m;
|
||||
connect(&mFileSystemModel, &QFileSystemModel::layoutChanged,
|
||||
this, &MainWindow::onFileSystemModelLayoutChanged, Qt::QueuedConnection);
|
||||
connect(&mFileSystemModel, &QFileSystemModel::fileRenamed,
|
||||
this, &MainWindow::onFileSystemModelLayoutChanged, Qt::QueuedConnection);
|
||||
connect(&mFileSystemModel, &QFileSystemModel::fileRenamed,
|
||||
this, &MainWindow::onFileRenamedInFileSystemModel);
|
||||
mFileSystemModel.setReadOnly(false);
|
||||
mFileSystemModel.setIconProvider(&mFileSystemModelIconProvider);
|
||||
|
||||
|
@ -5616,6 +5620,18 @@ void MainWindow::onFileSystemModelLayoutChanged()
|
|||
ui->treeFiles->scrollTo(ui->treeFiles->currentIndex(),QTreeView::PositionAtCenter);
|
||||
}
|
||||
|
||||
void MainWindow::onFileRenamedInFileSystemModel(const QString &path, const QString &oldName, const QString &newName)
|
||||
{
|
||||
QDir folder(path);
|
||||
QString oldFile = folder.absoluteFilePath(oldName);
|
||||
QString newFile = folder.absoluteFilePath(newName);
|
||||
|
||||
Editor *e = mEditorList->getOpenedEditorByFilename(path);
|
||||
if (e) {
|
||||
e->setFilename(newFile);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionOpen_triggered()
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -433,6 +433,7 @@ private slots:
|
|||
void on_EditorTabsRight_tabCloseRequested(int index);
|
||||
|
||||
void onFileSystemModelLayoutChanged();
|
||||
void onFileRenamedInFileSystemModel(const QString &path, const QString &oldName, const QString &newName);
|
||||
|
||||
void on_actionOpen_triggered();
|
||||
|
||||
|
|
Loading…
Reference in New Issue