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
|
|
|
|
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-09-23 16:18:33 -04:00
|
|
|
colourpicker,
|
2009-10-17 13:57:09 -04:00
|
|
|
windowselector,
|
|
|
|
lcltype
|
|
|
|
, SynEditKeyCmds;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TForm1 }
|
|
|
|
|
|
|
|
TForm1 = class(TForm)
|
2009-10-09 18:17:35 -04:00
|
|
|
Memo1: TMemo;
|
2009-10-17 13:57:09 -04:00
|
|
|
MenuFile: TMenuItem;
|
|
|
|
MenuEdit: TMenuItem;
|
|
|
|
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-17 13:57:09 -04:00
|
|
|
StatusBar: TStatusBar;
|
2009-09-12 02:24:59 -04:00
|
|
|
SynEdit1: TSynEdit;
|
|
|
|
SynFreePascalSyn1: TSynFreePascalSyn;
|
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;
|
|
|
|
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-09-04 00:26:56 -04:00
|
|
|
procedure Button1Click(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure ClearDebug(Sender: TObject);
|
|
|
|
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-10-17 13:57:09 -04:00
|
|
|
procedure MenuFileClick(Sender: TObject);
|
|
|
|
procedure MenuItemNewClick(Sender: TObject);
|
|
|
|
procedure MenuItemOpenClick(Sender: TObject);
|
2009-09-19 22:08:02 -04:00
|
|
|
procedure MenuItemRunClick(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure MenuItemSaveAsClick(Sender: TObject);
|
|
|
|
procedure MenuItemSaveClick(Sender: TObject);
|
2009-10-18 16:11:47 -04:00
|
|
|
procedure OnLinePSScript(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure OnSyneditChange(Sender: TObject);
|
2009-09-22 19:58:14 -04:00
|
|
|
procedure PickColorEvent(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure Redo(Sender: TObject);
|
2009-09-23 16:18:33 -04:00
|
|
|
procedure Selector_DOWN(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
2009-09-25 15:29:03 -04:00
|
|
|
procedure NoTray(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure SynEditProcessCommand(Sender: TObject;
|
|
|
|
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
|
2009-10-22 10:25:20 -04:00
|
|
|
procedure ToolBar1Click(Sender: TObject);
|
2009-09-25 15:29:03 -04:00
|
|
|
procedure ToTray(Sender: TObject);
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure Undo(Sender: TObject);
|
2009-09-04 00:26:56 -04:00
|
|
|
private
|
2009-10-20 15:48:18 -04:00
|
|
|
ScriptFile : string;//The path to the saved/opened file currently in the SynEdit
|
2009-10-17 13:57:09 -04:00
|
|
|
StartText : string;//The text synedit holds upon start/open/save
|
|
|
|
ScriptName : string;//The name of the currently opened/saved file.
|
|
|
|
ScriptDefault : string;//The default script e.g. program new; begin end.
|
|
|
|
ScriptChanged : boolean;//We need this for that little * (edited star).
|
2009-09-04 00:26:56 -04:00
|
|
|
public
|
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-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-20 15:48:18 -04:00
|
|
|
procedure run;
|
2009-10-17 13:57:09 -04:00
|
|
|
end;
|
|
|
|
const
|
|
|
|
WindowTitle = 'Mufasa v2 - %s';//Title, where %s = the place of the filename.
|
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-09-23 18:01:19 -04:00
|
|
|
lclintf,plugins;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-20 15:48:18 -04:00
|
|
|
procedure TForm1.Run;
|
2009-09-04 00:26:56 -04:00
|
|
|
Var
|
2009-09-12 02:24:59 -04:00
|
|
|
MMLPSThread : TMMLPSThread;
|
2009-09-04 00:26:56 -04:00
|
|
|
|
|
|
|
begin
|
2009-10-20 15:48:18 -04:00
|
|
|
CurrentSyncInfo.SyncMethod:= @Self.SafeCallThread;
|
2009-10-18 16:11:47 -04:00
|
|
|
MMLPSThread := TMMLPSThread.Create(True,@CurrentSyncInfo);
|
2009-10-20 15:48:18 -04:00
|
|
|
MMLPSThread.SetPSScript(Self.SynEdit1.Lines.Text);
|
|
|
|
MMLPSThread.SetDebug(Self.Memo1);
|
|
|
|
if ScriptFile <> '' then
|
2009-10-20 16:30:11 -04:00
|
|
|
MMLPSThread.SetPaths( ExtractFileDir(ScriptFile) + DS,IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)))
|
2009-10-20 15:48:18 -04:00
|
|
|
else
|
2009-10-20 16:30:11 -04:00
|
|
|
MMLPSThread.SetPaths('', IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds)));
|
2009-09-22 18:28:10 -04:00
|
|
|
|
|
|
|
// This doesn't actually set the Client's MWindow to the passed window, it
|
|
|
|
// only copies the current set window handle.
|
2009-10-20 15:48:18 -04:00
|
|
|
MMLPSThread.Client.MWindow.SetWindow(Self.Window);
|
2009-09-22 18:28:10 -04:00
|
|
|
|
2009-09-12 02:24:59 -04:00
|
|
|
MMLPSThread.Resume;
|
2009-09-28 22:12:29 -04:00
|
|
|
|
|
|
|
// sleep(500);
|
|
|
|
// MMLPSThread.PSScript.Stop;
|
|
|
|
|
2009-09-19 22:08:02 -04:00
|
|
|
end;
|
2009-09-12 02:24:59 -04:00
|
|
|
|
2009-09-19 22:08:02 -04:00
|
|
|
procedure TForm1.Button1Click(Sender: TObject);
|
|
|
|
begin;
|
|
|
|
Run;
|
2009-09-12 02:24:59 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure TForm1.ClearDebug(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Memo1.Clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|
|
|
begin
|
|
|
|
if not CanExitOrOpen then
|
|
|
|
CloseAction := caNone;
|
|
|
|
end;
|
|
|
|
|
2009-09-12 14:50:10 -04:00
|
|
|
procedure TForm1.FormCreate(Sender: TObject);
|
|
|
|
begin
|
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-10-17 13:57:09 -04:00
|
|
|
StartText:= SynEdit1.Lines.text;
|
|
|
|
ScriptDefault:= StartText;
|
|
|
|
Caption := Format(WindowTitle,['Untitled']);
|
|
|
|
ScriptName:= 'Untitled';
|
|
|
|
ScriptChanged := false;
|
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-09-19 22:08:02 -04:00
|
|
|
// SynMemo1.sc
|
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);
|
|
|
|
begin
|
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-09-12 14:50:10 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure TForm1.MenuFileClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.MenuItemNewClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ClearScript;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.MenuItemOpenClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
OpenScript;
|
|
|
|
end;
|
|
|
|
|
2009-09-19 22:08:02 -04:00
|
|
|
procedure TForm1.MenuItemRunClick(Sender: TObject);
|
2009-09-12 02:24:59 -04:00
|
|
|
begin
|
2009-09-19 22:08:02 -04:00
|
|
|
Run;
|
2009-09-04 00:26:56 -04:00
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure TForm1.MenuItemSaveAsClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
SaveCurrentScriptAs;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.MenuItemSaveClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
SaveCurrentScript;
|
|
|
|
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-17 13:57:09 -04:00
|
|
|
procedure TForm1.OnSyneditChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if not ScriptChanged then
|
|
|
|
begin;
|
|
|
|
ScriptChanged:= True;
|
|
|
|
Self.Caption:= Format(WindowTitle,[ScriptName + '*']);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-09-22 19:58:14 -04:00
|
|
|
procedure TForm1.PickColorEvent(Sender: TObject);
|
|
|
|
var
|
|
|
|
c, x, y: Integer;
|
|
|
|
begin
|
|
|
|
Picker.Pick(c, x, y);
|
|
|
|
writeln('Picked colour: ' + inttostr(c) + ' at (' + inttostr(x) + ', ' + inttostr(y) + ')');
|
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure TForm1.Redo(Sender: TObject);
|
|
|
|
begin
|
|
|
|
SynEdit1.Redo;
|
|
|
|
if ScriptChanged then
|
|
|
|
if SynEdit1.Lines.Text = StartText then
|
|
|
|
begin;
|
|
|
|
Self.Caption:= format(WindowTitle,[ScriptName]);
|
|
|
|
ScriptChanged := false;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-09-23 16:18:33 -04:00
|
|
|
procedure TForm1.Selector_DOWN(Sender: TObject; Button: TMouseButton;
|
|
|
|
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
|
|
|
|
Form1.Show
|
|
|
|
else
|
|
|
|
Form1.Hide;
|
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure TForm1.SynEditProcessCommand(Sender: TObject;
|
|
|
|
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
|
|
|
|
begin
|
|
|
|
if Command = ecUndo then
|
|
|
|
begin;
|
|
|
|
Command:= ecNone;
|
|
|
|
Undo(Sender);
|
|
|
|
end else
|
|
|
|
if Command = ecRedo then
|
|
|
|
begin;
|
|
|
|
Command := ecNone;
|
|
|
|
Redo(Sender);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-10-22 10:25:20 -04:00
|
|
|
procedure TForm1.ToolBar1Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2009-09-25 15:29:03 -04:00
|
|
|
procedure TForm1.ToTray(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Form1.Hide;
|
|
|
|
end;
|
|
|
|
|
2009-10-17 13:57:09 -04:00
|
|
|
procedure TForm1.Undo(Sender: TObject);
|
|
|
|
begin
|
|
|
|
SynEdit1.Undo;
|
|
|
|
if ScriptChanged then
|
|
|
|
if SynEdit1.Lines.Text = StartText then
|
|
|
|
begin;
|
|
|
|
Self.Caption:= format(WindowTitle,[ScriptName]);
|
|
|
|
ScriptChanged := false;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
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;
|
|
|
|
SynEdit1.Lines.LoadFromFile(FileName);
|
|
|
|
StartText := SynEdit1.Lines.text;
|
|
|
|
ScriptName:= ExtractFileNameOnly(FileName);
|
|
|
|
WriteLn('Script name will be: ' + ScriptName);
|
2009-10-20 15:48:18 -04:00
|
|
|
ScriptFile:= FileName;
|
2009-10-17 13:57:09 -04:00
|
|
|
StatusBar.Panels[0].Text:= ScriptName;
|
2009-10-20 15:48:18 -04:00
|
|
|
StatusBar.Panels[1].text:= FileName;
|
2009-10-17 13:57:09 -04:00
|
|
|
Self.Caption:= Format(WindowTitle,[ScriptName]);
|
|
|
|
ScriptChanged := false;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.SaveCurrentScript: boolean;
|
|
|
|
begin
|
2009-10-20 15:48:18 -04:00
|
|
|
Result := (ScriptFile <> '');
|
2009-10-17 13:57:09 -04:00
|
|
|
if Result then
|
|
|
|
begin;
|
|
|
|
ScriptChanged := false;
|
2009-10-20 15:48:18 -04:00
|
|
|
SynEdit1.Lines.SaveToFile(ScriptFile);
|
2009-10-17 13:57:09 -04:00
|
|
|
StartText:= SynEdit1.Lines.Text;
|
2009-10-22 10:25:20 -04:00
|
|
|
SynEdit1.MarkTextAsSaved;
|
|
|
|
Self.Caption:= Format(WindowTitle,[ScriptName]);
|
2009-10-17 13:57:09 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
result := SaveCurrentScriptAs;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.SaveCurrentScriptAs: boolean;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
with TSaveDialog.Create(nil) do
|
|
|
|
try
|
|
|
|
Filter:= 'Mufasa files|*.cogat;*.mufa;*.pas;*.txt|Any Files|*.*';
|
|
|
|
if Execute then
|
|
|
|
begin;
|
|
|
|
if ExtractFileExt(FileName) = '' then
|
|
|
|
begin;
|
2009-10-20 15:48:18 -04:00
|
|
|
ScriptFile := FileName + '.mufa';
|
2009-10-17 13:57:09 -04:00
|
|
|
end else
|
2009-10-20 15:48:18 -04:00
|
|
|
ScriptFile := FileName;
|
|
|
|
SynEdit1.Lines.SaveToFile(ScriptFile);
|
|
|
|
ScriptName:= ExtractFileNameOnly(ScriptFile);
|
2009-10-17 13:57:09 -04:00
|
|
|
StatusBar.Panels[0].Text:= ScriptName;
|
2009-10-20 15:48:18 -04:00
|
|
|
StatusBar.Panels[1].text := ScriptFile;
|
2009-10-17 13:57:09 -04:00
|
|
|
Self.Caption:= Format(WindowTitle,[ScriptName]);
|
|
|
|
WriteLn('Script name will be: ' + ScriptName);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Free;
|
|
|
|
end;
|
|
|
|
if result then
|
|
|
|
begin;
|
2009-10-20 15:48:18 -04:00
|
|
|
Writeln('Succesfully saved: ' + ScriptFile);
|
2009-10-17 13:57:09 -04:00
|
|
|
StartText:= SynEdit1.Lines.Text;
|
|
|
|
SynEdit1.MarkTextAsSaved;
|
|
|
|
ScriptChanged := false;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.CanExitOrOpen: boolean;
|
|
|
|
var
|
|
|
|
I : integer;
|
|
|
|
begin;
|
|
|
|
Result := True;
|
|
|
|
if StartText <> Synedit1.Lines.text then
|
|
|
|
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;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TForm1.ClearScript: boolean;
|
|
|
|
begin
|
|
|
|
if CanExitOrOpen then
|
|
|
|
begin;
|
2009-10-20 15:48:18 -04:00
|
|
|
ScriptFile:= '';
|
2009-10-17 13:57:09 -04:00
|
|
|
ScriptName:= 'Untitled';
|
|
|
|
StartText:= ScriptDefault;
|
|
|
|
SynEdit1.Lines.Text:= ScriptDefault;
|
|
|
|
StatusBar.Panels[0].Text:= 'Untitled';
|
|
|
|
StatusBar.Panels[1].Text:= '';
|
|
|
|
Self.Caption := Format(WindowTitle,['Untitled']);
|
|
|
|
ScriptChanged:= false;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-09-19 22:08:02 -04:00
|
|
|
|
2009-09-04 00:26:56 -04:00
|
|
|
initialization
|
|
|
|
{$I testunit.lrs}
|
|
|
|
|
|
|
|
end.
|
|
|
|
|