~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/fileselector/fileselector_widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2003 Alexander Dymo <cloudtemple@mksat.net>
3
 
   Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org>
4
 
   Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
5
 
   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
6
 
   Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
7
 
 
8
 
   This library is free software; you can redistribute it and/or
9
 
   modify it under the terms of the GNU Library General Public
10
 
   License version 2 as published by the Free Software Foundation.
11
 
 
12
 
   This library is distributed in the hope that it will be useful,
13
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
   Library General Public License for more details.
16
 
 
17
 
   You should have received a copy of the GNU Library General Public License
18
 
   along with this library; see the file COPYING.LIB.  If not, write to
19
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
   Boston, MA 02111-1307, USA.
21
 
*/
22
 
 
23
 
//BEGIN Includes
24
 
#include "fileselector_part.h"
25
 
#include "fileselector_widget.h"
26
 
#include "kactionselector.h"
27
 
#include "kbookmarkhandler.h"
28
 
 
29
 
#include <kdevcore.h>
30
 
#include <kdevmainwindow.h>
31
 
#include <kdevpartcontroller.h>
32
 
 
33
 
#include <qlayout.h>
34
 
#include <qtoolbutton.h>
35
 
#include <qhbox.h>
36
 
#include <qvbox.h>
37
 
#include <qlabel.h>
38
 
#include <qstrlist.h>
39
 
#include <qtooltip.h>
40
 
#include <qwhatsthis.h>
41
 
#include <qapplication.h>
42
 
#include <qlistbox.h>
43
 
#include <qscrollbar.h>
44
 
#include <qspinbox.h>
45
 
#include <qgroupbox.h>
46
 
#include <qcheckbox.h>
47
 
#include <qregexp.h>
48
 
#include <qdockarea.h>
49
 
#include <qtimer.h>
50
 
 
51
 
#include <ktexteditor/document.h>
52
 
 
53
 
#include <kmainwindow.h>
54
 
#include <kapplication.h>
55
 
#include <kiconloader.h>
56
 
#include <kurlcombobox.h>
57
 
#include <kurlcompletion.h>
58
 
#include <kprotocolinfo.h>
59
 
#include <kconfig.h>
60
 
#include <klocale.h>
61
 
#include <kcombobox.h>
62
 
#include <kaction.h>
63
 
#include <kmessagebox.h>
64
 
#include <ktoolbarbutton.h>
65
 
#include <qtoolbar.h>
66
 
#include <kpopupmenu.h>
67
 
#include <kdialog.h>
68
 
#include <kio/netaccess.h>
69
 
 
70
 
#include <kdebug.h>
71
 
//END Includes
72
 
 
73
 
 
74
 
// from kfiledialog.cpp - avoid qt warning in STDERR (~/.xsessionerrors)
75
 
static void silenceQToolBar(QtMsgType, const char *)
76
 
{}
77
 
 
78
 
 
79
 
KDevFileSelectorToolBar::KDevFileSelectorToolBar(QWidget *parent)
80
 
        : KToolBar( parent, "KDev FileSelector Toolbar", true )
81
 
{
82
 
    setMinimumWidth(10);
83
 
}
84
 
 
85
 
KDevFileSelectorToolBar::~KDevFileSelectorToolBar()
86
 
{}
87
 
 
88
 
void KDevFileSelectorToolBar::setMovingEnabled( bool)
89
 
{
90
 
    KToolBar::setMovingEnabled(false);
91
 
}
92
 
 
93
 
 
94
 
KDevFileSelectorToolBarParent::KDevFileSelectorToolBarParent(QWidget *parent)
95
 
        :QFrame(parent),m_tb(0)
96
 
{}
97
 
KDevFileSelectorToolBarParent::~KDevFileSelectorToolBarParent()
98
 
{}
99
 
void KDevFileSelectorToolBarParent::setToolBar(KDevFileSelectorToolBar *tb)
100
 
{
101
 
    m_tb=tb;
102
 
}
103
 
 
104
 
void KDevFileSelectorToolBarParent::resizeEvent ( QResizeEvent * )
105
 
{
106
 
    if (m_tb)
107
 
    {
108
 
        setMinimumHeight(m_tb->sizeHint().height());
109
 
        m_tb->resize(width(),height());
110
 
    }
111
 
}
112
 
 
113
 
 
114
 
//BEGIN Constructor/destructor
115
 
 
116
 
KDevFileSelector::KDevFileSelector( FileSelectorPart *part, KDevMainWindow *mainWindow,
117
 
                                    KDevPartController *partController,
118
 
                                    QWidget * parent, const char * name )
119
 
        : QWidget(parent, name),
120
 
        m_part(part),
121
 
        mainwin(mainWindow),
