Selaa lähdekoodia

ctkConsole - Added automaticIndentation property

Jean-Christophe Fillion-Robin 14 vuotta sitten
vanhempi
commit
1725d7e61f

+ 1 - 10
Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp

@@ -338,16 +338,7 @@ void ctkPythonConsole::executeCommand(const QString& command)
   Q_D(ctkPythonConsole);
 
   QString commandUpdated = command;
-  commandUpdated.replace(QRegExp("\\s*$"), "");
+  commandUpdated.replace(QRegExp("\\s*$"), ""); // Remove trailing spaces
 
   d->MultilineStatement = d->push(commandUpdated);
-
-  // Find the indent for the command.
-  QRegExp regExp("^(\\s+)");
-  QString indent;
-  if (regExp.indexIn(commandUpdated) != -1)
-    {
-    indent = regExp.cap(1);
-    }
-  d->promptForInput(indent);
 }

+ 17 - 1
Libs/Widgets/ctkConsole.cpp

@@ -74,7 +74,7 @@ ctkConsolePrivate::ctkConsolePrivate(ctkConsole& object) :
   QTextEdit(0),
   q_ptr(&object),
   InteractivePosition(documentEnd()),
-  MultilineStatement(false), Ps1(">>> "), Ps2("... ")
+  MultilineStatement(false), Ps1(">>> "), Ps2("... "), AutomaticIndentation(false)
 {
 }
 
@@ -403,6 +403,18 @@ void ctkConsolePrivate::internalExecuteCommand()
   emit q->executing(true);
   q->executeCommand(command);
   emit q->executing(false);
+
+  // Find the indent for the command.
+  QString indent;
+  if (this->AutomaticIndentation)
+    {
+    QRegExp regExp("^(\\s+)");
+    if (regExp.indexIn(command) != -1)
+      {
+      indent = regExp.cap(1);
+      }
+    }
+  this->promptForInput(indent);
 }
 
 //-----------------------------------------------------------------------------
@@ -580,6 +592,10 @@ CTK_GET_CPP(ctkConsole, QString, ps2, Ps2);
 CTK_SET_CPP(ctkConsole, const QString&, setPs2, Ps2);
 
 //-----------------------------------------------------------------------------
+CTK_GET_CPP(ctkConsole, bool, automaticIndentation, AutomaticIndentation);
+CTK_SET_CPP(ctkConsole, bool, setAutomaticIndentation, AutomaticIndentation);
+
+//-----------------------------------------------------------------------------
 void ctkConsole::executeCommand(const QString& command)
 {
   qWarning() << "ctkConsole::executeCommand not implemented !";

+ 6 - 0
Libs/Widgets/ctkConsole.h

@@ -76,6 +76,7 @@ class CTK_WIDGETS_EXPORT ctkConsole : public QWidget
   Q_PROPERTY(QColor welcomeTextColor READ welcomeTextColor WRITE setWelcomeTextColor)
   Q_PROPERTY(QString ps1 READ ps1 WRITE setPs1)
   Q_PROPERTY(QString ps2 READ ps2 WRITE setPs2)
+  Q_PROPERTY(bool automaticIndentation READ automaticIndentation WRITE setAutomaticIndentation)
   
 public:
   ctkConsole(QWidget* parentObject = 0);
@@ -115,6 +116,8 @@ public:
   /// \sa welcomeTextColor()
   void setWelcomeTextColor(const QColor& newColor);
 
+  bool automaticIndentation()const;
+
   /// Prints text on the console
   void printMessage(const QString& message, const QColor& color);
 
@@ -137,6 +140,9 @@ signals:
 
 public slots:
 
+  /// \sa automaticIndentation()
+  void setAutomaticIndentation(bool value);
+
   /// Clears the contents of the console
   virtual void clear();
 

+ 2 - 0
Libs/Widgets/ctkConsole_p.h

@@ -142,6 +142,8 @@ public:
   /// Secondary prompt
   QString Ps2;
 
+  bool AutomaticIndentation;
+
 };