2009-10-12 11:04:52 -04:00
|
|
|
{
|
|
|
|
This file is part of the Mufasa Macro Library (MML)
|
2009-10-12 13:47:46 -04:00
|
|
|
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
2009-10-12 11:04:52 -04:00
|
|
|
|
|
|
|
MML is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
MML is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with MML. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
See the file COPYING, included in this distribution,
|
|
|
|
for details about the copyright.
|
|
|
|
|
|
|
|
TestUnit/GUI for the Mufasa Macro Library
|
|
|
|
}
|
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
unit TestUnit;
|
|
|
|
|
2009-10-20 15:48:18 -04:00
|
|
|
{$Undef ProcessMessages} //Define this for processmessages in ThreadSafeCall
|
2009-09-04 00:26:56 -04:00
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2009-11-02 06:07:41 -05:00
|
|
|
{$ifdef linux}cthreads,{$endif}Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
2009-09-25 15:29:03 -04:00
|
|
|
StdCtrls, Menus, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, SynMemo,
|
2009-09-22 16:55:15 -04:00
|
|
|
//Client,
|
|
|
|
MufasaTypes,
|
|
|
|
mmlpsthread,
|
2009-09-22 19:58:14 -04:00
|
|
|
window, // for the comp picker and selector
|
2009-11-03 12:23:34 -05:00
|
|
|
colourpicker, framescript, windowselector, lcltype, ActnList, StdActns,
|
|
|
|
SynEditKeyCmds, SynEditHighlighter, SynEditMarkupSpecialLine,SynEditMarkupHighAll,
|
|
|
|
SynEditMiscClasses, LMessages, Buttons;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
type
|
2009-10-31 17:44:13 -04:00
|
|
|
|
|
|
|
{ TMufasaTab }
|
|
|
|
|
|
|
|
TMufasaTab = class(Tobject)
|
|
|
|
private
|
|
|
|
PageCtrl : TPageControl;
|
|
|
|
public
|
|
|
|
TabSheet : TTabsheet;
|
|
|
|
ScriptFrame : TScriptFrame;
|
|
|
|
procedure Clear;//This will 'reset' the ScriptFrame
|
|
|
|
constructor Create(Page : TPageControl);
|
|
|
|
destructor Destroy; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Tab
|
2009-09-04 00:26:56 -04:00
|
|
|
{ TForm1 }
|
|
|
|
|
|
|
|
TForm1 = class(TForm)
|
2009-11-04 15:05:35 -05:00
|
|
|
ActionFindStart: TAction;
|
2009-11-01 12:23:16 -05:00
|
|
|
ActionClearDebug: TAction;
|
2009-11-01 08:56:54 -05:00
|
|
|
ActionSaveAll: TAction;
|
|
|
|
ActionStopScript: TAction;
|
|
|
|
ActionSaveScript: TAction;
|
|
|
|
ActionSaveScriptAs: TAction;
|
|
|
|
ActionRunScript: TAction;
|
|
|
|
ActionPauseScript: TAction;
|
|
|
|
ActionNewScript: TAction;
|
|
|
|
ActionOpenScript: TAction;
|
|
|
|
ActionNewTab: TAction;
|
|
|
|
ActionCloseTab: TAction;
|
|
|
|
ActionTabLast: TAction;
|
|
|
|
ActionTabNext: TAction;
|
|
|
|
ActionList: TActionList;
|
2009-11-03 12:23:34 -05:00
|
|
|
LabeledEditSearch: TLabeledEdit;
|
2009-10-09 18:17:35 -04:00
|
|
|
Memo1: TMemo;
|
2009-10-17 13:57:09 -04:00
|
|
|
MenuFile: TMenuItem;
|
|
|
|
MenuEdit: TMenuItem;
|
2009-11-03 12:23:34 -05:00
|
|
|
MenuItemFind: TMenuItem;
|
|
|
|
MenuItemDivider4: TMenuItem;
|
2009-11-01 23:10:32 -05:00
|
|
|
MenuItemDivider3: TMenuItem;
|
|
|
|
MenuItemCopy: TMenuItem;
|
2009-11-01 08:56:54 -05:00
|
|
|
MenuItemSaveAll: TMenuItem;
|
|
|
|
MenuItemTabCloseOthers: TMenuItem;
|
|
|
|
MenuItemTabAdd: TMenuItem;
|
|
|
|
MenuItemTabClose: TMenuItem;
|
|
|
|
MenuItemCloseTabs: TMenuItem;
|
|
|
|
MenuItemCloseTab: TMenuItem;
|
|
|
|
MenuItemNewTab: TMenuItem;
|
|
|
|
MenuItemDivider2: TMenuItem;
|
|
|
|
MenuItemDivider: TMenuItem;
|
2009-11-03 12:23:34 -05:00
|
|
|
PageControl1: TPageControl;
|
|
|
|
SearchPanel: TPanel;
|
|
|
|
ScriptPanel: TPanel;
|
2009-11-01 08:56:54 -05:00
|
|
|
TabPopup: TPopupMenu;
|
|
|
|
TB_SaveAll: TToolButton;
|
2009-11-04 17:41:06 -05:00
|
|
|
DebugTimer: TTimer;
|
2009-11-01 08:56:54 -05:00
|
|
|
TrayDivider: TMenuItem;
|
2009-10-31 19:31:51 -04:00
|
|
|
TrayPlay: TMenuItem;
|
|
|
|
TrayStop: TMenuItem;
|
|
|
|
TrayPause: TMenuItem;
|
2009-10-24 12:00:10 -04:00
|
|
|
MenuItemPause: TMenuItem;
|
|
|
|
MenuItemStop: TMenuItem;
|
2009-10-24 11:37:00 -04:00
|
|
|
MenuItemShow: TMenuItem;
|
|
|
|
MenuItemExit: TMenuItem;
|
2009-10-24 10:01:21 -04:00
|
|
|
MenuItemCut: TMenuItem;
|
|
|
|
MenuItemPaste: TMenuItem;
|
2009-10-17 13:57:09 -04:00
|
|
|
MenuItemNew: TMenuItem;
|
|
|
|
MenuItemSaveAs: TMenuItem;
|
|
|
|
MenuItemOpen: TMenuItem;
|
|
|
|
MenuItemRedo: TMenuItem;
|
|
|
|
MenuItemUndo: TMenuItem;
|
|
|
|
MenuItemSave: TMenuItem;
|
2009-09-22 16:55:15 -04:00
|
|
|
Mufasa_Image_List: TImageList;
|
2009-09-19 22:08:02 -04:00
|
|
|
MainMenu1: TMainMenu;
|
|
|
|
MenuItemScript: TMenuItem;
|
|
|
|
MenuItemRun: TMenuItem;
|
2009-10-25 07:01:28 -04:00
|
|
|
PanelMemo: TPanel;
|
|
|
|
SplitterMemoSynedit: TSplitter;
|
2009-10-24 11:37:00 -04:00
|
|
|
TrayPopup: TPopupMenu;
|
2009-10-17 13:57:09 -04:00
|
|
|
StatusBar: TStatusBar;
|
2009-09-22 16:55:15 -04:00
|
|
|
ToolBar1: TToolBar;
|
|
|
|
TB_Run: TToolButton;
|
|
|
|
TB_Pause: TToolButton;
|
|
|
|
TB_Stop: TToolButton;
|
|
|
|
ToolButton1: TToolButton;
|
|
|
|
TB_ReloadPlugins: TToolButton;
|
2009-09-25 15:29:03 -04:00
|
|
|
TB_Tray: TToolButton;
|
2009-09-22 16:55:15 -04:00
|
|
|
TB_NewTab: TToolButton;
|
|
|
|
TB_CloseTab: TToolButton;
|
2009-10-24 10:01:21 -04:00
|
|
|
TB_New: TToolButton;
|
|
|
|
ToolButton2: TToolButton;
|
|
|
|
TB_Open: TToolButton;
|
2009-10-25 07:01:28 -04:00
|
|
|
TB_Save: TToolButton;
|
2009-09-22 16:55:15 -04:00
|
|
|
ToolButton4: TToolButton;
|
|
|
|
TB_ClearDebug: TToolButton;
|
|
|
|
TB_PickColour: TToolButton;
|
|
|
|
TB_SelectClient: TToolButton;
|
|
|
|
ToolButton8: TToolButton;
|
|
|
|
TB_Convert: TToolButton;
|
2009-09-25 15:29:03 -04:00
|
|
|
MTrayIcon: TTrayIcon;
|
2009-11-01 12:23:16 -05:00
|
|
|
procedure ActionClearDebugExecute(Sender: TObject);
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure ActionCloseTabExecute(Sender: TObject);
|
2009-11-04 15:05:35 -05:00
|
|
|
procedure ActionFindstartExecute(Sender: TObject);
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure ActionNewExecute(Sender: TObject);
|
|
|
|
procedure ActionNewTabExecute(Sender: TObject);
|
|
|
|
procedure ActionOpenExecute(Sender: TObject);
|
|
|
|
procedure ActionPauseExecute(Sender: TObject);
|
|
|
|
procedure ActionRunExecute(Sender: TObject);
|
|
|
|
procedure ActionSaveAllExecute(Sender: TObject);
|
|
|
|
procedure ActionSaveAsExecute(Sender: TObject);
|
|
|
|
procedure ActionSaveExecute(Sender: TObject);
|
|
|
|
procedure ActionStopExecute(Sender: TObject);
|
|
|
|
procedure ActionTabLastExecute(Sender: TObject);
|
|
|
|
procedure ActionTabNextExecute(Sender: TObject);
|
2009-11-03 12:23:34 -05:00
|
|
|
procedure EditSearchChange(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
2009-09-12 14:50:10 -04:00
|
|
|
procedure FormCreate(Sender: TObject);
|
2009-09-13 19:56:15 -04:00
|
|
|
procedure FormDestroy(Sender: TObject);
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure FormShortCuts(var Msg: TLMKey; var Handled: Boolean);
|
2009-11-04 15:05:35 -05:00
|
|
|
procedure LabeledEditSearchEnter(Sender: TObject);
|
|
|
|
procedure LabeledEditSearchExit(Sender: TObject);
|
|
|
|
procedure LabeledEditSearchKeyDown(Sender: TObject; var Key: Word;
|
|
|
|
Shift: TShiftState);
|
|
|
|
procedure LabeledEditSearchKeyPress(Sender: TObject; var Key: char);
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure MenuItemCloseTabsClick(Sender: TObject);
|
2009-11-01 23:10:32 -05:00
|
|
|
procedure MenuItemCopyClick(Sender: TObject);
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure MenuItemCutClick(Sender: TObject);
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure MenuItemExitClick(Sender: TObject);
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure MenuItemPasteClick(Sender: TObject);
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure MenuItemShowClick(Sender: TObject);
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure MenuItemTabCloseClick(Sender: TObject);
|
|
|
|
procedure MenuItemTabCloseOthersClick(Sender: TObject);
|
2009-10-18 16:11:47 -04:00
|
|
|
procedure OnLinePSScript(Sender: TObject);
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure ButtonPickClick(Sender: TObject);
|
|
|
|
procedure MenuItemRedoClick(Sender: TObject);
|
|
|
|
procedure ButtonSelectorDown(Sender: TObject; Button: TMouseButton;
|
2009-09-23 16:18:33 -04:00
|
|
|
Shift: TShiftState; X, Y: Integer);
|
2009-09-25 15:29:03 -04:00
|
|
|
procedure NoTray(Sender: TObject);
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure PageControl1Change(Sender: TObject);
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure ButtonTrayClick(Sender: TObject);
|
|
|
|
procedure MenuItemUndoClick(Sender: TObject);
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure PageControl1ContextPopup(Sender: TObject; MousePos: TPoint;
|
|
|
|
var Handled: Boolean);
|
|
|
|
procedure PageControl1DragDrop(Sender, Source: TObject; X, Y: Integer);
|
|
|
|
procedure PageControl1DragOver(Sender, Source: TObject; X, Y: Integer;
|
|
|
|
State: TDragState; var Accept: Boolean);
|
|
|
|
procedure PageControl1MouseDown(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
2009-11-04 17:41:06 -05:00
|
|
|
procedure ProcessDebugStream(Sender: TObject);
|
2009-09-04 00:26:56 -04:00
|
|
|
private
|
2009-11-01 08:56:54 -05:00
|
|
|
PopupTab : integer;
|
2009-11-04 15:05:35 -05:00
|
|
|
SearchStart : TPoint;
|
2009-10-31 17:44:13 -04:00
|
|
|
function GetScriptState: TScriptState;
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure SetScriptState(const State: TScriptState);
|
2009-09-04 00:26:56 -04:00
|
|
|
public
|
2009-11-04 17:41:06 -05:00
|
|
|
DebugStream: String;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrScript : TScriptFrame; //The current scriptframe
|
|
|
|
CurrTab : TMufasaTab; //The current TMufasaTab
|
|
|
|
Tabs : TList;
|
2009-09-22 16:55:15 -04:00
|
|
|
Window: TMWindow;
|
2009-09-22 19:58:14 -04:00
|
|
|
Picker: TMColorPicker;
|
2009-09-23 16:18:33 -04:00
|
|
|
Selector: TMWindowSelector;
|
2009-10-31 17:44:13 -04:00
|
|
|
property ScriptState : TScriptState read GetScriptState write SetScriptState;
|
2009-10-18 16:11:47 -04:00
|
|
|
procedure SafeCallThread;
|
2009-10-17 13:57:09 -04:00
|
|
|
function OpenScript : boolean;
|
|
|
|
function SaveCurrentScript : boolean;
|
|
|
|
function SaveCurrentScriptAs : boolean;
|
|
|
|
function CanExitOrOpen : boolean;
|
|
|
|
function ClearScript : boolean;
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure RunScript;
|
|
|
|
procedure PauseScript;
|
|
|
|
procedure StopScript;
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure Cut;
|
2009-11-01 23:10:32 -05:00
|
|
|
procedure Copy;
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure Paste;
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure AddTab;
|
|
|
|
function DeleteTab( TabIndex : integer; CloseLast : boolean) : boolean;
|
|
|
|
procedure ClearTab( TabIndex : integer);
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure CloseTabs( Exclude : integer);overload;//-1 for none
|
|
|
|
procedure CloseTabs;overload;
|
2009-11-04 15:05:35 -05:00
|
|
|
procedure DoSearch(Next : boolean);
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure RefreshTab;//Refreshes all the form items that depend on the Script (Panels, title etc.)
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
2009-11-04 17:41:06 -05:00
|
|
|
|
|
|
|
procedure formWriteln( S : String);
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
const
|
|
|
|
WindowTitle = 'Mufasa v2 - %s';//Title, where %s = the place of the filename.
|
2009-10-24 11:37:00 -04:00
|
|
|
Panel_State = 0;
|
|
|
|
Panel_ScriptName = 1;
|
|
|
|
Panel_ScriptPath = 2;
|
|
|
|
Image_Stop = 7;
|
|
|
|
Image_Terminate = 19;
|
2009-09-04 00:26:56 -04:00
|
|
|
var
|
2009-09-22 18:28:10 -04:00
|
|
|
Form1: TForm1;
|
2009-10-20 15:48:18 -04:00
|
|
|
MainDir : string;
|
2009-10-18 16:11:47 -04:00
|
|
|
CurrentSyncInfo : TSyncInfo;//We need this for SafeCallThread
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
implementation
|
2009-09-09 03:08:58 -04:00
|
|
|
uses
|
2009-11-04 17:41:06 -05:00
|
|
|
lclintf,plugins,
|
|
|
|
syncobjs; // for the critical sections
|
2009-09-04 00:26:56 -04:00
|
|
|
|
2009-11-04 17:41:06 -05:00
|
|
|
//{$ifdef mswindows}
|
|
|
|
|
|
|
|
var
|
|
|
|
DebugCriticalSection: syncobjs.TCriticalSection;
|
|
|
|
|
|
|
|
procedure TForm1.ProcessDebugStream(Sender: TObject);
|
|
|
|
|
|
|
|
begin
|
|
|
|
if length(DebugStream) = 0 then
|
|
|
|
Exit;
|
|
|
|
|
|
|
|
// cut off 1 newline char
|
|
|
|
|
|
|
|
DebugCriticalSection.Enter;
|
|
|
|
|
|
|
|
try
|
|
|
|
setlength(DebugStream, length(DebugStream) - 1);
|
|
|
|
Memo1.Lines.Add(DebugStream);
|
|
|
|
SetLength(DebugStream, 0);
|
|
|
|
finally
|
|
|
|
DebugCriticalSection.Leave;
|
|
|
|
end;
|
2009-10-25 07:01:28 -04:00
|
|
|
end;
|
2009-11-04 17:41:06 -05:00
|
|
|
|
|
|
|
procedure formWriteln( S : String);
|
|
|
|
|
|
|
|
begin
|
|
|
|
s := s + #10;
|
|
|
|
DebugCriticalSection.Enter;
|
|
|
|
try
|
|
|
|
Form1.DebugStream:= Form1.DebugStream + s;
|
|
|
|
finally
|
|
|
|
DebugCriticalSection.Leave;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
writeln('formWriteln: ' + s);
|
|
|
|
//Form1.Memo1.Lines.Add(s);
|
|
|
|
end;
|
|
|
|
|
|
|
|
//{$ENDIF}
|
2009-09-04 00:26:56 -04:00
|
|
|
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure TForm1.RunScript;
|
2009-09-04 00:26:56 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
with CurrScript do
|
|
|
|
begin
|
|
|
|
if ScriptState = ss_Paused then
|
|
|
|
begin;
|
|
|
|
ScriptThread.Resume;
|
|
|
|
ScriptState := ss_Running;
|
|
|
|
Exit;
|
|
|
|
end else
|
|
|
|
if ScriptState <> ss_None then
|
|
|
|
begin;
|
|
|
|
Writeln('The script hasn''t stopped yet, so we cannot start a new one.');
|
|
|
|
exit;
|
|
|
|
end;
|
2009-10-31 19:31:51 -04:00
|
|
|
ScriptErrorLine:= -1;
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread;
|
|
|
|
ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo);
|
|
|
|
ScriptThread.SetPSScript(CurrScript.SynEdit.Lines.Text);
|
2009-11-04 17:41:06 -05:00
|
|
|
// ScriptThread.SetDebug(Self.Memo1);
|
2009-11-04 18:02:37 -05:00
|
|
|
{$IFNDEF TERMINALWRITELN}
|
2009-11-04 17:41:06 -05:00
|
|
|
ScriptThread.SetDebug(@formWriteln);
|
2009-11-04 18:02:37 -05:00
|
|
|
{$ENDIF}
|
2009-10-31 17:44:13 -04:00
|
|
|
ScriptThread.OnError:=@ErrorThread;
|
|
|
|
if ScriptFile <> '' then
|
|
|
|
ScriptThread.SetPaths( ExtractFileDir(ScriptFile) + DS,IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)))
|
|
|
|
else
|
|
|
|
ScriptThread.SetPaths('', IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)));
|
|
|
|
|
|
|
|
// This doesn't actually set the Client's MWindow to the passed window, it
|
|
|
|
// only copies the current set window handle.
|
|
|
|
ScriptThread.Client.MWindow.SetWindow(Self.Window);
|
|
|
|
|
2009-11-02 19:40:07 -05:00
|
|
|
// we MUST set the OCR Path
|
|
|
|
writeln(IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + DS + 'Fonts' + DS);
|
|
|
|
ScriptThread.Client.MOCR.InitTOCR(IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)) + 'Fonts' + DS);
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
ScriptThread.OnTerminate:=@ScriptThreadTerminate;
|
|
|
|
ScriptState:= ss_Running;
|
|
|
|
//Lets run it!
|
2009-10-24 11:37:00 -04:00
|
|
|
ScriptThread.Resume;
|
|
|
|
end;
|
|
|
|
end;
|
2009-09-28 22:12:29 -04:00
|
|
|
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure TForm1.PauseScript;
|
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
with CurrScript do
|
2009-10-24 11:37:00 -04:00
|
|
|
begin;
|
2009-10-31 17:44:13 -04:00
|
|
|
if ScriptState = ss_Running then
|
|
|
|
begin;
|
|
|
|
{$ifdef MSWindows}
|
|
|
|
ScriptThread.Suspended:= True;
|
|
|
|
ScriptState:= ss_Paused;
|
|
|
|
{$else}
|
|
|
|
Writeln('Linux users are screwed, no pause button for u!');
|
|
|
|
{$endif}
|
|
|
|
end else if ScriptState = ss_Paused then
|
|
|
|
begin;
|
|
|
|
ScriptThread.Resume;
|
|
|
|
ScriptState := ss_Running;
|
|
|
|
end;
|
2009-10-24 11:37:00 -04:00
|
|
|
end;
|
|
|
|
end;
|
2009-09-28 22:12:29 -04:00
|
|
|
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure TForm1.StopScript;
|
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
with CurrScript do
|
|
|
|
begin;
|
|
|
|
case ScriptState of
|
|
|
|
ss_Stopping:
|
|
|
|
begin //Terminate the thread the tough way.
|
|
|
|
writeln('Terminating the Scriptthread');
|
2009-11-01 10:04:03 -05:00
|
|
|
Writeln('Exit code terminate: ' +inttostr(KillThread(ScriptThread.Handle)));
|
2009-11-02 05:18:35 -05:00
|
|
|
WaitForThreadTerminate(ScriptThread.Handle, 0);
|
2009-10-31 17:44:13 -04:00
|
|
|
ScriptThread.Free;
|
|
|
|
ScriptState := ss_None;
|
|
|
|
end;
|
|
|
|
ss_Running:
|
|
|
|
begin
|
|
|
|
ScriptThread.PSScript.Stop;
|
|
|
|
ScriptState := ss_Stopping;
|
|
|
|
end;
|
|
|
|
ss_Paused:
|
|
|
|
begin
|
|
|
|
ScriptThread.Resume;
|
|
|
|
ScriptThread.PSScript.Stop;
|
|
|
|
ScriptState:= ss_Stopping;
|
|
|
|
end;
|
|
|
|
end;
|
2009-10-24 11:37:00 -04:00
|
|
|
end;
|
2009-09-19 22:08:02 -04:00
|
|
|
end;
|
2009-09-12 02:24:59 -04:00
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure TForm1.Cut;
|
2009-10-24 10:01:21 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrScript.SynEdit.CutToClipboard;
|
2009-10-24 10:01:21 -04:00
|
|
|
end;
|
|
|
|
|
2009-11-01 23:10:32 -05:00
|
|
|
procedure TForm1.Copy;
|
|
|
|
begin
|
|
|
|
CurrScript.SynEdit.CopyToClipboard;
|
|
|
|
end;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure TForm1.Paste;
|
2009-10-24 10:01:21 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrScript.SynEdit.PasteFromClipboard;
|
2009-10-24 10:01:21 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure TForm1.AddTab;
|
|
|
|
var
|
|
|
|
Tab : TMufasaTab;
|
|
|
|
begin;
|
|
|
|
Tab := TMufasaTab.Create(Self.PageControl1);
|
|
|
|
Tabs.Add(Tab);
|
2009-11-04 10:56:28 -05:00
|
|
|
Tab.TabSheet.ImageIndex:= 8;
|
2009-11-01 08:56:54 -05:00
|
|
|
// Tab.TabSheet.OnContextPopup:= @TabPopup;
|
2009-10-31 17:44:13 -04:00
|
|
|
PageControl1.TabIndex:= Tabs.Count - 1;
|
|
|
|
RefreshTab;
|
2009-11-01 08:56:54 -05:00
|
|
|
if tabs.count > 1 then
|
|
|
|
begin;
|
|
|
|
TB_SaveAll.Enabled:= True;
|
|
|
|
MenuItemSaveAll.Enabled:= True;
|
|
|
|
end;
|
2009-10-31 17:44:13 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.DeleteTab(TabIndex: integer; CloseLast : boolean) : boolean;
|
|
|
|
var
|
|
|
|
Tab : TMufasaTab;
|
2009-11-01 08:56:54 -05:00
|
|
|
OldIndex : integer;//So that we can switch back, if needed.
|
2009-10-24 10:01:21 -04:00
|
|
|
begin
|
2009-11-01 08:56:54 -05:00
|
|
|
OldIndex := PageControl1.TabIndex;
|
2009-10-31 17:44:13 -04:00
|
|
|
PageControl1.TabIndex:= TabIndex;
|
|
|
|
//ScriptFrame now is now correct ;-D
|
|
|
|
result := CanExitOrOpen;
|
|
|
|
if not result then
|
|
|
|
exit;
|
|
|
|
Tab := TMufasaTab(Tabs[TabIndex]);
|
|
|
|
if (Tabs.Count = 1) and (not CloseLast) then
|
|
|
|
Tab.Clear
|
|
|
|
else
|
|
|
|
begin;
|
|
|
|
Tab.Free;
|
|
|
|
Tabs.Delete(TabIndex);
|
2009-11-01 08:56:54 -05:00
|
|
|
if OldIndex > TabIndex then
|
|
|
|
PageControl1.TabIndex := OldIndex - 1
|
|
|
|
else if OldIndex < TabIndex then
|
|
|
|
PageControl1.TabIndex := OldIndex;
|
|
|
|
end;
|
|
|
|
if tabs.count <= 1 then
|
|
|
|
begin;
|
|
|
|
TB_SaveAll.Enabled:= false;
|
|
|
|
MenuItemSaveAll.Enabled:= false;
|
2009-10-31 17:44:13 -04:00
|
|
|
end;
|
2009-10-24 10:01:21 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure TForm1.ClearTab(TabIndex: integer);
|
2009-10-24 10:01:21 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
TMufasaTab(Tabs[TabIndex]).Clear;
|
|
|
|
end;
|
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.CloseTabs(Exclude: integer);
|
|
|
|
var
|
|
|
|
I : integer;
|
|
|
|
begin
|
|
|
|
for i := tabs.count - 1 downto 0 do
|
|
|
|
if i <> exclude then
|
2009-11-01 23:10:32 -05:00
|
|
|
if not DeleteTab(i,false) then
|
|
|
|
exit;
|
2009-11-01 08:56:54 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.CloseTabs;
|
|
|
|
begin
|
|
|
|
CloseTabs(-1);
|
|
|
|
end;
|
|
|
|
|
2009-11-04 15:05:35 -05:00
|
|
|
procedure TForm1.DoSearch(Next: boolean);
|
|
|
|
var
|
|
|
|
Res : integer;
|
|
|
|
CurrPos : TPoint;
|
|
|
|
begin
|
|
|
|
if LabeledEditSearch.Text = '' then
|
|
|
|
begin
|
|
|
|
res := -1;
|
|
|
|
CurrScript.Synedit.SetHighlightSearch('',[]);
|
|
|
|
// CurrScript.SynEdit.SelectionMode:=
|
|
|
|
// CurrScript.SynEdit.CaretXY := CurrScript.SynEdit.CaretXY;
|
|
|
|
CurrScript.SynEdit.LogicalCaretXY := SearchStart;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Writeln('Searching: ' + LabeledEditSearch.Text);
|
|
|
|
if next then
|
|
|
|
CurrPos := CurrScript.SynEdit.LogicalCaretXY
|
|
|
|
else
|
|
|
|
CurrPos := SearchStart;
|
|
|
|
Res := CurrScript.SynEdit.SearchReplaceEx(LabeledEditSearch.Text,'',[],CurrPos);
|
|
|
|
if res = 0 then
|
|
|
|
begin
|
|
|
|
res := CurrScript.SynEdit.SearchReplaceEx(LabeledEditSearch.text,'',[],Point(0,0));
|
|
|
|
if res > 0 then
|
|
|
|
begin;
|
|
|
|
Writeln('End of document reached');
|
|
|
|
SearchStart.x := 0;
|
|
|
|
SearchStart.Y := CurrScript.SynEdit.LogicalCaretXY.y;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if res = 0 then
|
|
|
|
begin;
|
|
|
|
LabeledEditSearch.Color := 6711039;
|
|
|
|
LabeledEditSearch.Font.Color:= clWhite;
|
|
|
|
CurrScript.Synedit.SetHighlightSearch('',[]);
|
|
|
|
CurrScript.SynEdit.LogicalCaretXY := SearchStart;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
LabeledEditSearch.Color:= clWindow;
|
|
|
|
LabeledEditSearch.Font.Color:= clWindowText;
|
|
|
|
with CurrScript.SynEdit do
|
|
|
|
SetHighlightSearch(LabeledEditSearch.text,[]);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure TForm1.RefreshTab;
|
|
|
|
var
|
|
|
|
Tab : TMufasaTab;
|
|
|
|
Script : TScriptFrame;
|
|
|
|
NewTab : integer;
|
|
|
|
begin
|
|
|
|
NewTab := PageControl1.TabIndex;
|
|
|
|
Tab := TMufasaTab(Tabs[Newtab]);
|
|
|
|
Script := Tab.ScriptFrame;
|
|
|
|
Self.CurrScript := Script;
|
|
|
|
Self.CurrTab := Tab;
|
|
|
|
if Script.ScriptChanged then
|
|
|
|
begin;
|
|
|
|
Tab.TabSheet.Caption:= Script.ScriptName + '*';
|
|
|
|
Self.Caption := Format(WindowTitle,[Script.ScriptName + '*'])
|
|
|
|
end else
|
|
|
|
begin;
|
|
|
|
Self.Caption := Format(WindowTitle,[Script.ScriptName]);
|
|
|
|
Tab.TabSheet.Caption:= Script.ScriptName;
|
|
|
|
end;
|
|
|
|
StatusBar.Panels[Panel_ScriptName].Text:= Script.ScriptName;
|
|
|
|
StatusBar.Panels[Panel_ScriptPath].text:= Script.ScriptFile;
|
|
|
|
SetScriptState(Tab.ScriptFrame.FScriptState);//To set the buttons right
|
2009-10-31 19:31:51 -04:00
|
|
|
if Self.Showing then
|
2009-11-01 08:56:54 -05:00
|
|
|
if Tab.TabSheet.TabIndex = Self.PageControl1.TabIndex then
|
|
|
|
CurrScript.SynEdit.SetFocus;
|
2009-11-04 15:05:35 -05:00
|
|
|
with CurrScript.SynEdit do
|
|
|
|
begin
|
|
|
|
SetHighlightSearch('',[]);
|
|
|
|
UseIncrementalColor:= false;
|
|
|
|
MarkupByClass[TSynEditMarkupHighlightAllCaret].TempEnable;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
LabeledEditSearch.SelLength:= 0;
|
|
|
|
LabeledEditSearch.Color:= clWindow;
|
|
|
|
LabeledEditSearch.Font.Color:= clWindowText;
|
2009-10-24 10:01:21 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.ActionTabLastExecute(Sender: TObject);
|
|
|
|
var
|
|
|
|
CurrIndex : integer;
|
|
|
|
begin
|
|
|
|
CurrIndex := PageControl1.TabIndex;
|
|
|
|
if CurrIndex = 0 then
|
|
|
|
CurrIndex := Tabs.count - 1
|
|
|
|
else
|
|
|
|
Dec(CurrIndex);
|
|
|
|
PageControl1.TabIndex:= CurrIndex;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionCloseTabExecute(Sender: TObject);
|
|
|
|
begin
|
2009-11-01 23:10:32 -05:00
|
|
|
if(PageControl1.PageCount > 1)then
|
|
|
|
Self.DeleteTab(PageControl1.TabIndex,false)
|
|
|
|
else
|
2009-11-02 04:25:49 -05:00
|
|
|
Self.ClearScript; //DeleteTab would take care of this already, but yeah, it's neater this way.
|
2009-11-01 08:56:54 -05:00
|
|
|
end;
|
|
|
|
|
2009-11-04 15:05:35 -05:00
|
|
|
procedure TForm1.ActionFindstartExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if sender = LabeledEditSearch then
|
|
|
|
SearchPanel.Visible:= false
|
|
|
|
else
|
|
|
|
SearchPanel.Visible:= true;
|
|
|
|
if SearchPanel.Visible then
|
|
|
|
LabeledEditSearch.SetFocus;
|
|
|
|
end;
|
|
|
|
|
2009-11-01 12:23:16 -05:00
|
|
|
procedure TForm1.ActionClearDebugExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Memo1.Clear;
|
|
|
|
end;
|
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.ActionNewExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.ClearScript;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionNewTabExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.AddTab;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionOpenExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.OpenScript;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionPauseExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.PauseScript;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionRunExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.RunScript;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionSaveAllExecute(Sender: TObject);
|
|
|
|
var
|
|
|
|
i : integer;
|
|
|
|
OldIndex : integer;
|
|
|
|
begin
|
|
|
|
OldIndex := PageControl1.TabIndex;
|
|
|
|
for i := 0 to Tabs.Count - 1 do
|
|
|
|
begin;
|
|
|
|
PageControl1.TabIndex:= i;
|
|
|
|
SaveCurrentScript;
|
|
|
|
end;
|
|
|
|
PageControl1.TabIndex:= oldindex;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionSaveAsExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.SaveCurrentScriptAs;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionSaveExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.SaveCurrentScript;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ActionStopExecute(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.StopScript;
|
2009-10-31 17:44:13 -04:00
|
|
|
end;
|
2009-10-24 10:01:21 -04:00
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.ActionTabNextExecute(Sender: TObject);
|
|
|
|
var
|
|
|
|
CurrIndex : integer;
|
2009-10-31 17:44:13 -04:00
|
|
|
begin
|
2009-11-01 08:56:54 -05:00
|
|
|
CurrIndex := PageControl1.TabIndex;
|
|
|
|
if CurrIndex = Tabs.count - 1 then
|
|
|
|
CurrIndex := 0
|
|
|
|
else
|
|
|
|
Inc(CurrIndex);
|
|
|
|
PageControl1.TabIndex:= CurrIndex;
|
2009-10-24 10:01:21 -04:00
|
|
|
end;
|
|
|
|
|
2009-11-03 12:23:34 -05:00
|
|
|
procedure TForm1.EditSearchChange(Sender: TObject);
|
|
|
|
begin
|
2009-11-04 15:05:35 -05:00
|
|
|
DoSearch(false);
|
2009-11-03 12:23:34 -05:00
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
2009-10-31 17:44:13 -04:00
|
|
|
var
|
|
|
|
i : integer;
|
2009-10-17 13:57:09 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
for i := Tabs.Count - 1 downto 0 do
|
|
|
|
if not DeleteTab(i,true) then
|
|
|
|
begin;
|
|
|
|
CloseAction := caNone;
|
|
|
|
exit
|
|
|
|
end;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
|
2009-09-12 14:50:10 -04:00
|
|
|
procedure TForm1.FormCreate(Sender: TObject);
|
|
|
|
begin
|
2009-11-04 15:19:13 -05:00
|
|
|
//Show close buttons @ tabs
|
|
|
|
PageControl1.Options:=PageControl1.Options+[nboShowCloseButtons];
|
2009-11-04 15:25:56 -05:00
|
|
|
PageControl1.OnCloseTabClicked:=ActionCloseTab.OnExecute;
|
2009-10-31 17:44:13 -04:00
|
|
|
Tabs := TList.Create;
|
|
|
|
AddTab;//Give it alteast 1 tab ;-).
|
2009-09-22 16:55:15 -04:00
|
|
|
Window := TMWindow.Create;
|
2009-09-22 19:58:14 -04:00
|
|
|
Picker := TMColorPicker.Create(Window);
|
2009-09-23 16:18:33 -04:00
|
|
|
Selector := TMWindowSelector.Create(Window);
|
2009-09-13 19:56:15 -04:00
|
|
|
MainDir:= ExtractFileDir(Application.ExeName);
|
|
|
|
PluginsGlob := TMPlugins.Create;
|
|
|
|
PluginsGlob.PluginDirs.Add(ExpandFileName(MainDir + DS + '..' + DS + '..'+ DS + 'Plugins'+ DS));
|
2009-11-04 17:41:06 -05:00
|
|
|
|
|
|
|
{ For writeln }
|
|
|
|
SetLength(DebugStream, 0);
|
|
|
|
DebugCriticalSection := syncobjs.TCriticalSection.Create;
|
2009-09-13 19:56:15 -04:00
|
|
|
end;
|
2009-09-12 14:50:10 -04:00
|
|
|
|
2009-09-13 19:56:15 -04:00
|
|
|
procedure TForm1.FormDestroy(Sender: TObject);
|
2009-10-31 17:44:13 -04:00
|
|
|
var
|
|
|
|
i : integer;
|
2009-09-13 19:56:15 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
for i := Tabs.Count - 1 downto 0 do
|
|
|
|
TMufasaTab(Tabs[i]).Free;
|
|
|
|
Tabs.free;
|
2009-09-23 16:18:33 -04:00
|
|
|
Selector.Free;
|
2009-09-22 19:58:14 -04:00
|
|
|
Picker.Free;
|
2009-09-22 16:55:15 -04:00
|
|
|
Window.Free;
|
2009-09-13 19:56:15 -04:00
|
|
|
PluginsGlob.Free;
|
2009-11-04 17:41:06 -05:00
|
|
|
|
|
|
|
SetLength(DebugStream, 0);
|
|
|
|
DebugCriticalSection.Free;
|
2009-09-12 14:50:10 -04:00
|
|
|
end;
|
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.FormShortCuts(var Msg: TLMKey; var Handled: Boolean);
|
|
|
|
begin
|
|
|
|
Handled := ActionList.IsShortCut(Msg);
|
|
|
|
{ ShiftState := MsgKeyDataToShiftState(Message.KeyData);
|
|
|
|
ShortCut := KeyToShortCut(Message.CharCode, ShiftState);}
|
|
|
|
end;
|
|
|
|
|
2009-11-04 15:05:35 -05:00
|
|
|
procedure TForm1.LabeledEditSearchEnter(Sender: TObject);
|
|
|
|
begin
|
|
|
|
SearchStart := CurrScript.SynEdit.LogicalCaretXY;
|
|
|
|
with CurrScript.SynEdit do
|
|
|
|
begin
|
|
|
|
UseIncrementalColor:= true;
|
|
|
|
MarkupByClass[TSynEditMarkupHighlightAllCaret].TempDisable
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.LabeledEditSearchExit(Sender: TObject);
|
|
|
|
begin
|
|
|
|
RefreshTab;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.LabeledEditSearchKeyDown(Sender: TObject; var Key: Word;
|
|
|
|
Shift: TShiftState);
|
|
|
|
begin
|
|
|
|
if (ssCtrl in Shift) and (key = vk_f) then
|
|
|
|
begin;
|
|
|
|
LabeledEditSearch.SelectAll;
|
|
|
|
end else
|
|
|
|
if key = VK_ESCAPE then
|
|
|
|
begin
|
|
|
|
ActionFindstartExecute(Sender);
|
|
|
|
CurrScript.SynEdit.SetFocus;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.LabeledEditSearchKeyPress(Sender: TObject; var Key: char);
|
|
|
|
begin
|
|
|
|
if key = #13 then
|
|
|
|
begin;
|
|
|
|
DoSearch(true);
|
|
|
|
// LabeledEditSearch.SelStart:= Length(LabeledEditSearch.Text);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.MenuItemCloseTabsClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.CloseTabs;
|
|
|
|
end;
|
|
|
|
|
2009-11-01 23:10:32 -05:00
|
|
|
procedure TForm1.MenuItemCopyClick(Sender: TObject);
|
|
|
|
begin
|
2009-11-03 12:23:34 -05:00
|
|
|
if CurrScript.SynEdit.Focused then
|
|
|
|
Self.Copy
|
|
|
|
else if Memo1.Focused then
|
|
|
|
Memo1.CopyToClipboard;
|
2009-11-01 23:10:32 -05:00
|
|
|
end;
|
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure TForm1.MenuItemCutClick(Sender: TObject);
|
|
|
|
begin
|
2009-11-03 12:23:34 -05:00
|
|
|
if CurrScript.SynEdit.Focused then
|
|
|
|
Self.Cut
|
|
|
|
else if Memo1.Focused then
|
|
|
|
Memo1.CutToClipboard;
|
2009-10-24 10:01:21 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure TForm1.MenuItemExitClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.Close;
|
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure TForm1.MenuItemPasteClick(Sender: TObject);
|
|
|
|
begin
|
2009-11-03 12:23:34 -05:00
|
|
|
if CurrScript.SynEdit.Focused then
|
|
|
|
Self.Paste
|
|
|
|
else if Memo1.Focused then
|
|
|
|
Memo1.PasteFromClipboard;
|
2009-10-24 10:01:21 -04:00
|
|
|
end;
|
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
|
|
|
|
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure TForm1.MenuItemShowClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Self.Show;
|
2009-10-31 19:31:51 -04:00
|
|
|
Self.WindowState := wsNormal;
|
2009-10-24 11:37:00 -04:00
|
|
|
end;
|
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.MenuItemTabCloseClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DeleteTab(PopupTab,false);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.MenuItemTabCloseOthersClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
CloseTabs(PopupTab);
|
|
|
|
end;
|
|
|
|
|
2009-10-18 16:11:47 -04:00
|
|
|
procedure TForm1.OnLinePSScript(Sender: TObject);
|
|
|
|
begin
|
|
|
|
//Writeln('We just completed a line!!');
|
|
|
|
{$IFDEF ProcessMessages}
|
|
|
|
Application.ProcessMessages; //Don't think that this is neccesary though
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure TForm1.ButtonPickClick(Sender: TObject);
|
2009-09-22 19:58:14 -04:00
|
|
|
var
|
|
|
|
c, x, y: Integer;
|
|
|
|
begin
|
|
|
|
Picker.Pick(c, x, y);
|
|
|
|
writeln('Picked colour: ' + inttostr(c) + ' at (' + inttostr(x) + ', ' + inttostr(y) + ')');
|
|
|
|
end;
|
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
|
|
|
|
procedure TForm1.MenuItemRedoClick(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrScript.redo;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure TForm1.ButtonSelectorDown(Sender: TObject; Button: TMouseButton;
|
2009-09-23 16:18:33 -04:00
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
|
begin
|
2009-09-23 17:56:51 -04:00
|
|
|
Window.SetTarget(Selector.Drag {$ifdef MSWINDOWS},w_window{$endif});
|
2009-09-23 18:01:19 -04:00
|
|
|
writeln('New window: ' + IntToStr(Window.{$ifdef MSWindows}TargetHandle{$else}CurWindow{$ENDIF}));
|
2009-09-23 16:18:33 -04:00
|
|
|
end;
|
|
|
|
|
2009-09-25 15:29:03 -04:00
|
|
|
procedure TForm1.NoTray(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if Not Form1.IsVisible then
|
2009-11-01 08:56:54 -05:00
|
|
|
Self.MenuItemShowClick(Sender)
|
2009-09-25 15:29:03 -04:00
|
|
|
else
|
|
|
|
Form1.Hide;
|
|
|
|
end;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
procedure TForm1.PageControl1Change(Sender: TObject);
|
2009-10-24 11:37:00 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
RefreshTab();
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure TForm1.ButtonTrayClick(Sender: TObject);
|
2009-09-25 15:29:03 -04:00
|
|
|
begin
|
|
|
|
Form1.Hide;
|
|
|
|
end;
|
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
procedure TForm1.MenuItemUndoClick(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrScript.Undo;
|
|
|
|
end;
|
|
|
|
|
2009-11-01 08:56:54 -05:00
|
|
|
procedure TForm1.PageControl1ContextPopup(Sender: TObject; MousePos: TPoint;
|
|
|
|
var Handled: Boolean);
|
|
|
|
begin
|
|
|
|
PopupTab := PageControl1.TabIndexAtClientPos(MousePos);
|
2009-11-01 10:04:03 -05:00
|
|
|
if PopupTab = -1 then
|
|
|
|
begin
|
|
|
|
Writeln('We couldn''t find which tab you clicked on, closing the popup');
|
|
|
|
Handled := true;
|
|
|
|
end;
|
2009-11-01 08:56:54 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.PageControl1DragDrop(Sender, Source: TObject; X, Y: Integer);
|
|
|
|
var
|
|
|
|
NewPos : integer;
|
|
|
|
OldPos : integer;
|
|
|
|
begin
|
|
|
|
if sender <> PageControl1 then
|
|
|
|
exit;
|
|
|
|
NewPos := PageControl1.TabIndexAtClientPos(Point(x,y));
|
|
|
|
OldPos := PageControl1.TabIndex;
|
2009-11-01 10:04:03 -05:00
|
|
|
if (NewPos <> OldPos) and (NewPos <> -1) then
|
2009-11-01 08:56:54 -05:00
|
|
|
begin;
|
|
|
|
Tabs.Move(OldPos,NewPos);
|
2009-11-01 10:04:03 -05:00
|
|
|
PageControl1.Pages[OldPos].TabIndex:= NewPos;
|
2009-11-01 08:56:54 -05:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.PageControl1DragOver(Sender, Source: TObject; X, Y: Integer;
|
|
|
|
State: TDragState; var Accept: Boolean);
|
|
|
|
begin
|
|
|
|
if Sender = PageControl1 then;
|
|
|
|
Accept := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.PageControl1MouseDown(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
|
begin
|
2009-11-01 10:30:32 -05:00
|
|
|
{$ifdef mswindows}
|
|
|
|
PageControl1.BeginDrag(false);
|
|
|
|
{$endif}
|
2009-11-01 08:56:54 -05:00
|
|
|
end;
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
function TForm1.GetScriptState: TScriptState;
|
|
|
|
begin
|
|
|
|
result := CurrScript.FScriptState;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-24 11:37:00 -04:00
|
|
|
procedure TForm1.SetScriptState(const State: TScriptState);
|
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrScript.FScriptState:= State;
|
2009-10-24 11:37:00 -04:00
|
|
|
with Self.StatusBar.panels[Panel_State] do
|
2009-10-31 17:44:13 -04:00
|
|
|
case state of
|
2009-10-31 19:31:51 -04:00
|
|
|
ss_Running : begin Text := 'Running'; TB_Run.Enabled:= False; {$ifdef MSWindows}TB_Pause.Enabled:= True; {$endif}
|
|
|
|
TB_Stop.ImageIndex := Image_Stop; TB_Stop.Enabled:= True;
|
|
|
|
TrayPlay.Checked := True; TrayPlay.Enabled := False; {$ifdef MSWindows}TrayPause.Checked := false; TrayPause.Enabled := True;{$endif}
|
|
|
|
TrayStop.Enabled:= True; TrayStop.Checked:= False;
|
|
|
|
end;
|
|
|
|
ss_Paused : begin Text := 'Paused'; TB_Run.Enabled:= True; {$ifdef MSWindows}TB_Pause.Enabled:= True; {$endif}
|
|
|
|
TB_Stop.ImageIndex := Image_Stop; TB_Stop.Enabled:= True;
|
|
|
|
TrayPlay.Checked := false; TrayPlay.Enabled := True; {$ifdef MSWindows}TrayPause.Checked := True; TrayPause.Enabled := True;{$endif}
|
|
|
|
TrayStop.Enabled:= True; TrayStop.Checked:= False;
|
|
|
|
end;
|
|
|
|
ss_Stopping: begin Text := 'Stopping';TB_Run.Enabled:= False; TB_Pause.Enabled:= False; TB_Stop.Enabled:= True;
|
|
|
|
TB_Stop.ImageIndex := Image_Terminate;
|
|
|
|
TrayPlay.Checked := False; TrayPlay.Enabled := False; {$ifdef MSWindows}TrayPause.Checked := false; TrayPause.Enabled := False;{$endif}
|
|
|
|
TrayStop.Enabled:= True; TrayStop.Checked:= True;
|
|
|
|
end;
|
|
|
|
ss_None : begin Text := 'Done'; TB_Run.Enabled:= True; TB_Pause.Enabled:= False; TB_Stop.Enabled:= False;
|
|
|
|
TB_Stop.ImageIndex := Image_Stop;
|
|
|
|
TrayPlay.Checked := false; TrayPlay.Enabled := True; {$ifdef MSWindows}TrayPause.Checked := false; TrayPause.Enabled := False;{$endif}
|
|
|
|
TrayStop.Enabled:= false; TrayStop.Checked:= False;
|
|
|
|
end;
|
2009-10-24 11:37:00 -04:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-10-24 10:01:21 -04:00
|
|
|
|
2009-10-18 16:11:47 -04:00
|
|
|
procedure TForm1.SafeCallThread;
|
|
|
|
begin
|
|
|
|
Writeln('Executing : ' + CurrentSyncInfo.MethodName);
|
|
|
|
mmlpsthread.CurrThread := TMMLPSTHREAD(CurrentSyncInfo.OldThread);
|
|
|
|
with CurrentSyncInfo.PSScript do
|
|
|
|
begin;
|
|
|
|
OnLine:=@OnLinePSScript;
|
|
|
|
CurrentSyncInfo.Res:= Exec.RunProcPVar(CurrentSyncInfo.V,Exec.GetProc(CurrentSyncInfo.MethodName));
|
|
|
|
Online := nil;
|
|
|
|
end;
|
|
|
|
mmlpsthread.CurrThread := nil;
|
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
function TForm1.OpenScript: boolean;
|
|
|
|
begin;
|
|
|
|
Result := False;
|
|
|
|
if CanExitOrOpen = false then
|
|
|
|
Exit;
|
|
|
|
with TOpenDialog.Create(nil) do
|
|
|
|
try
|
|
|
|
Filter:= 'Mufasa Files|*.cogat;*.mufa;*.txt|Any files|*.*';
|
|
|
|
if Execute then
|
|
|
|
if FileExists(FileName) then
|
|
|
|
begin;
|
2009-10-31 17:44:13 -04:00
|
|
|
with CurrScript do
|
|
|
|
begin
|
|
|
|
SynEdit.Lines.LoadFromFile(FileName);
|
|
|
|
StartText := SynEdit.Lines.text;
|
|
|
|
ScriptName:= ExtractFileNameOnly(FileName);
|
|
|
|
WriteLn('Script name will be: ' + ScriptName);
|
|
|
|
ScriptFile:= FileName;
|
|
|
|
ScriptChanged := false;
|
|
|
|
RefreshTab();
|
|
|
|
Result := True;
|
|
|
|
end;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.SaveCurrentScript: boolean;
|
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
with CurrScript do
|
|
|
|
begin
|
|
|
|
Result := (ScriptFile <> '');
|
|
|
|
if Result then
|
|
|
|
begin;
|
|
|
|
ScriptChanged := false;
|
|
|
|
SynEdit.Lines.SaveToFile(ScriptFile);
|
|
|
|
StartText:= SynEdit.Lines.Text;
|
|
|
|
SynEdit.MarkTextAsSaved;
|
|
|
|
Self.Caption:= Format(WindowTitle,[ScriptName]);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
result := SaveCurrentScriptAs;
|
|
|
|
end;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.SaveCurrentScriptAs: boolean;
|
|
|
|
begin
|
2009-10-31 17:44:13 -04:00
|
|
|
with CurrScript do
|
|
|
|
begin;
|
|
|
|
Result := false;
|
|
|
|
with TSaveDialog.Create(nil) do
|
|
|
|
try
|
|
|
|
Filter:= 'Mufasa files|*.cogat;*.mufa;*.pas;*.txt|Any Files|*.*';
|
|
|
|
if Execute then
|
2009-10-17 13:57:09 -04:00
|
|
|
begin;
|
2009-10-31 17:44:13 -04:00
|
|
|
if ExtractFileExt(FileName) = '' then
|
|
|
|
begin;
|
|
|
|
ScriptFile := FileName + '.mufa';
|
|
|
|
end else
|
|
|
|
ScriptFile := FileName;
|
|
|
|
SynEdit.Lines.SaveToFile(ScriptFile);
|
|
|
|
ScriptName:= ExtractFileNameOnly(ScriptFile);
|
|
|
|
WriteLn('Script name will be: ' + ScriptName);
|
|
|
|
RefreshTab();
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Free;
|
|
|
|
end;
|
|
|
|
if result then
|
|
|
|
begin;
|
|
|
|
Writeln('Succesfully saved: ' + ScriptFile);
|
|
|
|
StartText:= SynEdit.Lines.Text;
|
|
|
|
SynEdit.MarkTextAsSaved;
|
|
|
|
ScriptChanged := false;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.CanExitOrOpen: boolean;
|
|
|
|
var
|
|
|
|
I : integer;
|
|
|
|
begin;
|
2009-10-30 16:21:44 -04:00
|
|
|
Self.Enabled := False;//We HAVE to answer the popup
|
2009-10-17 13:57:09 -04:00
|
|
|
Result := True;
|
2009-10-31 17:44:13 -04:00
|
|
|
if ScriptState <> ss_None then
|
|
|
|
begin
|
|
|
|
if ScriptState <> ss_Stopping then
|
|
|
|
begin
|
|
|
|
result := False;
|
|
|
|
Case MessageBox(0,pchar('Do you want to stop the script?'), Pchar('Script is still running.'),
|
|
|
|
MB_YESNOCANCEL or MB_ICONQUESTION) of
|
|
|
|
IDYES : StopScript;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
Case MessageBox(0,pchar('Do you want to terminate the script?'), Pchar('Script is stopping.'),
|
|
|
|
MB_YESNOCANCEL or MB_ICONQUESTION) of
|
|
|
|
IDNO,IDCancel: Result := false;
|
|
|
|
IDYES : StopScript;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if Result and (CurrScript.StartText <> CurrScript.SynEdit.Lines.text) then
|
2009-10-17 13:57:09 -04:00
|
|
|
Case MessageBox(0,pchar('Do you want to save the script?'), Pchar('Script has been modified.'),
|
|
|
|
MB_YESNOCANCEL or MB_ICONQUESTION) of
|
|
|
|
IDCANCEL : Result := False;
|
|
|
|
IDYES : Result := SaveCurrentScript;
|
|
|
|
end;
|
2009-10-30 16:21:44 -04:00
|
|
|
Self.Enabled := True;
|
|
|
|
Self.SetFocus;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.ClearScript: boolean;
|
|
|
|
begin
|
|
|
|
if CanExitOrOpen then
|
|
|
|
begin;
|
2009-10-31 17:44:13 -04:00
|
|
|
CurrTab.Clear;
|
|
|
|
RefreshTab();
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-09-19 22:08:02 -04:00
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
{ TMufasaTab }
|
|
|
|
|
|
|
|
procedure TMufasaTab.Clear;
|
|
|
|
begin
|
|
|
|
ScriptFrame.Free;
|
|
|
|
ScriptFrame := TScriptFrame.Create(Tabsheet);
|
|
|
|
ScriptFrame.Parent := Tabsheet;
|
|
|
|
ScriptFrame.Align:= alClient;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TMufasaTab.Create(Page: TPageControl);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
PageCtrl := Page;
|
|
|
|
Tabsheet := TTabSheet.Create(Page);
|
|
|
|
Tabsheet.PageControl := Page;
|
|
|
|
ScriptFrame := TScriptFrame.Create(Tabsheet);
|
|
|
|
ScriptFrame.Parent := Tabsheet;
|
|
|
|
ScriptFrame.Align:= alClient;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TMufasaTab.Destroy;
|
|
|
|
begin
|
|
|
|
ScriptFrame.Free;
|
|
|
|
TabSheet.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
initialization
|
|
|
|
{$I testunit.lrs}
|
|
|
|
|
2009-10-31 17:44:13 -04:00
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
end.
|
|
|
|
|