Changeset View
Changeset View
Standalone View
Standalone View
kate/katequickopen.cpp
Show All 40 Lines | |||||
41 | #include <QSortFilterProxyModel> | 41 | #include <QSortFilterProxyModel> | ||
42 | #include <QCoreApplication> | 42 | #include <QCoreApplication> | ||
43 | #include <QPointer> | 43 | #include <QPointer> | ||
44 | #include <QStandardItemModel> | 44 | #include <QStandardItemModel> | ||
45 | #include <QDesktopWidget> | 45 | #include <QDesktopWidget> | ||
46 | #include <QBoxLayout> | 46 | #include <QBoxLayout> | ||
47 | #include <QLabel> | 47 | #include <QLabel> | ||
48 | #include <QTreeView> | 48 | #include <QTreeView> | ||
49 | #include <QHeaderView> | ||||
49 | 50 | | |||
50 | Q_DECLARE_METATYPE(QPointer<KTextEditor::Document>) | 51 | Q_DECLARE_METATYPE(QPointer<KTextEditor::Document>) | ||
51 | 52 | | |||
52 | KateQuickOpen::KateQuickOpen(QWidget *parent, KateMainWindow *mainWindow) | 53 | KateQuickOpen::KateQuickOpen(QWidget *parent, KateMainWindow *mainWindow) | ||
53 | : QWidget(parent) | 54 | : QWidget(parent) | ||
54 | , m_mainWindow(mainWindow) | 55 | , m_mainWindow(mainWindow) | ||
55 | { | 56 | { | ||
56 | QVBoxLayout *layout = new QVBoxLayout(); | 57 | QVBoxLayout *layout = new QVBoxLayout(); | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 140 | { | |||
140 | QModelIndex index = m_model->index(0, 0); | 141 | QModelIndex index = m_model->index(0, 0); | ||
141 | m_listView->setCurrentIndex(index); | 142 | m_listView->setCurrentIndex(index); | ||
142 | } | 143 | } | ||
143 | 144 | | |||
144 | void KateQuickOpen::update() | 145 | void KateQuickOpen::update() | ||
145 | { | 146 | { | ||
146 | m_base_model->refresh(); | 147 | m_base_model->refresh(); | ||
147 | m_listView->resizeColumnToContents(0); | 148 | m_listView->resizeColumnToContents(0); | ||
149 | | ||||
150 | // If we have a very long file name we restrict the size of the first column | ||||
151 | // to take at most half of the space. Otherwise it would look odd. | ||||
152 | int colw0 = m_listView->header()->sectionSize(0); // file name | ||||
153 | int colw1 = m_listView->header()->sectionSize(1); // file path | ||||
154 | if (colw0 > colw1) { | ||||
155 | m_listView->setColumnWidth(0, (colw0 + colw1) / 2); | ||||
156 | } | ||||
148 | } | 157 | } | ||
149 | 158 | | |||
150 | void KateQuickOpen::slotReturnPressed() | 159 | void KateQuickOpen::slotReturnPressed() | ||
151 | { | 160 | { | ||
152 | const auto index = m_listView->model()->index(m_listView->currentIndex().row(), KateQuickOpenModel::Columns::FilePath); | 161 | const auto index = m_listView->model()->index(m_listView->currentIndex().row(), KateQuickOpenModel::Columns::FilePath); | ||
153 | auto url = QUrl(index.data(Qt::DisplayRole).toString()); | 162 | auto url = QUrl(index.data(Qt::DisplayRole).toString()); | ||
154 | m_mainWindow->wrapper()->openUrl(url); | 163 | m_mainWindow->wrapper()->openUrl(url); | ||
155 | m_mainWindow->slotWindowActivated(); | 164 | m_mainWindow->slotWindowActivated(); | ||
156 | m_inputLine->clear(); | 165 | m_inputLine->clear(); | ||
157 | } | 166 | } |