Skip to content

Commit

Permalink
Set editor as read-only if file is not writable
Browse files Browse the repository at this point in the history
Closes #202
  • Loading branch information
dail8859 committed Sep 24, 2022
1 parent d5d016b commit 66a32e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/NotepadNext/DockedEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,16 @@ void DockedEditor::addEditor(ScintillaNext *editor)
}

// Set the icon
dockWidget->tabWidget()->setIcon(QIcon(":/icons/saved.png"));
connect(editor, &ScintillaNext::savePointChanged, dockWidget, [=](bool dirty) {
const QString iconPath = dirty ? ":/icons/unsaved.png" : ":/icons/saved.png";
dockWidget->tabWidget()->setIcon(QIcon(iconPath));
});
if (editor->readOnly()) {
dockWidget->tabWidget()->setIcon(QIcon(":/icons/readonly.png"));
}
else {
dockWidget->tabWidget()->setIcon(QIcon(":/icons/saved.png"));
connect(editor, &ScintillaNext::savePointChanged, dockWidget, [=](bool dirty) {
const QString iconPath = dirty ? ":/icons/unsaved.png" : ":/icons/saved.png";
dockWidget->tabWidget()->setIcon(QIcon(iconPath));
});
}

connect(editor, &ScintillaNext::closed, dockWidget, &ads::CDockWidget::closeDockWidget);
connect(editor, &ScintillaNext::renamed, this, [=]() { editorRenamed(editor); });
Expand Down
5 changes: 5 additions & 0 deletions src/NotepadNext/ScintillaNext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ bool ScintillaNext::readFromDisk(QFile &file)
return false;
}

if (!QFileInfo(file).isWritable()) {
qInfo("Setting file as read-only");
setReadOnly(true);
}

return true;
}

Expand Down

0 comments on commit 66a32e9

Please sign in to comment.