Skip to content

Fix: Fixed errors that occurred with shortcut items in git repositories #17015

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

marcofranzen99
Copy link
Contributor

Resolved / Related Issues

Description
The problem was that GitShortcutItem cannot be cast to ShortcutItem because GitShortcutItem only inherits from GitItem and IShortcutItem. It cannot additionally inherit from ShortcutItem, since a class in C# cannot have multiple base classes.

Simply casting to IShortcutItem everywhere did not work, as the IShortcutItem interface would lack properties of the ListedItem (such as ItemPath).

That's why I decided to create an interface IListedItem. IShortcutItem & IGitItem now both inherit from this interface.

Problems only occurred with shortcut items that are part of a git repository. Not all of them led to a crash, some only displayed error messages or led to incorrect behavior. Here is a list of affected actions:

  • Selecting a shortcut item
  • Selecting a shortcut item with preview pane open
  • Open Properties Window for a shortcut item
  • Save modified properties of a shortcut via properties window
  • Open in new tab
  • Open in new pane
  • Open in new Window
  • Pin To Start
  • Unpin From Start
  • Share Item

Steps used to test these changes

  1. tested if the actions listed above work correctly

Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

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

I can repro that thehe latest stable version of Files crashes when selecting but in this PR it works well.

LGTM.

image

@@ -48,9 +48,8 @@ public override void GetBaseProperties()
ViewModel.LoadFileIcon = Item.LoadFileIcon;
ViewModel.ContainsFilesOrFolders = Item.ContainsFilesOrFolders;

if (Item.IsShortcut)
if (Item.IsShortcut && Item is IShortcutItem shortcutItem)
Copy link
Member

Choose a reason for hiding this comment

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

I think this is the important part. FYI for others.

@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed needs - code review labels Apr 9, 2025
@yaira2 yaira2 merged commit 96143bb into files-community:main Apr 9, 2025
6 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Selecting a shortcut in a git folder crashes Files
3 participants