1 /***************************************************************************
2 Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
3 ***************************************************************************/
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 ***************************************************************************/
15 #include "messagesendmanager.h"
16 #include <ktexteditor/document.h>
17 #include <ktexteditor/view.h>
19 #include <interfaces/icore.h>
20 #include <interfaces/idocument.h>
21 #include <interfaces/idocumentcontroller.h>
22 #include <indocumentreference.h>
24 #include "kdevteamworkplugin.h"
25 #include "teamworkfoldermanager.h"
27 MessageSendManager::MessageSendManager( Ui::Teamwork
& widgets
) : m_widgets( widgets
), m_lastDocument(0) {
28 connect( KDevTeamworkPlugin::staticDocumentController(), SIGNAL( documentActivated( KDevelop::IDocument
* ) ), this, SLOT( documentActivated( KDevelop::IDocument
* ) ) );
29 connect( KDevTeamworkPlugin::staticDocumentController(), SIGNAL( documentLoaded( KDevelop::IDocument
* ) ), this, SLOT( documentActivated( KDevelop::IDocument
* ) ) );
30 connect( KDevTeamworkPlugin::staticDocumentController(), SIGNAL( documentClosed( KDevelop::IDocument
* ) ), this, SLOT( documentClosed( KDevelop::IDocument
* ) ) );
31 if( KDevTeamworkPlugin::staticDocumentController()->activeDocument() )
32 documentActivated( KDevTeamworkPlugin::staticDocumentController()->activeDocument() );
35 void MessageSendManager::documentActivated( KDevelop::IDocument
* document
) {
36 if( document
== m_lastDocument
) return;
38 connectDocument( document
);
41 void MessageSendManager::documentClosed( KDevelop::IDocument
* document
) {
42 if( document
== m_lastDocument
)
46 void MessageSendManager::connectDocument( KDevelop::IDocument
* document
) {
47 m_lastDocument
= document
;
48 if( !document
->textDocument() ) return;
49 connect( document
->textDocument(), SIGNAL(destroyed( QObject
* )), this, SLOT( documentDestroyed( QObject
* ) ) );
50 connect( document
->textDocument(), SIGNAL( viewCreated( KTextEditor::Document
* , KTextEditor::View
* ) ), this, SLOT( viewCreated( KTextEditor::Document
*, KTextEditor::View
* ) ) );
52 KTextEditor::View
* v
= view();
57 void MessageSendManager::connectView( KTextEditor::View
* v
) {
58 disconnect( v
, SIGNAL( selectionChanged( KTextEditor::View
* ) ), this, SLOT( selectionChanged( KTextEditor::View
* ) ) ); ///Just to make sure that multiple connections don't happen
59 connect( v
, SIGNAL( selectionChanged( KTextEditor::View
* ) ), this, SLOT( selectionChanged( KTextEditor::View
* ) ) );
62 KTextEditor::View
* MessageSendManager::view() {
63 if( !m_lastDocument
) return 0;
64 if( !m_lastDocument
->textDocument() ) return 0;
65 return m_lastDocument
->textDocument()->activeView();
68 void MessageSendManager::disconnectDocument() {
69 KDevelop::IDocument
* document
= m_lastDocument
;
70 if( !document
) return;
71 if( !document
->textDocument() ) return;
72 disconnect( document
->textDocument(), SIGNAL(destroyed( QObject
* )), this, SLOT( documentDestroyed( QObject
* ) ) );
73 disconnect( document
->textDocument(), SIGNAL( viewCreated( KTextEditor::Document
* , KTextEditor::View
* ) ), this, SLOT( viewCreated( KTextEditor::Document
*, KTextEditor::View
* ) ) );
78 void MessageSendManager::documentDestroyed( QObject
* /*obj*/ ) {
82 void MessageSendManager::viewCreated( KTextEditor::Document
* , KTextEditor::View
* ) {
85 void MessageSendManager::selectionChanged( KTextEditor::View
* view
) {
87 m_currentSelection
= view
->selectionRange();
88 KTextEditor::Document
* doc
= view
->document();
91 m_currentFile
= TeamworkFolderManager::workspaceRelative( doc
->url() );
93 ///Now check if the message-send-widget is visible
94 if( m_widgets
.toolBox
->currentWidget() == m_widgets
.messaging
&& !m_currentFile
.isEmpty() ) {
95 if( m_currentSelection
.isEmpty() ) {
96 ///Remove the selection
98 m_widgets
.reference
->setText( InDocumentReference::createReference( m_currentFile
.pathOrUrl(), m_currentSelection
.start().line(), m_currentSelection
.start().column(), m_currentSelection
.end().line(), m_currentSelection
.end().column() ) );
103 #include "messagesendmanager.moc"
105 // kate: space-indent on; indent-width 2; tab-width 2; replace-tabs on