Skip to content
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

Refactor: use a single enum to classify all TConsole instances #2138

Conversation

SlySven
Copy link
Member

@SlySven SlySven commented Dec 17, 2018

By replacing the following somewhat adhoc collection of flags it is easier to refactor code that is dependent on the particular type of TConsole:

  • (bool) TConsole::mIsDebugConsole
  • (bool) TConsole::mIsSubConsole
  • (bool) TConsole::mUserConsole - flag for a subConsole/Buffer/UserWindow

Also removed the unused:
(bool) TConsole::mWindowIsHidden

This has revealed that there are numerous cases where the Buffer type of TConsole is including code that was likely only intended for the main one for each profile...!

Signed-off-by: Stephen Lyons slysven@virginmedia.com

By replacing the following somewhat adhoc collection of flags it is easier
to refactor code that is dependent on the particular type of `TConsole`:
* (bool) TConsole::mIsDebugConsole
* (bool) TConsole::mIsSubConsole
* (bool) TConsole::mUserConsole - flag for a subConsole/Buffer/UserWindow

Also removed the unused:
* (bool) TConsole::mWindowIsHidden

This has revealed that there are numerous cases where the `Buffer` type of
`TConsole` is including code that was likely only intended for the main
one for each profile...!

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@SlySven SlySven requested a review from a team December 17, 2018 00:36
@SlySven SlySven requested a review from a team as a code owner December 17, 2018 00:36
@SlySven
Copy link
Member Author

SlySven commented Dec 17, 2018

Suggestions for changes are welcome - as I say: some of the conditional code parts now look wrong...

