From 5a6ce16792e88f58a70ad89d319a52a7bc7c3423 Mon Sep 17 00:00:00 2001 From: Remisa Yousefvand Date: Thu, 5 Dec 2024 14:01:13 +0330 Subject: [PATCH] v0.0.68 --- CHANGELOG.md | 5 +++ CMakeLists.txt | 2 + CMakeLists.txt.user | 18 ++++----- src/mainwindow.cpp | 25 ++++++++++++- src/mainwindow.h | 4 ++ src/mainwindow.ui | 3 ++ src/view/movetonewview.cpp | 4 ++ src/view/openinnewwindow.cpp | 72 ++++++++++++++++++++++++++++++++++++ src/view/openinnewwindow.h | 17 +++++++++ 9 files changed, 139 insertions(+), 11 deletions(-) create mode 100644 src/view/openinnewwindow.cpp create mode 100644 src/view/openinnewwindow.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b70c36..9f1b6f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ============ +## 0.0.68 + +- Implemented: +- View Menu -> Open in a New Window + ## 0.0.67 - Implemented: diff --git a/CMakeLists.txt b/CMakeLists.txt index f00fc2b..e7399ca 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} ) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 11b4903..61ce0ef 100755 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -104,12 +104,12 @@ -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 +-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} /data/Code/Qt/Notepad-- 0 /data/Code/Qt/Notepad--/build/Desktop-Debug @@ -162,12 +162,12 @@ -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 +-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} /data/Code/Qt/Notepad-- /data/Code/Qt/Notepad--/build/Desktop-Release diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d10b862..c49057f 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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) @@ -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 { @@ -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() @@ -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; } @@ -680,6 +697,10 @@ void MainWindow::on_actionMove_to_a_New_View_triggered() + + + + diff --git a/src/mainwindow.h b/src/mainwindow.h index d3551d0..35a97ca 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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; } @@ -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; @@ -206,4 +209,5 @@ private slots: MainWindowConfigLoader* m_mainWindowConfigLoader; MoveToOtherView* m_moveToOtherView = nullptr; MoveToNewView* m_moveToNewView = nullptr; + OpenInNewWindow* m_openInNewWindow = nullptr; }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 0ea0888..d7c4bc8 100755 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1944,6 +1944,9 @@ + + true + &Move to Other View diff --git a/src/view/movetonewview.cpp b/src/view/movetonewview.cpp index 308f147..42f907e 100644 --- a/src/view/movetonewview.cpp +++ b/src/view/movetonewview.cpp @@ -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) {} @@ -66,6 +67,9 @@ void MoveToNewView::execute() { qDebug() << "No content to set for the new tab."; } + MainWindow* mainWindow = qobject_cast(parent()); + mainWindow->connectSignals(newDocument); + // Insert the new tab m_tabWidget->insertTab(currentIndex + 1, newDocument, QIcon(), "New View"); diff --git a/src/view/openinnewwindow.cpp b/src/view/openinnewwindow.cpp new file mode 100644 index 0000000..3b74c8d --- /dev/null +++ b/src/view/openinnewwindow.cpp @@ -0,0 +1,72 @@ +#include +#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(m_tabWidget->widget(currentIndex)); + if (!currentDocument) { + qDebug() << "Current tab is not a Document."; + return; + } + + CodeEditor* currentEditor = currentDocument->findChild(); + 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("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(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(); + 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."; +} diff --git a/src/view/openinnewwindow.h b/src/view/openinnewwindow.h new file mode 100644 index 0000000..0e8e042 --- /dev/null +++ b/src/view/openinnewwindow.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include + +class OpenInNewWindow : public QWidget { + Q_OBJECT + +public: + explicit OpenInNewWindow(QTabWidget* tabWidget, QWidget* parent = nullptr); + + void execute(); + +private: + QTabWidget* m_tabWidget; +};