From cd1efdc0ff54a318746a0784df858ee0f2ff7982 Mon Sep 17 00:00:00 2001 From: Dmitry Vedenko Date: Thu, 15 Jul 2021 19:13:38 +0300 Subject: [PATCH] Add new error dialog for unwritable directory. --- src/CMakeLists.txt | 2 + src/ProjectFileManager.cpp | 3 + src/widgets/UnwritableLocationErrorDialog.cpp | 102 ++++++++++++++++++ src/widgets/UnwritableLocationErrorDialog.h | 27 +++++ 4 files changed, 134 insertions(+) create mode 100644 src/widgets/UnwritableLocationErrorDialog.cpp create mode 100644 src/widgets/UnwritableLocationErrorDialog.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ac52cc89..ca60a742a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -961,6 +961,8 @@ list( APPEND SOURCES widgets/ReadOnlyText.h widgets/Ruler.cpp widgets/Ruler.h + widgets/UnwritableLocationErrorDialog.cpp + widgets/UnwritableLocationErrorDialog.h widgets/Warning.cpp widgets/Warning.h widgets/WindowAccessible.cpp diff --git a/src/ProjectFileManager.cpp b/src/ProjectFileManager.cpp index dc0aedd87..bc533c71b 100644 --- a/src/ProjectFileManager.cpp +++ b/src/ProjectFileManager.cpp @@ -44,9 +44,12 @@ Paul Licameli split from AudacityProject.cpp #include "widgets/AudacityMessageBox.h" #include "widgets/ErrorDialog.h" #include "widgets/FileHistory.h" +#include "widgets/UnwritableLocationErrorDialog.h" #include "widgets/Warning.h" #include "xml/XMLFileReader.h" +#include "HelpText.h" + static const AudacityProject::AttachedObjects::RegisteredFactory sFileManagerKey{ []( AudacityProject &parent ){ auto result = std::make_shared< ProjectFileManager >( parent ); diff --git a/src/widgets/UnwritableLocationErrorDialog.cpp b/src/widgets/UnwritableLocationErrorDialog.cpp new file mode 100644 index 000000000..4f014d502 --- /dev/null +++ b/src/widgets/UnwritableLocationErrorDialog.cpp @@ -0,0 +1,102 @@ +/********************************************************************** + + Audacity: A Digital Audio Editor + + UnwritableLocationError.h + + Dmitry Vedenko + +**********************************************************************/ + +#include "UnwritableLocationErrorDialog.h" + +#include "HelpSystem.h" +#include "ShuttleGui.h" + +#include "prefs/PrefsDialog.h" +#include "ui/AccessibleLinksFormatter.h" + +BEGIN_EVENT_TABLE(UnwritableLocationErrorDialog, wxDialogWrapper) + EVT_BUTTON(wxID_OK, UnwritableLocationErrorDialog::OnOk) + EVT_BUTTON(wxID_HELP, UnwritableLocationErrorDialog::OnError) +END_EVENT_TABLE() + +UnwritableLocationErrorDialog::UnwritableLocationErrorDialog(wxWindow* parent, const wxString& path) + : wxDialogWrapper( + parent, -1, XO("Error"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) +{ + ShuttleGui S(this, eIsCreating); + + S.SetBorder(8); + + S.StartVerticalLay(); + { + S.AddSpace(0, 12); + + S.StartHorizontalLay(); + { + S.AddSpace(12, 0); + + S.StartVerticalLay(); + { + S.AddFixedText( + /* i18n-hint: %s is replaced with a directory path. */ + XO("Unable to write files to directory: %s.").Format(path), + false, 500); + + S.AddFixedText( + /* i18n-hint: This message describes the error in the Error dialog. */ + XO("Please check that the directory exists, has the necessary permissions, and the drive isn't full."), + false, 0); + + S.AddSpace(0, 8); + + AccessibleLinksFormatter preferencesMessage( + /* i18n-hint: %s is replaced with 'Preferences > Directories'. */ + XO("You can change the directory in %s.")); + + preferencesMessage.FormatLink( + /* i18n-hint: Hyperlink title that opens Preferences dialog on Directories page. */ + wxT("%s"), XO("Preferences > Directories"), [parent, this]() { + EndModal(wxID_OK); + + GlobalPrefsDialog dialog(parent, nullptr); + + dialog.SelectPageByName(XO("Directories").Translation()); + dialog.ShowModal(); + }); + + + preferencesMessage.Populate(S); + } + S.EndVerticalLay(); + + S.AddSpace(12, 0); + } + S.EndHorizontalLay(); + + S.AddSpace(0, 12); + + S.AddStandardButtons(eHelpButton | eOkButton); + } + S.EndVerticalLay(); + + Layout(); + Fit(); + Center(); +} + +UnwritableLocationErrorDialog::~UnwritableLocationErrorDialog() +{ + +} + +void UnwritableLocationErrorDialog::OnOk(wxCommandEvent&) +{ + EndModal(wxID_OK); +} + +void UnwritableLocationErrorDialog::OnError(wxCommandEvent&) +{ + HelpSystem::ShowHelp(this, "Error:_Disk_full_or_not_writable", false); +} diff --git a/src/widgets/UnwritableLocationErrorDialog.h b/src/widgets/UnwritableLocationErrorDialog.h new file mode 100644 index 000000000..cf20b8c63 --- /dev/null +++ b/src/widgets/UnwritableLocationErrorDialog.h @@ -0,0 +1,27 @@ +/********************************************************************** + + Audacity: A Digital Audio Editor + + UnwritableLocationError.h + + Dmitry Vedenko + +**********************************************************************/ + +#pragma once + + +#include "widgets/wxPanelWrapper.h" + +/// An error dialog about unwritable location, that allows to navigate to settings quickly +class UnwritableLocationErrorDialog final : public wxDialogWrapper +{ +public: + explicit UnwritableLocationErrorDialog(wxWindow* parent, const wxString& path); + virtual ~UnwritableLocationErrorDialog(); + + void OnOk(wxCommandEvent& event); + void OnError(wxCommandEvent& event); + + DECLARE_EVENT_TABLE() +};