Develop and Download Open Source Software

Browse Subversion Repository

Contents of /CopalPro/StdError.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Thu Jul 28 09:05:52 2011 UTC (12 years, 9 months ago) by kaityo
File MIME type: text/x-c++src
File size: 7525 byte(s)
First Commit
1 //---------------------------------------------------------------------------
2 // 標準エラー出力を表示するフォーム
3 //---------------------------------------------------------------------------
4 #include <vcl.h>
5 #pragma hdrstop
6
7 #include "Main.h"
8 #include "StdError.h"
9 #include "KRegexp.h"
10 //---------------------------------------------------------------------------
11 #pragma package(smart_init)
12 #pragma link "Base"
13 #pragma resource "*.dfm"
14 TFStdError *FStdError;
15 //---------------------------------------------------------------------------
16 __fastcall
17 TFStdError::TFStdError(TComponent* Owner)
18 : TFBase(Owner) {
19 //自分をドッキングする
20 Caption = "Error";
21 Width = 400;
22 Height = 400;
23 ManualDock(FMain->PStdError,FMain->PStdError,alClient);
24 Visible = true;
25 }
26 //---------------------------------------------------------------------------
27 void
28 TFStdError::LoadFromStream(TStream *Stream) {
29 LBStdError->Items->LoadFromStream(Stream);
30 if(Stream->Size!=0) {
31 FMain->OpenError();
32 }
33 }
34 //---------------------------------------------------------------------------
35 void
36 TFStdError::Find(void) {
37 FMain->ChangeWindow(SCRIPT_WINDOW);
38 FScript->Find();
39 }
40 //---------------------------------------------------------------------------
41 bool
42 TFStdError::IsEmpty(void) {
43 if(LBStdError->Items->Text.Length()==0){
44 return true;
45 }else{
46 return false;
47 }
48 }
49 //---------------------------------------------------------------------------
50 // クリップボード
51 //---------------------------------------------------------------------------
52 /**
53 * コピー
54 */
55 void
56 TFStdError::Copy(void) {
57 TClipboard *Co = Clipboard();
58 AnsiString as1;
59 for (int i=0;i<LBStdError->Items->Count;i++) {
60 if(LBStdError->Selected[i]) {
61 as1 = as1 + LBStdError->Items->Strings[i]+"\r\n";
62 }
63 }
64 if(as1.Length()==0) {
65 return;
66 }
67 Co->AsText = as1;
68 }
69 //---------------------------------------------------------------------------
70 /**
71 * 貼り付け
72 */
73 void
74 TFStdError::Paste(void) {
75 ShowMessage("Error window is read only.");
76 }
77 //---------------------------------------------------------------------------
78 /**
79 * 切り取り
80 */
81 void
82 TFStdError::Cut(void) {
83 ShowMessage("Error window is read only.");
84 }
85 //---------------------------------------------------------------------------
86 /**
87 * 保存
88 */
89 void
90 TFStdError::Save(void) {
91 FMain->SaveDialog->Filter = "All Files(*.*)|*.*";
92 FMain->SaveDialog->Title = "エラー結果を保存";
93 if(!FMain->SaveDialog->Execute()) {
94 return;
95 }
96 LBStdError->Items->SaveToFile(FMain->SaveDialog->FileName);
97 }
98 //---------------------------------------------------------------------------
99 /**
100 * ステータスバー表示用の文字列を返す
101 */
102 AnsiString
103 TFStdError::GetCaretString(void) {
104 int line = LBStdError->ItemIndex;
105 int selected = 0;
106 for (int i=0;i<LBStdError->Items->Count;i++) {
107 if(LBStdError->Selected[i]) {
108 selected ++;
109 }
110 }
111 if(line ==-1) {
112 return "";
113 }
114 if(selected >1){
115 return IntToStr(line+1) + " (" + IntToStr(selected) + ")";
116 }else{
117 return IntToStr(line+1);
118 }
119 }
120 //---------------------------------------------------------------------------
121 void __fastcall
122 TFStdError::FormActivate(TObject *Sender) {
123 FMain->ChangeWindow(ERROR_WINDOW);
124 }
125 //---------------------------------------------------------------------------
126 void __fastcall
127 TFStdError::FormHide(TObject *Sender) {
128 FMain->CloseError();
129 }
130 //---------------------------------------------------------------------------
131 void __fastcall
132 TFStdError::LBStdErrorDblClick(TObject *Sender) {
133
134 int line = GetErrorLineNumber();
135 if (line == -1) {
136 return;
137 }
138
139 AnsiString FileName = FScript->GetFileName();
140 //外部エディタにタグジャンプをする
141 if(FileName!="" && FMain->GetCopalConfig()->UseTagJump) {
142
143 //保存の確認
144 //保存されてなければタグジャンプしない
145 if (!FScript->SaveQuery()) {
146 return;
147 }
148
149 //異なるファイルにタグジャンプする
150 if(FMain->GetCopalConfig()->GetUseTagJumpToOtherFile()) {
151 AnsiString asLine = LBStdError->Items->Strings[LBStdError->ItemIndex];
152 AnsiString asRegExp = FMain->GetCopalConfig()->GetRegExpFile();
153 if(!KRegexp::GetMatchStr(asLine,asRegExp) || KRegexp::Pattern[1] =="") {
154 return;
155 }
156 FileName = KRegexp::Pattern[1];
157 if(FileName.LowerCase() == FMain->GetCopalConfig()->GetTempFile().LowerCase()) {
158 FileName = FScript->GetFileName();
159 }
160 }
161
162 if(FMain->GetCopalConfig()->UseDoubleQuotes) {
163 FileName = "\""+FileName+"\"";
164 }
165
166 char *editor = FMain->GetCopalConfig()->Editor.c_str();
167 char *option = GetTagJumpText(FileName,line).c_str();
168
169 if(!FileExists(FMain->GetCopalConfig()->Editor)) {
170 ShowMessage(FMain->GetCopalConfig()->Editor+"が見つかりません。パスを確認してください。");
171 return;
172 }
173 ShellExecute(this->Handle,NULL,editor,option,NULL,SW_SHOW);
174 } else {
175 //Copalのエディタでエラー行ジャンプする
176 FMain->ChangeWindow(SCRIPT_WINDOW);
177 FScript->LineJump(line);
178 }
179
180 }
181 //---------------------------------------------------------------------------
182 int
183 TFStdError::GetErrorLineNumber(void) {
184
185 AnsiString asLine = LBStdError->Items->Strings[LBStdError->ItemIndex];
186 AnsiString asRegExp = FMain->GetCopalConfig()->GetRegExpErr();
187 if(!KRegexp::GetMatchStr(asLine,asRegExp)) {
188 return -1;
189 }
190 asLine = KRegexp::Pattern[0];
191 if(!KRegexp::GetMatchStr(asLine,"[0-9]+")) {
192 return -1;
193 }
194
195 int line = StrToIntDef(KRegexp::Pattern[0],-1);
196 return line;
197 }
198 //---------------------------------------------------------------------------
199 /**
200 * タグジャンプ用のオプション文字列を返す
201 * line エラー行
202 * FileName ファイル名
203 */
204 AnsiString
205 TFStdError::GetTagJumpText(AnsiString FileName,int line) {
206 KCopalConfig *CopalConfig = FMain->GetCopalConfig();
207 AnsiString TagJumpText = CopalConfig->GetTagJumpText();
208 AnsiString as;
209 char *buf = TagJumpText.c_str();
210 int length = TagJumpText.Length();
211
212 for(int i=0;i<length;i++) {
213 if(buf[i]=='%' && i<length-1 ) {
214 switch(buf[i+1]) {
215 case 'L':
216 as += IntToStr(line);
217 i++;
218 break;
219 case 'F':
220 as += FileName;
221 i++;
222 break;
223 }
224 } else {
225 as += buf[i];
226 }
227 }
228 return as;
229 }
230 //---------------------------------------------------------------------------
231 void __fastcall
232 TFStdError::PMCopyClick(TObject *Sender) {
233 FMain->MMCopy->Click();
234 }
235 //---------------------------------------------------------------------------
236 void __fastcall
237 TFStdError::LBStdErrorMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) {
238 FMain->UpdateStatusBar();
239 }
240 //---------------------------------------------------------------------------
241 void __fastcall
242 TFStdError::LBStdErrorKeyPress(TObject *Sender, char &Key) {
243 FMain->UpdateStatusBar();
244 }
245 //---------------------------------------------------------------------------
246 void __fastcall
247 TFStdError::LBStdErrorKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) {
248 FMain->UpdateStatusBar();
249 }
250 //---------------------------------------------------------------------------
251 void __fastcall
252 TFStdError::LBStdErrorKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) {
253 FMain->UpdateStatusBar();
254 }
255 //---------------------------------------------------------------------------
256

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26