From fbf65b8cf9fe10aaf6f3508693ed79e5a1cb9f66 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Fri, 1 Apr 2016 15:22:38 +0200 Subject: [PATCH] Fixes #3807 and #3808. Added line ending and bom settings. --- .../OMEditGUI/Debugger/DebuggerMainWindow.cpp | 2 +- OMEdit/OMEditGUI/Editors/BaseEditor.cpp | 105 +-- OMEdit/OMEditGUI/Editors/CEditor.cpp | 6 +- OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp | 10 +- ...elicaTextEditor.cpp => ModelicaEditor.cpp} | 70 +- ...{ModelicaTextEditor.h => ModelicaEditor.h} | 16 +- OMEdit/OMEditGUI/Editors/TextEditor.cpp | 19 +- .../OMEditGUI/Modeling/LibraryTreeWidget.cpp | 165 +++-- OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h | 7 +- .../Modeling/ModelWidgetContainer.cpp | 34 +- .../OMEditGUI/Modeling/ModelWidgetContainer.h | 2 +- .../Modeling/ModelicaClassDialog.cpp | 2 +- OMEdit/OMEditGUI/OMC/OMCProxy.cpp | 2 +- OMEdit/OMEditGUI/OMEditGUI.pro | 4 +- OMEdit/OMEditGUI/Options/OptionsDialog.cpp | 634 ++++++++++-------- OMEdit/OMEditGUI/Options/OptionsDialog.h | 121 ++-- .../Plotting/PlotWindowContainer.cpp | 49 +- .../TransformationsWidget.cpp | 2 +- OMEdit/OMEditGUI/Util/Helper.cpp | 4 +- OMEdit/OMEditGUI/Util/Helper.h | 3 +- OMEdit/OMEditGUI/Util/Utilities.cpp | 92 +++ OMEdit/OMEditGUI/Util/Utilities.h | 25 + 22 files changed, 769 insertions(+), 605 deletions(-) rename OMEdit/OMEditGUI/Editors/{ModelicaTextEditor.cpp => ModelicaEditor.cpp} (91%) rename OMEdit/OMEditGUI/Editors/{ModelicaTextEditor.h => ModelicaEditor.h} (90%) diff --git a/OMEdit/OMEditGUI/Debugger/DebuggerMainWindow.cpp b/OMEdit/OMEditGUI/Debugger/DebuggerMainWindow.cpp index 7aada121cbb..baa32e4a383 100644 --- a/OMEdit/OMEditGUI/Debugger/DebuggerMainWindow.cpp +++ b/OMEdit/OMEditGUI/Debugger/DebuggerMainWindow.cpp @@ -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())); diff --git a/OMEdit/OMEditGUI/Editors/BaseEditor.cpp b/OMEdit/OMEditGUI/Editors/BaseEditor.cpp index 1d1c29d1978..ac8435e788e 100644 --- a/OMEdit/OMEditGUI/Editors/BaseEditor.cpp +++ b/OMEdit/OMEditGUI/Editors/BaseEditor.cpp @@ -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(); @@ -669,18 +668,10 @@ void BaseEditor::PlainTextEdit::updateCursorPosition() void BaseEditor::PlainTextEdit::setLineWrapping() { OptionsDialog *pOptionsDialog = mpBaseEditor->getMainWindow()->getOptionsDialog(); - if (dynamic_cast(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); } } @@ -715,12 +706,7 @@ void BaseEditor::PlainTextEdit::toggleBreakpoint(const QString fileName, int lin */ void BaseEditor::PlainTextEdit::indentOrUnindent(bool doIndent) { - TabSettings tabSettings; - if (dynamic_cast(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 @@ -774,15 +760,7 @@ void BaseEditor::PlainTextEdit::indentOrUnindent(bool doIndent) */ void BaseEditor::PlainTextEdit::highlightCurrentLine() { - QList 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); } /*! @@ -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 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); } /*! @@ -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(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(); diff --git a/OMEdit/OMEditGUI/Editors/CEditor.cpp b/OMEdit/OMEditGUI/Editors/CEditor.cpp index 4fec774dde6..9fbb9510712 100644 --- a/OMEdit/OMEditGUI/Editors/CEditor.cpp +++ b/OMEdit/OMEditGUI/Editors/CEditor.cpp @@ -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(' '))); } /*! diff --git a/OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp b/OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp index 04d44610707..7bcfaddb1dd 100644 --- a/OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp +++ b/OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp @@ -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()); } @@ -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; @@ -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); diff --git a/OMEdit/OMEditGUI/Editors/ModelicaTextEditor.cpp b/OMEdit/OMEditGUI/Editors/ModelicaEditor.cpp similarity index 91% rename from OMEdit/OMEditGUI/Editors/ModelicaTextEditor.cpp rename to OMEdit/OMEditGUI/Editors/ModelicaEditor.cpp index 11d29432281..374e8f7994a 100644 --- a/OMEdit/OMEditGUI/Editors/ModelicaTextEditor.cpp +++ b/OMEdit/OMEditGUI/Editors/ModelicaEditor.cpp @@ -35,7 +35,7 @@ * */ #include "BreakpointMarker.h" -#include "ModelicaTextEditor.h" +#include "ModelicaEditor.h" #include "Helper.h" /*! @@ -125,7 +125,7 @@ bool isComment(const QString &text, //! @brief An editor for Modelica Text. Subclass QPlainTextEdit //! Constructor -ModelicaTextEditor::ModelicaTextEditor(ModelWidget *pParent) +ModelicaEditor::ModelicaEditor(ModelWidget *pParent) : BaseEditor(pParent), mLastValidText(""), mTextChanged(false), mForceSetPlainText(false) { setCanHaveBreakpoints(true); @@ -134,13 +134,13 @@ ModelicaTextEditor::ModelicaTextEditor(ModelWidget *pParent) } /*! - * \brief ModelicaTextEditor::getClassNames + * \brief ModelicaEditor::getClassNames * Uses the OMC parseString API to check the class names inside the Modelica Text * \param errorString * \return QStringList a list of class names * \sa ModelWidget::modelicaEditorTextChanged() */ -QStringList ModelicaTextEditor::getClassNames(QString *errorString) +QStringList ModelicaEditor::getClassNames(QString *errorString) { OMCProxy *pOMCProxy = mpMainWindow->getOMCProxy(); QStringList classNames; @@ -183,12 +183,12 @@ QStringList ModelicaTextEditor::getClassNames(QString *errorString) } /*! - * \brief ModelicaTextEditor::validateText - * When user make some changes in the ModelicaTextEditor text then this method validates the text and show text correct options. + * \brief ModelicaEditor::validateText + * When user make some changes in the ModelicaEditor text then this method validates the text and show text correct options. * \param pLibraryTreeItem * \return */ -bool ModelicaTextEditor::validateText(LibraryTreeItem **pLibraryTreeItem) +bool ModelicaEditor::validateText(LibraryTreeItem **pLibraryTreeItem) { if (mTextChanged) { // if the user makes few mistakes in the text then dont let him change the perspective @@ -225,12 +225,12 @@ bool ModelicaTextEditor::validateText(LibraryTreeItem **pLibraryTreeItem) } /*! - * \brief ModelicaTextEditor::removeLeadingSpaces + * \brief ModelicaEditor::removeLeadingSpaces * Removes the leading spaces from a nested class text to make it more readable. * \param contents * \return */ -QString ModelicaTextEditor::removeLeadingSpaces(QString contents) +QString ModelicaEditor::removeLeadingSpaces(QString contents) { QString text; int startLeadingSpaces = 0; @@ -252,11 +252,11 @@ QString ModelicaTextEditor::removeLeadingSpaces(QString contents) } /*! - * \brief ModelicaTextEditor::storeLeadingSpaces + * \brief ModelicaEditor::storeLeadingSpaces * Stores the leading spaces information in the text block user data. * \param leadingSpacesMap */ -void ModelicaTextEditor::storeLeadingSpaces(QMap leadingSpacesMap) +void ModelicaEditor::storeLeadingSpaces(QMap leadingSpacesMap) { QTextBlock block = mpPlainTextEdit->document()->firstBlock(); while (block.isValid()) { @@ -269,11 +269,11 @@ void ModelicaTextEditor::storeLeadingSpaces(QMap leadingSpacesMap) } /*! - * \brief ModelicaTextEditor::getPlainText + * \brief ModelicaEditor::getPlainText * Reads the leading spaces information from the text block user data and inserts them to the actual string. * \return */ -QString ModelicaTextEditor::getPlainText() +QString ModelicaEditor::getPlainText() { if (mpModelWidget->getLibraryTreeItem()->isInPackageOneFile()) { QString text; @@ -304,11 +304,11 @@ QString ModelicaTextEditor::getPlainText() } /*! - * \brief ModelicaTextEditor::showContextMenu + * \brief ModelicaEditor::showContextMenu * Create a context menu. * \param point */ -void ModelicaTextEditor::showContextMenu(QPoint point) +void ModelicaEditor::showContextMenu(QPoint point) { QMenu *pMenu = BaseEditor::createStandardContextMenu(); pMenu->addSeparator(); @@ -318,12 +318,12 @@ void ModelicaTextEditor::showContextMenu(QPoint point) } /*! - * \brief ModelicaTextEditor::setPlainText + * \brief ModelicaEditor::setPlainText * Reimplementation of QPlainTextEdit::setPlainText method. * Makes sure we dont update if the passed text is same. * \param text the string to set. */ -void ModelicaTextEditor::setPlainText(const QString &text) +void ModelicaEditor::setPlainText(const QString &text) { QMap leadingSpacesMap; QString contents = text; @@ -348,7 +348,7 @@ void ModelicaTextEditor::setPlainText(const QString &text) //! Slot activated when ModelicaTextEdit's QTextDocument contentsChanged SIGNAL is raised. //! Sets the model as modified so that user knows that his current model is not saved. -void ModelicaTextEditor::contentsHasChanged(int position, int charsRemoved, int charsAdded) +void ModelicaEditor::contentsHasChanged(int position, int charsRemoved, int charsAdded) { Q_UNUSED(position); if (mpModelWidget->isVisible()) { @@ -392,7 +392,7 @@ void ModelicaTextEditor::contentsHasChanged(int position, int charsRemoved, int Slot activated when toggle comment selection is seleteted from context menu or ctrl+k is pressed. The implementation and logic is inspired from Qt Creator sources. */ -void ModelicaTextEditor::toggleCommentSelection() +void ModelicaEditor::toggleCommentSelection() { CommentDefinition definition; if (!definition.hasSingleLineStyle() && !definition.hasMultiLineStyle()) { @@ -571,10 +571,10 @@ void ModelicaTextEditor::toggleCommentSelection() //! @brief A syntax highlighter for ModelicaEditor. //! Constructor -ModelicaTextHighlighter::ModelicaTextHighlighter(ModelicaTextEditorPage *pModelicaTextEditorPage, QPlainTextEdit *pPlainTextEdit) +ModelicaTextHighlighter::ModelicaTextHighlighter(ModelicaEditorPage *pModelicaEditorPage, QPlainTextEdit *pPlainTextEdit) : QSyntaxHighlighter(pPlainTextEdit->document()) { - mpModelicaTextEditorPage = pModelicaTextEditorPage; + mpModelicaEditorPage = pModelicaEditorPage; mpPlainTextEdit = pPlainTextEdit; initializeSettings(); } @@ -583,22 +583,22 @@ ModelicaTextHighlighter::ModelicaTextHighlighter(ModelicaTextEditorPage *pModeli void ModelicaTextHighlighter::initializeSettings() { QFont font; - font.setFamily(mpModelicaTextEditorPage->getFontFamilyComboBox()->currentFont().family()); - font.setPointSizeF(mpModelicaTextEditorPage->getFontSizeSpinBox()->value()); + font.setFamily(mpModelicaEditorPage->getOptionsDialog()->getTextEditorPage()->getFontFamilyComboBox()->currentFont().family()); + font.setPointSizeF(mpModelicaEditorPage->getOptionsDialog()->getTextEditorPage()->getFontSizeSpinBox()->value()); mpPlainTextEdit->document()->setDefaultFont(font); - mpPlainTextEdit->setTabStopWidth(mpModelicaTextEditorPage->getTabSizeSpinBox()->value() * QFontMetrics(font).width(QLatin1Char(' '))); + mpPlainTextEdit->setTabStopWidth(mpModelicaEditorPage->getOptionsDialog()->getTextEditorPage()->getTabSizeSpinBox()->value() * QFontMetrics(font).width(QLatin1Char(' '))); // set color highlighting mHighlightingRules.clear(); HighlightingRule rule; - mTextFormat.setForeground(mpModelicaTextEditorPage->getTextRuleColor()); - mKeywordFormat.setForeground(mpModelicaTextEditorPage->getKeywordRuleColor()); - mTypeFormat.setForeground(mpModelicaTextEditorPage->getTypeRuleColor()); - mSingleLineCommentFormat.setForeground(mpModelicaTextEditorPage->getCommentRuleColor()); - mMultiLineCommentFormat.setForeground(mpModelicaTextEditorPage->getCommentRuleColor()); - mFunctionFormat.setForeground(mpModelicaTextEditorPage->getFunctionRuleColor()); - mQuotationFormat.setForeground(QColor(mpModelicaTextEditorPage->getQuotesRuleColor())); + mTextFormat.setForeground(mpModelicaEditorPage->getTextRuleColor()); + mKeywordFormat.setForeground(mpModelicaEditorPage->getKeywordRuleColor()); + mTypeFormat.setForeground(mpModelicaEditorPage->getTypeRuleColor()); + mSingleLineCommentFormat.setForeground(mpModelicaEditorPage->getCommentRuleColor()); + mMultiLineCommentFormat.setForeground(mpModelicaEditorPage->getCommentRuleColor()); + mFunctionFormat.setForeground(mpModelicaEditorPage->getFunctionRuleColor()); + mQuotationFormat.setForeground(QColor(mpModelicaEditorPage->getQuotesRuleColor())); // Priority: keyword > func() > ident > number. Yes, the order matters :) - mNumberFormat.setForeground(mpModelicaTextEditorPage->getNumberRuleColor()); + mNumberFormat.setForeground(mpModelicaEditorPage->getNumberRuleColor()); rule.mPattern = QRegExp("[0-9][0-9]*([.][0-9]*)?([eE][+-]?[0-9]*)?"); rule.mFormat = mNumberFormat; mHighlightingRules.append(rule); @@ -750,7 +750,7 @@ void ModelicaTextHighlighter::highlightMultiLine(const QString &text) } } // if no single line comment, no multi line comment and no quotes then store the parentheses - if (pTextBlockUserData && (blockState < 1 || blockState > 3 || mpModelicaTextEditorPage->getMatchParenthesesCommentsQuotesCheckBox()->isChecked())) { + if (pTextBlockUserData && (blockState < 1 || blockState > 3 || mpModelicaEditorPage->getOptionsDialog()->getTextEditorPage()->getMatchParenthesesCommentsQuotesCheckBox()->isChecked())) { if (text[index] == '(' || text[index] == '{' || text[index] == '[') { parentheses.append(Parenthesis(Parenthesis::Opened, text[index], index)); } else if (text[index] == ')' || text[index] == '}' || text[index] == ']') { @@ -780,12 +780,12 @@ void ModelicaTextHighlighter::highlightMultiLine(const QString &text) void ModelicaTextHighlighter::highlightBlock(const QString &text) { /* Only highlight the text if user has enabled the syntax highlighting */ - if (!mpModelicaTextEditorPage->getSyntaxHighlightingCheckbox()->isChecked()) { + if (!mpModelicaEditorPage->getOptionsDialog()->getTextEditorPage()->getSyntaxHighlightingCheckbox()->isChecked()) { return; } // set text block state setCurrentBlockState(0); - setFormat(0, text.length(), mpModelicaTextEditorPage->getTextRuleColor()); + setFormat(0, text.length(), mpModelicaEditorPage->getTextRuleColor()); foreach (const HighlightingRule &rule, mHighlightingRules) { QRegExp expression(rule.mPattern); int index = expression.indexIn(text); diff --git a/OMEdit/OMEditGUI/Editors/ModelicaTextEditor.h b/OMEdit/OMEditGUI/Editors/ModelicaEditor.h similarity index 90% rename from OMEdit/OMEditGUI/Editors/ModelicaTextEditor.h rename to OMEdit/OMEditGUI/Editors/ModelicaEditor.h index c22d5d77867..c74d6c762f6 100644 --- a/OMEdit/OMEditGUI/Editors/ModelicaTextEditor.h +++ b/OMEdit/OMEditGUI/Editors/ModelicaEditor.h @@ -35,8 +35,8 @@ * */ -#ifndef MODELICATEXTEDITOR_H -#define MODELICATEXTEDITOR_H +#ifndef MODELICAEDITOR_H +#define MODELICAEDITOR_H #include @@ -71,11 +71,11 @@ class CommentDefinition QString m_multiLineEnd; }; -class ModelicaTextEditor : public BaseEditor +class ModelicaEditor : public BaseEditor { Q_OBJECT public: - ModelicaTextEditor(ModelWidget *pParent); + ModelicaEditor(ModelWidget *pParent); QString getLastValidText() {return mLastValidText;} QStringList getClassNames(QString *errorString); bool validateText(LibraryTreeItem **pLibraryTreeItem); @@ -94,18 +94,18 @@ public slots: virtual void toggleCommentSelection(); }; -class ModelicaTextEditorPage; +class ModelicaEditorPage; class ModelicaTextHighlighter : public QSyntaxHighlighter { Q_OBJECT public: - ModelicaTextHighlighter(ModelicaTextEditorPage *pModelicaTextEditorPage, QPlainTextEdit *pPlainTextEdit = 0); + ModelicaTextHighlighter(ModelicaEditorPage *pModelicaEditorPage, QPlainTextEdit *pPlainTextEdit = 0); void initializeSettings(); void highlightMultiLine(const QString &text); protected: virtual void highlightBlock(const QString &text); private: - ModelicaTextEditorPage *mpModelicaTextEditorPage; + ModelicaEditorPage *mpModelicaEditorPage; QPlainTextEdit *mpPlainTextEdit; struct HighlightingRule { @@ -125,4 +125,4 @@ public slots: void settingsChanged(); }; -#endif // MODELICATEXTEDITOR_H +#endif // MODELICAEDITOR_H diff --git a/OMEdit/OMEditGUI/Editors/TextEditor.cpp b/OMEdit/OMEditGUI/Editors/TextEditor.cpp index e6d291619f3..3fe18fefe6a 100644 --- a/OMEdit/OMEditGUI/Editors/TextEditor.cpp +++ b/OMEdit/OMEditGUI/Editors/TextEditor.cpp @@ -39,21 +39,26 @@ TextEditor::TextEditor(ModelWidget *pModelWidget) : BaseEditor(pModelWidget) { - //! @todo for now set the font of TextEditor to default monospaced font. Later define settings for it and read from there. - mpPlainTextEdit->setFont(QFont(Helper::monospacedFontInfo.family())); - mpPlainTextEdit->setTabStopWidth(4 * QFontMetrics(mpPlainTextEdit->font()).width(QLatin1Char(' '))); + MainWindow *pMainWindow = pModelWidget->getModelWidgetContainer()->getMainWindow(); + 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(' '))); } TextEditor::TextEditor(MainWindow *pMainWindow) : BaseEditor(pMainWindow) { - //! @todo for now set the font of TextEditor to default monospaced font. Later define settings for it and read from there. - mpPlainTextEdit->setFont(QFont(Helper::monospacedFontInfo.family())); - mpPlainTextEdit->setTabStopWidth(4 * QFontMetrics(mpPlainTextEdit->font()).width(QLatin1Char(' '))); + 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(' '))); } /*! - * \brief ModelicaTextEditor::setPlainText + * \brief TextEditor::setPlainText * Reimplementation of QPlainTextEdit::setPlainText method. * Makes sure we dont update if the passed text is same. * \param text the string to set. diff --git a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp index e4404298f4b..8ddca8af5a3 100644 --- a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp +++ b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp @@ -308,6 +308,7 @@ LibraryTreeItem::LibraryTreeItem() setClassTextAfter(""); setExpanded(false); setNonExisting(true); + setHasBOM(false); } /*! @@ -337,6 +338,7 @@ LibraryTreeItem::LibraryTreeItem(LibraryType type, QString text, QString nameStr setReadOnly(!StringHandler::isFileWritAble(fileName)); } setIsSaved(isSaved); + detectBOM(); if (isFilePathValid()) { QFileInfo fileInfo(getFileName()); // if item has file name as package.mo and is top level then its save folder structure @@ -712,6 +714,31 @@ void LibraryTreeItem::emitComponentAdded(Component *pComponent) emit componentAddedForComponent(); } +/*! + * \brief LibraryTreeItem::detectBOM + * Detects if the file has byte order mark (BOM) or not. + */ +void LibraryTreeItem::detectBOM() +{ + if (isFilePathValid()) { + QFile file(getFileName()); + if (file.open(QIODevice::ReadOnly)) { + QByteArray data = file.readAll(); + const int bytesRead = data.size(); + const unsigned char *buf = reinterpret_cast(data.constData()); + // code taken from qtextstream + if (bytesRead >= 3 && ((buf[0] == 0xef && buf[1] == 0xbb) && buf[2] == 0xbf)) { + setHasBOM(true); + } else { + setHasBOM(false); + } + file.close(); + } + } else { + setHasBOM(false); + } +} + /*! * \brief LibraryTreeItem::handleLoaded * Handles the case when an undefined inherited class is loaded. @@ -1358,9 +1385,9 @@ void LibraryTreeModel::updateLibraryTreeItemClassText(LibraryTreeItem *pLibraryT pParentLibraryTreeItem->setClassText(contents); if (pParentLibraryTreeItem->getModelWidget()) { pParentLibraryTreeItem->getModelWidget()->setWindowTitle(QString(pParentLibraryTreeItem->getName()).append("*")); - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(pParentLibraryTreeItem->getModelWidget()->getEditor()); - if (pModelicaTextEditor) { - pModelicaTextEditor->setPlainText(contents); + ModelicaEditor *pModelicaEditor = dynamic_cast(pParentLibraryTreeItem->getModelWidget()->getEditor()); + if (pModelicaEditor) { + pModelicaEditor->setPlainText(contents); } } // if we first updated the parent class then the child classes needs to be updated as well. @@ -1392,9 +1419,9 @@ void LibraryTreeModel::updateLibraryTreeItemClassTextManually(LibraryTreeItem *p pParentLibraryTreeItem->setClassText(contents); if (pParentLibraryTreeItem->getModelWidget()) { pParentLibraryTreeItem->getModelWidget()->setWindowTitle(QString(pParentLibraryTreeItem->getName()).append("*")); - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(pParentLibraryTreeItem->getModelWidget()->getEditor()); - if (pModelicaTextEditor) { - pModelicaTextEditor->setPlainText(contents); + ModelicaEditor *pModelicaEditor = dynamic_cast(pParentLibraryTreeItem->getModelWidget()->getEditor()); + if (pModelicaEditor) { + pModelicaEditor->setPlainText(contents); } } // if we first updated the parent class then the child classes needs to be updated as well. @@ -2002,11 +2029,11 @@ void LibraryTreeModel::updateChildLibraryTreeItemClassText(LibraryTreeItem *pLib pChildLibraryTreeItem->setClassInformation(mpLibraryWidget->getMainWindow()->getOMCProxy()->getClassInformation(pChildLibraryTreeItem->getNameStructure())); readLibraryTreeItemClassTextFromText(pChildLibraryTreeItem, contents); if (pChildLibraryTreeItem->getModelWidget()) { - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(pChildLibraryTreeItem->getModelWidget()->getEditor()); - if (pModelicaTextEditor) { - pModelicaTextEditor->setPlainText(pChildLibraryTreeItem->getClassText(this)); - if (pModelicaTextEditor->isVisible()) { - pModelicaTextEditor->getPlainTextEdit()->getLineNumberArea()->update(); + ModelicaEditor *pModelicaEditor = dynamic_cast(pChildLibraryTreeItem->getModelWidget()->getEditor()); + if (pModelicaEditor) { + pModelicaEditor->setPlainText(pChildLibraryTreeItem->getClassText(this)); + if (pModelicaEditor->isVisible()) { + pModelicaEditor->getPlainTextEdit()->getLineNumberArea()->update(); } } } @@ -3098,6 +3125,59 @@ void LibraryWidget::parseAndLoadModelicaText(QString modelText) } } +/*! + * \brief LibraryWidget::saveFile + * Saves the file with contents. + * \param fileName + * \param contents + * \return + */ +bool LibraryWidget::saveFile(QString fileName, QString contents, bool hasBOM) +{ + QFile file(fileName); + if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + QTextStream textStream(&file); + // set to UTF-8 + textStream.setCodec(Helper::utf8.toStdString().data()); + // set the BOM settings + QComboBox *pBOMComboBox = mpMainWindow->getOptionsDialog()->getTextEditorPage()->getBOMComboBox(); + Utilities::BomMode bomMode = (Utilities::BomMode)pBOMComboBox->itemData(pBOMComboBox->currentIndex()).toInt(); + switch (bomMode) { + case Utilities::AlwaysAddBom: + textStream.setGenerateByteOrderMark(true); + break; + case Utilities::KeepBom: + textStream.setGenerateByteOrderMark(hasBOM); + break; + case Utilities::AlwaysDeleteBom: + default: + textStream.setGenerateByteOrderMark(false); + break; + } + // set the line ending format + QComboBox *pLineEndingComboBox = mpMainWindow->getOptionsDialog()->getTextEditorPage()->getLineEndingComboBox(); + Utilities::LineEndingMode lineEndingMode = (Utilities::LineEndingMode)pLineEndingComboBox->itemData(pLineEndingComboBox->currentIndex()).toInt(); + switch (lineEndingMode) { + case Utilities::CRLFLineEnding: + contents.replace(QLatin1Char('\n'), QLatin1String("\r\n")); + break; + case Utilities::LFLineEnding: + contents.replace(QLatin1String("\r\n"), QLatin1String("\n")); + default: + break; + } + textStream << contents; + file.close(); + return true; + } else { + mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, + GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED) + .arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE) + .arg(file.errorString())), Helper::scriptingKind, Helper::errorLevel)); + return false; + } +} + /*! * \brief LibraryWidget::saveLibraryTreeItem * Saves the LibraryTreeItem @@ -3183,32 +3263,6 @@ void LibraryWidget::openLibraryTreeItem(QString nameStructure) } } -/*! - * \brief LibraryWidget::saveFile - * Saves the file with contents. - * \param fileName - * \param contents - * \return - */ -bool LibraryWidget::saveFile(QString fileName, QString contents) -{ - QFile file(fileName); - if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QTextStream textStream(&file); - textStream.setCodec(Helper::utf8.toStdString().data()); - textStream.setGenerateByteOrderMark(false); - textStream << contents; - file.close(); - return true; - } else { - mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, - GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED) - .arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE) - .arg(file.errorString())), Helper::scriptingKind, Helper::errorLevel)); - return false; - } -} - /*! * \brief LibraryWidget::saveModelicaLibraryTreeItem * Saves a Modelica LibraryTreeItem. @@ -3303,7 +3357,7 @@ bool LibraryWidget::saveModelicaLibraryTreeItemOneFile(LibraryTreeItem *pLibrary } else { contents = pLibraryTreeItem->getClassText(mpLibraryTreeModel); } - if (saveFile(fileName, contents)) { + if (saveFile(fileName, contents, pLibraryTreeItem->hasBOM())) { /* mark the file as saved and update the labels. */ pLibraryTreeItem->setIsSaved(true); pLibraryTreeItem->setFileName(fileName); @@ -3398,7 +3452,7 @@ bool LibraryWidget::saveModelicaLibraryTreeItemFolder(LibraryTreeItem *pLibraryT } else { contents = pLibraryTreeItem->getClassText(mpLibraryTreeModel); } - if (saveFile(fileName, contents)) { + if (saveFile(fileName, contents, pLibraryTreeItem->hasBOM())) { /* mark the file as saved and update the labels. */ pLibraryTreeItem->setIsSaved(true); pLibraryTreeItem->setFileName(fileName); @@ -3445,18 +3499,7 @@ bool LibraryWidget::saveModelicaLibraryTreeItemFolder(LibraryTreeItem *pLibraryT contents.append(pLibraryTreeItem->child(i)->getName()).append("\n"); } // create a new package.order file - if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QTextStream textStream(&file); - textStream.setCodec(Helper::utf8.toStdString().data()); - textStream.setGenerateByteOrderMark(false); - textStream << contents; - file.close(); - } else { - mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, - GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED) - .arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE) - .arg(file.errorString())), Helper::scriptingKind, Helper::errorLevel)); - } + saveFile(QString("%1/package.order").arg(fileInfo.absoluteDir().absolutePath()), contents, pLibraryTreeItem->hasBOM()); return true; } @@ -3480,13 +3523,7 @@ bool LibraryWidget::saveTextLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) fileName = pLibraryTreeItem->getFileName(); } - QFile file(fileName); - if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QTextStream textStream(&file); - textStream.setCodec(Helper::utf8.toStdString().data()); - textStream.setGenerateByteOrderMark(false); - textStream << pLibraryTreeItem->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText(); - file.close(); + if (saveFile(fileName, pLibraryTreeItem->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText(), pLibraryTreeItem->hasBOM())) { /* mark the file as saved and update the labels. */ pLibraryTreeItem->setIsSaved(true); pLibraryTreeItem->setFileName(fileName); @@ -3495,8 +3532,6 @@ bool LibraryWidget::saveTextLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) pLibraryTreeItem->getModelWidget()->setModelFilePathLabel(fileName); } } else { - QMessageBox::information(this, Helper::applicationName + " - " + Helper::error, GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED) - .arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE).arg(file.errorString())), Helper::ok); return false; } return true; @@ -3543,13 +3578,7 @@ bool LibraryWidget::saveAsMetaModelLibraryTreeItem(LibraryTreeItem *pLibraryTree */ bool LibraryWidget::saveMetaModelLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem, QString fileName) { - QFile file(fileName); - if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QTextStream textStream(&file); - textStream.setCodec(Helper::utf8.toStdString().data()); - textStream.setGenerateByteOrderMark(false); - textStream << pLibraryTreeItem->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText(); - file.close(); + if (saveFile(fileName, pLibraryTreeItem->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText(), pLibraryTreeItem->hasBOM())) { /* mark the file as saved and update the labels. */ pLibraryTreeItem->setIsSaved(true); QString oldMetaModelFile = pLibraryTreeItem->getFileName(); @@ -3590,8 +3619,6 @@ bool LibraryWidget::saveMetaModelLibraryTreeItem(LibraryTreeItem *pLibraryTreeIt QFile::copy(modelFileInfo.absoluteFilePath(), newFileName); } } else { - QMessageBox::information(this, Helper::applicationName + " - " + Helper::error, GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED) - .arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE).arg(file.errorString())), Helper::ok); return false; } return true; diff --git a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h index c54dc1ab93f..5c8b3c6a266 100644 --- a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h +++ b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h @@ -127,6 +127,8 @@ class LibraryTreeItem : public QObject bool isExpanded() const {return mExpanded;} void setNonExisting(bool nonExisting) {mNonExisting = nonExisting;} bool isNonExisting() const {return mNonExisting;} + void setHasBOM(bool hasBOM) {mHasBOM = hasBOM;} + bool hasBOM() const {return mHasBOM;} void updateAttributes(); QIcon getLibraryTreeItemIcon(); bool inRange(int lineNumber) {return (lineNumber >= mClassInformation.lineNumberStart) && (lineNumber <= mClassInformation.lineNumberEnd);} @@ -175,6 +177,9 @@ class LibraryTreeItem : public QObject QString mClassTextAfter; bool mExpanded; bool mNonExisting; + bool mHasBOM; + + void detectBOM(); signals: void loaded(LibraryTreeItem *pLibraryTreeItem); void loadedForComponent(); @@ -361,6 +366,7 @@ class LibraryWidget : public QWidget void openMetaModelOrTextFile(QFileInfo fileInfo, bool showProgress = true); bool parseMetaModelFile(QFileInfo fileInfo); void parseAndLoadModelicaText(QString modelText); + bool saveFile(QString fileName, QString contents, bool hasBOM); bool saveLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); void saveAsLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); bool saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); @@ -371,7 +377,6 @@ class LibraryWidget : public QWidget LibraryTreeModel *mpLibraryTreeModel; LibraryTreeProxyModel *mpLibraryTreeProxyModel; LibraryTreeView *mpLibraryTreeView; - bool saveFile(QString fileName, QString contents); bool saveModelicaLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem); bool saveModelicaLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem); bool saveModelicaLibraryTreeItemOneFile(LibraryTreeItem *pLibraryTreeItem); diff --git a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp index 534714e6e1b..3c581994752 100644 --- a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp +++ b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp @@ -2643,11 +2643,11 @@ void ModelWidget::createModelWidgetComponents() mpModelicaTypeLabel->setText(StringHandler::getModelicaClassType(mpLibraryTreeItem->getRestriction())); mpViewTypeLabel->setText(StringHandler::getViewType(StringHandler::Diagram)); // modelica text editor - mpEditor = new ModelicaTextEditor(this); - mpModelicaTextHighlighter = new ModelicaTextHighlighter(pMainWindow->getOptionsDialog()->getModelicaTextEditorPage(), + mpEditor = new ModelicaEditor(this); + mpModelicaTextHighlighter = new ModelicaTextHighlighter(pMainWindow->getOptionsDialog()->getModelicaEditorPage(), mpEditor->getPlainTextEdit()); - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(mpEditor); - pModelicaTextEditor->setPlainText(mpLibraryTreeItem->getClassText(pMainWindow->getLibraryWidget()->getLibraryTreeModel())); + ModelicaEditor *pModelicaEditor = dynamic_cast(mpEditor); + pModelicaEditor->setPlainText(mpLibraryTreeItem->getClassText(pMainWindow->getLibraryWidget()->getLibraryTreeModel())); mpEditor->hide(); // set it hidden so that Find/Replace action can get correct value. connect(pMainWindow->getOptionsDialog(), SIGNAL(modelicaTextSettingsChanged()), mpModelicaTextHighlighter, SLOT(settingsChanged())); mpModelStatusBar->addPermanentWidget(mpReadOnlyLabel, 0); @@ -2859,9 +2859,9 @@ void ModelWidget::reDrawModelWidget() */ bool ModelWidget::validateText(LibraryTreeItem **pLibraryTreeItem) { - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(mpEditor); - if (pModelicaTextEditor) { - return pModelicaTextEditor->validateText(pLibraryTreeItem); + ModelicaEditor *pModelicaEditor = dynamic_cast(mpEditor); + if (pModelicaEditor) { + return pModelicaEditor->validateText(pLibraryTreeItem); } MetaModelEditor *pMetaModelEditor = dynamic_cast(mpEditor); if (pMetaModelEditor) { @@ -2876,13 +2876,13 @@ bool ModelWidget::validateText(LibraryTreeItem **pLibraryTreeItem) * Updates the LibraryTreeItem and ModelWidget with new changes. * \param pLibraryTreeItem * \return - * \sa ModelicaTextEditor::getClassNames() + * \sa ModelicaEditor::getClassNames() */ bool ModelWidget::modelicaEditorTextChanged(LibraryTreeItem **pLibraryTreeItem) { QString errorString; - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(mpEditor); - QStringList classNames = pModelicaTextEditor->getClassNames(&errorString); + ModelicaEditor *pModelicaEditor = dynamic_cast(mpEditor); + QStringList classNames = pModelicaEditor->getClassNames(&errorString); LibraryTreeModel *pLibraryTreeModel = mpModelWidgetContainer->getMainWindow()->getLibraryWidget()->getLibraryTreeModel(); OMCProxy *pOMCProxy = mpModelWidgetContainer->getMainWindow()->getOMCProxy(); if (classNames.size() == 0) { @@ -2894,7 +2894,7 @@ bool ModelWidget::modelicaEditorTextChanged(LibraryTreeItem **pLibraryTreeItem) } /* if no errors are found with the Modelica Text then load it in OMC */ QString className = classNames.at(0); - QString modelicaText = pModelicaTextEditor->getPlainText(); + QString modelicaText = pModelicaEditor->getPlainText(); QString stringToLoad; LibraryTreeItem *pParentLibraryTreeItem = mpModelWidgetContainer->getMainWindow()->getLibraryWidget()->getLibraryTreeModel()->getContainingFileParentLibraryTreeItem(mpLibraryTreeItem); if (pParentLibraryTreeItem != mpLibraryTreeItem) { @@ -2987,9 +2987,9 @@ void ModelWidget::updateChildClasses(LibraryTreeItem *pLibraryTreeItem) if (pChildLibraryTreeItem->getModelWidget()) { pChildLibraryTreeItem->getModelWidget()->reDrawModelWidget(); pLibraryTreeModel->readLibraryTreeItemClassText(pChildLibraryTreeItem); - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(pChildLibraryTreeItem->getModelWidget()->getEditor()); - if (pModelicaTextEditor) { - pModelicaTextEditor->setPlainText(pChildLibraryTreeItem->getClassText(pLibraryTreeModel)); + ModelicaEditor *pModelicaEditor = dynamic_cast(pChildLibraryTreeItem->getModelWidget()->getEditor()); + if (pModelicaEditor) { + pModelicaEditor->setPlainText(pChildLibraryTreeItem->getClassText(pLibraryTreeModel)); } } updateChildClasses(pChildLibraryTreeItem); @@ -4384,14 +4384,14 @@ void ModelWidgetContainer::printModel() // print the text of the model if it is visible if (pModelWidget->getEditor()->isVisible()) { - ModelicaTextEditor *pModelicaTextEditor = dynamic_cast(pModelWidget->getEditor()); + ModelicaEditor *pModelicaEditor = dynamic_cast(pModelWidget->getEditor()); // set print options if text is selected - if (pModelicaTextEditor->getPlainTextEdit()->textCursor().hasSelection()) { + if (pModelicaEditor->getPlainTextEdit()->textCursor().hasSelection()) { pPrintDialog->addEnabledOption(QAbstractPrintDialog::PrintSelection); } // open print dialog if (pPrintDialog->exec() == QDialog::Accepted) { - pModelicaTextEditor->getPlainTextEdit()->print(&printer); + pModelicaEditor->getPlainTextEdit()->print(&printer); } } else { // print the model Diagram/Icon diff --git a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h index 07ccea92c2e..a2dd213a1cd 100644 --- a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h +++ b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h @@ -52,7 +52,7 @@ #include "StringHandler.h" #include "Helper.h" #include "BaseEditor.h" -#include "ModelicaTextEditor.h" +#include "ModelicaEditor.h" #include "MetaModelEditor.h" #include "TextEditor.h" diff --git a/OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp b/OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp index 6ccd7838d35..59b8019161b 100644 --- a/OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp +++ b/OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp @@ -927,7 +927,7 @@ InformationDialog::InformationDialog(QString windowTitle, QString informationTex // instantiate the model QPlainTextEdit *pPlainTextEdit = new QPlainTextEdit(informationText); if (modelicaTextHighlighter) { - ModelicaTextHighlighter *pModelicaHighlighter = new ModelicaTextHighlighter(mpMainWindow->getOptionsDialog()->getModelicaTextEditorPage(), + ModelicaTextHighlighter *pModelicaHighlighter = new ModelicaTextHighlighter(mpMainWindow->getOptionsDialog()->getModelicaEditorPage(), pPlainTextEdit); Q_UNUSED(pModelicaHighlighter); } diff --git a/OMEdit/OMEditGUI/OMC/OMCProxy.cpp b/OMEdit/OMEditGUI/OMC/OMCProxy.cpp index 8bf7eb0860c..2bf6d2f47a8 100644 --- a/OMEdit/OMEditGUI/OMC/OMCProxy.cpp +++ b/OMEdit/OMEditGUI/OMC/OMCProxy.cpp @@ -1637,7 +1637,7 @@ QString OMCProxy::diffModelicaFileListings(QString before, QString after) QString escapedAfter = StringHandler::escapeString(after); QString result; // only use the diffModelicaFileListings when preserve text indentation settings is true - if (mpMainWindow->getOptionsDialog()->getModelicaTextEditorPage()->getPreserveTextIndentationCheckBox()->isChecked()) { + if (mpMainWindow->getOptionsDialog()->getModelicaEditorPage()->getPreserveTextIndentationCheckBox()->isChecked()) { sendCommand("diffModelicaFileListings(\"" + escapedBefore + "\", \"" + escapedAfter + "\", OpenModelica.Scripting.DiffFormat.plain)"); result = StringHandler::unparse(getResult()); printMessagesStringInternal(); diff --git a/OMEdit/OMEditGUI/OMEditGUI.pro b/OMEdit/OMEditGUI/OMEditGUI.pro index a5bdc5bb58a..1320de56f44 100644 --- a/OMEdit/OMEditGUI/OMEditGUI.pro +++ b/OMEdit/OMEditGUI/OMEditGUI.pro @@ -103,7 +103,7 @@ SOURCES += main.cpp \ Modeling/ModelicaClassDialog.cpp \ Options/OptionsDialog.cpp \ Editors/BaseEditor.cpp \ - Editors/ModelicaTextEditor.cpp \ + Editors/ModelicaEditor.cpp \ Editors/TransformationsEditor.cpp \ Editors/DebuggerSourceEditor.cpp \ Editors/TextEditor.cpp \ @@ -168,7 +168,7 @@ HEADERS += Util/Helper.h \ Modeling/ModelicaClassDialog.h \ Options/OptionsDialog.h \ Editors/BaseEditor.h \ - Editors/ModelicaTextEditor.h \ + Editors/ModelicaEditor.h \ Editors/TransformationsEditor.h \ Editors/DebuggerSourceEditor.h \ Editors/TextEditor.h \ diff --git a/OMEdit/OMEditGUI/Options/OptionsDialog.cpp b/OMEdit/OMEditGUI/Options/OptionsDialog.cpp index 86904d36527..40735b0951d 100644 --- a/OMEdit/OMEditGUI/Options/OptionsDialog.cpp +++ b/OMEdit/OMEditGUI/Options/OptionsDialog.cpp @@ -51,7 +51,10 @@ OptionsDialog::OptionsDialog(MainWindow *pMainWindow) mpMainWindow = pMainWindow; mpGeneralSettingsPage = new GeneralSettingsPage(this); mpLibrariesPage = new LibrariesPage(this); - mpModelicaTextEditorPage = new ModelicaTextEditorPage(this); + mpTextEditorPage = new TextEditorPage(this); + mpModelicaEditorPage = new ModelicaEditorPage(this); + connect(mpTextEditorPage->getFontFamilyComboBox(), SIGNAL(currentFontChanged(QFont)), mpModelicaEditorPage, SIGNAL(updatePreview())); + connect(mpTextEditorPage->getFontSizeSpinBox(), SIGNAL(valueChanged(double)), mpModelicaEditorPage, SIGNAL(updatePreview())); mpGraphicalViewsPage = new GraphicalViewsPage(this); mpSimulationPage = new SimulationPage(this); mpMessagesPage = new MessagesPage(this); @@ -64,6 +67,8 @@ OptionsDialog::OptionsDialog(MainWindow *pMainWindow) mpFMIPage = new FMIPage(this); mpTLMPage = new TLMPage(this); mpMetaModelEditorPage = new MetaModelEditorPage(this); + connect(mpTextEditorPage->getFontFamilyComboBox(), SIGNAL(currentFontChanged(QFont)), mpMetaModelEditorPage, SIGNAL(updatePreview())); + connect(mpTextEditorPage->getFontSizeSpinBox(), SIGNAL(valueChanged(double)), mpMetaModelEditorPage, SIGNAL(updatePreview())); // get the settings readSettings(); // set up the Options Dialog @@ -76,7 +81,8 @@ void OptionsDialog::readSettings() mpSettings->sync(); readGeneralSettings(); readLibrariesSettings(); - readModelicaTextSettings(); + readTextEditorSettings(); + readModelicaEditorSettings(); emit modelicaTextSettingsChanged(); readGraphicalViewsSettings(); readSimulationSettings(); @@ -202,61 +208,88 @@ void OptionsDialog::readLibrariesSettings() mpSettings->endGroup(); } -//! Reads the ModelicaText settings from omedit.ini -void OptionsDialog::readModelicaTextSettings() +/*! + * \brief OptionsDialog::readTextEditorSettings + * Reads the Text editor settings from omedit.ini + */ +void OptionsDialog::readTextEditorSettings() { - int currentIndex; + int index; + if (mpSettings->contains("textEditor/lineEnding")) { + index = mpTextEditorPage->getLineEndingComboBox()->findData(mpSettings->value("textEditor/lineEnding").toInt()); + if (index > -1) { + mpTextEditorPage->getLineEndingComboBox()->setCurrentIndex(index); + } + } + if (mpSettings->contains("textEditor/bom")) { + index = mpTextEditorPage->getBOMComboBox()->findData(mpSettings->value("textEditor/bom").toInt()); + if (index > -1) { + mpTextEditorPage->getBOMComboBox()->setCurrentIndex(index); + } + } if (mpSettings->contains("textEditor/tabPolicy")) { - currentIndex = mpModelicaTextEditorPage->getTabPolicyComboBox()->findData(mpSettings->value("textEditor/tabPolicy").toInt()); - mpModelicaTextEditorPage->getTabPolicyComboBox()->setCurrentIndex(currentIndex); + index = mpTextEditorPage->getTabPolicyComboBox()->findData(mpSettings->value("textEditor/tabPolicy").toInt()); + if (index > -1) { + mpTextEditorPage->getTabPolicyComboBox()->setCurrentIndex(index); + } } if (mpSettings->contains("textEditor/tabSize")) { - mpModelicaTextEditorPage->getTabSizeSpinBox()->setValue(mpSettings->value("textEditor/tabSize").toInt()); + mpTextEditorPage->getTabSizeSpinBox()->setValue(mpSettings->value("textEditor/tabSize").toInt()); } 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()); + mpTextEditorPage->getIndentSpinBox()->setValue(mpSettings->value("textEditor/indentSize").toInt()); } if (mpSettings->contains("textEditor/enableSyntaxHighlighting")) { - mpModelicaTextEditorPage->getSyntaxHighlightingCheckbox()->setChecked(mpSettings->value("textEditor/enableSyntaxHighlighting").toBool()); + mpTextEditorPage->getSyntaxHighlightingCheckbox()->setChecked(mpSettings->value("textEditor/enableSyntaxHighlighting").toBool()); } if (mpSettings->contains("textEditor/matchParenthesesCommentsQuotes")) { - mpModelicaTextEditorPage->getMatchParenthesesCommentsQuotesCheckBox()->setChecked(mpSettings->value("textEditor/matchParenthesesCommentsQuotes").toBool()); + mpTextEditorPage->getMatchParenthesesCommentsQuotesCheckBox()->setChecked(mpSettings->value("textEditor/matchParenthesesCommentsQuotes").toBool()); } if (mpSettings->contains("textEditor/enableLineWrapping")) { - mpModelicaTextEditorPage->getLineWrappingCheckbox()->setChecked(mpSettings->value("textEditor/enableLineWrapping").toBool()); + mpTextEditorPage->getLineWrappingCheckbox()->setChecked(mpSettings->value("textEditor/enableLineWrapping").toBool()); } if (mpSettings->contains("textEditor/fontFamily")) { // select font family item - currentIndex = mpModelicaTextEditorPage->getFontFamilyComboBox()->findText(mpSettings->value("textEditor/fontFamily").toString(), Qt::MatchExactly); - mpModelicaTextEditorPage->getFontFamilyComboBox()->setCurrentIndex(currentIndex); + index = mpTextEditorPage->getFontFamilyComboBox()->findText(mpSettings->value("textEditor/fontFamily").toString(), Qt::MatchExactly); + if (index > -1) { + mpTextEditorPage->getFontFamilyComboBox()->setCurrentIndex(index); + } } if (mpSettings->contains("textEditor/fontSize")) { // select font size item - mpModelicaTextEditorPage->getFontSizeSpinBox()->setValue(mpSettings->value("textEditor/fontSize").toDouble()); + mpTextEditorPage->getFontSizeSpinBox()->setValue(mpSettings->value("textEditor/fontSize").toDouble()); } - if (mpSettings->contains("textEditor/textRuleColor")) { - mpModelicaTextEditorPage->setTextRuleColor(QColor(mpSettings->value("textEditor/textRuleColor").toUInt())); +} + +/*! + * \brief OptionsDialog::readModelicaEditorSettings + * Reads the ModelicaEditor settings from omedit.ini + */ +void OptionsDialog::readModelicaEditorSettings() +{ + if (mpSettings->contains("modelicaEditor/preserveTextIndentation")) { + mpModelicaEditorPage->getPreserveTextIndentationCheckBox()->setChecked(mpSettings->value("modelicaEditor/preserveTextIndentation").toBool()); + } + if (mpSettings->contains("modelicaEditor/textRuleColor")) { + mpModelicaEditorPage->setTextRuleColor(QColor(mpSettings->value("modelicaEditor/textRuleColor").toUInt())); } - if (mpSettings->contains("textEditor/keywordRuleColor")) { - mpModelicaTextEditorPage->setKeywordRuleColor(QColor(mpSettings->value("textEditor/keywordRuleColor").toUInt())); + if (mpSettings->contains("modelicaEditor/keywordRuleColor")) { + mpModelicaEditorPage->setKeywordRuleColor(QColor(mpSettings->value("modelicaEditor/keywordRuleColor").toUInt())); } - if (mpSettings->contains("textEditor/typeRuleColor")) { - mpModelicaTextEditorPage->setTypeRuleColor(QColor(mpSettings->value("textEditor/typeRuleColor").toUInt())); + if (mpSettings->contains("modelicaEditor/typeRuleColor")) { + mpModelicaEditorPage->setTypeRuleColor(QColor(mpSettings->value("modelicaEditor/typeRuleColor").toUInt())); } - if (mpSettings->contains("textEditor/functionRuleColor")) { - mpModelicaTextEditorPage->setFunctionRuleColor(QColor(mpSettings->value("textEditor/functionRuleColor").toUInt())); + if (mpSettings->contains("modelicaEditor/functionRuleColor")) { + mpModelicaEditorPage->setFunctionRuleColor(QColor(mpSettings->value("modelicaEditor/functionRuleColor").toUInt())); } - if (mpSettings->contains("textEditor/quotesRuleColor")) { - mpModelicaTextEditorPage->setQuotesRuleColor(QColor(mpSettings->value("textEditor/quotesRuleColor").toUInt())); + if (mpSettings->contains("modelicaEditor/quotesRuleColor")) { + mpModelicaEditorPage->setQuotesRuleColor(QColor(mpSettings->value("modelicaEditor/quotesRuleColor").toUInt())); } - if (mpSettings->contains("textEditor/commentRuleColor")) { - mpModelicaTextEditorPage->setCommentRuleColor(QColor(mpSettings->value("textEditor/commentRuleColor").toUInt())); + if (mpSettings->contains("modelicaEditor/commentRuleColor")) { + mpModelicaEditorPage->setCommentRuleColor(QColor(mpSettings->value("modelicaEditor/commentRuleColor").toUInt())); } - if (mpSettings->contains("textEditor/numberRuleColor")) { - mpModelicaTextEditorPage->setNumberRuleColor(QColor(mpSettings->value("textEditor/numberRuleColor").toUInt())); + if (mpSettings->contains("modelicaEditor/numberRuleColor")) { + mpModelicaEditorPage->setNumberRuleColor(QColor(mpSettings->value("modelicaEditor/numberRuleColor").toUInt())); } } @@ -572,43 +605,27 @@ void OptionsDialog::readTLMSettings() } } -//! Reads the MetaModelEditor settings from omedit.ini +/*! + * \brief OptionsDialog::readMetaModelEditorSettings + * Reads the MetaModelEditor settings from omedit.ini + */ void OptionsDialog::readMetaModelEditorSettings() { - int currentIndex; - if (mpSettings->contains("MetaModelEditor/tabPolicy")) { - currentIndex = mpMetaModelEditorPage->getTabPolicyComboBox()->findData(mpSettings->value("MetaModelEditor/tabPolicy").toInt()); - mpMetaModelEditorPage->getTabPolicyComboBox()->setCurrentIndex(currentIndex); - } - if (mpSettings->contains("MetaModelEditor/tabSize")) { - mpMetaModelEditorPage->getTabSizeSpinBox()->setValue(mpSettings->value("MetaModelEditor/tabSize").toInt()); - } - if (mpSettings->contains("MetaModelEditor/indentSize")) { - mpMetaModelEditorPage->getIndentSpinBox()->setValue(mpSettings->value("MetaModelEditor/indentSize").toInt()); - } - if (mpSettings->contains("MetaModelEditor/enableSyntaxHighlighting")) { - mpMetaModelEditorPage->getSyntaxHighlightingCheckbox()->setChecked(mpSettings->value("MetaModelEditor/enableSyntaxHighlighting").toBool()); - } - if (mpSettings->contains("MetaModelEditor/enableLineWrapping")) { - mpMetaModelEditorPage->getLineWrappingCheckbox()->setChecked(mpSettings->value("MetaModelEditor/enableLineWrapping").toBool()); - } - if (mpSettings->contains("MetaModelEditor/fontFamily")){ - // select font family item - currentIndex = mpMetaModelEditorPage->getFontFamilyComboBox()->findText(mpSettings->value("MetaModelEditor/fontFamily").toString(), Qt::MatchExactly); - mpMetaModelEditorPage->getFontFamilyComboBox()->setCurrentIndex(currentIndex); - } - if (mpSettings->contains("MetaModelEditor/fontSize")) - mpMetaModelEditorPage->getFontSizeSpinBox()->setValue(mpSettings->value("MetaModelEditor/fontSize").toDouble()); - if (mpSettings->contains("MetaModelEditor/textRuleColor")) + if (mpSettings->contains("MetaModelEditor/textRuleColor")) { mpMetaModelEditorPage->setTextRuleColor(QColor(mpSettings->value("MetaModelEditor/textRuleColor").toUInt())); - if (mpSettings->contains("MetaModelEditor/commentRuleColor")) + } + if (mpSettings->contains("MetaModelEditor/commentRuleColor")) { mpMetaModelEditorPage->setCommentRuleColor(QColor(mpSettings->value("MetaModelEditor/commentRuleColor").toUInt())); - if (mpSettings->contains("MetaModelEditor/tagRuleColor")) + } + if (mpSettings->contains("MetaModelEditor/tagRuleColor")) { mpMetaModelEditorPage->setTagRuleColor(QColor(mpSettings->value("MetaModelEditor/tagRuleColor").toUInt())); - if (mpSettings->contains("MetaModelEditor/quotesRuleColor")) + } + if (mpSettings->contains("MetaModelEditor/quotesRuleColor")) { mpMetaModelEditorPage->setQuotesRuleColor(QColor(mpSettings->value("MetaModelEditor/quotesRuleColor").toUInt())); - if (mpSettings->contains("MetaModelEditor/elementsRuleColor")) + } + if (mpSettings->contains("MetaModelEditor/elementsRuleColor")) { mpMetaModelEditorPage->setElementRuleColor(QColor(mpSettings->value("MetaModelEditor/elementsRuleColor").toUInt())); + } } //! Saves the General section settings to omedit.ini @@ -713,25 +730,38 @@ void OptionsDialog::saveLibrariesSettings() mpSettings->endGroup(); } -//! Saves the ModelicaText settings to omedit.ini -void OptionsDialog::saveModelicaTextSettings() +/*! + * \brief OptionsDialog::saveTextEditorSettings + * Saves the TextEditor settings to omedit.ini + */ +void OptionsDialog::saveTextEditorSettings() { - 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()); - mpSettings->setValue("textEditor/fontFamily", mpModelicaTextEditorPage->getFontFamilyComboBox()->currentFont().family()); - mpSettings->setValue("textEditor/fontSize", mpModelicaTextEditorPage->getFontSizeSpinBox()->value()); - mpSettings->setValue("textEditor/textRuleColor", mpModelicaTextEditorPage->getTextRuleColor().rgba()); - mpSettings->setValue("textEditor/keywordRuleColor", mpModelicaTextEditorPage->getKeywordRuleColor().rgba()); - mpSettings->setValue("textEditor/typeRuleColor", mpModelicaTextEditorPage->getTypeRuleColor().rgba()); - mpSettings->setValue("textEditor/functionRuleColor", mpModelicaTextEditorPage->getFunctionRuleColor().rgba()); - mpSettings->setValue("textEditor/quotesRuleColor", mpModelicaTextEditorPage->getQuotesRuleColor().rgba()); - mpSettings->setValue("textEditor/commentRuleColor", mpModelicaTextEditorPage->getCommentRuleColor().rgba()); - mpSettings->setValue("textEditor/numberRuleColor", mpModelicaTextEditorPage->getNumberRuleColor().rgba()); + mpSettings->setValue("textEditor/lineEnding", mpTextEditorPage->getLineEndingComboBox()->itemData(mpTextEditorPage->getLineEndingComboBox()->currentIndex()).toInt()); + mpSettings->setValue("textEditor/bom", mpTextEditorPage->getBOMComboBox()->itemData(mpTextEditorPage->getBOMComboBox()->currentIndex()).toInt()); + mpSettings->setValue("textEditor/tabPolicy", mpTextEditorPage->getTabPolicyComboBox()->itemData(mpTextEditorPage->getTabPolicyComboBox()->currentIndex()).toInt()); + mpSettings->setValue("textEditor/tabSize", mpTextEditorPage->getTabSizeSpinBox()->value()); + mpSettings->setValue("textEditor/indentSize", mpTextEditorPage->getIndentSpinBox()->value()); + mpSettings->setValue("textEditor/enableSyntaxHighlighting", mpTextEditorPage->getSyntaxHighlightingCheckbox()->isChecked()); + mpSettings->setValue("textEditor/matchParenthesesCommentsQuotes", mpTextEditorPage->getMatchParenthesesCommentsQuotesCheckBox()->isChecked()); + mpSettings->setValue("textEditor/enableLineWrapping", mpTextEditorPage->getLineWrappingCheckbox()->isChecked()); + mpSettings->setValue("textEditor/fontFamily", mpTextEditorPage->getFontFamilyComboBox()->currentFont().family()); + mpSettings->setValue("textEditor/fontSize", mpTextEditorPage->getFontSizeSpinBox()->value()); +} + +/*! + * \brief OptionsDialog::saveModelicaEditorSettings + * Saves the ModelicaEditor settings to omedit.ini + */ +void OptionsDialog::saveModelicaEditorSettings() +{ + mpSettings->setValue("modelicaEditor/preserveTextIndentation", mpModelicaEditorPage->getPreserveTextIndentationCheckBox()->isChecked()); + mpSettings->setValue("modelicaEditor/textRuleColor", mpModelicaEditorPage->getTextRuleColor().rgba()); + mpSettings->setValue("modelicaEditor/keywordRuleColor", mpModelicaEditorPage->getKeywordRuleColor().rgba()); + mpSettings->setValue("modelicaEditor/typeRuleColor", mpModelicaEditorPage->getTypeRuleColor().rgba()); + mpSettings->setValue("modelicaEditor/functionRuleColor", mpModelicaEditorPage->getFunctionRuleColor().rgba()); + mpSettings->setValue("modelicaEditor/quotesRuleColor", mpModelicaEditorPage->getQuotesRuleColor().rgba()); + mpSettings->setValue("modelicaEditor/commentRuleColor", mpModelicaEditorPage->getCommentRuleColor().rgba()); + mpSettings->setValue("modelicaEditor/numberRuleColor", mpModelicaEditorPage->getNumberRuleColor().rgba()); } //! Saves the GraphicsViews section settings to omedit.ini @@ -927,16 +957,12 @@ void OptionsDialog::saveTLMSettings() mpSettings->setValue("TLM/MonitorProcess", mpTLMPage->getTLMMonitorProcessTextBox()->text()); } -//! Saves the MetaModelEditor settings to omedit.ini +/*! + * \brief OptionsDialog::saveMetaModelEditorSettings + * Saves the MetaModelEditor settings to omedit.ini + */ void OptionsDialog::saveMetaModelEditorSettings() { - mpSettings->setValue("MetaModelEditor/tabPolicy", mpMetaModelEditorPage->getTabPolicyComboBox()->itemData(mpModelicaTextEditorPage->getTabPolicyComboBox()->currentIndex()).toInt()); - mpSettings->setValue("MetaModelEditor/tabSize", mpMetaModelEditorPage->getTabSizeSpinBox()->value()); - mpSettings->setValue("MetaModelEditor/indentSize", mpMetaModelEditorPage->getIndentSpinBox()->value()); - mpSettings->setValue("MetaModelEditor/enableSyntaxHighlighting", mpMetaModelEditorPage->getSyntaxHighlightingCheckbox()->isChecked()); - mpSettings->setValue("MetaModelEditor/enableLineWrapping", mpMetaModelEditorPage->getLineWrappingCheckbox()->isChecked()); - mpSettings->setValue("MetaModelEditor/fontFamily", mpMetaModelEditorPage->getFontFamilyComboBox()->currentFont().family()); - mpSettings->setValue("MetaModelEditor/fontSize", mpMetaModelEditorPage->getFontSizeSpinBox()->value()); mpSettings->setValue("MetaModelEditor/textRuleColor", mpMetaModelEditorPage->getTextRuleColor().rgba()); mpSettings->setValue("MetaModelEditor/commentRuleColor", mpMetaModelEditorPage->getCommentRuleColor().rgba()); mpSettings->setValue("MetaModelEditor/tagRuleColor", mpMetaModelEditorPage->getTagRuleColor().rgba()); @@ -1003,10 +1029,14 @@ void OptionsDialog::addListItems() QListWidgetItem *pLibrariesItem = new QListWidgetItem(mpOptionsList); pLibrariesItem->setIcon(QIcon(":/Resources/icons/libraries.svg")); pLibrariesItem->setText(Helper::libraries); - // Modelica Text Item - QListWidgetItem *pModelicaTextEditorItem = new QListWidgetItem(mpOptionsList); - pModelicaTextEditorItem->setIcon(QIcon(":/Resources/icons/modeltext.svg")); - pModelicaTextEditorItem->setText(tr("Modelica Text Editor")); + // Text Editor Item + QListWidgetItem *pTextEditorItem = new QListWidgetItem(mpOptionsList); + pTextEditorItem->setIcon(QIcon(":/Resources/icons/modeltext.svg")); + pTextEditorItem->setText(tr("Text Editor")); + // Modelica Editor Item + QListWidgetItem *pModelicaEditorItem = new QListWidgetItem(mpOptionsList); + pModelicaEditorItem->setIcon(QIcon(":/Resources/icons/modeltext.svg")); + pModelicaEditorItem->setText(tr("Modelica Editor")); // Graphical Views Item QListWidgetItem *pGraphicalViewsItem = new QListWidgetItem(mpOptionsList); pGraphicalViewsItem->setIcon(QIcon(":/Resources/icons/modeling.png")); @@ -1064,7 +1094,8 @@ void OptionsDialog::createPages() mpPagesWidget->setContentsMargins(5, 2, 5, 2); mpPagesWidget->addWidget(mpGeneralSettingsPage); mpPagesWidget->addWidget(mpLibrariesPage); - mpPagesWidget->addWidget(mpModelicaTextEditorPage); + mpPagesWidget->addWidget(mpTextEditorPage); + mpPagesWidget->addWidget(mpModelicaEditorPage); mpPagesWidget->addWidget(mpGraphicalViewsPage); mpPagesWidget->addWidget(mpSimulationPage); mpPagesWidget->addWidget(mpMessagesPage); @@ -1091,8 +1122,9 @@ void OptionsDialog::saveDialogGeometry() } /*! - Reimplementation of QDialog::show method. - */ + * \brief OptionsDialog::show + * Reimplementation of QDialog::show method. + */ void OptionsDialog::show() { /* restore the window geometry. */ @@ -1102,24 +1134,26 @@ void OptionsDialog::show() setVisible(true); } -TabSettings OptionsDialog::getModelicaTabSettings() +/*! + * \brief OptionsDialog::getTabSettings + * Returns a TabSettings + * \return + */ +TabSettings OptionsDialog::getTabSettings() { TabSettings tabSettings; - tabSettings.setTabPolicy(mpModelicaTextEditorPage->getTabPolicyComboBox()->itemData(mpModelicaTextEditorPage->getTabPolicyComboBox()->currentIndex()).toInt()); - tabSettings.setTabSize(mpModelicaTextEditorPage->getTabSizeSpinBox()->value()); - tabSettings.setIndentSize(mpModelicaTextEditorPage->getIndentSpinBox()->value()); + tabSettings.setTabPolicy(mpTextEditorPage->getTabPolicyComboBox()->itemData(mpTextEditorPage->getTabPolicyComboBox()->currentIndex()).toInt()); + tabSettings.setTabSize(mpTextEditorPage->getTabSizeSpinBox()->value()); + tabSettings.setIndentSize(mpTextEditorPage->getIndentSpinBox()->value()); return tabSettings; } -TabSettings OptionsDialog::getMetaModelTabSettings() -{ - TabSettings tabSettings; - tabSettings.setTabPolicy(mpMetaModelEditorPage->getTabPolicyComboBox()->itemData(mpMetaModelEditorPage->getTabPolicyComboBox()->currentIndex()).toInt()); - tabSettings.setTabSize(mpMetaModelEditorPage->getTabSizeSpinBox()->value()); - tabSettings.setIndentSize(mpMetaModelEditorPage->getIndentSpinBox()->value()); - return tabSettings; -} -//! Change the page in Options Widget when the mpOptionsList currentItemChanged Signal is raised. +/*! + * \brief OptionsDialog::changePage + * Change the page in Options Widget when the mpOptionsList currentItemChanged Signal is raised. + * \param current + * \param previous + */ void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) { if (!current) { @@ -1142,7 +1176,8 @@ void OptionsDialog::saveSettings() { saveGeneralSettings(); saveLibrariesSettings(); - saveModelicaTextSettings(); + saveTextEditorSettings(); + saveModelicaEditorSettings(); // emit the signal so that all syntax highlighters are updated emit modelicaTextSettingsChanged(); saveGraphicalViewsSettings(); @@ -1917,15 +1952,48 @@ void AddUserLibraryDialog::addUserLibrary() accept(); } -//! @class ModelicaTextEditorPage -//! @brief Creates an interface for Modelica Text settings. - -//! Constructor -//! @param pOptionsDialog is the pointer to OptionsDialog -ModelicaTextEditorPage::ModelicaTextEditorPage(OptionsDialog *pOptionsDialog) +/*! + * \class TextEditorPage + * \brief Creates an interface for Text Editor settings. + */ +/*! + * \brief TextEditorPage::TextEditorPage + * \param pOptionsDialog is the pointer to OptionsDialog + */ +TextEditorPage::TextEditorPage(OptionsDialog *pOptionsDialog) : QWidget(pOptionsDialog) { mpOptionsDialog = pOptionsDialog; + // format groupbox + mpFormatGroupBox = new QGroupBox(tr("Format")); + // line ending + mpLineEndingLabel = new Label(tr("Line Ending:")); + mpLineEndingComboBox = new QComboBox; + mpLineEndingComboBox->addItem(tr("Windows (CRLF)"), Utilities::CRLFLineEnding); + mpLineEndingComboBox->addItem(tr("Unix (LF)"), Utilities::LFLineEnding); +#ifndef WIN32 + mpLineEndingComboBox->setCurrentIndex(1); +#endif + // Byte Order Mark BOM + mpBOMLabel = new Label(tr("Byte Order Mark (BOM):")); + mpBOMComboBox = new QComboBox; + mpBOMComboBox->setToolTip(tr("" + "

