Skip to content

Commit

Permalink
View -> Show Symbol -> Show Tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Nov 29, 2024
1 parent a14c549 commit f56f292
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 37 deletions.
35 changes: 18 additions & 17 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ name: Build and Release

on:
push:
branches: [main, dev]
branches:
- main
- dev
pull_request:
branches: [main]
branches:
- main

jobs:
build-and-release:
Expand Down Expand Up @@ -53,7 +56,7 @@ jobs:
rsync -a "$BUILD_DIR/" "$TEMP_DIR/"
cd $TEMP_DIR
tar -czvf application.tar.gz ./*
# macOS Section
- name: Install dependencies (macOS)
if: matrix.os == 'macos-latest'
Expand All @@ -75,28 +78,28 @@ jobs:
cd "${{ github.workspace }}/build"
hdiutil create -volname Application -srcfolder . -ov -format UDZO application.dmg
zip application.zip application.dmg
# Windows Section
- name: Install dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install visualstudio2022buildtools -y --install-arguments \
'--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --quiet --norestart'
choco install qt --version=6.5.3 -y
choco install ninja -y
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y
echo "Checking for Qt installation..."
$qtPath = "C:\Qt\6.5.3\msvc2019_64\lib\cmake"
if (!(Test-Path $qtPath)) {
Write-Output "Qt not found. Downloading Qt installer..."
Invoke-WebRequest -Uri "https://download.qt.io/official_releases/online_installers/qt-unified-windows-x64-online.exe" -OutFile "qt-installer.exe"
Start-Process -FilePath "qt-installer.exe" -ArgumentList "--silent", "--platform", "win", "--prefix", "C:\Qt", "--modules", "qt.qt6.653.win64_msvc2019_64" -Wait
}
if (!(Test-Path $qtPath)) {
Write-Output "Qt installation failed."
shell: cmd
- name: Check Visual Studio Build Tools Path
if: matrix.os == 'windows-latest'
run: |
$vcvarsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
if (!(Test-Path $vcvarsPath)) {
Write-Host "Visual Studio Build Tools not found at $vcvarsPath"
exit 1
} else {
Write-Output "Qt installed successfully at $qtPath"
Write-Host "Found Visual Studio Build Tools at $vcvarsPath"
}
shell: pwsh

- name: Configure CMake (Windows)
if: matrix.os == 'windows-latest'
run: |
Expand All @@ -107,14 +110,12 @@ jobs:
-G Ninja ^
-S D:\a\Notepad--\Notepad--
shell: cmd

- name: Build application (Windows)
if: matrix.os == 'windows-latest'
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && ^
cmake --build D:\a\Notepad--\Notepad--\build --config Release
shell: cmd

- name: Package application (Windows)
if: matrix.os == 'windows-latest'
run: |
Expand Down
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.58

- View -> Show Symbol -> Show Tabs

## 0.0.57

- Indentation Implemented
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-28T23:55:12. -->
<!-- Written by QtCreator 14.0.2, 2024-11-29T16:21:54. -->
<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_GENERATOR:STRING=Ninja
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_BUILD_TYPE:STRING=Debug</value>
-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_GENERATOR:STRING=Ninja
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_BUILD_TYPE:STRING=Release</value>
-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
54 changes: 54 additions & 0 deletions src/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ CodeEditor::CodeEditor(QWidget *parent)

m_useTabs = Settings::instance()->loadSetting("Indentation", "Option", "Tabs") == "Tabs";
m_indentationWidth = Settings::instance()->loadSetting("Indentation", "Size", "1").toInt();
m_showTabs = Settings::instance()->loadSetting("View", "ShowTabs", "false") == "true";
m_tabWidth = Settings::instance()->loadSetting("View", "TabWidth", "4").toInt();
}

int CodeEditor::lineNumberAreaWidth() {
Expand Down Expand Up @@ -254,3 +256,55 @@ void CodeEditor::keyPressEvent(QKeyEvent *event) {
QPlainTextEdit::keyPressEvent(event);
}

void CodeEditor::setShowTabs(bool enabled) {
if (m_showTabs != enabled) {
m_showTabs = enabled;
viewport()->update(); // Redraw the editor to show or hide tab symbols
}
}

bool CodeEditor::showTabs() const {
return m_showTabs;
}

void CodeEditor::setTabWidth(int width = 4) {
m_tabWidth = width;
viewport()->update(); // Trigger a repaint to apply the new width
}

void CodeEditor::paintEvent(QPaintEvent *event) {
QPlainTextEdit::paintEvent(event);

if (!m_showTabs) return;

QPainter painter(viewport());
painter.setPen(Qt::gray);

QTextBlock block = document()->firstBlock();
QFontMetrics metrics(font());

while (block.isValid()) {
QString text = block.text();
int blockStart = block.position();
QTextCursor blockCursor(block);

// Iterate over characters in the block
for (int i = 0; i < text.length(); ++i) {
if (text[i] == '\t') {
// Move the cursor to the tab character
blockCursor.setPosition(blockStart + i);

// Get the rectangle of the cursor position
QRect rect = cursorRect(blockCursor);

// Adjust the position for the tab symbol
//QPoint position(rect.left(), rect.top() + metrics.ascent());
QPoint position(rect.left() + metrics.ascent(), rect.top() + metrics.ascent());

// Draw the tab symbol
painter.drawText(position, "");
}
}
block = block.next();
}
}
6 changes: 6 additions & 0 deletions src/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ class CodeEditor : public QPlainTextEdit {
void highlightAllOccurrences(const QString& keyword);
void goToLineInText(int lineNumber);
void gotoLineInEditor(int lineNumber);
void setShowTabs(bool enabled);
bool showTabs() const;
void setTabWidth(int width);

protected:
void resizeEvent(QResizeEvent *event) override;
virtual void keyPressEvent(QKeyEvent *event) override;
void paintEvent(QPaintEvent *event) override;

signals:
void textChanged(); // FIXME: Remove this line.
Expand All @@ -41,6 +45,8 @@ private slots:
QTabWidget* m_documentsTab;
bool m_useTabs;
int m_indentationWidth;
bool m_showTabs = false;
int m_tabWidth;
};

class LineNumberArea : public QWidget {
Expand Down
21 changes: 12 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,24 @@ void MainWindow::on_action_Find_triggered() {
}
}

/* View Menu */

void MainWindow::on_action_Show_Tabs_triggered(bool checked)
{
qDebug() << "Show Tabs is: " << checked;
Settings::instance()->saveSetting("View", "ShowTabs", checked ? "true" : "false");

for (int i = 0; i < ui->documentsTab->count(); ++i) {
Document *doc = qobject_cast<Document *>(ui->documentsTab->widget(i));
if (doc) {
doc->editor()->setShowTabs(checked);
}
}
}




/* View Menu */





Expand All @@ -513,9 +522,6 @@ void MainWindow::on_action_Find_triggered() {
/* Helper Functions */





// FIXME: Wrong line selected
void MainWindow::openSearchResult(const QString &filePath, int lineNumber) {
qInfo() << "openSearchResult called. File Path:" << filePath << ", Line Number:" << lineNumber;
Expand Down Expand Up @@ -645,6 +651,3 @@ void MainWindow::setActiveDocumentEditorInReplaceDialog() {






2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ private slots:

void on_actionGo_to_Line_in_Editor_triggered();

void on_action_Show_Tabs_triggered(bool checked);

private:
Ui::MainWindow* ui;
FileOperations* fileOperations;
Expand Down

0 comments on commit f56f292

Please sign in to comment.