Salome HOME
Split PyConsole in order to be used easily outside GUI of SALOME.
[modules/gui.git] / src / PyConsoleBase / PyConsole_EnhEditorBase.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Adrien Bruneton (CEA/DEN)
20 // Created on: 4 avr. 2013
21
22 #ifndef PYCONSOLE_ENHEDITORBASE_H_
23 #define PYCONSOLE_ENHEDITORBASE_H_
24
25 #include "PyConsoleBase.h"
26 #include "PyConsole_EditorBase.h"
27
28 #include <QObject>
29 #include <queue>
30
31 /**
32  * Enhanced Python editor handling tab completion.
33  */
34 class PYCONSOLEBASE_EXPORT PyConsole_EnhEditorBase : public PyConsole_EditorBase
35 {
36   Q_OBJECT;
37
38 public:
39   PyConsole_EnhEditorBase(PyConsole_Interp* interp, QWidget* parent = 0);
40   virtual ~PyConsole_EnhEditorBase() {}
41
42 signals:
43   /**
44    * Signal emitted by the editor widget when the doc string should be updated.
45    * @param doc a HTML block with the formatted doc string.
46    * TODO: for now this signal is left uncaught.
47    */
48   void updateDoc(QString doc);
49
50 protected:
51   /** List of separators identifying the last parsable token for completion */
52   static const std::vector<QString> SEPARATORS;
53
54   /** Maximum number of completions shown at once */
55   static const int MAX_COMPLETIONS = 70;
56
57   /** Are we in completion mode */
58   bool _tab_mode;
59
60   /** String on which the dir() comamnd is executed */
61   QString _compl_before_point;
62   /** String on which the results of the dir() are matched */
63   QString _compl_after_point;
64
65   /** Cursor position when <TAB> is hit */
66   int _cursor_pos;
67
68   /** Are we currently pasting several lines */
69   bool _multi_line_paste;
70
71   /** Queue of lines being pasted */
72   std::queue<QString> _multi_line_content;
73
74   // Overrides:
75   virtual void   keyPressEvent ( QKeyEvent* event);
76   virtual void   customEvent( QEvent* event);
77   virtual void   mousePressEvent( QMouseEvent* event );
78   virtual void   insertFromMimeData(const QMimeData* source);
79
80   virtual PyInterp_Request* createTabRequest( const QString& input );
81   virtual void handleTab();
82   virtual void handleBackTab();
83   virtual void clearCompletion();
84   virtual void formatCompletion(const QStringList& matches, QString& result) const;
85   virtual QString formatDocHTML(const QString & doc) const;
86
87   virtual void multilinePaste(const QString & s);
88   virtual void multiLineProcessNextLine();
89
90 private:
91   void extractCommon(const QStringList& matches, QString& result) const;
92
93 };
94
95 #endif /* PYCONSOLE_ENHEDITORBASE_H_ */