Skip to content

Commit 1246f5a

Browse files
author
panwenbo
committed
One.Toolbox
优化NotePad重命名的逻辑:
1 parent 157273f commit 1246f5a

File tree

6 files changed

+173
-163
lines changed

6 files changed

+173
-163
lines changed

One.Toolbox/Helpers/PathHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using One.Toolbox.Views.Stick;
2-
3-
using System.IO;
1+
using System.IO;
42

53
namespace One.Toolbox.Helpers
64
{

One.Toolbox/ViewModels/MainWindow/MainWindowVM.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public MainWindowVM()
8383
//TargetPageType = typeof(Views.NotePad.NotePadPage),
8484
Content = new Views.Stick.StickPage(),
8585
},
86-
new MainMenuItemVM()
86+
new()
8787
{
8888
Header = "EveryImage",
8989
Icon = ResourceHelper.Dic["ImageArea"],
@@ -105,7 +105,7 @@ public MainWindowVM()
105105
// Content = new Views.TestPage(),
106106
//},
107107
//倒叙
108-
new MainMenuItemVM()
108+
new()
109109
{
110110
Header = "Setting",
111111
Icon = ResourceHelper.Dic["SettingsRound"],

One.Toolbox/ViewModels/NotePad/EditFileInfoVM.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
using One.Toolbox.Helpers;
88

99
using System.Collections.ObjectModel;
10+
using System.Diagnostics;
1011
using System.IO;
1112
using System.Text;
13+
using System.Windows.Controls;
1214

1315
namespace One.Toolbox.ViewModels.NotePad;
1416

@@ -80,6 +82,8 @@ public EditFileInfoVM(string filePath)
8082
HighlightingDefinitionOC = HighlightingManager.Instance.HighlightingDefinitions;
8183
}
8284

85+
#region RelayCommand
86+
8387
[RelayCommand]
8488
private void OpenFile()
8589
{
@@ -90,6 +94,12 @@ private void OpenFile()
9094
}
9195
}
9296

97+
[RelayCommand]
98+
private void OpenFilePath()
99+
{
100+
Process.Start("explorer.exe", PathHelper.dataPath);
101+
}
102+
93103
[RelayCommand]
94104
private void SaveFile()
95105
{
@@ -112,6 +122,28 @@ private void OnSelectedHighlightingChanged(object obj)
112122
return;
113123
}
114124

125+
[RelayCommand]
126+
private void RenameFile(object obj)
127+
{
128+
var parent = obj as Grid;
129+
var txb = parent.FindName("txb1") as TextBox;
130+
if (txb != null)
131+
{
132+
IsEditFileName = true;
133+
txb.LostFocus += Txb_LostFocus;
134+
var res = txb.Focus();
135+
136+
//txb.SelectAll();
137+
}
138+
}
139+
140+
private void Txb_LostFocus(object sender, RoutedEventArgs e)
141+
{
142+
IsEditFileName = false;
143+
}
144+
145+
#endregion RelayCommand
146+
115147
partial void OnFileNameChanged(string? oldValue, string newValue)
116148
{
117149
if (oldValue == null)

One.Toolbox/ViewModels/NotePad/NotePadPageVM.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using One.Toolbox.ViewModels.Setting;
1010

1111
using System.Collections.ObjectModel;
12-
using System.Diagnostics;
1312
using System.IO;
1413

1514
namespace One.Toolbox.ViewModels.NotePad;
@@ -101,27 +100,6 @@ private void DeleteFile()
101100
}
102101
}
103102

104-
[RelayCommand]
105-
private void RenameFile()
106-
{
107-
if (SelectedEditFileInfo != null)
108-
{
109-
//var newFileName = "";
110-
//SelectedEditFileInfo.RenameFile(newFileName);
111-
112-
SelectedEditFileInfo.IsEditFileName = true;
113-
}
114-
}
115-
116-
[RelayCommand]
117-
private void OpenFilePath()
118-
{
119-
if (SelectedEditFileInfo != null)
120-
{
121-
Process.Start("explorer.exe", PathHelper.dataPath);
122-
}
123-
}
124-
125103
#endregion Command
126104

127105
#region Setting

One.Toolbox/Views/MainWindow.xaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</ItemsPanelTemplate>
6666
</ListBox.ItemsPanel>
6767
<ListBox.ItemTemplate>
68-
<DataTemplate DataType="viewmodels:MainMenuItemViewModel">
68+
<DataTemplate DataType="viewmodels:MainMenuItemVM">
6969
<Grid>
7070
<Grid.RowDefinitions>
7171
<RowDefinition />
@@ -80,15 +80,15 @@
8080
</DataTemplate>
8181
</ListBox.ItemTemplate>
8282
<d:ListBox.ItemsSource>
83-
<x:Array Type="{x:Type vms:MainMenuItemViewModel}">
84-
<vms:MainMenuItemViewModel Header="1" Icon="{StaticResource HomeRound}" />
85-
<vms:MainMenuItemViewModel Icon="{StaticResource TextFieldsRound}" />
86-
<vms:MainMenuItemViewModel Header="2" Icon="{StaticResource SerialPort24Filled}" />
87-
<vms:MainMenuItemViewModel Icon="{StaticResource Network}" />
88-
<vms:MainMenuItemViewModel Icon="{StaticResource EditNoteFilled}" />
83+
<x:Array Type="{x:Type vms:MainMenuItemVM}">
84+
<vms:MainMenuItemVM Header="1" Icon="{StaticResource HomeRound}" />
85+
<vms:MainMenuItemVM Icon="{StaticResource TextFieldsRound}" />
86+
<vms:MainMenuItemVM Header="2" Icon="{StaticResource SerialPort24Filled}" />
87+
<vms:MainMenuItemVM Icon="{StaticResource Network}" />
88+
<vms:MainMenuItemVM Icon="{StaticResource EditNoteFilled}" />
8989

90-
<vms:MainMenuItemViewModel Dock="Bottom" Icon="{StaticResource SettingsRound}" />
91-
<vms:MainMenuItemViewModel Dock="Bottom" Icon="{StaticResource CloudSyncFilled}" />
90+
<vms:MainMenuItemVM Dock="Bottom" Icon="{StaticResource SettingsRound}" />
91+
<vms:MainMenuItemVM Dock="Bottom" Icon="{StaticResource CloudSyncFilled}" />
9292
</x:Array>
9393
</d:ListBox.ItemsSource>
9494
</ListBox>

0 commit comments

Comments
 (0)