From 060455998a74b93eb8ac3b8627d54ca7b9e61146 Mon Sep 17 00:00:00 2001 From: athaa Date: Sun, 19 Mar 2023 13:03:15 +0700 Subject: Add project files. --- MarkdownEditor.sln | 31 ++++ MarkdownEditor/AboutWindow.xaml | 72 ++++++++ MarkdownEditor/AboutWindow.xaml.cs | 34 ++++ MarkdownEditor/App.xaml | 9 + MarkdownEditor/App.xaml.cs | 17 ++ MarkdownEditor/AssemblyInfo.cs | 10 ++ MarkdownEditor/LICENSE.txt | 21 +++ MarkdownEditor/MainWindow.xaml | 61 +++++++ MarkdownEditor/MainWindow.xaml.cs | 295 +++++++++++++++++++++++++++++++++ MarkdownEditor/MarkdownEditor.csproj | 32 ++++ MarkdownEditor/ResourceDictionary.xaml | 26 +++ MarkdownEditor/app.manifest | 79 +++++++++ MarkdownEditor/icon_markdowneditor.ico | Bin 0 -> 67646 bytes MarkdownEditor/icon_markdowneditor.png | Bin 0 -> 47370 bytes 14 files changed, 687 insertions(+) create mode 100644 MarkdownEditor.sln create mode 100644 MarkdownEditor/AboutWindow.xaml create mode 100644 MarkdownEditor/AboutWindow.xaml.cs create mode 100644 MarkdownEditor/App.xaml create mode 100644 MarkdownEditor/App.xaml.cs create mode 100644 MarkdownEditor/AssemblyInfo.cs create mode 100644 MarkdownEditor/LICENSE.txt create mode 100644 MarkdownEditor/MainWindow.xaml create mode 100644 MarkdownEditor/MainWindow.xaml.cs create mode 100644 MarkdownEditor/MarkdownEditor.csproj create mode 100644 MarkdownEditor/ResourceDictionary.xaml create mode 100644 MarkdownEditor/app.manifest create mode 100644 MarkdownEditor/icon_markdowneditor.ico create mode 100644 MarkdownEditor/icon_markdowneditor.png diff --git a/MarkdownEditor.sln b/MarkdownEditor.sln new file mode 100644 index 0000000..7734a88 --- /dev/null +++ b/MarkdownEditor.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33403.182 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarkdownEditor", "MarkdownEditor\MarkdownEditor.csproj", "{AF292269-4A5B-442C-AF86-75CF18860370}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF292269-4A5B-442C-AF86-75CF18860370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF292269-4A5B-442C-AF86-75CF18860370}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF292269-4A5B-442C-AF86-75CF18860370}.Debug|x64.ActiveCfg = Debug|x64 + {AF292269-4A5B-442C-AF86-75CF18860370}.Debug|x64.Build.0 = Debug|x64 + {AF292269-4A5B-442C-AF86-75CF18860370}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF292269-4A5B-442C-AF86-75CF18860370}.Release|Any CPU.Build.0 = Release|Any CPU + {AF292269-4A5B-442C-AF86-75CF18860370}.Release|x64.ActiveCfg = Release|x64 + {AF292269-4A5B-442C-AF86-75CF18860370}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EF8C08E9-E2DD-4439-BE9B-B42AA6AA1D85} + EndGlobalSection +EndGlobal diff --git a/MarkdownEditor/AboutWindow.xaml b/MarkdownEditor/AboutWindow.xaml new file mode 100644 index 0000000..f7aff6c --- /dev/null +++ b/MarkdownEditor/AboutWindow.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + MarkdownEditor + v0.1 + + + github.com/altaf-creator/MarkdownEditor + + + + + + + + + MarkdownEditor + Developer + + + altaf-creator + + + Packages and Software + + + CefSharp + + - chromium wrapper + + + + Markdig + + - markdown parser + + + + Ookii Dialogs + + - open folder dialog + + Made using .NET C# WPF + + + + + View License + + + + diff --git a/MarkdownEditor/AboutWindow.xaml.cs b/MarkdownEditor/AboutWindow.xaml.cs new file mode 100644 index 0000000..0c1bf24 --- /dev/null +++ b/MarkdownEditor/AboutWindow.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace MarkdownEditor +{ + /// + /// Interaction logic for AboutWindow.xaml + /// + public partial class AboutWindow : Window + { + public AboutWindow() + { + InitializeComponent(); + } + + private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e) + { + Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); + e.Handled = true; + } + } +} diff --git a/MarkdownEditor/App.xaml b/MarkdownEditor/App.xaml new file mode 100644 index 0000000..33a6502 --- /dev/null +++ b/MarkdownEditor/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/MarkdownEditor/App.xaml.cs b/MarkdownEditor/App.xaml.cs new file mode 100644 index 0000000..88a53f2 --- /dev/null +++ b/MarkdownEditor/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace MarkdownEditor +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/MarkdownEditor/AssemblyInfo.cs b/MarkdownEditor/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/MarkdownEditor/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/MarkdownEditor/LICENSE.txt b/MarkdownEditor/LICENSE.txt new file mode 100644 index 0000000..4d4e53a --- /dev/null +++ b/MarkdownEditor/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Athaalaa Altaf Hafidz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/MarkdownEditor/MainWindow.xaml b/MarkdownEditor/MainWindow.xaml new file mode 100644 index 0000000..f15d489 --- /dev/null +++ b/MarkdownEditor/MainWindow.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Opened Files + + + C:\path\to\file + + + + + + + + + diff --git a/MarkdownEditor/MainWindow.xaml.cs b/MarkdownEditor/MainWindow.xaml.cs new file mode 100644 index 0000000..68c90f2 --- /dev/null +++ b/MarkdownEditor/MainWindow.xaml.cs @@ -0,0 +1,295 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Threading; +using System.Diagnostics; +using Microsoft.Win32; +using System.IO; +using CefSharp; +using Markdig; +using Path = System.IO.Path; +using Ookii.Dialogs.Wpf; +using System.ComponentModel; +using System.Drawing; + +namespace MarkdownEditor +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public string path; + public string rootPath; + public string tempPath = Path.GetTempPath() + "markdowneditor_temp.html"; + private string prevTxt; + public bool isOpened = false; + + public MainWindow() + { + InitializeComponent(); + prevTxt = txtRaw.Text; + rootPath = ""; + path = ""; + + System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); + dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); + dispatcherTimer.Interval = TimeSpan.FromSeconds(.5f); + dispatcherTimer.Start(); + File.WriteAllText(tempPath, ""); + browser.Load(tempPath); + } + + private void dispatcherTimer_Tick(object sender, EventArgs e) + { + if (prevTxt != txtRaw.Text) + { + var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); + string font = "\r\n\r\n"; + // CSS styling. Please forgive me. + string style = @""; + var result = Markdown.ToHtml(txtRaw.Text, pipeline); + + File.WriteAllText(tempPath, font + style + result); + + string htmlPath = "file:///" + tempPath; + + if (browser.Address != htmlPath.Replace('\\','/')) + { + browser.Load(tempPath); + } + else + { + browser.Reload(); + } + prevTxt = txtRaw.Text; + } + + string formattedPath = path; + + pathTxt.Text = formattedPath.Substring(rootPath.Length); + browser.LoadError += browser_LoadError; + } + + private void saveBtn_Click(object sender, RoutedEventArgs e) + { + string text = txtRaw.Text; + + if (!isOpened) + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Markdown (*.md)|*.md|Text (*.txt)|*.txt|All (*.*)|*.*"; + + if (saveFileDialog.ShowDialog() == true) + { + path = saveFileDialog.FileName; + File.WriteAllText(path, text); + isOpened = true; + } + } + else + { + File.WriteAllText(path, text); + } + } + + private void openBtn_Click(object sender, RoutedEventArgs e) + { + OpenFileDialog openFileDialog = new OpenFileDialog(); + openFileDialog.Filter = "Markdown Files (*.md)|*.md|Text Files (*.txt)|*.txt|All (*.*)|*.*"; + + if (openFileDialog.ShowDialog() == true) + { + path = openFileDialog.FileName; + rootPath = ""; + txtRaw.Text = File.ReadAllText(path); + + var fileButton = new Button(); + fileButton.Content = Path.GetFileName(path); + fileButton.ToolTip = path; + fileButton.Click += fileBtn_Click; + filePanel.Items.Insert(0, fileButton); + + isOpened = true; + } + } + + private void exportBtn_Click(object sender, RoutedEventArgs e) + { + string text = Markdig.Markdown.ToHtml(txtRaw.Text); + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "HTML (*.html)|*.html|Text (*.txt)|*.txt|All (*.*)|*.*"; + + if (saveFileDialog.ShowDialog() == true) + { + path = saveFileDialog.FileName; + File.WriteAllText(path, text); + } + } + + private void fileBtn_Click(object sender, RoutedEventArgs e) + { + + var element = (FrameworkElement)sender; + string tooltip = element.ToolTip.ToString(); + + txtRaw.Text = File.ReadAllText(tooltip); + path = tooltip; + isOpened = true; + } + + private void clearBtn_Click(object sender, RoutedEventArgs e) + { + filePanel.Items.Clear(); + } + + private void openFolderBtn_Click(object sender, RoutedEventArgs e) + { + var dialog = new VistaFolderBrowserDialog(); + dialog.Description = "Select Folder"; + dialog.UseDescriptionForTitle = true; + + if (dialog.ShowDialog() == true) + { + path = dialog.SelectedPath; + rootPath = dialog.SelectedPath; + + string[] files = Directory.GetFiles(path, "*.md", SearchOption.AllDirectories); + + filePanel.Items.Clear(); + + for (int i = files.Length - 1; i >= 0; i--) + { + var fileButton = new Button(); + string str = files[i]; + + str = str.Substring(path.Length); + + fileButton.Content = str; + fileButton.ToolTip = files[i]; + fileButton.Click += fileBtn_Click; + filePanel.Items.Insert(0, fileButton); + } + } + } + + private void saveAsBtn_Click(object sender, RoutedEventArgs e) + { + string text = txtRaw.Text; + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Markdown (*.md)|*.md|Text (*.txt)|*.txt|All (*.*)|*.*"; + + if (saveFileDialog.ShowDialog() == true) + { + path = saveFileDialog.FileName; + File.WriteAllText(path, text); + } + + } + + private void Window_Closing(object sender, CancelEventArgs e) + { + File.Delete(tempPath); + } + + public void browser_LoadError(object sender, EventArgs e) + { + browser.Load(tempPath); + } + + private void aboutBtn_Click(object sender, RoutedEventArgs e) + { + Window window = new AboutWindow(); + window.Show(); + } + } +} diff --git a/MarkdownEditor/MarkdownEditor.csproj b/MarkdownEditor/MarkdownEditor.csproj new file mode 100644 index 0000000..f1a6435 --- /dev/null +++ b/MarkdownEditor/MarkdownEditor.csproj @@ -0,0 +1,32 @@ + + + + WinExe + net48 + enable + true + AnyCPU;x64 + app.manifest + 8.0 + icon_markdowneditor.ico + + + + + + + + + + + + + + + + + + + + + diff --git a/MarkdownEditor/ResourceDictionary.xaml b/MarkdownEditor/ResourceDictionary.xaml new file mode 100644 index 0000000..fb2e442 --- /dev/null +++ b/MarkdownEditor/ResourceDictionary.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/MarkdownEditor/app.manifest b/MarkdownEditor/app.manifest new file mode 100644 index 0000000..fa8f332 --- /dev/null +++ b/MarkdownEditor/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MarkdownEditor/icon_markdowneditor.ico b/MarkdownEditor/icon_markdowneditor.ico new file mode 100644 index 0000000..65b39b9 Binary files /dev/null and b/MarkdownEditor/icon_markdowneditor.ico differ diff --git a/MarkdownEditor/icon_markdowneditor.png b/MarkdownEditor/icon_markdowneditor.png new file mode 100644 index 0000000..40d0d9d Binary files /dev/null and b/MarkdownEditor/icon_markdowneditor.png differ -- cgit v1.2.3