Common: Add title, modal information to ProgressCallback

This commit is contained in:
Connor McLaughlin
2020-08-06 19:32:53 +10:00
parent 8c1a72f640
commit 6e586311e8
6 changed files with 65 additions and 48 deletions

View File

@ -93,6 +93,18 @@ bool ProgressCallback::DisplayFormattedModalConfirmation(const char* format, ...
return ModalConfirmation(str);
}
void ProgressCallback::DisplayFormattedModalInformation(const char* format, ...)
{
SmallString str;
va_list ap;
va_start(ap, format);
str.FormatVA(format, ap);
va_end(ap);
ModalInformation(str);
}
void ProgressCallback::UpdateProgressFromStream(ByteStream* pStream)
{
u32 streamSize = (u32)pStream->GetSize();
@ -112,6 +124,7 @@ public:
bool IsCancellable() const override { return false; }
void SetCancellable(bool cancellable) override {}
void SetTitle(const char* title) override {}
void SetStatusText(const char* statusText) override {}
void SetProgressRange(u32 range) override {}
void SetProgressValue(u32 value) override {}
@ -128,12 +141,7 @@ public:
Log_InfoPrint(message);
return false;
}
u32 ModalPrompt(const char* message, u32 nOptions, ...) override
{
DebugAssert(nOptions > 0);
Log_InfoPrint(message);
return 0;
}
void ModalInformation(const char* message) override { Log_InfoPrint(message); }
};
static NullProgressCallbacks s_nullProgressCallbacks;
@ -264,6 +272,13 @@ void ConsoleProgressCallback::SetCancellable(bool cancellable)
Redraw(false);
}
void ConsoleProgressCallback::SetTitle(const char* title)
{
Clear();
std::fprintf(stdout, "== %s ==\n", title);
Redraw(false);
}
void ConsoleProgressCallback::SetStatusText(const char* text)
{
BaseProgressCallback::SetStatusText(text);
@ -387,11 +402,9 @@ bool ConsoleProgressCallback::ModalConfirmation(const char* message)
return false;
}
u32 ConsoleProgressCallback::ModalPrompt(const char* message, u32 num_options, ...)
void ConsoleProgressCallback::ModalInformation(const char* message)
{
Clear();
DebugAssert(num_options > 0);
Log_InfoPrint(message);
Redraw(false);
return 0;
}

View File

@ -17,6 +17,7 @@ public:
virtual void SetCancellable(bool cancellable) = 0;
virtual void SetTitle(const char* title) = 0;
virtual void SetStatusText(const char* text) = 0;
virtual void SetProgressRange(u32 range) = 0;
virtual void SetProgressValue(u32 value) = 0;
@ -31,7 +32,7 @@ public:
virtual void ModalError(const char* message) = 0;
virtual bool ModalConfirmation(const char* message) = 0;
virtual u32 ModalPrompt(const char* message, u32 num_options, ...) = 0;
virtual void ModalInformation(const char* message) = 0;
void DisplayFormattedError(const char* format, ...);
void DisplayFormattedWarning(const char* format, ...);
@ -39,6 +40,7 @@ public:
void DisplayFormattedDebugMessage(const char* format, ...);
void DisplayFormattedModalError(const char* format, ...);
bool DisplayFormattedModalConfirmation(const char* format, ...);
void DisplayFormattedModalInformation(const char* format, ...);
void UpdateProgressFromStream(ByteStream* stream);
@ -86,7 +88,7 @@ protected:
State* m_saved_state;
};
class ConsoleProgressCallback : public BaseProgressCallback
class ConsoleProgressCallback final : public BaseProgressCallback
{
public:
static const u32 COLUMNS = 78;
@ -95,22 +97,23 @@ public:
ConsoleProgressCallback();
~ConsoleProgressCallback();
virtual void PushState() override;
virtual void PopState() override;
void PushState() override;
void PopState() override;
virtual void SetCancellable(bool cancellable) override;
virtual void SetStatusText(const char* text) override;
virtual void SetProgressRange(u32 range) override;
virtual void SetProgressValue(u32 value) override;
void SetCancellable(bool cancellable) override;
void SetTitle(const char* title) override;
void SetStatusText(const char* text) override;
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) override;
virtual void DisplayError(const char* message) override;
virtual void DisplayWarning(const char* message) override;
virtual void DisplayInformation(const char* message) override;
virtual void DisplayDebugMessage(const char* message) override;
void DisplayError(const char* message) override;
void DisplayWarning(const char* message) override;
void DisplayInformation(const char* message) override;
void DisplayDebugMessage(const char* message) override;
virtual void ModalError(const char* message) override;
virtual bool ModalConfirmation(const char* message) override;
virtual u32 ModalPrompt(const char* message, u32 num_options, ...) override;
void ModalError(const char* message) override;
bool ModalConfirmation(const char* message) override;
void ModalInformation(const char* message) override;
private:
void Clear();