[PATCH] Re: how to access the editor configuration from the cppsupportpart.cpp

Andreas Wuest AndreasWuest at gmx.de
Fri Dec 20 19:27:04 UTC 2002


Hi,

> Hi,
> 
> On Thursday 19 December 2002 11:53, Victor Röder wrote:
> > Hi,
> >
> >  > I wouldn't it like if the cppsupportpart knows about all the editors
> >  > and how they can be accessed. It results in a huge switch statement
> >  > for the single editors.
> >  > Better is to extend the KTextEditor interface with a for instance
> >  > putStringInFile(const QString& text, int line, int column) method.
> >  > Then the editor can handle it by itself (or not).
> >
> > Isn't there a insertText ( line, col, text ) method in the KTextEditor
> > interface (EditInterface)?
> 
> yes, but would be nice to have more methods suitable for IDE like kdevelop, 
> e.g.
> 
>   void indent( int line );
>   void indentBlock();
>   void markTextAsError( int fromLine, int fromColumn, ... )
> ...
> 
> anyway, i don't know if add "IDE specific" interfaces to KTextEditor 
> is the right solution
> 
> ciao robe

attached you will find a patch that indents the method definition in the
header file according to the "code style configuration". At the moment
the header definition is always indented with a tab, which i do not
like. 

The solution in the patch is however only suboptimal. the best solution
would be in imho :
 
1. create the code that will be inserted into the editor. 
2. Pass that code along to a Formatter (ASFormatter, ASBeautifier ??) to
format the code according to the code style configuration.
3. inserted the formatted code into the editor.


Bye,

 Andreas


-------------- next part --------------
Index: cppsupportpart.cpp
===================================================================
RCS file: /home/kde/kdevelop/parts/cppsupport/cppsupportpart.cpp,v
retrieving revision 1.74
diff -u -p -r1.74 cppsupportpart.cpp
--- cppsupportpart.cpp	19 Dec 2002 20:29:40 -0000	1.74
+++ cppsupportpart.cpp	20 Dec 2002 18:17:52 -0000
@@ -40,6 +40,7 @@
 #include <kmainwindow.h>
 #include <kstatusbar.h>
 #include <kmessagebox.h>
+#include <kconfig.h>
 
 #include <ktexteditor/document.h>
 #include <ktexteditor/editinterface.h>
@@ -733,13 +734,35 @@ QString CppSupportPart::asHeaderCode(Par
 {
     QString str;
 
+    KConfig *config = kapp->config ();
+    config->setGroup ("AStyle");
+    QString fill = config->readEntry ("Fill");
+    QString fillSpaces = config->readEntry ("FillSpaces");
+    QString style = config->readEntry ("Style");
+
+    // set the default indent : space
+    QString indent = " ";
+   
+    if (style == "UserDefined")
+    { 
+      bool ok = true; 
+      // set indention according to the configuration 
+      indent = ((fill == "Tabs") ? QString ("\t") : indent.fill (' ', fillSpaces.toInt (&ok)));
+      // if the fillSpaces property is not a number -> reset indention to 2 spaces
+      indent = (ok ? indent : QString ("  "));
+    }
+    else
+    {
+      indent = "\t";
+    } 
+ 
     if( !pm->comment().isEmpty() ) {
-        str += "\t/**\n\t";
-        str += pm->comment().replace( QRegExp("\n"), "\n\t" );
-        str += "\n\t*/\n";
+        str += indent + "/**\n" + indent;
+        str += pm->comment().replace( QRegExp("\n"), "\n" + indent );
+        str += "\n" + indent + "*/\n";
     }
-
-    str += "\t";
+ 
+    str += indent;
 
     if (pm->isVirtual())
         str += "virtual ";


More information about the KDevelop-devel mailing list