Fixed ApplesoftFileViewer menu options

This commit is contained in:
Mark Long 2016-10-29 16:28:25 -05:00
parent 9ae934808c
commit c6d4020310
3 changed files with 97 additions and 35 deletions

View File

@ -16,13 +16,12 @@ public:
enum FormatOption { enum FormatOption {
NoOptions = 0x00, NoOptions = 0x00,
FormatHTML = 0x01, SyntaxHighlighting = 0x01,
ShowCtrlChars = 0x02, ShowCtrlChars = 0x02,
BreakAfterReturn = 0x04, BreakAfterReturn = 0x04,
PrettyFlags = ShowCtrlChars | BreakAfterReturn | FormatHTML,
ReindentCode = 0x08, ReindentCode = 0x08,
ShowIntsAsHex = 0x10, ShowIntsAsHex = 0x10,
AllFlags = 0xffffffff AllFlags = 0xffffffff
}; };

View File

@ -20,17 +20,25 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
setWindowTitle(title); setWindowTitle(title);
m_formatter = new ApplesoftFormatter(this); m_formatter = new ApplesoftFormatter(this);
m_formatter->setFlags(ApplesoftFormatter::PrettyFlags); m_formatter->setFlags(ApplesoftFormatter::NoOptions);
connect(ui->findButton,SIGNAL(clicked(bool)), SLOT(findText())); connect(ui->findButton,SIGNAL(clicked(bool)), SLOT(findText()));
m_isFirstFind = true; m_isFirstFind = true;
ui->textArea->setUndoRedoEnabled(false); ui->textArea->setUndoRedoEnabled(false);
ui->textArea->setUndoRedoEnabled(true); ui->textArea->setUndoRedoEnabled(true);
m_showIntsAction = Q_NULLPTR;
m_reindentCodeAction = Q_NULLPTR;
m_blankAfterReturnsAction = Q_NULLPTR;
m_syntaxHighlightingAction = Q_NULLPTR;
m_showVarExplorerAction = Q_NULLPTR;
m_wordWrapAction = Q_NULLPTR;
toggleWordWrap(settings.value("ASViewer.WordWrap",true).toBool()); toggleWordWrap(settings.value("ASViewer.WordWrap",true).toBool());
setIndentCode(settings.value("ASViewer.indentCode",false).toBool(), NoReformat); setIndentCode(settings.value("ASViewer.indentCode",false).toBool(), NoReformat);
setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool(), NoReformat); setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool(), NoReformat);
setBreakAfterReturn(settings.value("ASViewer.breakAfterReturn",false).toBool(), NoReformat); setBreakAfterReturn(settings.value("ASViewer.breakAfterReturn",false).toBool(), NoReformat);
setSyntaxHighlighting(settings.value("ASViewer.syntaxHighlighting",false).toBool(), NoReformat);
} }
ApplesoftFileViewer::~ApplesoftFileViewer() ApplesoftFileViewer::~ApplesoftFileViewer()
@ -42,44 +50,75 @@ bool ApplesoftFileViewer::makeMenuOptions(QMenu *menu)
{ {
QSettings settings; QSettings settings;
QAction *action = new QAction("Show &Ints as Hex",menu); if (!m_showIntsAction)
action->setCheckable(true); {
action->setChecked(settings.value("ASViewer.intsAsHex",false).toBool()); m_showIntsAction = new QAction("Show &Ints as Hex",menu);
setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool(),NoReformat); m_showIntsAction->setCheckable(true);
connect(action, SIGNAL(toggled(bool)), ui->findText,SLOT(clear())); m_showIntsAction->setChecked(settings.value("ASViewer.intsAsHex",false).toBool());
connect(action, SIGNAL(toggled(bool)),SLOT(setIntsAsHex(bool))); setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool(),NoReformat);
menu->addAction(action); connect(m_showIntsAction, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
connect(m_showIntsAction, SIGNAL(toggled(bool)),SLOT(setIntsAsHex(bool)));
}
menu->addAction(m_showIntsAction);
action = new QAction("&Reindent code",menu); if (!m_reindentCodeAction)
action->setCheckable(true); {
action->setChecked(settings.value("ASViewer.indentCode",false).toBool()); m_reindentCodeAction = new QAction("&Indent code",menu);
m_reindentCodeAction->setCheckable(true);
m_reindentCodeAction->setChecked(settings.value("ASViewer.indentCode",false).toBool());
setIndentCode(settings.value("ASViewer.indentCode",false).toBool(),NoReformat); setIndentCode(settings.value("ASViewer.indentCode",false).toBool(),NoReformat);
connect(action, SIGNAL(toggled(bool)), ui->findText,SLOT(clear())); connect(m_reindentCodeAction, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
connect(action, SIGNAL(toggled(bool)),SLOT(setIndentCode(bool))); connect(m_reindentCodeAction, SIGNAL(toggled(bool)),SLOT(setIndentCode(bool)));
menu->addAction(action); }
menu->addAction(m_reindentCodeAction);
action = new QAction("Blank &Line after RETURNs",menu); if (!m_blankAfterReturnsAction)
action->setCheckable(true); {
action->setChecked(settings.value("ASViewer.breakAfterReturn",false).toBool()); m_blankAfterReturnsAction = new QAction("Blank &Line after RETURNs",menu);
m_blankAfterReturnsAction->setCheckable(true);
m_blankAfterReturnsAction->setChecked(settings.value("ASViewer.breakAfterReturn",false).toBool());
setIndentCode(settings.value("ASViewer.breakAfterReturn",false).toBool(),NoReformat); setIndentCode(settings.value("ASViewer.breakAfterReturn",false).toBool(),NoReformat);
connect(action, SIGNAL(toggled(bool)), ui->findText,SLOT(clear())); connect(m_blankAfterReturnsAction, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
connect(action, SIGNAL(toggled(bool)),SLOT(setBreakAfterReturn(bool))); connect(m_blankAfterReturnsAction, SIGNAL(toggled(bool)),SLOT(setBreakAfterReturn(bool)));
menu->addAction(action); }
menu->addAction(m_blankAfterReturnsAction);
menu->addSeparator(); menu->addSeparator();
action = new QAction("Show &Variable Explorer...",menu); if (!m_wordWrapAction)
action->setCheckable(false); {
connect(action, SIGNAL(triggered(bool)), SLOT(launchVarBrowser())); m_wordWrapAction = new QAction("&Word Wrap");
menu->addAction(action); m_wordWrapAction->setCheckable(true);
m_wordWrapAction->setChecked(settings.value("ASViewer.WordWrap",true).toBool());
toggleWordWrap(settings.value("ASViewer.WordWrap",true).toBool());
connect(m_wordWrapAction, SIGNAL(toggled(bool)), SLOT(toggleWordWrap(bool)));
}
menu->addAction(m_wordWrapAction);
if (!m_syntaxHighlightingAction)
{
m_syntaxHighlightingAction = new QAction("&Syntax Highlighting",menu);
m_syntaxHighlightingAction->setCheckable(true);
m_syntaxHighlightingAction->setChecked(settings.value("ASViewer.syntaxHighlighting",false).toBool());
setIndentCode(settings.value("ASViewer.syntaxHighlighting",false).toBool(),NoReformat);
connect(m_syntaxHighlightingAction, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
connect(m_syntaxHighlightingAction, SIGNAL(toggled(bool)),SLOT(setSyntaxHighlighting(bool)));
}
menu->addAction(m_syntaxHighlightingAction);
menu->addSeparator(); menu->addSeparator();
action = new QAction("&Word Wrap"); if (!m_showVarExplorerAction)
action->setCheckable(true); {
action->setChecked(settings.value("ASViewer.WordWrap",true).toBool()); m_showVarExplorerAction = new QAction("Show &Variable Explorer...",menu);
connect(action, SIGNAL(toggled(bool)), SLOT(toggleWordWrap(bool))); m_showVarExplorerAction->setCheckable(false);
menu->addAction(action); connect(m_showVarExplorerAction, SIGNAL(triggered(bool)), SLOT(launchVarBrowser()));
}
menu->addAction(m_showVarExplorerAction);
return true; return true;
} }
@ -136,6 +175,22 @@ void ApplesoftFileViewer::setBreakAfterReturn(bool enabled, ReformatRule reforma
reformatText(); reformatText();
} }
void ApplesoftFileViewer::setSyntaxHighlighting(bool enabled, ReformatRule reformat)
{
if (enabled)
{
m_formatter->setFlags(m_formatter->flags() | ApplesoftFormatter::SyntaxHighlighting);
}
else
{
m_formatter->setFlags(m_formatter->flags() & ~ApplesoftFormatter::SyntaxHighlighting);
}
QSettings settings;
settings.setValue("ASViewer.syntaxHighlighting",enabled);
if (reformat == ForceReformat)
reformatText();
}
void ApplesoftFileViewer::setIntsAsHex(bool enabled, ReformatRule reformat) void ApplesoftFileViewer::setIntsAsHex(bool enabled, ReformatRule reformat)
{ {
if (enabled) if (enabled)

View File

@ -46,6 +46,7 @@ public slots:
protected slots: protected slots:
void toggleWordWrap(bool enabled); void toggleWordWrap(bool enabled);
void setSyntaxHighlighting(bool enabled, ReformatRule reformat);
void setIndentCode(bool enabled, ReformatRule reformat = ForceReformat); void setIndentCode(bool enabled, ReformatRule reformat = ForceReformat);
void setIntsAsHex(bool enabled, ReformatRule reformat = ForceReformat); void setIntsAsHex(bool enabled, ReformatRule reformat = ForceReformat);
void setBreakAfterReturn(bool enabled, ReformatRule reformat = ForceReformat); void setBreakAfterReturn(bool enabled, ReformatRule reformat = ForceReformat);
@ -59,6 +60,13 @@ private:
ApplesoftFormatter *m_formatter; ApplesoftFormatter *m_formatter;
bool m_isFirstFind; bool m_isFirstFind;
Ui::ApplesoftFileViewer *ui; Ui::ApplesoftFileViewer *ui;
QAction *m_showIntsAction;
QAction *m_reindentCodeAction;
QAction *m_blankAfterReturnsAction;
QAction *m_syntaxHighlightingAction;
QAction *m_showVarExplorerAction;
QAction *m_wordWrapAction;
}; };
#endif // APPLESOFTFILEVIEWER_H #endif // APPLESOFTFILEVIEWER_H