[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/kdevelop/3.4
From: Jens Dagerbo <jens.dagerbo () swipnet ! se>
Date: 2007-01-21 2:22:32
Message-ID: 1169346152.573160.11321.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 625770 by dagerbo:
Reduce code duplication by using the common implementation
M +5 -30 parts/ctags2/ctags2_part.cpp
M +0 -1 parts/ctags2/ctags2_part.h
M +8 -36 parts/documentation/documentation_part.cpp
M +0 -1 parts/documentation/documentation_part.h
M +4 -46 parts/quickopen/quickopen_part.cpp
M +0 -2 parts/quickopen/quickopen_part.h
M +54 -85 src/editorproxy.cpp
--- branches/kdevelop/3.4/parts/ctags2/ctags2_part.cpp #625769:625770
@@ -20,6 +20,7 @@
#include <kiconloader.h>
#include <klocale.h>
#include <kparts/part.h>
+#include <ktexteditor/document.h>
#include <ktexteditor/editinterface.h>
#include <ktexteditor/viewcursorinterface.h>
#include <kprocess.h>
@@ -39,6 +40,7 @@
#include <kdevplugininfo.h>
#include "configwidgetproxy.h"
#include "domutil.h"
+#include "kdeveditorutil.h"
#include "ctags2_settingswidget.h"
#include "ctags2_widget.h"
@@ -324,7 +326,7 @@
void CTags2Part::slotLookupDeclaration( )
{
- m_contextString = currentWord();
+ m_contextString = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) ); if ( \
!m_contextString.isEmpty() ) {
slotGotoDeclaration();
@@ -333,7 +335,7 @@
void CTags2Part::slotLookupDefinition( )
{
- m_contextString = currentWord();
+ m_contextString = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) ); if ( \
!m_contextString.isEmpty() ) {
slotGotoDefinition();
@@ -342,7 +344,7 @@
void CTags2Part::slotLookup( )
{
- m_contextString = currentWord();
+ m_contextString = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) ); if ( \
!m_contextString.isEmpty() ) {
slotGotoTag();
@@ -360,33 +362,6 @@
m_widget->goToNext();
}
-QString CTags2Part::currentWord( )
-{
- KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*>( \
partController()->activePart() );
- if ( !ro_part || !ro_part->widget() ) return QString::null;
-
- KTextEditor::ViewCursorInterface * cursorIface = \
dynamic_cast<KTextEditor::ViewCursorInterface*>( ro_part->widget() );
- KTextEditor::EditInterface * editIface = dynamic_cast<KTextEditor::EditInterface*>( \
ro_part );
-
- QString wordstr, linestr;
- if( cursorIface && editIface )
- {
- uint line, col;
- line = col = 0;
- cursorIface->cursorPositionReal(&line, &col);
- linestr = editIface->textLine(line);
- int startPos = QMAX( QMIN( (int)col, (int)linestr.length()-1 ), 0 );
- int endPos = startPos;
- while (startPos >= 0 && ( linestr[startPos].isLetterOrNumber() || \
linestr[startPos] == '_' || linestr[startPos] == '~') )
- startPos--;
- while (endPos < (int)linestr.length() && ( linestr[endPos].isLetterOrNumber() || \
linestr[endPos] == '_' ) )
- endPos++;
-
- return ( ( startPos == endPos ) ? QString::null : linestr.mid( startPos+1, \
endPos-startPos-1 ) );
- }
- return QString::null;
-}
-
#include "ctags2_part.moc"
// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;
--- branches/kdevelop/3.4/parts/ctags2/ctags2_part.h #625769:625770
@@ -56,7 +56,6 @@
int getFileLineFromStream( QTextStream & stream, QString const & pattern);
void gotoTagForTypes( QStringList const & types );
void showHits( Tags::TagList const & tags );
- QString currentWord();
QGuardedPtr<CTags2Widget> m_widget;
QString m_contextString ;
--- branches/kdevelop/3.4/parts/documentation/documentation_part.cpp #625769:625770
@@ -46,8 +46,7 @@
#include <kstringhandler.h>
#include <kconfig.h>
#include <kwin.h>
-#include <ktexteditor/editinterface.h>
-#include <ktexteditor/viewcursorinterface.h>
+#include <ktexteditor/document.h>
#include "kdevplugininfo.h"
#include "kdevcore.h"
@@ -59,6 +58,7 @@
#include "kdevpartcontroller.h"
#include "domutil.h"
#include "urlutil.h"
+#include "kdeveditorutil.h"
#include "documentation_widget.h"
#include "docglobalconfigwidget.h"
@@ -259,7 +259,7 @@
void DocumentationPart::searchInDocumentation()
{
- QString word = currentWord();
+ QString word = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) );
if ( word.isEmpty() )
{
@@ -299,7 +299,7 @@
void DocumentationPart::manPage()
{
- QString word = currentWord();
+ QString word = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) );
if ( isAssistantUsed() )
{
@@ -323,8 +323,8 @@
void DocumentationPart::infoPage()
{
- QString word = currentWord();
-
+ QString word = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) ); +
if ( isAssistantUsed() )
{
if ( word.isEmpty() )
@@ -383,7 +383,7 @@
void DocumentationPart::findInDocumentation()
{
- QString word = currentWord();
+ QString word = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) );
if ( word.isEmpty() )
{
@@ -415,7 +415,7 @@
void DocumentationPart::lookInDocumentationIndex()
{
- QString word = currentWord();
+ QString word = KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) );
if ( word.isEmpty() )
{
@@ -763,32 +763,4 @@
loadSettings();
}
-///@todo - duplicated from ctags part, which came from editorproxy. we also have a \
shorter version in other places..
-QString DocumentationPart::currentWord()
-{
- KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*> ( \
partController()->activePart() );
- if ( !ro_part || !ro_part->widget() ) return QString::null;
-
- KTextEditor::ViewCursorInterface * cursorIface = \
dynamic_cast<KTextEditor::ViewCursorInterface*> ( ro_part->widget() \
);
- KTextEditor::EditInterface * editIface = \
dynamic_cast<KTextEditor::EditInterface*> ( ro_part );
-
- QString wordstr, linestr;
- if ( cursorIface && editIface )
- {
- uint line, col;
- line = col = 0;
- cursorIface->cursorPositionReal ( &line, &col );
- linestr = editIface->textLine ( line );
- int startPos = QMAX ( QMIN ( ( int ) col, ( int ) linestr.length()-1 ), 0 );
- int endPos = startPos;
- while ( startPos >= 0 && ( linestr[startPos].isLetterOrNumber() || \
linestr[startPos] == '_' || linestr[startPos] == '~' ) )
- startPos--;
- while ( endPos < ( int ) linestr.length() && ( \
linestr[endPos].isLetterOrNumber() || linestr[endPos] == '_' ) )
- endPos++;
-
- return ( ( startPos == endPos ) ? QString::null : linestr.mid ( startPos+1, \
endPos-startPos-1 ) );
- }
- return QString::null;
-}
-
#include "documentation_part.moc"
--- branches/kdevelop/3.4/parts/documentation/documentation_part.h #625769:625770
@@ -107,7 +107,6 @@
QValueList<DocumentationPlugin*> m_plugins;
ProjectDocumentationPlugin *m_projectDocumentationPlugin;
ProjectDocumentationPlugin *m_userManualPlugin;
- QString currentWord();
QString m_contextStr;
bool m_hasIndex;
--- branches/kdevelop/3.4/parts/quickopen/quickopen_part.cpp #625769:625770
@@ -33,10 +33,7 @@
#include <kmainwindow.h>
#include <kparts/part.h>
-#include <ktexteditor/viewcursorinterface.h>
-#include <ktexteditor/popupmenuinterface.h>
-#include <ktexteditor/editinterface.h>
-#include <ktexteditor/selectioninterface.h>
+#include <ktexteditor/document.h>
#include <kdevmainwindow.h>
#include <kdevcore.h>
@@ -44,6 +41,7 @@
#include <kdevproject.h>
#include <codebrowserfrontend.h>
+#include "kdeveditorutil.h"
typedef KDevGenericFactory<QuickOpenPart> QuickOpenFactory;
static const KDevPluginInfo data("kdevquickopen");
@@ -102,14 +100,14 @@
void QuickOpenPart::slotQuickOpenClass( )
{
QuickOpenClassDialog dlg( this, mainWindow()->main() );
- dlg.nameEdit->setText(getWordInEditor());
+ dlg.nameEdit->setText( KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) ) ); \
dlg.exec(); }
void QuickOpenPart::slotQuickOpenFunction()
{
QuickOpenFunctionDialog dlg( this, mainWindow()->main() );
- dlg.nameEdit->setText(getWordInEditor());
+ dlg.nameEdit->setText( KDevEditorUtil::currentWord( \
dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) ) ); \
dlg.exec(); }
@@ -119,46 +117,6 @@
dlg.exec();
}
-
-QString QuickOpenPart::getWordInEditor()
-{
- KParts::ReadOnlyPart *
- ro_part = dynamic_cast<KParts::ReadOnlyPart*>(partController()->activePart());
- if (!ro_part)
- return "";
- SelectionInterface *selectIface = dynamic_cast<SelectionInterface*>(ro_part);
- ViewCursorInterface *cursorIface = \
dynamic_cast<ViewCursorInterface*>(ro_part->widget());
- EditInterface *editIface = dynamic_cast<EditInterface*>(ro_part);
- QString wordstr;
- bool hasMultilineSelection = false;
- if (selectIface && selectIface->hasSelection())
- {
- hasMultilineSelection = ( selectIface->selection().contains('\n') != 0 );
- if (!hasMultilineSelection)
- wordstr = selectIface->selection();
- }
- if (cursorIface && editIface)
- {
- uint line, col;
- line = col = 0;
- cursorIface->cursorPositionReal(&line, &col);
- QString linestr = editIface->textLine(line);
- if (wordstr.isEmpty() && !hasMultilineSelection)
- {
- int startPos = QMAX(QMIN((int)col, (int)linestr.length()-1), 0);
- int endPos = startPos;
- while (startPos >= 0 &&
- ( linestr[startPos].isLetterOrNumber() || linestr[startPos] == \
'_' ) )
- startPos--;
- while (endPos < (int)linestr.length() &&
- ( linestr[endPos].isLetterOrNumber() || linestr[endPos] == '_' ) \
)
- endPos++;
- wordstr = (startPos==endPos)? QString() : linestr.mid(startPos+1, \
endPos-startPos-1);
- }
- }
- return wordstr;
-}
-
void QuickOpenPart::selectItem( ItemDom item )
{
Extensions::KDevCodeBrowserFrontend* f = extension< \
Extensions::KDevCodeBrowserFrontend > ( \
"KDevelop/CodeBrowserFrontend" );
--- branches/kdevelop/3.4/parts/quickopen/quickopen_part.h #625769:625770
@@ -45,8 +45,6 @@
void slotSwitchTo();
private:
- QString getWordInEditor();
-
KAction* m_actionQuickOpen;
KAction* m_actionQuickOpenClass;
KAction* m_actionFunctionOpen;
--- branches/kdevelop/3.4/src/editorproxy.cpp #625769:625770
@@ -27,6 +27,7 @@
#include "partcontroller.h"
#include "core.h"
#include "multibuffer.h"
+#include "kdeveditorutil.h"
#include "editorproxy.h"
@@ -154,96 +155,64 @@
void EditorProxy::popupAboutToShow()
{
- QPopupMenu *popup = (QPopupMenu*)sender();
- if (!popup)
- return;
+ QPopupMenu *popup = (QPopupMenu*)sender();
+ if (!popup)
+ return;
+
+ // ugly hack: remove all but the "original" items
+ for (int index=popup->count()-1; index >= 0; --index)
+ {
+ int id = popup->idAt(index);
+ if (m_popupIds.contains(id) == 0)
+ {
+ QMenuItem *item = popup->findItem(id);
+ if ( item && item->popup() )
+ delete item->popup();
+ else
+ popup->removeItemAt(index);
+ }
+ }
- // ugly hack: remove all but the "original" items
- for (int index=popup->count()-1; index >= 0; --index)
- {
- int id = popup->idAt(index);
- if (m_popupIds.contains(id) == 0)
- {
- QMenuItem *item = popup->findItem(id);
- if (item->popup())
- delete item->popup();
- else
- popup->removeItemAt(index);
-// kdDebug(9000) << "removed id " << id << " at index " << index << endl;
- } else {
-// kdDebug(9000) << "leaving id " << id << endl;
- }
- }
-/* // why twice !?!?
- // ugly hack: mark the "original" items
- m_popupIds.resize(popup->count());
- for (uint index=0; index < popup->count(); ++index)
- m_popupIds[index] = popup->idAt(index);
-*/
+ KTextEditor::Document * doc = dynamic_cast<KTextEditor::Document*>( \
PartController::getInstance()->activePart() ); + if (!doc ) return;
- KParts::ReadOnlyPart *ro_part = \
dynamic_cast<KParts::ReadOnlyPart*>(PartController::getInstance()->activePart());
- if (!ro_part)
- return;
-/* // I disagree.. the EditorContext shouldn't emit the filecontext event
- // fill the menu in the file context
- FileContext context(ro_part->url().path(), false);
- Core::getInstance()->fillContextMenu(popup, &context);
-*/
- // fill the menu in the editor context
- if (!ro_part->widget())
- return;
+ unsigned int line;
+ unsigned int col;
+ if ( !KDevEditorUtil::currentPositionReal( &line, &col, doc ) ) return;
- SelectionInterface *selectIface = dynamic_cast<SelectionInterface*>(ro_part);
- ViewCursorInterface *cursorIface = \
dynamic_cast<ViewCursorInterface*>(ro_part->widget());
- EditInterface *editIface = dynamic_cast<EditInterface*>(ro_part);
+ QString wordstr;
+ QString selection = KDevEditorUtil::currentSelection( doc );
+ if ( !selection.isEmpty() && selection.contains('\n') != 0 )
+ {
+ wordstr = selection;
+ }
+ else
+ {
+ wordstr = KDevEditorUtil::currentWord( doc );
+ }
- QString wordstr, linestr;
- bool hasMultilineSelection = false;
- if( selectIface && selectIface->hasSelection() )
- {
- hasMultilineSelection = ( selectIface->selection().contains('\n') != 0 );
- if ( !hasMultilineSelection )
- {
- wordstr = selectIface->selection();
- }
- }
- if( cursorIface && editIface )
- {
- uint line, col;
- line = col = 0;
- cursorIface->cursorPositionReal(&line, &col);
- linestr = editIface->textLine(line);
- if( wordstr.isEmpty() && !hasMultilineSelection ) {
- int startPos = QMAX(QMIN((int)col, (int)linestr.length()-1), 0);
- int endPos = startPos;
- while (startPos >= 0 && ( linestr[startPos].isLetterOrNumber() || \
linestr[startPos] == '_' ) )
- startPos--;
- while (endPos < (int)linestr.length() && ( linestr[endPos].isLetterOrNumber() \
|| linestr[endPos] == '_' ) )
- endPos++;
- wordstr = (startPos==endPos)?
- QString() : linestr.mid(startPos+1, endPos-startPos-1);
- }
- kdDebug(9000) << "Word:" << wordstr << ":" << endl;
- EditorContext context(ro_part->url(), line, col, linestr, wordstr);
- Core::getInstance()->fillContextMenu(popup, &context);
- } else {
- Core::getInstance()->fillContextMenu(popup, 0);
- }
+ QString linestr = KDevEditorUtil::currentLine( doc );
+
+ EditorContext context( doc->url(), line, col, linestr, wordstr );
+ Core::getInstance()->fillContextMenu( popup, &context );
- // Remove redundant separators (any that are first, last, or doubled)
- bool lastWasSeparator = true;
- for( uint i = 0; i < popup->count(); ) {
- int id = popup->idAt( i );
- if( lastWasSeparator && popup->findItem( id )->isSeparator() ) {
- popup->removeItem( id );
- // Since we removed an item, don't increment i
- } else {
- lastWasSeparator = false;
- i++;
- }
- }
- if( lastWasSeparator && popup->count() > 0 )
- popup->removeItem( popup->idAt( popup->count() - 1 ) );
+ // Remove redundant separators (any that are first, last, or doubled)
+ bool lastWasSeparator = true;
+ for( uint i = 0; i < popup->count(); )
+ {
+ int id = popup->idAt( i );
+ if( lastWasSeparator && popup->findItem( id )->isSeparator() )
+ {
+ popup->removeItem( id );
+ // Since we removed an item, don't increment i
+ } else
+ {
+ lastWasSeparator = false;
+ i++;
+ }
+ }
+ if( lastWasSeparator && popup->count() > 0 )
+ popup->removeItem( popup->idAt( popup->count() - 1 ) );
}
void EditorProxy::showPopup( )
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic