Suchen in Dateien hinzugefügt
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
#include "EditorTab.h"
|
||||
#include "CodeEditor.h"
|
||||
#include "SearchPanel.h"
|
||||
#include "FileSearchPanel.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
|
||||
EditorPanel::EditorPanel(Settings *settings, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@@ -28,15 +31,20 @@ void EditorPanel::setupUi()
|
||||
m_tabWidget->setDocumentMode(true);
|
||||
|
||||
m_searchPanel = new SearchPanel(this);
|
||||
m_fileSearch = new FileSearchPanel(this);
|
||||
|
||||
m_layout->addWidget(m_tabWidget, 1);
|
||||
m_layout->addWidget(m_searchPanel, 0);
|
||||
m_layout->addWidget(m_fileSearch, 0);
|
||||
|
||||
connect(m_tabWidget, &QTabWidget::tabCloseRequested,
|
||||
this, &EditorPanel::onTabCloseRequested);
|
||||
|
||||
connect(m_tabWidget, &QTabWidget::currentChanged,
|
||||
this, &EditorPanel::onCurrentTabChanged);
|
||||
|
||||
connect(m_fileSearch, &FileSearchPanel::fileLineRequested,
|
||||
this, &EditorPanel::goToLine);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -127,9 +135,88 @@ void EditorPanel::saveAllFiles()
|
||||
|
||||
void EditorPanel::showSearchPanel()
|
||||
{
|
||||
m_fileSearch->hide();
|
||||
m_searchPanel->activate();
|
||||
}
|
||||
|
||||
void EditorPanel::showFileSearchPanel()
|
||||
{
|
||||
m_searchPanel->hide();
|
||||
m_fileSearch->activate();
|
||||
}
|
||||
|
||||
void EditorPanel::setSearchRoot(const QString &path)
|
||||
{
|
||||
m_fileSearch->setSearchRoot(path);
|
||||
}
|
||||
|
||||
void EditorPanel::goToLine(const QString &filePath, int line)
|
||||
{
|
||||
// Datei öffnen falls noch nicht geöffnet
|
||||
openFile(filePath);
|
||||
|
||||
EditorTab *tab = m_openTabs.value(filePath, nullptr);
|
||||
if (!tab)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_tabWidget->setCurrentWidget(tab);
|
||||
|
||||
// Zur gewünschten Zeile springen
|
||||
CodeEditor *editor = tab->editor();
|
||||
QTextBlock block = editor->document()->findBlockByLineNumber(line - 1);
|
||||
if (block.isValid())
|
||||
{
|
||||
QTextCursor cursor(block);
|
||||
cursor.movePosition(QTextCursor::StartOfBlock);
|
||||
editor->setTextCursor(cursor);
|
||||
editor->centerCursor();
|
||||
editor->setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList EditorPanel::openFilePaths() const
|
||||
{
|
||||
QStringList paths;
|
||||
for (int i = 0; i < m_tabWidget->count(); ++i)
|
||||
{
|
||||
EditorTab *tab = qobject_cast<EditorTab *>(m_tabWidget->widget(i));
|
||||
if (tab)
|
||||
{
|
||||
paths.append(tab->filePath());
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
QString EditorPanel::activeFilePath() const
|
||||
{
|
||||
EditorTab *tab = currentTab();
|
||||
return tab ? tab->filePath() : QString();
|
||||
}
|
||||
|
||||
void EditorPanel::restoreSession(const QStringList &files, const QString &activeFile)
|
||||
{
|
||||
for (const QString &path : files)
|
||||
{
|
||||
if (QFile::exists(path))
|
||||
{
|
||||
openFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
// Aktiven Tab wiederherstellen
|
||||
if (!activeFile.isEmpty())
|
||||
{
|
||||
const int idx = findTabForFile(activeFile);
|
||||
if (idx != -1)
|
||||
{
|
||||
m_tabWidget->setCurrentIndex(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorPanel::undo()
|
||||
{
|
||||
if (EditorTab *tab = currentTab())
|
||||
|
||||
Reference in New Issue
Block a user