Skip to content

Commit

Permalink
v0.0.48
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Nov 17, 2024
1 parent a1e8ace commit e524a5c
Show file tree
Hide file tree
Showing 36 changed files with 1,646 additions and 229 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,23 @@ jobs:
path: ${{ runner.temp }}/qt-source
key: qt-source-6.5.3

- name: Download and Extract Qt Source (Windows)
- name: Download Qt Source (Windows)
if: matrix.os == 'windows-latest'
shell: powershell
run: |
$qtSourceDir = "$env:TEMP\qt-source"
$qtZip = "$qtSourceDir\qt-everywhere-src-6.5.3.zip"
if (-Not (Test-Path "$qtSourceDir\qt-everywhere-src-6.5.3\qtbase\configure.bat")) {
if (-Not (Test-Path $qtZip)) {
Write-Host "Downloading Qt Source"
New-Item -ItemType Directory -Path $qtSourceDir -Force
Invoke-WebRequest -Uri "https://download.qt.io/official_releases/qt/6.5/6.5.3/single/qt-everywhere-src-6.5.3.zip" -OutFile $qtZip
Expand-Archive -Path $qtZip -DestinationPath $qtSourceDir
}
if (-Not (Test-Path "$qtSourceDir\qt-everywhere-src-6.5.3\qtbase\configure.bat")) {
Write-Host "Error: configure.bat is missing in $qtSourceDir after extraction."
dir "$qtSourceDir"
throw "configure.bat not found. Verify extraction process."
}
- name: Build and Install Qt (Windows)
if: matrix.os == 'windows-latest'
shell: cmd
run: |
REM Locate Visual Studio Build Tools
FOR /F "tokens=*" %%i IN ('"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" ^
-latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') DO SET VS_PATH=%%i
IF NOT DEFINED VS_PATH (
Expand All @@ -93,15 +87,11 @@ jobs:
SET "VS_VARS_CMD=%VS_PATH%\VC\Auxiliary\Build\vcvars64.bat"
CALL "%VS_VARS_CMD%" || exit /b 1
REM Configure and build Qt
SET QT_SOURCE=%TEMP%\qt-source\qt-everywhere-src-6.5.3
IF NOT EXIST "%QT_SOURCE%\qtbase\configure.bat" (
echo "configure.bat not found in %QT_SOURCE%\qtbase" && exit /b 1
)
cd "%QT_SOURCE%\qtbase"
call configure.bat -top-level -prefix C:\Qt -release -opensource -confirm-license -nomake examples -nomake tests -platform win32-msvc -cmake-generator Ninja
cmake --build "%QT_SOURCE%\qtbase" --parallel
cmake --install "%QT_SOURCE%\qtbase"
# Configure and build Qt with Ninja
cd %TEMP%\qt-source\qt-everywhere-src-6.5.3\qtbase
configure.bat -top-level -prefix C:\Qt -release -opensource -confirm-license -nomake examples -nomake tests -platform win32-msvc -cmake-generator Ninja
cmake --build . --parallel
cmake --install .
- name: Set Qt Environment Variables (Windows)
if: matrix.os == 'windows-latest'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 0.0.48

- Implemented:
- Search Menu -> Find System (partially)

## 0.0.47

- Implemented:
Expand Down
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(PROJECT_UI
src/indentation/indentationdialog.ui
src/systemfind/systemfinddialog.ui
src/systemreplace/systemreplacedialog.ui
src/systemsearchresultdialog.ui
)

set(PROJECT_SOURCES
Expand Down Expand Up @@ -76,19 +77,29 @@ set(PROJECT_SOURCES
src/find/finddialog.h
src/replace/replacedialog.cpp
src/replace/replacedialog.h
src/systemfind/systemfinddialog.cpp
src/systemfind/systemfinddialog.h
src/systemreplace/systemreplacedialog.cpp
src/systemreplace/systemreplacedialog.h
src/replace/replace.cpp
src/replace/replace.h
src/find/find.cpp
src/find/find.h
src/search/search.cpp
src/search/search.h


src/search/searchoptions.h
src/systemfind/systemfinddialog.cpp
src/systemfind/systemfinddialog.h
src/systemreplace/systemreplacedialog.cpp
src/systemreplace/systemreplacedialog.h
src/systemfind/systemfind.cpp
src/systemfind/systemfind.h
src/systemreplace/systemreplace.cpp
src/systemreplace/systemreplace.h
src/systemsearchresultdialog.cpp
src/systemsearchresultdialog.h
src/search/filesearchworker.cpp
src/search/filesearchworker.h
src/systemfind/richtextdelegate.cpp
src/systemfind/richtextdelegate.h
src/systemtextdelegate.cpp
src/systemtextdelegate.h
${PROJECT_UI}
)

Expand Down
22 changes: 11 additions & 11 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-10T04:16:59. -->
<!-- Written by QtCreator 14.0.2, 2024-11-18T02:54:05. -->
<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}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_BUILD_TYPE:STRING=Debug</value>
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}</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}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_BUILD_TYPE:STRING=Release</value>
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}</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
78 changes: 76 additions & 2 deletions src/codeeditor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "codeeditor.h"
#include <QPainter>
#include <QTextBlock>
#include <QScrollBar>
#include "helpers.h"

