-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
86 lines (72 loc) · 2.93 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Diagnostics;
using System.Text;
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
string SVGInput = txtInput.Text.Trim();
string BootstrapClassValue = GetClassAttributeValue(SVGInput).Split(' ')[1] + "-nav-menu";
string NewSvgData = SVGInput.Replace(Environment.NewLine, "")
.Replace('"', '\'')
.Replace("<", "%3C")
.Replace(">", "%3E")
.Replace("currentColor", txtIconForegroundColor.Text.Trim());
StringBuilder cssOutputBuilder = new StringBuilder();
cssOutputBuilder.AppendLine("." + BootstrapClassValue + " {")
.AppendLine("\tbackground-image: url(\"data:image/svg+xml," + NewSvgData + "\");")
.AppendLine("}");
txtOutputCSS.Text = cssOutputBuilder.ToString();
StringBuilder navMenuOutputBuilder = new StringBuilder();
navMenuOutputBuilder.AppendLine("<div class=\"nav-item px-3\">")
.AppendLine("\t<NavLink class=\"nav-link\" href=\"pagename\">")
.AppendLine("\t\t<span class=\"bi " + BootstrapClassValue + "\" aria-hidden=\"true\"></span> Your Page Name")
.AppendLine("\t</NavLink>")
.AppendLine("</div>");
txtOutputNavMenuTemplate.Text = navMenuOutputBuilder.ToString();
}
public static string GetClassAttributeValue(string html)
{
string classAttribute = "class=\"";
int classIndex = html.IndexOf(classAttribute);
if (classIndex == -1)
{
return string.Empty;
}
int startIndex = classIndex + classAttribute.Length;
int endIndex = html.IndexOf("\"", startIndex);
if (endIndex == -1)
{
return string.Empty;
}
return html.Substring(startIndex, endIndex - startIndex);
}
private void btnVisitBootstrapIconsPage_Click(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo
{
FileName = "https://icons.getbootstrap.com/",
UseShellExecute = true
});
}
private void btnCopyCSSToClipboard_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(txtOutputCSS.Text);
MessageBox.Show("CSS code copied to clipboard!");
}
private void btnCopyHTMLToClipboard_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(txtOutputNavMenuTemplate.Text);
MessageBox.Show("HTML code copied to clipboard!");
}
}
}