mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-28 12:02:15 -05:00
Extensions: Paster Update
This commit is contained in:
parent
34a2322311
commit
3a7e6841c5
@ -10,17 +10,31 @@ end;
|
|||||||
|
|
||||||
function GetVersion: string;
|
function GetVersion: string;
|
||||||
begin;
|
begin;
|
||||||
Result := '0.5';
|
Result := '1.0';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$IFDEF EXTENSION}
|
{$IFDEF EXTENSION}
|
||||||
|
|
||||||
|
type
|
||||||
|
TAltHost_Menu = record
|
||||||
|
Index: integer;
|
||||||
|
Menu: TMenuItem;
|
||||||
|
Paste_MenuItem: TMenuItem;
|
||||||
|
PasteS_MenuItem: TMenuItem;
|
||||||
|
GetPaste_MenuItem: TMenuItem;
|
||||||
|
Divider_MenuItem: TMenuItem;
|
||||||
|
Default_MenuItem: TMenuItem;
|
||||||
|
Update_MenuItem: TMenuItem;
|
||||||
|
Delete_MenuItem: TMenuItem;
|
||||||
|
end;
|
||||||
|
TAltHost_Menus = array of TAltHost_Menu;
|
||||||
|
|
||||||
var
|
var
|
||||||
Paster_Menu, GetPaste_MenuItem, Private_MenuItem,
|
Paster_Menu, GetPaste_MenuItem, Private_MenuItem,
|
||||||
Browser_MenuItem, AltHost_Menu: TMenuItem;
|
Browser_MenuItem, AltHost_Menu, AltHostAdd_MenuItem: TMenuItem;
|
||||||
Paster_MenuItems, Divider_MenuItems: array[1..2] of TMenuItem;
|
Paster_MenuItems: array[1..2] of TMenuItem;
|
||||||
AltHost_Menus: array[1..5] of TMenuItem;
|
Divider_MenuItems: array[1..3] of TMenuItem;
|
||||||
AltHost_MenuItems: array[1..5] of array[1..6] of TMenuItem;
|
AltHost_Menus: TAltHost_Menus;
|
||||||
|
|
||||||
function EncodeString(Data: string): string;
|
function EncodeString(Data: string): string;
|
||||||
var
|
var
|
||||||
@ -145,16 +159,14 @@ begin
|
|||||||
WriteLn(Data);
|
WriteLn(Data);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure UpdateDefault(I: integer);
|
procedure UpdateDefault(Index: integer);
|
||||||
var
|
var
|
||||||
J: integer;
|
I: integer;
|
||||||
begin
|
begin
|
||||||
Settings.setKeyValue('DefaultHost', IntToStr(I));
|
Settings.setKeyValue('DefaultHost', IntToStr(Index));
|
||||||
for J := 1 to 5 do
|
for I := 0 to High(AltHost_Menus) do
|
||||||
if (J = I) then
|
AltHost_Menus[I].Default_MenuItem.Checked := False;
|
||||||
AltHost_MenuItems[J][5].Checked := True
|
AltHost_Menus[Index].Default_MenuItem.Checked := True
|
||||||
else
|
|
||||||
AltHost_MenuItems[J][5].Checked := False;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure UpdateHost(I: integer);
|
procedure UpdateHost(I: integer);
|
||||||
@ -165,34 +177,82 @@ begin
|
|||||||
begin
|
begin
|
||||||
{$IFDEF DEV}WriteLn('Data := '#39 + Data + #39';');{$ENDIF}
|
{$IFDEF DEV}WriteLn('Data := '#39 + Data + #39';');{$ENDIF}
|
||||||
if (Data = '') then
|
if (Data = '') then
|
||||||
if (AltHost_Menus[I].Caption = 'Host ' + IntToStr(I)) then
|
|
||||||
begin
|
begin
|
||||||
WriteLn('[Paster]Error: The host cannot be blank!');
|
WriteLn('[Paster]Error: The host cannot be blank!');
|
||||||
Exit;
|
Exit;
|
||||||
end else
|
|
||||||
begin
|
|
||||||
AltHost_Menus[I].Caption := 'Host ' + IntToStr(I);
|
|
||||||
AltHost_MenuItems[I][1].Enabled := False;
|
|
||||||
AltHost_MenuItems[I][2].Enabled := False;
|
|
||||||
AltHost_MenuItems[I][3].Enabled := False;
|
|
||||||
AltHost_MenuItems[I][5].Enabled := False;
|
|
||||||
Settings.setKeyValue('Host' + IntToStr(I), 'Host ' + IntToStr(I));
|
|
||||||
if (Settings.getKeyValueDef('DefaultHost', '1') = IntToStr(I)) then
|
|
||||||
UpdateDefault(1);
|
|
||||||
Exit;
|
|
||||||
end;
|
end;
|
||||||
AltHost_Menus[I].Caption := Data;
|
|
||||||
AltHost_MenuItems[I][1].Enabled := True;
|
AltHost_Menus[I].Menu.Caption := Data;
|
||||||
AltHost_MenuItems[I][2].Enabled := True;
|
Settings.setKeyValue('Host' + IntToStr(AltHost_Menus[I].Index), Data);
|
||||||
AltHost_MenuItems[I][3].Enabled := True;
|
end;
|
||||||
AltHost_MenuItems[I][5].Enabled := True;
|
end;
|
||||||
Settings.setKeyValue('Host' + IntToStr(I), Data);
|
|
||||||
|
procedure OnClick(Sender: TObject); forward;
|
||||||
|
|
||||||
|
procedure CreateAltMenu(I: integer);
|
||||||
|
var
|
||||||
|
J: integer;
|
||||||
|
begin
|
||||||
|
J := Length(AltHost_Menus);
|
||||||
|
SetLength(AltHost_Menus, J + 1);
|
||||||
|
with AltHost_Menus[J] do
|
||||||
|
begin
|
||||||
|
Index := I;
|
||||||
|
|
||||||
|
Divider_MenuItems[3].Visible := (Divider_MenuItems[3].MenuIndex > 0);
|
||||||
|
|
||||||
|
Menu := TMenuItem.Create(AltHost_Menu);
|
||||||
|
Menu.Name := 'Host_' + IntToStr(I) + '_Menu'
|
||||||
|
Menu.Caption := Settings.getKeyValueDef('Host' + IntToStr(I), '');
|
||||||
|
AltHost_Menu.Insert(Divider_MenuItems[3].MenuIndex, Menu);
|
||||||
|
|
||||||
|
Paste_MenuItem := TMenuItem.Create(Menu);
|
||||||
|
Paste_MenuItem.Name := Menu.Name + '_Paste';
|
||||||
|
Paste_MenuItem.Caption := 'Paste';
|
||||||
|
Paste_MenuItem.OnClick := @OnClick;
|
||||||
|
Menu.Add(Paste_MenuItem);
|
||||||
|
|
||||||
|
PasteS_MenuItem := TMenuItem.Create(Menu);
|
||||||
|
PasteS_MenuItem.Name := Menu.Name + '_PasteS';
|
||||||
|
PasteS_MenuItem.Caption := 'Paste Selection';
|
||||||
|
PasteS_MenuItem.OnClick := @OnClick;
|
||||||
|
Menu.Add(PasteS_MenuItem);
|
||||||
|
|
||||||
|
GetPaste_MenuItem := TMenuItem.Create(Menu);
|
||||||
|
GetPaste_MenuItem.Name := Menu.Name + '_GetPaste';
|
||||||
|
GetPaste_MenuItem.Caption := 'Get Paste';
|
||||||
|
GetPaste_MenuItem.OnClick := @OnClick;
|
||||||
|
Menu.Add(GetPaste_MenuItem);
|
||||||
|
|
||||||
|
Divider_MenuItem := TMenuItem.Create(Menu);
|
||||||
|
Divider_MenuItem.Caption := '-';
|
||||||
|
Menu.Add(Divider_MenuItem);
|
||||||
|
|
||||||
|
Default_MenuItem := TMenuItem.Create(Menu);
|
||||||
|
Default_MenuItem.Name := Menu.Name + '_Default';
|
||||||
|
Default_MenuItem.Caption := 'Default';
|
||||||
|
Default_MenuItem.Checked := (Settings.getKeyValueDef('DefaultHost', '1') = IntToStr(I));
|
||||||
|
Default_MenuItem.OnClick := @OnClick;
|
||||||
|
Menu.Add(Default_MenuItem);
|
||||||
|
|
||||||
|
Update_MenuItem := TMenuItem.Create(Menu);
|
||||||
|
Update_MenuItem.Name := Menu.Name + '_Update';
|
||||||
|
Update_MenuItem.Caption := 'Update Host';
|
||||||
|
Update_MenuItem.OnClick := @OnClick;
|
||||||
|
Menu.Add(Update_MenuItem);
|
||||||
|
|
||||||
|
{ Delete_MenuItem := TMenuItem.Create(Menu);
|
||||||
|
Delete_MenuItem.Name := Menu.Name + '_Delete';
|
||||||
|
Delete_MenuItem.Caption := 'Delete Host';
|
||||||
|
Delete_MenuItem.OnClick := @OnClick;
|
||||||
|
Menu.Add(Delete_MenuItem); } // This is annoying to do so lets just leave it out for now...
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure OnClick(Sender: TObject);
|
procedure OnClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
I, K: integer;
|
I, K: integer;
|
||||||
|
Data: string;
|
||||||
begin;
|
begin;
|
||||||
{$IFDEF DEV}
|
{$IFDEF DEV}
|
||||||
if (Sender is TMenuItem) then
|
if (Sender is TMenuItem) then
|
||||||
@ -204,6 +264,25 @@ begin;
|
|||||||
|
|
||||||
GetPaste_MenuItem: GetPaste(Settings.getKeyValue('Host' + Settings.getKeyValueDef('DefaultHost', '1')));
|
GetPaste_MenuItem: GetPaste(Settings.getKeyValue('Host' + Settings.getKeyValueDef('DefaultHost', '1')));
|
||||||
|
|
||||||
|
AltHostAdd_MenuItem: begin
|
||||||
|
I := 1;
|
||||||
|
while (Settings.IsKey('Host' + IntToStr(I))) do
|
||||||
|
Inc(I);
|
||||||
|
|
||||||
|
if InputQuery(GetName + ' ' + GetVersion + ' Extension', 'Please input the LodgeIt Host! (Ex: paste.pocoo.org)', Data) then
|
||||||
|
begin
|
||||||
|
{$IFDEF DEV}WriteLn('Data := '#39 + Data + #39';');{$ENDIF}
|
||||||
|
if (Data = '') then
|
||||||
|
begin
|
||||||
|
WriteLn('[Paster]Error: The host cannot be blank!');
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Settings.setKeyValue('Host' + IntToStr(I), Data);
|
||||||
|
CreateAltMenu(I);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
Private_MenuItem: begin
|
Private_MenuItem: begin
|
||||||
Private_MenuItem.Checked := (not (Private_MenuItem.Checked));
|
Private_MenuItem.Checked := (not (Private_MenuItem.Checked));
|
||||||
Settings.setKeyValue('Private', Lowercase(BoolToStr(Private_MenuItem.Checked)));
|
Settings.setKeyValue('Private', Lowercase(BoolToStr(Private_MenuItem.Checked)));
|
||||||
@ -216,18 +295,14 @@ begin;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for I := 1 to 5 do
|
for I := 0 to High(AltHost_Menus) do
|
||||||
for K := 1 to 6 do
|
with AltHost_Menus[I] do
|
||||||
if (Sender = AltHost_MenuItems[I][K]) then
|
case Sender of
|
||||||
begin
|
Paste_MenuItem: Paste(Settings.getKeyValue('Host' + IntToStr(Index)), ScriptText);
|
||||||
case K of
|
PasteS_MenuItem: Paste(Settings.getKeyValue('Host' + IntToStr(Index)), GetSelectedText);
|
||||||
1: Paste(Settings.getKeyValue('Host' + IntToStr(I)), ScriptText);
|
GetPaste_MenuItem: GetPaste(Settings.getKeyValue('Host' + IntToStr(Index)));
|
||||||
2: Paste(Settings.getKeyValue('Host' + IntToStr(I)), GetSelectedText);
|
Default_MenuItem: UpdateDefault(I);
|
||||||
3: GetPaste(Settings.getKeyValue('Host' + IntToStr(I)));
|
Update_MenuItem: UpdateHost(I);
|
||||||
5: UpdateDefault(I);
|
|
||||||
6: UpdateHost(I);
|
|
||||||
end;
|
|
||||||
Break;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -242,7 +317,7 @@ begin
|
|||||||
Paster_Menu.Visible := False;
|
Paster_Menu.Visible := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure init;
|
procedure Init;
|
||||||
var
|
var
|
||||||
I, K: integer;
|
I, K: integer;
|
||||||
begin;
|
begin;
|
||||||
@ -311,51 +386,27 @@ begin;
|
|||||||
AltHost_Menu.Caption := 'Hosts';
|
AltHost_Menu.Caption := 'Hosts';
|
||||||
Paster_Menu.Add(AltHost_Menu);
|
Paster_Menu.Add(AltHost_Menu);
|
||||||
|
|
||||||
for I := 1 to 5 do
|
Divider_MenuItems[3] := TMenuItem.Create(AltHost_Menu);
|
||||||
|
Divider_MenuItems[3].Caption := '-';
|
||||||
|
Divider_MenuItems[3].Visible := False;
|
||||||
|
AltHost_Menu.Add(Divider_MenuItems[3]);
|
||||||
|
|
||||||
|
AltHostAdd_MenuItem := TMenuItem.Create(AltHost_Menu);
|
||||||
|
AltHostAdd_MenuItem.Name := 'AddHost';
|
||||||
|
AltHostAdd_MenuItem.Caption := 'Add Host';
|
||||||
|
AltHostAdd_MenuItem.OnClick := @OnClick;
|
||||||
|
AltHost_Menu.Add(AltHostAdd_MenuItem);
|
||||||
|
|
||||||
|
if (not (Settings.IsKey('Host1'))) then
|
||||||
|
Settings.setKeyValue('Host1', HOSTDef);
|
||||||
|
|
||||||
|
I := 1;
|
||||||
|
while (Settings.IsKey('Host' + IntToStr(I))) do
|
||||||
begin
|
begin
|
||||||
AltHost_Menus[I] := TMenuItem.Create(AltHost_Menu);
|
if (Settings.GetKeyValue('Host' + IntToStr(I)) = 'Host ' + IntToStr(I)) then
|
||||||
if (I = 1) then
|
Continue;
|
||||||
AltHost_Menus[I].Caption := HOSTDef
|
CreateAltMenu(I);
|
||||||
else
|
Inc(I);
|
||||||
AltHost_Menus[I].Caption := Settings.getKeyValueDef('Host' + IntToStr(I), 'Host ' + IntToStr(I));
|
|
||||||
AltHost_Menu.Add(AltHost_Menus[I]);
|
|
||||||
|
|
||||||
for K := 1 to 6 do
|
|
||||||
begin
|
|
||||||
AltHost_MenuItems[I][K] := TMenuItem.Create(AltHost_Menus[I]);
|
|
||||||
case K of
|
|
||||||
1: begin
|
|
||||||
AltHost_MenuItems[I][1].Name := 'Host' + IntToStr(I) + '_Paste';
|
|
||||||
AltHost_MenuItems[I][1].Caption := 'Paste It!';
|
|
||||||
end;
|
|
||||||
2: begin
|
|
||||||
AltHost_MenuItems[I][2].Name := 'Host' + IntToStr(I) + '_PasteS';
|
|
||||||
AltHost_MenuItems[I][2].Caption := 'Paste Selection!';
|
|
||||||
end;
|
|
||||||
3: begin
|
|
||||||
AltHost_MenuItems[I][3].Name := 'Host' + IntToStr(I) + '_GetPaste';
|
|
||||||
AltHost_MenuItems[I][3].Caption := 'Get Paste!';
|
|
||||||
end;
|
|
||||||
4: AltHost_MenuItems[I][4].Caption := '-';
|
|
||||||
5: begin
|
|
||||||
AltHost_MenuItems[I][5].Name := 'Host' + IntToStr(I) + '_Default';
|
|
||||||
AltHost_MenuItems[I][5].Caption := 'Default';
|
|
||||||
AltHost_MenuItems[I][5].Checked := (Settings.getKeyValueDef('DefaultHost', '1') = IntToStr(I));
|
|
||||||
end;
|
|
||||||
6: begin
|
|
||||||
AltHost_MenuItems[I][6].Name := 'Host' + IntToStr(I) + '_Update';
|
|
||||||
AltHost_MenuItems[I][6].Caption := 'Update Host';
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
AltHost_MenuItems[I][K].OnClick := @OnClick;
|
|
||||||
|
|
||||||
if ((not ((K = 4) or (K = 6))) and (AltHost_Menus[I].Caption = 'Host ' + IntToStr(I))) then
|
|
||||||
AltHost_MenuItems[I][K].Enabled := False;
|
|
||||||
|
|
||||||
if ((I = 1) and (K = 6)) then
|
|
||||||
AltHost_MenuItems[I][K].Visible := False;
|
|
||||||
AltHost_Menus[I].Add(AltHost_MenuItems[I][K]);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -369,3 +420,4 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user