summaryrefslogtreecommitdiffstats
path: root/parts/fileselector/fileselector_widget.h
blob: 5ff80ed9cc76b917680a7749e4b8cc220c113cf8 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* This file is part of the KDE project
   Copyright (C) 2003 Roberto Raggi <roberto@tdevelop.org>
   Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
   Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library 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 Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef FILESELECTOR_WIDGET_H
#define FILESELECTOR_WIDGET_H

#include <tqwidget.h>
#include <tdefile.h>
#include <kurl.h>
#include <tdetoolbar.h>
#include <tqframe.h>
#include <tdediroperator.h>

class KDevMainWindow;
class KDevPartController;
class FileSelectorPart;
class TDEActionCollection;
class TDEActionSelector;
class KDirOperator;
class KURLComboBox;
class KHistoryCombo;

namespace KParts
{
    class Part;
}

namespace KTextEditor
{
    class Document;
}

/*
    The KDev file selector presents a directory view, in which the default action is
    to open the activated file.
    Additinally, a toolbar for managing the kdiroperator widget + sync that to
    the directory of the current file is available, as well as a filter widget
    allowing to filter the displayed files using a name filter.
*/

/* I think this fix for not moving toolbars is better */
class KDevFileSelectorToolBar: public TDEToolBar
{
    Q_OBJECT
  
public:
    KDevFileSelectorToolBar(TQWidget *parent);
    virtual ~KDevFileSelectorToolBar();

    virtual void setMovingEnabled( bool b );
};

class KDevFileSelectorToolBarParent: public TQFrame
{
    Q_OBJECT
  
public:
    KDevFileSelectorToolBarParent(TQWidget *parent);
    ~KDevFileSelectorToolBarParent();
    void setToolBar(KDevFileSelectorToolBar *tb);

private:
    KDevFileSelectorToolBar *m_tb;

protected:
    virtual void resizeEvent ( TQResizeEvent * );
};

class KDevDirOperator: public KDirOperator
{
    Q_OBJECT
  
public:
    KDevDirOperator(FileSelectorPart *part, const KURL &urlName=KURL(), TQWidget *parent=0, const char *name=0)
        :KDirOperator(urlName, parent, name), m_part(part)
    {
    }

protected slots:
    virtual void activatedMenu (const KFileItem *fi, const TQPoint &pos);

private:
    FileSelectorPart *m_part;
};

class KDevFileSelector : public TQWidget
{
    Q_OBJECT
  

    friend class KFSConfigPage;

public:
    /* When to sync to current document directory */
    enum AutoSyncEvent { DocumentChanged=1, DocumentOpened=2, GotVisible=4 };

    KDevFileSelector( FileSelectorPart *part, KDevMainWindow *mainWindow=0, KDevPartController *partController=0,
                      TQWidget * parent = 0, const char * name = 0 );
    ~KDevFileSelector();

    void readConfig( TDEConfig *, const TQString & );
    void writeConfig( TDEConfig *, const TQString & );
    void setupToolbar( TDEConfig * );
    void setView( KFile::FileView );
    KDevDirOperator *dirOperator(){ return dir; }
    TDEActionCollection *actionCollection() { return mActionCollection; };

public slots:
    void slotFilterChange(const TQString&);
    void setDir(KURL);
    void setDir( const TQString& url ) { setDir( KURL( url ) ); };

private slots:
    void cmbPathActivated( const KURL& u );
    void cmbPathReturnPressed( const TQString& u );
    void dirUrlEntered( const KURL& u );
    void dirFinishedLoading();
    void setActiveDocumentDir();
    void viewChanged();
    void btnFilterClick();
    void autoSync();
    void autoSync( KParts::Part * );
	void initialDirChangeHack();
protected:
    void focusInEvent( TQFocusEvent * );
    void showEvent( TQShowEvent * );
    bool eventFilter( TQObject *, TQEvent * );
    KURL activeDocumentUrl();

private:
    class KDevFileSelectorToolBar *toolbar;
    TDEActionCollection *mActionCollection;
    class KBookmarkHandler *bookmarkHandler;
    KURLComboBox *cmbPath;
    KDevDirOperator * dir;
    class TDEAction *acSyncDir;
    KHistoryCombo * filter;
    class TQToolButton *btnFilter;

    FileSelectorPart *m_part;
    KDevMainWindow *mainwin;
    KDevPartController *partController;

    TQString lastFilter;
    int autoSyncEvents; // enabled autosync events
    TQString waitingUrl; // maybe display when we gets visible
    TQString waitingDir;
};

/*  @todo anders
    KFSFilterHelper
    A popup widget presenting a listbox with checkable items
    representing the mime types available in the current directory, and
    providing a name filter based on those.
*/

/*
    Config page for file selector.
    Allows for configuring the toolbar, the history length
    of the path and file filter combos, and how to handle
    user closed session.
*/
class KFSConfigPage : public TQWidget
{
    Q_OBJECT
  
public:
    KFSConfigPage( TQWidget* parent=0, const char *name=0, KDevFileSelector *kfs=0);
    virtual ~KFSConfigPage() {};

public slots:
    virtual void apply();
    virtual void reload();
    virtual void slotChanged();

private:
    void init();

    KDevFileSelector *fileSelector;
    bool bDirty;
    //class TQListBox *lbAvailableActions, *lbUsedActions;
    TDEActionSelector *acSel;
    class TQSpinBox *sbPathHistLength, *sbFilterHistLength;
    class TQCheckBox *cbSyncOpen, *cbSyncActive, *cbSyncShow;
    class TQCheckBox *cbSesLocation, *cbSesFilter;
};


#endif