Skip to content

Commit fe1d347

Browse files
committed
Use popup to display editable filename
Added x:Load attribute to edit popup
1 parent 587df5c commit fe1d347

File tree

2 files changed

+55
-27
lines changed

2 files changed

+55
-27
lines changed

Files/UserControls/LayoutModes/GridViewBrowser.xaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,27 @@
389389
</Viewbox>
390390
</Grid>
391391
</Grid>
392-
<StackPanel Grid.Row="1">
393-
<TextBlock
394-
Margin="0,0,0,10"
395-
HorizontalAlignment="Stretch"
396-
VerticalAlignment="Stretch"
397-
HorizontalTextAlignment="Center"
398-
Text="{x:Bind ItemName}"
399-
TextTrimming="CharacterEllipsis"
400-
TextWrapping="NoWrap" />
392+
<TextBlock
393+
Grid.Row="1"
394+
Margin="0,0,0,10"
395+
HorizontalAlignment="Stretch"
396+
VerticalAlignment="Stretch"
397+
HorizontalTextAlignment="Center"
398+
Text="{x:Bind ItemName}"
399+
TextTrimming="CharacterEllipsis"
400+
TextWrapping="NoWrap" />
401+
<Popup Grid.Row="1"
402+
x:Name="EditPopup"
403+
x:Load="False">
401404
<TextBox
402405
Margin="0"
406+
Width="{x:Bind local:App.AppSettings.GridViewSize, Mode=OneWay}"
403407
HorizontalAlignment="Stretch"
404408
VerticalAlignment="Stretch"
405409
Text="{x:Bind ItemName}"
406410
TextAlignment="Center"
407-
TextWrapping="Wrap"
408-
Visibility="Collapsed" />
409-
</StackPanel>
411+
TextWrapping="Wrap" />
412+
</Popup>
410413
</Grid>
411414
</DataTemplate>
412415

Files/UserControls/LayoutModes/GridViewBrowser.xaml.cs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Windows.UI.Core;
77
using Windows.UI.Xaml;
88
using Windows.UI.Xaml.Controls;
9+
using Windows.UI.Xaml.Controls.Primitives;
910
using Windows.UI.Xaml.Input;
1011
using Interaction = Files.Interacts.Interaction;
1112

@@ -138,21 +139,35 @@ private void FileList_SelectionChanged(object sender, SelectionChangedEventArgs
138139
public override void StartRenameItem()
139140
{
140141
renamingItem = SelectedItem;
141-
GridViewItem gridViewItem = FileList.ContainerFromItem(renamingItem) as GridViewItem;
142-
// Handle layout differences between tiles browser and photo album
143-
StackPanel stackPanel = (App.AppSettings.LayoutMode == 2)
144-
? (gridViewItem.ContentTemplateRoot as Grid).Children[1] as StackPanel
145-
: (((gridViewItem.ContentTemplateRoot as Grid).Children[0] as StackPanel).Children[1] as Grid).Children[0] as StackPanel;
146-
TextBlock textBlock = stackPanel.Children[0] as TextBlock;
147-
TextBox textBox = stackPanel.Children[1] as TextBox;
148142
int extensionLength = renamingItem.FileExtension?.Length ?? 0;
143+
GridViewItem gridViewItem = FileList.ContainerFromItem(renamingItem) as GridViewItem;
144+
TextBox textBox = null;
149145

150-
textBlock.Visibility = Visibility.Collapsed;
151-
textBox.Visibility = Visibility.Visible;
146+
// Handle layout differences between tiles browser and photo album
147+
if (App.AppSettings.LayoutMode == 2)
148+
{
149+
Popup popup =
150+
(gridViewItem.ContentTemplateRoot as Grid).FindName("EditPopup") as Popup;
151+
TextBlock textBlock =
152+
(gridViewItem.ContentTemplateRoot as Grid).Children[1] as TextBlock;
153+
textBox = popup.Child as TextBox;
154+
popup.IsOpen = true;
155+
}
156+
else
157+
{
158+
StackPanel stackPanel =
159+
(((gridViewItem.ContentTemplateRoot as Grid).Children[0] as StackPanel).Children[1] as Grid).Children[0] as StackPanel;
160+
TextBlock textBlock = stackPanel.Children[0] as TextBlock;
161+
textBox = stackPanel.Children[1] as TextBox;
162+
textBlock.Visibility = Visibility.Collapsed;
163+
textBox.Visibility = Visibility.Visible;
164+
}
165+
152166
textBox.Focus(FocusState.Pointer);
153167
textBox.LostFocus += RenameTextBox_LostFocus;
154168
textBox.KeyDown += RenameTextBox_KeyDown;
155169
textBox.Select(0, renamingItem.ItemName.Length - extensionLength);
170+
156171
isRenamingItem = true;
157172
}
158173

@@ -219,12 +234,22 @@ private async void CommitRename(TextBox textBox)
219234

220235
private void EndRename(TextBox textBox)
221236
{
222-
StackPanel parentPanel = textBox.Parent as StackPanel;
223-
TextBlock textBlock = parentPanel.Children[0] as TextBlock;
224-
textBox.Visibility = Visibility.Collapsed;
225-
textBlock.Visibility = Visibility.Visible;
237+
if (App.AppSettings.LayoutMode == 2)
238+
{
239+
Popup popup = (textBox.Parent) as Popup;
240+
TextBlock textBlock = (popup.Parent as Grid).Children[1] as TextBlock;
241+
popup.IsOpen = false;
242+
}
243+
else
244+
{
245+
StackPanel parentPanel = textBox.Parent as StackPanel;
246+
TextBlock textBlock = parentPanel.Children[0] as TextBlock;
247+
textBox.Visibility = Visibility.Collapsed;
248+
textBlock.Visibility = Visibility.Visible;
249+
}
250+
226251
textBox.LostFocus -= RenameTextBox_LostFocus;
227-
textBox.KeyDown += RenameTextBox_KeyDown;
252+
textBox.KeyDown -= RenameTextBox_KeyDown;
228253
isRenamingItem = false;
229254
}
230255

@@ -338,4 +363,4 @@ private void AppSettings_GridViewSizeChangeRequested(object sender, EventArgs e)
338363
_iconSize = iconSize; // Update icon size
339364
}
340365
}
341-
}
366+
}

0 commit comments

Comments
 (0)