| 78 | |
| 79 | |
| 80 | ScratchpadView::ScratchpadView(QWidget* parent, Scratchpad* scratchpad) |
| 81 | : QWidget(parent) |
| 82 | , m_scratchpad(scratchpad) |
| 83 | { |
| 84 | setupUi(this); |
| 85 | |
| 86 | setupActions(); |
| 87 | |
| 88 | setWindowTitle(i18nc("@title:window", "Scratchpad")); |
| 89 | setWindowIcon(QIcon::fromTheme(QStringLiteral("note"))); |
| 90 | |
| 91 | auto* const modelProxy = new QSortFilterProxyModel(this); |
| 92 | modelProxy->setSourceModel(m_scratchpad->model()); |
| 93 | modelProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); |
| 94 | modelProxy->setSortCaseSensitivity(Qt::CaseInsensitive); |
| 95 | modelProxy->setSortRole(Qt::DisplayRole); |
| 96 | connect(m_filter, &QLineEdit::textEdited, |
| 97 | modelProxy, &QSortFilterProxyModel::setFilterWildcard); |
| 98 | |
| 99 | scratchView->setModel(modelProxy); |
| 100 | scratchView->setItemDelegate(new FileRenameDelegate(this, m_scratchpad)); |
| 101 | scratchView->setEmptyMessage(i18n("Scratchpad lets you quickly run and experiment with code without a full project, and even store todos. Create a new scratch to start.")); |
| 102 | |
| 103 | connect(scratchView, &QListView::activated, this, &ScratchpadView::scratchActivated); |
| 104 | |
| 105 | connect(m_scratchpad, &Scratchpad::actionFailed, this, [](const QString& messageText) { |
| 106 | // TODO: could be also messagewidget inside toolview? |
| 107 | auto* message = new Sublime::Message(messageText, Sublime::Message::Error); |
| 108 | KDevelop::ICore::self()->uiController()->postMessage(message); |
| 109 | }); |
| 110 | |
| 111 | connect(commandWidget, &QLineEdit::returnPressed, this, &ScratchpadView::runSelectedScratch); |
| 112 | connect(commandWidget, &QLineEdit::returnPressed, this, [this] { |
| 113 | m_scratchpad->setCommand(proxyModel()->mapToSource(currentIndex()), commandWidget->text()); |
| 114 | }); |
| 115 | commandWidget->setToolTip(i18nc("@info:tooltip", "Command to run this scratch. '$f' will expand to the scratch path.")); |
| 116 | commandWidget->setPlaceholderText(commandWidget->toolTip()); |
| 117 | |
| 118 | // change active scratch when changing document |
| 119 | connect(KDevelop::ICore::self()->documentController(), &KDevelop::IDocumentController::documentActivated, this, |
| 120 | [this](const KDevelop::IDocument* document) { |
| 121 | if (document->url().isLocalFile()) { |
| 122 | const auto* model = scratchView->model(); |
| 123 | const auto index = model->match(model->index(0, 0), Scratchpad::FullPathRole, |
| 124 | document->url().toLocalFile()).value({}); |
| 125 | if (index.isValid()) { |
| 126 | scratchView->setCurrentIndex(index); |
| 127 | } |
| 128 | } |
| 129 | }); |
| 130 | |
| 131 | connect(scratchView, &QAbstractItemView::pressed, this, &ScratchpadView::validateItemActions); |
| 132 | |
| 133 | validateItemActions(); |
| 134 | } |
| 135 | |
| 136 | void ScratchpadView::setupActions() |
| 137 | { |
nothing calls this directly
no test coverage detected