added missing changes in LoggerDialog

This commit is contained in:
thrust26 2020-12-26 10:32:00 +01:00
parent 13d3fcd52f
commit 0f04048ab9
2 changed files with 41 additions and 6 deletions

View File

@ -24,6 +24,7 @@
#include "Settings.hxx"
#include "PopUpWidget.hxx"
#include "StringListWidget.hxx"
#include "BrowserDialog.hxx"
#include "StringParser.hxx"
#include "Widget.hxx"
#include "Font.hxx"
@ -39,7 +40,7 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
const int lineHeight = font.getLineHeight(),
fontWidth = font.getMaxCharWidth(),
fontHeight = font.getFontHeight(),
buttonWidth = font.getStringWidth("Save log to disk") + fontWidth * 2.5,
buttonWidth = font.getStringWidth("Save log to disk" + ELLIPSIS) + fontWidth * 2.5,
buttonHeight = font.getLineHeight() * 1.25;
const int VBORDER = fontHeight / 2;
const int HBORDER = fontWidth * 1.25;
@ -80,7 +81,7 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
// Add Save, OK and Cancel buttons
ButtonWidget* b;
b = new ButtonWidget(this, font, HBORDER, _h - buttonHeight - VBORDER,
buttonWidth, buttonHeight, "Save log to disk",
buttonWidth, buttonHeight, "Save log to disk" + ELLIPSIS,
GuiObject::kDefaultsCmd);
wid.push_back(b);
addOKCancelBGroup(wid, font);
@ -88,6 +89,22 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
addToFocusList(wid);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LoggerDialog::createBrowser(const string& title)
{
uInt32 w = 0, h = 0;
getDynamicBounds(w, h);
if(w > uInt32(_font.getMaxCharWidth() * 80))
w = _font.getMaxCharWidth() * 80;
// Create file browser dialog
if(!myBrowser || uInt32(myBrowser->getWidth()) != w ||
uInt32(myBrowser->getHeight()) != h)
myBrowser = make_unique<BrowserDialog>(this, _font, w, h, title);
else
myBrowser->setTitle(title);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LoggerDialog::loadConfig()
{
@ -116,19 +133,18 @@ void LoggerDialog::saveConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LoggerDialog::saveLogFile()
{
FilesystemNode node = instance().userDir();
node /= "stella.log";
FilesystemNode node(myBrowser->getResult().getShortPath());
try
{
stringstream out;
out << Logger::instance().logMessages();
instance().frameBuffer().showTextMessage("Saving log file to " + node.getShortPath());
node.write(out);
instance().frameBuffer().showTextMessage("System log saved");
}
catch(...)
{
instance().frameBuffer().showTextMessage("Error saving log file to " + node.getShortPath());
instance().frameBuffer().showTextMessage("Error saving system log");
}
}
@ -144,6 +160,15 @@ void LoggerDialog::handleCommand(CommandSender* sender, int cmd,
break;
case GuiObject::kDefaultsCmd:
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
createBrowser("Save Log as");
myBrowser->show(instance().userDir().getPath() + "stella.log",
BrowserDialog::FileSave, kSaveCmd);
break;
case kSaveCmd:
saveLogFile();
break;

View File

@ -22,6 +22,7 @@ class GuiObject;
class CheckboxWidget;
class PopUpWidget;
class StringListWidget;
class BrowserDialog;
#include "Dialog.hxx"
#include "bspf.hxx"
@ -35,6 +36,8 @@ class LoggerDialog : public Dialog
~LoggerDialog() override = default;
private:
void createBrowser(const string& title);
void loadConfig() override;
void saveConfig() override;
void saveLogFile();
@ -46,6 +49,13 @@ class LoggerDialog : public Dialog
PopUpWidget* myLogLevel{nullptr};
CheckboxWidget* myLogToConsole{nullptr};
unique_ptr<BrowserDialog> myBrowser;
enum {
kSaveCmd = 'SvLg'
};
private:
// Following constructors and assignment operators not supported
LoggerDialog() = delete;