Skip to content

Commit

Permalink
Search & Replace Menu -> Fixed double click on results
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Nov 28, 2024
1 parent 9864f7a commit dff78ff
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.0.56

- Search & Replace Menu -> Fixed double click on results

## 0.0.55

- Search & Replace Menu -> Fixed casing in search
Expand Down
26 changes: 13 additions & 13 deletions CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 14.0.2, 2024-11-28T11:05:48. -->
<!-- Written by QtCreator 14.0.2, 2024-11-28T14:01:46. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -102,14 +102,14 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
<value type="QString" key="CMake.Initial.Parameters">-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}</value>
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/Code/Qt/Notepad--/build/Desktop-Debug</value>
Expand Down Expand Up @@ -160,14 +160,14 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
<value type="QString" key="CMake.Initial.Parameters">-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}</value>
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/Code/Qt/Notepad--/build/Desktop-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
Expand Down
60 changes: 50 additions & 10 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ MainWindow::~MainWindow() {
delete ui;
delete fileOperations;
delete textOperations;
delete m_systemFindDialog;
delete m_systemReplaceDialog;
}

Ui::MainWindow* MainWindow::getUi() const {
Expand Down Expand Up @@ -366,7 +368,6 @@ void MainWindow::on_actionReplace_P_revious_triggered()
}

void MainWindow::on_actionFind_System_triggered() {
qDebug() << "on_actionFind_System_triggered called";

if (!m_systemFindDialog) {
qDebug() << "Creating new SystemFindDialog";
Expand All @@ -382,7 +383,7 @@ void MainWindow::on_actionFind_System_triggered() {
});

// Ensure connections are established
setupSearchResultDialogConnections();
setupSearchResultDialogConnectionsForFind();

m_systemFindDialog->show();
} else {
Expand All @@ -392,7 +393,33 @@ void MainWindow::on_actionFind_System_triggered() {
}
}

void MainWindow::setupSearchResultDialogConnections() {
void MainWindow::on_actionReplace_S_ystem_triggered()
{
if (!m_systemReplaceDialog) {
qDebug() << "Creating new SystemReplaceDialog";

m_systemReplaceDialog = new SystemReplaceDialog(this);
m_systemReplaceDialog->setWindowModality(Qt::NonModal);
m_systemReplaceDialog->setAttribute(Qt::WA_DeleteOnClose);

// Reset pointer when dialog is destroyed
connect(m_systemReplaceDialog, &QObject::destroyed, this, [this]() {
qDebug() << "SystemReplaceDialog destroyed. Resetting pointer.";
m_systemReplaceDialog = nullptr;
});

// Ensure connections are established
setupSearchResultDialogConnectionsForReplace();

m_systemReplaceDialog->show();
} else {
qDebug() << "SystemReplaceDialog already exists. Bringing it to the front.";
m_systemReplaceDialog->raise();
m_systemReplaceDialog->activateWindow();
}
}

void MainWindow::setupSearchResultDialogConnectionsForFind() {
QTimer::singleShot(0, this, [this]() {
SystemSearchResultDialog* m_systemSearchResultDialog =
m_systemFindDialog->findChild<SystemSearchResultDialog *>("SystemSearchResultDialog");
Expand All @@ -402,21 +429,34 @@ void MainWindow::setupSearchResultDialogConnections() {

// Re-establish the signal-slot connection
connect(m_systemSearchResultDialog, &SystemSearchResultDialog::openFileAtMatch,
this, &MainWindow::openSearchResult, Qt::UniqueConnection);
this, &MainWindow::openSearchResult);

qDebug() << "Signal-Slot Connection for SystemSearchResultDialog re-established.";
} else {
qDebug() << "SystemSearchResultDialog not found. Retrying...";
QTimer::singleShot(100, this, &MainWindow::setupSearchResultDialogConnections);
QTimer::singleShot(100, this, &MainWindow::setupSearchResultDialogConnectionsForFind);
}
});
}

void MainWindow::on_actionReplace_S_ystem_triggered()
{
SystemReplaceDialog* systemReplaceDialog = new SystemReplaceDialog(this);
systemReplaceDialog->setWindowModality(Qt::NonModal);
systemReplaceDialog->show();
void MainWindow::setupSearchResultDialogConnectionsForReplace() {
QTimer::singleShot(0, this, [this]() {
SystemSearchResultDialog* m_systemSearchResultDialog =
m_systemReplaceDialog->findChild<SystemSearchResultDialog *>("SystemSearchResultDialog");

if (m_systemSearchResultDialog) {
qDebug() << "SystemSearchResultDialog found:" << m_systemSearchResultDialog;

// Re-establish the signal-slot connection
connect(m_systemSearchResultDialog, &SystemSearchResultDialog::openFileAtMatch,
this, &MainWindow::openSearchResult);

qDebug() << "Signal-Slot Connection for SystemSearchResultDialog re-established.";
} else {
qDebug() << "SystemSearchResultDialog not found. Retrying...";
QTimer::singleShot(100, this, &MainWindow::setupSearchResultDialogConnectionsForReplace);
}
});
}

void MainWindow::on_actionGo_to_Line_in_Text_triggered()
Expand Down
5 changes: 4 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mainwindow/textoperations.h"
#include "indentation/indentationmanager.h"
#include "systemfind/systemfinddialog.h"
#include "systemreplace/systemreplacedialog.h"
#include "systemsearchresultdialog.h"

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -156,7 +157,8 @@ private slots:
void applyColorCoding(Document* doc, bool isModified);
void setActiveDocumentEditorInFindDialog();
void setActiveDocumentEditorInReplaceDialog();
void setupSearchResultDialogConnections();
void setupSearchResultDialogConnectionsForFind();
void setupSearchResultDialogConnectionsForReplace();

void setupIndentationMenu();
QAction* action_Custom;
Expand All @@ -166,6 +168,7 @@ private slots:
void loadIndentationSetting(); // Load and apply the saved setting
IndentationManager* indentationManager;
SystemFindDialog* m_systemFindDialog = nullptr;
SystemReplaceDialog* m_systemReplaceDialog = nullptr;
SystemSearchResultDialog* m_systemSearchResultDialog;
FindDialog* findDialog;
ReplaceDialog* replaceDialog;
Expand Down
2 changes: 0 additions & 2 deletions src/systemreplace/systemreplacedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ SystemReplaceDialog::SystemReplaceDialog(QWidget *parent)
SystemReplaceDialog::~SystemReplaceDialog()
{
delete ui;
delete m_replace;
delete m_searchOptions;
delete m_systemSearchResultDialog;
}

Expand Down

0 comments on commit dff78ff

Please sign in to comment.