122
 
        partController(partController)
123
 
{
124
 
    mActionCollection = new KActionCollection( this );
125
 
 
126
 
    QVBoxLayout* lo = new QVBoxLayout(this);
127
 
 
128
 
    QtMsgHandler oldHandler = qInstallMsgHandler( silenceQToolBar );
129
 
 
130
 
    KDevFileSelectorToolBarParent *tbp=new KDevFileSelectorToolBarParent(this);
131
 
    toolbar = new KDevFileSelectorToolBar(tbp);
132
 
    tbp->setToolBar(toolbar);
133
 
    lo->addWidget(tbp);
134
 
    toolbar->setMovingEnabled(false);
135
 
    toolbar->setFlat(true);
136
 
    qInstallMsgHandler( oldHandler );
137
 
 
138
 
    cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
139
 
    cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
140
 
    KURLCompletion* cmpl = new KURLCompletion(KURLCompletion::DirCompletion);
141
 
    cmbPath->setCompletionObject( cmpl );
142
 
    lo->addWidget(cmbPath);
143
 
    cmbPath->listBox()->installEventFilter( this );
144
 
 
145
 
    dir = new KDevDirOperator(m_part, KURL(), this, "operator");
146
 
    dir->setView(KFile::/*Simple*/Detail);
147
 
 
148
 
    KActionCollection *coll = dir->actionCollection();
149
 
    // some shortcuts of diroperator that clashes with KDev
150
 
    coll->action( "delete" )->setShortcut( KShortcut( ALT + Key_Delete ) );
151
 
    coll->action( "reload" )->setShortcut( KShortcut( ALT + Key_F5 ) );
152
 
    coll->action( "back" )->setShortcut( KShortcut( ALT + SHIFT + Key_Left ) );
153
 
    coll->action( "forward" )->setShortcut( KShortcut( ALT + SHIFT + Key_Right ) );
154
 
    // some consistency - reset up for dir too
155
 
    coll->action( "up" )->setShortcut( KShortcut( ALT + SHIFT + Key_Up ) );
156
 
    coll->action( "home" )->setShortcut( KShortcut( CTRL + ALT + Key_Home ) );
157
 
 
158
 
    lo->addWidget(dir);
159
 
    lo->setStretchFactor(dir, 2);
160
 
 
161
 
    // bookmarks action!
162
 
    KActionMenu *acmBookmarks = new KActionMenu( i18n("Bookmarks"), "bookmark",
163
 
                                mActionCollection, "bookmarks" );
164
 
    acmBookmarks->setDelayed( false );
165
 
 
166
 
    bookmarkHandler = new KBookmarkHandler( this, acmBookmarks->popupMenu() );
167
 
 
168
 
    QHBox* filterBox = new QHBox(this);
169
 
 
170
 
    btnFilter = new QToolButton( filterBox );
171
 
    btnFilter->setIconSet( SmallIconSet("filter" ) );
172
 
    btnFilter->setToggleButton( true );
173
 
    filter = new KHistoryCombo( true, filterBox, "filter");
174
 
    filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
175
 
    filterBox->setStretchFactor(filter, 2);
176
 
    connect( btnFilter, SIGNAL( clicked() ), this, SLOT( btnFilterClick() ) );
177
 
    lo->addWidget(filterBox);
178
 
 
179
 
    connect( filter, SIGNAL( activated(const QString&) ),
180
 
             SLOT( slotFilterChange(const QString&) ) );
181
 
 
182
 
    connect( filter, SIGNAL( textChanged(const QString&) ),
183
 
             SLOT( slotFilterChange(const QString&) ) );
184
 
    connect( filter, SIGNAL( returnPressed(const QString&) ),
185
 
             filter, SLOT( addToHistory(const QString&) ) );
186
 
 
187
 
    // kaction for the dir sync method
188
 
    acSyncDir = new KAction( i18n("Current Document Directory"), "dirsynch", 0,
189
 
                             this, SLOT( setActiveDocumentDir() ), mActionCollection, "sync_dir" );
190
 
    toolbar->setIconText( KToolBar::IconOnly );
191
 
    toolbar->setIconSize( 16 );
192
 
    toolbar->setEnableContextMenu( false );
193
 
 
194
 
    connect( cmbPath, SIGNAL( urlActivated( const KURL&  )),
195
 
             this,  SLOT( cmbPathActivated( const KURL& ) ));
196
 
    connect( cmbPath, SIGNAL( returnPressed( const QString&  )),
197
 
             this,  SLOT( cmbPathReturnPressed( const QString& ) ));
198
 
    connect(dir, SIGNAL(urlEntered(const KURL&)),
199
 
            this, SLOT(dirUrlEntered(const KURL&)) );
200
 
 
201
 
    connect(dir, SIGNAL(finishedLoading()),
202
 
            this, SLOT(dirFinishedLoading()) );
203
 
 
204
 
    // enable dir sync button if current doc has a valid URL
205
 
    connect ( partController, SIGNAL(activePartChanged(KParts::Part*) ),
206
 
              this, SLOT(viewChanged() ) );
207
 
 
208
 
    // Connect the bookmark handler
209
 
    connect( bookmarkHandler, SIGNAL( openURL( const QString& )),
210
 
             this, SLOT( setDir( const QString& ) ) );
211
 
 
212
 
    waitingUrl = QString::null;
213
 
 
214
 
    // whatsthis help
215
 
    QWhatsThis::add
216
 
        ( cmbPath,
217
 
                i18n("<p>Here you can enter a path for a directory to display."
218
 
                     "<p>To go to a directory previously entered, press the arrow on "
219
 
                     "the right and choose one. <p>The entry has directory "
220
 
                     "completion. Right-click to choose how completion should behave.") );
221
 
    QWhatsThis::add
222
 
        ( filter,
223
 
                i18n("<p>Here you can enter a name filter to limit which files are displayed."
224
 
                     "<p>To clear the filter, toggle off the filter button to the left."
225
 
                     "<p>To reapply the last filter used, toggle on the filter button." ) );
226
 
    QWhatsThis::add
227
 
        ( btnFilter,
228
 
                i18n("<p>This button clears the name filter when toggled off, or "
229
 
                     "reapplies the last filter used when toggled on.") );
230
 
}
231
 
 
232
 
