Added new function to calltips: opens include file on click

Fixed some bugs in the menu generator
This commit is contained in:
Christian Hammacher 2005-11-19 19:46:29 +00:00
parent 429798ae35
commit db0dd03128
8 changed files with 100 additions and 93 deletions

View File

@ -115,7 +115,7 @@ AutoIncBuild=1
MajorVer=1
MinorVer=3
Release=0
Build=31
Build=32
Debug=0
PreRelease=0
Special=0
@ -126,7 +126,7 @@ CodePage=1252
[Version Info Keys]
CompanyName=AMX Mod X Dev Team
FileDescription=
FileVersion=1.3.0.31
FileVersion=1.3.0.32
InternalName=
LegalCopyright=
LegalTrademarks=

Binary file not shown.

Binary file not shown.

View File

@ -19,6 +19,8 @@ function CountChars(eIn: String; eChar: Char): Integer;
function RemoveStringsAndComments(eLine: String; eRemoveStrings: Boolean; eRemoveComments: Boolean): String;
function GetMatchingBrace(eString: String): Integer;
function GetColoredLine(eLine: Integer): String;
function GetFunctionPos: Integer;
function GetCurrFunc: String;
function GetRTFText(ARichEdit: TRichedit): string;
procedure SetRTFText(ARichEdit: TRichedit; ARTFText: String);
@ -448,4 +450,30 @@ begin
end;
end;
function GetFunctionPos: Integer;
var eStr: String;
i: integer;
begin
Result := 0;
eStr := StringReplace(frmMain.sciEditor.Lines[frmMain.sciEditor.GetCurrentLineNumber], '^"', '', [rfReplaceAll]);
while Between(eStr, '"', '"') <> '' do
eStr := StringReplace(eStr, Between(eStr, '"', '"'), '', [rfReplaceAll]);
while Between(eStr, '{', '}') <> '' do
eStr := StringReplace(eStr, Between(eStr, '"', '"'), '', [rfReplaceAll]);
for i := 0 to Length(eStr) -1 do begin
if eStr[i] = ',' then
Result := Result +1;
end;
end;
function GetCurrFunc: String;
var eStr: String;
begin
eStr := frmMain.sciEditor.Lines[frmMain.sciEditor.GetCurrentLineNumber];
if Pos('(', eStr) = 0 then
Result := ''
else
Result := Trim(Copy(eStr, 1, Pos('(', eStr)));
end;
end.

View File

