Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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

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.

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-gordon yeelam-gordon requested a review from Copilot June 19, 2025 00:27
@yeelam-gordon yeelam-gordon added the Product-Environment Variables Refers to Environment Variables PowerToys label Jun 19, 2025
Copy link
Contributor

@Copilot Copilot AI 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

Adds drag-and-drop reordering to the environment variable values list and synchronizes the reordered values back into the edit dialog’s text box.

  • Swaps the ItemsControl for a ListView with CanDragItems/CanReorderItems enabled.
  • Introduces EditVariableValuesList_DragItemsCompleted to rebuild the semicolon-delimited value string.
  • Updates the item template to include a drag handle icon and repositioned action button.

Reviewed Changes

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

File Description
EnvironmentVariablesMainPage.xaml.cs Added EditVariableValuesList_DragItemsCompleted handler to sync reordered items into the text box.
EnvironmentVariablesMainPage.xaml Replaced ItemsControl with ListView, enabled drag-and-drop, and updated the data template.
Comments suppressed due to low confidence (1)

src/modules/EnvironmentVariables/EnvironmentVariablesUILib/EnvironmentVariablesMainPage.xaml.cs:552

  • Add unit tests or UI automation tests for the drag-and-drop handler to verify that the text box is updated correctly when the ValuesList is reordered.
        private void EditVariableValuesList_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)

<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<FontIcon
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Add an AutomationProperties.Name (or appropriate accessible name) to the FontIcon used as a drag handle so that screen readers can announce its purpose.

Copilot uses AI. Check for mistakes.

{
if (EditVariableDialog.DataContext is Variable variable && variable.ValuesList != null)
{
var newValues = string.Join(";", variable.ValuesList.Select(x => x.Text));
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Extract the literal separator ";" into a constant (e.g., ValueListSeparator) to avoid magic strings and improve maintainability.

Suggested change
var newValues = string.Join(";", variable.ValuesList.Select(x => x.Text));
var newValues = string.Join(ValueListSeparator, variable.ValuesList.Select(x => x.Text));

Copilot uses AI. Check for mistakes.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product-Environment Variables Refers to Environment Variables PowerToys
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants