1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-24 16:28:53 -05:00

Commits: Initial support for external editor.

Doesn't work properly yet. I can't get the SynEdit to focus on tab change. And
this is required when changing from a ReadOnly tab to a ReadWrite tab.
This commit is contained in:
Merlijn Wajer 2011-02-22 22:00:00 +01:00
parent c0b6afa570
commit a0df9d7e7c
3 changed files with 98 additions and 24 deletions

View File

@ -83,9 +83,13 @@ type
procedure undo;
procedure redo;
procedure HandleErrorData;
function GetReadOnly: Boolean;
procedure SetReadOnly(ReadOnly: Boolean);
procedure MakeActiveScriptFrame;
procedure ScriptThreadTerminate(Sender: TObject);
constructor Create(TheOwner: TComponent); override;
procedure ReloadScript;
{ public declarations }
end;
@ -644,6 +648,37 @@ begin
AddKey(SynEdit,ecCodeHints,VK_SPACE,[ssCtrl,ssShift]);
end;
function TScriptFrame.GetReadOnly: Boolean;
begin
Result := SynEdit.ReadOnly;
end;
procedure TScriptFrame.SetReadOnly(ReadOnly: Boolean);
begin
SynEdit.ReadOnly := ReadOnly;
SynEdit.Enabled := not ReadOnly;
if not ReadOnly then
SynEdit.SetFocus;
end;
procedure TScriptFrame.ReloadScript;
var
newScript: String;
ExternScript: TFileStream;
begin
try
ExternScript := TFileStream.Create(ScriptFile, fmOpenRead);
ExternScript.Read(NewScript, ExternScript.Size);
SynEdit.Lines.SetText(PChar(NewScript));
except
on EFOpenError do
begin
formWriteln('Could not open extern script :' + ScriptFile);
end;
end;
end;
initialization
{$R *.lfm}

View File

@ -5,7 +5,7 @@ object SimbaForm: TSimbaForm
Width = 660
AllowDropFiles = True
Caption = 'THA FUKING Simba'
ClientHeight = 603
ClientHeight = 598
ClientWidth = 660
KeyPreview = True
Menu = MainMenu
@ -207,8 +207,8 @@ object SimbaForm: TSimbaForm
end
object StatusBar: TStatusBar
Left = 0
Height = 23
Top = 580
Height = 21
Top = 577
Width = 660
Panels = <
item
@ -230,7 +230,7 @@ object SimbaForm: TSimbaForm
object PanelMemo: TPanel
Left = 0
Height = 154
Top = 426
Top = 423
Width = 660
Align = alBottom
ClientHeight = 154
@ -253,19 +253,19 @@ object SimbaForm: TSimbaForm
Cursor = crVSplit
Left = 0
Height = 5
Top = 421
Top = 418
Width = 660
Align = alBottom
ResizeAnchor = akBottom
end
object ScriptPanel: TPanel
Left = 0
Height = 397
Height = 394
Top = 24
Width = 660
Align = alClient
BevelOuter = bvNone
ClientHeight = 397
ClientHeight = 394
ClientWidth = 660
DockSite = True
TabOrder = 4
@ -273,7 +273,7 @@ object SimbaForm: TSimbaForm
OnDockOver = ScriptPanelDockOver
object PageControl1: TPageControl
Left = 155
Height = 362
Height = 359
Top = 0
Width = 505
Align = alClient
@ -292,7 +292,7 @@ object SimbaForm: TSimbaForm
object SearchPanel: TPanel
Left = 0
Height = 35
Top = 362
Top = 359
Width = 660
Align = alBottom
BevelOuter = bvSpace
@ -387,7 +387,7 @@ object SimbaForm: TSimbaForm
end
object LabeledEditSearch: TLabeledEdit
Left = 104
Height = 21
Height = 27
Top = 6
Width = 80
EditLabel.AnchorSideLeft.Control = LabeledEditSearch
@ -395,10 +395,10 @@ object SimbaForm: TSimbaForm
EditLabel.AnchorSideTop.Side = asrCenter
EditLabel.AnchorSideRight.Control = LabeledEditSearch
EditLabel.AnchorSideBottom.Control = LabeledEditSearch
EditLabel.Left = 73
EditLabel.Height = 14
EditLabel.Top = 9
EditLabel.Width = 28
EditLabel.Left = 67
EditLabel.Height = 18
EditLabel.Top = 10
EditLabel.Width = 34
EditLabel.Caption = 'Find: '
EditLabel.ParentColor = False
LabelPosition = lpLeft
@ -411,9 +411,9 @@ object SimbaForm: TSimbaForm
end
object CheckBoxMatchCase: TCheckBox
Left = 320
Height = 17
Height = 22
Top = 7
Width = 72
Width = 97
Caption = 'Match case'
OnClick = CheckBoxMatchCaseClick
TabOrder = 1
@ -421,34 +421,38 @@ object SimbaForm: TSimbaForm
end
object SplitterFunctionList: TSplitter
Left = 150
Height = 362
Height = 359
Top = 0
Width = 5
OnCanResize = SplitterFunctionListCanResize
Visible = False
end
inline frmFunctionList: TFunctionListFrame
Height = 362
Height = 359
Width = 150
ClientHeight = 362
ClientHeight = 359
ClientWidth = 150
OnEndDock = nil
TabOrder = 3
inherited FunctionList: TTreeView
Height = 323
Height = 310
Top = 22
Width = 150
DefaultItemHeight = 19
OnChange = FunctionListChange
OnEnter = FunctionListEnter
OnExit = FunctionListExit
end
inherited editSearchList: TEdit
Top = 341
Height = 27
Top = 332
Width = 150
OnExit = editSearchListExit
OnKeyDown = editSearchListKeyDown
OnKeyPress = editSearchListKeyPress
end
inherited FunctionListLabel: TLabel
Height = 18
Width = 146
end
end
@ -2839,6 +2843,10 @@ object SimbaForm: TSimbaForm
Caption = 'Close Other Tabs'
OnClick = MenuItemTabCloseOthersClick
end
object MenuItemReadOnlyTab: TMenuItem
Caption = 'Read Only'
OnClick = MenuItemReadOnlyTabClick
end
end
object ActionList: TActionList
Images = Mufasa_Image_List

View File

@ -30,7 +30,7 @@ unit SimbaUnit;
interface
uses
{$ifdef linux}cthreads,{$endif}Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
{$ifdef linux}cthreads,cmem,{$endif}Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Menus, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas,
//Client,
MufasaTypes,
@ -116,6 +116,7 @@ type
MenuHelp: TMenuItem;
MenuDivider7: TMenuItem;
MenuInterpreters: TMenuItem;
MenuItemReadOnlyTab: TMenuItem;
MenuItemGoto: TMenuItem;
MenuItemDivider50: TMenuItem;
MenuItemPascalScript: TMenuItem;
@ -288,6 +289,7 @@ type
procedure FunctionListEnter(Sender: TObject);
procedure FunctionListExit(Sender: TObject);
procedure FunctionListTimerTimer(Sender: TObject);
procedure MenuItemReadOnlyTabClick(Sender: TObject);
procedure MenuItemBitmapConvClick(Sender: TObject);
procedure MenuItemHandbookClick(Sender: TObject);
procedure MenuItemColourHistoryClick(Sender: TObject);
@ -1204,6 +1206,7 @@ begin
LabeledEditSearch.SelLength:= 0;
LabeledEditSearch.Color:= clWindow;
LabeledEditSearch.Font.Color:= clWindowText;
//Set tha edit buttons right
SetEditActions;
end;
@ -1454,8 +1457,16 @@ var
Se: TMMLSettingsSandbox;
loadFontsOnScriptStart: boolean;
Continue : boolean;
begin
Script :=CurrScript.SynEdit.Lines.Text;
if (CurrScript.ScriptFile <> '') and CurrScript.GetReadOnly() then
begin
formWriteln('Reloading read only script');
CurrScript.ReloadScript;
end;
Script := CurrScript.SynEdit.Lines.Text;
if Assigned(OnScriptStart) then
begin
Continue := True;
@ -1480,6 +1491,7 @@ begin
Thread.SetDebug(@formWriteln);
{$ENDIF}
Thread.SetScript(Script);
Thread.ErrorData:= @CurrScript.ErrorData;
Thread.OnError:= @CurrScript.HandleErrorData;
FormCallBackData.FormCallBack:= @self.FormCallBack;
@ -2571,6 +2583,17 @@ begin
CloseTabs(PopupTab);
end;
procedure TSimbaForm.MenuItemReadOnlyTabClick(Sender: TObject);
var
Tab: TMufasaTab;
begin
Tab := TMufasaTab(Tabs[PopupTab]);
Tab.ScriptFrame.SetReadOnly(not Tab.ScriptFrame.GetReadOnly());
MenuItemReadOnlyTab.Checked := not Tab.ScriptFrame.GetReadOnly();
end;
procedure TSimbaForm.MenuItemFunctionListClick(Sender: TObject);
begin
FunctionListShown(not MenuItemFunctionList.Checked);
@ -2684,6 +2707,9 @@ begin
begin
mDebugLn('We couldn''t find which tab you clicked on, closing the popup');
Handled := true;
end else
begin
MenuItemReadOnlyTab.Checked := TMufasaTab(Tabs[PopupTab]).ScriptFrame.GetReadOnly();
end;
end;
@ -3065,7 +3091,7 @@ end;
procedure TSimbaForm.UpdateTitle;
begin
Application.Title:= PChar('Simba');
Application.Title:= PChar('Simba'); // XXX - Sure you want to do this for Disguise?
if CurrScript.ScriptChanged then
begin;
CurrTab.TabSheet.Caption:= CurrScript.ScriptName + '*';
@ -3165,6 +3191,11 @@ end;
function TSimbaForm.SaveCurrentScript: boolean;
begin
if CurrScript.GetReadOnly() then
begin
formWriteln('Script is in read-only/external editor mode. Not saving!');
exit(false);
end;
if not CurrScript.ScriptChanged then
begin
writeln('SaveScript - no changes.');