├── .gitattributes
├── .gitignore
├── ModernNotepad.sln
├── ModernNotepad
├── App.xaml
├── App.xaml.cs
├── AssemblyInfo.cs
├── Behaviors
│ ├── PasteContentBehavior.cs
│ ├── PopupOpenedBehavior.cs
│ ├── SelectionChangedBehavior.cs
│ └── TextChangedBehavior.cs
├── Converters
│ ├── BaseConverter.cs
│ ├── BooleanToSelectedIndexConverter.cs
│ ├── BooleanToTextWrappingConverter.cs
│ └── StringToFontFamilyConverter.cs
├── CustomControls
│ ├── DialogWindow.cs
│ ├── TextArea.cs
│ └── TextContextMenuEx.cs
├── Fonts
│ └── SegMDL2.ttf
├── Images
│ ├── DarkTheme.png
│ ├── LightTheme.png
│ └── SplashScreen.png
├── Locales
│ ├── LocaleRepository.cs
│ ├── Strings_en-US.xaml
│ └── Strings_es-ES.xaml
├── ModernNotepad.csproj
├── ModernNotepad.ico
├── Program.cs
├── Services
│ ├── AdornerService.cs
│ ├── ApplicationThemeManager.cs
│ ├── ContentDialogService.cs
│ ├── LocaleManager.cs
│ ├── OpenFileDialogService.cs
│ ├── PrintService.cs
│ ├── SaveFileDialogService.cs
│ ├── SettingsManager.cs
│ └── WindowService.cs
├── Styles
│ ├── FluentStyle.xaml
│ └── TextAreaStyle.xaml
├── Util
│ ├── FontWrapper.cs
│ ├── HighlightCurrentLineAdorner.cs
│ ├── NativeMethods.cs
│ └── TextContextMenuExExtension.cs
├── Views
│ ├── AboutWindow.xaml
│ ├── AboutWindow.xaml.cs
│ ├── FindReplaceWindow.xaml
│ ├── FindReplaceWindow.xaml.cs
│ ├── FontSettingsWindow.xaml
│ ├── FontSettingsWindow.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── SettingsWindow.xaml
│ └── SettingsWindow.xaml.cs
└── app.manifest
├── ModernNotepadLibrary
├── Core
│ ├── IMainView.cs
│ ├── ITextArea.cs
│ ├── TextEditor.cs
│ └── UserSettings.cs
├── Helpers
│ ├── DelegateCommand.cs
│ ├── GenericDelegateCommand.cs
│ ├── ServiceResolver.cs
│ └── StringExtensions.cs
├── ModernNotepadLibrary.csproj
├── Services
│ ├── IAdornerService.cs
│ ├── IApplicationThemeManager.cs
│ ├── IContentDialogService.cs
│ ├── ILocaleManager.cs
│ ├── IOpenFileService.cs
│ ├── IPrintService.cs
│ ├── ISaveFileService.cs
│ ├── ISettingsManager.cs
│ └── IWindowService.cs
└── ViewModels
│ ├── AboutViewModel.cs
│ ├── BaseViewModel.cs
│ ├── FindReplaceViewModel.cs
│ ├── FontSettingsViewModel.cs
│ ├── MainViewModel.cs
│ └── SettingsViewModel.cs
├── README.md
├── _config.yml
└── _layouts
└── default.html
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/ModernNotepad.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29806.167
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernNotepad", "ModernNotepad\ModernNotepad.csproj", "{0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModernNotepadLibrary", "ModernNotepadLibrary\ModernNotepadLibrary.csproj", "{DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|ARM = Debug|ARM
14 | Debug|ARM64 = Debug|ARM64
15 | Debug|x64 = Debug|x64
16 | Debug|x86 = Debug|x86
17 | Release|Any CPU = Release|Any CPU
18 | Release|ARM = Release|ARM
19 | Release|ARM64 = Release|ARM64
20 | Release|x64 = Release|x64
21 | Release|x86 = Release|x86
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|ARM.ActiveCfg = Debug|Any CPU
27 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|ARM.Build.0 = Debug|Any CPU
28 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|ARM64.ActiveCfg = Debug|Any CPU
29 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|ARM64.Build.0 = Debug|Any CPU
30 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|x64.ActiveCfg = Debug|Any CPU
31 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|x64.Build.0 = Debug|Any CPU
32 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|x86.ActiveCfg = Debug|Any CPU
33 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Debug|x86.Build.0 = Debug|Any CPU
34 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|ARM.ActiveCfg = Release|Any CPU
37 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|ARM.Build.0 = Release|Any CPU
38 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|ARM64.ActiveCfg = Release|Any CPU
39 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|ARM64.Build.0 = Release|Any CPU
40 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|x64.ActiveCfg = Release|x64
41 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|x64.Build.0 = Release|x64
42 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|x86.ActiveCfg = Release|x86
43 | {0B743CA4-B9B8-4FB0-8188-B0F2198A3B39}.Release|x86.Build.0 = Release|x86
44 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|ARM.ActiveCfg = Debug|Any CPU
47 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|ARM.Build.0 = Debug|Any CPU
48 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|ARM64.ActiveCfg = Debug|Any CPU
49 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|ARM64.Build.0 = Debug|Any CPU
50 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|x64.ActiveCfg = Debug|Any CPU
51 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|x64.Build.0 = Debug|Any CPU
52 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|x86.ActiveCfg = Debug|Any CPU
53 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Debug|x86.Build.0 = Debug|Any CPU
54 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|ARM.ActiveCfg = Release|Any CPU
57 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|ARM.Build.0 = Release|Any CPU
58 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|ARM64.ActiveCfg = Release|Any CPU
59 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|ARM64.Build.0 = Release|Any CPU
60 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|x64.ActiveCfg = Release|x64
61 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|x64.Build.0 = Release|x64
62 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|x86.ActiveCfg = Release|x86
63 | {DA374DDA-0EB1-49FD-94EB-BEF7DB619FB2}.Release|x86.Build.0 = Release|x86
64 | EndGlobalSection
65 | GlobalSection(SolutionProperties) = preSolution
66 | HideSolutionNode = FALSE
67 | EndGlobalSection
68 | GlobalSection(ExtensibilityGlobals) = postSolution
69 | SolutionGuid = {B11D39AF-791C-487C-B2DD-BCC114F37CA8}
70 | EndGlobalSection
71 | EndGlobal
72 |
--------------------------------------------------------------------------------
/ModernNotepad/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 | True
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/ModernNotepad/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using ModernNotepad.Util;
2 | using ModernNotepadLibrary.ViewModels;
3 | using System;
4 | using System.ComponentModel;
5 | using System.Globalization;
6 | using System.IO;
7 | using System.Text;
8 | using System.Windows;
9 | using System.Windows.Threading;
10 |
11 | namespace ModernNotepad
12 | {
13 | public partial class App : Application
14 | {
15 | public MainViewModel MainViewModel { get; }
16 |
17 | public App() => MainViewModel = (MainViewModel)Program.ServiceResolver.Create();
18 |
19 | protected override void OnStartup(StartupEventArgs e)
20 | {
21 | base.OnStartup(e);
22 | var mainWindow = MainViewModel.WindowService.CreateMainView(MainViewModel, typeof(MainViewModel));
23 | MainViewModel.TextEditor.TextArea = mainWindow.TextArea;
24 |
25 | if (!Directory.Exists(MainViewModel.SettingsManager.SettingsDirectoryPath))
26 | {
27 | MainViewModel.SettingsManager.SaveSettings(MainViewModel.SettingsViewModel.UserSettings);
28 | }
29 | ApplySettings(MainViewModel);
30 | LoadLocale(MainViewModel);
31 | MainViewModel.Title = MainViewModel.LocaleManager.LoadString("AppTitle");
32 | MainViewModel.FilePath = MainViewModel.LocaleManager.LoadString("NewDocument");
33 |
34 | if (e.Args.Length > 0)
35 | {
36 | MainViewModel.TextEditor.SavedAsFile = true;
37 | MainViewModel.Title = Path.GetFileName(e.Args[0]);
38 | MainViewModel.FilePath = Path.GetFullPath(e.Args[0]);
39 | MainViewModel.TextEditor.TextArea.Text = File.ReadAllText(e.Args[0], Encoding.Default);
40 | MainViewModel.SaveFileService.FileName = e.Args[0];
41 | }
42 | }
43 |
44 | private void ApplySettings(MainViewModel MainViewModel)
45 | {
46 | MainViewModel.SettingsViewModel.IsDarkThemeEnabled = MainViewModel.SettingsManager.LoadSettings().IsDarkThemeEnabled;
47 | MainViewModel.SettingsViewModel.IsSpellCheckingEnabled = MainViewModel.SettingsManager.LoadSettings().IsSpellCheckingEnabled;
48 | MainViewModel.SettingsViewModel.IsStatusBarVisible = MainViewModel.SettingsManager.LoadSettings().IsStatusBarVisible;
49 | MainViewModel.SettingsViewModel.IsWordWrapEnabled = MainViewModel.SettingsManager.LoadSettings().IsWordWrapEnabled;
50 | MainViewModel.ThemeManager.ChangeTheme(MainViewModel.SettingsViewModel.IsDarkThemeEnabled);
51 | }
52 |
53 | private void LoadLocale(MainViewModel MainViewModel)
54 | {
55 | try
56 | {
57 | MainViewModel.LocaleManager.LoadStringResource(CultureInfo.CurrentUICulture.Name);
58 | }
59 | catch (Exception)
60 | {
61 | MainViewModel.LocaleManager.LoadStringResource("en-US");
62 | }
63 | }
64 |
65 | private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
66 | {
67 | WriteLogFile(e.Exception.ToString());
68 | const long MB_OK = 0x0L, MB_ERROR = 0x10L;
69 | var message = MainViewModel.LocaleManager.LoadString("ErrorMessage");
70 | NativeMethods.MessageBox(IntPtr.Zero, message, "Modern Notepad", (uint)(MB_OK | MB_ERROR));
71 | e.Handled = true;
72 | Current.Shutdown();
73 | }
74 |
75 | private void WriteLogFile(string message)
76 | {
77 | var logPath = @$"{Directory.GetCurrentDirectory()}\error.log";
78 | File.WriteAllText(logPath, message);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/ModernNotepad/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | [assembly: ThemeInfo(
4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5 | //(used if a resource is not found in the page,
6 | // or application resource dictionaries)
7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8 | //(used if a resource is not found in the page,
9 | // app, or any theme specific resource dictionaries)
10 | )]
11 |
--------------------------------------------------------------------------------
/ModernNotepad/Behaviors/PasteContentBehavior.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xaml.Behaviors;
2 | using ModernNotepadLibrary.ViewModels;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 |
6 | namespace ModernNotepad.Behaviors
7 | {
8 | class PasteContentBehavior : Behavior
9 | {
10 | protected override void OnAttached()
11 | {
12 | base.OnAttached();
13 | DataObject.AddPastingHandler(AssociatedObject, OnPaste);
14 | }
15 |
16 | protected override void OnDetaching()
17 | {
18 | base.OnDetaching();
19 | DataObject.RemovePastingHandler(AssociatedObject, OnPaste);
20 | }
21 |
22 | private void OnPaste(object sender, DataObjectPastingEventArgs e)
23 | {
24 | if (e.DataObject.GetDataPresent(DataFormats.Text, true) ||
25 | e.DataObject.GetDataPresent(DataFormats.UnicodeText, true))
26 | {
27 | var viewModel = Application.Current.MainWindow.DataContext as MainViewModel;
28 | viewModel.Title = $"*{viewModel.Title.Replace("*", "")}";
29 | viewModel.TextEditor.UnsavedChanges = true;
30 | //AssociatedObject.InvalidateVisual();
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ModernNotepad/Behaviors/PopupOpenedBehavior.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xaml.Behaviors;
2 | using System;
3 | using System.Threading.Tasks;
4 | using System.Windows;
5 | using System.Windows.Controls;
6 | using System.Windows.Controls.Primitives;
7 |
8 | namespace ModernNotepad.Behaviors
9 | {
10 | class PopupOpenedBehavior : Behavior
11 | {
12 | protected override void OnAttached()
13 | {
14 | base.OnAttached();
15 | AssociatedObject.Opened += OnPopupOpened;
16 | }
17 |
18 | protected override void OnDetaching()
19 | {
20 | base.OnDetaching();
21 | AssociatedObject.Opened -= OnPopupOpened;
22 | }
23 |
24 | private async void OnPopupOpened(object sender, EventArgs e)
25 | {
26 | var child = (Border)AssociatedObject.Child;
27 | AssociatedObject.HorizontalOffset = (Application.Current.MainWindow.ActualWidth - child.ActualWidth) / 2;
28 | AssociatedObject.VerticalOffset = -100.0;
29 |
30 | await Task.Delay(2000);
31 | AssociatedObject.IsOpen = false;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ModernNotepad/Behaviors/SelectionChangedBehavior.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xaml.Behaviors;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 |
5 | namespace ModernNotepad.Behaviors
6 | {
7 | class SelectionChangedBehavior : Behavior
8 | {
9 | public static readonly DependencyProperty CurrentCharacterProperty =
10 | DependencyProperty.Register("CurrentCharacter", typeof(string), typeof(SelectionChangedBehavior), new PropertyMetadata(null));
11 |
12 | public string CurrentCharacter
13 | {
14 | get => (string)GetValue(CurrentCharacterProperty);
15 | set => SetValue(CurrentCharacterProperty, value);
16 | }
17 |
18 | public static readonly DependencyProperty CurrentLineProperty =
19 | DependencyProperty.Register("CurrentLine", typeof(string), typeof(SelectionChangedBehavior), new PropertyMetadata(null));
20 |
21 | public string CurrentLine
22 | {
23 | get => (string)GetValue(CurrentLineProperty);
24 | set => SetValue(CurrentLineProperty, value);
25 | }
26 |
27 | protected override void OnAttached()
28 | {
29 | base.OnAttached();
30 | AssociatedObject.SelectionChanged += OnSelectionChanged;
31 | }
32 |
33 | protected override void OnDetaching()
34 | {
35 | base.OnDetaching();
36 | AssociatedObject.SelectionChanged -= OnSelectionChanged;
37 | }
38 |
39 | private void OnSelectionChanged(object sender, RoutedEventArgs e)
40 | {
41 | var currentLine = AssociatedObject.GetLineIndexFromCharacterIndex(AssociatedObject.CaretIndex) + 1;
42 | CurrentLine = $"{Application.Current.TryFindResource("CurrentLine")}: {currentLine}";
43 |
44 | var firstCharIndex = AssociatedObject.GetCharacterIndexFromLineIndex(currentLine - 1);
45 | var currentCharacter = AssociatedObject.CaretIndex - firstCharIndex + 1;
46 | CurrentCharacter = $"{Application.Current.TryFindResource("CurrentChar")}: {currentCharacter}";
47 |
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ModernNotepad/Behaviors/TextChangedBehavior.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xaml.Behaviors;
2 | using ModernNotepadLibrary.ViewModels;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 | using System.Linq;
6 |
7 | namespace ModernNotepad.Behaviors
8 | {
9 | class TextChangedBehavior : Behavior
10 | {
11 | protected override void OnAttached()
12 | {
13 | base.OnAttached();
14 | AssociatedObject.TextChanged += OnTextChanged;
15 | }
16 |
17 | protected override void OnDetaching()
18 | {
19 | base.OnDetaching();
20 | AssociatedObject.TextChanged -= OnTextChanged;
21 | }
22 |
23 | private void OnTextChanged(object sender, TextChangedEventArgs e)
24 | {
25 | var viewModel = Application.Current.MainWindow.DataContext as MainViewModel;
26 | var editor = viewModel.TextEditor;
27 | var textArea = editor.TextArea;
28 |
29 | if ((!editor.SavedAsFile && e.Changes.FirstOrDefault().AddedLength > 0) ||
30 | e.Changes.FirstOrDefault().AddedLength != textArea.Text.Length ||
31 | e.Changes.FirstOrDefault().RemovedLength > 0)
32 | {
33 | viewModel.Title = $"*{viewModel.Title.Replace("*", "")}";
34 | viewModel.TextEditor.UnsavedChanges = true;
35 | }
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/ModernNotepad/Converters/BaseConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Windows.Data;
4 |
5 | namespace ModernNotepad.Converters
6 | {
7 | class BaseConverter : IValueConverter
8 | {
9 | public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | => Binding.DoNothing;
11 |
12 | public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
13 | => Binding.DoNothing;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ModernNotepad/Converters/BooleanToSelectedIndexConverter.cs:
--------------------------------------------------------------------------------
1 | using ModernWpf;
2 | using System;
3 | using System.Globalization;
4 |
5 | namespace ModernNotepad.Converters
6 | {
7 | class BooleanToSelectedIndexConverter : BaseConverter
8 | {
9 | public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | => ((bool?)value) switch
11 | {
12 | false => (int)ApplicationTheme.Light,
13 | true => (int)ApplicationTheme.Dark,
14 | null => Enum.GetValues(typeof(ApplicationTheme)).Length,
15 | };
16 |
17 | public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18 | => ((int)value) switch
19 | {
20 | (int)ApplicationTheme.Light => false,
21 | (int)ApplicationTheme.Dark => true,
22 | _ => null,
23 | };
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ModernNotepad/Converters/BooleanToTextWrappingConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Windows;
4 |
5 | namespace ModernNotepad.Converters
6 | {
7 | class BooleanToTextWrappingConverter : BaseConverter
8 | {
9 | public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | if (value != null)
12 | {
13 | var isTextWrappingEnabled = (bool)value;
14 | return isTextWrappingEnabled ? TextWrapping.Wrap : TextWrapping.NoWrap;
15 | }
16 | return TextWrapping.NoWrap;
17 | }
18 |
19 | public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20 | {
21 | if (value != null)
22 | {
23 | var textWrapping = (TextWrapping)value;
24 | return textWrapping == TextWrapping.Wrap;
25 | }
26 | return false;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ModernNotepad/Converters/StringToFontFamilyConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Windows.Media;
4 |
5 | namespace ModernNotepad.Converters
6 | {
7 | class StringToFontFamilyConverter : BaseConverter
8 | {
9 | public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | if (value != null)
12 | {
13 | var fontFamilyName = value.ToString();
14 | return new FontFamily(fontFamilyName);
15 | }
16 | return null;
17 | }
18 |
19 | public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20 | {
21 | if (value != null)
22 | {
23 | var fontFamily = value as FontFamily;
24 | return fontFamily.Source;
25 | }
26 | return null;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ModernNotepad/CustomControls/DialogWindow.cs:
--------------------------------------------------------------------------------
1 | using ModernNotepad.Util;
2 | using System;
3 | using System.Windows;
4 | using System.Windows.Interop;
5 |
6 | namespace ModernNotepad.CustomControls
7 | {
8 | ///
9 | /// Child window with a custom system menu.
10 | ///
11 | public class DialogWindow : Window
12 | {
13 | protected override void OnSourceInitialized(EventArgs e)
14 | {
15 | base.OnSourceInitialized(e);
16 | var hwnd = new WindowInteropHelper(this).Handle;
17 | var hSystemMenu = NativeMethods.GetSystemMenu(hwnd, false);
18 | NativeMethods.DeleteMenu(hSystemMenu, 0, NativeMethods.MF_BYPOSITION);
19 | NativeMethods.DeleteMenu(hSystemMenu, 1, NativeMethods.MF_BYPOSITION);
20 | NativeMethods.DeleteMenu(hSystemMenu, 1, NativeMethods.MF_BYPOSITION);
21 | NativeMethods.DeleteMenu(hSystemMenu, 1, NativeMethods.MF_BYPOSITION);
22 | NativeMethods.DeleteMenu(hSystemMenu, 1, NativeMethods.MF_BYPOSITION);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ModernNotepad/CustomControls/TextArea.cs:
--------------------------------------------------------------------------------
1 | using ModernNotepad.Util;
2 | using ModernNotepadLibrary.Core;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 | using System.Windows.Media;
6 |
7 | namespace ModernNotepad.CustomControls
8 | {
9 | ///
10 | /// Represents a multiline TextBox.
11 | ///
12 | public class TextArea : TextBox, ITextArea
13 | {
14 | public TextArea()
15 | {
16 | AcceptsReturn = true;
17 | AcceptsTab = true;
18 | Loaded += TextArea_Loaded;
19 | }
20 |
21 | public HighlightCurrentLineAdorner HighlightCurrentLineAdorner { get; private set; }
22 |
23 | public void SetFontFamily(string fontFamilyName) => FontFamily = new FontFamily(fontFamilyName);
24 |
25 | private void TextArea_Loaded(object sender, RoutedEventArgs e)
26 | {
27 | HighlightCurrentLineAdorner = new HighlightCurrentLineAdorner(this);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ModernNotepad/CustomControls/TextContextMenuEx.cs:
--------------------------------------------------------------------------------
1 | using ModernWpf.Controls;
2 | using ModernWpf.Controls.Primitives;
3 | using System.Globalization;
4 | using System.Linq;
5 | using System.Windows;
6 | using System.Windows.Controls;
7 | using System.Windows.Controls.Primitives;
8 | using System.Windows.Documents;
9 | using System.Windows.Input;
10 |
11 | namespace ModernNotepad.CustomControls
12 | {
13 | public class TextContextMenuEx : ContextMenu
14 | {
15 | private static readonly CommandBinding selectAllBinding;
16 | private static readonly CommandBinding deleteBinding;
17 | private static readonly CommandBinding undoBinding;
18 | private static readonly CommandBinding redoBinding;
19 |
20 | private readonly MenuItem proofingMenuItem;
21 |
22 | static TextContextMenuEx()
23 | {
24 | DefaultStyleKeyProperty.OverrideMetadata(typeof(TextContextMenuEx), new FrameworkPropertyMetadata(typeof(TextContextMenuEx)));
25 |
26 | selectAllBinding = new CommandBinding(ApplicationCommands.SelectAll);
27 | selectAllBinding.PreviewCanExecute += OnSelectAllPreviewCanExecute;
28 |
29 | deleteBinding = new CommandBinding(EditingCommands.Delete);
30 | deleteBinding.PreviewCanExecute += OnDeletePreviewCanExecute;
31 |
32 | undoBinding = new CommandBinding(ApplicationCommands.Undo);
33 | undoBinding.PreviewCanExecute += OnUndoRedoPreviewCanExecute;
34 |
35 | redoBinding = new CommandBinding(ApplicationCommands.Redo);
36 | redoBinding.PreviewCanExecute += OnUndoRedoPreviewCanExecute;
37 | }
38 |
39 | ///
40 | /// Initializes a new instance of the TextContextMenuEx class.
41 | ///
42 | public TextContextMenuEx()
43 | {
44 | proofingMenuItem = new MenuItem();
45 | Items.Add(proofingMenuItem);
46 | Items.Add(new MenuItem
47 | {
48 | Command = ApplicationCommands.Cut,
49 | Icon = new SymbolIcon(Symbol.Cut)
50 | });
51 | Items.Add(new MenuItem
52 | {
53 | Command = ApplicationCommands.Copy,
54 | Icon = new SymbolIcon(Symbol.Copy)
55 | });
56 | Items.Add(new MenuItem
57 | {
58 | Command = ApplicationCommands.Paste,
59 | Icon = new SymbolIcon(Symbol.Paste)
60 | });
61 | Items.Add(new MenuItem
62 | {
63 | Command = ApplicationCommands.Undo,
64 | Icon = new SymbolIcon(Symbol.Undo)
65 | });
66 | Items.Add(new MenuItem
67 | {
68 | Command = ApplicationCommands.Redo,
69 | Icon = new SymbolIcon(Symbol.Redo)
70 | });
71 | Items.Add(new MenuItem
72 | {
73 | Command = EditingCommands.Delete,
74 | Icon = new SymbolIcon(Symbol.ClearSelection)
75 | });
76 | Items.Add(new MenuItem
77 | {
78 | Command = ApplicationCommands.SelectAll,
79 | Icon = new SymbolIcon(Symbol.SelectAll),
80 | InputGestureText = GetDisplayStringForSelectAll()
81 | });
82 | }
83 |
84 | #region UsingTextContextMenu
85 |
86 | public static readonly DependencyProperty UsingTextContextMenuExProperty =
87 | DependencyProperty.RegisterAttached(
88 | "UsingTextContextMenuEx",
89 | typeof(bool),
90 | typeof(TextContextMenuEx),
91 | new PropertyMetadata(false, OnUsingTextContextMenuExChanged));
92 |
93 | public static bool GetUsingTextContextMenuEx(Control textControl)
94 | => (bool)textControl.GetValue(UsingTextContextMenuExProperty);
95 |
96 | public static void SetUsingTextContextMenuEx(Control textControl, bool value)
97 | => textControl.SetValue(UsingTextContextMenuExProperty, value);
98 |
99 | private static void OnUsingTextContextMenuExChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
100 | {
101 | var textControl = (Control)d;
102 |
103 | if ((bool)e.NewValue)
104 | {
105 | textControl.CommandBindings.Add(selectAllBinding);
106 | textControl.CommandBindings.Add(deleteBinding);
107 | textControl.CommandBindings.Add(undoBinding);
108 | textControl.CommandBindings.Add(redoBinding);
109 | textControl.ContextMenuOpening += OnContextMenuOpening;
110 | }
111 | else
112 | {
113 | textControl.CommandBindings.Remove(selectAllBinding);
114 | textControl.CommandBindings.Remove(deleteBinding);
115 | textControl.CommandBindings.Remove(undoBinding);
116 | textControl.CommandBindings.Remove(redoBinding);
117 | textControl.ContextMenuOpening -= OnContextMenuOpening;
118 | }
119 | }
120 |
121 | #endregion
122 |
123 | protected override void OnOpened(RoutedEventArgs e)
124 | {
125 | base.OnOpened(e);
126 | if (proofingMenuItem.IsVisible)
127 | {
128 | proofingMenuItem.IsSubmenuOpen = true;
129 | }
130 | }
131 |
132 | protected override void OnClosed(RoutedEventArgs e)
133 | {
134 | base.OnClosed(e);
135 | if (!IsOpen)
136 | {
137 | proofingMenuItem.Items.Clear();
138 |
139 | foreach (MenuItem menuItem in Items)
140 | {
141 | menuItem.ClearValue(MenuItem.CommandTargetProperty);
142 | }
143 | }
144 | }
145 |
146 | private static void OnSelectAllPreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
147 | {
148 | if (sender is TextBox textBox &&
149 | (string.IsNullOrEmpty(textBox.Text) || textBox.SelectionLength >= textBox.Text.Length))
150 | {
151 | e.CanExecute = false;
152 | e.Handled = true;
153 | }
154 | else if (sender is PasswordBox passwordBox && string.IsNullOrEmpty(passwordBox.Password))
155 | {
156 | e.CanExecute = false;
157 | e.Handled = true;
158 | }
159 | }
160 |
161 | private static void OnDeletePreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
162 | {
163 | if (sender is TextBox textBox && string.IsNullOrEmpty(textBox.Text))
164 | {
165 | e.CanExecute = false;
166 | e.Handled = true;
167 | }
168 | else if (sender is PasswordBox passwordBox && string.IsNullOrEmpty(passwordBox.Password))
169 | {
170 | e.CanExecute = false;
171 | e.Handled = true;
172 | }
173 | }
174 |
175 | private static void OnUndoRedoPreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
176 | {
177 | if (sender is TextBoxBase textBoxBase && textBoxBase.IsReadOnly)
178 | {
179 | e.CanExecute = false;
180 | e.Handled = true;
181 | }
182 | }
183 |
184 | private static void OnContextMenuOpening(object sender, ContextMenuEventArgs e)
185 | {
186 | var textControl = (Control)sender;
187 |
188 | if (textControl.ContextMenu is TextContextMenuEx contextMenu)
189 | {
190 | Control target;
191 |
192 | if (textControl is PasswordBox passwordBox &&
193 | PasswordBoxHelper.GetPasswordRevealMode(passwordBox) == PasswordRevealMode.Visible &&
194 | e.Source is TextBox)
195 | {
196 | target = (Control)e.Source;
197 | }
198 | else
199 | {
200 | target = textControl;
201 | }
202 | contextMenu.UpdateItems(target);
203 | bool hasVisibleItems = contextMenu.Items.OfType