├── .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().Any(mi => mi.Visibility == Visibility.Visible); 204 | 205 | if (!hasVisibleItems) 206 | { 207 | e.Handled = true; 208 | } 209 | } 210 | } 211 | 212 | private void UpdateProofingMenuItem(Control target) 213 | { 214 | proofingMenuItem.Header = Application.Current.TryFindResource("Proofing"); 215 | proofingMenuItem.Items.Clear(); 216 | 217 | SpellingError spellingError = null; 218 | 219 | if (target is TextBox textBox) 220 | { 221 | spellingError = textBox.GetSpellingError(textBox.CaretIndex); 222 | } 223 | else if (target is RichTextBox richTextBox) 224 | { 225 | spellingError = richTextBox.GetSpellingError(richTextBox.CaretPosition); 226 | } 227 | 228 | if (spellingError != null) 229 | { 230 | foreach (string suggestion in spellingError.Suggestions) 231 | { 232 | var menuItem = new MenuItem 233 | { 234 | Header = suggestion, 235 | Command = EditingCommands.CorrectSpellingError, 236 | CommandParameter = suggestion, 237 | CommandTarget = target 238 | }; 239 | proofingMenuItem.Items.Add(menuItem); 240 | } 241 | if (proofingMenuItem.HasItems) 242 | { 243 | proofingMenuItem.Items.Add(new Separator()); 244 | } 245 | proofingMenuItem.Items.Add(new MenuItem 246 | { 247 | Header = Application.Current.TryFindResource("Ignore"), 248 | Command = EditingCommands.IgnoreSpellingError, 249 | CommandTarget = target 250 | }); 251 | proofingMenuItem.Visibility = Visibility.Visible; 252 | } 253 | else 254 | { 255 | proofingMenuItem.Visibility = Visibility.Collapsed; 256 | } 257 | } 258 | 259 | private void UpdateItems(Control target) 260 | { 261 | UpdateProofingMenuItem(target); 262 | 263 | foreach (MenuItem menuItem in Items) 264 | { 265 | if (menuItem.Command is RoutedUICommand command) 266 | { 267 | if (command == ApplicationCommands.Cut) 268 | { 269 | menuItem.Header = Application.Current.TryFindResource("Cut"); 270 | } 271 | else if (command == ApplicationCommands.Copy) 272 | { 273 | menuItem.Header = Application.Current.TryFindResource("Copy"); 274 | } 275 | else if (command == ApplicationCommands.Paste) 276 | { 277 | menuItem.Header = Application.Current.TryFindResource("Paste"); 278 | } 279 | else if (command == ApplicationCommands.Undo) 280 | { 281 | menuItem.Header = Application.Current.TryFindResource("Undo"); 282 | } 283 | else if (command == ApplicationCommands.Redo) 284 | { 285 | menuItem.Header = Application.Current.TryFindResource("Redo"); 286 | } 287 | else if (command == EditingCommands.Delete) 288 | { 289 | menuItem.Header = Application.Current.TryFindResource("Delete"); 290 | } 291 | else if (command == ApplicationCommands.SelectAll) 292 | { 293 | menuItem.Header = Application.Current.TryFindResource("SelectAll"); 294 | } 295 | menuItem.CommandTarget = target; 296 | menuItem.Visibility = command.CanExecute(null, target) ? Visibility.Visible : Visibility.Collapsed; 297 | } 298 | } 299 | } 300 | 301 | private string GetDisplayStringForSelectAll() => CultureInfo.CurrentUICulture.Name == "es-ES" 302 | ? "Ctrl+A" : ApplicationCommands.SelectAll.InputGestures.Cast().First().DisplayString; 303 | } 304 | } 305 | -------------------------------------------------------------------------------- /ModernNotepad/Fonts/SegMDL2.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XamDR/ModernNotepad/8e8178128483046a5979d5b2bed1c1fd150f3cf7/ModernNotepad/Fonts/SegMDL2.ttf -------------------------------------------------------------------------------- /ModernNotepad/Images/DarkTheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XamDR/ModernNotepad/8e8178128483046a5979d5b2bed1c1fd150f3cf7/ModernNotepad/Images/DarkTheme.png -------------------------------------------------------------------------------- /ModernNotepad/Images/LightTheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XamDR/ModernNotepad/8e8178128483046a5979d5b2bed1c1fd150f3cf7/ModernNotepad/Images/LightTheme.png -------------------------------------------------------------------------------- /ModernNotepad/Images/SplashScreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XamDR/ModernNotepad/8e8178128483046a5979d5b2bed1c1fd150f3cf7/ModernNotepad/Images/SplashScreen.png -------------------------------------------------------------------------------- /ModernNotepad/Locales/LocaleRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | 4 | namespace ModernNotepad.Locales 5 | { 6 | class LocaleRepository 7 | { 8 | public LocaleRepository() 9 | { 10 | Locales = new HashSet 11 | { 12 | "en-US", 13 | "es-ES", 14 | }; 15 | EnglishDictionary = new Dictionary 16 | { 17 | { "OpenFileTitle", "Open File" }, 18 | { "SaveFileTitle", "Save File" }, 19 | { "FilterTxt", "Plain Text Files" }, 20 | { "FilterAll", "All Files" }, 21 | { "ConfirmationQuestion", "Would you like to save the changes made in the file?" }, 22 | { "AppDescription", EnglishDescription }, 23 | { "AppTitle", "Untitled" }, 24 | { "NewDocument", "New Document.txt" }, 25 | { "ErrorMessage", "Error executing the program. Please send a copy of the file \"error\" to the email: maxdr.mat@gmail.com"}, 26 | }; 27 | SpanishDictionary = new Dictionary 28 | { 29 | { "OpenFileTitle", "Abrir archivo" }, 30 | { "SaveFileTitle", "Guardar archivo" }, 31 | { "FilterTxt", "Documento de texto" }, 32 | { "FilterAll", "Todos los archivos" }, 33 | { "ConfirmationQuestion", "¿Quieres guardar los cambios hechos en el archivo?" }, 34 | { "AppDescription", SpanishDescription }, 35 | { "AppTitle", "Sín título" }, 36 | { "NewDocument", "Nuevo documento.txt" }, 37 | { "ErrorMessage", "Error al ejecutar el programa. Por favor envíe una copia del archivo \"error\" al correo: maxdr.mat@gmail.com"}, 38 | }; 39 | Dictionaries = new Dictionary> 40 | { 41 | { "en-US", EnglishDictionary }, 42 | { "es-ES", SpanishDictionary }, 43 | }; 44 | } 45 | 46 | public ISet Locales { get; } 47 | 48 | public Dictionary EnglishDictionary { get; } 49 | 50 | public Dictionary SpanishDictionary { get; } 51 | 52 | public Dictionary> Dictionaries { get; } 53 | 54 | private string EnglishDescription 55 | { 56 | get 57 | { 58 | var attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); 59 | return ((AssemblyDescriptionAttribute)attributes[0]).Description; 60 | } 61 | } 62 | 63 | private string SpanishDescription 64 | { 65 | get 66 | { 67 | var description = string.Join(" ", new string[] 68 | { 69 | "Modern Notepad es una aplicación de bloc de notas moderna y minimalista.", 70 | "Está desarrollada con WPF en .Net Core 3.1.", 71 | }); 72 | return description; 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /ModernNotepad/Locales/Strings_en-US.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | Untitled - Modern Notepad 6 | 7 | 8 | New 9 | Open 10 | Save 11 | Find 12 | Font 13 | Format 14 | Save As 15 | Settings 16 | Print Preview 17 | About 18 | Exit 19 | 20 | 21 | 22 | Print 23 | Previous 24 | Next 25 | of 26 | Cancel 27 | Document 28 | 29 | 30 | 31 | Open a New Window (Ctrl+Shift+N) 32 | Create New File (Ctrl+N) 33 | Open File (Ctrl+A) 34 | Save File (Ctrl+S) 35 | Save File As (Ctrl+Shift+S) 36 | Show Settings Window (Ctrl+G) 37 | Find or Replace Text (Ctrl+R) 38 | Find Next 39 | Find Previous 40 | Replace 41 | Replace All 42 | Font Settings (Ctrl+F) 43 | Show Print Preview (Ctrl+P) 44 | Show Print Dialog 45 | Previous Page 46 | Next Page 47 | Zoom In 48 | Zoom Out 49 | Reset Zoom (100%) 50 | About Modern Notepad 51 | Close Program (Alt+F4) 52 | 53 | 54 | 55 | Line: 1 56 | Char: 1 57 | Line 58 | Char 59 | 60 | 61 | 62 | Font Settings 63 | Font: 64 | Size: 65 | Sample: 66 | Ok 67 | Cancel 68 | 69 | 70 | 71 | Find/Replace 72 | Match case 73 | Original text 74 | Replace with 75 | It could not find the text 76 | 77 | 78 | 79 | Settings 80 | Text Wrapping 81 | Spell Checking 82 | Status Bar 83 | Visible 84 | Hidden 85 | Application Theme 86 | Dark 87 | Light 88 | Follow OS Theme 89 | 90 | 91 | 92 | About {0} 93 | Developed by 94 | Email: maxdr.mat@gmail.com 95 | The source code is available at Github: 96 | This app makes use of the following libraries: 97 | Version: 98 | 99 | 100 | 101 | Modern Notepad 102 | Yes, save 103 | No, discard 104 | 105 | 106 | 107 | Cut 108 | Copy 109 | Paste 110 | Undo 111 | Redo 112 | Delete 113 | Select All 114 | Proofing 115 | Ignore 116 | 117 | 118 | -------------------------------------------------------------------------------- /ModernNotepad/Locales/Strings_es-ES.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | Sin título - Modern Notepad 6 | 7 | 8 | Nuevo 9 | Abrir 10 | Guardar 11 | Buscar 12 | Fuente 13 | Guardar como 14 | Configuración 15 | Vista previa 16 | Acerca de 17 | Salir 18 | 19 | 20 | 21 | Imprimir 22 | Anterior 23 | Siguiente 24 | de 25 | Cancelar 26 | Documento 27 | 28 | 29 | 30 | Abrir una ventana nueva (Ctrl+Shift+N) 31 | Crear archivo nuevo (Ctrl+N) 32 | Abrir archivo (Ctrl+A) 33 | Guardar archivo (Ctrl+S) 34 | Guardar archivo como (Ctrl+S) 35 | Mostrar ventana de configuración (Ctrl+G) 36 | Buscar o reemplazar texto (Ctrl+R) 37 | Buscar siguiente 38 | Buscar anterior 39 | Reemplazar 40 | Reemplazar todo 41 | Configuración de la fuente (Ctrl+F) 42 | Mostrar vista previa de impresión (Ctrl+P) 43 | Mostrar diálogo de impresión 44 | Página anterior 45 | Página siguiente 46 | Acercar 47 | Alejar 48 | Restaurar zoom (100%) 49 | Acerca de Modern Notepad 50 | Cerrar programa (Alt+F4) 51 | 52 | 53 | 54 | Línea: 1 55 | Carácter: 1 56 | Línea 57 | Carácter 58 | 59 | 60 | 61 | Fuente 62 | Familia: 63 | Tamaño: 64 | Muestra: 65 | Aceptar 66 | Cancelar 67 | 68 | 69 | 70 | Buscar/Reemplazar 71 | Coincidir mayúsculas y minúsculas 72 | Texto original 73 | Reemplazar con 74 | No se encontró el texto 75 | 76 | 77 | 78 | Configuración 79 | Ajuste de línea 80 | Corrector ortográfico 81 | Barra de estado 82 | Visible 83 | Oculto 84 | Tema de la aplicación 85 | Oscuro 86 | Claro 87 | Usar el tema de Windows 88 | 89 | 90 | 91 | Acerca de {0} 92 | Desarrollado por 93 | Correo: maxdr.mat@gmail.com 94 | El código fuente está disponible en GitHub: 95 | Esta aplicación hace uso de las siguientes librerías: 96 | Versión: 97 | 98 | 99 | 100 | Modern Notepad 101 | Sí, guardar 102 | No, descartar 103 | 104 | 105 | 106 | Cortar 107 | Copiar 108 | Pegar 109 | Deshacer 110 | Rehacer 111 | Eliminar 112 | Seleccionar todo 113 | Revisión 114 | Omitir 115 | 116 | 117 | -------------------------------------------------------------------------------- /ModernNotepad/ModernNotepad.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | netcoreapp3.1 6 | true 7 | ModernNotepad.Program 8 | Copyright © 2020 Max Díaz. 9 | 10 | Max Díaz 11 | Modern Notepad is a modern and minimalist notepad application. It was developed using WPF on .Net Core 3.1. 12 | Modern Notepad 13 | AnyCPU;x64;x86 14 | 1.1.3 15 | ModernNotepad.ico 16 | app.manifest 17 | Modern Notepad 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | MSBuild:Compile 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ModernNotepad/ModernNotepad.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XamDR/ModernNotepad/8e8178128483046a5979d5b2bed1c1fd150f3cf7/ModernNotepad/ModernNotepad.ico -------------------------------------------------------------------------------- /ModernNotepad/Program.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepad.Dialogs; 2 | using ModernNotepad.Services; 3 | using ModernNotepadLibrary.Core; 4 | using ModernNotepadLibrary.Helpers; 5 | using ModernNotepadLibrary.Services; 6 | using ModernNotepadLibrary.ViewModels; 7 | using System; 8 | using System.ComponentModel; 9 | using System.Windows; 10 | 11 | namespace ModernNotepad 12 | { 13 | class Program 14 | { 15 | public static ServiceResolver ServiceResolver { get; private set; } 16 | 17 | [STAThread] 18 | public static void Main() 19 | { 20 | ShowSplashScreen(); 21 | RegisterServices(); 22 | var app = new App(); 23 | app.InitializeComponent(); 24 | app.Run(); 25 | } 26 | 27 | private static void ShowSplashScreen() 28 | { 29 | var splashScreen = new SplashScreen("Images/SplashScreen.png"); 30 | splashScreen.Show(true); 31 | } 32 | 33 | private static void RegisterServices() 34 | { 35 | ServiceResolver = new ServiceResolver(); 36 | ServiceResolver.Register(); 37 | ServiceResolver.Register(); 38 | ServiceResolver.Register(); 39 | ServiceResolver.Register(); 40 | ServiceResolver.Register(); 41 | ServiceResolver.Register(); 42 | ServiceResolver.Register(); 43 | ServiceResolver.Register, SettingsManager>(); 44 | ServiceResolver.Register(); 45 | ServiceResolver.Register(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ModernNotepad/Services/AdornerService.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepad.CustomControls; 2 | using ModernNotepadLibrary.Core; 3 | using ModernNotepadLibrary.Services; 4 | using System.Windows.Documents; 5 | 6 | namespace ModernNotepad.Services 7 | { 8 | class AdornerService : IAdornerService 9 | { 10 | public void AddAdorner(ITextArea textArea) 11 | { 12 | var adornedTextArea = textArea as TextArea; 13 | var adornerLayer = AdornerLayer.GetAdornerLayer(adornedTextArea); 14 | 15 | if (adornerLayer.GetAdorners(adornedTextArea) != null) // Workaround 16 | { 17 | adornerLayer.Remove(adornedTextArea.HighlightCurrentLineAdorner); 18 | } 19 | adornerLayer.Add(adornedTextArea.HighlightCurrentLineAdorner); 20 | } 21 | 22 | public void RemoveAdorner(ITextArea textArea) 23 | { 24 | var adornedTextArea = textArea as TextArea; 25 | var adornerLayer = AdornerLayer.GetAdornerLayer(adornedTextArea); 26 | adornerLayer.Remove(adornedTextArea.HighlightCurrentLineAdorner); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ModernNotepad/Services/ApplicationThemeManager.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepadLibrary.Services; 2 | using ModernWpf; 3 | 4 | namespace ModernNotepad.Services 5 | { 6 | class ApplicationThemeManager : IApplicationThemeManager 7 | { 8 | public void ChangeTheme(bool? isDarkThemeRequested) 9 | { 10 | ThemeManager.Current.ApplicationTheme = isDarkThemeRequested switch 11 | { 12 | true => ApplicationTheme.Dark, 13 | false => ApplicationTheme.Light, 14 | _ => null, 15 | }; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ModernNotepad/Services/ContentDialogService.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepadLibrary.Services; 2 | using ModernWpf.Controls; 3 | using System.Threading.Tasks; 4 | using System.Windows; 5 | 6 | namespace ModernNotepad.Dialogs 7 | { 8 | class ContentDialogService : IContentDialogService 9 | { 10 | public async Task AskConfirmationAsync(string question) 11 | { 12 | var dialog = new ContentDialog 13 | { 14 | Content = question, 15 | DefaultButton = ContentDialogButton.Primary, 16 | PrimaryButtonText = (string)Application.Current.TryFindResource("SaveButton"), 17 | SecondaryButtonText = (string)Application.Current.TryFindResource("NoSaveButton"), 18 | CloseButtonText = (string)Application.Current.TryFindResource("CancelButton"), 19 | Title = Application.Current.TryFindResource("Caption"), 20 | }; 21 | var result = await dialog.ShowAsync(); 22 | 23 | return result switch 24 | { 25 | ContentDialogResult.None => null, 26 | ContentDialogResult.Primary => true, 27 | ContentDialogResult.Secondary => false, 28 | _ => null, 29 | }; 30 | } 31 | 32 | public async Task ShowInformationAsync(string message) 33 | { 34 | var dialog = new ContentDialog 35 | { 36 | Content = message, 37 | DefaultButton = ContentDialogButton.Primary, 38 | CloseButtonText = (string)Application.Current.TryFindResource("OkButton"), 39 | Title = Application.Current.TryFindResource("Caption"), 40 | Owner = Application.Current.MainWindow, 41 | }; 42 | await dialog.ShowAsync(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ModernNotepad/Services/LocaleManager.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepad.Locales; 2 | using ModernNotepadLibrary.Services; 3 | using System; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Windows; 7 | 8 | namespace ModernNotepad.Services 9 | { 10 | class LocaleManager : ILocaleManager 11 | { 12 | private readonly LocaleRepository repository = new LocaleRepository(); 13 | 14 | public bool IsLocalAvailable 15 | => Application.Current.Resources.MergedDictionaries 16 | .Where(r => r.Source != null) 17 | .SingleOrDefault(r => r.Source.OriginalString.Replace(".xaml", "").EndsWith(CultureInfo.CurrentUICulture.Name)) != null; 18 | 19 | public string LoadString(string key) 20 | { 21 | if (IsLocalAvailable) 22 | { 23 | var dictionary = repository.Dictionaries.SingleOrDefault(d => d.Key == CultureInfo.CurrentUICulture.Name); 24 | return dictionary.Value[key]; 25 | } 26 | else 27 | { 28 | return repository.EnglishDictionary[key]; 29 | } 30 | } 31 | 32 | public void LoadStringResource(string locale) 33 | { 34 | var resource = new ResourceDictionary 35 | { 36 | Source = new Uri($"pack://application:,,,/Locales/Strings_{locale}.xaml") 37 | }; 38 | Application.Current.Resources.MergedDictionaries.Add(resource); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ModernNotepad/Services/OpenFileDialogService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using ModernNotepadLibrary.Services; 3 | 4 | namespace ModernNotepad.Dialogs 5 | { 6 | class OpenFileDialogService : IOpenFileService 7 | { 8 | private readonly OpenFileDialog ofd; 9 | 10 | public OpenFileDialogService() => ofd = new OpenFileDialog(); 11 | 12 | public string DefaultExtension 13 | { 14 | get => ofd.DefaultExt; 15 | set => ofd.DefaultExt = value; 16 | } 17 | 18 | public string FileName => ofd.FileName; 19 | 20 | public string[] FileNames => ofd.FileNames; 21 | 22 | public string Filter 23 | { 24 | get => ofd.Filter; 25 | set => ofd.Filter = value; 26 | } 27 | 28 | public int FilterIndex 29 | { 30 | get => ofd.FilterIndex; 31 | set => ofd.FilterIndex = value; 32 | } 33 | 34 | public bool MultiSelect 35 | { 36 | get => ofd.Multiselect; 37 | set => ofd.Multiselect = value; 38 | } 39 | 40 | public string Title 41 | { 42 | get => ofd.Title; 43 | set => ofd.Title = value; 44 | } 45 | 46 | public bool? ShowDialog() => ofd.ShowDialog(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ModernNotepad/Services/PrintService.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepad.Util; 2 | using ModernNotepad.Views; 3 | using ModernNotepadLibrary.Services; 4 | using System.Windows; 5 | 6 | namespace ModernNotepad.Services 7 | { 8 | class PrintService : IPrintService 9 | { 10 | public void PrintDocument() 11 | { 12 | //if (PrintDialogWrapper.IsPrintJobSendToQueue) 13 | //{ 14 | // var document = (Application.Current.MainWindow as MainWindow).Document; 15 | // var documentPaginator = document.DocumentPaginator; 16 | // var description = (string)Application.Current.TryFindResource("DescriptionPrintJob"); 17 | // PrintDialogWrapper.PrintDocument(documentPaginator, description); 18 | //} 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ModernNotepad/Services/SaveFileDialogService.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using ModernNotepadLibrary.Services; 3 | 4 | namespace ModernNotepad.Dialogs 5 | { 6 | class SaveFileDialogService : ISaveFileService 7 | { 8 | private readonly SaveFileDialog sfd; 9 | 10 | public SaveFileDialogService() => sfd = new SaveFileDialog(); 11 | 12 | public bool AddExtension 13 | { 14 | get => sfd.AddExtension; 15 | set => sfd.AddExtension = value; 16 | } 17 | 18 | public string DefaultExtension 19 | { 20 | get => sfd.DefaultExt; 21 | set => sfd.DefaultExt = value; 22 | } 23 | 24 | public string FileName 25 | { 26 | get => sfd.FileName; 27 | set => sfd.FileName = value; 28 | } 29 | 30 | public string Filter 31 | { 32 | get => sfd.Filter; 33 | set => sfd.Filter = value; 34 | } 35 | 36 | public int FilterIndex 37 | { 38 | get => sfd.FilterIndex; 39 | set => sfd.FilterIndex = value; 40 | } 41 | 42 | public string Title 43 | { 44 | get => sfd.Title; 45 | set => sfd.Title = value; 46 | } 47 | 48 | public bool? ShowDialog() => sfd.ShowDialog(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ModernNotepad/Services/SettingsManager.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepadLibrary.Core; 2 | using ModernNotepadLibrary.Services; 3 | using System; 4 | using System.IO; 5 | using System.Text.Json; 6 | 7 | namespace ModernNotepad.Services 8 | { 9 | class SettingsManager : ISettingsManager 10 | { 11 | public string SettingsDirectoryPath => GetFullPath().Replace(@"\userdata.json", string.Empty); 12 | 13 | public UserSettings LoadSettings() 14 | { 15 | var fullPath = GetFullPath(); 16 | var settings = JsonSerializer.Deserialize(File.ReadAllText(fullPath)); 17 | return settings; 18 | } 19 | 20 | public void SaveSettings(UserSettings settings) 21 | { 22 | var fullPath = GetFullPath(); 23 | Directory.CreateDirectory(SettingsDirectoryPath); 24 | var options = new JsonSerializerOptions { WriteIndented = true }; 25 | File.WriteAllText(fullPath, JsonSerializer.Serialize(settings, options)); 26 | } 27 | 28 | private string GetFullPath() 29 | { 30 | var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); 31 | return Path.Combine(appDataPath, @"ModernNotepad\userdata.json"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ModernNotepad/Services/WindowService.cs: -------------------------------------------------------------------------------- 1 | using ModernNotepad.Views; 2 | using ModernNotepadLibrary.Core; 3 | using ModernNotepadLibrary.Services; 4 | using System; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Windows; 8 | 9 | namespace ModernNotepad.Services 10 | { 11 | class WindowService : IWindowService 12 | { 13 | public void Close(Type viewModelType) 14 | { 15 | var mainWindow = Application.Current.MainWindow; 16 | var childWindow = mainWindow.OwnedWindows 17 | .Cast() 18 | .SingleOrDefault(w => w.GetType() == GetViewType(viewModelType)); 19 | childWindow.Close(); 20 | } 21 | 22 | public void CloseMainWindow() => Application.Current.MainWindow.Close(); 23 | 24 | public void Show(object viewModel, Type viewModelType) 25 | { 26 | var window = CreateWindow(viewModelType); 27 | window.DataContext = viewModel; 28 | window.Owner = Application.Current.MainWindow; 29 | window.Show(); 30 | } 31 | 32 | public bool? ShowDialog(object viewModel, Type viewModelType) 33 | { 34 | var window = CreateWindow(viewModelType); 35 | window.DataContext = viewModel; 36 | window.Owner = Application.Current.MainWindow; 37 | return window.ShowDialog(); 38 | } 39 | 40 | public IMainView CreateMainView(object viewModel, Type viewModelType) 41 | { 42 | var window = CreateWindow(viewModelType) as MainWindow; 43 | window.DataContext = viewModel; 44 | window.Show(); 45 | return window; 46 | } 47 | 48 | private Type GetViewType(Type viewModelType) 49 | { 50 | var viewModelFullName = viewModelType.FullName; //ModernNotepadLibrary.ViewModels.AboutViewModel 51 | 52 | var names = viewModelFullName.Split('.'); 53 | var firstName = names[0].Replace("Library", ""); 54 | var secondName = names[1].Replace("Model", ""); 55 | var thirdName = names[2].Replace("ViewModel", "Window"); 56 | 57 | var viewFullName = string.Join('.', new[] { firstName, secondName, thirdName }); //ModernNotepad.Views.AboutWindow 58 | var viewType = Assembly.GetExecutingAssembly().GetType(viewFullName); 59 | 60 | return viewType; 61 | } 62 | 63 | private Window CreateWindow(Type viewModelType) 64 | { 65 | var viewType = GetViewType(viewModelType); 66 | return Activator.CreateInstance(viewType) as Window; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ModernNotepad/Styles/FluentStyle.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 2 7 | 2 8 | 9 | 142 | -------------------------------------------------------------------------------- /ModernNotepad/Styles/TextAreaStyle.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 0,0,0,4 8 | 9 | 10 | 11 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 123 | 136 | 149 | 161 |