• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Utility Library
 

KDevelop Utility Library

  • lib
  • util
kdeveditorutil.cpp
1 /***************************************************************************
2  * Copyright (C) 2007 by Jens Dagerbo *
3  * jens.dagerbo@swipnet.se *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  ***************************************************************************/
11 
12 #include "kdeveditorutil.h"
13 
14 #include <tdetexteditor/document.h>
15 #include <tdetexteditor/view.h>
16 #include <tdetexteditor/viewcursorinterface.h>
17 #include <tdetexteditor/editinterface.h>
18 #include <tdetexteditor/selectioninterface.h>
19 
20 bool KDevEditorUtil::currentPositionReal( unsigned int * line, unsigned int * col, KTextEditor::Document * doc, KTextEditor::View * view )
21 {
22  if ( !line || !col ) return false;
23 
24  KTextEditor::EditInterface * editIface = dynamic_cast<KTextEditor::EditInterface*>( doc );
25  if ( !editIface ) return false;
26 
27  view = view ? view : dynamic_cast<KTextEditor::View*>( doc->widget() );
28 
29  KTextEditor::ViewCursorInterface * cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>( view );
30  if ( !cursorIface ) return false;
31 
32  cursorIface->cursorPositionReal( line, col );
33  return true;
34 }
35 
36 TQString KDevEditorUtil::currentLine( KTextEditor::Document * doc, KTextEditor::View * view )
37 {
38  KTextEditor::EditInterface * editIface = dynamic_cast<KTextEditor::EditInterface*>( doc );
39  if ( !editIface ) return TQString();
40 
41  view = view ? view : dynamic_cast<KTextEditor::View*>( doc->widget() );
42 
43  KTextEditor::ViewCursorInterface * cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>( view );
44  if ( !cursorIface ) return TQString();
45 
46  uint line = 0;
47  uint col = 0;
48  cursorIface->cursorPositionReal(&line, &col);
49 
50  return editIface->textLine(line);
51 }
52 
53 TQString KDevEditorUtil::currentWord( KTextEditor::Document * doc, KTextEditor::View * view )
54 {
55  KTextEditor::EditInterface * editIface = dynamic_cast<KTextEditor::EditInterface*>( doc );
56  if ( !editIface ) return TQString();
57 
58  view = view ? view : dynamic_cast<KTextEditor::View*>( doc->widget() );
59 
60  KTextEditor::ViewCursorInterface * cursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>( view );
61  if ( !cursorIface ) return TQString();
62 
63  uint line = 0;
64  uint col = 0;
65  cursorIface->cursorPositionReal(&line, &col);
66 
67  TQString linestr = editIface->textLine(line);
68 
69  int startPos = TQMAX( TQMIN( (int)col, (int)linestr.length()-1 ), 0 );
70  int endPos = startPos;
71  startPos--;
72  while (startPos >= 0 && ( linestr[startPos].isLetterOrNumber() || linestr[startPos] == '_' || linestr[startPos] == '~') )
73  startPos--;
74  while (endPos < (int)linestr.length() && ( linestr[endPos].isLetterOrNumber() || linestr[endPos] == '_' ) )
75  endPos++;
76 
77  return ( ( startPos == endPos ) ? TQString() : linestr.mid( startPos+1, endPos-startPos-1 ) );
78 }
79 
80 
81 TQString KDevEditorUtil::currentSelection( KTextEditor::Document * doc )
82 {
83  KTextEditor::SelectionInterface * selectIface = dynamic_cast<KTextEditor::SelectionInterface*>( doc );
84  return selectIface ? selectIface->selection() : TQString();
85 }
86 
87 
88 // kate: space-indent off; indent-width 4; tab-width 4; show-tabs on;
89 
KDevEditorUtil::currentSelection
static TQString currentSelection(KTextEditor::Document *doc)
Call to get the selection in the currently active view.
Definition: kdeveditorutil.cpp:81
KDevEditorUtil::currentLine
static TQString currentLine(KTextEditor::Document *doc, KTextEditor::View *view=0)
Definition: kdeveditorutil.cpp:36
KDevEditorUtil::currentWord
static TQString currentWord(KTextEditor::Document *doc, KTextEditor::View *view=0)
Call to get the text under the cursor of the currently active view.
Definition: kdeveditorutil.cpp:53
KDevEditorUtil::currentPositionReal
static bool currentPositionReal(unsigned int *line, unsigned int *col, KTextEditor::Document *doc, KTextEditor::View *view=0)
Definition: kdeveditorutil.cpp:20

KDevelop Utility Library

Skip menu "KDevelop Utility Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDevelop Utility Library

Skip menu "KDevelop Utility Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Utility Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.