KDevFileSelector::~KDevFileSelector()
233
 
{
234
 
        writeConfig( m_part->instance()->config(), "fileselector" );
235
 
}
236
 
//END Constroctor/Destrctor
237
 
 
238
 
//BEGIN Public Methods
239
 
 
240
 
void KDevFileSelector::readConfig(KConfig *config, const QString & name)
241
 
{
242
 
    dir->readConfig(config, name + ":dir");
243
 
    dir->setView( KFile::Default );
244
 
 
245
 
    config->setGroup( name );
246
 
 
247
 
    // set up the toolbar
248
 
    setupToolbar( config );
249
 
 
250
 
    cmbPath->setMaxItems( config->readNumEntry( "pathcombo history len", 9 ) );
251
 
    cmbPath->setURLs( config->readPathListEntry("dir history") );
252
 
    // if we restore history
253
 
    if ( config->readBoolEntry( "restore location", true ) || kapp->isRestored() )
254
 
    {
255
 
        QString loc( config->readPathEntry( "location" ) );
256
 
        if ( ! loc.isEmpty() )
257
 
        {
258
 
            waitingDir = loc;
259
 
            QTimer::singleShot(0, this, SLOT(initialDirChangeHack()));
260
 
        }
261
 
    }
262
 
 
263
 
    // else is automatic, as cmpPath->setURL is called when a location is entered.
264
 
 
265
 
    filter->setMaxCount( config->readNumEntry( "filter history len", 9 ) );
266
 
    filter->setHistoryItems( config->readListEntry("filter history"), true );
267
 
    lastFilter = config->readEntry( "last filter" );
268
 
    QString flt("");
269
 
    if ( config->readBoolEntry( "restore last filter", true ) || kapp->isRestored() )
270
 
        flt = config->readEntry("current filter");
271
 
    filter->lineEdit()->setText( flt );
272
 
    slotFilterChange( flt );
273
 
 
274
 
    autoSyncEvents = config->readNumEntry( "AutoSyncEvents", 0 );
275
 
    // connect events as needed
276
 
    /// @todo - solve startup problem: no need to set location for each doc opened!
277
 
    if ( autoSyncEvents & DocumentChanged )
278
 
        connect( partController, SIGNAL( viewChanged() ), this, SLOT( autoSync() ) );
279
 
 
280
 
    if ( autoSyncEvents & DocumentOpened )
281
 
        connect( partController, SIGNAL( partAdded(KParts::Part*) ),
282
 
                 this, SLOT( autoSync(KParts::Part*) ) );
283
 
 
284
 
}
285
 
 
286
 
void KDevFileSelector::initialDirChangeHack()
287
 
{
288
 
    setDir( waitingDir );
289
 
}
290
 
 
291
 
void KDevFileSelector::setupToolbar( KConfig *config )
292
 
