@@ -12,7 +12,7 @@ namespace Vight_Note
1212{
1313 public partial class MainForm : System . Windows . Forms . Form
1414 {
15- public static class Define
15+ private static class Define
1616 {
1717 public const string NAME = @"Vight Note" ;
1818 public static readonly string VERSION = Application . ProductVersion ;
@@ -32,11 +32,11 @@ public static class Define
3232 public const string BAIDU_TRANSLATE_API = @"https://fanyi.baidu.com/#zh/en/" ;
3333
3434 public const string EMAIL_REGEX = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" ;
35-
36- public static bool CHANGE_MARK = false ;
37- public static string FILE_PATH = @"" ;
3835 }
3936
37+ private static bool CHANGE_MARK = false ;
38+ private static string FILE_PATH = @"" ;
39+
4040 public MainForm ( string [ ] args )
4141 {
4242 InitializeComponent ( ) ;
@@ -47,7 +47,7 @@ public MainForm(string[] args)
4747 //拖拽至图标打开文件
4848 if ( args . Length >= 1 )
4949 {
50- Define . FILE_PATH = args [ 0 ] ;
50+ FILE_PATH = args [ 0 ] ;
5151 ImportFile ( ) ;
5252 }
5353 }
@@ -132,7 +132,7 @@ private void Close_Click(object sender, EventArgs e)
132132 private void Save_Click ( object sender , EventArgs e )
133133 {
134134 //显示文件保存窗口,向用户获取保存路径
135- if ( sender == Export || Define . FILE_PATH == "" )
135+ if ( sender == Export || FILE_PATH == "" )
136136 {
137137 SaveFileDialog saveDialog = new SaveFileDialog ( ) ;
138138
@@ -152,19 +152,19 @@ private void Save_Click(object sender, EventArgs e)
152152 if ( saveDialog . ShowDialog ( ) != DialogResult . OK )
153153 return ;
154154 else
155- Define . FILE_PATH = saveDialog . FileName . ToString ( ) ; //文件路径
155+ FILE_PATH = saveDialog . FileName . ToString ( ) ; //文件路径
156156 }
157157
158158 //写文件
159- FileStream saver = new FileStream ( Define . FILE_PATH , FileMode . Create , FileAccess . ReadWrite , FileShare . ReadWrite | FileShare . Delete ) ;
159+ FileStream saver = new FileStream ( FILE_PATH , FileMode . Create , FileAccess . ReadWrite , FileShare . ReadWrite | FileShare . Delete ) ;
160160 StreamWriter writer = new StreamWriter ( saver ) ;
161161 writer . Write ( TextBox . Text ) ;
162162 writer . Flush ( ) ;
163163 writer . Close ( ) ;
164164 saver . Close ( ) ;
165165
166- Text = Path . GetFileName ( Define . FILE_PATH ) ;
167- Define . CHANGE_MARK = false ;
166+ Text = Path . GetFileName ( FILE_PATH ) ;
167+ CHANGE_MARK = false ;
168168 }
169169 private void Export_Click ( object sender , EventArgs e )
170170 {
@@ -192,7 +192,7 @@ private void Import_Click(object sender, EventArgs e)
192192
193193 if ( openDialog . ShowDialog ( ) == DialogResult . OK )
194194 {
195- Define . FILE_PATH = openDialog . FileName . ToString ( ) ; //文件路径
195+ FILE_PATH = openDialog . FileName . ToString ( ) ; //文件路径
196196 ImportFile ( ) ;
197197 }
198198 }
@@ -378,14 +378,21 @@ private void Run_Click(object sender, EventArgs e)
378378 else
379379 Process . Start ( TextBox . SelectedText ) ; //文件路径
380380 }
381- catch
381+ catch //百度搜索
382382 {
383- Process . Start ( Define . BAIDU_SEARCH_API + Uri . EscapeDataString ( TextBox . SelectedText ) ) ; //百度搜索
383+ if ( TextBox . SelectionLength > 3628 )
384+ Process . Start ( Define . BAIDU_SEARCH_API + Uri . EscapeDataString ( TextBox . SelectedText . Substring ( 0 , 3628 ) ) ) ; //最长32659(编码后汉字长度x9)
385+ else
386+ Process . Start ( Define . BAIDU_SEARCH_API + Uri . EscapeDataString ( TextBox . SelectedText ) ) ; //正常选择
384387 }
385388 }
386389 private void Translate_Click ( object sender , EventArgs e )
387390 {
388- Process . Start ( Define . BAIDU_TRANSLATE_API + TextBox . SelectedText ) ; //百度翻译
391+ //百度翻译
392+ if ( TextBox . SelectionLength > 32650 )
393+ Process . Start ( Define . BAIDU_TRANSLATE_API + TextBox . SelectedText . Substring ( 0 , 32655 ) ) ; //最长32655
394+ else
395+ Process . Start ( Define . BAIDU_TRANSLATE_API + TextBox . SelectedText ) ; //正常选择
389396 }
390397
391398 //拖放
@@ -401,7 +408,7 @@ private void TextBox_DragDrop(object sender, DragEventArgs e)
401408 if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
402409 {
403410 string [ ] path = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
404- Define . FILE_PATH = path [ 0 ] ;
411+ FILE_PATH = path [ 0 ] ;
405412 ImportFile ( ) ;
406413 }
407414 }
@@ -504,10 +511,10 @@ private void LiteShortcut(bool turnOn)
504511 //文件未保存标记
505512 private void TextBox_TextChanged ( object sender , EventArgs e )
506513 {
507- if ( ! Define . CHANGE_MARK )
514+ if ( ! CHANGE_MARK )
508515 {
509516 Text += "*" ;
510- Define . CHANGE_MARK = true ;
517+ CHANGE_MARK = true ;
511518 }
512519 }
513520 //导入
@@ -517,7 +524,7 @@ private void ImportFile()
517524 if ( LockTextBox . Checked )
518525 return ;
519526
520- if ( ! System . IO . File . Exists ( Define . FILE_PATH ) || ! LiteMode . Checked && ( ( Path . GetExtension ( Define . FILE_PATH ) != ".txt" && Path . GetExtension ( Define . FILE_PATH ) != ".vtxt" ) ) )
527+ if ( ! System . IO . File . Exists ( FILE_PATH ) || ! LiteMode . Checked && ( ( Path . GetExtension ( FILE_PATH ) != ".txt" && Path . GetExtension ( FILE_PATH ) != ".vtxt" ) ) )
521528 {
522529 //非正常后缀提示
523530 MessageBox . Show ( "请不要往我里面塞奇怪的东西..." ) ;
@@ -533,15 +540,15 @@ private void ImportFile()
533540 }
534541
535542 //读文件
536- FileStream importer = new FileStream ( Define . FILE_PATH , FileMode . OpenOrCreate , FileAccess . ReadWrite , FileShare . ReadWrite | FileShare . Delete ) ;
543+ FileStream importer = new FileStream ( FILE_PATH , FileMode . OpenOrCreate , FileAccess . ReadWrite , FileShare . ReadWrite | FileShare . Delete ) ;
537544 StreamReader reader = new StreamReader ( importer ) ;
538545 TextBox . Text = reader . ReadToEnd ( ) ;
539546
540- Text = Path . GetFileName ( Define . FILE_PATH ) ;
541- Define . CHANGE_MARK = false ;
547+ Text = Path . GetFileName ( FILE_PATH ) ;
548+ CHANGE_MARK = false ;
542549 }
543550 //字符串格式匹配
544- public static bool CheckStrFormat ( string regexRule , string strValue )
551+ private bool CheckStrFormat ( string regexRule , string strValue )
545552 {
546553 Regex regex = new Regex ( regexRule ) ;
547554 return regex . IsMatch ( strValue ) ;
0 commit comments