OSDN Git Service

252577b371bdb383afe95b2252616ce3cb04a419
[winmerge-jp/winmerge-jp.git] / Plugins / dlls / editor addin.sct
1 <scriptlet>
2
3 <implements type="Automation" id="dispatcher">
4         <property name="PluginEvent">
5                   <get/>
6         </property>
7         <property name="PluginDescription">
8                   <get/>
9         </property>
10         <method name="MakeUpper"/>
11         <method name="MakeLower"/>
12         <method name="SortAscending"/>
13         <method name="SortDescending"/>
14         <method name="ExecFilterCommand"/>
15 </implements>
16
17 <script language="VBS">
18 Option Explicit
19
20 Function get_PluginEvent()
21          get_PluginEvent = "EDITOR_SCRIPT"
22 End Function
23
24 Function get_PluginDescription()
25          get_PluginDescription = "Basic text functions for the context menu"
26 End Function
27
28 Function IsLangJapanese()
29     Dim languageId
30     languageId = 1033
31     On Error Resume Next
32     languageId = CLng(wsh.RegRead(REGKEY_PATH & "\Locale\LanguageId"))
33     IsLangJapanese = (languageId = 1041)
34 End Function
35
36 ' transformation functions
37 Function MakeUpper(Text)
38         MakeUpper = UCase(Text)
39 End Function
40
41 Function MakeLower(Text)
42         MakeLower = LCase(Text)
43 End Function
44
45 Function ExecFilterCommand(Text)
46         Dim cmd
47         If IsLangJapanese() Then
48                 cmd = InputBox("\8c»\8dÝ\82Ì\91I\91ð\94Í\88Í\82Ì\95\8e\9a\97ñ\82ð\83t\83B\83\8b\83^\83R\83}\83\93\83h\82Å\8f\88\97\9d\82µ\82½\8c\8b\89Ê\82Å\92u\8a·\82µ\82Ü\82·\81B\83R\83}\83\93\83h\82ð\93ü\97Í\82µ\82Ä\82­\82¾\82³\82¢\81B")
49         Else
50                 cmd = InputBox("Enter filter command to replace the selection.")
51         End If
52         If cmd = "" Then
53                 If IsLangJapanese() Then
54                         Err.Raise 30001, , "\83L\83\83\83\93\83Z\83\8b\82³\82ê\82Ü\82µ\82½"
55                 Else
56                         Err.Raise 30001, , "Canceled"
57                 End If
58                 Exit Function
59         End If
60
61         On Error Resume Next
62
63         Dim wsh
64         Dim path
65         Set wsh = CreateObject("WScript.Shell")
66         path = wsh.ExpandEnvironmentStrings("%TEMP%\_winmerge_addin_temp_.txt")
67
68         Dim fso
69         Dim ts
70         Set fso = CreateObject("Scripting.FileSystemObject")
71         Set ts = fso.CreateTextFile(path)
72         If ts Is Nothing Then
73                 Exit Function
74         End If
75         ts.Write Text
76         ts.Close
77
78         Dim exe
79         Set exe = wsh.Exec("cmd /c type """ & path & """  | " & cmd & " 2>&1")
80         If exe Is Nothing Then
81                 If IsLangJapanese() Then
82                         MsgBox "\83R\83}\83\93\83h " & cmd & " \82Ì\8eÀ\8ds\82É\8e¸\94s\82µ\82Ü\82µ\82½:" & Err.Description 
83                 Else
84                         MsgBox "Failed to execute the command '" & cmd & "':" & Err.Description 
85                 End If
86                 fso.DeleteFile path
87                 Exit Function
88         End If
89
90         ExecFilterCommand = ""
91         Do Until exe.StdOut.AtEndOfStream
92                 ExecFilterCommand = ExecFilterCommand & exe.StdOut.ReadLine & vbCrLf
93         Loop
94
95         fso.DeleteFile path
96
97 End Function
98
99
100 </script>
101
102 <script language="JScript">
103
104 function SortAscending(Text) {
105         var eol = Text.match(/\r\n|\n|\r/);
106         var lines = Text.split(eol);
107
108         if (lines.length == 1) {
109                 return Text;
110         } else if (lines[lines.length - 1] == "") {
111                 lines.pop();
112                 return lines.sort().join(eol) + eol;
113         } else {
114                 return lines.sort().join(eol);
115         }
116 }
117
118 function SortDescending(Text) {
119         var eol = Text.match(/\r\n|\n|\r/);
120         var lines = Text.split(eol);
121
122         if (lines.length == 1) {
123                 return Text;
124         } else if (lines[lines.length - 1] == "") {
125                 lines.pop();
126                 lines.sort(function(a, b) { return a < b ? 1 : -1; });
127                 return lines.join(eol) + eol;
128         } else {
129                 return lines.sort(function(a, b) { return a < b ? 1 : -1; }).join(eol);
130         }
131 }
132
133 </script>
134
135 </scriptlet>