{
293
 
    toolbar->clear();
294
 
    QStringList tbactions = config->readListEntry( "toolbar actions", ',' );
295
 
    if ( tbactions.isEmpty() )
296
 
    {
297
 
        // resonable collection for default toolbar
298
 
        tbactions << "up" << "back" << "forward" << "home" <<
299
 
        "short view" << "detailed view" <<
300
 
        "bookmarks" << "sync_dir";
301
 
    }
302
 
    KAction *ac;
303
 
    for ( QStringList::Iterator it=tbactions.begin(); it != tbactions.end(); ++it )
304
 
    {
305
 
        if ( *it == "bookmarks" || *it == "sync_dir" )
306
 
            ac = mActionCollection->action( (*it).latin1() );
307
 
        else
308
 
            ac = dir->actionCollection()->action( (*it).latin1() );
309
 
        if ( ac )
310
 
            ac->plug( toolbar );
311
 
    }
312
 
}
313
 
 
314
 
void KDevFileSelector::writeConfig(KConfig *config, const QString & name)
315
 
{
316
 
    dir->writeConfig(config,name + ":dir");
317
 
 
318
 
    config->setGroup( name );
319
 
    config->writeEntry( "pathcombo history len", cmbPath->maxItems() );
320
 
    QStringList l;
321
 
    for (int i = 0; i < cmbPath->count(); i++)
322
 
    {
323
 
        l.append( cmbPath->text( i ) );
324
 
    }
325
 
    config->writePathEntry( "dir history", l );
326
 
    config->writePathEntry( "location", cmbPath->currentText() );
327
 
 
328
 
    config->writeEntry( "filter history len", filter->maxCount() );
329
 
    config->writeEntry( "filter history", filter->historyItems() );
330
 
    config->writeEntry( "current filter", filter->currentText() );
331
 
    config->writeEntry( "last filter", lastFilter );
332
 
    config->writeEntry( "AutoSyncEvents", autoSyncEvents );
333
 
}
334
 
 
335
 
void KDevFileSelector::setView(KFile::FileView view)
336
 
{
337
 
    dir->setView(view);
338
 
}
339
 
 
340
 
//END Public Methods
341
 
 
342
 
//BEGIN Public Slots
343
 
 
344
 
void KDevFileSelector::slotFilterChange( const QString & nf )
345
 
{
346
 
    QToolTip::remove( btnFilter );
347
 
    QString f = nf.stripWhiteSpace();
348
 
    bool empty = f.isEmpty() || f == "*";
349
 
    if ( empty )
350
 
    {
351
 
        dir->clearFilter();
352
 
        filter->lineEdit()->setText( QString::null );
353
 
        QToolTip::add
354
 
            ( btnFilter,
355
 
                    QString( i18n("Apply last filter (\"%1\")") ).arg( lastFilter ) );
356
 
    }
357
 
    else
358
 
    {
359
 
        if ( !f.startsWith( "*" ) )
360
 
            f.prepend( '*' );
361
 
        if ( !f.endsWith( "*" ) )
362
 
            f.append( '*' );
363
 
        dir->setNameFilter( f );
364
 
        lastFilter = f;
365
 
        QToolTip::add
366
 
            ( btnFilter, i18n("Clear filter") );
367
 
    }
368
 
    btnFilter->setOn( !empty );
369
 
    dir->updateDir();
370
 
    // this will be never true after the filter has been used;)
371
 
    btnFilter->setEnabled( !( empty && lastFilter.isEmpty() ) );
372
 
 
373
 
}
374
 
void KDevFileSelector::setDir( KURL u )
375
 
{
376
 
    dir->setURL(u, true);
377
 
}
378
 
 
379
 
//END Public Slots
380
 
 
381
 
//BEGIN Private Slots
382
 
 
383
 
void KDevFileSelector::cmbPathActivated( const KURL& u )
384
 
{
385
 
    cmbPathReturnPressed( u.url() );
386
 
}
387
 
 
388
 
void KDevFileSelector::cmbPathReturnPressed( const QString& u )
389
 
{
390
 
    QStringList urls = cmbPath->urls();
391
 
    urls.remove( u );
392
 
    urls.prepend( u );
393
 
    cmbPath->setURLs( urls, KURLComboBox::RemoveBottom );
394
 
    dir->setFocus();
395
 
    dir->setURL( KURL(u), true );
396
 
}
397
 
 
398
 
void KDevFileSelector::dirUrlEntered( const KURL& u )
399
 
{
400
 
    cmbPath->setURL( u );
401
 
}
402
 
 
403
 
void KDevFileSelector::dirFinishedLoading()
404
 
{}
405
 
 
406
 
 
407
 
/*
408
 
   When the button in the filter box toggles:
409
 
   If off:
410
 
   If the name filer is anything but "" or "*", reset it.
411
 
   If on:
412
 
   Set last filter.
413
 
*/
414
 
void KDevFileSelector::btnFilterClick()
415
 
