Fixed issue with AppleSoft code needlessly reformatting multiple times

This commit is contained in:
Mark Long 2016-10-24 22:53:35 -05:00
parent e4c81ee70c
commit f4c871c9b9
2 changed files with 23 additions and 8 deletions

View File

@ -27,6 +27,9 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
ui->textArea->setUndoRedoEnabled(true); ui->textArea->setUndoRedoEnabled(true);
toggleWordWrap(settings.value("ASViewer.WordWrap",true).toBool()); toggleWordWrap(settings.value("ASViewer.WordWrap",true).toBool());
setIndentCode(settings.value("ASViewer.indentCode",false).toBool(), NoReformat);
setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool(), NoReformat);
} }
ApplesoftFileViewer::~ApplesoftFileViewer() ApplesoftFileViewer::~ApplesoftFileViewer()
@ -34,6 +37,8 @@ ApplesoftFileViewer::~ApplesoftFileViewer()
delete ui; delete ui;
} }
bool ApplesoftFileViewer::makeMenuOptions(QMenu *menu) bool ApplesoftFileViewer::makeMenuOptions(QMenu *menu)
{ {
QSettings settings; QSettings settings;
@ -41,7 +46,7 @@ bool ApplesoftFileViewer::makeMenuOptions(QMenu *menu)
QAction *action = new QAction("Show &Ints as Hex",menu); QAction *action = new QAction("Show &Ints as Hex",menu);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(settings.value("ASViewer.intsAsHex",false).toBool()); action->setChecked(settings.value("ASViewer.intsAsHex",false).toBool());
setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool()); setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool(),NoReformat);
connect(action, SIGNAL(toggled(bool)), ui->findText,SLOT(clear())); connect(action, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
connect(action, SIGNAL(toggled(bool)),SLOT(setIntsAsHex(bool))); connect(action, SIGNAL(toggled(bool)),SLOT(setIntsAsHex(bool)));
menu->addAction(action); menu->addAction(action);
@ -49,7 +54,7 @@ bool ApplesoftFileViewer::makeMenuOptions(QMenu *menu)
action = new QAction("&Reindent code",menu); action = new QAction("&Reindent code",menu);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(settings.value("ASViewer.indentCode",false).toBool()); action->setChecked(settings.value("ASViewer.indentCode",false).toBool());
setIndentCode(settings.value("ASViewer.indentCode",false).toBool()); setIndentCode(settings.value("ASViewer.indentCode",false).toBool(),NoReformat);
connect(action, SIGNAL(toggled(bool)), ui->findText,SLOT(clear())); connect(action, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
connect(action, SIGNAL(toggled(bool)),SLOT(setIndentCode(bool))); connect(action, SIGNAL(toggled(bool)),SLOT(setIndentCode(bool)));
menu->addAction(action); menu->addAction(action);
@ -92,7 +97,7 @@ void ApplesoftFileViewer::toggleWordWrap(bool enabled)
settings.setValue("ASViewer.WordWrap",enabled); settings.setValue("ASViewer.WordWrap",enabled);
} }
void ApplesoftFileViewer::setIndentCode(bool enabled) void ApplesoftFileViewer::setIndentCode(bool enabled, ReformatRule reformat)
{ {
if (enabled) if (enabled)
{ {
@ -104,10 +109,11 @@ void ApplesoftFileViewer::setIndentCode(bool enabled)
} }
QSettings settings; QSettings settings;
settings.setValue("ASViewer.indentCode",enabled); settings.setValue("ASViewer.indentCode",enabled);
reformatText(); if (reformat == ForceReformat)
reformatText();
} }
void ApplesoftFileViewer::setIntsAsHex(bool enabled) void ApplesoftFileViewer::setIntsAsHex(bool enabled, ReformatRule reformat)
{ {
if (enabled) if (enabled)
{ {
@ -119,12 +125,14 @@ void ApplesoftFileViewer::setIntsAsHex(bool enabled)
} }
QSettings settings; QSettings settings;
settings.setValue("ASViewer.intsAsHex",enabled); settings.setValue("ASViewer.intsAsHex",enabled);
reformatText(); if (reformat == ForceReformat)
reformatText();
} }
void ApplesoftFileViewer::reformatText() void ApplesoftFileViewer::reformatText()
{ {
ui->textArea->setText(m_formatter->formatText()); ui->textArea->setText(m_formatter->formatText());
qDebug() << m_formatter->flowTargets();
} }
void ApplesoftFileViewer::setFile(GenericFile *file) { void ApplesoftFileViewer::setFile(GenericFile *file) {

View File

@ -18,6 +18,12 @@ class ApplesoftFileViewer : public FileViewerInterface
Q_OBJECT Q_OBJECT
public: public:
typedef enum {
ForceReformat,
NoReformat
} ReformatRule;
ApplesoftFileViewer(QWidget *parent = 0); ApplesoftFileViewer(QWidget *parent = 0);
~ApplesoftFileViewer(); ~ApplesoftFileViewer();
@ -28,6 +34,7 @@ public:
virtual bool canPrint() const; virtual bool canPrint() const;
bool canExport() const; bool canExport() const;
public slots: public slots:
void setFile(GenericFile *file); void setFile(GenericFile *file);
void setFile(ApplesoftFile *m_file); void setFile(ApplesoftFile *m_file);
@ -39,8 +46,8 @@ public slots:
protected slots: protected slots:
void toggleWordWrap(bool enabled); void toggleWordWrap(bool enabled);
void setIndentCode(bool enabled); void setIndentCode(bool enabled, ReformatRule reformat = ForceReformat);
void setIntsAsHex(bool enabled); void setIntsAsHex(bool enabled, ReformatRule reformat = ForceReformat);
void launchVarBrowser(); void launchVarBrowser();
void reformatText(); void reformatText();