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

[Issue] "Enable", "Disable" and "Delete Mod" buttons show up when clicking blank space in listbox. #12

Closed
RyanWalpole opened this issue Mar 3, 2022 · 2 comments · Fixed by #13
Assignees
Labels
status: needs triage Requires assessment to determine severity, impact and to collect more data on the issue. type: bug A bug or issue that causes the application to not function as intended.

Comments

@RyanWalpole
Copy link
Collaborator

Describe the Issue
The enable, disable and delete mod buttons are disabled until a mod is selected - however clicking on the white space in the list of mods registers as highlighting a mod and the buttons become enabled and can be clicked. Clicking it returns an error code "Object reference not set to an instance of an object" and in the instance of using the delete button without a mod selected, the error assumes the mod you're trying to delete is not disabled(?).

Steps to Replicate
Steps to reproduce the behavior:

  1. Open Stardew Valley Mod Manager
  2. Click on the white space within the enabled or disabled mods list
  3. Notice that the enable, disable and delete mod buttons become interactable (depending on which list you click on)
  4. Click any of the three buttons without highlighting a mod to view error code.

Expected behavior
The expected behaviour would be for the enable, disable and delete mods buttons to only appear when a mod is highlighted/selected and not simply when the user clicks on white psace in the disabled and enabled mods lists.

Environment:

  • Windows Version: Windows 11
  • Mod Manager Version: 220201, 220301

Suggested Resolution
Inspect how the interactability of the buttons is determined and evaluate other ways it can be determined.

@RyanWalpole RyanWalpole added status: needs triage Requires assessment to determine severity, impact and to collect more data on the issue. version: 220202 labels Mar 3, 2022
@RyanWalpole
Copy link
Collaborator Author

Issue Investigation
Currently the application uses the "Click" event for the listboxes. This fires even when the listbox is clicked on but nothing is selected - hence the current behaviour.

private void InstalledModsList_Click(object sender, EventArgs e)
        {
            AvailableModsList.SelectedItem = null;
            DeleteMod.Enabled = false;
            EnableMod.Enabled = false;
            DisableMod.Enabled = true;
        }

Proposed Solution
Immediately the proposed solution would be to move to the "SelectedValueChanged" event so that it only fires code when the listbox selection changes. This however has the flaw in that the code deselects any item in the opposite list box - which then would fire the SelectedValueChanged again - simply having both buttons be enabled anyway.

@RyanWalpole RyanWalpole self-assigned this Mar 3, 2022
@RyanWalpole RyanWalpole added the type: bug A bug or issue that causes the application to not function as intended. label Mar 4, 2022
@RyanWalpole
Copy link
Collaborator Author

Issue Resolved
The issue has been resolved. I decided not to go with the SelectedValueChanged event as it was causing too many other issues to arise. Instead, I decided to retrieve the SelectedIndex value. When nothing is selected, it returns a value of -1. Therefore I can make an if statement, if value returned is less than 0 (nothing selected), do this.

New code can be found below:

private void InstalledModsList_Click(object sender, EventArgs e)
        {
            if(InstalledModsList.SelectedIndex < 0)
            {
                //AvailableModsList.SelectedItem = null;
                //AvailableModsList.SelectedIndex = -1;
            }
            else
            {
                AvailableModsList.SelectedItem = null;
                AvailableModsList.SelectedIndex = -1;
                DeleteMod.Enabled = false;
                EnableMod.Enabled = false;
                DisableMod.Enabled = true;
            }
        }

        private void AvailableModsList_Click(object sender, EventArgs e)
        {
            if (AvailableModsList.SelectedIndex < 0)
            {
                //InstalledModsList.SelectedItem = null;
                //InstalledModsList.SelectedIndex = -1;
            }
            else
            {
                InstalledModsList.SelectedItem = null;
                InstalledModsList.SelectedIndex = -1;
                DeleteMod.Enabled = true;
                EnableMod.Enabled = true;
                DisableMod.Enabled = false;
            }
        }

Now it will only disable and enable the interactability of the buttons if the listbox is clicked AND the SelectedIndex value is 0 and higher (a valid selection).

RWELabs added a commit that referenced this issue Mar 4, 2022
 Listbox whitespace triggers buttons to become interactable when they shouldn't be. This has been fixed. See #12 for information.

Co-Authored-By: Ryan Walpole <69621127+RyanWalpole@users.noreply.github.com>
@RyanWalpole RyanWalpole linked a pull request Mar 4, 2022 that will close this issue
@RWELabs RWELabs added this to To do in Dev: SDVMM v220302 Mar 6, 2022
@RWELabs RWELabs moved this from To do to Done in Dev: SDVMM v220302 Mar 6, 2022
@RyanWalpole RyanWalpole added this to Fixed In Release in Stardew Valley Mod Manager (Stable) Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Requires assessment to determine severity, impact and to collect more data on the issue. type: bug A bug or issue that causes the application to not function as intended.
Projects
Development

Successfully merging a pull request may close this issue.

1 participant