{
416
 
    if ( !btnFilter->isOn() )
417
 
    {
418
 
        slotFilterChange( QString::null );
419
 
    }
420
 
    else
421
 
    {
422
 
        filter->lineEdit()->setText( lastFilter );
423
 
        slotFilterChange( lastFilter );
424
 
    }
425
 
}
426
 
 
427
 
 
428
 
void KDevFileSelector::autoSync()
429
 
{
430
 
    kdDebug()<<"KDevFileSelector::autoSync()"<<endl;
431
 
    // if visible, sync
432
 
    if ( isVisible() )
433
 
    {
434
 
        setActiveDocumentDir();
435
 
        waitingUrl = QString::null;
436
 
    }
437
 
    // else set waiting url
438
 
    else
439
 
    {
440
 
        KURL u = activeDocumentUrl();
441
 
        if (!u.isEmpty())
442
 
            waitingUrl = u.directory();
443
 
    }
444
 
}
445
 
 
446
 
void KDevFileSelector::autoSync( KParts::Part *part )
447
 
{
448
 
    KTextEditor::Document* doc = dynamic_cast<KTextEditor::Document*>( part );
449
 
    if( !doc )
450
 
        return;
451
 
 
452
 
    // as above, but using document url.
453
 
    kdDebug()<<"KDevFileSelector::autoSync( KTextEditor::Document )"<<endl;
454
 
    KURL u ( doc->url() );
455
 
    if ( u.isEmpty() )
456
 
    {
457
 
        waitingUrl = QString::null;
458
 
        return;
459
 
    }
460
 
    if ( isVisible() )
461
 
    {
462
 
        setDir( u.directory() );
463
 
        waitingUrl = QString::null;
464
 
    }
465
 
    else
466
 
    {
467
 
        waitingUrl = u.directory();
468
 
    }
469
 
}
470
 
/// \FIXME crash on shutdown
471
 
void KDevFileSelector::setActiveDocumentDir()
472
 
{
473
 
    //kdDebug()<<"KDevFileSelector::setActiveDocumentDir()"<<endl;
474
 
    KURL u = activeDocumentUrl();
475
 
    if (!u.isEmpty())
476
 
        setDir( u.upURL() );
477
 
}
478
 
 
479
 
void KDevFileSelector::viewChanged()
480
 
{
481
 
    /// @todo make sure the button is disabled if the directory is unreadable, eg
482
 
    ///       the document URL has protocol http
483
 
    acSyncDir->setEnabled( ! activeDocumentUrl().directory().isEmpty() );
484
 
}
485
 
 
486
 
//END Private Slots
487
 
 
488
 
//BEGIN Protected
489
 
 
490
 
void KDevFileSelector::focusInEvent( QFocusEvent * )
491
 
{
492
 
    dir->setFocus();
493
 
}
494
 
 
495
 
void KDevFileSelector::showEvent( QShowEvent * )
496
 
{
497
 
    // sync if we should
498
 
    if ( autoSyncEvents & GotVisible )
499
 
    {
500
 
        kdDebug()<<"syncing fs on show"<<endl;
501
 
        setActiveDocumentDir();
502
 
        waitingUrl = QString::null;
503
 
    }
504
 
    // else, if we have a waiting URL set it
505
 
    else if ( ! waitingUrl.isEmpty() )
506
 
    {
507
 
        setDir( waitingUrl );
508
 
        waitingUrl = QString::null;
509
 
    }
510
 
}
511
 
 
512
 
bool KDevFileSelector::eventFilter( QObject* o, QEvent *e )
513
 
{
514
 
    /*
515
 
        This is rather unfortunate, but:
516
 
        QComboBox does not support setting the size of the listbox to something
517
 
        resonable. Even using listbox->setVariableWidth() does not yeld a
518
 
        satisfying result, something is wrong with the handling of the sizehint.
519
 
        And the popup is rather useless, if the paths are only partly visible.
520
 
    */
521
 
    QListBox *lb = cmbPath->listBox();
522
 
    if ( o == lb && e->type() == QEvent::Show )
523
 
    {
524
 
        int add
525
 
            = lb->height() < lb->contentsHeight() ? lb->verticalScrollBar()->width() : 0;
526
 
        int w = QMIN( mainwin->main()->width(), lb->contentsWidth() + add );
527
 
        lb->resize( w, lb->height() );
528
 
        /// @todo - move the listbox to a suitable place if nessecary
529
 
        /// @todo - decide if it is worth caching the size while untill the contents
530
 
        ///        are changed.
531
 
    }
532
 
    /// @todo - same thing for the completion popup?
533
 
    return QWidget::eventFilter( o, e );
534
 
}
535
 
 
536
 