@@ -122,21 +120,27 @@ TConsole::TConsole(Host* pH, bool isDebugConsole, QWidget* parent)
mStandardFormat.flags &= ~(TCHAR_STRIKEOUT);
} else {
setWindowTitle(tr("Non Debug Console"));
if (parent) {
mIsSubConsole = true;
if (mType & (ErrorConsole|SubConsole|UserWindow)) {
Copy link
Member Author

@SlySven SlySven Dec 17, 2018

Choose a reason for hiding this comment

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

Not sure that the ErrorConsole type should be here as I do not think it should be added to the "main" console's mSubConsoleList though give that that is not used anywhere it is probably due for removal anyhow.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it matters then - we can leave it be

mpHost->mpConsole->mSubConsoleList.append(this);
mMainFrameTopHeight = 0;
mMainFrameBottomHeight = 0;
mMainFrameLeftWidth = 0;
mMainFrameRightWidth = 0;
} else {
mIsSubConsole = false;
} else if (mType & (MainConsole|Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The Buffer type should not be here I think. in fact, in the light of the previous comment I guess the ErrorConsole and Buffer types could/should be move to a new else if with just:

            mMainFrameTopHeight = 0;
            mMainFrameBottomHeight = 0;
            mMainFrameLeftWidth = 0;
            mMainFrameRightWidth = 0;

@@ -567,7 +571,7 @@ TConsole::TConsole(Host* pH, bool isDebugConsole, QWidget* parent)
layerCommandLine->setPalette(__pal);

changeColors();
if (!mIsSubConsole && !mIsDebugConsole) {
if (mType & (MainConsole|Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Should, I think, be just MainConsole...

@@ -603,7 +607,7 @@ void TConsole::setLabelStyleSheet(std::string& buf, std::string& sh)

void TConsole::resizeEvent(QResizeEvent* event)
{
if (!mIsDebugConsole && !mIsSubConsole) {
if (mType & (MainConsole|Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Just MainConsole here also?

@@ -613,7 +617,7 @@ void TConsole::resizeEvent(QResizeEvent* event)
int y = event->size().height();


if (!mIsSubConsole && !mIsDebugConsole) {
if (mType & (MainConsole|Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this and the previous can be run together with the two event->size() lines being done beforehand.

@@ -626,7 +630,7 @@ void TConsole::resizeEvent(QResizeEvent* event)
}
mpMainDisplay->move(mMainFrameLeftWidth, mMainFrameTopHeight);

if (mIsSubConsole || mIsDebugConsole) {
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the logic needs to be inverted so that the former else code is then only used for the MainConsole case...

@@ -635,7 +639,7 @@ void TConsole::resizeEvent(QResizeEvent* event)

QWidget::resizeEvent(event);

if (!mIsDebugConsole && !mIsSubConsole) {
if (mType & (MainConsole|Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We do not need a WindowResizeEvent for the Buffer type but since it is not visible we probably have not been seeing the code being run for them!

@@ -656,7 +660,7 @@ void TConsole::resizeEvent(QResizeEvent* event)

void TConsole::refresh()
{
if (!mIsDebugConsole) {
if (mType & (ErrorConsole|MainConsole|SubConsole|UserWindow|Buffer)) {
Copy link
Member Author

@SlySven SlySven Dec 17, 2018

Choose a reason for hiding this comment

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

This looks odd - being run on everything except the CentralDebugConsole ???

@@ -820,7 +824,7 @@ int TConsole::getButtonState()

void TConsole::toggleLogging(bool isMessageEnabled)
{
if (mIsDebugConsole || mIsSubConsole) {
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Technically, it should include the Buffer type as well.

@@ -1030,7 +1034,7 @@ void TConsole::toggleLogging(bool isMessageEnabled)
// generated for Lua user control by the Lua subsystem.
void TConsole::slot_toggleLogging()
{
if (mIsDebugConsole || mIsSubConsole) {
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

As previous - should include Buffer as well.

@@ -1040,7 +1044,7 @@ void TConsole::slot_toggleLogging()

void TConsole::slot_toggleReplayRecording()
{
if (mIsDebugConsole) {
if (mType & CentralDebugConsole) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Surely this should include everything apart from the MainConsole so that only that type actually does anything here.

@@ -1329,7 +1335,7 @@ void TConsole::deselect()

void TConsole::showEvent(QShowEvent* event)
{
if (!mIsDebugConsole && !mIsSubConsole) {
if (mType & (MainConsole|Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Given that the Buffer type is never visible I guess it shouldn't be here.

@@ -1339,7 +1345,7 @@ void TConsole::showEvent(QShowEvent* event)

void TConsole::hideEvent(QHideEvent* event)
{
if (!mIsDebugConsole && !mIsSubConsole) {
if (mType & (MainConsole|Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as showEvent.

@@ -1061,7 +1061,7 @@ void TTextEdit::slot_popupMenu()

void TTextEdit::mousePressEvent(QMouseEvent* event)
{
if (!mpConsole->mIsSubConsole && !mpConsole->mIsDebugConsole) {
if (mpConsole->getType() & (TConsole::MainConsole|TConsole::Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Impossible for the Buffer type!

@@ -1610,7 +1610,7 @@ void TTextEdit::mouseReleaseEvent(QMouseEvent* event)
mCtrlSelecting = false;
}

if (!mpConsole->mIsSubConsole && !mpConsole->mIsDebugConsole) {
if (mpConsole->getType() & (TConsole::MainConsole|TConsole::Buffer)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Again, impossible for the Buffer type!

@SlySven
Copy link
Member Author

SlySven commented Dec 29, 2018

@vadi2 This is marked as a W.I.P. because I want feed-back on the types that each if (...) is working on in the commented places. The current selection reproduces the current code situation as far as I can tell - I just want input from other sets of eyeballs before making any functional changes.

@Kebap
Copy link
Contributor

Kebap commented Dec 29, 2018

My 0.02$ is: don't let the PR grow into an untameable mess again. Merge the refractoring which reproduces the current behavior as is. Move the discussion about functional changes into their own issues, which can then spawn seperated PRs.

Copy link
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

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

I agree - lets merge this in now so we have the improvement, and then look into cleanup as a separate PR. I've read through your comments @SlySven and they seem to make sense. Let's also merge early so people can help test!

@SlySven
Copy link
Member Author

SlySven commented Jan 1, 2019

Okay, I'll raise an issue to link back to the points I've raised here after merging it in.

@SlySven SlySven merged commit 11f46b3 into Mudlet:development Jan 1, 2019
@SlySven SlySven deleted the Refactor_useASingleEnumToClassifyAllTConsoleInstances branch January 1, 2019 19:11
@SlySven SlySven restored the Refactor_useASingleEnumToClassifyAllTConsoleInstances branch June 22, 2020 17:58
@SlySven SlySven deleted the Refactor_useASingleEnumToClassifyAllTConsoleInstances branch June 22, 2020 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants