Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Drag and Drop For Environment Variables#40105

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Darkace01 wants to merge2 commits intomicrosoft:main
base:main
Choose a base branch
Loading
fromDarkace01:environment-variables-drag-and-drop

Conversation

Darkace01
Copy link

Summary of the Pull Request

This PR introduces drag-and-drop functionality for environment variables, allowing users to easily update the order of variables based on their preferences. Users can now rearrange variables directly in the UI by dragging and dropping, making it more intuitive and efficient to customise the order without manual editing.

PR Checklist

Detailed Description of the Pull Request / Additional comments

UpdatedEnvironmentVariablesMainPage.xaml to use aListView instead of anItemsControl, enabling item dragging and reordering. The newListView features a grid layout with aFontIcon,TextBox, andButton, while maintaining visibility control through data binding.

AddedEditVariableValuesList_DragItemsCompleted method inEnvironmentVariablesMainPage.xaml.cs to update the text box with the new order of items after drag-and-drop operations, ensuring consistency with the underlying data model.

Validation Steps Performed

  • Manually tested the affected functionality.
  • Change was minimal and did not impact existing automated tests.
  • Verified that the new/modified feature works as expected and did not cause regressions in related areas.

Updated `EnvironmentVariablesMainPage.xaml` to use a `ListView` instead of an `ItemsControl`, enabling item dragging and reordering. The new `ListView` features a grid layout with a `FontIcon`, `TextBox`, and `Button`, while maintaining visibility control through data binding.Added `EditVariableValuesList_DragItemsCompleted` method in `EnvironmentVariablesMainPage.xaml.cs` to update the text box with the new order of items after drag-and-drop operations, ensuring consistency with the underlying data model.
@Darkace01
Copy link
Author

@microsoft-github-policy-service agree

@yeelam-gordonyeelam-gordon added the Product-Environment VariablesRefers to Environment Variables PowerToys labelJun 19, 2025
Copilot

This comment was marked as outdated.

Replaced hardcoded string separator `";"` with a constant `ValueListSeparator` in `EnvironmentVariablesMainPage.xaml.cs`. This change improves maintainability by centralizing the separator definition, making it easier to modify in the future. All instances of the separator in `string.Join` have been updated accordingly.
@Darkace01Darkace01 requested a review fromCopilotJune 25, 2025 08:53
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds drag-and-drop support to the environment variables UI, enabling users to rearrange variables more intuitively. Key changes include:

  • Introducing a constant (ValueListSeparator) and updating join calls in EnvironmentVariablesMainPage.xaml.cs.
  • Replacing an ItemsControl with a ListView in EnvironmentVariablesMainPage.xaml to support dragging and reordering.
  • Adding the EditVariableValuesList_DragItemsCompleted event handler to update the UI upon reordering.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

FileDescription
src/modules/EnvironmentVariables/EnvironmentVariablesUILib/EnvironmentVariablesMainPage.xaml.csUpdated join logic with a constant and added a new drag completion event handler.
src/modules/EnvironmentVariables/EnvironmentVariablesUILib/EnvironmentVariablesMainPage.xamlReplaced ItemsControl with a ListView enabling drag-and-drop functionality.

@@ -440,7 +441,7 @@ private void ReorderButtonUp_Click(object sender, Microsoft.UI.Xaml.RoutedEventA
variable.ValuesList.Move(index, index - 1);
}

var newValues = string.Join(";", variable.ValuesList?.Select(x => x.Text).ToArray());
var newValues = string.Join(ValueListSeparator, variable.ValuesList?.Select(x => x.Text).ToArray());
Copy link
Preview

CopilotAIJun 25, 2025

Choose a reason for hiding this comment

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

The logic to update the newValues string and reattach the TextChanged event is repeated across multiple methods. Consider extracting this common functionality into a helper method to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

Copy link

@dcq01dcq01 left a comment

Choose a reason for hiding this comment

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

Hi! I'm a grad student working on a research project about using large language models to automate code review. Based on your commita0e65cb and the changes in src/modules/EnvironmentVariables/EnvironmentVariablesUILib/EnvironmentVariablesMainPage.xaml.cs, my tool generated this comment:

  1. Null Handling: Ensure thatvariable andvariable.ValuesList are not null before attempting to join the values. If either is null, handle this case explicitly.

    if(variable==null||variable.ValuesList==null){// Handle the null case appropriatelyreturn;}
  2. Potential for IndexOutOfRange: Implement additional checks to ensure that the index is valid before attempting to move items inReorderButtonDown_Click andReorderButtonUp_Click.

  3. Event Unsubscription and Subscription: Use a try-finally block to ensure that the event handler is always reattached after setting the text ofEditVariableDialogValueTxtBox.

    EditVariableDialogValueTxtBox.TextChanged-=EditVariableDialogValueTxtBox_TextChanged;try{EditVariableDialogValueTxtBox.Text=newValues;}finally{EditVariableDialogValueTxtBox.TextChanged+=EditVariableDialogValueTxtBox_TextChanged;}
  4. Consistency of Separator: Ensure that theValueListSeparator is consistently used throughout the codebase wherever the values are joined. If there are other parts of the code that still use the hardcoded";" separator, it could lead to inconsistencies in how values are represented.

  5. TextBox Event Handling: Ensure that the eventEditVariableDialogValueTxtBox.TextChanged is not being triggered unnecessarily. If the new value is the same as the current value, it might be better to avoid setting the text and modifying the event handlers.

  6. Potential Performance Impact: IfValuesList contains a large number of items, consider usingstring.Join directly on theSelect without converting to an array to avoid performance implications.
    Change:

    varnewValues=string.Join(ValueListSeparator,variable.ValuesList?.Select(x=>x.Text).ToArray());

    to:

    varnewValues=string.Join(ValueListSeparator,variable.ValuesList?.Select(x=>x.Text));
  7. Code Duplication: The code for creatingnewValues is duplicated across multiple methods. Consider refactoring this into a separate method to adhere to the DRY (Don't Repeat Yourself) principle.

    privatevoidUpdateValuesTextBox(Variablevariable){varnewValues=string.Join(ValueListSeparator,variable.ValuesList?.Select(x=>x.Text));EditVariableDialogValueTxtBox.TextChanged-=EditVariableDialogValueTxtBox_TextChanged;EditVariableDialogValueTxtBox.Text=newValues;EditVariableDialogValueTxtBox.TextChanged+=EditVariableDialogValueTxtBox_TextChanged;}
  8. User Experience: When inserting a newValuesListItem with an empty string, consider how this affects the user experience. If the user is not expecting an empty entry, it might be better to prompt them or handle it differently.

  9. Unit Tests for ValueListSeparator: Add unit tests to verify the behavior of the code when using theValueListSeparator constant. Ensure it is correctly used in all relevant methods.

As part of my research, I'm trying to understand how useful these comments are in real-world development. If you have a moment, I'd be super grateful if you could quickly reply to these two yes/no questions:

  1. Does this comment provide suggestions from a dimension you hadn’t considered?
    1. Do you find this comment helpful?

Thanks a lot for your time and feedback! And sorry again if this message is a bother.

@crutkascrutkas added the Needs-ReviewThis Pull Request awaits the review of a maintainer. labelJul 10, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@dcq01dcq01dcq01 left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
Needs-ReviewThis Pull Request awaits the review of a maintainer.Product-Environment VariablesRefers to Environment Variables PowerToys
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@Darkace01@dcq01@crutkas@yeelam-gordon

[8]ページ先頭

©2009-2025 Movatter.jp