CodeEditor::CodeEditor(QWidget *parent)
Expand Down Expand Up @@ -153,10 +154,83 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) {
}

void CodeEditor::applyIndentation(bool useTabs, int indentationWidth) {
// TODO: Implement indentation
qDebug() << "Indentation. Use Tabs: " << useTabs << ". Indentation width: " << indentationWidth;
QTextCursor cursor = textCursor();
QString indentation = useTabs ? "\t" : QString(indentationWidth, ' ');
cursor.insertText(indentation);
}

QTabWidget* CodeEditor::DocumentsTab() {
return m_documentsTab;
}

void CodeEditor::highlightAllOccurrences(const QString& keyword) {
QList<QTextEdit::ExtraSelection> extraSelections;

QTextCursor cursor(document());
QTextCursor highlightCursor(document());
QTextCharFormat highlightFormat;
highlightFormat.setBackground(Qt::cyan);

while (!cursor.isNull() && !cursor.atEnd()) {
cursor = document()->find(keyword, cursor);
if (!cursor.isNull()) {
QTextEdit::ExtraSelection selection;
selection.cursor = cursor;
selection.format = highlightFormat;
extraSelections.append(selection);
}
}

setExtraSelections(extraSelections);
}

void CodeEditor::goToLine(int lineNumber) {
if (lineNumber < 1 || lineNumber > document()->blockCount()) {
qWarning() << "Line number" << lineNumber << "is out of range.";
return;
}

QTextCursor cursor(document()->findBlockByNumber(lineNumber - 1));
setTextCursor(cursor);
centerCursor(); // Ensure the cursor is centered in the view

qDebug() << "Moved to line:" << lineNumber;

// Log current cursor position
qDebug() << "Cursor position after move:" << textCursor().position();
}

/*
void CodeEditor::goToLine(int lineNumber) {
// Validate line number range
if (lineNumber < 1 || lineNumber > document()->blockCount()) {
qWarning() << "Line number" << lineNumber << "is out of range. Valid range: 1 to" << document()->blockCount();
return;
}
// Find the text block corresponding to the line number
QTextBlock block = document()->findBlockByNumber(lineNumber - 1);
if (!block.isValid()) {
qWarning() << "Invalid block for line number:" << lineNumber;
return;
}
// Set the text cursor to the block
QTextCursor cursor(block);
setTextCursor(cursor);
// Scroll to the block manually
QRectF blockRect = blockBoundingGeometry(block).translated(contentOffset());
verticalScrollBar()->setValue(static_cast<int>(blockRect.top()));
// Ensure the editor has focus (optional)
if (!hasFocus()) {
setFocus();
}
qDebug() << "Moved to line:" << lineNumber;
qDebug() << "Block position:" << block.position()
<< "Block geometry:" << blockRect
<< "Viewport height:" << viewport()->height();
}
*/
4 changes: 3 additions & 1 deletion src/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class CodeEditor : public QPlainTextEdit {
void highlightCurrentLine();
void applyIndentation(bool useTabs, int indentationWidth);
QTabWidget* DocumentsTab();
void highlightAllOccurrences(const QString& keyword);
void goToLine(int lineNumber);

protected:
void resizeEvent(QResizeEvent *event) override;

signals:
void textChanged();
void textChanged(); // FIXME: Remove this line.

private slots:
void updateLineNumberAreaWidth(int newBlockCount);
Expand Down
12 changes: 3 additions & 9 deletions src/find/finddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QTextEdit>
#include "find.h"
#include "../codeeditor.h"
#include "../search/searchoptions.h"

namespace Ui {
class FindDialog;
Expand All @@ -17,13 +18,6 @@ class FindDialog : public QDialog
explicit FindDialog(QWidget *parent = nullptr);
~FindDialog();

enum FindMode {
PlainText,
RegularExpression,
SpecialCharacters
};

void performFind();
static void showDialog(QWidget *parent = nullptr);
QString getFindText() const;
bool findPlainTextSelected() const;
Expand All @@ -37,7 +31,7 @@ class FindDialog : public QDialog
SearchOptions* getSearchOptions();

signals:
void findRequested(const QString& findText, bool matchCase, bool matchWholeWord, FindDialog::FindMode mode);
void findRequested(const QString& findText, bool matchCase, bool matchWholeWord, FindMethod mode);

private slots:

Expand Down Expand Up @@ -69,7 +63,7 @@ private slots:

private:
Ui::FindDialog *ui;
FindMode selectedFindMode() const;
FindMethod selectedFindMethod() const;
SearchOptions* m_searchOptions;
Find* m_find;
CodeEditor* m_editor = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/find/finddialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<rect>
<x>16</x>
<y>150</y>
<width>91</width>
<width>101</width>
<height>23</height>
</rect>
</property>
Expand Down
67 changes: 67 additions & 0 deletions src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "helpers.h"
#include "document.h"
#include "codeeditor.h"
#include "search/searchoptions.h"

bool Helpers::isUntitledDocument(const QString& title) {
// Static QRegularExpression to avoid repeated creation
Expand Down Expand Up @@ -176,7 +177,73 @@ bool Helpers::isValidRegularExpression(const QString& pattern) {
return regex.isValid();
}

int Helpers::countKeywordsInLine(const QString& line, const SearchOptions& options) {
QString keyword = options.keyword;
if (keyword.isEmpty()) {
return 0;
}

QString pattern = options.matchWholeWord
? QString("\\b%1\\b").arg(QRegularExpression::escape(keyword))
: QRegularExpression::escape(keyword);

QRegularExpression regex(pattern, options.matchCase
? QRegularExpression::NoPatternOption
: QRegularExpression::CaseInsensitiveOption);

int count = 0;
QRegularExpressionMatchIterator it = regex.globalMatch(line);
while (it.hasNext()) {
it.next();
count++;
}

return count;
}

// FIXME: If user search for "hello" and a match found as "Hello" in retun string "hello" would return.
QString Helpers::highlightKeywords(const QString& line, const SearchOptions& options) {
QString keyword = options.keyword;
if (keyword.isEmpty()) {
return line; // No keyword to highlight
}

// Build the regex pattern
QString pattern = options.matchWholeWord
? QString("\\b%1\\b").arg(QRegularExpression::escape(keyword)) // Whole word matching
: QRegularExpression::escape(keyword); // Partial match

// Configure case sensitivity
QRegularExpression regex(pattern, options.matchCase
? QRegularExpression::NoPatternOption
: QRegularExpression::CaseInsensitiveOption);

// Process the line and replace matches with highlighted versions
QString highlightedLine;
int lastIndex = 0;

QRegularExpressionMatchIterator it = regex.globalMatch(line);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();

// Append the part before the match
highlightedLine.append(line.mid(lastIndex, match.capturedStart() - lastIndex));

// Append the highlighted match
highlightedLine.append("<span style='background-color: yellow; color: black;'>");
highlightedLine.append(match.captured());
highlightedLine.append("</span>");

// Update the last index to the end of the match
lastIndex = match.capturedEnd();
}

// Append the remaining part of the line
highlightedLine.append(line.mid(lastIndex));

// Ensure no `<highlight>` tags exist
highlightedLine.replace("<highlight>", "");
highlightedLine.replace("</highlight>", "");

return highlightedLine;
}
Loading

0 comments on commit e524a5c

Please sign in to comment.