[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/kdevelop/3.4/languages/cpp
From:       Jens Dagerbo <jens.dagerbo () swipnet ! se>
Date:       2007-01-26 0:51:36
Message-ID: 1169772696.884438.13388.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 627219 by dagerbo:

Add cursor context shortcut lookup of method definition/declaration.

For some reason, the shortcuts aren't active until one has changed something in the \
shortcut dialog. This can be seen on some of the older shortcuts on the cpp language \
plugin too. Something's fishy..

 M  +47 -0     cppcodecompletion.cpp  
 M  +6 -0      cppcodecompletion.h  


--- branches/kdevelop/3.4/languages/cpp/cppcodecompletion.cpp #627218:627219
@@ -46,6 +46,7 @@
 #include <kparts/part.h>
 #include <kstatusbar.h>
 #include <ktexteditor/document.h>
+#include <kaction.h>
 
 #include <qdatastream.h>
 #include <qfile.h>
@@ -868,6 +869,9 @@
            this, SLOT( slotFileParsed( const QString& ) ) );
   connect( part, SIGNAL( codeModelUpdated( const QString& ) ),
            this, SLOT( slotCodeModelUpdated( const QString& ) ) );
+	
+	new KAction( i18n("Jump to declaration under cursor"), CTRL+Key_Comma, this, \
SLOT(slotJumpToDeclCursorContext()), part->actionCollection(), \
"jump_to_declaration_cursor_context" ); +	new KAction( i18n("Jump to definition under \
cursor"), CTRL+Key_Period, this, SLOT(slotJumpToDefCursorContext()), \
part->actionCollection(), "jump_to_defintion_cursor_context" );  }
 
 CppCodeCompletion::~CppCodeCompletion( ) {
@@ -4183,6 +4187,49 @@
 	return HashedStringSet();
 }
 
+void CppCodeCompletion::slotJumpToDeclCursorContext()
+{
+	kdDebug(9007) << k_funcinfo << endl;
+	jumpCursorContext( Declaration );
+}
 
+void CppCodeCompletion::slotJumpToDefCursorContext()
+{
+	kdDebug(9007) << k_funcinfo << endl;
+	jumpCursorContext( Definition );
+}
+
+void CppCodeCompletion::jumpCursorContext( FunctionType f )
+{
+	if ( !m_activeCursor ) return;
+	
+	SimpleTypeConfiguration conf( m_activeFileName );	
+	
+	unsigned int line;
+	unsigned int column;
+	m_activeCursor->cursorPositionReal( &line, &column );
+	
+	EvaluationResult result = evaluateExpressionAt( line, column, conf );
+	
+	TypeDesc type = result.resultType;
+	
+	if ( type.resolved() ) 
+	{
+		if ( type.resolved()->asFunction() ) 
+		{
+			DeclarationInfo d = type.resolved()->getDeclarationInfo();
+			QString fileName = d.file == "current_file" ? m_activeFileName : d.file.operator \
QString(); +			
+			if ( f == Definition && m_pSupport->switchHeaderImpl( fileName, d.startLine, \
d.startCol ) ) +				return;
+			
+			m_pSupport->partController()->editDocument( fileName, d.startLine );
+		}
+	}
+}
+
+
 #include "cppcodecompletion.moc"
 //kate: indent-mode csands; tab-width 2; space-indent off;
+
+
--- branches/kdevelop/3.4/languages/cpp/cppcodecompletion.h #627218:627219
@@ -173,7 +173,12 @@
 	void popupDefinitionAction( int number );
     void popupClassViewAction( int number );
 	void synchronousParseReady( const QString& file, ParsedFilePointer unit );
+	void slotJumpToDefCursorContext();
+	void slotJumpToDeclCursorContext();
+	
 private:
+	enum FunctionType { Declaration, Definition };
+	
     TypePointer createGlobalNamespace();
 	bool functionContains( FunctionDom f , int line, int col );
 	void getFunctionBody( FunctionDom f , int& line, int& col );
@@ -186,6 +191,7 @@
 	FunctionDefinitionAST* functionDefinition( AST* node );
 	void computeRecoveryPoints( ParsedFilePointer unit );
 	void computeRecoveryPointsLocked();
+	void jumpCursorContext( FunctionType );
 	
     enum EvaluateExpressionOptions {
         IncludeStandardExpressions = 1,


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic