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: Fixed an issue where new files were sometimes created in the wrong directory #13523

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 34 additions & 37 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,55 +61,52 @@ public bool ShowPreviewPaneButton
DependencyProperty.Register("ShowPreviewPaneButton", typeof(bool), typeof(AddressToolbar), new PropertyMetadata(null));
private void NewEmptySpace_Opening(object sender, object e)
{
var shell = NewEmptySpace.Items.Where(x => (x.Tag as string) == "CreateNewFile").Reverse().ToList();
shell.ForEach(x => NewEmptySpace.Items.Remove(x));
if (!ViewModel.InstanceViewModel.CanCreateFileInPage)
{
var shell = NewEmptySpace.Items.Where(x => (x.Tag as string) == "CreateNewFile").Reverse().ToList();
shell.ForEach(x => NewEmptySpace.Items.Remove(x));
return;
}

var cachedNewContextMenuEntries = addItemService.GetEntries();
if (cachedNewContextMenuEntries is null)
return;
if (!NewEmptySpace.Items.Any(x => (x.Tag as string) == "CreateNewFile"))
{
var separatorIndex = NewEmptySpace.Items.IndexOf(NewEmptySpace.Items.Single(x => x.Name == "NewMenuFileFolderSeparator"));

ushort key = 0;
string keyFormat = $"D{cachedNewContextMenuEntries.Count.ToString().Length}";
var separatorIndex = NewEmptySpace.Items.IndexOf(NewEmptySpace.Items.Single(x => x.Name == "NewMenuFileFolderSeparator"));

ushort key = 0;
string keyFormat = $"D{cachedNewContextMenuEntries.Count.ToString().Length}";

foreach (var newEntry in Enumerable.Reverse(cachedNewContextMenuEntries))
foreach (var newEntry in Enumerable.Reverse(cachedNewContextMenuEntries))
{
MenuFlyoutItem menuLayoutItem;
if (!string.IsNullOrEmpty(newEntry.IconBase64))
{
MenuFlyoutItem menuLayoutItem;
if (!string.IsNullOrEmpty(newEntry.IconBase64))
byte[] bitmapData = Convert.FromBase64String(newEntry.IconBase64);
using var ms = new MemoryStream(bitmapData);
var image = new BitmapImage();
_ = image.SetSourceAsync(ms.AsRandomAccessStream());
menuLayoutItem = new MenuFlyoutItemWithImage()
{
byte[] bitmapData = Convert.FromBase64String(newEntry.IconBase64);
using var ms = new MemoryStream(bitmapData);
var image = new BitmapImage();
_ = image.SetSourceAsync(ms.AsRandomAccessStream());
menuLayoutItem = new MenuFlyoutItemWithImage()
{
Text = newEntry.Name,
BitmapIcon = image,
Tag = "CreateNewFile"
};
}
else
Text = newEntry.Name,
BitmapIcon = image,
Tag = "CreateNewFile"
};
}
else
{
menuLayoutItem = new MenuFlyoutItem()
{
menuLayoutItem = new MenuFlyoutItem()
Text = newEntry.Name,
Icon = new FontIcon
{
Text = newEntry.Name,
Icon = new FontIcon
{
Glyph = "\xE7C3"
},
Tag = "CreateNewFile"
};
}
menuLayoutItem.AccessKey = (cachedNewContextMenuEntries.Count + 1 - (++key)).ToString(keyFormat);
menuLayoutItem.Command = ViewModel.CreateNewFileCommand;
menuLayoutItem.CommandParameter = newEntry;
NewEmptySpace.Items.Insert(separatorIndex + 1, menuLayoutItem);
Glyph = "\xE7C3"
},
Tag = "CreateNewFile"
};
}
menuLayoutItem.AccessKey = (cachedNewContextMenuEntries.Count + 1 - (++key)).ToString(keyFormat);
menuLayoutItem.Command = ViewModel.CreateNewFileCommand;
menuLayoutItem.CommandParameter = newEntry;
NewEmptySpace.Items.Insert(separatorIndex + 1, menuLayoutItem);
}
}

Expand Down