Skip to content

Commit

Permalink
+ syntax highlighter for Abaqus, show short filename on tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 28, 2015
1 parent 18e4fdf commit 88ef0b5
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/Gui/EditorView.cpp
Expand Up @@ -58,6 +58,7 @@ class EditorViewP {
public:
QPlainTextEdit* textEdit;
QString fileName;
EditorView::DisplayName displayName;
QTimer* activityTimer;
uint timeStamp;
bool lock;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/Gui/EditorView.h
Expand Up @@ -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<const char*> &rCaller,const char* rcReason);

const char *getName(void) const {return "EditorView";}
Expand Down
58 changes: 58 additions & 0 deletions src/Mod/Fem/Gui/AbaqusHighlighter.cpp
@@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <QRegExp>
#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;
}
}
}
47 changes: 47 additions & 0 deletions src/Mod/Fem/Gui/AbaqusHighlighter.h
@@ -0,0 +1,47 @@
/***************************************************************************
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Gui/SyntaxHighlighter.h>

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
5 changes: 3 additions & 2 deletions src/Mod/Fem/Gui/AppFemGuiPy.cpp
Expand Up @@ -38,6 +38,7 @@

#include <Mod/Fem/App/FemAnalysis.h>
#include "ActiveAnalysisObserver.h"
#include "AbaqusHighlighter.h"


/* module functions */
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Fem/Gui/CMakeLists.txt
Expand Up @@ -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
Expand Down

0 comments on commit 88ef0b5

Please sign in to comment.