File indexing completed on 2024-05-05 05:51:24

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 2001 Christoph Cullmann <cullmann@kde.org>
0003    SPDX-FileCopyrightText: 2001 Joseph Wenninger <jowenn@kde.org>
0004    SPDX-FileCopyrightText: 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
0005    SPDX-FileCopyrightText: 2007 Mirko Stocker <me@misto.ch>
0006    SPDX-FileCopyrightText: 2009 Dominik Haumann <dhaumann kde org>
0007 
0008    SPDX-License-Identifier: LGPL-2.0-only
0009 */
0010 
0011 #pragma once
0012 
0013 #include <ktexteditor/mainwindow.h>
0014 
0015 #include <KDirOperator>
0016 #include <KFile>
0017 #include <kio_version.h>
0018 
0019 #include <QMenu>
0020 #include <QUrl>
0021 #include <QWidget>
0022 
0023 #include "katefilebrowseropenwithmenu.h"
0024 
0025 class KateBookmarkHandler;
0026 class KActionCollection;
0027 class KDirOperator;
0028 class KFileItem;
0029 class KHistoryComboBox;
0030 class KToolBar;
0031 class KConfigGroup;
0032 class KUrlNavigator;
0033 
0034 class QAbstractItemView;
0035 class QAction;
0036 
0037 /*
0038     The kate file selector presents a directory view, in which the default action is
0039     to open the activated file.
0040     Additionally, a toolbar for managing the kdiroperator widget + sync that to
0041     the directory of the current file is available, as well as a filter widget
0042     allowing to filter the displayed files using a name filter.
0043 */
0044 
0045 class KateFileBrowser : public QWidget
0046 {
0047     Q_OBJECT
0048 
0049 public:
0050     explicit KateFileBrowser(KTextEditor::MainWindow *mainWindow = nullptr, QWidget *parent = nullptr);
0051     ~KateFileBrowser() override;
0052 
0053     void readSessionConfig(const KConfigGroup &config);
0054     void writeSessionConfig(KConfigGroup &config);
0055 
0056     void setupToolbar();
0057     void setView(KFile::FileView);
0058     KDirOperator *dirOperator()
0059     {
0060         return m_dirOperator;
0061     }
0062 
0063     KActionCollection *actionCollection()
0064     {
0065         return m_actionCollection;
0066     }
0067 
0068     static KDirOperator::Action actionFromName(const QString &name);
0069 
0070 public Q_SLOTS:
0071     void slotFilterChange(const QString &);
0072     void setDir(const QUrl &);
0073     void setDir(const QString &url)
0074     {
0075         setDir(QUrl(url));
0076     }
0077     static void selectorViewChanged(QAbstractItemView *);
0078 
0079 private Q_SLOTS:
0080     void fileSelected(const KFileItem & /*file*/);
0081     void updateDirOperator(const QUrl &u);
0082     void updateUrlNavigator(const QUrl &u);
0083     void setActiveDocumentDir();
0084     void autoSyncFolder();
0085     void contextMenuAboutToShow(const KFileItem &item, QMenu *menu);
0086     void fixOpenWithMenu();
0087     void openWithMenuAction(QAction *a);
0088 
0089 protected:
0090     QUrl activeDocumentUrl();
0091     void openSelectedFiles();
0092     void setupActions();
0093 
0094 public:
0095     KTextEditor::MainWindow *mainWindow()
0096     {
0097         return m_mainWindow;
0098     }
0099 
0100 private:
0101     KToolBar *m_toolbar;
0102     KActionCollection *m_actionCollection;
0103     KateBookmarkHandler *m_bookmarkHandler = nullptr;
0104     KUrlNavigator *m_urlNavigator;
0105     KDirOperator *m_dirOperator;
0106     KHistoryComboBox *m_filter;
0107     QAction *m_autoSyncFolder = nullptr;
0108     QAction *m_highlightCurrentFile = nullptr;
0109     KateFileBrowserOpenWithMenu *m_openWithMenu = nullptr;
0110 
0111     KTextEditor::MainWindow *m_mainWindow;
0112 };