Browse Source

combine duplicated code

tags/2.3
clowwindy 10 years ago
parent
commit
082494d587
2 changed files with 18 additions and 37 deletions
  1. +3
    -4
      shadowsocks-csharp/Data/cn.txt
  2. +15
    -33
      shadowsocks-csharp/View/MenuViewController.cs

+ 3
- 4
shadowsocks-csharp/Data/cn.txt View File

@@ -39,7 +39,6 @@ Shadowsocks is here=Shadowsocks 在这里
You can turn on/off Shadowsocks in the context menu=可以在右键菜单中开关 Shadowsocks You can turn on/off Shadowsocks in the context menu=可以在右键菜单中开关 Shadowsocks
Enabled=已启用代理 Enabled=已启用代理
Disabled=已禁用代理 Disabled=已禁用代理
Update PAC File via gfwlist...=基于 gfwlist 更新 PAC 文件...
Update PAC file failed=更新 PAC 文件失败
Update PAC file succeed=更新 PAC 文件成功
Job already running...=任务已经运行...
Update PAC File via GFWList...=从 GFWList 更新 PAC 文件...
Failed to update PAC file =更新 PAC 文件失败
PAC updated=更新 PAC 成功

+ 15
- 33
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
@@ -33,8 +34,6 @@ namespace Shadowsocks.View
private MenuItem PACModeItem; private MenuItem PACModeItem;
private ConfigForm configForm; private ConfigForm configForm;
private bool isUpdatePACFromGFWListRunning = false;
public MenuViewController(ShadowsocksController controller) public MenuViewController(ShadowsocksController controller)
{ {
this.controller = controller; this.controller = controller;
@@ -181,38 +180,36 @@ namespace Shadowsocks.View
System.Diagnostics.Process.Start("explorer.exe", argument); System.Diagnostics.Process.Start("explorer.exe", argument);
} }
void controller_UpdatePACFromGFWListError(object sender, System.IO.ErrorEventArgs e)
void ShowBalloonTip(string title, string content, ToolTipIcon icon, int timeout)
{
_notifyIcon.BalloonTipTitle = title;
_notifyIcon.BalloonTipText = content;
_notifyIcon.BalloonTipIcon = icon;
_notifyIcon.ShowBalloonTip(timeout);
}
void controller_UpdatePACFromGFWListError(object sender, ErrorEventArgs e)
{ {
isUpdatePACFromGFWListRunning = false;
_notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist...");
_notifyIcon.BalloonTipText = I18N.GetString("Update PAC file failed");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
_notifyIcon.ShowBalloonTip(5000);
ShowBalloonTip(I18N.GetString("Failed to update PAC file"), e.GetException().Message, ToolTipIcon.Error, 5000);
Logging.LogUsefulException(e.GetException()); Logging.LogUsefulException(e.GetException());
} }
void controller_UpdatePACFromGFWListCompleted(object sender, EventArgs e) void controller_UpdatePACFromGFWListCompleted(object sender, EventArgs e)
{ {
isUpdatePACFromGFWListRunning = false;
_notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist...");
_notifyIcon.BalloonTipText = I18N.GetString("Update PAC file succeed");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
_notifyIcon.ShowBalloonTip(5000);
ShowBalloonTip(I18N.GetString("Shadowsocks"), I18N.GetString("PAC updated"), ToolTipIcon.Info, 1000);
} }
void updateChecker_NewVersionFound(object sender, EventArgs e) void updateChecker_NewVersionFound(object sender, EventArgs e)
{ {
_notifyIcon.BalloonTipTitle = String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber);
_notifyIcon.BalloonTipText = I18N.GetString("Click here to download");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
ShowBalloonTip(String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber), I18N.GetString("Click here to download"), ToolTipIcon.Info, 5000);
_notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked; _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
_notifyIcon.ShowBalloonTip(5000);
_isFirstRun = false; _isFirstRun = false;
} }
void notifyIcon1_BalloonTipClicked(object sender, EventArgs e) void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
{ {
System.Diagnostics.Process.Start(updateChecker.LatestVersionURL); System.Diagnostics.Process.Start(updateChecker.LatestVersionURL);
_notifyIcon.BalloonTipClicked -= notifyIcon1_BalloonTipClicked;
} }
@@ -337,22 +334,7 @@ namespace Shadowsocks.View
private void UpdatePACFromGFWListItem_Click(object sender, EventArgs e) private void UpdatePACFromGFWListItem_Click(object sender, EventArgs e)
{ {
if (isUpdatePACFromGFWListRunning)
{
_notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist...");
_notifyIcon.BalloonTipText = I18N.GetString("Job already running...");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
_notifyIcon.ShowBalloonTip(5000);
}
else
{
isUpdatePACFromGFWListRunning = true;
_notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version;
_notifyIcon.BalloonTipText = I18N.GetString("Update PAC File via gfwlist...");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
_notifyIcon.ShowBalloonTip(5000);
controller.UpdatePACFromGFWList();
}
controller.UpdatePACFromGFWList();
} }
private void AServerItem_Click(object sender, EventArgs e) private void AServerItem_Click(object sender, EventArgs e)


Loading…
Cancel
Save