diff --git a/src/Gui/EditorView.cpp b/src/Gui/EditorView.cpp
index 0fddaa5d5..4566a4117 100644
--- a/src/Gui/EditorView.cpp
+++ b/src/Gui/EditorView.cpp
@@ -47,6 +47,7 @@
#include "FileDialog.h"
#include "Macro.h"
#include "PythonDebugger.h"
+#include "PythonEditor.h"
#include
#include
@@ -124,10 +125,6 @@ EditorView::~EditorView()
getWindowParameter()->Detach( this );
}
-void EditorView::drawMarker(int line, int x, int y, QPainter*)
-{
-}
-
QPlainTextEdit* EditorView::getEditor() const
{
return d->textEdit;
@@ -293,7 +290,7 @@ bool EditorView::open(const QString& fileName)
QFileInfo fi(fileName);
d->timeStamp = fi.lastModified().toTime_t();
d->activityTimer->setSingleShot(true);
- d->activityTimer->start(3000);
+ d->activityTimer->start(3000);
setCurrentFileName(fileName);
return true;
@@ -399,6 +396,7 @@ void EditorView::printPdf()
void EditorView::setCurrentFileName(const QString &fileName)
{
d->fileName = fileName;
+ /*emit*/ changeFileName(d->fileName);
d->textEdit->document()->setModified(false);
QString shownName;
@@ -488,12 +486,11 @@ void EditorView::focusInEvent (QFocusEvent * e)
// ---------------------------------------------------------
-PythonEditorView::PythonEditorView(QPlainTextEdit* editor, QWidget* parent)
- : EditorView(editor, parent), m_debugLine(-1),
- breakpoint(QLatin1String(":/icons/breakpoint.png")),
- debugMarker(QLatin1String(":/icons/debug-marker.png"))
+PythonEditorView::PythonEditorView(PythonEditor* editor, QWidget* parent)
+ : EditorView(editor, parent), _pye(editor)
{
- _dbg = Application::Instance->macroManager()->debugger();
+ connect(this, SIGNAL(changeFileName(const QString&)),
+ editor, SLOT(setFileName(const QString&)));
}
PythonEditorView::~PythonEditorView()
@@ -532,18 +529,6 @@ bool PythonEditorView::onHasMsg(const char* pMsg) const
return EditorView::onHasMsg(pMsg);
}
-void PythonEditorView::drawMarker(int line, int x, int y, QPainter* p)
-{
- Breakpoint bp = _dbg->getBreakpoint(fileName());
- if (bp.checkLine(line)) {
- p->drawPixmap(x, y, breakpoint);
- }
- if (m_debugLine == line) {
- p->drawPixmap(x, y+2, debugMarker);
- debugRect = QRect(x, y+2, debugMarker.width(), debugMarker.height());
- }
-}
-
/**
* Runs the opened script in the macro manager.
*/
@@ -554,42 +539,22 @@ void PythonEditorView::executeScript()
void PythonEditorView::startDebug()
{
- if (_dbg->start()) {
- _dbg->runFile(fileName());
- _dbg->stop();
- }
+ _pye->startDebug();
}
void PythonEditorView::toggleBreakpoint()
{
- QTextCursor cursor = getEditor()->textCursor();
- int line = cursor.blockNumber() + 1;
- _dbg->toggleBreakpoint(line, fileName());
-// getMarker()->update();
+ _pye->toggleBreakpoint();
}
void PythonEditorView::showDebugMarker(int line)
{
- m_debugLine = line;
-// getMarker()->update();
- QTextCursor cursor = getEditor()->textCursor();
- cursor.movePosition(QTextCursor::StartOfBlock);
- int cur = cursor.blockNumber() + 1;
- if (cur > line) {
- for (int i=line; isetTextCursor(cursor);
+ _pye->showDebugMarker(line);
}
void PythonEditorView::hideDebugMarker()
{
- m_debugLine = -1;
-// getMarker()->update();
+ _pye->hideDebugMarker();
}
#include "moc_EditorView.cpp"
diff --git a/src/Gui/EditorView.h b/src/Gui/EditorView.h
index 096733ba9..e9201e482 100644
--- a/src/Gui/EditorView.h
+++ b/src/Gui/EditorView.h
@@ -50,8 +50,6 @@ public:
~EditorView();
QPlainTextEdit* getEditor() const;
- //todo: remove
- virtual void drawMarker(int line, int x, int y, QPainter*);
void OnChange(Base::Subject &rCaller,const char* rcReason);
const char *getName(void) const {return "EditorView";}
@@ -90,6 +88,9 @@ private Q_SLOTS:
void undoAvailable(bool);
void redoAvailable(bool);
+Q_SIGNALS:
+ void changeFileName(const QString&);
+
private:
void setCurrentFileName(const QString &fileName);
bool saveFile();
@@ -98,21 +99,18 @@ private:
EditorViewP* d;
};
-class PythonDebugger;
+class PythonEditor;
class GuiExport PythonEditorView : public EditorView
{
Q_OBJECT
public:
- PythonEditorView(QPlainTextEdit* editor, QWidget* parent);
+ PythonEditorView(PythonEditor* editor, QWidget* parent);
~PythonEditorView();
- //todo: remove
- void drawMarker(int line, int x, int y, QPainter*);
bool onMsg(const char* pMsg,const char** ppReturn);
bool onHasMsg(const char* pMsg) const;
- //todo: move to PythonEditor
public Q_SLOTS:
void executeScript();
void startDebug();
@@ -120,13 +118,8 @@ public Q_SLOTS:
void showDebugMarker(int line);
void hideDebugMarker();
- //todo: move to PythonEditor
private:
- int m_debugLine;
- QRect debugRect;
- QPixmap breakpoint;
- QPixmap debugMarker;
- PythonDebugger* _dbg;
+ PythonEditor* _pye;
};
} // namespace Gui
diff --git a/src/Gui/PythonEditor.cpp b/src/Gui/PythonEditor.cpp
index 14db48db7..756c15c3b 100644
--- a/src/Gui/PythonEditor.cpp
+++ b/src/Gui/PythonEditor.cpp
@@ -30,8 +30,10 @@
#endif
#include "PythonEditor.h"
+#include "PythonDebugger.h"
#include "Application.h"
#include "BitmapFactory.h"
+#include "Macro.h"
#include "FileDialog.h"
#include "DlgEditorImp.h"
@@ -45,8 +47,19 @@ namespace Gui {
struct PythonEditorP
{
QMap colormap; // Color map
+ int debugLine;
+ QRect debugRect;
+ QPixmap breakpoint;
+ QPixmap debugMarker;
+ QString filename;
+ PythonDebugger* debugger;
PythonEditorP()
+ : debugLine(-1),
+ breakpoint(QLatin1String(":/icons/breakpoint.png")),
+ debugMarker(QLatin1String(":/icons/debug-marker.png"))
{
+ debugger = Application::Instance->macroManager()->debugger();
+
colormap[QLatin1String("Text")] = Qt::black;
colormap[QLatin1String("Bookmark")] = Qt::cyan;
colormap[QLatin1String("Breakpoint")] = Qt::red;
@@ -98,18 +111,61 @@ PythonEditor::~PythonEditor()
delete d;
}
+void PythonEditor::setFileName(const QString& fn)
+{
+ d->filename = fn;
+}
+
+void PythonEditor::startDebug()
+{
+ if (d->debugger->start()) {
+ d->debugger->runFile(d->filename);
+ d->debugger->stop();
+ }
+}
+
+void PythonEditor::toggleBreakpoint()
+{
+ QTextCursor cursor = textCursor();
+ int line = cursor.blockNumber() + 1;
+ d->debugger->toggleBreakpoint(line, d->filename);
+ getMarker()->update();
+}
+
+void PythonEditor::showDebugMarker(int line)
+{
+ d->debugLine = line;
+ getMarker()->update();
+ QTextCursor cursor = textCursor();
+ cursor.movePosition(QTextCursor::StartOfBlock);
+ int cur = cursor.blockNumber() + 1;
+ if (cur > line) {
+ for (int i=line; idebugLine = -1;
+ getMarker()->update();
+}
+
void PythonEditor::drawMarker(int line, int x, int y, QPainter* p)
{
-#if 0
- Breakpoint bp = _dbg->getBreakpoint(fileName());
+ Breakpoint bp = d->debugger->getBreakpoint(d->filename);
if (bp.checkLine(line)) {
- p->drawPixmap(x, y, breakpoint);
+ p->drawPixmap(x, y, d->breakpoint);
}
- if (m_debugLine == line) {
- p->drawPixmap(x, y+2, debugMarker);
- debugRect = QRect(x, y+2, debugMarker.width(), debugMarker.height());
+ if (d->debugLine == line) {
+ p->drawPixmap(x, y+2, d->debugMarker);
+ d->debugRect = QRect(x, y+2, d->debugMarker.width(), d->debugMarker.height());
}
-#endif
}
void PythonEditor::contextMenuEvent ( QContextMenuEvent * e )
diff --git a/src/Gui/PythonEditor.h b/src/Gui/PythonEditor.h
index 8e5b71e2e..f64e9ddf5 100644
--- a/src/Gui/PythonEditor.h
+++ b/src/Gui/PythonEditor.h
@@ -45,6 +45,11 @@ public:
PythonEditor(QWidget *parent = 0);
~PythonEditor();
+ void startDebug();
+ void toggleBreakpoint();
+ void showDebugMarker(int line);
+ void hideDebugMarker();
+
public Q_SLOTS:
/** Inserts a '#' at the beginning of each selected line or the current line if
* nothing is selected
@@ -56,6 +61,7 @@ public Q_SLOTS:
* this line is skipped.
*/
void onUncomment();
+ void setFileName(const QString&);
protected:
/** Pops up the context menu with some extensions */
diff --git a/src/Gui/TextEdit.h b/src/Gui/TextEdit.h
index f14ca65cf..2ad2a7fa8 100644
--- a/src/Gui/TextEdit.h
+++ b/src/Gui/TextEdit.h
@@ -99,6 +99,8 @@ protected:
/** Draw a beam in the line where the cursor is. */
void paintEvent (QPaintEvent * e);
void resizeEvent(QResizeEvent* e);
+ QWidget* getMarker() const
+ { return lineNumberArea; }
virtual void drawMarker(int line, int x, int y, QPainter*);
private: