Salome HOME
Synchronize adm files
[modules/gui.git] / src / PyConsole / PyConsole_EnhEditor.h
1 // Copyright (C) 2007-2014  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_ENHEDITOR_H_
23 #define PYCONSOLE_ENHEDITOR_H_
24
25 #include "PyConsole.h"
26
27 #include "PyConsole_Editor.h"
28 #include <QObject>
29 #include <queue>
30
31 class PyConsole_EnhInterp;
32
33 /**
34  * Enhanced Python editor handling tab completion.
35  */
36 class PYCONSOLE_EXPORT PyConsole_EnhEditor: public PyConsole_Editor
37 {
38   Q_OBJECT;
39
40 public:
41   PyConsole_EnhEditor(PyConsole_EnhInterp * interp, QWidget * parent=0);
42   virtual ~PyConsole_EnhEditor() {}
43
44 signals:
45   /**
46    * Signal emitted by the editor widget when the doc string should be updated.
47    * @param doc a HTML block with the formatted doc string.
48    * TODO: for now this signal is left uncaught.
49    */
50   void updateDoc(QString doc);
51
52 protected:
53   /** List of separators identifying the last parsable token for completion */
54   static const std::vector<QString> SEPARATORS;
55
56   /** Maximum number of completions shown at once */
57   static const int MAX_COMPLETIONS = 70;
58
59   /** Are we in completion mode */
60   bool _tab_mode;
61
62   /** String on which the dir() comamnd is executed */
63   QString _compl_before_point;
64   /** String on which the results of the dir() are matched */
65   QString _compl_after_point;
66
67   /** Cursor position when <TAB> is hit */
68   int _cursor_pos;
69
70   /** Are we currently pasting several lines */
71   bool _multi_line_paste;
72
73   /** Queue of lines being pasted */
74   std::queue<QString> _multi_line_content;
75
76   // Overrides:
77   virtual void   keyPressEvent ( QKeyEvent* event);
78   virtual void   customEvent( QEvent* event);
79   virtual void   mousePressEvent( QMouseEvent* event );
80   virtual void   insertFromMimeData(const QMimeData * source);
81
82   virtual PyInterp_Request* createTabRequest( const QString& input );
83   virtual void handleTab();
84   virtual void handleBackTab();
85   virtual void clearCompletion();
86   virtual void formatCompletion(const std::vector<QString> & matches, QString & result) const;
87   virtual QString formatDocHTML(const QString & doc) const;
88
89   virtual void multilinePaste(const QString & s);
90   virtual void multiLineProcessNextLine();
91
92 private:
93   void extractCommon(const std::vector<QString> & matches, QString & result) const;
94
95 };
96
97 #endif /* PYCONSOLE_ENHEDITOR_H_ */