├── .gitignore
├── Images
├── back.png
├── close.png
├── exit.png
├── more.png
├── open.png
├── save.png
├── stat.png
├── tool.png
├── download.png
├── encoding.png
├── forward.png
└── Countries
│ ├── eng.png
│ └── ru.png
├── App.config
├── Properties
├── Settings.settings
├── Settings.Designer.cs
├── AssemblyInfo.cs
├── Resources.Designer.cs
└── Resources.resx
├── Views
├── MainWindow.xaml.cs
├── LoadFilePage.xaml.cs
├── WorkFilePage.xaml.cs
├── LoadFilePage.xaml
├── WorkFilePage.xaml
└── MainWindow.xaml
├── Models
├── StringElement.cs
├── LanguageMethods.cs
├── ILanguage.cs
├── EnglishLanguage.cs
└── RussianLanguage.cs
├── App.xaml.cs
├── Classes
├── LogEvent.cs
├── LanguageSettings.cs
├── Collections.cs
├── RegistryMethods.cs
└── Log.cs
├── README.md
├── Converters
├── MultiCommandParameterConverter.cs
├── OddConverter.cs
└── TextListWidthConverter.cs
├── ViewModels
├── BaseViewModel.cs
├── LoadFileViewModel.cs
├── WorkFileViewModel.cs
└── MainViewModel.cs
├── Commands
├── RelayCommand.cs
└── DelegateCommand.cs
├── YarcheTextEditor.sln
├── App.xaml
├── Dictionaries
├── ImagesDictionary.xaml
└── StylesDictionary.xaml
└── YarcheTextEditor.csproj
/.gitignore:
--------------------------------------------------------------------------------
1 | *.dll
2 | *.pdb
3 | *.txt
4 | *.cache
5 | Debug/
6 | Release/
7 | obj/
8 | bin/
9 | .vs/
--------------------------------------------------------------------------------
/Images/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/back.png
--------------------------------------------------------------------------------
/Images/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/close.png
--------------------------------------------------------------------------------
/Images/exit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/exit.png
--------------------------------------------------------------------------------
/Images/more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/more.png
--------------------------------------------------------------------------------
/Images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/open.png
--------------------------------------------------------------------------------
/Images/save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/save.png
--------------------------------------------------------------------------------
/Images/stat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/stat.png
--------------------------------------------------------------------------------
/Images/tool.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/tool.png
--------------------------------------------------------------------------------
/Images/download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/download.png
--------------------------------------------------------------------------------
/Images/encoding.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/encoding.png
--------------------------------------------------------------------------------
/Images/forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/forward.png
--------------------------------------------------------------------------------
/Images/Countries/eng.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/Countries/eng.png
--------------------------------------------------------------------------------
/Images/Countries/ru.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/menshikovyaroslav/YarcheTextEditor/HEAD/Images/Countries/ru.png
--------------------------------------------------------------------------------
/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Views/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | namespace YarcheTextEditor
4 | {
5 | public partial class MainWindow : Window
6 | {
7 | public MainWindow()
8 | {
9 | InitializeComponent();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Models/StringElement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace YarcheTextEditor.Models
8 | {
9 | public class StringElement
10 | {
11 | public int Index { get; set; }
12 | public string Text { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace YarcheTextEditor
10 | {
11 | ///
12 | /// Логика взаимодействия для App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Classes/LogEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace YarcheTextEditor.Classes
8 | {
9 | public class LogEvent
10 | {
11 | public string Text { get; set; }
12 | public DateTime Time { get; set; }
13 |
14 | public LogEvent(string text)
15 | {
16 | Text = text;
17 | Time = DateTime.Now;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YarcheTextEditor
2 | It's a TextEditor for a list of similar lines. For example, for logs.
3 | You can:
4 |
5 | 1. Delete lines with certain word.
6 |
7 | Example: "aaa" "bbb" "ccc"
8 | if we will delete with word 'aa', we will get a following result: "bbb" "ccc"
9 |
10 | 2. Delete lines without certain word.
11 | example: "aaa" "bbb" "ccc"
12 | if we delete with word 'aa', we will get a following result: "aaa"
13 |
14 | 3. Take statistics on occurrences.
15 | example: "aaa" "bbb" "aaa" "ccc"
16 | result: "aaa=2" "bbb=1" "ccc=1"
17 |
--------------------------------------------------------------------------------
/Views/LoadFilePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 | using System.Windows.Controls;
3 | using YarcheTextEditor.Classes;
4 | using YarcheTextEditor.Models;
5 | using YarcheTextEditor.ViewModels;
6 |
7 | namespace YarcheTextEditor.Views
8 | {
9 | ///
10 | /// Логика взаимодействия для LoadFilePage.xaml
11 | ///
12 | public partial class LoadFilePage
13 | {
14 | public LoadFilePage()
15 | {
16 | InitializeComponent();
17 | }
18 |
19 | private void Grid_Drop(object sender, DragEventArgs e)
20 | {
21 |
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Views/WorkFilePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace YarcheTextEditor.Views
17 | {
18 | ///
19 | /// Логика взаимодействия для WorkFilePage.xaml
20 | ///
21 | public partial class WorkFilePage
22 | {
23 | public WorkFilePage()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Converters/MultiCommandParameterConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Data;
9 |
10 | namespace YarcheTextEditor.Converters
11 | {
12 | public class MultiCommandParameterConverter : IMultiValueConverter
13 | {
14 | object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
15 | {
16 | return values.ToArray();
17 | }
18 |
19 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
20 | {
21 | throw new NotImplementedException();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ViewModels/BaseViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.ComponentModel;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Windows.Controls;
9 | using YarcheTextEditor.Classes;
10 | using YarcheTextEditor.Models;
11 |
12 | namespace YarcheTextEditor.ViewModels
13 | {
14 | public class BaseViewModel : INotifyPropertyChanged
15 | {
16 | public BaseViewModel()
17 | {
18 |
19 | }
20 |
21 | public event PropertyChangedEventHandler PropertyChanged;
22 |
23 | protected virtual void OnPropertyChanged(string propertyName)
24 | {
25 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Converters/OddConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Data;
9 |
10 | namespace YarcheTextEditor.Converters
11 | {
12 | [ValueConversion(typeof(bool), typeof(string))]
13 | public class OddConverter : IValueConverter
14 | {
15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16 | {
17 | if ((int)value % 2 == 0) return "#ffffff";
18 | else return "#44008080";
19 | }
20 |
21 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
22 | {
23 | return DependencyProperty.UnsetValue;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ViewModels/LoadFileViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using YarcheTextEditor.Classes;
8 | using YarcheTextEditor.Models;
9 |
10 | namespace YarcheTextEditor.ViewModels
11 | {
12 | public class LoadFileViewModel : BaseViewModel
13 | {
14 | public ILanguage Language
15 | {
16 | get
17 | {
18 | return LanguageSettings.Language;
19 | }
20 | }
21 |
22 | public LoadFileViewModel()
23 | {
24 | LanguageSettings.LanguageChangedHandler += LanguageChangedHandler;
25 | }
26 |
27 | private void LanguageChangedHandler(object sender, LanguageEventArgs languageEventArgs)
28 | {
29 | OnPropertyChanged("Language");
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Converters/TextListWidthConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Data;
9 |
10 | namespace YarcheTextEditor.Converters
11 | {
12 | [ValueConversion(typeof(int), typeof(string))]
13 | public class TextListWidthConverter : IValueConverter
14 | {
15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16 | {
17 | var width = 0;
18 | Int32.TryParse(value.ToString(), out width);
19 | if (width > 30) width -= 30;
20 | return width;
21 | }
22 |
23 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
24 | {
25 | return DependencyProperty.UnsetValue;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ViewModels/WorkFileViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.ComponentModel;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Windows.Data;
9 | using YarcheTextEditor.Classes;
10 | using YarcheTextEditor.Models;
11 |
12 | namespace YarcheTextEditor.ViewModels
13 | {
14 | public class WorkFileViewModel : BaseViewModel
15 | {
16 | public static ObservableCollection TextCollection { get { return Collections.TextCollection; } }
17 |
18 | public WorkFileViewModel()
19 | {
20 |
21 | // Collections.TextCollectionChangedHandler += TextCollectionChangedHandler;
22 | }
23 |
24 | // private void TextCollectionChangedHandler(object sender, EventArgs EventArgs)
25 | // {
26 | // OnPropertyChanged("TextCollection");
27 | // }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Models/LanguageMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Reflection;
4 |
5 | namespace YarcheTextEditor.Models
6 | {
7 | public static class LanguageMethods
8 | {
9 | ///
10 | /// Get language object by language code
11 | ///
12 | ///
13 | ///
14 | public static ILanguage GetLanguage(string languageCode)
15 | {
16 | foreach (Type languageType in Assembly.GetExecutingAssembly().GetTypes().Where(languageType => languageType.GetInterfaces().Contains(typeof(ILanguage))))
17 | {
18 | object languageObject = Activator.CreateInstance(languageType);
19 | var language = languageObject as ILanguage;
20 | if (language.LanguageCode == languageCode) return language;
21 | }
22 |
23 | return new EnglishLanguage();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Commands/RelayCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 |
4 | namespace YarcheTextEditor.Commands
5 | {
6 | public class RelayCommand : ICommand
7 | {
8 | public event EventHandler CanExecuteChanged
9 | {
10 | add { CommandManager.RequerySuggested += value; }
11 | remove { CommandManager.RequerySuggested -= value; }
12 | }
13 | private Action methodToExecute;
14 | private Predicate canExecuteEvaluator;
15 | public RelayCommand(Action methodToExecute, Predicate canExecuteEvaluator)
16 | {
17 | this.methodToExecute = methodToExecute;
18 | this.canExecuteEvaluator = canExecuteEvaluator;
19 | }
20 |
21 | public bool CanExecute(object parameter)
22 | {
23 | return canExecuteEvaluator == null ? true : canExecuteEvaluator((T)parameter);
24 | }
25 | public void Execute(object parameter)
26 | {
27 | this.methodToExecute((T)parameter);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/YarcheTextEditor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YarcheTextEditor", "YarcheTextEditor.csproj", "{CBE51D97-25BF-4F73-A365-E8D4BD10DB06}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {CBE51D97-25BF-4F73-A365-E8D4BD10DB06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {CBE51D97-25BF-4F73-A365-E8D4BD10DB06}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {CBE51D97-25BF-4F73-A365-E8D4BD10DB06}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {CBE51D97-25BF-4F73-A365-E8D4BD10DB06}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/Classes/LanguageSettings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using YarcheTextEditor.Models;
7 |
8 | namespace YarcheTextEditor.Classes
9 | {
10 | public static class LanguageSettings
11 | {
12 | private static ILanguage _language { get; set; }
13 | public static ILanguage Language
14 | {
15 | get
16 | {
17 | return _language;
18 | }
19 | set
20 | {
21 | _language = value;
22 | RegistryMethods.SetLanguage(Language);
23 |
24 | var eventArgs = new LanguageEventArgs(Language);
25 | LanguageChangedHandler?.Invoke(null, eventArgs);
26 | }
27 | }
28 |
29 | public static EventHandler LanguageChangedHandler;
30 | }
31 |
32 | public class LanguageEventArgs : EventArgs
33 | {
34 | public ILanguage Language;
35 | public LanguageEventArgs(ILanguage language)
36 | {
37 | Language = language;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/App.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Dictionaries/ImagesDictionary.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 | /Images/back.png
6 | /Images/close.png
7 | /Images/download.png
8 | /Images/encoding.png
9 | /Images/exit.png
10 | /Images/forward.png
11 | /Images/open.png
12 | /Images/save.png
13 | /Images/more.png
14 | /Images/stat.png
15 | /Images/tool.png
16 |
17 | /Images/Countries/ru.png
18 | /Images/Countries/eng.png
19 |
20 |
--------------------------------------------------------------------------------
/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace YarcheTextEditor.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Classes/Collections.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows.Data;
8 | using YarcheTextEditor.Models;
9 |
10 | namespace YarcheTextEditor.Classes
11 | {
12 | public static class Collections
13 | {
14 | public static EventHandler TextCollectionChangedHandler;
15 | public static ObservableCollection TextCollection { get; set; }
16 | public static ObservableCollection BackCollection { get; set; }
17 | public static ObservableCollection ForwardCollection { get; set; }
18 |
19 | static Collections()
20 | {
21 | TextCollection = new ObservableCollection();
22 | BackCollection = new ObservableCollection();
23 | ForwardCollection = new ObservableCollection();
24 | }
25 |
26 |
27 |
28 | public static void TextCollectionChanged()
29 | {
30 | var eventArgs = new EventArgs();
31 | TextCollectionChangedHandler?.Invoke(null, eventArgs);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Views/LoadFilePage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Models/ILanguage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace YarcheTextEditor.Models
8 | {
9 | public interface ILanguage
10 | {
11 | ///
12 | /// Code to fast access
13 | ///
14 | string AllFiles { get; }
15 | string Close { get; }
16 | string Current { get; }
17 | string LanguageCode { get; }
18 | string DeleteEmptyLines { get; }
19 | string DragFile { get; }
20 | string Encoding { get; }
21 | string English { get; }
22 | string Exit { get; }
23 | string File { get; }
24 | string Open { get; }
25 | string Language { get; }
26 | string Russian { get; }
27 | string Save { get; }
28 | string SaveAs { get; }
29 | string Tools { get; }
30 | string OnlyOneFileSupported { get; }
31 | string YourEncoding { get; }
32 |
33 | string RemoveStringWithWordTool { get; }
34 | string RemoveStringWithOutWordTool { get; }
35 | string RemoveWordTool { get; }
36 | string ReplaceWordTool { get; }
37 | string StatisticsOnOccurrences { get; }
38 | string StatisticsOnOccurrencesWithWord { get; }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Commands/DelegateCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 |
4 | namespace YarcheTextEditor.Commands
5 | {
6 | public class DelegateCommand : ICommand
7 | {
8 | public event EventHandler CanExecuteChanged
9 | {
10 | add { CommandManager.RequerySuggested += value; }
11 | remove { CommandManager.RequerySuggested -= value; }
12 | }
13 | private Action methodToExecute;
14 | private Func canExecuteEvaluator;
15 | public DelegateCommand(Action methodToExecute, Func canExecuteEvaluator)
16 | {
17 | this.methodToExecute = methodToExecute;
18 | this.canExecuteEvaluator = canExecuteEvaluator;
19 | }
20 | public DelegateCommand(Action methodToExecute)
21 | : this(methodToExecute, null)
22 | {
23 | }
24 | public bool CanExecute(object parameter)
25 | {
26 | if (this.canExecuteEvaluator == null)
27 | {
28 | return true;
29 | }
30 | else
31 | {
32 | bool result = this.canExecuteEvaluator.Invoke();
33 | return result;
34 | }
35 | }
36 | public void Execute(object parameter)
37 | {
38 | this.methodToExecute.Invoke();
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Views/WorkFilePage.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Classes/RegistryMethods.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32;
2 | using System;
3 | using YarcheTextEditor.Models;
4 |
5 | namespace YarcheTextEditor.Classes
6 | {
7 | public static class RegistryMethods
8 | {
9 | ///
10 | /// Save chosen language for next start
11 | ///
12 | /// chosen language
13 | public static void SetLanguage(ILanguage language)
14 | {
15 | try
16 | {
17 | var hkcu = Registry.CurrentUser;
18 | RegistryKey settingsBranch = hkcu.OpenSubKey("Software\\YarcheTextEditor", true);
19 | settingsBranch.SetValue("Language", language.LanguageCode, RegistryValueKind.String);
20 |
21 | settingsBranch?.Close();
22 | hkcu?.Close();
23 | }
24 | catch (Exception ex)
25 | {
26 | Log.Instance.Error(1, ex.Message, "RegistryMethods");
27 | }
28 |
29 | }
30 |
31 | public static ILanguage GetLanguage()
32 | {
33 | ILanguage result = new EnglishLanguage();
34 |
35 | try
36 | {
37 | var hkcu = Registry.CurrentUser;
38 | RegistryKey settingsBranch = hkcu.OpenSubKey("Software\\YarcheTextEditor", true);
39 | if (settingsBranch == null)
40 | {
41 | hkcu.CreateSubKey("Software\\YarcheTextEditor");
42 | settingsBranch = hkcu.OpenSubKey("Software\\YarcheTextEditor", true);
43 | }
44 |
45 | var languageCode = settingsBranch.GetValue("Language", "en").ToString();
46 |
47 | settingsBranch?.Close();
48 | hkcu?.Close();
49 |
50 | result = LanguageMethods.GetLanguage(languageCode);
51 | }
52 | catch (Exception ex)
53 | {
54 | Log.Instance.Error(1, ex.Message, "RegistryMethods");
55 | }
56 |
57 | return result;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Models/EnglishLanguage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace YarcheTextEditor.Models
8 | {
9 | public class EnglishLanguage : ILanguage
10 | {
11 | public string AllFiles { get { return "All Files (*.*)|*.*"; } }
12 | public string LanguageCode { get { return "en"; } }
13 | public string Close { get { return "Close"; } }
14 | public string Current { get { return "Current"; } }
15 | public string DeleteEmptyLines { get { return "Delete empty lines"; } }
16 | public string DragFile { get { return "Drag text file here or press"; } }
17 | public string Encoding { get { return "Encoding"; } }
18 | public string English { get { return "English"; } }
19 | public string Exit { get { return "Exit"; } }
20 | public string File { get { return "File"; } }
21 | public string Language { get { return "Language"; } }
22 | public string OnlyOneFileSupported { get { return "Only one file is supported, drag and drop one file"; } }
23 | public string Open { get { return "Open"; } }
24 | public string Russian { get { return "Русский"; } }
25 | public string Save { get { return "Save"; } }
26 | public string SaveAs { get { return "Save as"; } }
27 | public string Tools { get { return "Tools"; } }
28 | public string YourEncoding { get { return "Your Encoding"; } }
29 | public string RemoveStringWithWordTool { get { return "Remove strings with certain word"; } }
30 | public string RemoveStringWithOutWordTool { get { return "Remove strings without certain word"; } }
31 | public string RemoveWordTool { get { return "Remove string"; } }
32 | public string ReplaceWordTool { get { return "Replace string by another string"; } }
33 | public string StatisticsOnOccurrences { get { return "Statistics on occurrences"; } }
34 | public string StatisticsOnOccurrencesWithWord { get { return "How many lines contain certain word"; } }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Models/RussianLanguage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace YarcheTextEditor.Models
8 | {
9 | public class RussianLanguage : ILanguage
10 | {
11 | public string AllFiles { get { return "Все файлы (*.*)|*.*"; } }
12 | public string LanguageCode { get { return "ru"; } }
13 | public string Close { get { return "Закрыть"; } }
14 | public string Current { get { return "Текущий"; } }
15 | public string DeleteEmptyLines { get { return "Удалить пустые строки"; } }
16 | public string DragFile { get { return "Перетащите текстовый файл сюда или нажмите"; } }
17 | public string Encoding { get { return "Кодировка"; } }
18 | public string English { get { return "English"; } }
19 | public string Exit { get { return "Выход"; } }
20 | public string File { get { return "Файл"; } }
21 | public string Language { get { return "Язык"; } }
22 | public string OnlyOneFileSupported { get { return "Поддерживается работа только с одним файлом, перетащите один файл"; } }
23 | public string Open { get { return "Открыть"; } }
24 | public string Russian { get { return "Русский"; } }
25 | public string Save { get { return "Сохранить"; } }
26 | public string SaveAs { get { return "Сохранить как"; } }
27 | public string Tools { get { return "Инструменты"; } }
28 | public string YourEncoding { get { return "Своя кодировка"; } }
29 | public string RemoveStringWithWordTool { get { return "Удалить строки с определенным словом"; } }
30 | public string RemoveStringWithOutWordTool { get { return "Удалить строки без определенного слова"; } }
31 | public string RemoveWordTool { get { return "Удалить строку"; } }
32 | public string ReplaceWordTool { get { return "Заменить строку другой строкой"; } }
33 | public string StatisticsOnOccurrences { get { return "Статистика по вхождениям"; } }
34 | public string StatisticsOnOccurrencesWithWord { get { return "Как много строк содержат слово"; } }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Classes/Log.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 |
5 | namespace YarcheTextEditor.Classes
6 | {
7 | public sealed class Log
8 | {
9 | private static volatile Log _instance;
10 | private static readonly object SyncRoot = new object();
11 | private readonly object _logLocker = new object();
12 |
13 | private Log()
14 | {
15 | CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
16 | LogDirectory = Path.Combine(CurrentDirectory, "log");
17 | }
18 |
19 | public string CurrentDirectory { get; set; }
20 | public string LogDirectory { get; set; }
21 |
22 | public static Log Instance
23 | {
24 | get
25 | {
26 | if (_instance == null)
27 | {
28 | lock (SyncRoot)
29 | {
30 | if (_instance == null) _instance = new Log();
31 | }
32 | }
33 | return _instance;
34 | }
35 | }
36 |
37 | public void Error(int errorNumber, string errorText, string owner)
38 | {
39 | // Ошибки пишем в лог всегда
40 | Add($"Ошибка {(errorNumber.ToString()).PadLeft(4, '0')}: {errorText}", "[ERROR]", owner);
41 | }
42 |
43 | public void Info(string log, string owner)
44 | {
45 | Add(log, "[INFO]", owner);
46 | }
47 |
48 | private void Add(string log, string logLevel, string owner)
49 | {
50 | lock (_logLocker)
51 | {
52 | try
53 | {
54 | if (!Directory.Exists(LogDirectory))
55 | {
56 | // creating log directory
57 | Directory.CreateDirectory(LogDirectory);
58 | }
59 | // write to log
60 | string newFileName = Path.Combine(LogDirectory, String.Format("{0}.txt", DateTime.Now.ToString("yyyyMMdd")));
61 | File.AppendAllText(newFileName, $"{DateTime.Now} {owner} {logLevel} {log} \r\n", Encoding.UTF8);
62 | }
63 | catch { }
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // Управление общими сведениями о сборке осуществляется с помощью
8 | // набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
9 | // связанные со сборкой.
10 | [assembly: AssemblyTitle("YarcheTextEditor")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("YarcheTextEditor")]
15 | [assembly: AssemblyCopyright("Copyright © 2020")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Параметр ComVisible со значением FALSE делает типы в сборке невидимыми
20 | // для COM-компонентов. Если требуется обратиться к типу в этой сборке через
21 | // COM, задайте атрибуту ComVisible значение TRUE для этого типа.
22 | [assembly: ComVisible(false)]
23 |
24 | //Чтобы начать сборку локализованных приложений, задайте
25 | //CultureYouAreCodingWith в файле .csproj
26 | //внутри . Например, если используется английский США
27 | //в своих исходных файлах установите в en-US. Затем отмените преобразование в комментарий
28 | //атрибута NeutralResourceLanguage ниже. Обновите "en-US" в
29 | //строка внизу для обеспечения соответствия настройки UICulture в файле проекта.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //где расположены словари ресурсов по конкретным тематикам
36 | //(используется, если ресурс не найден на странице
37 | // или в словарях ресурсов приложения)
38 | ResourceDictionaryLocation.SourceAssembly //где расположен словарь универсальных ресурсов
39 | //(используется, если ресурс не найден на странице,
40 | // в приложении или в каких-либо словарях ресурсов для конкретной темы)
41 | )]
42 |
43 |
44 | // Сведения о версии сборки состоят из следующих четырех значений:
45 | //
46 | // Основной номер версии
47 | // Дополнительный номер версии
48 | // Номер сборки
49 | // Редакция
50 | //
51 | // Можно задать все значения или принять номера сборки и редакции по умолчанию
52 | // используя "*", как показано ниже:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Этот код создан программным средством.
4 | // Версия среды выполнения: 4.0.30319.42000
5 | //
6 | // Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если
7 | // код создан повторно.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace YarcheTextEditor.Properties
12 | {
13 |
14 |
15 | ///
16 | /// Класс ресурсов со строгим типом для поиска локализованных строк и пр.
17 | ///
18 | // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder
19 | // класс с помощью таких средств, как ResGen или Visual Studio.
20 | // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen
21 | // с параметром /str или заново постройте свой VS-проект.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("YarcheTextEditor.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Переопределяет свойство CurrentUICulture текущего потока для всех
56 | /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Views/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/YarcheTextEditor.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {CBE51D97-25BF-4F73-A365-E8D4BD10DB06}
8 | WinExe
9 | Properties
10 | YarcheTextEditor
11 | YarcheTextEditor
12 | v4.5.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 4.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | MSBuild:Compile
56 | Designer
57 |
58 |
59 | MSBuild:Compile
60 | Designer
61 |
62 |
63 | Designer
64 | MSBuild:Compile
65 |
66 |
67 | Designer
68 | MSBuild:Compile
69 |
70 |
71 | Designer
72 | MSBuild:Compile
73 |
74 |
75 | MSBuild:Compile
76 | Designer
77 |
78 |
79 | App.xaml
80 | Code
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | LoadFilePage.xaml
99 |
100 |
101 | WorkFilePage.xaml
102 |
103 |
104 |
105 |
106 |
107 |
108 | MainWindow.xaml
109 | Code
110 |
111 |
112 |
113 |
114 | Code
115 |
116 |
117 | True
118 | True
119 | Resources.resx
120 |
121 |
122 | True
123 | Settings.settings
124 | True
125 |
126 |
127 | ResXFileCodeGenerator
128 | Resources.Designer.cs
129 |
130 |
131 | SettingsSingleFileGenerator
132 | Settings.Designer.cs
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
183 |
--------------------------------------------------------------------------------
/Dictionaries/StylesDictionary.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
68 |
69 |
102 |
103 |
141 |
142 |
191 |
192 |
217 |
218 |
252 |
253 |
266 |
267 |
284 |
285 |
292 |
293 |
299 |
300 |
--------------------------------------------------------------------------------
/ViewModels/MainViewModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Collections.ObjectModel;
5 | using System.ComponentModel;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows;
11 | using System.Windows.Controls;
12 | using System.Windows.Input;
13 | using YarcheTextEditor.Classes;
14 | using YarcheTextEditor.Commands;
15 | using YarcheTextEditor.Models;
16 |
17 | namespace YarcheTextEditor.ViewModels
18 | {
19 | public class MainViewModel : BaseViewModel
20 | {
21 | #region Commands
22 |
23 | #region Command Init
24 |
25 | public ICommand SetRussianCommand { get; set; }
26 | public ICommand SetEnglishCommand { get; set; }
27 | public ICommand CloseProgramCommand { get; set; }
28 | public ICommand RemoveStringWithWordCommand { get; set; }
29 | public ICommand RemoveStringWithOutWordCommand { get; set; }
30 | public ICommand StatisticsOnOccurrencesCommand { get; set; }
31 | public ICommand StatisticsOnOccurrencesWithWordCommand { get; set; }
32 | public ICommand FileOpenCommand { get; set; }
33 | public ICommand FileCloseCommand { get; set; }
34 | public ICommand FileSaveCommand { get; set; }
35 | public ICommand FileSaveAsCommand { get; set; }
36 | public ICommand EncodingMenuCommand { get; set; }
37 | public ICommand SetEncodingWin1251Command { get; set; }
38 | public ICommand SetEncodingUtf8Command { get; set; }
39 | public ICommand SetYourEncodingCommand { get; set; }
40 | public ICommand NavigationBackCommand { get; set; }
41 | public ICommand NavigationForwardCommand { get; set; }
42 | public ICommand DeleteEmptyLinesCommand { get; set; }
43 | public ICommand RemoveWordCommand { get; set; }
44 | public ICommand ReplaceWordCommand { get; set; }
45 |
46 | #endregion
47 |
48 | #region Commands - Methods
49 |
50 | public void SetRussianCommand_Execute()
51 | {
52 | Language = new RussianLanguage();
53 | AddMessageToUser($"Language changed to '{Language.LanguageCode}'");
54 | }
55 |
56 | public void SetEnglishCommand_Execute()
57 | {
58 | Language = new EnglishLanguage();
59 | AddMessageToUser($"Language changed to '{Language.LanguageCode}'");
60 | }
61 |
62 | public bool SetRussianCommand_CanExecute()
63 | {
64 | if (Language.GetType() == typeof(RussianLanguage)) return false;
65 | return true;
66 | }
67 |
68 | public bool SetEnglishCommand_CanExecute()
69 | {
70 | if (Language.GetType() == typeof(EnglishLanguage)) return false;
71 | return true;
72 | }
73 |
74 | public void CloseProgramCommand_Execute()
75 | {
76 | Application.Current.Shutdown();
77 | }
78 |
79 | public bool CloseProgramCommand_CanExecute()
80 | {
81 | return true;
82 | }
83 |
84 | public void EncodingMenuCommand_Execute()
85 | {
86 | }
87 |
88 | public bool EncodingMenuCommand_CanExecute()
89 | {
90 | return IsFileLoaded;
91 | }
92 |
93 | public void FileOpenCommand_Execute()
94 | {
95 | ChooseFile();
96 | }
97 |
98 | public bool FileOpenCommand_CanExecute()
99 | {
100 | return true;
101 | }
102 |
103 | public void SetEncodingWin1251Command_Execute()
104 | {
105 | _canBack = _canForward = false;
106 |
107 | _fileEncoding = Encoding.GetEncoding("Windows-1251");
108 | AddMessageToUser($"Set '{_fileEncoding.BodyName}' encoding");
109 | LoadFile(_pathToLoadedFile);
110 | }
111 |
112 | public bool SetEncodingWin1251Command_CanExecute()
113 | {
114 | if (IsFileLoaded && _fileEncoding != Encoding.GetEncoding("Windows-1251")) return true;
115 | return false;
116 | }
117 |
118 | public void SetEncodingUtf8Command_Execute()
119 | {
120 | _canBack = _canForward = false;
121 |
122 | _fileEncoding = Encoding.UTF8;
123 | AddMessageToUser($"Set '{_fileEncoding.BodyName}' encoding");
124 | LoadFile(_pathToLoadedFile);
125 | }
126 |
127 | public bool SetEncodingUtf8Command_CanExecute()
128 | {
129 | if (IsFileLoaded && _fileEncoding != Encoding.UTF8) return true;
130 | return false;
131 | }
132 |
133 | public void SetYourEncodingCommand_Execute(string encoding)
134 | {
135 | try
136 | {
137 | _canBack = _canForward = false;
138 |
139 | _fileEncoding = Encoding.GetEncoding(encoding);
140 | AddMessageToUser($"Set '{_fileEncoding.BodyName}' encoding");
141 | LoadFile(_pathToLoadedFile);
142 | }
143 | catch (Exception ex)
144 | {
145 | AddMessageToUser($"Failed to set '{encoding}' encoding: {ex.Message}");
146 | }
147 | }
148 |
149 | public bool SetYourEncodingCommand_CanExecute(string parameter)
150 | {
151 | return IsFileLoaded;
152 | }
153 |
154 | public void RemoveStringWithWordCommand_Execute(string word)
155 | {
156 | var enumerableCollection = from i in Collections.TextCollection where !i.Text.Contains(word) select i;
157 | var newCollection = new ObservableCollection(enumerableCollection);
158 |
159 | AddMessageToUser($"Used {Language.RemoveStringWithWordTool}, word='{word}'");
160 | ChangeTextCollection(newCollection);
161 | }
162 |
163 | public bool RemoveStringWithWordCommand_CanExecute(string parameter)
164 | {
165 | return IsFileLoaded;
166 | }
167 |
168 | public void RemoveWordCommand_Execute(string word)
169 | {
170 | var newCollection = new ObservableCollection();
171 | var index = 0;
172 | foreach (var stringElement in Collections.TextCollection)
173 | {
174 | index++;
175 | var line = stringElement.Text;
176 | var isContains = line.Contains(word);
177 | if (isContains)
178 | {
179 | line = line.Replace(word, "");
180 | }
181 | newCollection.Add(new StringElement() { Index = index, Text = line });
182 | }
183 |
184 | AddMessageToUser($"Used {Language.RemoveWordTool}, word='{word}'");
185 | ChangeTextCollection(newCollection);
186 | }
187 |
188 | public bool RemoveWordCommand_CanExecute(string parameter)
189 | {
190 | return IsFileLoaded;
191 | }
192 |
193 | public void ReplaceWordCommand_Execute(object[] parameters)
194 | {
195 | try
196 | {
197 | var word1 = parameters[0] as string;
198 | var word2 = parameters[1] as string;
199 |
200 | var newCollection = new ObservableCollection();
201 | var index = 0;
202 | foreach (var stringElement in Collections.TextCollection)
203 | {
204 | index++;
205 | var line = stringElement.Text;
206 | var isContains = line.Contains(word1);
207 | if (isContains)
208 | {
209 | line = line.Replace(word1, word2);
210 | }
211 | newCollection.Add(new StringElement() { Index = index, Text = line });
212 | }
213 |
214 | AddMessageToUser($"Used {Language.ReplaceWordTool}, word='{word1} to word='{word2}'");
215 | ChangeTextCollection(newCollection);
216 | }
217 | catch (Exception)
218 | {
219 | }
220 |
221 | }
222 |
223 | public bool ReplaceWordCommand_CanExecute(object[] parameters)
224 | {
225 | return true;
226 | }
227 |
228 | public void RemoveStringWithOutWordCommand_Execute(string word)
229 | {
230 | var enumerableCollection = from i in Collections.TextCollection where i.Text.Contains(word) select i;
231 | var newCollection = new ObservableCollection(enumerableCollection);
232 |
233 | AddMessageToUser($"Used {Language.RemoveStringWithOutWordTool}, word='{word}'");
234 | ChangeTextCollection(newCollection);
235 | }
236 |
237 | public bool RemoveStringWithOutWordCommand_CanExecute(string parameter)
238 | {
239 | return IsFileLoaded;
240 | }
241 |
242 | public void StatisticsOnOccurrencesCommand_Execute()
243 | {
244 | var newCollection = new ObservableCollection();
245 |
246 | // line -> number of occurrences
247 | var dict = new SortedList();
248 | foreach (var stringElement in Collections.TextCollection)
249 | {
250 | if (dict.ContainsKey(stringElement.Text)) dict[stringElement.Text]++;
251 | else dict[stringElement.Text] = 1;
252 | }
253 |
254 | var index = 0;
255 | foreach (KeyValuePair pair in dict.OrderByDescending(pair => pair.Value))
256 | {
257 | index++;
258 | newCollection.Add(new StringElement() { Index = index, Text = $"{pair.Key}={pair.Value}" });
259 | }
260 |
261 | AddMessageToUser($"Used {Language.StatisticsOnOccurrences}");
262 | ChangeTextCollection(newCollection);
263 | }
264 |
265 | public bool StatisticsOnOccurrencesCommand_CanExecute()
266 | {
267 | return IsFileLoaded;
268 | }
269 |
270 | public void StatisticsOnOccurrencesWithWordCommand_Execute(string word)
271 | {
272 | var newCollection = new ObservableCollection();
273 | var count = (from i in Collections.TextCollection where i.Text.Contains(word) select i).Count();
274 | newCollection.Add(new StringElement() { Index = 1, Text = $"{word}={count}" });
275 |
276 | AddMessageToUser($"Used {Language.StatisticsOnOccurrencesWithWord}, word='{word}'");
277 | ChangeTextCollection(newCollection);
278 | }
279 |
280 | public bool StatisticsOnOccurrencesWithWordCommand_CanExecute(string word)
281 | {
282 | return IsFileLoaded;
283 | }
284 |
285 | public void DeleteEmptyLinesCommand_Execute()
286 | {
287 | var enumerableCollection = from i in Collections.TextCollection where !string.IsNullOrWhiteSpace(i.Text) select i;
288 | var newCollection = new ObservableCollection(enumerableCollection);
289 |
290 | AddMessageToUser($"Used {Language.DeleteEmptyLines}");
291 | ChangeTextCollection(newCollection);
292 | }
293 |
294 | public bool DeleteEmptyLinesCommand_CanExecute()
295 | {
296 | return IsFileLoaded;
297 | }
298 |
299 | public void FileSaveCommand_Execute()
300 | {
301 | var lines = new List();
302 | foreach (var item in Collections.TextCollection)
303 | {
304 | lines.Add(item.Text);
305 | }
306 | File.WriteAllLines(_pathToLoadedFile, lines, _fileEncoding);
307 |
308 | AddMessageToUser($"Saved '{_pathToLoadedFile}' file");
309 | }
310 |
311 | public bool FileSaveCommand_CanExecute()
312 | {
313 | return IsFileLoaded;
314 | }
315 |
316 | public void NavigationBackCommand_Execute()
317 | {
318 | AddMessageToUser($"Navigation back");
319 | _canBack = false;
320 | _canForward = true;
321 | Collections.ForwardCollection.Clear();
322 | foreach (var item in Collections.TextCollection)
323 | {
324 | Collections.ForwardCollection.Add(item);
325 | }
326 | Collections.TextCollection.Clear();
327 | foreach (var item in Collections.BackCollection)
328 | {
329 | Collections.TextCollection.Add(item);
330 | }
331 | Collections.BackCollection.Clear();
332 | OnPropertyChanged("TextCollection");
333 | }
334 |
335 | public bool NavigationBackCommand_CanExecute()
336 | {
337 | return IsFileLoaded && _canBack;
338 | }
339 |
340 | public void NavigationForwardCommand_Execute()
341 | {
342 | AddMessageToUser($"Navigation forward");
343 | _canBack = true;
344 | _canForward = false;
345 | Collections.BackCollection.Clear();
346 | foreach (var item in Collections.TextCollection)
347 | {
348 | Collections.BackCollection.Add(item);
349 | }
350 | Collections.TextCollection.Clear();
351 | foreach (var item in Collections.ForwardCollection)
352 | {
353 | Collections.TextCollection.Add(item);
354 | }
355 | Collections.ForwardCollection.Clear();
356 | OnPropertyChanged("TextCollection");
357 | }
358 |
359 | public bool NavigationForwardCommand_CanExecute()
360 | {
361 | return IsFileLoaded && _canForward;
362 | }
363 |
364 | public void FileCloseCommand_Execute()
365 | {
366 | Collections.TextCollection.Clear();
367 |
368 | // MainWindow.LoadFileControl.Visibility = System.Windows.Visibility.Visible;
369 | // MainWindow.WorkFileControl.Visibility = System.Windows.Visibility.Collapsed;
370 |
371 | IsFileLoaded = false;
372 | OnPropertyChanged("TextCollection");
373 | OnPropertyChanged("IsFileLoaded");
374 |
375 | AddMessageToUser($"Closed '{_pathToLoadedFile}' file");
376 | }
377 |
378 | public bool FileCloseCommand_CanExecute()
379 | {
380 | return IsFileLoaded;
381 | }
382 |
383 | public void FileSaveAsCommand_Execute()
384 | {
385 | var chosenFile = string.Empty;
386 | try
387 | {
388 | var extension = Path.GetExtension(_pathToLoadedFile);
389 |
390 | var saveDialog = new SaveFileDialog();
391 | saveDialog.AddExtension = true;
392 | saveDialog.Filter = $"{Language.Current} ({extension})|*{extension}|{Language.AllFiles}";
393 | if (saveDialog.ShowDialog() == true)
394 | {
395 | chosenFile = saveDialog.FileName;
396 |
397 | var lines = new List();
398 | foreach (var item in Collections.TextCollection)
399 | {
400 | lines.Add(item.Text);
401 | }
402 |
403 | File.WriteAllLines(chosenFile, lines, _fileEncoding);
404 |
405 | AddMessageToUser($"Saved as '{chosenFile}' file");
406 |
407 | _pathToLoadedFile = chosenFile;
408 | }
409 | }
410 | catch (Exception ex)
411 | {
412 | AddMessageToUser($"Not saved as '{chosenFile}' file: {ex.Message}");
413 | }
414 |
415 | }
416 |
417 | public bool FileSaveAsCommand_CanExecute()
418 | {
419 | return IsFileLoaded;
420 | }
421 |
422 | #endregion
423 |
424 | #endregion
425 |
426 |
427 | private ObservableCollection _eventsCollection;
428 | public ObservableCollection EventsCollection { get { return new ObservableCollection(_eventsCollection.OrderByDescending(t => t.Time)); } set { _eventsCollection = value; } }
429 | public bool IsFileLoaded { get; set; }
430 | private string _pathToLoadedFile { get; set; }
431 | private Encoding _fileEncoding { get; set; }
432 | private bool _canBack;
433 | private bool _canForward;
434 |
435 | private BaseViewModel _selectedViewModel = new LoadFileViewModel();
436 | public BaseViewModel SelectedViewModel { get { return _selectedViewModel; } set { _selectedViewModel = value; } }
437 |
438 | public ILanguage Language
439 | {
440 | get
441 | {
442 | return LanguageSettings.Language;
443 | }
444 | set
445 | {
446 | LanguageSettings.Language = value;
447 | OnPropertyChanged("Language");
448 | }
449 | }
450 |
451 | public MainViewModel()
452 | {
453 | Language = RegistryMethods.GetLanguage();
454 | Collections.TextCollectionChangedHandler += TextCollectionChangedHandler;
455 |
456 |
457 | EventsCollection = new ObservableCollection();
458 |
459 | SetRussianCommand = new DelegateCommand(SetRussianCommand_Execute, SetRussianCommand_CanExecute);
460 | SetEnglishCommand = new DelegateCommand(SetEnglishCommand_Execute, SetEnglishCommand_CanExecute);
461 | CloseProgramCommand = new DelegateCommand(CloseProgramCommand_Execute, CloseProgramCommand_CanExecute);
462 | RemoveStringWithWordCommand = new RelayCommand(RemoveStringWithWordCommand_Execute, RemoveStringWithWordCommand_CanExecute);
463 | RemoveStringWithOutWordCommand = new RelayCommand(RemoveStringWithOutWordCommand_Execute, RemoveStringWithOutWordCommand_CanExecute);
464 | StatisticsOnOccurrencesCommand = new DelegateCommand(StatisticsOnOccurrencesCommand_Execute, StatisticsOnOccurrencesCommand_CanExecute);
465 | FileOpenCommand = new DelegateCommand(FileOpenCommand_Execute, FileOpenCommand_CanExecute);
466 | FileCloseCommand = new DelegateCommand(FileCloseCommand_Execute, FileCloseCommand_CanExecute);
467 | FileSaveCommand = new DelegateCommand(FileSaveCommand_Execute, FileSaveCommand_CanExecute);
468 | FileSaveAsCommand = new DelegateCommand(FileSaveAsCommand_Execute, FileSaveAsCommand_CanExecute);
469 | EncodingMenuCommand = new DelegateCommand(EncodingMenuCommand_Execute, EncodingMenuCommand_CanExecute);
470 | SetEncodingWin1251Command = new DelegateCommand(SetEncodingWin1251Command_Execute, SetEncodingWin1251Command_CanExecute);
471 | SetEncodingUtf8Command = new DelegateCommand(SetEncodingUtf8Command_Execute, SetEncodingUtf8Command_CanExecute);
472 | SetYourEncodingCommand = new RelayCommand(SetYourEncodingCommand_Execute, SetYourEncodingCommand_CanExecute);
473 | StatisticsOnOccurrencesWithWordCommand = new RelayCommand(StatisticsOnOccurrencesWithWordCommand_Execute, StatisticsOnOccurrencesWithWordCommand_CanExecute);
474 | NavigationBackCommand = new DelegateCommand(NavigationBackCommand_Execute, NavigationBackCommand_CanExecute);
475 | NavigationForwardCommand = new DelegateCommand(NavigationForwardCommand_Execute, NavigationForwardCommand_CanExecute);
476 | DeleteEmptyLinesCommand = new DelegateCommand(DeleteEmptyLinesCommand_Execute, DeleteEmptyLinesCommand_CanExecute);
477 | RemoveWordCommand = new RelayCommand(RemoveWordCommand_Execute, RemoveWordCommand_CanExecute);
478 | ReplaceWordCommand = new RelayCommand