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

Fix append extension to work when ok button clicked #9945

Closed

Conversation

mere-human
Copy link
Contributor

Fix #9939

In some cases, checkbox was found instead of OK button and window
procedure was overriden for it. Now, the OK button is identified
using style and label checks.

Also, in some cases IFileDialog::GetFileTypeIndex() returns
the old value. To fix that, always remember the file type selected.

Fix notepad-plus-plus#9939

In some cases, checkbox was found instead of OK button and window
procedure was overriden for it. Now, the OK button is identified
using style and label checks.

Also, in some cases IFileDialog::GetFileTypeIndex() returns
the old value. To fix that, always remember the file type selected.
@mere-human mere-human marked this pull request as ready for review June 3, 2021 18:59
}
_dialog->SetFileTypeIndex(newFileType);
Copy link

Choose a reason for hiding this comment

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

Should there be a sanity check just to make sure that newFileType is not the same as _currentType? That is, that it actually changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.
But I believe, it could never happen.

This function is called each time the checkbox is clicked.
_lastSelectedType could be anything but _wildcardType (condition at the line 325).
And when the new file type is selected (user clicks an item in the dropdown list) the checkbox is checked if it was unchecked.

@@ -51,6 +50,7 @@ namespace // anonymous

static const int IDC_FILE_CUSTOM_CHECKBOX = 4;
static const int IDC_FILE_TYPE_CHECKBOX = IDC_FILE_CUSTOM_CHECKBOX + 1;
static const TCHAR TEMP_OK_BUTTON_LABEL[] = _T("Save");
Copy link

Choose a reason for hiding this comment

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

Following C++14+, this should probably be static constexpr const....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this context, I think it doesn't matter.
The compiler generates the same assembly.

If I were to declare this as a static member of a class, then it makes more sense.
Since I could initialize constexpr in place while for a static const I need an initializer in the .cpp.

Copy link

Choose a reason for hiding this comment

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

Sure, I just make it a habit nowadays to use constexpr wherever it is relevant instead of just const alone.

Many things will generate the same machine code output, but will have slightly different semantics, but in general I keep it constexpr because it encourages me to use it more often.

@@ -826,7 +830,7 @@ class CustomFileDialog::Impl

///////////////////////////////////////////////////////////////////////////////

CustomFileDialog::CustomFileDialog(HWND hwnd) : _impl{std::make_unique<Impl>()}
CustomFileDialog::CustomFileDialog(HWND hwnd) : _impl{ std::make_unique<Impl>() }
Copy link

@ameisen ameisen Jun 4, 2021

Choose a reason for hiding this comment

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

Strangely, MSVC (GCC and Clang do not) generates different code depending on if you brace or parantheses-initialize. Also, generates different code if you use new instead of std::make_unique.

https://godbolt.org/z/3WfKaqEYP

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 don't see any significant differences between braces vs parentheses init. Below is a diff of your example when I left only int overload and only float overload:
image

As for new, yes, it would be different as expected.
But still, using make_unique over bare new is a good practice to avoid leaks if constructor throws:
https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique

Copy link

Choose a reason for hiding this comment

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

I don't disagree, I was just surprised at the difference as I'd expected the optimizer to reduce them to the same thing in the end.

Don't look at the wrapper_types as they are __forceinlined - look at the outputs for func0/1/2.

@donho donho self-assigned this Jun 4, 2021
@donho donho added the accepted label Jun 4, 2021
@mere-human
Copy link
Contributor Author

I also checked this PR on Windows 7 VM. Seems to be working fine.

@chcg chcg added the bug label Jun 5, 2021
@donho donho closed this in 0e1a466 Jun 6, 2021
@mere-human mere-human deleted the fdlg-assign-type-9939 branch June 6, 2021 20:07
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.

Append extension doesn't work in Save As dialog
4 participants