20 #include "katebookmarks.h"
21 #include "katebookmarks.moc"
23 #include "katedocument.h"
27 #include <tdeaction.h>
28 #include <tdepopupmenu.h>
29 #include <kstringhandler.h>
30 #include <kxmlguiclient.h>
31 #include <kxmlguifactory.h>
34 #include <tqmemarray.h>
44 static void ssort( TQMemArray<uint> &a,
int max )
47 for ( uint h = max; h >= 1; h-- )
50 for ( j = 0; j <= h; j++ )
51 maxpos = a[j] > a[maxpos] ? j : maxpos;
60 KateBookmarks::KateBookmarks( KateView* view, Sorting sort )
61 : TQObject( view,
"kate bookmarks" )
65 connect (view->
getDoc(), TQ_SIGNAL(marksChanged()),
this, TQ_SLOT(marksChanged()));
70 KateBookmarks::~KateBookmarks()
77 i18n(
"Set &Bookmark"),
"bookmark", CTRL+Key_B,
78 this, TQ_SLOT(toggleBookmark()),
79 ac,
"bookmarks_toggle" );
80 m_bookmarkToggle->setWhatsThis(i18n(
"If a line has no bookmark then add one, otherwise remove it."));
81 m_bookmarkToggle->setCheckedState( i18n(
"Clear &Bookmark") );
84 i18n(
"Clear &All Bookmarks"), 0,
85 this, TQ_SLOT(clearBookmarks()),
86 ac,
"bookmarks_clear");
87 m_bookmarkClear->setWhatsThis(i18n(
"Remove all bookmarks of the current document."));
90 i18n(
"Next Bookmark"),
"go-next", ALT + Key_PageDown,
91 this, TQ_SLOT(goNext()),
92 ac,
"bookmarks_next");
93 m_goNext->setWhatsThis(i18n(
"Go to the next bookmark."));
96 i18n(
"Previous Bookmark"),
"go-previous", ALT + Key_PageUp,
97 this, TQ_SLOT(goPrevious()),
98 ac,
"bookmarks_previous");
99 m_goPrevious->setWhatsThis(i18n(
"Go to the previous bookmark."));
101 m_bookmarksMenu = (
new TDEActionMenu(i18n(
"&Bookmarks"), ac,
"bookmarks"))->popupMenu();
105 connect( m_bookmarksMenu, TQ_SIGNAL(aboutToShow()),
this, TQ_SLOT(bookmarkMenuAboutToShow()));
106 connect( m_bookmarksMenu, TQ_SIGNAL(aboutToHide()),
this, TQ_SLOT(bookmarkMenuAboutToHide()) );
109 bookmarkMenuAboutToHide();
111 connect( m_view, TQ_SIGNAL( gotFocus(
Kate::View * ) ),
this, TQ_SLOT( slotViewGotFocus(
Kate::View * ) ) );
112 connect( m_view, TQ_SIGNAL( lostFocus(
Kate::View * ) ),
this, TQ_SLOT( slotViewLostFocus(
Kate::View * ) ) );
115 void KateBookmarks::toggleBookmark ()
117 uint mark = m_view->getDoc()->mark( m_view->cursorLine() );
118 if( mark & KTextEditor::MarkInterface::markType01 )
119 m_view->getDoc()->removeMark( m_view->cursorLine(),
120 KTextEditor::MarkInterface::markType01 );
122 m_view->getDoc()->addMark( m_view->cursorLine(),
123 KTextEditor::MarkInterface::markType01 );
126 void KateBookmarks::clearBookmarks ()
129 TQPtrList<KTextEditor::Mark> m = m_view->getDoc()->marks();
130 for (uint i=0; i < m.count(); i++)
131 m_view->getDoc()->removeMark( m.at(i)->line, KTextEditor::MarkInterface::markType01 );
137 void KateBookmarks::slotViewGotFocus(
Kate::View *v )
140 bookmarkMenuAboutToHide();
143 void KateBookmarks::slotViewLostFocus(
Kate::View *v )
146 m_bookmarksMenu->clear();
149 void KateBookmarks::insertBookmarks( TQPopupMenu& menu )
151 uint line = m_view->cursorLine();
152 const TQRegExp re(
"&(?!&)");
154 int old_menu_count = menu.count();
155 KTextEditor::Mark *
next = 0;
156 KTextEditor::Mark *prev = 0;
158 TQPtrList<KTextEditor::Mark> m = m_view->
getDoc()->marks();
159 TQMemArray<uint> sortArray( m.count() );
160 TQPtrListIterator<KTextEditor::Mark> it( m );
162 if ( it.count() > 0 )
163 menu.insertSeparator();
165 for(
int i = 0; *it; ++it, ++i )
167 if( (*it)->type & KTextEditor::MarkInterface::markType01 )
170 ( m_view->
getDoc()->textLine( (*it)->line ),
171 menu.fontMetrics(), 32 );
172 bText.replace(re,
"&&");
173 bText.replace(
'\t',
' ');
175 if ( m_sorting == Position )
177 sortArray[i] = (*it)->line;
178 ssort( sortArray, i );
179 idx = sortArray.find( (*it)->line ) + 3;
183 TQString(
"%1 - \"%2\"").arg( (*it)->line+1 ).arg( bText ),
184 m_view, TQ_SLOT(gotoLineNumber(
int)), 0, (*it)->line, idx );
186 if ( (*it)->line < line )
188 if ( ! prev || prev->line < (*it)->line )
192 else if ( (*it)->line > line )
194 if ( ! next ||
next->line > (*it)->line )
200 idx = ++old_menu_count;
203 m_goNext->setText( i18n(
"&Next: %1 - \"%2\"").arg(
next->line + 1 )
205 m_goNext->plug( &menu, idx );
210 m_goPrevious->setText( i18n(
"&Previous: %1 - \"%2\"").arg(prev->line + 1 )
212 m_goPrevious->plug( &menu, idx );
216 menu.insertSeparator( idx );
220 void KateBookmarks::bookmarkMenuAboutToShow()
223 TQPtrList<KTextEditor::Mark> m = m_view->
getDoc()->marks();
225 m_bookmarksMenu->clear();
226 m_bookmarkToggle->setChecked( m_view->
getDoc()->mark( m_view->cursorLine() )
227 & KTextEditor::MarkInterface::markType01 );
228 m_bookmarkToggle->plug( m_bookmarksMenu );
229 m_bookmarkClear->plug( m_bookmarksMenu );
232 insertBookmarks(*m_bookmarksMenu);
238 void KateBookmarks::bookmarkMenuAboutToHide()
240 m_bookmarkToggle->plug( m_bookmarksMenu );
241 m_bookmarkClear->plug( m_bookmarksMenu );
242 m_goNext->setText( i18n(
"Next Bookmark") );
243 m_goNext->plug( m_bookmarksMenu );
244 m_goPrevious->setText( i18n(
"Previous Bookmark") );
245 m_goPrevious->plug( m_bookmarksMenu );
248 void KateBookmarks::goNext()
250 TQPtrList<KTextEditor::Mark> m = m_view->
getDoc()->marks();
254 uint line = m_view->cursorLine();
257 for (uint z=0; z < m.count(); z++)
258 if ( (m.at(z)->line > line) && ((found == -1) || (uint(found) > m.at(z)->line)) )
259 found = m.at(z)->line;
262 m_view->gotoLineNumber ( found );
265 void KateBookmarks::goPrevious()
267 TQPtrList<KTextEditor::Mark> m = m_view->
getDoc()->marks();
271 uint line = m_view->cursorLine();
274 for (uint z=0; z < m.count(); z++)
275 if ((m.at(z)->line < line) && ((found == -1) || (uint(found) < m.at(z)->line)))
276 found = m.at(z)->line;
279 m_view->gotoLineNumber ( found );
282 void KateBookmarks::marksChanged ()
284 m_bookmarkClear->setEnabled( !m_view->
getDoc()->marks().isEmpty() );
static TQString rEmSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxlen=30)
static TQString rsqueeze(const TQString &str, uint maxlen=40)
The Kate::View text editor interface.
virtual Document * getDoc()
Returns a pointer to the document of the view.
const TDEShortcut & next()