Changeset 13
- Timestamp:
- Feb 8, 2021, 4:23:17 PM (4 years ago)
- Location:
- Common
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/ComboBoxEx.cs
r3 r13 1 using System;1 using System; 2 2 using System.Collections.Generic; 3 3 using System.ComponentModel; … … 31 31 if (index >= 0) Items.RemoveAt(index); 32 32 Text = previousText; 33 Items.Insert(0, Text);33 Items.Insert(0, previousText); 34 34 35 35 while (Items.Count > maxHistoryCount) -
Common/ExtTools.cs
r8 r13 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 1 using System; 6 2 using System.IO; 7 3 using System.Diagnostics; 8 4 using System.Windows.Forms; 5 using Microsoft.Win32; 6 using System.Runtime.InteropServices; 9 7 10 8 namespace Common … … 12 10 static class ExtTools 13 11 { 14 public static string compareProgram;15 public static string compareAttributes;12 public static string CompareProgram; 13 public static string CompareAttributes; 16 14 17 15 static ExtTools() 18 16 { 19 17 // Autodetect location of Beyond Compare executable 20 compareProgram = "C:\\Program Files\\Beyond Compare 4\\BCompare.exe";21 if (!File.Exists( compareProgram)) compareProgram = "C:\\Program Files (x86)\\Beyond Compare 4\\BCompare.exe";22 if (!File.Exists( compareProgram)) compareProgram = "C:\\Program Files\\Beyond Compare 3\\BCompare.exe";23 if (!File.Exists( compareProgram)) compareProgram = "C:\\Program Files (x86)\\Beyond Compare 3\\BCompare.exe";18 CompareProgram = "C:\\Program Files\\Beyond Compare 4\\BCompare.exe"; 19 if (!File.Exists(CompareProgram)) CompareProgram = "C:\\Program Files (x86)\\Beyond Compare 4\\BCompare.exe"; 20 if (!File.Exists(CompareProgram)) CompareProgram = "C:\\Program Files\\Beyond Compare 3\\BCompare.exe"; 21 if (!File.Exists(CompareProgram)) CompareProgram = "C:\\Program Files (x86)\\Beyond Compare 3\\BCompare.exe"; 24 22 25 compareAttributes = "\"<<left_file>>\" \"<<right_file>>\"";23 CompareAttributes = "\"<<left_file>>\" \"<<right_file>>\""; 26 24 } 27 25 … … 29 27 { 30 28 return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + 31 System.Windows.Forms.Application.ProductName + "\\Temp";29 Application.ProductName + "\\Temp"; 32 30 } 33 31 … … 51 49 { 52 50 // Execute comparison process 53 string att s = compareAttributes;54 att s = atts.Replace("<<left_file>>", filenameLeft);55 att s = atts.Replace("<<right_file>>", filenameRight);56 ExecuteProgram( compareProgram, atts);51 string attributes = CompareAttributes; 52 attributes = attributes.Replace("<<left_file>>", filenameLeft); 53 attributes = attributes.Replace("<<right_file>>", filenameRight); 54 ExecuteProgram(CompareProgram, attributes); 57 55 } catch (Exception e) 58 56 { 59 MessageBox.Show(e.Message .ToString());57 MessageBox.Show(e.Message); 60 58 } 61 59 } 62 60 63 public static void ExecuteProgram(string executableFileName, string arguments , string workingDirectory = "")61 public static void ExecuteProgram(string executableFileName, string arguments = "", string workingDirectory = "") 64 62 { 65 63 // Execute external process … … 106 104 } 107 105 return output; 108 } 106 } 107 108 public static void SetFileAssociation(string extension, string progId, string openWith, string fileDescription) 109 { 110 RegistryKey BaseKey; 111 RegistryKey OpenMethod; 112 RegistryKey Shell; 113 RegistryKey CurrentUser; 114 115 BaseKey = Registry.ClassesRoot.CreateSubKey(extension); 116 BaseKey?.SetValue("", progId); 117 118 OpenMethod = Registry.ClassesRoot.CreateSubKey(progId); 119 OpenMethod?.SetValue("", fileDescription); 120 OpenMethod?.CreateSubKey("DefaultIcon")?.SetValue("", "\"" + openWith + "\",0"); 121 Shell = OpenMethod?.CreateSubKey("Shell"); 122 Shell?.CreateSubKey("edit")?.CreateSubKey("command")?.SetValue("", "\"" + openWith + "\"" + " \"%1\""); 123 Shell?.CreateSubKey("open")?.CreateSubKey("command")?.SetValue("", "\"" + openWith + "\"" + " \"%1\""); 124 Shell?.Close(); 125 OpenMethod?.Close(); 126 BaseKey?.Close(); 127 128 // Delete explorer override 129 CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + extension, true); 130 CurrentUser?.DeleteSubKey("UserChoice", false); 131 CurrentUser?.Close(); 132 133 // Tell explorer the file association has been changed 134 SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero); 135 } 136 137 [DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true)] 138 public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); 109 139 } 110 140 } -
Common/FormFind.cs
r3 r13 1 using System;1 using System; 2 2 using System.Collections.Generic; 3 3 using System.ComponentModel; … … 96 96 Theme.UseTheme(this); 97 97 DpiScaling.Apply(this); 98 this.Icon = Icon.ExtractAssociatedIcon(Application.Execut ablePath);98 this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); 99 99 new FormDimensions().Load(this, Owner); 100 100 comboBoxWhat.Focus(); -
Common/Prompt.cs
r12 r13 284 284 SaveFileDialog saveFileDialog = new SaveFileDialog() 285 285 { 286 Filter = fileType + " (." + fileExtension + ")|*." +286 Filter = fileType + "|*." + 287 287 fileExtension + "|Any file|*.*", 288 288 DefaultExt = fileExtension -
Common/Registry.cs
r9 r13 1 using System;1 using System; 2 2 using System.Collections.Generic; 3 3 using System.Linq; … … 35 35 } 36 36 37 public static long GetValueLong(this RegistryKey regKey, string name, long defaultValue) 38 { 39 object value = regKey.GetValue(name, defaultValue); 40 if (value is long) return (long)value; 41 else return defaultValue; 42 } 43 37 44 public static float GetValueFloat(this RegistryKey regKey, string name, float defaultValue) 38 45 { 39 46 object value = regKey.GetValue(name, defaultValue.ToString()); 40 float num;41 if (float.TryParse((string)value, out num))47 if (float.TryParse((string) value, out float num)) 48 { 42 49 return num; 50 } 43 51 else return defaultValue; 44 52 } … … 60 68 } 61 69 70 public static void SetValueLong(this RegistryKey regKey, string name, long value) 71 { 72 regKey.SetValue(name, value); 73 } 74 62 75 public static void SetValueFloat(this RegistryKey regKey, string name, float value) 63 76 { -
Common/RichTextBoxEx.cs
r1 r13 1 using System;1 using System; 2 2 using System.Collections.Generic; 3 using System.ComponentModel;4 using System.Data;5 3 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 4 using System.Runtime.InteropServices; 9 5 using System.Windows.Forms; 10 6 … … 66 62 List<string> linkMatchStartString = new List<string>(); 67 63 foreach (var linkMatch in linkMatches) 68 linkMatchStartString.Add(linkMatch.startString.ToLower ());64 linkMatchStartString.Add(linkMatch.startString.ToLowerInvariant()); 69 65 70 66 string content = richTextBox.Text; 71 string contentLowerCase = content.ToLower ();67 string contentLowerCase = content.ToLowerInvariant(); 72 68 73 69 RichTextBox tempRichTextBox = new RichTextBox(); … … 149 145 } 150 146 151 [ System.Runtime.InteropServices.DllImport("user32.dll")]147 [DllImport("user32.dll")] 152 148 private static extern int SendMessage(IntPtr hwndLock, Int32 wMsg, Int32 wParam, Int32 lParam); 153 149 … … 192 188 RichTextBoxContext context = new RichTextBoxContext(); 193 189 context.SaveContext(this); 194 //SelectionStart = 0; 195 SelectAll(); 196 SelectedRtf = previousRtf; 190 Rtf = previousRtf; 197 191 UndoUnknownActions(); 198 192 … … 279 273 if (link != "") 280 274 { 281 int number;282 275 foreach (var linkMatch in linkMatches) 283 276 { 284 277 if ((link.Length >= linkMatch.startString.Length) && ( 285 278 (linkMatch.caseSensitive && (link.Substring(0, linkMatch.startString.Length) == linkMatch.startString)) || 286 (!linkMatch.caseSensitive && (link.ToLower ().Substring(0, linkMatch.startString.Length) == linkMatch.startString.ToLower()))))279 (!linkMatch.caseSensitive && (link.ToLowerInvariant().Substring(0, linkMatch.startString.Length) == linkMatch.startString.ToLower())))) 287 280 { 288 281 string linkNumber = link.Substring(linkMatch.startString.Length).Trim(new char[] { ' ', '#' }); 289 if (int.TryParse(linkNumber, out number))282 if (int.TryParse(linkNumber, out int number)) 290 283 { 291 284 linkMatch.ExecuteLinkAction(number); … … 314 307 StartPosition = FormStartPosition.CenterScreen, 315 308 }; 316 textForm.Icon = Icon.ExtractAssociatedIcon(Application.Execut ablePath);309 textForm.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); 317 310 RichTextBoxEx richTextBox = new RichTextBoxEx(); 318 311 richTextBox.parentForm = textForm; … … 446 439 formFind = new FormFind(); 447 440 formFind.richTextBox = this; 448 formFind.Owner = this.parentForm;441 formFind.Owner = parentForm; 449 442 } 450 443 formFind.Show(); … … 463 456 cms.Items.Add(tsmiShowInWindow); 464 457 465 cms.Opening += delegate (object sender, CancelEventArgs e)458 cms.Opening += delegate 466 459 { 467 460 HideLinks(); … … 481 474 private int oldLength; 482 475 483 [ System.Runtime.InteropServices.DllImport("user32.dll")]484 private extern staticIntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);485 [ System.Runtime.InteropServices.DllImport("user32.dll")]476 [DllImport("user32.dll")] 477 private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); 478 [DllImport("user32.dll")] 486 479 private static extern int SendMessage(IntPtr hwndLock, Int32 wMsg, Int32 wParam, ref Point pt); 487 [ System.Runtime.InteropServices.DllImport("User32.dll")]488 extern staticint GetScrollPos(IntPtr hWnd, int nBar);489 [ System.Runtime.InteropServices.DllImport("user32.dll")]480 [DllImport("User32.dll")] 481 static extern int GetScrollPos(IntPtr hWnd, int nBar); 482 [DllImport("user32.dll")] 490 483 static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw); 491 484 … … 542 535 public void ExecuteLinkAction(int number) 543 536 { 544 LinkAction (number);537 LinkAction?.Invoke(number); 545 538 } 546 539 … … 573 566 number = content.Substring(numberStart, i); 574 567 575 int intNumber = 0; 576 if (int.TryParse(number, out intNumber)) 568 if (int.TryParse(number, out int intNumber)) 577 569 { 578 570 linkLength += number.Length; -
Common/SuspendDrawing.cs
r5 r13 1 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 2 using System.Runtime.InteropServices; 6 3 using System.Windows.Forms; 7 4 … … 10 7 class SuspendDrawing 11 8 { 12 [ System.Runtime.InteropServices.DllImport("user32.dll")]9 [DllImport("user32.dll")] 13 10 private static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam); 14 11 private const int WM_SETREDRAW = 11; -
Common/Theme.cs
r12 r13 87 87 else if (color == Color.LightGray) color = Color.DarkGray; 88 88 else if (color == Color.DarkGray) color = Color.LightGray; 89 else if (color == Color.Orchid) color = Color.DarkOrchid; 90 else if (color == Color.DarkOrchid) color = Color.Orchid; 89 91 } 90 92 }
Note:
See TracChangeset
for help on using the changeset viewer.