+ syntax highlighter for Abaqus, show short filename on tabs
This commit is contained in:
parent
18e4fdf5c2
commit
88ef0b58d9
|
@ -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);
|
||||
|
|
|
@ -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";}
|
||||
|
|
58
src/Mod/Fem/Gui/AbaqusHighlighter.cpp
Normal file
58
src/Mod/Fem/Gui/AbaqusHighlighter.cpp
Normal file
|
@ -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
src/Mod/Fem/Gui/AbaqusHighlighter.h
Normal file
47
src/Mod/Fem/Gui/AbaqusHighlighter.h
Normal file
|
@ -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
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
#include <Mod/Fem/App/FemAnalysis.h>
|
||||
#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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user