Skip to content

New file feature #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

franciscomartinez45
Copy link
Contributor

A new file can only be created if the text editor is not empty and the file has been saved, if any changes to an existing file are made and addressed accordingly, or if the text editor is empty and there is no saved file.

Copy link
Member

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @franciscomartinez45

Thank you for your time and contribution! I have a couple of requests for changes (please see the comments I’ve provided) as well as a logic question regarding the test files.

Once these changes are addressed, the PR should be nearly ready to merge. I do have one additional request before merging: could you break down the newFile function slightly to improve modularity? This will improve maintainability and reusability, especially since I’ll need the logic that detects whether a file has been edited to be used in other functions as well.

Thank you again for your hard work on this!

Comment on lines 92 to 101
else
{
MainWindow *newWindow = new MainWindow();
newWindow->setWindowTitle("Code Astra ~ untitled");
newWindow->show();
}

// // New window will be created with the untitled name

// newWindow->~MainWindow();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will again create a new file in a new window, and not in the current one.
You should not create a new window object as an object is already created at the initialization of the software (the m_mainWindow, the m_ is how you know it is available as a member here).
Plus, you also want to reset the editor (with member editor object m_editor).

Finally, you also want this to be outside of the condition (outside the if/else statement). Otherwise, it will not be applied properly once you fix what I said above.

Here is a possible implementation:

    // Clear the editor and reset the state for a new file
    setCurrentFileName("");
    m_editor->clear();
    if (m_mainWindow)
    {
        m_mainWindow->setWindowTitle("CodeAstra ~ untitled");
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the fixes so that the editor is only reset. The reason I have created an else statement for cleaning the editor is that if the user exits during the save process, then the user still has the current state of the editor intact. The editor will only be reset to an untitled file if there are no changes to the current saved file or if the file has not been saved. Please let me know if you would like me to keep my logic in there for detecting changes to the current file.

Copy link
Member

@chrisdedman chrisdedman Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see @franciscomartinez45 . Yeah. The problem is that when you save the changes, it does not create a new file (I tested it right now). You may want to wrap this inside an if statement instead of an else statement, such as:

    if( !m_currentFileName.isEmpty())
    {
        setCurrentFileName("");
        m_editor->clear();
        m_mainWindow->setWindowTitle("Code Astra ~ untitled");
    }

Here, if the user is changing their mind, the code will check if the file name is empty; if not empty, it will go through the process and clear the editor. If it is empty, that would mean that the file has not been saved, so it won't clear it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for changing QCOMPARE_EQ to QCOMPARE_H?

The change will introduce a serious issue. From my research, QCOMPARE_H is not a valid test assertion macro and has no effect in testing. The original implementation with QCOMPARE_EQ is correct as it checks the equality of the menu bar’s action count and provides meaningful test output in case of failure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as the other test file. I am not sure to understand your logic in changing QCOMPARE_EQ to QCOMPARE_H. I will wait for your answer, but I would prefer to change back to the original implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the feed back Chris! I would like to note that I am working on WSL. When I was compiling the code I kept getting issue with the QCOMPARE_EQ function. Instead, it advised me to use QCOMPARE_H. No real logic behind using it besides the fact it makes my code work on my machine. I would also like to not that QCOMPARE() also works. Not sure if it is a machine independent issue.
Screenshot 2025-04-23 154920

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @franciscomartinez45 . Ok, so I did some research, and your Qt6 version on WSL is probably not updated. QCOMPARE_EQ() is a better and safer feature for testing than QCOMPARE() and was introduced in Qt 6.6.0 (see here https://doc.qt.io/qt-6/qtest.html#QCOMPARE_EQ).

Could you check your Qt version by adding a debugging line (maybe at the start of the program in the main function) and show me what you get?

qDebug() << QT_VERSION_STR;

If your version is greater than 6.6.0, then it would be best to update with QCOMPARE() for now, as QCOMPARE_H() isn't intended for this purpose

Copy link
Member

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update. Other than the little update for this feature and the problem with the Test, everything looks good. Once you update this, I can merge it.

Comment on lines 89 to 93
else {
setCurrentFileName("");
m_editor->clear();
m_mainWindow->setWindowTitle("Code Astra ~ untitled");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the comment in the conversation, this would be better in that case (please, see the latest comment I left after you updated from my previous review):

    if( !m_currentFileName.isEmpty())
    {
        setCurrentFileName("");
        m_editor->clear();
        m_mainWindow->setWindowTitle("Code Astra ~ untitled");
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment left on the previous conversation on this file. Thanks

@chrisdedman
Copy link
Member

Hi @franciscomartinez45 . First of all, I want to thank you for your contribution. I also want to let you know that over the weekend, I will be adding the 2 changes I left in the PR comment and merging your contribution. The comments are not that big, but if I do that before you have time to do it, please take a quick look at what I said. Does not add much value in learning, but good information :). Once again, thank you for taking the time to contribute, and I hope to see a new PR from you in the future :).

The problem was that when you save the changes, it does not create a new file because of the else condition. The if condition will fix this.
QCOMPARE_H does not do what it is supposed to do here.
Copy link
Member

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@chrisdedman chrisdedman merged commit 466cd79 into sandbox-science:main May 4, 2025
5 checks passed
@chrisdedman chrisdedman linked an issue May 4, 2025 that may be closed by this pull request
@chrisdedman chrisdedman mentioned this pull request May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create New File
2 participants