Skip to content

Commit

Permalink
add more filter, new feature: save rule, save last folder location
Browse files Browse the repository at this point in the history
  • Loading branch information
phamngocduy98 committed Sep 16, 2019
1 parent 42260fa commit 2245cfa
Show file tree
Hide file tree
Showing 30 changed files with 512 additions and 120 deletions.
30 changes: 29 additions & 1 deletion WPF.NET/Swipe/AppModel/DataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Swipe.AppModel
{
class DataStore
{
public string folderPath { get; set; }
private List<FileName> files = new List<FileName>();
public void SetFileList(string[] files)
{
Expand All @@ -28,4 +28,32 @@ public List<FileName> getFileList()


}
[Serializable]
[XmlRoot(ElementName = "Config")]
public class ConfigStore
{
[XmlElement("FolderPath")]
public string folderPath;
[XmlArrayItem("ReplaceWhatItem")]
public List<string> ReplaceWhat;
[XmlArrayItem("ReplaceByItem")]
public List<string> ReplaceBy;

public ConfigStore()
{
ReplaceWhat = new List<string>();
ReplaceBy = new List<string>();
}

public void SetCustomReplaceWhat(List<string> customReplaceWhat)
{
ReplaceWhat.Clear();
ReplaceWhat.AddRange(customReplaceWhat);
}
public void SetCustomReplaceBy(List<string> customReplaceBy)
{
ReplaceBy.Clear();
ReplaceBy.AddRange(customReplaceBy);
}
}
}
53 changes: 53 additions & 0 deletions WPF.NET/Swipe/AppModel/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

namespace Swipe.AppModel
{
Expand Down Expand Up @@ -47,5 +49,56 @@ public static bool rename(string folderPath, string oldName, string newName)
File.Move(folderPath + "\\" + oldName, folderPath + "\\" + newName);
return false;
}
public static void SerializeObject<T>(T serializableObject, string fileName)
{
if (serializableObject == null) { return; }

try
{
XmlDocument xmlDocument = new XmlDocument();
XmlSerializer serializer = new XmlSerializer(serializableObject.GetType());
using (MemoryStream stream = new MemoryStream())
{
serializer.Serialize(stream, serializableObject);
stream.Position = 0;
xmlDocument.Load(stream);
xmlDocument.Save(fileName);
}
}
catch (Exception ex)
{
// //Log exception here
}
}
public static T DeSerializeObject<T>(string fileName)
{
if (string.IsNullOrEmpty(fileName)) { return default(T); }

T objectOut = default(T);

try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(fileName);
string xmlString = xmlDocument.OuterXml;

using (StringReader read = new StringReader(xmlString))
{
Type outType = typeof(T);

XmlSerializer serializer = new XmlSerializer(outType);
using (XmlReader reader = new XmlTextReader(read))
{
objectOut = (T)serializer.Deserialize(reader);
}
}
}
catch (Exception ex)
{
//Log exception here
}

return objectOut;
}
}
}
36 changes: 22 additions & 14 deletions WPF.NET/Swipe/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Swipe"
mc:Ignorable="d"
Title="Rename Tool - Pham Ngoc Duy" Height="500" Width="500">
Title="Rename Tool v19.09.16 - Pham Ngoc Duy" Height="500" Width="500">
<TabControl x:Name="tabControl">
<TabItem Header="Trang chủ">
<DockPanel>
Expand All @@ -19,19 +19,20 @@
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="14*"/>
<ColumnDefinition Width="53*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button x:Name="btnBrowse" Click="BtnBrowse_Click" IsDefault="True" Content="Duyệt" Width="75" Grid.Column="1"/>
<TextBox x:Name="inputFolder" Text="Chọn một thư mục..." Grid.Column="0" Margin="5,5,0,5" />
<Button x:Name="btnPreview" Click="BtnPreview_Click" Content="Xem trước" Grid.Row="1" Grid.Column="0"/>
<Button x:Name="btnStart" Click="BtnStart_Click" Content="Bắt đầu" Grid.Row="1" Grid.Column="1"/>
<Button x:Name="btnBrowse" Click="BtnBrowse_Click" IsDefault="True" Content="Duyệt" Width="75" Grid.Column="2" Margin="4.6,5,5.2,4.8"/>
<TextBox x:Name="inputFolder" Text="Chọn một thư mục..." Grid.Column="0" Margin="5,5,84.2,4.8" Grid.ColumnSpan="3" />
<Button x:Name="btnPreview" Click="BtnPreview_Click" Content="Xem trước" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,5.2,5.4,4.6"/>
<Button x:Name="btnStart" Click="BtnStart_Click" Content="Đổi tên file" Grid.Row="1" Grid.Column="2" Margin="4.6,5.2,5.2,4.6"/>
</Grid>

<ListView x:Name="listView" DockPanel.Dock="Bottom" >
<ListView.View>
<GridView>
Expand All @@ -42,11 +43,15 @@
</ListView.View>
</ListView>
</DockPanel>

</TabItem>
<TabItem Header="Cấu hình">
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Top" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
Expand All @@ -60,10 +65,13 @@
</Style>
</Grid.Resources>
<CheckBox x:Name="cboxRemoveVNCSign" Content="Bỏ dấu tiếng việt" IsChecked="True"/>
<CheckBox x:Name="cboxBracket" Content="Thay [] bằng ()" IsChecked="True" Grid.Row="1"/>
<CheckBox x:Name="cboxSpace" Content="Thay space bằng _" IsChecked="True" Grid.Row="2"/>
<CheckBox x:Name="cboxHyphen" Content="Thay - bằng _" IsChecked="True" Grid.Row="3"/>
<CheckBox x:Name="cboxQuotation" Content="Thay ' bằng _" IsChecked="True" Grid.Row="4"/>
<CheckBox x:Name="cboxBracket" Content="Thay [] bằng ()" IsChecked="True" Grid.Row="0" Grid.Column="1"/>
<CheckBox x:Name="cboxSpace" Content="Thay space bằng _" IsChecked="True" Grid.Row="1" Grid.Column="0"/>
<CheckBox x:Name="cboxHyphen" Content="Thay - bằng _" IsChecked="True" Grid.Row="1" Grid.Column="1"/>
<CheckBox x:Name="cboxQuotation" Content="Thay ' bằng _" IsChecked="True" Grid.Row="2" Grid.Column="0"/>
<CheckBox x:Name="cboxSpecialCharacter" Content="Xóa kí hiệu @ Ⓡ" IsChecked="True" Grid.Row="2" Grid.Column="1"/>
<CheckBox x:Name="cboxRemoveDuplicateSpace" Content="Xóa các dấu __ trùng lặp" IsChecked="True" Grid.Row="3" Grid.Column="0"/>
<CheckBox x:Name="cboxRemoveBeginSpace" Content="Xóa __ ở đầu tên" IsChecked="True" Grid.Row="3" Grid.Column="1"/>
</Grid>
<Button x:Name="btnAddRule" Click="BtnAddRule_Click" Content="Thêm luật thay thế" DockPanel.Dock="Bottom" />
<ScrollViewer DockPanel.Dock="Bottom">
Expand All @@ -83,10 +91,10 @@
</Grid.ColumnDefinitions>
</Grid>
</ScrollViewer>

</DockPanel>
</TabItem>

</TabControl>

</Window>
Loading

0 comments on commit 2245cfa

Please sign in to comment.