mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-30 23:23:44 +02:00
Add BasicUI::MakeGenericProgress, for when the denominator is unknown
This commit is contained in:
parent
0555c1139d
commit
333aa10624
@ -19,6 +19,8 @@ Services::~Services() = default;
|
||||
|
||||
ProgressDialog::~ProgressDialog() = default;
|
||||
|
||||
GenericProgressDialog::~GenericProgressDialog() = default;
|
||||
|
||||
static Services *theInstance = nullptr;
|
||||
|
||||
Services *Get() { return theInstance; }
|
||||
|
@ -162,6 +162,15 @@ public:
|
||||
const TranslatableString &message = {}) = 0;
|
||||
};
|
||||
|
||||
//! Abstraction of a progress dialog with undefined time-to-completion estimate
|
||||
class BASIC_UI_API GenericProgressDialog
|
||||
{
|
||||
public:
|
||||
virtual ~GenericProgressDialog();
|
||||
//! Give some visual indication of progress. Call only on the main thread.
|
||||
virtual void Pulse() = 0;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
//! Abstract class defines a few user interface services, not mentioning particular toolkits
|
||||
@ -186,6 +195,10 @@ public:
|
||||
const TranslatableString &message,
|
||||
unsigned flag,
|
||||
const TranslatableString &remainingLabelText) = 0;
|
||||
virtual std::unique_ptr<GenericProgressDialog>
|
||||
DoMakeGenericProgress(const WindowPlacement &placement,
|
||||
const TranslatableString &title,
|
||||
const TranslatableString &message) = 0;
|
||||
};
|
||||
|
||||
//! Fetch the global instance, or nullptr if none is yet installed
|
||||
@ -259,6 +272,22 @@ inline std::unique_ptr<ProgressDialog> MakeProgress(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//! Create and display a progress dialog (return nullptr if Services not installed)
|
||||
/*!
|
||||
This function makes a "generic" progress dialog, for the case when time
|
||||
to completion cannot be estimated, but some indication of progress is still
|
||||
given
|
||||
*/
|
||||
inline std::unique_ptr<GenericProgressDialog> MakeGenericProgress(
|
||||
const WindowPlacement &placement,
|
||||
const TranslatableString &title, const TranslatableString &message)
|
||||
{
|
||||
if (auto p = Get())
|
||||
return p->DoMakeGenericProgress(placement, title, message);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//! @}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ Paul Licameli
|
||||
#include "widgets/AudacityMessageBox.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include <wx/app.h>
|
||||
#include <wx/progdlg.h>
|
||||
#include <wx/windowptr.h>
|
||||
|
||||
using namespace BasicUI;
|
||||
@ -204,3 +205,32 @@ wxWidgetsBasicUI::DoMakeProgress(const TranslatableString & title,
|
||||
safenew ::ProgressDialog(
|
||||
title, message, options, remainingLabelText));
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct MyGenericProgress : GenericProgressDialog {
|
||||
wxWindowPtr<wxGenericProgressDialog> mpDialog;
|
||||
|
||||
MyGenericProgress(const TranslatableString &title,
|
||||
const TranslatableString &message,
|
||||
wxWindow *parent = nullptr)
|
||||
: mpDialog{ safenew wxGenericProgressDialog(
|
||||
title.Translation(), message.Translation(),
|
||||
300000, // range
|
||||
parent,
|
||||
wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_SMOOTH
|
||||
) }
|
||||
{}
|
||||
~MyGenericProgress() override = default;
|
||||
void Pulse() override { mpDialog->Pulse(); }
|
||||
};
|
||||
}
|
||||
|
||||
std::unique_ptr<GenericProgressDialog>
|
||||
wxWidgetsBasicUI::DoMakeGenericProgress(
|
||||
const BasicUI::WindowPlacement &placement,
|
||||
const TranslatableString &title,
|
||||
const TranslatableString &message)
|
||||
{
|
||||
return std::make_unique<MyGenericProgress>(
|
||||
title, message, GetParent(placement));
|
||||
}
|
||||
|
@ -49,6 +49,10 @@ protected:
|
||||
const TranslatableString &message,
|
||||
unsigned flags,
|
||||
const TranslatableString &remainingLabelText) override;
|
||||
std::unique_ptr<BasicUI::GenericProgressDialog>
|
||||
DoMakeGenericProgress(const BasicUI::WindowPlacement &placement,
|
||||
const TranslatableString &title,
|
||||
const TranslatableString &message) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user