Skip to content

Commit

Permalink
save a copy as
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Oct 16, 2024
1 parent e95decc commit ec08a05
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
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.1, 2024-10-16T00:47:16. -->
<!-- Written by QtCreator 14.0.1, 2024-10-16T16:35:17. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -103,13 +103,13 @@
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}</value>
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake</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 @@ -161,13 +161,13 @@
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}</value>
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake</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
27 changes: 27 additions & 0 deletions src/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Document::Document(const QString &filePath, QWidget *parent)
m_statusLabel = new QLabel(this);
m_progressBar = new QProgressBar(this);
m_progressBar->setRange(0, 100);
m_progressBar->setVisible(false);
layout->addWidget(m_statusLabel);
layout->addWidget(m_progressBar);

Expand Down Expand Up @@ -261,6 +262,32 @@ void Document::saveFileAs(const QString &newFilePath) {
saveFile();
}

void Document::saveAcopyAs() {
QString filePath = QFileDialog::getSaveFileName(this, tr("Save a Copy As"), QString(),
tr("Text Files (*.txt);;All Files (*)"));

if (filePath.isEmpty())
return;

if (!m_fileLoaderWorker) {
qDebug() << "No file loader worker initialized. Cannot save file.";
return;
}

QString currentText = editor->toPlainText();

// Reset progress bar and show it
m_progressBar->setValue(0);
m_progressBar->setVisible(true);
m_statusLabel->setText("Saving Copy of File...");

// Start the save operation in the worker thread
m_isSaving = true;
m_fileLoaderWorker->saveFile(filePath, currentText);
m_isModified = false;
qDebug() << "Save operation started for file:" << filePath;
}

bool Document::closeDocument() {
qDebug() << "Checking document close: isLoading=" << m_isLoading << ", isSaving=" << m_isSaving;

Expand Down
1 change: 1 addition & 0 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Document : public QWidget {
void onWorkerTaskCompleted();
bool checkForUnsavedChanges();
void saveFileAs(const QString &newFilePath);
void saveAcopyAs();
bool closeDocument();
void goToLineNumberInText(QWidget* parent);
void goToLineNumberInEditor();
Expand Down
1 change: 1 addition & 0 deletions src/fileloaderworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void FileLoaderWorker::loadFile(const QString &filePath) {
qDebug() << "Read chunk of size: " << buffer.size() << " Total bytesRead: " << bytesRead;

emit contentLoaded(buffer);
QCoreApplication::processEvents();

// Update progress bar
int progress = static_cast<int>((bytesRead * 100) / m_fileSize);
Expand Down
13 changes: 6 additions & 7 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
#include "ui_mainwindow.h"
#include "document.h"
#include <QDebug>
#include <QFileDialog>
#include <QFile>
#include <QFileInfo>
#include <QFileDialog>
#include <QMessageBox>
#include <QProgressBar>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include "mainwindow.h"
#include <QLabel>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QProgressBar>
#include <QTimer>
#include <QActionGroup>
#include <QMimeDatabase>
Expand Down Expand Up @@ -385,5 +381,8 @@ void MainWindow::on_actionOpen_Folder_triggered() {
}
}


void MainWindow::on_actionSa_ve_a_copy_as_triggered() {
Document *doc = qobject_cast<Document *>(ui->documentsTab->currentWidget());
doc->saveAcopyAs();
}

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

void on_actionOpen_Folder_triggered();

void on_actionSa_ve_a_copy_as_triggered();

private:
Ui::MainWindow *ui;
void initialize();
Expand Down

0 comments on commit ec08a05

Please sign in to comment.