Skip to content

Commit 8dbada3

Browse files
committed
Added browser utils
1 parent b44f31c commit 8dbada3

12 files changed

+344
-417
lines changed

.gitignore

Lines changed: 10 additions & 397 deletions
Large diffs are not rendered by default.

App.axaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="WriterSharp.App"
4+
RequestedThemeVariant="Default">
5+
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
6+
7+
<Application.Styles>
8+
<FluentTheme />
9+
</Application.Styles>
10+
</Application>

App.axaml.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.Markup.Xaml;
4+
5+
namespace WriterSharp
6+
{
7+
public partial class App : Application
8+
{
9+
public override void Initialize()
10+
{
11+
AvaloniaXamlLoader.Load(this);
12+
}
13+
14+
public override void OnFrameworkInitializationCompleted()
15+
{
16+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
17+
{
18+
desktop.MainWindow = new MainWindow();
19+
}
20+
21+
base.OnFrameworkInitializationCompleted();
22+
}
23+
}
24+
}
308 KB
Loading
285 KB
Loading
259 KB
Loading

MainWindow.axaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
6+
x:Class="WriterSharp.MainWindow"
7+
Icon="avares://WriterSharp/Assets/TransparentIcon.ico"
8+
Title="WriterSharp">
9+
<Grid RowDefinitions="Auto, *, Auto" Name="MainGrid">
10+
<Grid Grid.Row="0">
11+
<Menu>
12+
<MenuItem Header="_File">
13+
<MenuItem Header="New text file"></MenuItem>
14+
<MenuItem Header="New from template"></MenuItem>
15+
<Separator></Separator>
16+
<MenuItem Header="Open" Click="OnClickOpen"></MenuItem>
17+
<MenuItem Header="Open recent file"></MenuItem>
18+
<Separator></Separator>
19+
<MenuItem Header="Save"></MenuItem>
20+
<MenuItem Header="Save as"></MenuItem>
21+
<Separator></Separator>
22+
<MenuItem Header="Exit"></MenuItem>
23+
<Separator></Separator>
24+
<MenuItem Header="Exit without saving"></MenuItem>
25+
</MenuItem>
26+
<MenuItem Header="_About">
27+
<MenuItem Header="What is WriterSharp?"></MenuItem>
28+
<MenuItem Header="License"></MenuItem>
29+
<Separator></Separator>
30+
<MenuItem Header="Repository" Click="OnClickRepository"></MenuItem>
31+
<MenuItem Header="Website" Click="OnClickWebsite"></MenuItem>
32+
<Separator></Separator>
33+
<MenuItem Header="Nostalgia Hit"></MenuItem>
34+
</MenuItem>
35+
</Menu>
36+
</Grid>
37+
<Grid Grid.Row="1">
38+
<TextBox AcceptsReturn="True"
39+
AcceptsTab="True"
40+
TextWrapping="Wrap"
41+
Name="MainTextBox">
42+
</TextBox>
43+
</Grid>
44+
</Grid>
45+
</Window>
46+

Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using Avalonia;
3+
4+
namespace WriterSharp
5+
{
6+
internal class Program
7+
{
8+
// Initialization code. Don't use any Avalonia, third-party APIs or any
9+
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
10+
// yet and stuff might break.
11+
[STAThread]
12+
public static void Main(string[] args) => BuildAvaloniaApp()
13+
.StartWithClassicDesktopLifetime(args);
14+
15+
// Avalonia configuration, don't remove; also used by visual designer.
16+
public static AppBuilder BuildAvaloniaApp()
17+
=> AppBuilder.Configure<App>()
18+
.UsePlatformDetect()
19+
.WithInterFont()
20+
.LogToTrace();
21+
}
22+
}

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# WriterSharp
2-
Writer# (or WriterSharp) is THE new WriterClassic, now in C#, with even more corss-platform compatibility.
2+
<img src="Assets/Logo.png" align="right" width="100" alt="Norb's WriterClassic Logo"/>
3+
4+
So, what is WriterSharp?
5+
6+
Well, long time ago *(it was only 3 years)*, I created a Python program with a GUI called [**WriterClassic**](https://github.com/MF366-Coding/WriterClassic). It was a basic text editor that evolved into something special - at least for me.
7+
8+
It was my biggest project for quite a while and it was also... my first actual programming project. I mean, public at least.
9+
10+
I ended up releasing 11 major versions for it and almost released v12.0.0, but I couldn't. The codebase was old and unorganized and it was getting increasingly hard to maintain WriterClassic.
11+
12+
So, **WriterSharp** was born. WriterSharp (please don't write **Writer#** - it's cursed) is WriterClassic but in C#, with a more modern look and better cross-platform compatibility.
13+
14+
I also made the decision of not dropping the WriterClassic logo for a new one, because **A) It was made by a friend** and **B) It's *classic* :)**.

Utils/Browser.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* ___
3+
* | _ ) _ _ ___ __ __ __ ___ ___ _ _
4+
* | _ \ | '_| / _ \ \ V V / (_-< / -_) | '_|
5+
* |___/ |_| \___/ \_/\_/ /__/ \___| |_|
6+
*
7+
* MIT License * MF366
8+
*
9+
*/
10+
11+
12+
// System
13+
using System;
14+
using System.Diagnostics;
15+
using System.Reflection;
16+
using System.Threading.Tasks;
17+
18+
19+
namespace WriterSharp.Browser
20+
{
21+
22+
/// <summary>
23+
/// Browser-related operations.
24+
/// </summary>
25+
public static class BrowserService
26+
{
27+
28+
/// <summary>
29+
/// Open a URL with the default webbrowser.
30+
/// </summary>
31+
/// <param name="url">The URL to open</param>
32+
/// <returns>0 if successful or -1 if an error was caught</returns>
33+
public static int OpenURL(string url)
34+
{
35+
36+
try
37+
{
38+
39+
ProcessStartInfo psi = new()
40+
{
41+
42+
FileName = url,
43+
UseShellExecute = true
44+
45+
};
46+
Process.Start(psi);
47+
return 0;
48+
49+
}
50+
51+
catch (Exception)
52+
{
53+
54+
return -1;
55+
56+
}
57+
58+
}
59+
60+
/// <summary>
61+
/// Opens a URL with the default webbrowser, but asyncronously.
62+
/// </summary>
63+
/// <param name="url">The URL to open.</param>
64+
/// <returns>Null if an error was caught</returns>
65+
public static async Task<Process?> OpenURLAsync(string url)
66+
{
67+
68+
try
69+
{
70+
71+
ProcessStartInfo psi = new()
72+
{
73+
74+
FileName = url,
75+
UseShellExecute = true
76+
77+
};
78+
79+
return await Task.Run(() => Process.Start(psi));
80+
81+
}
82+
catch (Exception)
83+
{
84+
85+
return null;
86+
87+
}
88+
89+
}
90+
91+
}
92+
93+
}

0 commit comments

Comments
 (0)