//END Protected
537
 
 
538
 
//BEGIN ACtionLBItem
539
 
/*
540
 
   QListboxItem that can store and return a string,
541
 
   used for the toolbar action selector.
542
 
*/
543
 
class ActionLBItem : public QListBoxPixmap
544
 
{
545
 
public:
546
 
    ActionLBItem( QListBox *lb=0,
547
 
                  const QPixmap &pm = QPixmap(),
548
 
                  const QString &text=QString::null,
549
 
                  const QString &str=QString::null ) :
550
 
            QListBoxPixmap( lb, pm, text ),
551
 
            _str(str)
552
 
    {}
553
 
    ;
554
 
    QString idstring()
555
 
    {
556
 
        return _str;
557
 
    };
558
 
private:
559
 
    QString _str;
560
 
};
561
 
 
562
 
KURL KDevFileSelector::activeDocumentUrl( )
563
 
{
564
 
        KParts::ReadOnlyPart * part = dynamic_cast<KParts::ReadOnlyPart*>( partController->activePart() );
565
 
        if ( part )
566
 
        {
567
 
                return part->url();
568
 
        }
569
 
 
570
 
    return KURL();
571
 
}
572
 
//END ActionLBItem
573
 
 
574
 
//BEGIN KFSConfigPage
575
 
////////////////////////////////////////////////////////////////////////////////
576
 
// KFSConfigPage implementation
577
 
////////////////////////////////////////////////////////////////////////////////
578
 
KFSConfigPage::KFSConfigPage( QWidget *parent, const char *name, KDevFileSelector *kfs )
579
 
        : QWidget( parent, name ),
580
 
        fileSelector( kfs ),
581
 
        bDirty( false )
582
 
