Skip to content

Commit

Permalink
Fixes #3807 and #3808.
Browse files Browse the repository at this point in the history
Added line ending and bom settings.
  • Loading branch information
adeas31 committed Apr 1, 2016
1 parent 9b9a159 commit fbf65b8
Show file tree
Hide file tree
Showing 22 changed files with 769 additions and 605 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Debugger/DebuggerMainWindow.cpp
Expand Up @@ -92,7 +92,7 @@ DebuggerMainWindow::DebuggerMainWindow(MainWindow *pMainWindow)
mpDebuggerSourceEditorInfoBar->hide();
mpDebuggerSourceEditor = new DebuggerSourceEditor(this);
ModelicaTextHighlighter *pModelicaTextHighlighter;
pModelicaTextHighlighter = new ModelicaTextHighlighter(mpMainWindow->getOptionsDialog()->getModelicaTextEditorPage(),
pModelicaTextHighlighter = new ModelicaTextHighlighter(mpMainWindow->getOptionsDialog()->getModelicaEditorPage(),
mpDebuggerSourceEditor->getPlainTextEdit());
connect(mpMainWindow->getOptionsDialog(), SIGNAL(modelicaTextSettingsChanged()), pModelicaTextHighlighter, SLOT(settingsChanged()));
connect(mpGDBAdapter, SIGNAL(GDBProcessFinished()), SLOT(handleGDBProcessFinished()));
Expand Down
105 changes: 10 additions & 95 deletions OMEdit/OMEditGUI/Editors/BaseEditor.cpp
Expand Up @@ -443,9 +443,8 @@ BaseEditor::PlainTextEdit::PlainTextEdit(BaseEditor *pBaseEditor)
// line numbers widget
mpLineNumberArea = new LineNumberArea(mpBaseEditor);
// parentheses matcher
mParenthesesMatchFormat.setForeground(Qt::red);
mParenthesesMatchFormat.setBackground(QColor(160, 238, 160));
mParenthesesMisMatchFormat.setBackground(Qt::red);
mParenthesesMatchFormat = Utilities::getParenthesesMatchFormat();
mParenthesesMisMatchFormat = Utilities::getParenthesesMisMatchFormat();

updateLineNumberAreaWidth(0);
updateHighlights();
Expand Down Expand Up @@ -669,18 +668,10 @@ void BaseEditor::PlainTextEdit::updateCursorPosition()
void BaseEditor::PlainTextEdit::setLineWrapping()
{
OptionsDialog *pOptionsDialog = mpBaseEditor->getMainWindow()->getOptionsDialog();
if (dynamic_cast<MetaModelEditor*>(mpBaseEditor)) {
if (pOptionsDialog->getMetaModelEditorPage()->getLineWrappingCheckbox()->isChecked()) {
setLineWrapMode(QPlainTextEdit::WidgetWidth);
} else {
setLineWrapMode(QPlainTextEdit::NoWrap);
}
} else { //! @todo we should check all editors here.
if (pOptionsDialog->getModelicaTextEditorPage()->getLineWrappingCheckbox()->isChecked()) {
setLineWrapMode(QPlainTextEdit::WidgetWidth);
} else {
setLineWrapMode(QPlainTextEdit::NoWrap);
}
if (pOptionsDialog->getTextEditorPage()->getLineWrappingCheckbox()->isChecked()) {
setLineWrapMode(QPlainTextEdit::WidgetWidth);
} else {
setLineWrapMode(QPlainTextEdit::NoWrap);
}
}

Expand Down Expand Up @@ -715,12 +706,7 @@ void BaseEditor::PlainTextEdit::toggleBreakpoint(const QString fileName, int lin
*/
void BaseEditor::PlainTextEdit::indentOrUnindent(bool doIndent)
{
TabSettings tabSettings;
if (dynamic_cast<MetaModelEditor*>(mpBaseEditor)) {
tabSettings = mpBaseEditor->getMainWindow()->getOptionsDialog()->getMetaModelTabSettings();
} else { //! @todo we should check all editors here.
tabSettings = mpBaseEditor->getMainWindow()->getOptionsDialog()->getModelicaTabSettings();
}
TabSettings tabSettings = mpBaseEditor->getMainWindow()->getOptionsDialog()->getTabSettings();
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
// Indent or unindent the selected lines
Expand Down Expand Up @@ -774,15 +760,7 @@ void BaseEditor::PlainTextEdit::indentOrUnindent(bool doIndent)
*/
void BaseEditor::PlainTextEdit::highlightCurrentLine()
{
QList<QTextEdit::ExtraSelection> selections = extraSelections();
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(232, 242, 254);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
selections.append(selection);
setExtraSelections(selections);
Utilities::highlightCurrentLine(this);
}

/*!
Expand All @@ -791,65 +769,7 @@ void BaseEditor::PlainTextEdit::highlightCurrentLine()
*/
void BaseEditor::PlainTextEdit::highlightParentheses()
{
if (isReadOnly()) {
return;
}

QTextCursor backwardMatch = textCursor();
QTextCursor forwardMatch = textCursor();
if (overwriteMode()) {
backwardMatch.movePosition(QTextCursor::Right);
}

const TextBlockUserData::MatchType backwardMatchType = TextBlockUserData::matchCursorBackward(&backwardMatch);
const TextBlockUserData::MatchType forwardMatchType = TextBlockUserData::matchCursorForward(&forwardMatch);
QList<QTextEdit::ExtraSelection> selections = extraSelections();

if (backwardMatchType == TextBlockUserData::NoMatch && forwardMatchType == TextBlockUserData::NoMatch) {
setExtraSelections(selections);
return;
}

if (backwardMatch.hasSelection()) {
QTextEdit::ExtraSelection selection;
if (backwardMatchType == TextBlockUserData::Mismatch) {
selection.cursor = backwardMatch;
selection.format = mParenthesesMisMatchFormat;
selections.append(selection);
} else {
selection.cursor = backwardMatch;
selection.format = mParenthesesMatchFormat;

selection.cursor.setPosition(backwardMatch.selectionStart());
selection.cursor.setPosition(selection.cursor.position() + 1, QTextCursor::KeepAnchor);
selections.append(selection);

selection.cursor.setPosition(backwardMatch.selectionEnd());
selection.cursor.setPosition(selection.cursor.position() - 1, QTextCursor::KeepAnchor);
selections.append(selection);
}
}

if (forwardMatch.hasSelection()) {
QTextEdit::ExtraSelection selection;
if (forwardMatchType == TextBlockUserData::Mismatch) {
selection.cursor = forwardMatch;
selection.format = mParenthesesMisMatchFormat;
selections.append(selection);
} else {
selection.cursor = forwardMatch;
selection.format = mParenthesesMatchFormat;

selection.cursor.setPosition(forwardMatch.selectionStart());
selection.cursor.setPosition(selection.cursor.position() + 1, QTextCursor::KeepAnchor);
selections.append(selection);

selection.cursor.setPosition(forwardMatch.selectionEnd());
selection.cursor.setPosition(selection.cursor.position() - 1, QTextCursor::KeepAnchor);
selections.append(selection);
}
}
setExtraSelections(selections);
Utilities::highlightParentheses(this, mParenthesesMatchFormat, mParenthesesMisMatchFormat);
}

/*!
Expand Down Expand Up @@ -948,12 +868,7 @@ void BaseEditor::PlainTextEdit::keyPressEvent(QKeyEvent *pEvent)
*/
/*! @todo We should add formatter classes to handle this based on editor language i.e Modelica or C/C++. */
if (pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::Key_Return) {
TabSettings tabSettings;
if (dynamic_cast<MetaModelEditor*>(mpBaseEditor)) {
tabSettings = mpBaseEditor->getMainWindow()->getOptionsDialog()->getMetaModelTabSettings();
} else { //! @todo we should check all editors here.
tabSettings = mpBaseEditor->getMainWindow()->getOptionsDialog()->getModelicaTabSettings();
}
TabSettings tabSettings = mpBaseEditor->getMainWindow()->getOptionsDialog()->getTabSettings();
QTextCursor cursor = textCursor();
const QTextBlock previousBlock = cursor.block().previous();
QString indentText = previousBlock.text();
Expand Down
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/Editors/CEditor.cpp
Expand Up @@ -39,7 +39,11 @@
CEditor::CEditor(MainWindow *pMainWindow)
: BaseEditor(pMainWindow)
{

QFont font;
font.setFamily(pMainWindow->getOptionsDialog()->getTextEditorPage()->getFontFamilyComboBox()->currentFont().family());
font.setPointSizeF(pMainWindow->getOptionsDialog()->getTextEditorPage()->getFontSizeSpinBox()->value());
mpPlainTextEdit->document()->setDefaultFont(font);
mpPlainTextEdit->setTabStopWidth(pMainWindow->getOptionsDialog()->getTextEditorPage()->getTabSizeSpinBox()->value() * QFontMetrics(font).width(QLatin1Char(' ')));
}

/*!
Expand Down
10 changes: 5 additions & 5 deletions OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp
Expand Up @@ -45,7 +45,7 @@ XMLDocument::XMLDocument(MetaModelEditor *pMetaModelEditor)

QString XMLDocument::toString() const
{
TabSettings tabSettings = mpMetaModelEditor->getMainWindow()->getOptionsDialog()->getMetaModelTabSettings();
TabSettings tabSettings = mpMetaModelEditor->getMainWindow()->getOptionsDialog()->getTabSettings();
return QDomDocument::toString(tabSettings.getIndentSize());
}

Expand Down Expand Up @@ -731,10 +731,10 @@ MetaModelHighlighter::MetaModelHighlighter(MetaModelEditorPage *pMetaModelEditor
void MetaModelHighlighter::initializeSettings()
{
QFont font;
font.setFamily(mpMetaModelEditorPage->getFontFamilyComboBox()->currentFont().family());
font.setPointSizeF(mpMetaModelEditorPage->getFontSizeSpinBox()->value());
font.setFamily(mpMetaModelEditorPage->getOptionsDialog()->getTextEditorPage()->getFontFamilyComboBox()->currentFont().family());
font.setPointSizeF(mpMetaModelEditorPage->getOptionsDialog()->getTextEditorPage()->getFontSizeSpinBox()->value());
mpPlainTextEdit->document()->setDefaultFont(font);
mpPlainTextEdit->setTabStopWidth(mpMetaModelEditorPage->getTabSizeSpinBox()->value() * QFontMetrics(font).width(QLatin1Char(' ')));
mpPlainTextEdit->setTabStopWidth(mpMetaModelEditorPage->getOptionsDialog()->getTextEditorPage()->getTabSizeSpinBox()->value() * QFontMetrics(font).width(QLatin1Char(' ')));
// set color highlighting
mHighlightingRules.clear();
HighlightingRule rule;
Expand Down Expand Up @@ -848,7 +848,7 @@ void MetaModelHighlighter::highlightMultiLine(const QString &text)
void MetaModelHighlighter::highlightBlock(const QString &text)
{
/* Only highlight the text if user has enabled the syntax highlighting */
if (!mpMetaModelEditorPage->getSyntaxHighlightingCheckbox()->isChecked()) {
if (!mpMetaModelEditorPage->getOptionsDialog()->getTextEditorPage()->getSyntaxHighlightingCheckbox()->isChecked()) {
return;
}
setCurrentBlockState(0);
Expand Down

0 comments on commit fbf65b8

Please sign in to comment.