Skip to content

Commit

Permalink
[UI] support save mainwindow size
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Nov 3, 2020
1 parent 5f3ea9a commit 668497e
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Rider
.idea
29 changes: 18 additions & 11 deletions .idea/.idea.NaiveSharp/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions NaiveSharp/ConstText/Path/Config.cs
Expand Up @@ -4,6 +4,7 @@ public static partial class PATH
{
public const string CONFIG = @"config";
public const string CONFIG_INI = @"config\config.ini";
public const string CONFIG_FORM = @"config\form.ns";
public const string CONFIG_NODE_NS = @"config\node.ns";
public const string CONFIG_NODELIST = @"config\list.ns";
public const string CONFIG_SELECT_NODE = @"config\selectnode.ns";
Expand Down
4 changes: 2 additions & 2 deletions NaiveSharp/Controller/Encoder.cs
Expand Up @@ -11,7 +11,7 @@ public static string ConvertToBase64(string str, bool exceptionReturnSourceData
{
try
{
return Convert.ToBase64String((byte[]) Encoding.UTF8.GetBytes(str));
return Convert.ToBase64String(Encoding.UTF8.GetBytes(str));
}
catch
{
Expand All @@ -30,7 +30,7 @@ public static string ConvertFromBase64(string str, bool exceptionReturnSourceDat
{
try
{
return Encoding.UTF8.GetString((byte[]) Convert.FromBase64String(str));
return Encoding.UTF8.GetString(Convert.FromBase64String(str));
}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions NaiveSharp/Controller/Operation.cs
@@ -1,9 +1,9 @@
using NaiveSharp.ConstText;
using NaiveSharp.Model;
using NaiveSharp.Model;

using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using PATH = NaiveSharp.ConstText.PATH;

namespace NaiveSharp.Controller
{
Expand Down
14 changes: 13 additions & 1 deletion NaiveSharp/Model/Config.cs
@@ -1,4 +1,6 @@
using NaiveSharp.Controller.Extension;
using System.IO;
using NaiveSharp.ConstText;
using NaiveSharp.Controller.Extension;

namespace NaiveSharp.Model
{
Expand Down Expand Up @@ -26,6 +28,16 @@ public static string ConvertToNs()
{
return Controller.NaiveCmdBuilder.Proxy(Scheme, Username, Password, Host).ToBase64();
}

public static void Save()
{
if (!File.Exists(PATH.CONFIG_INI))
{
File.Create(PATH.CONFIG_INI).Close();
}

File.WriteAllText(PATH.CONFIG_INI, $"mode = {Config.RunMode}");
}

}
}
21 changes: 21 additions & 0 deletions NaiveSharp/Model/FormSize.cs
@@ -0,0 +1,21 @@
using System.IO;
using NaiveSharp.ConstText;

namespace NaiveSharp.Model
{
public class FormSize
{
public static int X;
public static int Y;

public static void Save()
{
if (!File.Exists(PATH.CONFIG_FORM))
{
File.Create(PATH.CONFIG_FORM).Close();
}

File.WriteAllText(PATH.CONFIG_FORM, $"{X},{Y}");
}
}
}
1 change: 1 addition & 0 deletions NaiveSharp/NaiveSharp.csproj
Expand Up @@ -129,6 +129,7 @@
<Compile Include="Controller\Sharelink.cs" />
<Compile Include="Controller\Update.cs" />
<Compile Include="Model\Config.cs" />
<Compile Include="Model\FormSize.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="View\About.cs">
Expand Down
1 change: 1 addition & 0 deletions NaiveSharp/View/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions NaiveSharp/View/MainWindow.cs
Expand Up @@ -14,6 +14,18 @@ public MainWindow()
{
CheckPath();

if (File.Exists(ConstText.PATH.CONFIG_FORM))
{
var c = File.ReadAllText(PATH.CONFIG_FORM).Replace(" ", "").Split(',');
if (c.Length == 2)
{
if (int.TryParse(c[0].Trim(), out int iTX))
FormSize.X = iTX;
if (int.TryParse(c[1].Trim(), out int iTY))
FormSize.Y = iTY;
}
}

// MessageBox.Show(File.ReadAllText(PATH.CONFIG_INI));
string runMode = LoadModeConfig();

Expand Down Expand Up @@ -74,6 +86,10 @@ public MainWindow()
}
}
*/
if (Model.FormSize.X > 0)
this.Width = FormSize.X;
if (FormSize.Y > 0)
this.Height = FormSize.Y;
}

private void MainWindows_Load(object sender, EventArgs e)
Expand All @@ -86,6 +102,13 @@ private void MainWindows_Load(object sender, EventArgs e)

icnNotify.Visible = true;
}

private void MainWindow_ResizeEnd(object sender, EventArgs e)
{
FormSize.X = Width;
FormSize.Y = Height;
FormSize.Save();
}

#region ProxyMode

Expand All @@ -97,7 +120,7 @@ private void rdoGlobal_CheckedChanged(object sender, EventArgs e)
}

SyncRunModeToView(SyncMode.RadioToTsm);
SaveConfig();
Config.Save();
}

private void rdoGfwlist_CheckedChanged(object sender, EventArgs e)
Expand All @@ -108,7 +131,7 @@ private void rdoGfwlist_CheckedChanged(object sender, EventArgs e)
}

SyncRunModeToView(SyncMode.RadioToTsm);
SaveConfig();
Config.Save();
}

private void rdoGeoIP_CheckedChanged(object sender, EventArgs e)
Expand All @@ -119,7 +142,7 @@ private void rdoGeoIP_CheckedChanged(object sender, EventArgs e)
}

SyncRunModeToView(SyncMode.RadioToTsm);
SaveConfig();
Config.Save();
}

private void rdoNone_CheckedChanged(object sender, EventArgs e)
Expand All @@ -130,7 +153,7 @@ private void rdoNone_CheckedChanged(object sender, EventArgs e)
}

SyncRunModeToView(SyncMode.RadioToTsm);
SaveConfig();
Config.Save();
}

#endregion
Expand Down Expand Up @@ -446,10 +469,6 @@ private void btnAddNode_Click(object sender, EventArgs e)
tnc.Add(new TreeNode() {Text = "default", Tag = "naive+https://default:default@default#default"});
}

private void btnDelNode_Click(object sender, EventArgs e)
{
}

private void lblAddGroup_Click(object sender, EventArgs e)
{
string group = "Default";
Expand Down
10 changes: 0 additions & 10 deletions NaiveSharp/View/MainWindowsEx.cs
Expand Up @@ -178,16 +178,6 @@ private static string LoadModeConfig()
return "global";
}

private static void SaveConfig()
{
if (!File.Exists(PATH.CONFIG_INI))
{
File.Create(PATH.CONFIG_INI).Close();
}

File.WriteAllText(PATH.CONFIG_INI, $"mode = {Config.RunMode}");
}

private void CheckPath()
{
CheckDirectory(PATH.CONFIG);
Expand Down
7 changes: 0 additions & 7 deletions NaiveSharp/View/Qr.cs
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


Expand Down

0 comments on commit 668497e

Please sign in to comment.