{
583
 
    QVBoxLayout *lo = new QVBoxLayout( this );
584
 
    int spacing = KDialog::spacingHint();
585
 
    lo->setSpacing( spacing );
586
 
 
587
 
    // Toolbar - a lot for a little...
588
 
    QGroupBox *gbToolbar = new QGroupBox( 1, Qt::Vertical, i18n("Toolbar"), this );
589
 
    acSel = new KActionSelector( gbToolbar );
590
 
    acSel->setAvailableLabel( i18n("A&vailable actions:") );
591
 
    acSel->setSelectedLabel( i18n("S&elected actions:") );
592
 
    lo->addWidget( gbToolbar );
593
 
    connect( acSel, SIGNAL( added( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
594
 
    connect( acSel, SIGNAL( removed( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
595
 
    connect( acSel, SIGNAL( movedUp( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
596
 
    connect( acSel, SIGNAL( movedDown( QListBoxItem * ) ), this, SLOT( slotChanged() ) );
597
 
 
598
 
    // Sync
599
 
    QGroupBox *gbSync = new QGroupBox( 1, Qt::Horizontal, i18n("Auto Synchronization"), this );
600
 
    cbSyncActive = new QCheckBox( i18n("When a docu&ment becomes active"), gbSync );
601
 
    cbSyncOpen = new QCheckBox( i18n("When a document is o&pened"), gbSync );
602
 
    cbSyncShow = new QCheckBox( i18n("When the file selector becomes visible"), gbSync );
603
 
    lo->addWidget( gbSync );
604
 
    connect( cbSyncActive, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
605
 
    connect( cbSyncOpen, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
606
 
    connect( cbSyncShow, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
607
 
 
608
 
    // Histories
609
 
    QHBox *hbPathHist = new QHBox ( this );
610
 
    QLabel *lbPathHist = new QLabel( i18n("Remember &locations:"), hbPathHist );
611
 
    sbPathHistLength = new QSpinBox( hbPathHist );
612
 
    lbPathHist->setBuddy( sbPathHistLength );
613
 
    lo->addWidget( hbPathHist );
614
 
    connect( sbPathHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
615
 
 
616
 
    QHBox *hbFilterHist = new QHBox ( this );
617
 
    QLabel *lbFilterHist = new QLabel( i18n("Remember &filters:"), hbFilterHist );
618
 
    sbFilterHistLength = new QSpinBox( hbFilterHist );
619
 
    lbFilterHist->setBuddy( sbFilterHistLength );
620
 
    lo->addWidget( hbFilterHist );
621
 
    connect( sbFilterHistLength, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
622
 
 
623
 
    // Session
624
 
    QGroupBox *gbSession = new QGroupBox( 1, Qt::Horizontal, i18n("Session"), this );
625
 
    cbSesLocation = new QCheckBox( i18n("Restore loca&tion"), gbSession );
626
 
    cbSesFilter = new QCheckBox( i18n("Restore last f&ilter"), gbSession );
627
 
    lo->addWidget( gbSession );
628
 
    connect( cbSesLocation, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
629
 
    connect( cbSesFilter, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
630
 
 
631
 
    // make it look nice
632
 
    lo->addStretch( 1 );
633
 
 
634
 
    // be helpfull
635
 
    /*
636
 
    QWhatsThis::add( lbAvailableActions, i18n(
637
 
          "<p>Available actions for the toolbar. To add an action, select it here "
638
 
          "and press the add (<strong>-&gt;</strong>) button" ) );
639
 
    QWhatsThis::add( lbUsedActions, i18n(
640
 
          "<p>Actions used in the toolbar. To remove an action, select it and "
641
 
          "press the remove (<strong>&lt;-</strong>) button."
642
 
          "<p>To change the order of the actions, use the Up and Down buttons to "
643
 
          "move the selected action.") );
644
 
    */
645
 
    QString lhwt( i18n(
646
 
                      "<p>Decides how many locations to keep in the history of the location "
647
 
                      "combo box") );
648
 
    QWhatsThis::add
649
 
        ( lbPathHist, lhwt );
650
 
    QWhatsThis::add
651
 
        ( sbPathHistLength, lhwt );
652
 
    QString fhwt( i18n(
653
 
                      "<p>Decides how many filters to keep in the history of the filter "
654
 
                      "combo box") );
655
 
    QWhatsThis::add
656
 
        ( lbFilterHist, fhwt );
657
 
    QWhatsThis::add
658
 
        ( sbFilterHistLength, fhwt );
659
 
    QString synwt( i18n(
660
 
                       "<p>These options allow you to have the File Selector automatically "
661
 
                       "change location to the directory of the active document on certain "
662
 
                       "events."
663
 
                       "<p>Auto synchronization is <em>lazy</em>, meaning it will not take "
664
 
                       "effect until the file selector is visible."
665
 
                       "<p>None of these are enabled by default, but you can always sync the "
666
 
                       "location by pressing the sync button in the toolbar.") );
667
 
    QWhatsThis::add
668
 
        ( gbSync, synwt );
669
 
    QWhatsThis::add
670
 
        ( cbSesLocation, i18n(
671
 
                    "<p>If this option is enabled (default), the location will be restored "
672
 
                    "when you start KDev.<p><strong>Note</strong> that if the session is "
673
 
                    "handled by the KDE session manager, the location is always restored.") );
674
 
    QWhatsThis::add
675
 
        ( cbSesFilter, i18n(
676
 
                    "<p>If this option is enabled (default), the current filter will be "
677
 
                    "restored when you start KDev.<p><strong>Note</strong> that if the "
678
 
                    "session is handled by the KDE session manager, the filter is always "
679
 
                    "restored."
680
 
                    "<p><strong>Note</strong> that some of the autosync settings may "
681
 
                    "override the restored location if on.") );
682
 
 
683
 
    init();
684
 
 
685
 
}
686
 
 
687
 
void KFSConfigPage::apply()
688
 
{
689
 
    KConfig *config = fileSelector->m_part->instance()->config();
690
 
    config->setGroup( "fileselector" );
691
 
    // toolbar
692
 
    QStringList l;
693
 
    QListBoxItem *item = acSel->selectedListBox()->firstItem();
694
 
    ActionLBItem *aItem;
695
 
    while ( item )
696
 
    {
697
 
        aItem = (ActionLBItem*)item;
698
 
        if ( aItem )
699
 
        {
700
 
            l << aItem->idstring();
701
 
        }
702
 
        item = item->next();
703
 
    }
704
 
    config->writeEntry( "toolbar actions", l );
705
 
    fileSelector->setupToolbar( config );
706
 
    // sync
707
 
    int s = 0;
708
 
    if ( cbSyncActive->isChecked() )
709
 
        s |= KDevFileSelector::DocumentChanged;
710
 
    if ( cbSyncOpen->isChecked() )
711
 
        s |= KDevFileSelector::DocumentOpened;
712
 
    if ( cbSyncShow->isChecked() )
713
 
        s |= KDevFileSelector::GotVisible;
714
 
    fileSelector->autoSyncEvents = s;
715
 
    // reset connections
716
 
    disconnect( fileSelector->partController, 0, fileSelector, SLOT( autoSync() ) );
717
 
    disconnect( fileSelector->partController, 0,
718
 
                fileSelector, SLOT( autoSync( KParts::Part *) ) );
719
 
    if ( s & KDevFileSelector::DocumentChanged )
720
 
        connect( fileSelector->partController, SIGNAL( viewChanged() ),
721
 
                 fileSelector, SLOT( autoSync() ) );
722
 
    if ( s & KDevFileSelector::DocumentOpened )
723
 
        connect( fileSelector->partController,
724
 
                 SIGNAL( partAdded(KParts::Part *) ),
725
 
                 fileSelector, SLOT( autoSync(KParts::Part *) ) );
726
 
 
727
 
    // histories
728
 
    fileSelector->cmbPath->setMaxItems( sbPathHistLength->value() );
729
 
    fileSelector->filter->setMaxCount( sbFilterHistLength->value() );
730
 
    // session - theese are read/written directly to the app config,
731
 
    //           as they are not needed during operation.
732
 
    config->writeEntry( "restore location", cbSesLocation->isChecked() );
733
 
    config->writeEntry( "restore last filter", cbSesFilter->isChecked() );
734
 
}
735
 
 
736
 
void KFSConfigPage::reload()
737
 
{
738
 
    // hmm, what is this supposed to do, actually??
739
 
    init();
740
 
}
741
 
 
742
 
void KFSConfigPage::init()
743
 
{
744
 
    KConfig *config = fileSelector->m_part->instance()->config();
745
 
    config->setGroup( "fileselector" );
746
 
    // toolbar
747
 
    QStringList l = config->readListEntry( "toolbar actions", ',' );
748
 
    if ( l.isEmpty() ) // default toolbar
749
 
        l << "up" << "back" << "forward" << "home" <<
750
 
        "short view" << "detailed view" <<
751
 
        "bookmarks" << "sync_dir";
752
 
 
753
 
    // actions from diroperator + two of our own
754
 
    QStringList allActions;
755
 
    allActions << "up" << "back" << "forward" << "home" <<
756
 
    "reload" << "mkdir" << "delete" <<
757
 
    "short view" << "detailed view" /*<< "view menu" <<
758
 
                      "show hidden" << "properties"*/ <<
759
 
    "bookmarks" << "sync_dir";
760
 
    QRegExp re("&(?=[^&])");
761
 
    KAction *ac;
762
 
    QListBox *lb;
763
 
    for ( QStringList::Iterator it=allActions.begin(); it != allActions.end(); ++it )
764
 
    {
765
 
        lb = l.contains( *it ) ? acSel->selectedListBox() : acSel->availableListBox();
766
 
        if ( *it == "bookmarks" || *it == "sync_dir" )
767
 
            ac = fileSelector->actionCollection()->action( (*it).latin1() );
768
 
        else
769
 
            ac = fileSelector->dirOperator()->actionCollection()->action( (*it).latin1() );
770
 
        if ( ac )
771
 
            new ActionLBItem( lb, SmallIcon( ac->icon() ), ac->text().replace( re, "" ), *it );
772
 
    }
773
 
 
774
 
    // sync
775
 
    int s = fileSelector->autoSyncEvents;
776
 
    cbSyncActive->setChecked( s & KDevFileSelector::DocumentChanged );
777
 
    cbSyncOpen->setChecked( s & KDevFileSelector::DocumentOpened );
778
 
    cbSyncShow->setChecked( s & KDevFileSelector::GotVisible );
779
 
    // histories
780
 
    sbPathHistLength->setValue( fileSelector->cmbPath->maxItems() );
781
 
    sbFilterHistLength->setValue( fileSelector->filter->maxCount() );
782
 
    // session
783
 
    cbSesLocation->setChecked( config->readBoolEntry( "restore location", true ) );
784
 
    cbSesFilter->setChecked( config->readBoolEntry( "restore last filter", true ) );
785
 
}
786
 
 
787
 
void KFSConfigPage::slotChanged()
788
 
{
789
 
}
790
 
 
791
 
//END KFSConfigPage
792
 
 
793
 
 
794
 
//BEGIN KDevDirOperator
795
 
 
796
 
void KDevDirOperator::activatedMenu( const KFileItem *fi, const QPoint & pos )
797
 
{
798
 
    setupMenu();
799
 
    updateSelectionDependentActions();
800
 
 
801
 
    KActionMenu * am = dynamic_cast<KActionMenu*>(actionCollection()->action("popupMenu"));
802
 
    if (!am)
803
 
        return;
804
 
    KPopupMenu *popup = am->popupMenu();
805
 
 
806
 
    popup->insertSeparator();
807
 
    m_part->newFileAction()->plug(popup);
808
 
 
809
 
    if (fi)
810
 
    {
811
 
        FileContext context( KURL::List(fi->url()));
812
 
        if ( (m_part) && (m_part->core()))
813
 
            m_part->core()->fillContextMenu(popup, &context);
814
 
    }
815
 
 
816
 
    popup->popup(pos);
817
 
}
818
 
 
819
 
//END KDevDirOperator
820
 
 
821
 
#include "fileselector_widget.moc"