Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 91027a65 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Enable the "save" option only if a real file is present on the disk

parent 4a6f4549
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Ce commit fait partie de la requête de fusion !18. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
......@@ -43,6 +43,7 @@ public:
signals:
void viewActionsChanged();
void documentPropertyChanged();
protected:
void deleteAllContent() noexcept;
......
......@@ -100,10 +100,11 @@ MainWindow::MainWindow() noexcept
loadSubDocumentVideoAct->setEnabled(false);
loadSubDocumentAudioAct->setEnabled(false);
// Enable actions if the document is save-able
auto enableSaveOnDocument = [this](auto *widget, int index) noexcept -> void {
// Enable "Save As" action
auto enableSaveAsOnDocument = [this](auto *widget, int index) noexcept -> void {
if (index >= 0) {
auto type = static_cast<AbstractDocumentView *>(documents->widget(index))->getType();
const auto doc = static_cast<AbstractDocumentView *>(documents->widget(index));
const auto type = doc->getType();
widget->setEnabled(type == AbstractDocumentView::Type::Vivy ||
type == AbstractDocumentView::Type::Script);
} else {
......@@ -111,6 +112,22 @@ MainWindow::MainWindow() noexcept
}
};
// Enable actions if the document is save-able
auto enableSaveOnDocument = [this](auto *widget, int index) noexcept -> void {
if (index >= 0) {
const auto doc = static_cast<AbstractDocumentView *>(documents->widget(index));
const auto type = doc->getType();
const bool isVivyMemoryDoc =
(type == AbstractDocumentView::Type::Vivy) &&
dynamic_cast<VivyDocument *>(doc->getDocument())
->checkDocumentOption(VivyDocument::MemoryDocumentCreation);
widget->setEnabled((!isVivyMemoryDoc) && (type == AbstractDocumentView::Type::Vivy ||
type == AbstractDocumentView::Type::Script));
} else {
widget->setEnabled(false);
}
};
// Enable load sub-document on sub-document able objects
auto enableLoadSubOnDocument = [this](auto *widget, int index) noexcept -> void {
if (index >= 0) {
......@@ -129,7 +146,7 @@ MainWindow::MainWindow() noexcept
[this](int) noexcept -> void { documentViewActionsChanged(); });
CONNECT_ENABLE(saveFileAct, enableSaveOnDocument);
CONNECT_ENABLE(saveFileAsAct, enableSaveOnDocument);
CONNECT_ENABLE(saveFileAsAct, enableSaveAsOnDocument);
CONNECT_ENABLE(loadSubDocumentAssAct, enableLoadSubOnDocument);
CONNECT_ENABLE(loadSubDocumentVideoAct, enableLoadSubOnDocument);
......@@ -188,7 +205,7 @@ void
MainWindow::saveFile() noexcept
{
try {
auto document = getCurrentDocument();
const auto document = getCurrentDocument();
qDebug() << "Request to save the document" << document->getName();
document->save();
} catch (const std::runtime_error &e) {
......@@ -200,16 +217,19 @@ void
MainWindow::saveFileAs() noexcept
{
try {
auto document = getCurrentDocument();
const auto docView = getCurrentDocumentView();
auto document = docView->getDocument();
qDebug() << "Request to save the document" << document->getName();
const QString filename =
dialogSaveFileName("Select the target file to save into", QDir::homePath(),
Utils::getVivyDocumentFileSuffixFilter());
if (filename.isEmpty()) {
qWarning() << "Found an empty filename, don't open a file";
} else {
document->rename(filename);
document->save();
emit docView->documentPropertyChanged();
}
} catch (const std::runtime_error &e) {
qCritical() << "Failed to save current document:" << e.what();
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter