mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-11 20:05:03 -05:00
Extensions: Paster Update
This commit is contained in:
parent
34a2322311
commit
3a7e6841c5
@ -2,7 +2,7 @@ program Paster;
|
||||
//{$DEFINE DEV}
|
||||
const
|
||||
HOSTDef = 'paste.villavu.com';
|
||||
|
||||
|
||||
function GetName: string;
|
||||
begin;
|
||||
Result := 'Paster';
|
||||
@ -10,17 +10,31 @@ end;
|
||||
|
||||
function GetVersion: string;
|
||||
begin;
|
||||
Result := '0.5';
|
||||
Result := '1.0';
|
||||
end;
|
||||
|
||||
{$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
|
||||
Paster_Menu, GetPaste_MenuItem, Private_MenuItem,
|
||||
Browser_MenuItem, AltHost_Menu: TMenuItem;
|
||||
Paster_MenuItems, Divider_MenuItems: array[1..2] of TMenuItem;
|
||||
AltHost_Menus: array[1..5] of TMenuItem;
|
||||
AltHost_MenuItems: array[1..5] of array[1..6] of TMenuItem;
|
||||
Browser_MenuItem, AltHost_Menu, AltHostAdd_MenuItem: TMenuItem;
|
||||
Paster_MenuItems: array[1..2] of TMenuItem;
|
||||
Divider_MenuItems: array[1..3] of TMenuItem;
|
||||
AltHost_Menus: TAltHost_Menus;
|
||||
|
||||
function EncodeString(Data: string): string;
|
||||
var
|
||||
@ -145,16 +159,14 @@ begin
|
||||
WriteLn(Data);
|
||||
end;
|
||||
|
||||
procedure UpdateDefault(I: integer);
|
||||
procedure UpdateDefault(Index: integer);
|
||||
var
|
||||
J: integer;
|
||||
I: integer;
|
||||
begin
|
||||
Settings.setKeyValue('DefaultHost', IntToStr(I));
|
||||
for J := 1 to 5 do
|
||||
if (J = I) then
|
||||
AltHost_MenuItems[J][5].Checked := True
|
||||
else
|
||||
AltHost_MenuItems[J][5].Checked := False;
|
||||
Settings.setKeyValue('DefaultHost', IntToStr(Index));
|
||||
for I := 0 to High(AltHost_Menus) do
|
||||
AltHost_Menus[I].Default_MenuItem.Checked := False;
|
||||
AltHost_Menus[Index].Default_MenuItem.Checked := True
|
||||
end;
|
||||
|
||||
procedure UpdateHost(I: integer);
|
||||
@ -165,34 +177,82 @@ begin
|
||||
begin
|
||||
{$IFDEF DEV}WriteLn('Data := '#39 + Data + #39';');{$ENDIF}
|
||||
if (Data = '') then
|
||||
if (AltHost_Menus[I].Caption = 'Host ' + IntToStr(I)) then
|
||||
begin
|
||||
WriteLn('[Paster]Error: The host cannot be blank!');
|
||||
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;
|
||||
AltHost_Menus[I].Caption := Data;
|
||||
AltHost_MenuItems[I][1].Enabled := True;
|
||||
AltHost_MenuItems[I][2].Enabled := True;
|
||||
AltHost_MenuItems[I][3].Enabled := True;
|
||||
AltHost_MenuItems[I][5].Enabled := True;
|
||||
Settings.setKeyValue('Host' + IntToStr(I), Data);
|
||||
begin
|
||||
WriteLn('[Paster]Error: The host cannot be blank!');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
AltHost_Menus[I].Menu.Caption := Data;
|
||||
Settings.setKeyValue('Host' + IntToStr(AltHost_Menus[I].Index), Data);
|
||||
end;
|
||||
end;
|
||||
|
||||
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;
|
||||
|
||||
procedure OnClick(Sender: TObject);
|
||||
var
|
||||
I, K: integer;
|
||||
Data: string;
|
||||
begin;
|
||||
{$IFDEF DEV}
|
||||
if (Sender is TMenuItem) then
|
||||
@ -204,6 +264,25 @@ begin;
|
||||
|
||||
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.Checked := (not (Private_MenuItem.Checked));
|
||||
Settings.setKeyValue('Private', Lowercase(BoolToStr(Private_MenuItem.Checked)));
|
||||
@ -216,18 +295,14 @@ begin;
|
||||
end;
|
||||
end;
|
||||
|
||||
for I := 1 to 5 do
|
||||
for K := 1 to 6 do
|
||||
if (Sender = AltHost_MenuItems[I][K]) then
|
||||
begin
|
||||
case K of
|
||||
1: Paste(Settings.getKeyValue('Host' + IntToStr(I)), ScriptText);
|
||||
2: Paste(Settings.getKeyValue('Host' + IntToStr(I)), GetSelectedText);
|
||||
3: GetPaste(Settings.getKeyValue('Host' + IntToStr(I)));
|
||||
5: UpdateDefault(I);
|
||||
6: UpdateHost(I);
|
||||
end;
|
||||
Break;
|
||||
for I := 0 to High(AltHost_Menus) do
|
||||
with AltHost_Menus[I] do
|
||||
case Sender of
|
||||
Paste_MenuItem: Paste(Settings.getKeyValue('Host' + IntToStr(Index)), ScriptText);
|
||||
PasteS_MenuItem: Paste(Settings.getKeyValue('Host' + IntToStr(Index)), GetSelectedText);
|
||||
GetPaste_MenuItem: GetPaste(Settings.getKeyValue('Host' + IntToStr(Index)));
|
||||
Default_MenuItem: UpdateDefault(I);
|
||||
Update_MenuItem: UpdateHost(I);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -242,14 +317,14 @@ begin
|
||||
Paster_Menu.Visible := False;
|
||||
end;
|
||||
|
||||
procedure init;
|
||||
procedure Init;
|
||||
var
|
||||
I, K: integer;
|
||||
begin;
|
||||
Paster_Menu := TMenuItem.Create(Simba_MainMenu);
|
||||
Paster_Menu.Caption := GetName;
|
||||
Simba_MainMenu.Items.Add(Paster_Menu);
|
||||
|
||||
|
||||
Paster_MenuItems[1] := TMenuItem.Create(Paster_Menu);
|
||||
with Paster_MenuItems[1] do
|
||||
begin
|
||||
@ -306,56 +381,32 @@ begin;
|
||||
Paster_Menu.Add(Browser_MenuItem);
|
||||
|
||||
Paster_Menu.Add(Divider_MenuItems[2]);
|
||||
|
||||
|
||||
AltHost_Menu := TMenuItem.Create(Paster_Menu);
|
||||
AltHost_Menu.Caption := 'Hosts';
|
||||
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
|
||||
AltHost_Menus[I] := TMenuItem.Create(AltHost_Menu);
|
||||
if (I = 1) then
|
||||
AltHost_Menus[I].Caption := HOSTDef
|
||||
else
|
||||
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;
|
||||
if (Settings.GetKeyValue('Host' + IntToStr(I)) = 'Host ' + IntToStr(I)) then
|
||||
Continue;
|
||||
CreateAltMenu(I);
|
||||
Inc(I);
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
@ -369,3 +420,4 @@ begin
|
||||
{$ENDIF}
|
||||
end.
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user