mirror of
https://github.com/moparisthebest/Simba
synced 2025-01-10 21:28:00 -05:00
Simba: Patch by Dgby714 adds more paster func.
This commit is contained in:
parent
34cab7827a
commit
56f4895be3
@ -2,7 +2,8 @@ program Paster;
|
|||||||
//{$DEFINE DEV}
|
//{$DEFINE DEV}
|
||||||
{$IFDEF EXTENSION}
|
{$IFDEF EXTENSION}
|
||||||
var
|
var
|
||||||
Paster_Menu, GetPaste_MenuItem, Private_MenuItem, Paster_MenuItem, AltHost_Menu: TMenuItem;
|
Paster_Menu, GetPaste_MenuItem, Private_MenuItem: TMenuItem;
|
||||||
|
Browser_MenuItem, Paster_MenuItem, AltHost_Menu: TMenuItem;
|
||||||
Divider_MenuItems: array[1..2] of TMenuItem;
|
Divider_MenuItems: array[1..2] of TMenuItem;
|
||||||
AltHost_Menus: array[1..5] of TMenuItem;
|
AltHost_Menus: array[1..5] of TMenuItem;
|
||||||
AltHost_MenuItems: array[1..5] of array[1..4] of TMenuItem;
|
AltHost_MenuItems: array[1..5] of array[1..4] of TMenuItem;
|
||||||
@ -44,8 +45,6 @@ begin;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function JSONRequest(var Data: string; const HOST, Method: string): boolean;
|
function JSONRequest(var Data: string; const HOST, Method: string): boolean;
|
||||||
{$IFDEF DEV}var
|
|
||||||
I: integer;{$ENDIF}
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF DEV}
|
{$IFDEF DEV}
|
||||||
WriteLn('(HOST, Method) := ('#39 + HOST + #39', '#39 + Method + #39');');
|
WriteLn('(HOST, Method) := ('#39 + HOST + #39', '#39 + Method + #39');');
|
||||||
@ -90,34 +89,29 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if ((GetJSONValue(Data, 'code') = 'null') and (GetJSONValue(Data, 'error') = 'null')) then
|
if ((GetJSONValue(Data, 'code') = '') and (GetJSONValue(Data, 'error') = '')) then
|
||||||
begin
|
begin
|
||||||
WriteLn('[Paster]Error: Invalid Paste ID!');
|
WriteLn('[Paster]Error: Invalid Paste ID!');
|
||||||
Result := False;
|
Result := False;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Data := GetJSONValue(Data, 'code');
|
OpenScript('Paste #' + GetJSONValue(Data, 'paste_id'), GetJSONValue(Data, 'code'));
|
||||||
WriteLn('[Paster]Info: Sorry guys I can''t open a script from extensions yet...');
|
|
||||||
WriteLn(Data);
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function PasteIt(out Data: string; HOST: string): boolean;
|
function PasteIt(out Data: string; HOST: string): boolean;
|
||||||
var
|
|
||||||
is_private: boolean;
|
|
||||||
begin
|
begin
|
||||||
if (HOST = '') then
|
if (HOST = '') then
|
||||||
HOST := 'paste.sheeva.villavu.com';
|
HOST := 'paste.sheeva.villavu.com';
|
||||||
if (MessageDlg(GetName + ' ' + GetVersion + ' Extension', 'Upload this script to ' + HOST + '?', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
|
if (MessageDlg(GetName + ' ' + GetVersion + ' Extension', 'Upload this script to ' + HOST + '?', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
|
||||||
begin
|
begin
|
||||||
is_private := (Lowercase(Settings.getKeyValueDef('Private', 'true')) = 'true');
|
Data := '{"language": "delphi", "code": "' + EncodeString(ScriptText) + '", "private": ' + Lowercase(BoolToStr(Private_MenuItem.Checked)) + '}';
|
||||||
Data := '{"language": "delphi", "code": "' + EncodeString(ScriptText) + '", "private": ' + Lowercase(BoolToStr(is_private)) + '}';
|
|
||||||
JSONRequest(Data, HOST, 'pastes.newPaste');
|
JSONRequest(Data, HOST, 'pastes.newPaste');
|
||||||
if (GetJSONValue(Data, 'error') = 'null') then
|
if (GetJSONValue(Data, 'error') = 'null') then
|
||||||
begin
|
begin
|
||||||
Data := 'http://' + HOST + '/show/' + GetJSONValue(Data, 'data') + '/';
|
Data := GetJSONValue(Data, 'data');
|
||||||
Result := True;
|
Result := True;
|
||||||
end else
|
end else
|
||||||
Data := '[Paster]Error: ' + GetJSONValue(Data, 'error');
|
Data := '[Paster]Error: ' + GetJSONValue(Data, 'error');
|
||||||
@ -130,8 +124,12 @@ var
|
|||||||
begin
|
begin
|
||||||
if PasteIt(Data, Host) then
|
if PasteIt(Data, Host) then
|
||||||
begin
|
begin
|
||||||
WriteLn('Opening pasted script at "' + Data + '"!');
|
if (Browser_MenuItem.Checked) then
|
||||||
OpenWebPage(Data);
|
begin
|
||||||
|
WriteLn('Opening pasted script at "http://' + HOST + '/show/' + Data + '/"!');
|
||||||
|
OpenWebPage('http://' + HOST + '/show/' + Data + '/');
|
||||||
|
end else
|
||||||
|
WriteLn('Script pasted at id "' + Data + '"');
|
||||||
end else
|
end else
|
||||||
WriteLn(Data);
|
WriteLn(Data);
|
||||||
end;
|
end;
|
||||||
@ -167,6 +165,11 @@ begin;
|
|||||||
Settings.setKeyValue('Private', Lowercase(BoolToStr(Private_MenuItem.Checked)));
|
Settings.setKeyValue('Private', Lowercase(BoolToStr(Private_MenuItem.Checked)));
|
||||||
{$IFDEF DEV}WriteLn('Private = ' + Lowercase(BoolToStr(Private_MenuItem.Checked)));{$ENDIF}
|
{$IFDEF DEV}WriteLn('Private = ' + Lowercase(BoolToStr(Private_MenuItem.Checked)));{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
Browser_MenuItem: begin
|
||||||
|
Browser_MenuItem.Checked := (not (Browser_MenuItem.Checked));
|
||||||
|
Settings.setKeyValue('OpenBrowser', Lowercase(BoolToStr(Browser_MenuItem.Checked)));
|
||||||
|
{$IFDEF DEV}WriteLn('OpenBrowser = ' + Lowercase(BoolToStr(Browser_MenuItem.Checked)));{$ENDIF}
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
for I := 1 to 5 do
|
for I := 1 to 5 do
|
||||||
for K := 1 to 4 do
|
for K := 1 to 4 do
|
||||||
@ -233,7 +236,6 @@ begin;
|
|||||||
begin
|
begin
|
||||||
Caption := 'Get Paste!';
|
Caption := 'Get Paste!';
|
||||||
OnClick := @OnClick;
|
OnClick := @OnClick;
|
||||||
{$IFNDEF DEV}Visible := False;{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
Paster_Menu.Add(GetPaste_MenuItem);
|
Paster_Menu.Add(GetPaste_MenuItem);
|
||||||
|
|
||||||
@ -254,6 +256,15 @@ begin;
|
|||||||
end;
|
end;
|
||||||
Paster_Menu.Add(Private_MenuItem);
|
Paster_Menu.Add(Private_MenuItem);
|
||||||
|
|
||||||
|
Browser_MenuItem := TMenuItem.Create(Paster_Menu);
|
||||||
|
with Browser_MenuItem do
|
||||||
|
begin
|
||||||
|
Caption := 'Open in Browser';
|
||||||
|
OnClick := @OnClick;
|
||||||
|
Checked := (Lowercase(Settings.getKeyValueDef('OpenBrowser', 'true')) = 'true');
|
||||||
|
end;
|
||||||
|
Paster_Menu.Add(Browser_MenuItem);
|
||||||
|
|
||||||
Paster_Menu.Add(Divider_MenuItems[2]);
|
Paster_Menu.Add(Divider_MenuItems[2]);
|
||||||
|
|
||||||
AltHost_Menu := TMenuItem.Create(Paster_Menu);
|
AltHost_Menu := TMenuItem.Create(Paster_Menu);
|
||||||
@ -279,9 +290,6 @@ begin;
|
|||||||
if ((not ((K = 3) or (K = 4))) and (AltHost_Menus[I].Caption = 'Host ' + IntToStr(I))) then
|
if ((not ((K = 3) or (K = 4))) and (AltHost_Menus[I].Caption = 'Host ' + IntToStr(I))) then
|
||||||
AltHost_MenuItems[I][K].Enabled := False;
|
AltHost_MenuItems[I][K].Enabled := False;
|
||||||
|
|
||||||
{$IFNDEF DEV}if (K = 2) then
|
|
||||||
AltHost_MenuItems[I][K].Visible := False;{$ENDIF}
|
|
||||||
|
|
||||||
AltHost_Menus[I].Add(AltHost_MenuItems[I][K]);
|
AltHost_Menus[I].Add(AltHost_MenuItems[I][K]);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -184,6 +184,7 @@ begin
|
|||||||
AddFunction(@ext_MessageDlg,'function MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;');
|
AddFunction(@ext_MessageDlg,'function MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;');
|
||||||
AddFunction(@ext_InputQuery,'function InputQuery(const ACaption, APrompt : String; var Value : String) : Boolean;');
|
AddFunction(@ext_InputQuery,'function InputQuery(const ACaption, APrompt : String; var Value : String) : Boolean;');
|
||||||
AddFunction(@ext_ScriptText,'function ScriptText: string;');
|
AddFunction(@ext_ScriptText,'function ScriptText: string;');
|
||||||
|
AddFunction(@ext_OpenScript,'procedure OpenScript(Name, Data: string);');
|
||||||
AddRegisteredPTRVariable('Settings','TMMLSettingsSandbox');
|
AddRegisteredPTRVariable('Settings','TMMLSettingsSandbox');
|
||||||
AddFunction(@ext_GetPageEx,'function GetPageEx(const URL, PostData, MimeType: string): string;');
|
AddFunction(@ext_GetPageEx,'function GetPageEx(const URL, PostData, MimeType: string): string;');
|
||||||
AddFunction(@ext_GetJSONValue,'function GetJSONValue(const Data, Value: string): string;');
|
AddFunction(@ext_GetJSONValue,'function GetJSONValue(const Data, Value: string): string;');
|
||||||
|
@ -126,7 +126,18 @@ end;
|
|||||||
function ext_ScriptText: string;
|
function ext_ScriptText: string;
|
||||||
begin
|
begin
|
||||||
Result := SimbaForm.CurrScript.SynEdit.Lines.Text;
|
Result := SimbaForm.CurrScript.SynEdit.Lines.Text;
|
||||||
Result := ReplaceRegExpr('Players\[(.*?)\]\.([N|n][A|a][M|m][E|e]|[P|p][A|a][S|s]{2}|[P|p][I|i][N|n])\s*\:\=\s*\''.*?\'';', Result, 'Players[$1].$2 := ''*********'';', True);
|
Result := ReplaceRegExpr('([N|n][A|a][M|m][E|e]|[P|p][A|a][S|s]{2}|[P|p][I|i][N|n])\s*\:\=\s*\''.*?\'';', Result, '$1 := ''*********'';', True);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure ext_OpenScript(Name, Data: string);
|
||||||
|
begin
|
||||||
|
if (Name = '') then
|
||||||
|
Name := 'Untitled';
|
||||||
|
SimbaForm.AddTab;
|
||||||
|
SimbaForm.CurrScript.SynEdit.Lines.Text := Data;
|
||||||
|
SimbaForm.CurrScript.ScriptName := Name;
|
||||||
|
SimbaForm.RefreshTab;
|
||||||
|
SimbaForm.UpdateTitle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ext_GetPageEx(const URL, PostData, MimeType: string): string;
|
function ext_GetPageEx(const URL, PostData, MimeType: string): string;
|
||||||
|
Loading…
Reference in New Issue
Block a user