From 88ef0b58d94cd1680b7e0d07d1007e7722cd1802 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 28 Mar 2015 21:50:01 +0100 Subject: [PATCH] + syntax highlighter for Abaqus, show short filename on tabs --- src/Gui/EditorView.cpp | 23 ++++++++++- src/Gui/EditorView.h | 7 ++++ src/Mod/Fem/Gui/AbaqusHighlighter.cpp | 58 +++++++++++++++++++++++++++ src/Mod/Fem/Gui/AbaqusHighlighter.h | 47 ++++++++++++++++++++++ src/Mod/Fem/Gui/AppFemGuiPy.cpp | 5 ++- src/Mod/Fem/Gui/CMakeLists.txt | 2 + 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 src/Mod/Fem/Gui/AbaqusHighlighter.cpp create mode 100644 src/Mod/Fem/Gui/AbaqusHighlighter.h diff --git a/src/Gui/EditorView.cpp b/src/Gui/EditorView.cpp index 034564a3f..dc3ba3b98 100644 --- a/src/Gui/EditorView.cpp +++ b/src/Gui/EditorView.cpp @@ -58,6 +58,7 @@ class EditorViewP { public: QPlainTextEdit* textEdit; QString fileName; + EditorView::DisplayName displayName; QTimer* activityTimer; uint timeStamp; bool lock; @@ -79,6 +80,7 @@ EditorView::EditorView(QPlainTextEdit* editor, QWidget* parent) { d = new EditorViewP; d->lock = false; + d->displayName = EditorView::FullName; // create the editor first d->textEdit = editor; @@ -256,6 +258,11 @@ bool EditorView::canClose(void) } } +void EditorView::setDisplayName(EditorView::DisplayName type) +{ + d->displayName = type; +} + /** * Saves the content of the editor to a file specified by the appearing file dialog. */ @@ -399,11 +406,25 @@ void EditorView::setCurrentFileName(const QString &fileName) /*emit*/ changeFileName(d->fileName); d->textEdit->document()->setModified(false); + QString name; + QFileInfo fi(fileName); + switch (d->displayName) { + case FullName: + name = fileName; + break; + case FileName: + name = fi.fileName(); + break; + case BaseName: + name = fi.baseName(); + break; + } + QString shownName; if (fileName.isEmpty()) shownName = tr("untitled[*]"); else - shownName = QString::fromAscii("%1[*]").arg(fileName); + shownName = QString::fromAscii("%1[*]").arg(name); shownName += tr(" - Editor"); setWindowTitle(shownName); setWindowModified(false); diff --git a/src/Gui/EditorView.h b/src/Gui/EditorView.h index e9201e482..61db75266 100644 --- a/src/Gui/EditorView.h +++ b/src/Gui/EditorView.h @@ -46,10 +46,17 @@ class GuiExport EditorView : public MDIView, public WindowParameter Q_OBJECT public: + enum DisplayName { + FullName, + FileName, + BaseName + }; + EditorView(QPlainTextEdit* editor, QWidget* parent); ~EditorView(); QPlainTextEdit* getEditor() const; + void setDisplayName(DisplayName); void OnChange(Base::Subject &rCaller,const char* rcReason); const char *getName(void) const {return "EditorView";} diff --git a/src/Mod/Fem/Gui/AbaqusHighlighter.cpp b/src/Mod/Fem/Gui/AbaqusHighlighter.cpp new file mode 100644 index 000000000..de9338968 --- /dev/null +++ b/src/Mod/Fem/Gui/AbaqusHighlighter.cpp @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include "AbaqusHighlighter.h" + +using namespace FemGui; + +/** + * Constructs a syntax highlighter. + */ +AbaqusHighlighter::AbaqusHighlighter(QObject* parent) + : SyntaxHighlighter(parent) +{ +} + +/** Destroys this object. */ +AbaqusHighlighter::~AbaqusHighlighter() +{ +} + +void AbaqusHighlighter::highlightBlock(const QString &text) +{ + for (int i = 0; i < text.length(); ++i) { + if (text.mid(i, 2) == QLatin1String("**")) { + setFormat(i, text.length() - i, this->colorByType(SyntaxHighlighter::Comment)); + break; + } + else if (text.mid(i, 1) == QLatin1String("*")) { + setFormat(i, text.length() - i, this->colorByType(SyntaxHighlighter::Defname)); + break; + } + } +} diff --git a/src/Mod/Fem/Gui/AbaqusHighlighter.h b/src/Mod/Fem/Gui/AbaqusHighlighter.h new file mode 100644 index 000000000..c3122800c --- /dev/null +++ b/src/Mod/Fem/Gui/AbaqusHighlighter.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (c) 2015 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef FEMGUI_ABAQUSHIGHLIGHTER_H +#define FEMGUI_ABAQUSHIGHLIGHTER_H + +#include + +namespace FemGui { + +/** + * Syntax highlighter for Abaqus. + * @author Werner Mayer + */ +class AbaqusHighlighter : public Gui::SyntaxHighlighter +{ +public: + AbaqusHighlighter(QObject* parent); + virtual ~AbaqusHighlighter(); + +protected: + void highlightBlock(const QString &text); +}; + +} // namespace FemGui + +#endif // FEMGUI_ABAQUSHIGHLIGHTER_H diff --git a/src/Mod/Fem/Gui/AppFemGuiPy.cpp b/src/Mod/Fem/Gui/AppFemGuiPy.cpp index 3fe3b83fa..9cabb8258 100755 --- a/src/Mod/Fem/Gui/AppFemGuiPy.cpp +++ b/src/Mod/Fem/Gui/AppFemGuiPy.cpp @@ -38,6 +38,7 @@ #include #include "ActiveAnalysisObserver.h" +#include "AbaqusHighlighter.h" /* module functions */ @@ -100,10 +101,10 @@ static PyObject * openEditor(PyObject *self, PyObject *args) Gui::TextEditor* editor = new Gui::TextEditor(); editor->setWindowIcon(Gui::BitmapFactory().pixmap(":/icons/Fem_Inp_Editor.svg")); Gui::EditorView* edit = new Gui::EditorView(editor, Gui::getMainWindow()); + editor->setSyntaxHighlighter(new FemGui::AbaqusHighlighter(editor)); + edit->setDisplayName(Gui::EditorView::FileName); edit->open(fileName); edit->resize(400, 300); - QString shownName = QString::fromAscii("%1[*]").arg(fi.fileName()); - edit->setWindowTitle(shownName); Gui::getMainWindow()->addWindow(edit); } } PY_CATCH; diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index a3da64f00..fefd63fd5 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -170,6 +170,8 @@ SOURCE_GROUP("Task_Dialogs" FILES ${FemGui_SRCS_TaskDlg}) SET(FemGui_SRCS_Module AppFemGui.cpp AppFemGuiPy.cpp + AbaqusHighlighter.cpp + AbaqusHighlighter.h ActiveAnalysisObserver.cpp ActiveAnalysisObserver.h Command.cpp