summaryrefslogtreecommitdiffstats
path: root/parts/quickopen/quickopenfiledialog.cpp
blob: fc8da49ac7165c36c9045acb20a7d4753cf1b690 (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
/*
 *  Copyright (C) 2003 Roberto Raggi (roberto@kdevelop.org)
 *
 *  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.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */

#include <tdevproject.h>
#include <tdevpartcontroller.h>


#include <tdelistbox.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <kcompletion.h>
#include <klineedit.h>


#include <tqregexp.h>
#include <tqlabel.h>

#include "quickopenfiledialog.h"
#include "quickopen_part.h"

QuickOpenFileDialog::QuickOpenFileDialog(QuickOpenPart* part, TQWidget* parent, const char* name, bool modal, WFlags fl)
    : QuickOpenDialog( part, parent, name, modal, fl ), m_hasFullPaths( false )
{
    nameLabel->setText( i18n("File &name:") );
    itemListLabel->setText( i18n("File &list:") );

    m_items = m_part->project()->allFiles();

    nameEdit->setFocus();

    itemList->setSelectionMode( TQListBox::Extended );
    itemList->insertStringList( m_items );
    setFirstItemSelected();
}

QuickOpenFileDialog::QuickOpenFileDialog(QuickOpenPart* part, const KURL::List & urls, TQWidget* parent, const char* name, bool modal, WFlags fl)
    : QuickOpenDialog( part, parent, name, modal, fl ), m_hasFullPaths( true )
{
    nameLabel->setText( i18n("File &name:") );
    itemListLabel->setText( i18n("File &list:") );

    m_items = urls.toStringList();
    TQStringList_unique( m_items );

    if (m_part->project())
    {
        for (unsigned int i = 0; i < m_items.count(); ++i)
        {
            TQString url = m_items[i];
            TQString projectUrl = "file://" + m_part->project()->projectDirectory();
            if (url.startsWith(projectUrl))
                m_items[i] = url.mid(projectUrl.length() + 1);
        }
    }

    nameEdit->setFocus();

    itemList->setSelectionMode( TQListBox::Extended );
    itemList->insertStringList( m_items );
    setFirstItemSelected();
}

QuickOpenFileDialog::~QuickOpenFileDialog()
{
}

void QuickOpenFileDialog::slotExecuted( TQListBoxItem* item )
{
    if ( !item ) return;

    if ( m_hasFullPaths )
    {
        m_part->partController()->editDocument( KURL::fromPathOrURL( item->text() ) );
    }
    else
    {
        m_part->partController()->editDocument( KURL::fromPathOrURL( m_part->project()->projectDirectory() + "/" + item->text() ) );
    }
    accept();
}

void QuickOpenFileDialog::slotReturnPressed( )
{
    maybeUpdateSelection();

    for (int i = 0; i < itemList->count(); ++i)
    {
        if (itemList->isSelected(i))
        {
            if (m_hasFullPaths)
            {
                m_part->partController()->editDocument(KURL::fromPathOrURL(itemList->item(i)->text()));
            }
            else
            {
                m_part->partController()->editDocument(KURL::fromPathOrURL(m_part->project()->projectDirectory() + "/" + itemList->item(i)->text()));
            }
        }
    }
    accept();
}

#include "quickopenfiledialog.moc"