Note that BOMs are uncommon and treated incorrectly by some editors, so it usually makes little sense to add any.

" + "
  • Always Add: always add a BOM when saving a file.
  • " + "
  • Keep If Already Present: save the file with a BOM if it already had one when it was loaded.
  • " + "
  • Always Delete: never write a BOM, possibly deleting a pre-existing one.
" + "")); + mpBOMComboBox->addItem(tr("Always Add"), Utilities::AlwaysAddBom); + mpBOMComboBox->addItem(tr("Keep If Already Present"), Utilities::KeepBom); + mpBOMComboBox->addItem(tr("Always Delete"), Utilities::AlwaysDeleteBom); + mpBOMComboBox->setCurrentIndex(1); + // set format groupbox layout + QGridLayout *pFormatGroupBoxLayout = new QGridLayout; + pFormatGroupBoxLayout->addWidget(mpLineEndingLabel, 0, 0); + pFormatGroupBoxLayout->addWidget(mpLineEndingComboBox, 0, 1); + pFormatGroupBoxLayout->addWidget(mpBOMLabel, 1, 0); + pFormatGroupBoxLayout->addWidget(mpBOMComboBox, 1, 1); + mpFormatGroupBox->setLayout(pFormatGroupBoxLayout); // tabs and indentation groupbox mpTabsAndIndentation = new QGroupBox(tr("Tabs and Indentation")); // tab policy @@ -1943,9 +2011,6 @@ 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); @@ -1954,7 +2019,6 @@ 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")); @@ -1966,29 +2030,103 @@ ModelicaTextEditorPage::ModelicaTextEditorPage(OptionsDialog *pOptionsDialog) // line wrap checkbox mpLineWrappingCheckbox = new QCheckBox(tr("Enable Line Wrapping")); mpLineWrappingCheckbox->setChecked(true); - connect(mpLineWrappingCheckbox, SIGNAL(toggled(bool)), this, SLOT(setLineWrapping())); // set Syntax Highlight & Text Wrapping groupbox layout QGridLayout *pSyntaxHighlightAndTextWrappingGroupBoxLayout = new QGridLayout; pSyntaxHighlightAndTextWrappingGroupBoxLayout->addWidget(mpSyntaxHighlightingCheckbox, 0, 0); pSyntaxHighlightAndTextWrappingGroupBoxLayout->addWidget(mpMatchParenthesesCommentsQuotesCheckBox, 1, 0); pSyntaxHighlightAndTextWrappingGroupBoxLayout->addWidget(mpLineWrappingCheckbox, 2, 0); mpSyntaxHighlightAndTextWrappingGroupBox->setLayout(pSyntaxHighlightAndTextWrappingGroupBoxLayout); - // fonts & colors groupbox - mpFontColorsGroupBox = new QGroupBox(Helper::fontAndColors); + // font groupbox + mpFontGroupBox = new QGroupBox(tr("Font")); // font family combobox mpFontFamilyLabel = new Label(Helper::fontFamily); mpFontFamilyComboBox = new QFontComboBox; int currentIndex; currentIndex = mpFontFamilyComboBox->findText(Helper::monospacedFontInfo.family(), Qt::MatchExactly); mpFontFamilyComboBox->setCurrentIndex(currentIndex); - connect(mpFontFamilyComboBox, SIGNAL(currentFontChanged(QFont)), SIGNAL(updatePreview())); // font size combobox mpFontSizeLabel = new Label(Helper::fontSize); mpFontSizeSpinBox = new DoubleSpinBox; mpFontSizeSpinBox->setRange(6, std::numeric_limits::max()); mpFontSizeSpinBox->setValue(Helper::monospacedFontInfo.pointSizeF()); mpFontSizeSpinBox->setSingleStep(1); - connect(mpFontSizeSpinBox, SIGNAL(valueChanged(double)), SIGNAL(updatePreview())); + // set font groupbox layout + QGridLayout *pFontGroupBoxLayout = new QGridLayout; + pFontGroupBoxLayout->addWidget(mpFontFamilyLabel, 0, 0); + pFontGroupBoxLayout->addWidget(mpFontSizeLabel, 0, 1); + pFontGroupBoxLayout->addWidget(mpFontFamilyComboBox, 1, 0); + pFontGroupBoxLayout->addWidget(mpFontSizeSpinBox, 1, 1); + mpFontGroupBox->setLayout(pFontGroupBoxLayout); + // set the layout + QVBoxLayout *pMainLayout = new QVBoxLayout; + pMainLayout->setContentsMargins(0, 0, 0, 0); + pMainLayout->setAlignment(Qt::AlignTop); + pMainLayout->addWidget(mpFormatGroupBox); + pMainLayout->addWidget(mpTabsAndIndentation); + pMainLayout->addWidget(mpSyntaxHighlightAndTextWrappingGroupBox); + pMainLayout->addWidget(mpFontGroupBox); + setLayout(pMainLayout); +} + +PreviewPlainTextEdit::PreviewPlainTextEdit(QWidget *parent) + : QPlainTextEdit(parent) +{ + QTextDocument *pTextDocument = document(); + pTextDocument->setDocumentMargin(2); + BaseEditorDocumentLayout *pModelicaTextDocumentLayout = new BaseEditorDocumentLayout(pTextDocument); + pTextDocument->setDocumentLayout(pModelicaTextDocumentLayout); + setDocument(pTextDocument); + // parentheses matcher + mParenthesesMatchFormat = Utilities::getParenthesesMatchFormat(); + mParenthesesMisMatchFormat = Utilities::getParenthesesMisMatchFormat(); + + updateHighlights(); + connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateHighlights())); +} + +/*! + * \brief PreviewPlainTextEdit::highlightCurrentLine + * Hightlights the current line. + */ +void PreviewPlainTextEdit::highlightCurrentLine() +{ + Utilities::highlightCurrentLine(this); +} + +/*! + * \brief PreviewPlainTextEdit::highlightParentheses + * Highlights the matching parentheses. + */ +void PreviewPlainTextEdit::highlightParentheses() +{ + Utilities::highlightParentheses(this, mParenthesesMatchFormat, mParenthesesMisMatchFormat); +} + +void PreviewPlainTextEdit::updateHighlights() +{ + QList selections; + setExtraSelections(selections); + highlightCurrentLine(); + highlightParentheses(); +} + +/*! + * \class ModelicaEditorPage + * \brief Creates an interface for Modelica Text settings. + */ +/*! + * \brief ModelicaEditorPage::ModelicaEditorPage + * \param pOptionsDialog is the pointer to OptionsDialog + */ +ModelicaEditorPage::ModelicaEditorPage(OptionsDialog *pOptionsDialog) + : QWidget(pOptionsDialog) +{ + mpOptionsDialog = pOptionsDialog; + // preserve text indentation + mpPreserveTextIndentationCheckBox = new QCheckBox(tr("Preserve Text Indentation")); + mpPreserveTextIndentationCheckBox->setChecked(true); + // colors groupbox + mpColorsGroupBox = new QGroupBox(Helper::Colors); // Item color label and pick color button mpItemColorLabel = new Label(tr("Item Color:")); mpItemColorPickButton = new QPushButton(Helper::pickColor); @@ -2005,8 +2143,8 @@ ModelicaTextEditorPage::ModelicaTextEditorPage(OptionsDialog *pOptionsDialog) mpItemsList->setCurrentRow(0, QItemSelectionModel::Select); // preview textbox mpPreviewLabel = new Label(tr("Preview:")); - mpPreviewPlainTextBox = new QPlainTextEdit; - mpPreviewPlainTextBox->setTabStopWidth(Helper::tabWidth); + mpPreviewPlainTextEdit = new PreviewPlainTextEdit; + mpPreviewPlainTextEdit->setTabStopWidth(Helper::tabWidth); QString previewText; previewText.append("class HelloWorld /* block\n" "comment */\n" @@ -2017,38 +2155,36 @@ ModelicaTextEditorPage::ModelicaTextEditorPage(OptionsDialog *pOptionsDialog) "equation\n" "\tder(x) = - a * x;\n" "end HelloWorld;\n"); - mpPreviewPlainTextBox->setPlainText(previewText); + mpPreviewPlainTextEdit->setPlainText(previewText); // highlight preview textbox - ModelicaTextHighlighter *pModelicaTextHighlighter = new ModelicaTextHighlighter(this, mpPreviewPlainTextBox); + ModelicaTextHighlighter *pModelicaTextHighlighter = new ModelicaTextHighlighter(this, mpPreviewPlainTextEdit); connect(this, SIGNAL(updatePreview()), pModelicaTextHighlighter, SLOT(settingsChanged())); - connect(mpSyntaxHighlightingCheckbox, SIGNAL(toggled(bool)), pModelicaTextHighlighter, SLOT(settingsChanged())); - connect(mpMatchParenthesesCommentsQuotesCheckBox, SIGNAL(toggled(bool)), pModelicaTextHighlighter, SLOT(settingsChanged())); - // set fonts & colors groupbox layout - QGridLayout *pFontsColorsGroupBoxLayout = new QGridLayout; - pFontsColorsGroupBoxLayout->addWidget(mpFontFamilyLabel, 0, 0); - pFontsColorsGroupBoxLayout->addWidget(mpFontSizeLabel, 0, 1); - pFontsColorsGroupBoxLayout->addWidget(mpFontFamilyComboBox, 1, 0); - pFontsColorsGroupBoxLayout->addWidget(mpFontSizeSpinBox, 1, 1); - pFontsColorsGroupBoxLayout->addWidget(mpItemsLabel, 2, 0); - pFontsColorsGroupBoxLayout->addWidget(mpItemColorLabel, 2, 1); - pFontsColorsGroupBoxLayout->addWidget(mpItemsList, 3, 0); - pFontsColorsGroupBoxLayout->addWidget(mpItemColorPickButton, 3, 1, Qt::AlignTop); - pFontsColorsGroupBoxLayout->addWidget(mpPreviewLabel, 4, 0, 1, 2); - pFontsColorsGroupBoxLayout->addWidget(mpPreviewPlainTextBox, 5, 0, 1, 2); - mpFontColorsGroupBox->setLayout(pFontsColorsGroupBoxLayout); + connect(mpOptionsDialog->getTextEditorPage()->getSyntaxHighlightingCheckbox(), SIGNAL(toggled(bool)), + pModelicaTextHighlighter, SLOT(settingsChanged())); + connect(mpOptionsDialog->getTextEditorPage()->getMatchParenthesesCommentsQuotesCheckBox(), SIGNAL(toggled(bool)), + pModelicaTextHighlighter, SLOT(settingsChanged())); + connect(mpOptionsDialog->getTextEditorPage()->getLineWrappingCheckbox(), SIGNAL(toggled(bool)), this, SLOT(setLineWrapping(bool))); + // set colors groupbox layout + QGridLayout *pColorsGroupBoxLayout = new QGridLayout; + pColorsGroupBoxLayout->addWidget(mpItemsLabel, 1, 0); + pColorsGroupBoxLayout->addWidget(mpItemColorLabel, 1, 1); + pColorsGroupBoxLayout->addWidget(mpItemsList, 2, 0); + pColorsGroupBoxLayout->addWidget(mpItemColorPickButton, 2, 1, Qt::AlignTop); + pColorsGroupBoxLayout->addWidget(mpPreviewLabel, 3, 0, 1, 2); + pColorsGroupBoxLayout->addWidget(mpPreviewPlainTextEdit, 4, 0, 1, 2); + mpColorsGroupBox->setLayout(pColorsGroupBoxLayout); // set the layout QVBoxLayout *pMainLayout = new QVBoxLayout; pMainLayout->setContentsMargins(0, 0, 0, 0); - pMainLayout->addWidget(mpTabsAndIndentation); - pMainLayout->addWidget(mpSyntaxHighlightAndTextWrappingGroupBox); - pMainLayout->addWidget(mpFontColorsGroupBox); + pMainLayout->addWidget(mpPreserveTextIndentationCheckBox); + pMainLayout->addWidget(mpColorsGroupBox); setLayout(pMainLayout); } //! Adds the Modelica Text settings rules to the mpItemsList. -void ModelicaTextEditorPage::addListItems() +void ModelicaEditorPage::addListItems() { - // don't change the Data of items as it is being used in ModelicaTextEditorPage::pickColor slot to identify the items + // don't change the Data of items as it is being used in ModelicaEditorPage::pickColor slot to identify the items // text mpTextItem = new QListWidgetItem(mpItemsList); mpTextItem->setText("Text"); @@ -2087,95 +2223,81 @@ void ModelicaTextEditorPage::addListItems() } /*! - * \brief ModelicaTextEditorPage::setTextRuleColor + * \brief ModelicaEditorPage::setTextRuleColor * \param color */ -void ModelicaTextEditorPage::setTextRuleColor(QColor color) +void ModelicaEditorPage::setTextRuleColor(QColor color) { mTextColor = color; mpTextItem->setForeground(color); } /*! - * \brief ModelicaTextEditorPage::setNumberRuleColor + * \brief ModelicaEditorPage::setNumberRuleColor * \param color */ -void ModelicaTextEditorPage::setNumberRuleColor(QColor color) +void ModelicaEditorPage::setNumberRuleColor(QColor color) { mNumberColor = color; mpNumberItem->setForeground(color); } /*! - * \brief ModelicaTextEditorPage::setKeywordRuleColor + * \brief ModelicaEditorPage::setKeywordRuleColor * \param color */ -void ModelicaTextEditorPage::setKeywordRuleColor(QColor color) +void ModelicaEditorPage::setKeywordRuleColor(QColor color) { mKeywordColor = color; mpKeywordItem->setForeground(color); } /*! - * \brief ModelicaTextEditorPage::setTypeRuleColor + * \brief ModelicaEditorPage::setTypeRuleColor * \param color */ -void ModelicaTextEditorPage::setTypeRuleColor(QColor color) +void ModelicaEditorPage::setTypeRuleColor(QColor color) { mTypeColor = color; mpTypeItem->setForeground(color); } /*! - * \brief ModelicaTextEditorPage::setFunctionRuleColor + * \brief ModelicaEditorPage::setFunctionRuleColor * \param color */ -void ModelicaTextEditorPage::setFunctionRuleColor(QColor color) +void ModelicaEditorPage::setFunctionRuleColor(QColor color) { mFunctionColor = color; mpFunctionItem->setForeground(color); } /*! - * \brief ModelicaTextEditorPage::setQuotesRuleColor + * \brief ModelicaEditorPage::setQuotesRuleColor * \param color */ -void ModelicaTextEditorPage::setQuotesRuleColor(QColor color) +void ModelicaEditorPage::setQuotesRuleColor(QColor color) { mQuotesColor = color; mpQuotesItem->setForeground(color); } /*! - * \brief ModelicaTextEditorPage::setCommentRuleColor + * \brief ModelicaEditorPage::setCommentRuleColor * \param color */ -void ModelicaTextEditorPage::setCommentRuleColor(QColor color) +void ModelicaEditorPage::setCommentRuleColor(QColor color) { mCommentColor = color; mpCommentItem->setForeground(color); } /*! - * \brief ModelicaTextEditorPage::setLineWrapping - * Slot activated when mpLineWrappingCheckbox toggled SIGNAL is raised. - * Sets the mpPreviewPlainTextBox line wrapping mode. - */ -void ModelicaTextEditorPage::setLineWrapping() -{ - if (mpLineWrappingCheckbox->isChecked()) { - mpPreviewPlainTextBox->setLineWrapMode(QPlainTextEdit::WidgetWidth); - } else { - mpPreviewPlainTextBox->setLineWrapMode(QPlainTextEdit::NoWrap); - } -} - -/*! - * \brief ModelicaTextEditorPage::pickColor + * \brief ModelicaEditorPage::pickColor * Picks a color for one of the Modelica Text Settings rules. * This method is called when mpColorPickButton clicked SIGNAL raised. */ -void ModelicaTextEditorPage::pickColor() +void ModelicaEditorPage::pickColor() { QListWidgetItem *item = mpItemsList->currentItem(); QColor initialColor; @@ -2218,6 +2340,20 @@ void ModelicaTextEditorPage::pickColor() emit updatePreview(); } +/*! + * \brief ModelicaEditorPage::setLineWrapping + * Slot activated when mpLineWrappingCheckbox toggled SIGNAL is raised. + * Sets the mpPreviewPlainTextBox line wrapping mode. + */ +void ModelicaEditorPage::setLineWrapping(bool enabled) +{ + if (enabled) { + mpPreviewPlainTextEdit->setLineWrapMode(QPlainTextEdit::WidgetWidth); + } else { + mpPreviewPlainTextEdit->setLineWrapMode(QPlainTextEdit::NoWrap); + } +} + GraphicalViewsPage::GraphicalViewsPage(OptionsDialog *pOptionsDialog) : QWidget(pOptionsDialog) { @@ -2761,7 +2897,7 @@ MessagesPage::MessagesPage(OptionsDialog *pOptionsDialog) pGeneralGroupBoxLayout->addWidget(mpResetMessagesNumberBeforeSimulationCheckBox, 1, 0, 1, 2); mpGeneralGroupBox->setLayout(pGeneralGroupBoxLayout); // Font and Colors - mpFontColorsGroupBox = new QGroupBox(Helper::fontAndColors); + mpFontColorsGroupBox = new QGroupBox(Helper::Colors); // font family combobox mpFontFamilyLabel = new Label(Helper::fontFamily); mpFontFamilyComboBox = new QFontComboBox; @@ -3732,72 +3868,20 @@ void TLMPage::browseTLMMonitorProcess() mpTLMMonitorProcessTextBox->setText(StringHandler::getOpenFileName(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFile), NULL, Helper::exeFileTypes, NULL)); } - -//! @class MetaModelEditorPage -//! @brief Creates an interface for MetaModel Text settings. - -//! Constructor -//! @param pOptionsDialog is the pointer to OptionsDialog +/*! + * \class MetaModelEditorPage + * \brief Creates an interface for MetaModel Text settings. + */ +/*! + * \brief MetaModelEditorPage::MetaModelEditorPage + * \param pOptionsDialog is the pointer to OptionsDialog + */ MetaModelEditorPage::MetaModelEditorPage(OptionsDialog *pOptionsDialog) : QWidget(pOptionsDialog) { mpOptionsDialog = pOptionsDialog; - // tabs and indentation groupbox - mpTabsAndIndentation = new QGroupBox(tr("Tabs and Indentation")); - // tab policy - mpTabPolicyLabel = new Label(tr("Tab Policy:")); - mpTabPolicyComboBox = new QComboBox; - mpTabPolicyComboBox->addItem(tr("Spaces Only"), 0); - mpTabPolicyComboBox->addItem(tr("Tabs Only"), 1); - // tab size - mpTabSizeLabel = new Label(tr("Tab Size:")); - mpTabSizeSpinBox = new QSpinBox; - mpTabSizeSpinBox->setRange(1, 20); - mpTabSizeSpinBox->setValue(4); - // indent size - mpIndentSizeLabel = new Label(tr("Indent Size:")); - mpIndentSpinBox = new QSpinBox; - mpIndentSpinBox->setRange(1, 20); - mpIndentSpinBox->setValue(2); - // set tabs & indentation groupbox layout - QGridLayout *pTabsAndIndentationGroupBoxLayout = new QGridLayout; - pTabsAndIndentationGroupBoxLayout->addWidget(mpTabPolicyLabel, 0, 0); - pTabsAndIndentationGroupBoxLayout->addWidget(mpTabPolicyComboBox, 0, 1); - pTabsAndIndentationGroupBoxLayout->addWidget(mpTabSizeLabel, 1, 0); - pTabsAndIndentationGroupBoxLayout->addWidget(mpTabSizeSpinBox, 1, 1); - pTabsAndIndentationGroupBoxLayout->addWidget(mpIndentSizeLabel, 2, 0); - pTabsAndIndentationGroupBoxLayout->addWidget(mpIndentSpinBox, 2, 1); - mpTabsAndIndentation->setLayout(pTabsAndIndentationGroupBoxLayout); - // syntax highlight and text wrapping groupbox - mpSyntaxHighlightAndTextWrappingGroupBox = new QGroupBox(tr("Syntax Highlight and Text Wrapping")); - // syntax highlighting checkbox - mpSyntaxHighlightingCheckbox = new QCheckBox(tr("Enable Syntax Highlighting")); - mpSyntaxHighlightingCheckbox->setChecked(true); - // line wrap checkbox - mpLineWrappingCheckbox = new QCheckBox(tr("Enable Line Wrapping")); - mpLineWrappingCheckbox->setChecked(true); - connect(mpLineWrappingCheckbox, SIGNAL(toggled(bool)), this, SLOT(setLineWrapping())); - // set Syntax Highlight & Text Wrapping groupbox layout - QGridLayout *pSyntaxHighlightAndTextWrappingGroupBoxLayout = new QGridLayout; - pSyntaxHighlightAndTextWrappingGroupBoxLayout->addWidget(mpSyntaxHighlightingCheckbox, 0, 0); - pSyntaxHighlightAndTextWrappingGroupBoxLayout->addWidget(mpLineWrappingCheckbox, 1, 0); - mpSyntaxHighlightAndTextWrappingGroupBox->setLayout(pSyntaxHighlightAndTextWrappingGroupBoxLayout); - // fonts & colors groupbox - mpFontColorsGroupBox = new QGroupBox(Helper::fontAndColors); - // font family combobox - mpFontFamilyLabel = new Label(Helper::fontFamily); - mpFontFamilyComboBox = new QFontComboBox; - int currentIndex; - currentIndex = mpFontFamilyComboBox->findText(Helper::monospacedFontInfo.family(), Qt::MatchExactly); - mpFontFamilyComboBox->setCurrentIndex(currentIndex); - connect(mpFontFamilyComboBox, SIGNAL(currentFontChanged(QFont)), SIGNAL(updatePreview())); - // font size combobox - mpFontSizeLabel = new Label(Helper::fontSize); - mpFontSizeSpinBox = new DoubleSpinBox; - mpFontSizeSpinBox->setRange(6, std::numeric_limits::max()); - mpFontSizeSpinBox->setValue(Helper::monospacedFontInfo.pointSizeF()); - mpFontSizeSpinBox->setSingleStep(1); - connect(mpFontSizeSpinBox, SIGNAL(valueChanged(double)), SIGNAL(updatePreview())); + // colors groupbox + mpColorsGroupBox = new QGroupBox(Helper::Colors); // Item color label and pick color button mpItemColorLabel = new Label(tr("Item Color:")); mpItemColorPickButton = new QPushButton(Helper::pickColor); @@ -3814,8 +3898,8 @@ MetaModelEditorPage::MetaModelEditorPage(OptionsDialog *pOptionsDialog) mpItemsList->setCurrentRow(0, QItemSelectionModel::Select); // preview textbox mpPreviewLabel = new Label(tr("Preview:")); - mpPreviewPlainTextBox = new QPlainTextEdit; - mpPreviewPlainTextBox->setTabStopWidth(Helper::tabWidth); + mpPreviewPlainTextEdit = new PreviewPlainTextEdit; + mpPreviewPlainTextEdit->setTabStopWidth(Helper::tabWidth); QString previewText; previewText.append("\n" "\n" @@ -3827,30 +3911,28 @@ MetaModelEditorPage::MetaModelEditorPage(OptionsDialog *pOptionsDialog) "\t\t\n" "\t\n" "\n"); - mpPreviewPlainTextBox->setPlainText(previewText); + mpPreviewPlainTextEdit->setPlainText(previewText); // highlight preview textbox - MetaModelHighlighter *pMetaModelHighlighter = new MetaModelHighlighter(this, mpPreviewPlainTextBox); + MetaModelHighlighter *pMetaModelHighlighter = new MetaModelHighlighter(this, mpPreviewPlainTextEdit); connect(this, SIGNAL(updatePreview()), pMetaModelHighlighter, SLOT(settingsChanged())); - connect(mpSyntaxHighlightingCheckbox, SIGNAL(toggled(bool)), pMetaModelHighlighter, SLOT(settingsChanged())); - // set fonts & colors groupbox layout - QGridLayout *pFontsColorsGroupBoxLayout = new QGridLayout; - pFontsColorsGroupBoxLayout->addWidget(mpFontFamilyLabel, 0, 0); - pFontsColorsGroupBoxLayout->addWidget(mpFontSizeLabel, 0, 1); - pFontsColorsGroupBoxLayout->addWidget(mpFontFamilyComboBox, 1, 0); - pFontsColorsGroupBoxLayout->addWidget(mpFontSizeSpinBox, 1, 1); - pFontsColorsGroupBoxLayout->addWidget(mpItemsLabel, 2, 0); - pFontsColorsGroupBoxLayout->addWidget(mpItemColorLabel, 2, 1); - pFontsColorsGroupBoxLayout->addWidget(mpItemsList, 3, 0); - pFontsColorsGroupBoxLayout->addWidget(mpItemColorPickButton, 3, 1, Qt::AlignTop); - pFontsColorsGroupBoxLayout->addWidget(mpPreviewLabel, 4, 0, 1, 2); - pFontsColorsGroupBoxLayout->addWidget(mpPreviewPlainTextBox, 5, 0, 1, 2); - mpFontColorsGroupBox->setLayout(pFontsColorsGroupBoxLayout); + connect(mpOptionsDialog->getTextEditorPage()->getSyntaxHighlightingCheckbox(), SIGNAL(toggled(bool)), + pMetaModelHighlighter, SLOT(settingsChanged())); + connect(mpOptionsDialog->getTextEditorPage()->getMatchParenthesesCommentsQuotesCheckBox(), SIGNAL(toggled(bool)), + pMetaModelHighlighter, SLOT(settingsChanged())); + connect(mpOptionsDialog->getTextEditorPage()->getLineWrappingCheckbox(), SIGNAL(toggled(bool)), this, SLOT(setLineWrapping(bool))); + // set colors groupbox layout + QGridLayout *pColorsGroupBoxLayout = new QGridLayout; + pColorsGroupBoxLayout->addWidget(mpItemsLabel, 1, 0); + pColorsGroupBoxLayout->addWidget(mpItemColorLabel, 1, 1); + pColorsGroupBoxLayout->addWidget(mpItemsList, 2, 0); + pColorsGroupBoxLayout->addWidget(mpItemColorPickButton, 2, 1, Qt::AlignTop); + pColorsGroupBoxLayout->addWidget(mpPreviewLabel, 3, 0, 1, 2); + pColorsGroupBoxLayout->addWidget(mpPreviewPlainTextEdit, 4, 0, 1, 2); + mpColorsGroupBox->setLayout(pColorsGroupBoxLayout); // set the layout QVBoxLayout *pMainLayout = new QVBoxLayout; pMainLayout->setContentsMargins(0, 0, 0, 0); - pMainLayout->addWidget(mpTabsAndIndentation); - pMainLayout->addWidget(mpSyntaxHighlightAndTextWrappingGroupBox); - pMainLayout->addWidget(mpFontColorsGroupBox); + pMainLayout->addWidget(mpColorsGroupBox); setLayout(pMainLayout); } @@ -3935,20 +4017,6 @@ void MetaModelEditorPage::setCommentRuleColor(QColor color) mpCommentItem->setForeground(color); } -/*! - * \brief MetaModelEditorPage::setLineWrapping - * Slot activated when mpLineWrappingCheckbox toggled SIGNAL is raised. - * Sets the mpPreviewPlainTextBox line wrapping mode. - */ -void MetaModelEditorPage::setLineWrapping() -{ - if (mpLineWrappingCheckbox->isChecked()) { - mpPreviewPlainTextBox->setLineWrapMode(QPlainTextEdit::WidgetWidth); - } else { - mpPreviewPlainTextBox->setLineWrapMode(QPlainTextEdit::NoWrap); - } -} - //! Picks a color for one of the MetaModelEditor Settings rules. //! This method is called when mpColorPickButton clicked signal raised. void MetaModelEditorPage::pickColor() @@ -3984,3 +4052,17 @@ void MetaModelEditorPage::pickColor() } emit updatePreview(); } + +/*! + * \brief MetaModelEditorPage::setLineWrapping + * Slot activated when mpLineWrappingCheckbox toggled SIGNAL is raised. + * Sets the mpPreviewPlainTextBox line wrapping mode. + */ +void MetaModelEditorPage::setLineWrapping(bool enabled) +{ + if (enabled) { + mpPreviewPlainTextEdit->setLineWrapMode(QPlainTextEdit::WidgetWidth); + } else { + mpPreviewPlainTextEdit->setLineWrapMode(QPlainTextEdit::NoWrap); + } +} diff --git a/OMEdit/OMEditGUI/Options/OptionsDialog.h b/OMEdit/OMEditGUI/Options/OptionsDialog.h index 754cc2215d0..73e95b2706c 100644 --- a/OMEdit/OMEditGUI/Options/OptionsDialog.h +++ b/OMEdit/OMEditGUI/Options/OptionsDialog.h @@ -45,8 +45,9 @@ class MainWindow; class GeneralSettingsPage; class LibrariesPage; +class TextEditorPage; class ModelicaTextHighlighter; -class ModelicaTextEditorPage; +class ModelicaEditorPage; class GraphicalViewsPage; class SimulationPage; class MessagesPage; @@ -69,7 +70,8 @@ class OptionsDialog : public QDialog void readSettings(); void readGeneralSettings(); void readLibrariesSettings(); - void readModelicaTextSettings(); + void readTextEditorSettings(); + void readModelicaEditorSettings(); void readGraphicalViewsSettings(); void readSimulationSettings(); void readMessagesSettings(); @@ -84,7 +86,8 @@ class OptionsDialog : public QDialog void readMetaModelEditorSettings(); void saveGeneralSettings(); void saveLibrariesSettings(); - void saveModelicaTextSettings(); + void saveTextEditorSettings(); + void saveModelicaEditorSettings(); void saveTLMSettings(); void saveMetaModelEditorSettings(); void saveGraphicalViewsSettings(); @@ -102,7 +105,8 @@ class OptionsDialog : public QDialog void createPages(); MainWindow* getMainWindow() {return mpMainWindow;} GeneralSettingsPage* getGeneralSettingsPage() {return mpGeneralSettingsPage;} - ModelicaTextEditorPage* getModelicaTextEditorPage() {return mpModelicaTextEditorPage;} + TextEditorPage* getTextEditorPage() {return mpTextEditorPage;} + ModelicaEditorPage* getModelicaEditorPage() {return mpModelicaEditorPage;} GraphicalViewsPage* getGraphicalViewsPage() {return mpGraphicalViewsPage;} SimulationPage* getSimulationPage() {return mpSimulationPage;} MessagesPage* getMessagesPage() {return mpMessagesPage;} @@ -117,8 +121,7 @@ class OptionsDialog : public QDialog MetaModelEditorPage* getMetaModelEditorPage() {return mpMetaModelEditorPage;} void saveDialogGeometry(); void show(); - TabSettings getModelicaTabSettings(); - TabSettings getMetaModelTabSettings(); + TabSettings getTabSettings(); signals: void modelicaTextSettingsChanged(); void MetaModelEditorSettingsChanged(); @@ -131,7 +134,8 @@ public slots: MainWindow *mpMainWindow; GeneralSettingsPage *mpGeneralSettingsPage; LibrariesPage *mpLibrariesPage; - ModelicaTextEditorPage *mpModelicaTextEditorPage; + TextEditorPage *mpTextEditorPage; + ModelicaEditorPage *mpModelicaEditorPage; GraphicalViewsPage *mpGraphicalViewsPage; SimulationPage *mpSimulationPage; MessagesPage *mpMessagesPage; @@ -294,20 +298,68 @@ private slots: void addUserLibrary(); }; -class ModelicaTextEditorPage : public QWidget +class TextEditorPage : public QWidget { Q_OBJECT public: - ModelicaTextEditorPage(OptionsDialog *pOptionsDialog); + TextEditorPage(OptionsDialog *pOptionsDialog); + QComboBox *getLineEndingComboBox() {return mpLineEndingComboBox;} + QComboBox *getBOMComboBox() {return mpBOMComboBox;} 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;} QFontComboBox* getFontFamilyComboBox() {return mpFontFamilyComboBox;} DoubleSpinBox* getFontSizeSpinBox() {return mpFontSizeSpinBox;} +private: + OptionsDialog *mpOptionsDialog; + QGroupBox *mpFormatGroupBox; + Label *mpLineEndingLabel; + QComboBox *mpLineEndingComboBox; + Label *mpBOMLabel; + QComboBox *mpBOMComboBox; + QGroupBox *mpTabsAndIndentation; + Label *mpTabPolicyLabel; + QComboBox *mpTabPolicyComboBox; + Label *mpTabSizeLabel; + QSpinBox *mpTabSizeSpinBox; + Label *mpIndentSizeLabel; + QSpinBox *mpIndentSpinBox; + QGroupBox *mpSyntaxHighlightAndTextWrappingGroupBox; + QCheckBox *mpSyntaxHighlightingCheckbox; + QCheckBox *mpMatchParenthesesCommentsQuotesCheckBox; + QCheckBox *mpLineWrappingCheckbox; + QGroupBox *mpFontGroupBox; + Label *mpFontFamilyLabel; + QFontComboBox *mpFontFamilyComboBox; + Label *mpFontSizeLabel; + DoubleSpinBox *mpFontSizeSpinBox; +}; + +class PreviewPlainTextEdit : public QPlainTextEdit +{ + Q_OBJECT +public: + PreviewPlainTextEdit(QWidget *parent = 0); +private: + QTextCharFormat mParenthesesMatchFormat; + QTextCharFormat mParenthesesMisMatchFormat; + + void highlightCurrentLine(); + void highlightParentheses(); +public slots: + void updateHighlights(); +}; + +class ModelicaEditorPage : public QWidget +{ + Q_OBJECT +public: + ModelicaEditorPage(OptionsDialog *pOptionsDialog); + OptionsDialog* getOptionsDialog() {return mpOptionsDialog;} + QCheckBox *getPreserveTextIndentationCheckBox() {return mpPreserveTextIndentationCheckBox;} void addListItems(); void setTextRuleColor(QColor color); QColor getTextRuleColor() {return mTextColor;} @@ -325,29 +377,14 @@ class ModelicaTextEditorPage : public QWidget QColor getCommentRuleColor() {return mCommentColor;} private: OptionsDialog *mpOptionsDialog; - QGroupBox *mpTabsAndIndentation; - Label *mpTabPolicyLabel; - QComboBox *mpTabPolicyComboBox; - Label *mpTabSizeLabel; - QSpinBox *mpTabSizeSpinBox; - Label *mpIndentSizeLabel; - QSpinBox *mpIndentSpinBox; QCheckBox *mpPreserveTextIndentationCheckBox; - QGroupBox *mpSyntaxHighlightAndTextWrappingGroupBox; - QCheckBox *mpSyntaxHighlightingCheckbox; - QCheckBox *mpMatchParenthesesCommentsQuotesCheckBox; - QCheckBox *mpLineWrappingCheckbox; - QGroupBox *mpFontColorsGroupBox; - Label *mpFontFamilyLabel; - QFontComboBox *mpFontFamilyComboBox; - Label *mpFontSizeLabel; - DoubleSpinBox *mpFontSizeSpinBox; + QGroupBox *mpColorsGroupBox; Label *mpItemsLabel; QListWidget *mpItemsList; Label *mpItemColorLabel; QPushButton *mpItemColorPickButton; Label *mpPreviewLabel; - QPlainTextEdit *mpPreviewPlainTextBox; + PreviewPlainTextEdit *mpPreviewPlainTextEdit; QColor mTextColor; QListWidgetItem *mpTextItem; QColor mNumberColor; @@ -365,8 +402,8 @@ class ModelicaTextEditorPage : public QWidget signals: void updatePreview(); public slots: - void setLineWrapping(); void pickColor(); + void setLineWrapping(bool enabled); }; class GraphicalViewsPage : public QWidget @@ -761,13 +798,7 @@ class MetaModelEditorPage : public QWidget Q_OBJECT public: MetaModelEditorPage(OptionsDialog *pOptionsDialog); - QComboBox *getTabPolicyComboBox() {return mpTabPolicyComboBox;} - QSpinBox *getTabSizeSpinBox() {return mpTabSizeSpinBox;} - QSpinBox *getIndentSpinBox() {return mpIndentSpinBox;} - QCheckBox* getSyntaxHighlightingCheckbox() {return mpSyntaxHighlightingCheckbox;} - QCheckBox* getLineWrappingCheckbox() {return mpLineWrappingCheckbox;} - QFontComboBox* getFontFamilyComboBox() {return mpFontFamilyComboBox;} - DoubleSpinBox* getFontSizeSpinBox() {return mpFontSizeSpinBox;} + OptionsDialog* getOptionsDialog() {return mpOptionsDialog;} void addListItems(); void setTextRuleColor(QColor color); QColor getTextRuleColor(){return mTextColor;} @@ -781,27 +812,13 @@ class MetaModelEditorPage : public QWidget QColor getElementRuleColor(){return mElementColor;} private: OptionsDialog *mpOptionsDialog; - QGroupBox *mpTabsAndIndentation; - Label *mpTabPolicyLabel; - QComboBox *mpTabPolicyComboBox; - Label *mpTabSizeLabel; - QSpinBox *mpTabSizeSpinBox; - Label *mpIndentSizeLabel; - QSpinBox *mpIndentSpinBox; - QGroupBox *mpSyntaxHighlightAndTextWrappingGroupBox; - QCheckBox *mpSyntaxHighlightingCheckbox; - QCheckBox *mpLineWrappingCheckbox; - QGroupBox *mpFontColorsGroupBox; - Label *mpFontFamilyLabel; - QFontComboBox *mpFontFamilyComboBox; - Label *mpFontSizeLabel; - DoubleSpinBox *mpFontSizeSpinBox; + QGroupBox *mpColorsGroupBox; Label *mpItemsLabel; QListWidget *mpItemsList; Label *mpItemColorLabel; QPushButton *mpItemColorPickButton; Label *mpPreviewLabel; - QPlainTextEdit *mpPreviewPlainTextBox; + PreviewPlainTextEdit *mpPreviewPlainTextEdit; QColor mTextColor; QListWidgetItem *mpTextItem; QColor mQuotesColor; @@ -815,8 +832,8 @@ class MetaModelEditorPage : public QWidget signals: void updatePreview(); public slots: - void setLineWrapping(); void pickColor(); + void setLineWrapping(bool enabled); }; #endif // OPTIONSDIALOG_H diff --git a/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp b/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp index c253a0d66ae..c7c94108bdc 100644 --- a/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp +++ b/OMEdit/OMEditGUI/Plotting/PlotWindowContainer.cpp @@ -212,37 +212,30 @@ void PlotWindowContainer::exportVariables() if (fileName.isEmpty()) { // if user press ESC return; } - // create the file - QFile file(fileName); - if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QTextStream textStream(&file); - textStream.setCodec(Helper::utf8.toStdString().data()); - textStream.setGenerateByteOrderMark(false); - QStringList headers; - int dataPoints = 0; - headers << "\"time\""; - foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) { - headers << "\"" + pPlotCurve->getName() + "\""; - dataPoints = pPlotCurve->getXAxisData().size(); - } - // write the csv header - textStream << headers.join(",") << "\n"; - // write csv data - for (int i = 0 ; i < dataPoints ; ++i) { - QStringList data; - // write time data - data << QString::number(pPlotWindow->getPlot()->getPlotCurvesList().at(0)->getXAxisData().at(i)); - for (int j = 0; j < headers.size() - 1; ++j) { - data << QString::number(pPlotWindow->getPlot()->getPlotCurvesList().at(j)->getYAxisData().at(i)); - } - textStream << data.join(",") << "\n"; + QString contents; + QStringList headers; + int dataPoints = 0; + headers << "\"time\""; + foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) { + headers << "\"" + pPlotCurve->getName() + "\""; + dataPoints = pPlotCurve->getXAxisData().size(); + } + // write the csv header + contents.append(headers.join(",")).append("\n"); + // write csv data + for (int i = 0 ; i < dataPoints ; ++i) { + QStringList data; + // write time data + data << QString::number(pPlotWindow->getPlot()->getPlotCurvesList().at(0)->getXAxisData().at(i)); + for (int j = 0; j < headers.size() - 1; ++j) { + data << QString::number(pPlotWindow->getPlot()->getPlotCurvesList().at(j)->getYAxisData().at(i)); } - file.close(); + contents.append(data.join(",")).append("\n"); + } + // create a file + if (mpMainWindow->getLibraryWidget()->saveFile(fileName, contents, false)) { mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, tr("Exported variables in %1") .arg(fileName), Helper::scriptingKind, Helper::notificationLevel)); - } else { - QMessageBox::information(this, Helper::applicationName + " - " + Helper::error, GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED) - .arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE).arg(file.errorString())), Helper::ok); } } diff --git a/OMEdit/OMEditGUI/TransformationalDebugger/TransformationsWidget.cpp b/OMEdit/OMEditGUI/TransformationalDebugger/TransformationsWidget.cpp index 3dec8a17241..e950ac6617b 100644 --- a/OMEdit/OMEditGUI/TransformationalDebugger/TransformationsWidget.cpp +++ b/OMEdit/OMEditGUI/TransformationalDebugger/TransformationsWidget.cpp @@ -607,7 +607,7 @@ TransformationsWidget::TransformationsWidget(QString infoXMLFullFileName, MainWi mpTSourceEditorInfoBar->hide(); mpTransformationsEditor = new TransformationsEditor(this); ModelicaTextHighlighter *pModelicaTextHighlighter; - pModelicaTextHighlighter = new ModelicaTextHighlighter(mpMainWindow->getOptionsDialog()->getModelicaTextEditorPage(), + pModelicaTextHighlighter = new ModelicaTextHighlighter(mpMainWindow->getOptionsDialog()->getModelicaEditorPage(), mpTransformationsEditor->getPlainTextEdit()); connect(mpMainWindow->getOptionsDialog(), SIGNAL(modelicaTextSettingsChanged()), pModelicaTextHighlighter, SLOT(settingsChanged())); QVBoxLayout *pTSourceEditorVerticalLayout = new QVBoxLayout; diff --git a/OMEdit/OMEditGUI/Util/Helper.cpp b/OMEdit/OMEditGUI/Util/Helper.cpp index c415afad704..cca5255e9b3 100644 --- a/OMEdit/OMEditGUI/Util/Helper.cpp +++ b/OMEdit/OMEditGUI/Util/Helper.cpp @@ -222,7 +222,7 @@ QString Helper::arrowSize; QString Helper::size; QString Helper::lineStyle; QString Helper::color; -QString Helper::fontAndColors; +QString Helper::Colors; QString Helper::fontFamily; QString Helper::fontSize; QString Helper::pickColor; @@ -424,7 +424,7 @@ void Helper::initHelperVariables() Helper::size = tr("Size:"); Helper::lineStyle = tr("Line Style"); Helper::color = tr("Color:"); - Helper::fontAndColors = tr("Font and Colors"); + Helper::Colors = tr("Colors"); Helper::fontFamily = tr("Font Family:"); Helper::fontSize = tr("Font Size:"); Helper::pickColor = tr("Pick Color"); diff --git a/OMEdit/OMEditGUI/Util/Helper.h b/OMEdit/OMEditGUI/Util/Helper.h index 74b9f6d6c36..1f81a5e81f2 100644 --- a/OMEdit/OMEditGUI/Util/Helper.h +++ b/OMEdit/OMEditGUI/Util/Helper.h @@ -229,7 +229,7 @@ class Helper : public QObject static QString size; static QString lineStyle; static QString color; - static QString fontAndColors; + static QString Colors; static QString fontFamily; static QString fontSize; static QString pickColor; @@ -383,7 +383,6 @@ class GUIMessages : public QObject static QString getMessage(int type); }; - namespace OpenModelica { QString& tempDirectory(); QSettings* getApplicationSettings(); diff --git a/OMEdit/OMEditGUI/Util/Utilities.cpp b/OMEdit/OMEditGUI/Util/Utilities.cpp index 92a8df67ddf..ab26eeef224 100644 --- a/OMEdit/OMEditGUI/Util/Utilities.cpp +++ b/OMEdit/OMEditGUI/Util/Utilities.cpp @@ -337,3 +337,95 @@ QFrame* Utilities::getHeadingLine() pHeadingLine->setFrameShadow(QFrame::Sunken); return pHeadingLine; } + +QTextCharFormat Utilities::getParenthesesMatchFormat() +{ + QTextCharFormat parenthesesMatchFormat; + parenthesesMatchFormat.setForeground(Qt::red); + parenthesesMatchFormat.setBackground(QColor(160, 238, 160)); + return parenthesesMatchFormat; +} + +QTextCharFormat Utilities::getParenthesesMisMatchFormat() +{ + QTextCharFormat parenthesesMisMatchFormat; + parenthesesMisMatchFormat.setBackground(Qt::red); + return parenthesesMisMatchFormat; +} + +void Utilities::highlightCurrentLine(QPlainTextEdit *pPlainTextEdit) +{ + QList selections = pPlainTextEdit->extraSelections(); + QTextEdit::ExtraSelection selection; + QColor lineColor = QColor(232, 242, 254); + selection.format.setBackground(lineColor); + selection.format.setProperty(QTextFormat::FullWidthSelection, true); + selection.cursor = pPlainTextEdit->textCursor(); + selection.cursor.clearSelection(); + selections.append(selection); + pPlainTextEdit->setExtraSelections(selections); +} + +void Utilities::highlightParentheses(QPlainTextEdit *pPlainTextEdit, QTextCharFormat parenthesesMatchFormat, + QTextCharFormat parenthesesMisMatchFormat) +{ + if (pPlainTextEdit->isReadOnly()) { + return; + } + + QTextCursor backwardMatch = pPlainTextEdit->textCursor(); + QTextCursor forwardMatch = pPlainTextEdit->textCursor(); + if (pPlainTextEdit->overwriteMode()) { + backwardMatch.movePosition(QTextCursor::Right); + } + + const TextBlockUserData::MatchType backwardMatchType = TextBlockUserData::matchCursorBackward(&backwardMatch); + const TextBlockUserData::MatchType forwardMatchType = TextBlockUserData::matchCursorForward(&forwardMatch); + QList selections = pPlainTextEdit->extraSelections(); + + if (backwardMatchType == TextBlockUserData::NoMatch && forwardMatchType == TextBlockUserData::NoMatch) { + pPlainTextEdit->setExtraSelections(selections); + return; + } + + if (backwardMatch.hasSelection()) { + QTextEdit::ExtraSelection selection; + if (backwardMatchType == TextBlockUserData::Mismatch) { + selection.cursor = backwardMatch; + selection.format = parenthesesMisMatchFormat; + selections.append(selection); + } else { + selection.cursor = backwardMatch; + selection.format = parenthesesMatchFormat; + + 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 = parenthesesMisMatchFormat; + selections.append(selection); + } else { + selection.cursor = forwardMatch; + selection.format = parenthesesMatchFormat; + + 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); + } + } + pPlainTextEdit->setExtraSelections(selections); +} diff --git a/OMEdit/OMEditGUI/Util/Utilities.h b/OMEdit/OMEditGUI/Util/Utilities.h index 4a0f8107b05..523634854f6 100644 --- a/OMEdit/OMEditGUI/Util/Utilities.h +++ b/OMEdit/OMEditGUI/Util/Utilities.h @@ -47,6 +47,8 @@ #include #include #include +#include +#include #ifndef UTILITIES_H #define UTILITIES_H @@ -311,10 +313,33 @@ typedef struct { } MetaModelConnection; namespace Utilities { + + enum LineEndingMode { + CRLFLineEnding = 0, + LFLineEnding = 1, + NativeLineEnding = +#ifdef WIN32 + CRLFLineEnding, +#else + LFLineEnding +#endif + }; + + enum BomMode { + AlwaysAddBom = 0, + KeepBom = 1, + AlwaysDeleteBom = 2 + }; + void parseMetaModelText(MessageHandler *pMessageHandler, QString contents); qreal convertUnit(qreal value, qreal offset, qreal scaleFactor); Label* getHeadingLabel(QString heading); QFrame* getHeadingLine(); + QTextCharFormat getParenthesesMatchFormat(); + QTextCharFormat getParenthesesMisMatchFormat(); + void highlightCurrentLine(QPlainTextEdit *pPlainTextEdit); + void highlightParentheses(QPlainTextEdit *pPlainTextEdit, QTextCharFormat parenthesesMatchFormat, QTextCharFormat parenthesesMisMatchFormat); + } #endif // UTILITIES_H