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 "Settings.hxx"
#include "PopUpWidget.hxx" #include "PopUpWidget.hxx"
#include "StringListWidget.hxx" #include "StringListWidget.hxx"
#include "BrowserDialog.hxx"
#include "StringParser.hxx" #include "StringParser.hxx"
#include "Widget.hxx" #include "Widget.hxx"
#include "Font.hxx" #include "Font.hxx"
@ -39,7 +40,7 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
const int lineHeight = font.getLineHeight(), const int lineHeight = font.getLineHeight(),
fontWidth = font.getMaxCharWidth(), fontWidth = font.getMaxCharWidth(),
fontHeight = font.getFontHeight(), 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; buttonHeight = font.getLineHeight() * 1.25;
const int VBORDER = fontHeight / 2; const int VBORDER = fontHeight / 2;
const int HBORDER = fontWidth * 1.25; const int HBORDER = fontWidth * 1.25;
@ -80,7 +81,7 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
// Add Save, OK and Cancel buttons // Add Save, OK and Cancel buttons
ButtonWidget* b; ButtonWidget* b;
b = new ButtonWidget(this, font, HBORDER, _h - buttonHeight - VBORDER, b = new ButtonWidget(this, font, HBORDER, _h - buttonHeight - VBORDER,
buttonWidth, buttonHeight, "Save log to disk", buttonWidth, buttonHeight, "Save log to disk" + ELLIPSIS,
GuiObject::kDefaultsCmd); GuiObject::kDefaultsCmd);
wid.push_back(b); wid.push_back(b);
addOKCancelBGroup(wid, font); addOKCancelBGroup(wid, font);
@ -88,6 +89,22 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
addToFocusList(wid); 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() void LoggerDialog::loadConfig()
{ {
@ -116,19 +133,18 @@ void LoggerDialog::saveConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LoggerDialog::saveLogFile() void LoggerDialog::saveLogFile()
{ {
FilesystemNode node = instance().userDir(); FilesystemNode node(myBrowser->getResult().getShortPath());
node /= "stella.log";
try try
{ {
stringstream out; stringstream out;
out << Logger::instance().logMessages(); out << Logger::instance().logMessages();
instance().frameBuffer().showTextMessage("Saving log file to " + node.getShortPath());
node.write(out); node.write(out);
instance().frameBuffer().showTextMessage("System log saved");
} }
catch(...) 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; break;
case GuiObject::kDefaultsCmd: 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(); saveLogFile();
break; break;

View File

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