summaryrefslogtreecommitdiffstats
path: root/parts/fileview/partwidget.cpp
blob: 4387b26cefbd227bdf8cd69c36d5cec0d11e25a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/***************************************************************************
 *   Copyright (C) 2003 by KDevelop authors                                *
 *   [email protected]                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include "partwidget.h"

#include <tqwhatsthis.h>
#include <tqvbox.h>
#include <tqlayout.h>
#include <tqtoolbutton.h>
#include <tqdom.h>
#include <kxmlguiclient.h>
#include <kcombobox.h>
#include <tdeaction.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <tdelocale.h>

#include "kdevversioncontrol.h"
#include "kdevcore.h"
#include "kdevproject.h"
#include "kdevmainwindow.h"

#include "fileviewpart.h"
#include "filetreewidget.h"

///////////////////////////////////////////////////////////////////////////////
// class PartWidget
///////////////////////////////////////////////////////////////////////////////

PartWidget::PartWidget( FileViewPart *part, TQWidget *parent )
    : TQVBox( parent, "fileviewpartwidget" ), m_filetree( 0 ),
    m_filter( 0 ), m_btnFilter( 0 ), m_part( part )
{
    Q_ASSERT( part && parent );

    KDevVCSFileInfoProvider *infoProvider = 0;
    if (part && part->versionControl() && part->versionControl()->fileInfoProvider())
        infoProvider = part->versionControl()->fileInfoProvider();

    m_filetree = new FileTreeWidget( m_part, this, infoProvider );
    setCaption(i18n("File Tree"));
    m_filetree->setCaption(i18n("File Tree"));
    m_filetree->setIcon(SmallIcon("folder"));
    TQWhatsThis::add(m_filetree, i18n("<b>File tree</b><p>"
                                    "The file viewer shows all files of the project "
                                    "in a tree layout."));

    TQHBox* filterBox = new TQHBox( this );
    m_btnFilter = new TQToolButton( filterBox );
    m_btnFilter->setIconSet( SmallIconSet("filter" ) );
    m_btnFilter->setToggleButton( true );
    m_filter = new KHistoryCombo( true, filterBox, "filter");
    m_filter->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
    filterBox->setStretchFactor(m_filter, 2);

    connect( m_btnFilter, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotBtnFilterClick() ) );
    connect( m_filter, TQ_SIGNAL( activated(const TQString&) ), this, TQ_SLOT( slotFilterChange(const TQString&) ) );
    connect( m_filter, TQ_SIGNAL( returnPressed(const TQString&) ),
             m_filter, TQ_SLOT( addToHistory(const TQString&) ) );

    TQWhatsThis::add
        ( m_filter,
                i18n("<p>Here you can enter a name filter to limit which files are <b>not displayed</b>."
                     "<p>To clear the filter, toggle off the filter button to the left."
                     "<p>To reapply the last filter used, toggle on the filter button." ) );
    TQWhatsThis::add
        ( m_btnFilter,
                i18n("<p>This button clears the name filter when toggled off, or "
                     "reapplies the last filter used when toggled on.") );

    m_filter->insertItem( m_filetree->hidePatterns() );
}

///////////////////////////////////////////////////////////////////////////////

PartWidget::~PartWidget()
{
}

///////////////////////////////////////////////////////////////////////////////

void PartWidget::showProjectFiles()
{
    m_filetree->openDirectory( m_part->project()->projectDirectory() );
    m_filetree->applyHidePatterns( m_filetree->hidePatterns() );
}

///////////////////////////////////////////////////////////////////////////////

void PartWidget::slotFilterChange( const TQString & nf )
{
    TQString f = nf.stripWhiteSpace();
    bool empty = f.isEmpty() || f == "*";
    if ( empty )
    {
        m_filter->lineEdit()->setText( TQString() );
        TQToolTip::add( m_btnFilter, i18n("Apply last filter (\"%1\")").arg( m_lastFilter ) );
    }
    else
    {
        m_lastFilter = f;
        TQToolTip::add( m_btnFilter, i18n("Clear filter") );
    }
    m_btnFilter->setOn( !empty );
    // this will be never true after the m_filter has been used;)
    m_btnFilter->setEnabled( !( empty && m_lastFilter.isEmpty() ) );

    m_filetree->applyHidePatterns( f );
}

///////////////////////////////////////////////////////////////////////////////
/*
   When the button in the filter box toggles:
   If off:
   If the name filer is anything but "" or "*", reset it.
   If on:
   Set last filter.
*/
void PartWidget::slotBtnFilterClick()
{
    if ( !m_btnFilter->isOn() )
    {
        slotFilterChange( TQString() );
    }
    else
    {
        m_filter->lineEdit()->setText( m_lastFilter );
        slotFilterChange( m_lastFilter );
    }
}

void PartWidget::focusInEvent( TQFocusEvent * )
{
    m_filetree->setFocus();
}

#include "partwidget.moc"