Skip to content

Commit

Permalink
Added a settings option to enable/disable preserve indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Feb 8, 2016
1 parent db0641f commit 0ab2c2f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -1608,8 +1608,14 @@ QString OMCProxy::diffModelicaFileListings(QString before, QString after)
{
QString escapedBefore = StringHandler::escapeString(before);
QString escapedAfter = StringHandler::escapeString(after);
// sendCommand("diffModelicaFileListings(\"" + escapedBefore + "\", \"" + escapedAfter + "\", OpenModelica.Scripting.DiffFormat.plain)");
QString result = after; // StringHandler::unparse(getResult());
QString result;
// only use the diffModelicaFileListings when preserve text indentation settings is true
if (mpMainWindow->getOptionsDialog()->getModelicaTextEditorPage()->getPreserveTextIndentationCheckBox()->isChecked()) {
sendCommand("diffModelicaFileListings(\"" + escapedBefore + "\", \"" + escapedAfter + "\", OpenModelica.Scripting.DiffFormat.plain)");
result = StringHandler::unparse(getResult());
} else {
result = after;
}
if (mpMainWindow->isDebug()) {
mpOMCDiffBeforeTextBox->setPlainText(before);
mpOMCDiffAfterTextBox->setPlainText(after);
Expand Down
8 changes: 8 additions & 0 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -223,6 +223,9 @@ void OptionsDialog::readModelicaTextSettings()
if (mpSettings->contains("textEditor/indentSize")) {
mpModelicaTextEditorPage->getIndentSpinBox()->setValue(mpSettings->value("textEditor/indentSize").toInt());
}
if (mpSettings->contains("textEditor/preserveTextIndentation")) {
mpModelicaTextEditorPage->getPreserveTextIndentationCheckBox()->setChecked(mpSettings->value("textEditor/preserveTextIndentation").toBool());
}
if (mpSettings->contains("textEditor/enableSyntaxHighlighting")) {
mpModelicaTextEditorPage->getSyntaxHighlightingCheckbox()->setChecked(mpSettings->value("textEditor/enableSyntaxHighlighting").toBool());
}
Expand Down Expand Up @@ -703,6 +706,7 @@ void OptionsDialog::saveModelicaTextSettings()
mpSettings->setValue("textEditor/tabPolicy", mpModelicaTextEditorPage->getTabPolicyComboBox()->itemData(mpModelicaTextEditorPage->getTabPolicyComboBox()->currentIndex()).toInt());
mpSettings->setValue("textEditor/tabSize", mpModelicaTextEditorPage->getTabSizeSpinBox()->value());
mpSettings->setValue("textEditor/indentSize", mpModelicaTextEditorPage->getIndentSpinBox()->value());
mpSettings->setValue("textEditor/preserveTextIndentation", mpModelicaTextEditorPage->getPreserveTextIndentationCheckBox()->isChecked());
mpSettings->setValue("textEditor/enableSyntaxHighlighting", mpModelicaTextEditorPage->getSyntaxHighlightingCheckbox()->isChecked());
mpSettings->setValue("textEditor/matchParenthesesCommentsQuotes", mpModelicaTextEditorPage->getMatchParenthesesCommentsQuotesCheckBox()->isChecked());
mpSettings->setValue("textEditor/enableLineWrapping", mpModelicaTextEditorPage->getLineWrappingCheckbox()->isChecked());
Expand Down Expand Up @@ -1920,6 +1924,9 @@ ModelicaTextEditorPage::ModelicaTextEditorPage(OptionsDialog *pOptionsDialog)
mpIndentSpinBox = new QSpinBox;
mpIndentSpinBox->setRange(1, 20);
mpIndentSpinBox->setValue(2);
// preserve text indentation
mpPreserveTextIndentationCheckBox = new QCheckBox(tr("Preserve Text Indentation"));
mpPreserveTextIndentationCheckBox->setChecked(true);
// set tabs & indentation groupbox layout
QGridLayout *pTabsAndIndentationGroupBoxLayout = new QGridLayout;
pTabsAndIndentationGroupBoxLayout->addWidget(mpTabPolicyLabel, 0, 0);
Expand All @@ -1928,6 +1935,7 @@ ModelicaTextEditorPage::ModelicaTextEditorPage(OptionsDialog *pOptionsDialog)
pTabsAndIndentationGroupBoxLayout->addWidget(mpTabSizeSpinBox, 1, 1);
pTabsAndIndentationGroupBoxLayout->addWidget(mpIndentSizeLabel, 2, 0);
pTabsAndIndentationGroupBoxLayout->addWidget(mpIndentSpinBox, 2, 1);
pTabsAndIndentationGroupBoxLayout->addWidget(mpPreserveTextIndentationCheckBox, 3, 0, 1, 2);
mpTabsAndIndentation->setLayout(pTabsAndIndentationGroupBoxLayout);
// syntax highlight and text wrapping groupbox
mpSyntaxHighlightAndTextWrappingGroupBox = new QGroupBox(tr("Syntax Highlight and Text Wrapping"));
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Options/OptionsDialog.h
Expand Up @@ -307,6 +307,7 @@ class ModelicaTextEditorPage : public QWidget
QComboBox *getTabPolicyComboBox() {return mpTabPolicyComboBox;}
QSpinBox *getTabSizeSpinBox() {return mpTabSizeSpinBox;}
QSpinBox *getIndentSpinBox() {return mpIndentSpinBox;}
QCheckBox *getPreserveTextIndentationCheckBox() {return mpPreserveTextIndentationCheckBox;}
QCheckBox* getSyntaxHighlightingCheckbox() {return mpSyntaxHighlightingCheckbox;}
QCheckBox* getMatchParenthesesCommentsQuotesCheckBox() {return mpMatchParenthesesCommentsQuotesCheckBox;}
QCheckBox* getLineWrappingCheckbox() {return mpLineWrappingCheckbox;}
Expand Down Expand Up @@ -336,6 +337,7 @@ class ModelicaTextEditorPage : public QWidget
QSpinBox *mpTabSizeSpinBox;
Label *mpIndentSizeLabel;
QSpinBox *mpIndentSpinBox;
QCheckBox *mpPreserveTextIndentationCheckBox;
QGroupBox *mpSyntaxHighlightAndTextWrappingGroupBox;
QCheckBox *mpSyntaxHighlightingCheckbox;
QCheckBox *mpMatchParenthesesCommentsQuotesCheckBox;
Expand Down

0 comments on commit 0ab2c2f

Please sign in to comment.