Skip to content

Commit

Permalink
v0.0.68
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Dec 5, 2024
1 parent cab5816 commit 5a6ce16
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

============

## 0.0.68

- Implemented:
- View Menu -> Open in a New Window

## 0.0.67

- Implemented:
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ set(PROJECT_SOURCES
src/view/movetootherview.h
src/view/movetonewview.cpp
src/view/movetonewview.h
src/view/openinnewwindow.cpp
src/view/openinnewwindow.h
${PROJECT_UI}
)

Expand Down
18 changes: 9 additions & 9 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-12-05T12:06:40. -->
<!-- Written by QtCreator 14.0.2, 2024-12-05T13:56:55. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -104,12 +104,12 @@
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_BUILD_TYPE:STRING=Debug
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_GENERATOR:STRING=Ninja</value>
-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}</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 @@ -162,12 +162,12 @@
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_BUILD_TYPE:STRING=Release
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_GENERATOR:STRING=Ninja</value>
-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}</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
25 changes: 23 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "systemreplace/systemreplacedialog.h"
#include "view/movetootherview.h"
#include "view/movetonewview.h"
#include "view/openinnewwindow.h"
#include "aboutdialog.h"

MainWindow::MainWindow(QWidget* parent)
Expand Down Expand Up @@ -77,8 +78,6 @@ MainWindow::~MainWindow() {
delete m_systemFindDialog;
delete m_systemReplaceDialog;
delete m_mainWindowConfigLoader;
delete m_moveToOtherView;
delete m_moveToNewView;
}

Ui::MainWindow* MainWindow::getUi() const {
Expand Down Expand Up @@ -619,6 +618,7 @@ void MainWindow::on_action_Move_to_Other_View_triggered()
MoveToOtherView* m_moveToOtherView = new MoveToOtherView(ui->documentsTab, this);
m_moveToOtherView->execute();
}
delete m_moveToOtherView;
}

void MainWindow::on_actionMove_to_a_New_View_triggered()
Expand All @@ -634,6 +634,23 @@ void MainWindow::on_actionMove_to_a_New_View_triggered()
MoveToNewView* m_moveToNewView = new MoveToNewView(ui->documentsTab, this);
m_moveToNewView->execute();
}
delete m_moveToNewView;
}

void MainWindow::on_action_Open_in_a_New_Window_triggered()
{
if (!ui->documentsTab) {
qDebug() << "documentsTab is null!";
return;
}

if (m_openInNewWindow) {
m_openInNewWindow->execute();
} else {
OpenInNewWindow* m_openInNewWindow = new OpenInNewWindow(ui->documentsTab, this);
m_openInNewWindow->execute();
}
delete m_openInNewWindow;
}


Expand Down Expand Up @@ -680,6 +697,10 @@ void MainWindow::on_actionMove_to_a_New_View_triggered()










Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "systemsearchresultdialog.h"
#include "view/movetootherview.h"
#include "view/movetonewview.h"
#include "view/openinnewwindow.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
Expand Down Expand Up @@ -174,6 +175,8 @@ private slots:

void on_actionMove_to_a_New_View_triggered();

void on_action_Open_in_a_New_Window_triggered();

private:
Ui::MainWindow* ui;
FileOperations* fileOperations;
Expand Down Expand Up @@ -206,4 +209,5 @@ private slots:
MainWindowConfigLoader* m_mainWindowConfigLoader;
MoveToOtherView* m_moveToOtherView = nullptr;
MoveToNewView* m_moveToNewView = nullptr;
OpenInNewWindow* m_openInNewWindow = nullptr;
};
3 changes: 3 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,9 @@
</property>
</action>
<action name="action_Move_to_Other_View">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Move to Other View</string>
</property>
Expand Down
4 changes: 4 additions & 0 deletions src/view/movetonewview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../codeeditor.h"
#include "movetonewview.h"
#include "../document.h"
#include "../mainwindow.h"

MoveToNewView::MoveToNewView(QTabWidget *tabWidget, QWidget *parent)
: QWidget(parent), m_tabWidget(tabWidget) {}
Expand Down Expand Up @@ -66,6 +67,9 @@ void MoveToNewView::execute() {
qDebug() << "No content to set for the new tab.";
}

MainWindow* mainWindow = qobject_cast<MainWindow*>(parent());
mainWindow->connectSignals(newDocument);

// Insert the new tab
m_tabWidget->insertTab(currentIndex + 1, newDocument, QIcon(), "New View");

Expand Down
72 changes: 72 additions & 0 deletions src/view/openinnewwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <QDebug>
#include "openinnewwindow.h"
#include "../mainwindow.h"
#include "../document.h"
#include "../codeeditor.h"

OpenInNewWindow::OpenInNewWindow(QTabWidget* tabWidget, QWidget* parent)
: QWidget(parent), m_tabWidget(tabWidget) {}

void OpenInNewWindow::execute() {
// Get the index of the current tab
int currentIndex = m_tabWidget->currentIndex();
if (currentIndex < 0) {
qDebug() << "No active tab found in the documentsTab";
return;
}

// Get the content of the current tab
Document* currentDocument = qobject_cast<Document*>(m_tabWidget->widget(currentIndex));
if (!currentDocument) {
qDebug() << "Current tab is not a Document.";
return;
}

CodeEditor* currentEditor = currentDocument->findChild<CodeEditor*>();
QString currentContent;
if (currentEditor) {
currentContent = currentEditor->toPlainText();
} else {
qDebug() << "No CodeEditor found in the current Document.";
return;
}

// Create a new MainWindow
MainWindow* newWindow = new MainWindow();
QTabWidget* newTabWidget = newWindow->findChild<QTabWidget*>("documentsTab");

if (!newTabWidget) {
qDebug() << "No QTabWidget found in the new MainWindow.";
delete newWindow;
return;
}

// Get the default tab created by the new window
Document* untitledDocument = qobject_cast<Document*>(newTabWidget->widget(0));
if (!untitledDocument) {
qDebug() << "No default Document found in the new window.";
delete newWindow;
return;
}

// Set the content of the default tab
CodeEditor* newEditor = untitledDocument->findChild<CodeEditor*>();
if (newEditor) {
newEditor->setPlainText(currentContent);
qDebug() << "Content set for the default tab in the new window.";
} else {
qDebug() << "No CodeEditor found in the default Document to set content.";
}

// Rename the default tab to "New View"
int defaultTabIndex = newTabWidget->indexOf(untitledDocument);
if (defaultTabIndex >= 0) {
newTabWidget->setTabText(defaultTabIndex, "New View");
} else {
qDebug() << "Could not find the default tab in the new window.";
}

// Show the new window
newWindow->show();
qDebug() << "New window created and displayed with the content copied.";
}
17 changes: 17 additions & 0 deletions src/view/openinnewwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <QWidget>
#include <QTabWidget>
#include <QString>

class OpenInNewWindow : public QWidget {
Q_OBJECT

public:
explicit OpenInNewWindow(QTabWidget* tabWidget, QWidget* parent = nullptr);

void execute();

private:
QTabWidget* m_tabWidget;
};

0 comments on commit 5a6ce16

Please sign in to comment.