@ -6,8 +6,8 @@ uses SysUtils, Classes, Windows, Forms, Graphics;
procedure GenerateSimpleMenu;
{ Yes, this is from AMXX-Edit v2. I'm too lazy to rewrite it... }
{ >:( }
{ Yes, a part is copied from AMXX-Edit v2. I'm too lazy to rewrite everything... }
{ gaben }
function AddOldMenu: Boolean;
function AddOldPlayerMenu: Boolean;
@ -20,7 +20,8 @@ function PluginInitLine: Integer;
implementation
uses UnitCodeUtils, UnitfrmMain, UnitfrmMenuGenerator, UnitLanguages;
uses UnitCodeUtils, UnitfrmMain, UnitfrmMenuGenerator, UnitLanguages,
UnitMainTools;
function GetLine(eExpression: String; eAllowFunction, eBreak: Boolean): Integer;
var i: integer;
@ -99,6 +100,9 @@ begin
end
else
MessageBox(frmMenuGenerator.Handle, PChar(lInvalidPlugin), PChar(Application.Title), MB_ICONERROR);
ActiveDoc.Modified := True;
frmMain.mnuModified.Caption := lModified;
end;
{ Normal Menu }
@ -159,11 +163,9 @@ begin
eStr.Add('}');
// Insert
AddIfDoesntExist('amxmodx');
i := GetFirst('#define', True) +2;
if i = 1 then
i := GetFirst('#include', True) +2;
if i = 1 then
i := 0;
i := GetLast('#define', True) +1;
if i = 0 then
i := GetLast('#include', True) +1;
frmMain.sciEditor.Lines.Insert(i, Format('#define Keys%s %s', [frmMenuGenerator.txtMenuName.Text, DefinedKeys]));
frmMain.sciEditor.Lines.Text := frmMain.sciEditor.Lines.Text + #13 + eStr.Text;
@ -183,6 +185,8 @@ begin
frmMain.sciEditor.Lines.Insert(i, ' register_menucmd(register_menuid("' + frmMenuGenerator.txtMenuName.Text + '"), Keys' + frmMenuGenerator.txtMenuName.Text + ', "Pressed' + frmMenuGenerator.txtMenuName.Text + '")');
end;
eStr.Free;
ActiveDoc.Modified := True;
frmMain.mnuModified.Caption := lModified;
end;
{ Player Menu }
@ -312,14 +316,14 @@ begin
end;
Delete(DefinedKeys, 1, 1);
end;
i := GetLast('#define', True) +2;
if i = 1 then
i := GetLast('#include', True) +2;
if i = 1 then
i := 0;
i := GetLast('#define', True) +1;
if i = 0 then
i := GetLast('#include', True) +1;
frmMain.sciEditor.Lines.Insert(i, Format('#define Keys%s %s', [frmMenuGenerator.txtMenuName.Text, DefinedKeys]));
frmMain.sciEditor.Lines.Insert(i +1, 'new MenuPos' + frmMenuGenerator.txtMenuName.Text);
frmMain.sciEditor.Lines.Insert(i +2, 'new MenuPlayers' + frmMenuGenerator.txtMenuName.Text + '[32]');
frmMain.sciEditor.Lines.Insert(i +1, '');
frmMain.sciEditor.Lines.Insert(i +2, 'new MenuPos' + frmMenuGenerator.txtMenuName.Text);
frmMain.sciEditor.Lines.Insert(i +3, 'new MenuPlayers' + frmMenuGenerator.txtMenuName.Text + '[32]');
{ Register }
i := GetFirst('register_plugin', True) +2;
if i = 1 then
@ -344,7 +348,7 @@ begin
eStr.Add('public ShowMenu' + frmMenuGenerator.txtMenuName.Text + '(id, position) {');
if frmMenuGenerator.chkAddComment.Checked then
eStr.Add(' // Menu stuff //');
eStr.Add(' if (position < 0) { return 0 }-/*');
eStr.Add(' if (position < 0) { return 0; }');
eStr.Add(' ');
eStr.Add(' new i, k');
eStr.Add(' new MenuBody[255]');
@ -356,8 +360,8 @@ begin
eStr.Add(' get_players(MenuPlayers' + frmMenuGenerator.txtMenuName.Text + ', Num)');
eStr.Add(' if (Start >= Num) { Start = position = MenuPos' + frmMenuGenerator.txtMenuName.Text + ' = 0; }');
eCurLine := GetColoredMenu;
eCurLine := Copy(eCurLine, 1, Pos('$players', eCurLine) -3);
Insert('\R%d/%d^n\w', eCurLine, Pos('^n', eCurLine));
eCurLine := Copy(eCurLine, 1, Pos('$players', eCurLine) -5);
Insert('\R%d/%d', eCurLine, Pos('^n', eCurLine));
eStr.Add(' new Len = format(MenuBody, 255, "' + eCurLine + '", position+1, (Num / ' + IntToStr(ePlayersTo - ePlayersFrom) + ' + ((Num % ' + IntToStr(ePlayersTo - ePlayersFrom) + ') ? 1 : 0 )) )');
eStr.Add(' new End = Start + ' + IntToStr(ePlayersTo - ePlayersFrom));
if eExit = 0 then
@ -386,7 +390,7 @@ begin
// eStr.Add(' }');
// end
// else begin
eStr.Add(' Keys |= (i<<CurrentKey++)');
eStr.Add(' Keys |= (1<<CurrentKey++)');
eStr.Add(' Len += format(MenuBody[Len], (255-Len), "' + PrepareItem(ePlayerFormat, False) + '", CurrentKey, UserName)');
// end;
eStr.Add(' }');
@ -438,11 +442,13 @@ begin
eStr.Add(' }');
eStr.Add(' return PLUGIN_HANDLED');
eStr.Add('}');
frmMain.sciEditor.Lines.Text := frmMain.sciEditor.Lines.Text + #13 + eStr.Text;
frmMain.sciEditor.Lines.Text := frmMain.sciEditor.Lines.Text + #13 + eStr.Text;
except
MessageBox(frmMenuGenerator.Handle, PChar('An error occured while inserting code!'), 'Warning', MB_ICONWARNING);
end;
eStr.Free;
frmMain.mnuModified.Caption := lModified;
ActiveDoc.Modified := True;
end;
{ Functions }

View File

@ -40,12 +40,15 @@ var eLookedUpIncluded: TStringList;
function UpdateIncPath(eInput: string): string;
begin
eInput := StringReplace(Trim(eInput), '/', '\', [rfReplaceAll]);
if FileExists(ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + eInput + '.inc') then
Result := ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + eInput + '.inc'
else if FileExists(ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + 'include\' + eInput + '.inc') then
Result := ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + 'include\' + eInput + '.inc'
else if (FileExists(ExtractFilePath(ActiveDoc.FileName) + eInput + '.inc')) then
Result := ExtractFilePath(ActiveDoc.FileName) + eInput + '.inc'
if ExtractFileExt(eInput) = '' then
eInput := eInput + '.inc';
if FileExists(ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + eInput) then
Result := ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + eInput
else if FileExists(ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + 'include\' + eInput) then
Result := ExtractFilePath(frmSettings.txtPawnCompilerPath.Text) + 'include\' + eInput
else if (FileExists(ExtractFilePath(ActiveDoc.FileName) + eInput)) then
Result := ExtractFilePath(ActiveDoc.FileName) + eInput
else
Result := '';
end;
@ -133,21 +136,10 @@ begin
{ Included }
if (IsAtStart('#include', eBackup)) then begin
eString := StringReplace(eBackup, '/', '\', [rfReplaceAll]);
if Between(eString, '<', '>') <> '' then begin
eString := Between(eString, '<', '>');
if ExtractFileExt(eString) <> '' then
ChangeFileExt(eString, '');
end
else if Between(eString, '"', '"') <> '' then begin
if Between(eString, '<', '>') <> '' then
eString := Between(eString, '<', '>')
else if Between(eString, '"', '"') <> '' then
eString := Between(eString, '"', '"');
if ExtractFileExt(eString) <> '' then
ChangeFileExt(eString, '');
end
else begin
eString := Trim(eString);
if ExtractFileExt(eString) <> '' then
ChangeFileExt(eString, '');
end;
eString := Trim(eString);
Result.Included.AddObject(eString, TObject(i));
@ -273,6 +265,7 @@ begin
if Pos('operator', eTemp) = 1 then
k := 6;
eTemp := RemoveSemicolon(eTemp);
if k < 5 then begin
case k of
0: Result.CallTips.Add(eTemp + '-> ' + FileName + ', function');
@ -360,6 +353,7 @@ begin
if (Pos(':', eTemp) <> 0) and (Pos(':', eTemp) < Pos('(', eTemp)) then
Delete(eTemp, 1, Pos(':', eTemp));
eTemp := RemoveSemicolon(eTemp);
if (Pos('enum', eTemp) = Pos('operator', eTemp)) and (Pos('enum', eTemp) = 0) then
Result.CallTips.Add(eTemp + '-> ' + FileName + ', ' + Trim(Copy(eString, 1, Pos(#32, eString) -1)));

View File

@ -1,6 +1,6 @@
object frmMain: TfrmMain
Left = 257
Top = 302
Top = 297
Width = 888
Height = 646
Caption = 'AMXX-Studio'
@ -756,6 +756,7 @@ object frmMain: TfrmMain
Align = alClient
OnModified = sciEditorModified
OnDblClick = sciEditorDblClick
OnCallTipClick = sciEditorCallTipClick
OnKeyUp = sciEditorKeyUp
OnKeyDown = sciEditorKeyDown
OnKeyPress = sciEditorKeyPress

View File

@ -1704,6 +1704,8 @@ begin
eStr := Format(GetIndents + 'set_hudmessage(%u, %u, %u, %s, %s, 0, 6.0, %s)', [GetRValue(frmHudMsgGenerator.CurrColor), GetGValue(frmHudMsgGenerator.CurrColor), GetBValue(frmHudMsgGenerator.CurrColor), Dot(frmHudMsgGenerator.txtXPos.Text), Dot(frmHudMsgGenerator.txtYPos.Text), Dot(frmHudMsgGenerator.txtTimeToShow.Text)]);
eStr := eStr + #13#10 + GetIndents + 'show_hudmessage(id, "' + frmHudMsgGenerator.txtText.Text + '")';
sciEditor.Lines.Insert(sciEditor.GetCurrentLineNumber, eStr);
mnuModified.Caption := lModified;
ActiveDoc.Modified := True;
end;
end;
@ -1968,22 +1970,6 @@ end;
procedure TfrmMain.sciAutoCompleteBeforeShow(Sender: TObject;
const Position: Integer; ListToDisplay: TStrings;
var CancelDisplay: Boolean);
function GetFunctionPos: Integer;
var eStr: String;
i: integer;
begin
Result := 0;
eStr := StringReplace(sciEditor.Lines[sciEditor.GetCurrentLineNumber], '^"', '', [rfReplaceAll]);
while Between(eStr, '"', '"') <> '' do
eStr := StringReplace(eStr, Between(eStr, '"', '"'), '', [rfReplaceAll]);
while Between(eStr, '{', '}') <> '' do
eStr := StringReplace(eStr, Between(eStr, '"', '"'), '', [rfReplaceAll]);
for i := 0 to Length(eStr) -1 do begin
if eStr[i] = ',' then
Result := Result +1;
end;
end;
var eCurrStyle: Integer;
eFunction: String;
i: integer;
@ -1997,15 +1983,9 @@ begin
eCurrStyle := GetStyleAt(sciEditor.SelStart).StyleNumber;
if (ActiveDoc.Highlighter = 'Pawn') or (ActiveDoc.Highlighter = 'C++') then begin
eFunction := '';
for i := 0 to jviCode.Root.Count -1 do begin
if jviCode.Root.Items[i].DisplayName = 'Function Call' then begin
eFunction := jviCode.Root.Items[i].Items[0].DisplayValue;
break;
end;
end;
eFunction := GetCurrFunc;
if eFunction <> '' then begin
eFunction := LowerCase(Trim(eFunction));
eFunction := LowerCase(eFunction);
for i := 0 to eACList.Count -1 do begin
if eFunction = LowerCase(Trim(TACFunction(eACList.Items[i]).Name)) then begin
if TACFunction(eACList.Items[i]).Items.Count > GetFunctionPos then begin
@ -2106,6 +2086,7 @@ end;
procedure TfrmMain.mnuMenuGeneratorClick(Sender: TObject);
begin
frmMenuGenerator.jplMain.ActivePage := frmMenuGenerator.jspSelectType;
frmMenuGenerator.ShowModal;
end;
@ -2153,36 +2134,14 @@ end;
procedure TfrmMain.sciCallTipsBeforeShow(Sender: TObject;
const Position: Integer; ListToDisplay: TStrings;
var CancelDisplay: Boolean);
function GetFunctionPos: Integer;
var eStr: String;
i: integer;
begin
Result := 0;
eStr := StringReplace(sciEditor.Lines[sciEditor.GetCurrentLineNumber], '^"', '', [rfReplaceAll]);
while Between(eStr, '"', '"') <> '' do
eStr := StringReplace(eStr, Between(eStr, '"', '"'), '', [rfReplaceAll]);
while Between(eStr, '{', '}') <> '' do
eStr := StringReplace(eStr, Between(eStr, '"', '"'), '', [rfReplaceAll]);
for i := 0 to Length(eStr) -1 do begin
if eStr[i] = ',' then
Result := Result +1;
end;
end;
var i: integer;
eFunction: String;
begin
CancelDisplay := not Plugin_CallTipShow(ListToDisplay.GetText);
if (frmSettings.chkAutoHideCT.Checked) and (jviCode.Root.Items[0].DisplayName = 'Function Call') then begin
for i := 0 to jviCode.Root.Count -1 do begin
if jviCode.Root.Items[i].DisplayName = 'Function Call' then begin
eFunction := jviCode.Root.Items[i].Items[0].DisplayValue;
break;
end;
end;
eFunction := GetCurrFunc;
if eFunction <> '' then begin
eFunction := LowerCase(Trim(eFunction));
eFunction := LowerCase(eFunction);
for i := 0 to eACList.Count -1 do begin
if eFunction = LowerCase(Trim(TACFunction(eACList.Items[i]).Name)) then begin
if TACFunction(eACList.Items[i]).Items.Count > GetFunctionPos then begin
@ -2197,9 +2156,26 @@ end;
procedure TfrmMain.sciEditorCallTipClick(Sender: TObject;
const position: Integer);
var i: integer;
eFunc: String;
begin
if not Plugin_CallTipClick(position) then
if not Plugin_CallTipClick(position) then begin
sciEditor.CallTipCancel;
exit;
end;
eFunc := LowerCase(GetCurrFunc);
for i := 0 to sciCallTips.ApiStrings.Count -1 do begin
if Pos(eFunc, LowerCase(sciCallTips.ApiStrings[i])) = 1 then begin
eFunc := UpdateIncPath(Between(sciCallTips.ApiStrings[i], '-> ', ','));
if eFunc <> '' then begin
sciEditor.CallTipCancel;
PawnProjects.Open(eFunc);
end;
break;
end;
end;
end;
procedure TfrmMain.sciEditorAutoCSelection(Sender: TObject;
@ -2313,6 +2289,9 @@ begin
sciEditor.Lines.Add(#9 + 'return nIdx');
sciEditor.Lines.Add('}');
end;
mnuModified.Caption := lModified;
ActiveDoc.Modified := True;
end;
end;
@ -2960,7 +2939,6 @@ begin
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var i: integer;
begin
sciEditor.StreamClass := TSciMyStream;
eACList := TmxJsCollection.Create(TACFunction);