From 00d18b187527b4d93c07c777a13fafa860f6c792 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sat, 9 Apr 2011 11:19:18 +0200 Subject: [PATCH 1/8] Simba: Start cleaning and memory management work. --- Projects/Simba/Simba.lpr | 4 ++-- Projects/Simba/simbaunit.pas | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Projects/Simba/Simba.lpr b/Projects/Simba/Simba.lpr index a93e8b7..7ee202b 100644 --- a/Projects/Simba/Simba.lpr +++ b/Projects/Simba/Simba.lpr @@ -29,11 +29,11 @@ program Simba; uses {$IFDEF UNIX}{$IFDEF UseCThreads} - cthreads, cmem, + cthreads, cmem, heaptrc, {$ENDIF}{$ENDIF} Interfaces, Forms, SimbaUnit, colourhistory, About, internets, debugimage, framefunctionlist, simpleanalyzer, updater, updateform, Simbasettings, - libloader, mufasabase, {$IFDEF LINUX}os_linux,{$ENDIF} v_ideCodeInsight, + libloader, mufasabase, v_ideCodeInsight, PSDump, v_ideCodeParser, v_AutoCompleteForm, CastaliaPasLex, CastaliaPasLexTypes, CastaliaSimplePasPar, CastaliaSimplePasParTypes, dcpbase64, mPasLex, v_Constants, v_MiscFunctions, diff --git a/Projects/Simba/simbaunit.pas b/Projects/Simba/simbaunit.pas index b67c495..2e69f4e 100644 --- a/Projects/Simba/simbaunit.pas +++ b/Projects/Simba/simbaunit.pas @@ -18,7 +18,7 @@ See the file COPYING, included in this distribution, for details about the copyright. - Simba/GUI for the Mufasa Macro Library + Simba: GUI for the Mufasa Macro Library } unit SimbaUnit; @@ -30,20 +30,31 @@ unit SimbaUnit; interface uses - {$ifdef linux}cthreads,cmem,{$endif}Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + {$IFDEF LINUX}cthreads, cmem, heaptrc,{$ENDIF} + Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, - //Client, + MufasaTypes, - mmlpsthread,synedittypes, + mmlpsthread, // Code to use the interpreters in threads. + synedittypes, + {$IFDEF MSWINDOWS} os_windows, windows,{$ENDIF} //For ColorPicker etc. {$IFDEF LINUX} os_linux, {$ENDIF} //For ColorPicker etc. - colourpicker, framescript, windowselector, lcltype, ActnList, + + colourpicker, windowselector, // We need these for the Colour Picker and Window Selector + + framescript, lcltype, ActnList, SynExportHTML, SynEditKeyCmds, SynEditHighlighter, SynEditMarkupHighAll, LMessages, Buttons,mmisc, stringutil,mufasatypesutil,mufasabase, v_ideCodeParser, about, framefunctionlist, ocr, updateform, Simbasettings, psextension, virtualextension, - extensionmanager, settingssandbox, v_ideCodeInsight, CastaliaPasLexTypes, - CastaliaSimplePasPar, v_AutoCompleteForm, PSDump, settings, updater; + extensionmanager, settingssandbox, + + v_ideCodeInsight, CastaliaPasLexTypes, // Code completion units + CastaliaSimplePasPar, v_AutoCompleteForm, // Code completion units + PSDump, + + settings, updater; const SimbaVersion = 820; @@ -503,10 +514,13 @@ var {$endif} CurrentSyncInfo : TSyncInfo;//We need this for SafeCallThread + + + implementation uses lclintf, - syncobjs, // for the critical sections + syncobjs, // for the critical sections / mutexes debugimage, files, InterfaceBase, @@ -517,6 +531,9 @@ uses math, keybinder; + + + {$ifdef mswindows} function ConsoleHandler( eventType : DWord) : WINBOOL;stdcall; begin From c353870a840825007053d7e8ab9709f3d5c125a7 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sat, 9 Apr 2011 20:45:36 +0200 Subject: [PATCH 2/8] Simba: Add directives file. Clean up hotkeys. --- Projects/Simba/Simba.inc | 34 ++++++++++ Projects/Simba/Simba.lpr | 2 +- Projects/Simba/simbaunit.pas | 122 +++++++++++++++++++++++++---------- 3 files changed, 124 insertions(+), 34 deletions(-) create mode 100644 Projects/Simba/Simba.inc diff --git a/Projects/Simba/Simba.inc b/Projects/Simba/Simba.inc new file mode 100644 index 0000000..5750080 --- /dev/null +++ b/Projects/Simba/Simba.inc @@ -0,0 +1,34 @@ +{ + This file is part of the Mufasa Macro Library (MML) + Copyright (c) 2009 by Raymond van Venetiƫ and Merlijn Wajer + + 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 . + + See the file COPYING, included in this distribution, + for details about the copyright. + + Simba.inc: File with directives for SimbaUnit. +} + +{$IFDEF LINUX} + {$DEFINE LINUX_HOTKEYS} // For global hotkeys, requires libkeybinder. + // See Units/Linux/keybinder.pas +{$ENDIF} + +//{$DEFINE USE_RUTIS} + +//{$DEFINE USE_CPASCAL} // TODO +//{$DEFINE USE_LAPE} // TODO +//{$DEFINE USE_EXTENSIONS} // TODO +//{$DEFINE USE_CODECOMPLETION} // TODO diff --git a/Projects/Simba/Simba.lpr b/Projects/Simba/Simba.lpr index 7ee202b..d2da58a 100644 --- a/Projects/Simba/Simba.lpr +++ b/Projects/Simba/Simba.lpr @@ -29,7 +29,7 @@ program Simba; uses {$IFDEF UNIX}{$IFDEF UseCThreads} - cthreads, cmem, heaptrc, + cthreads, cmem, {heaptrc, } {$ENDIF}{$ENDIF} Interfaces, Forms, SimbaUnit, colourhistory, About, internets, debugimage, framefunctionlist, simpleanalyzer, updater, updateform, Simbasettings, diff --git a/Projects/Simba/simbaunit.pas b/Projects/Simba/simbaunit.pas index 2e69f4e..06379f5 100644 --- a/Projects/Simba/simbaunit.pas +++ b/Projects/Simba/simbaunit.pas @@ -23,14 +23,16 @@ unit SimbaUnit; {$undef EditButtons} -//{$define USE_RUTIS} {$Undef ProcessMessages} //Define this for processmessages in ThreadSafeCall + {$mode objfpc}{$H+} +{$I Simba.inc} + interface uses - {$IFDEF LINUX}cthreads, cmem, heaptrc,{$ENDIF} + {$IFDEF LINUX}cthreads, cmem,{$ENDIF} Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, @@ -43,10 +45,12 @@ uses colourpicker, windowselector, // We need these for the Colour Picker and Window Selector - framescript, lcltype, ActnList, + framescript, + + lcltype, ActnList, SynExportHTML, SynEditKeyCmds, SynEditHighlighter, - SynEditMarkupHighAll, LMessages, Buttons,mmisc, - stringutil,mufasatypesutil,mufasabase, v_ideCodeParser, + SynEditMarkupHighAll, LMessages, Buttons, + mmisc, stringutil,mufasatypesutil, mufasabase, v_ideCodeParser, about, framefunctionlist, ocr, updateform, Simbasettings, psextension, virtualextension, extensionmanager, settingssandbox, @@ -63,6 +67,9 @@ const interp_RT = 1; //RUTIS interp_CP = 2; //CPascal + { Place the shortcuts here } + shortcut_StopScript = 'S'; + type { TMufasaTab } @@ -528,18 +535,25 @@ uses bitmaps, extensionmanagergui, colourhistory, - math, - keybinder; + math + {$IFDEF LINUX_HOTKEYS} + ,keybinder + {$ENDIF} + ; - - -{$ifdef mswindows} +{ Console handler } +{$IFDEF MSWINDOWS} function ConsoleHandler( eventType : DWord) : WINBOOL;stdcall; begin TThread.Synchronize(nil,@SimbaForm.Close); Result := true; end; +{$ENDIF} + +{Global Hotkey Binding } + +{$ifdef mswindows} { Used for global callbacks on WINDOWS } function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; @@ -553,15 +567,38 @@ begin Result := Windows.CallWindowProc(PrevWndProc,Ahwnd, uMsg, WParam, LParam); end; -{$else} +procedure Bind_Windows_Keys; + +begin + PrevWndProc := Windows.WNDPROC(GetWindowLong(self.handle,GWL_WNDPROC)); + SetWindowLong(Self.Handle,GWL_WNDPROC,PtrInt(@WndCallback)); + if not RegisterHotkey(Self.Handle,0,MOD_CONTROL or MOD_ALT,VK_S) then + mDebugLn('Unable to register Ctrl + Alt + S as global hotkey'); +end; + + +{$ELSE} + {$IFDEF LINUX_HOTKEYS} {$WARNING This will probably not work if people don't have libkeybinder installed. Perhaps ship it with Simba? } + { Used for global callbacks on LINUX } procedure keybinder_callback(keystring: PChar; user_data: PtrUInt); cdecl; begin SimbaForm.ActionStopScript.Execute; end; -{$endif} +{ XXX, TODO: Pressing the stop shortcut twice (quickly) may crash Simba. } +procedure Bind_Linux_Keys; +begin + keybinder_init(); { Initialise keybinder } + + { Bind keys } + if not keybinder_bind(PChar(shortcut_StopScript), @keybinder_callback, PtrUInt(0)) then + mDebugLn('Unable to register Ctrl + Alt + S as global hotkey'); +end; + {$ENDIF} + +{$ENDIF} var DebugCriticalSection: syncobjs.TCriticalSection; @@ -2226,7 +2263,7 @@ begin end; end; SimbaForm.InitializeTMThread(t); - KillThread(t.ThreadID); + KillThread(t.ThreadID); { XXX: Why do we kill the thread again ? } if (t is TPSThread) then try a := TPSScriptExtension.Create(SimbaForm); @@ -2281,24 +2318,20 @@ begin CodeCompletionForm.InsertProc := @OnCompleteCode; ParamHint := TParamHint.Create(self); - {$ifdef MSWindows} + {$IFDEF MSWindows} ConsoleVisible := True; { Bind CTRL+ALT+S to Script stop } - PrevWndProc := Windows.WNDPROC(GetWindowLong(self.handle,GWL_WNDPROC)); - SetWindowLong(Self.Handle,GWL_WNDPROC,PtrInt(@WndCallback)); - if not RegisterHotkey(Self.Handle,0,MOD_CONTROL or MOD_ALT,VK_S) then - mDebugLn('Unable to register Ctrl + Alt + S as global hotkey'); - {$else} + Bind_Windows_Keys(); + + {$ELSE} TT_Console.Visible:= False; { Bind CTRL+ALT+S to Script stop } - keybinder_init(); { Initialise keybinder } - - { Bind keys } - if not keybinder_bind(PChar('S'), @keybinder_callback, PtrUInt(0)) then - mDebugLn('Unable to register Ctrl + Alt + S as global hotkey'); - {$endif} + {$IFDEF LINUX_HOTKEYS} + Bind_Linux_Keys(); + {$ENDIF} + {$ENDIF} InitmDebug; { Perhaps we need to place this before our mDebugLines?? } @@ -2332,30 +2365,40 @@ begin Picker := TMColorPicker.Create(Manager); Picker.OnPick:=@PickerPick; Selector := TMWindowSelector.Create(Manager); + { For writeln } SetLength(DebugStream, 0); DebugCriticalSection := syncobjs.TCriticalSection.Create; - {$ifdef mswindows} + + {$ifdef mswindows} { The Debug timer checks for new stuff to print } DebugTimer.Enabled:= false; {$endif} + Application.QueueAsyncCall(@RefreshTabSender,0); - {$ifdef mswindows} + + {$ifdef mswindows} { Only windows can't remove files if they are in use } if FileExists(Application.ExeName+'_old_') then begin - mDebugLn('We still have an out-dated exe file in the dir, lets remove!'); - mDebugLn(format('Sucesfully deleted the file? %s',[BoolToStr(DeleteFile(PChar(Application.ExeName + '_old_')),true)])); + mDebugLn('We still have an out-dated exe file in the dir. Lets remove!'); + mDebugLn(format('Successfully deleted the file? %s',[BoolToStr(DeleteFile(PChar(Application.ExeName + '_old_')),true)])); end; SetConsoleCtrlHandler(@ConsoleHandler,true); {$endif} + frmFunctionList.OnEndDock:= @frmFunctionList.FrameEndDock; - FirstRun := true;//Our next run is the first run. - HandleParameters; + + FirstRun := True;//Our next run is the first run. + + HandleParameters; { Handle command line parameters } + TT_Update.Visible:= false; //Fill the codeinsight buffer FillThread.Resume; + //Load the extensions LoadExtensions; + UpdateTitle; {$IFNDEF USE_RUTIS} @@ -2371,24 +2414,37 @@ procedure TSimbaForm.FormDestroy(Sender: TObject); var i : integer; begin + { Free the tabs } for i := Tabs.Count - 1 downto 0 do TMufasaTab(Tabs[i]).Free; + for i := 0 to high(RecentFileItems) do RecentFileItems[i].Free; + if ExtManager <> nil then FreeAndNil(extmanager); - Tabs.free; + + Tabs.Free; + + { Free MML Core stuff } Selector.Free; Picker.Free; Manager.Free; + + { Free the plugins } PluginsGlob.Free; + SetLength(DebugStream, 0); - RecentFiles.Free; DebugCriticalSection.Free; + + RecentFiles.Free; ParamHint.Free; + {$ifdef MSWindows} if not UnRegisterHotkey(Self.Handle,0) then mDebugLn('Unable to unregister ctrl + alt + s as global hotkey'); + {$else} + keybinder_unbind(PChar(shortcut_StopScript), @keybinder_callback, PtrUInt(0)); {$endif} end; From dfe97bf3a82006fb56f147fb13b87a1b2b3cbcd6 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sat, 9 Apr 2011 21:11:40 +0200 Subject: [PATCH 3/8] Simba: Further clean up keybinding code. --- Projects/Simba/simbaunit.pas | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Projects/Simba/simbaunit.pas b/Projects/Simba/simbaunit.pas index 06379f5..58b46bb 100644 --- a/Projects/Simba/simbaunit.pas +++ b/Projects/Simba/simbaunit.pas @@ -576,10 +576,16 @@ begin mDebugLn('Unable to register Ctrl + Alt + S as global hotkey'); end; +procedure Unbind_Windows_Keys; +begin + if not UnRegisterHotkey(Self.Handle,0) then + mDebugLn('Unable to unregister ctrl + alt + s as global hotkey'); +end; + {$ELSE} {$IFDEF LINUX_HOTKEYS} -{$WARNING This will probably not work if people don't have libkeybinder installed. Perhaps ship it with Simba? } + {$WARNING This will probably not work if people don't have libkeybinder installed. Perhaps ship it with Simba? } { Used for global callbacks on LINUX } procedure keybinder_callback(keystring: PChar; user_data: PtrUInt); cdecl; @@ -596,6 +602,11 @@ begin if not keybinder_bind(PChar(shortcut_StopScript), @keybinder_callback, PtrUInt(0)) then mDebugLn('Unable to register Ctrl + Alt + S as global hotkey'); end; + +procedure Unbind_Linux_Keys; +begin + keybinder_unbind(PChar(shortcut_StopScript), @keybinder_callback, PtrUInt(0)); +end; {$ENDIF} {$ENDIF} @@ -2441,10 +2452,11 @@ begin ParamHint.Free; {$ifdef MSWindows} - if not UnRegisterHotkey(Self.Handle,0) then - mDebugLn('Unable to unregister ctrl + alt + s as global hotkey'); + Unbind_Windows_Keys; {$else} - keybinder_unbind(PChar(shortcut_StopScript), @keybinder_callback, PtrUInt(0)); + {$IFDEF LINUX_HOTKEYS} + Unbind_Linux_Keys; + {$ENDIF} {$endif} end; From 6eb7651c2745416e134b7f2442ded627ad5e3347 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sat, 9 Apr 2011 21:33:11 +0200 Subject: [PATCH 4/8] Simba: Some more cleanups. --- Projects/Simba/Simba.inc | 2 ++ Projects/Simba/simbaunit.pas | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Projects/Simba/Simba.inc b/Projects/Simba/Simba.inc index 5750080..b0079f7 100644 --- a/Projects/Simba/Simba.inc +++ b/Projects/Simba/Simba.inc @@ -32,3 +32,5 @@ //{$DEFINE USE_LAPE} // TODO //{$DEFINE USE_EXTENSIONS} // TODO //{$DEFINE USE_CODECOMPLETION} // TODO + +//{$DEFINE TERMINALWRITELN} // Only used once. Remove from SimbaUnit? diff --git a/Projects/Simba/simbaunit.pas b/Projects/Simba/simbaunit.pas index 58b46bb..59b84a7 100644 --- a/Projects/Simba/simbaunit.pas +++ b/Projects/Simba/simbaunit.pas @@ -504,6 +504,7 @@ type const WindowTitle = 'Simba - %s';//Title, where %s = the place of the filename. + Panel_State = 0; Panel_Coords = 1; Panel_ScriptName = 2; @@ -553,7 +554,7 @@ end; {Global Hotkey Binding } -{$ifdef mswindows} +{$IFDEF MSWINDOWS} { Used for global callbacks on WINDOWS } function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; @@ -912,6 +913,7 @@ end; procedure TSimbaForm.TrayPopupPopup(Sender: TObject); begin + { XXX: What's up with this? } MenuItemHide.enabled:= SimbaForm.Visible; {$ifdef MSWindows} MenuItemShow.Enabled:= not SimbaForm.Visible; @@ -963,11 +965,13 @@ begin ShowMessage('No Updates Available!'); end; +{ Clear te debug memo } procedure ClearDebug; begin - {$IFNDEF MSWINDOWS} + {$IFNDEF MSWINDOWS} { First write everything we can, then clear } SimbaForm.ProcessDebugStream(nil); {$ENDIF} + TThread.Synchronize(nil,@SimbaForm.Memo1.Clear); end; @@ -1028,7 +1032,7 @@ begin ScriptThread.Suspended:= True; ScriptState:= ss_Paused; {$else} - mDebugLn('Linux users are screwed, no pause button for u!'); + mDebugLn('Linux does not yet support suspending threads.'); {$endif} end else if ScriptState = ss_Paused then begin; @@ -1066,6 +1070,8 @@ begin end; end; +{ Tab management } + procedure TSimbaForm.AddTab; var Tab : TMufasaTab; @@ -1143,6 +1149,8 @@ begin exit; end; + + procedure TSimbaForm.SetEditActions; procedure EditActions(Undo,Redo,Cut,Copy,Paste,Delete : boolean); begin; @@ -1294,6 +1302,9 @@ begin RefreshTab; end; +{ Settings related code } + +{ Creates default settings } procedure TSimbaForm.CreateDefaultEnvironment; var PluginsPath,extensionsPath : string; @@ -1351,6 +1362,7 @@ begin UpdateTimer.Interval:=25; end; +{ Load settings } procedure TSimbaForm.LoadFormSettings; var str,str2 : string; @@ -1407,6 +1419,7 @@ begin self.EndFormUpdate; end; +{ Save Settings } procedure TSimbaForm.SaveFormSettings; var Data : TStringArray; @@ -1418,7 +1431,7 @@ begin if Self.WindowState = wsMaximized then SetSetting('LastConfig/MainForm/State','maximized') else - begin; //Only save the form position if its non maximized. + begin; //Only save the form position if its not maximized. SetSetting('LastConfig/MainForm/State','normal'); Data := ConvArr([inttostr(Self.left),inttostr(self.top),inttostr(self.width),inttostr(self.height)]); SetSetting('LastConfig/MainForm/Position', Implode(':',Data )); @@ -1527,6 +1540,9 @@ begin RecentFileItems[len - 1-i].Caption:= ExtractFileName(RecentFiles[i]); end; + +{ Loads/Creates the required stuff for a script thread. } + procedure TSimbaForm.InitializeTMThread(out Thread: TMThread); var AppPath : string; @@ -1558,6 +1574,9 @@ begin try case Interpreter of interp_PS : Thread := TPSThread.Create(true,@CurrentSyncInfo,PluginPath); + + // XXX: Rutis needs to be completely removed from Simba if it's not defined. + // XXX: Not just print a message that it's not supported now. interp_RT : {$IFDEF USE_RUTIS}Thread := TRTThread.Create(true,@CurrentSyncInfo,PluginPath){$ELSE}formWriteln('RUTIS NOT SUPPORTED') {$ENDIF}; interp_CP : Thread := TCPThread.Create(true,@CurrentSyncInfo,PluginPath); end; From ac343389f2c8f0578b6c69adc8ca8e2f73433175 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sat, 9 Apr 2011 21:33:30 +0200 Subject: [PATCH 5/8] Simba: Change handbook URL to villavu. --- Projects/Simba/simbaunit.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projects/Simba/simbaunit.pas b/Projects/Simba/simbaunit.pas index 59b84a7..b65cd33 100644 --- a/Projects/Simba/simbaunit.pas +++ b/Projects/Simba/simbaunit.pas @@ -2195,7 +2195,7 @@ end; procedure TSimbaForm.MenuItemHandbookClick(Sender: TObject); begin - OpenURL('http://docs.wizzup.org/simba/'); + OpenURL('http://docs.villavu.com/simba/'); end; procedure TSimbaForm.MenuItemColourHistoryClick(Sender: TObject); From 3400027de7daab7c0d367f32046ee9af2a852553 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sat, 9 Apr 2011 23:47:41 +0200 Subject: [PATCH 6/8] Simba: StrToInt raises an exception now. --- Units/MMLAddon/PSInc/Wrappers/strings.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Units/MMLAddon/PSInc/Wrappers/strings.inc b/Units/MMLAddon/PSInc/Wrappers/strings.inc index e541d2f..dcb8eb4 100644 --- a/Units/MMLAddon/PSInc/Wrappers/strings.inc +++ b/Units/MMLAddon/PSInc/Wrappers/strings.inc @@ -1 +1 @@ -function ps_Capitalize(str : string) : string;extdecl; begin result := Capitalize(str); end; function ps_CompressString(const Str : string) : string; extdecl; begin result := CompressString(str); end; function ps_DecompressString(const Compressed : string) : string; extdecl; begin result := DecompressString(Compressed); end; function ps_Base64Encode(const str : string) : string; extdecl; begin result := Base64Encode(str); end; function ps_Base64Decode(const str : string) : string; extdecl; begin result := Base64Decode(str); end; function ps_ExtractFromStr( Str : string; Extract : StrExtr) : string; extdecl; begin result := extractfromstr(str,extract); end; function ps_BoolToStr(bool : boolean) : string; extdecl; begin; result := BoolToStr(bool,true); end; function ps_Replace(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string; extdecl; begin; result := StringReplace(Text,FindStr,ReplaceStr,Flags); end; function ps_IntToStr(int : integer) : string; extdecl; begin result := inttostr(int); end; function ps_FloatToStr(flt : extended) : string; extdecl; begin result := floattostr(flt); end; function ps_StrToInt(value: String): Integer; extdecl; begin result := StrToInt(value); end; function ps_StrToIntDef(value: String; default: Integer): Integer; extdecl; begin result := StrToIntDef(value,default); end; function ps_StrToFloat(value: String): Extended; extdecl; begin result := StrToFloat(value); end; function ps_StrToFloatDef(value: String; default: Extended): Extended; extdecl; begin result := StrToFloatDef(value,default); end; function ps_StrToBool(value: String): Boolean;extdecl; begin result := StrToBool(value); end; function ps_StrToBoolDef(value: String; default: Boolean): Boolean; extdecl; begin result := StrToBoolDef(value,default); end; function ps_Between(s1, s2, str: string): string; extdecl; var I,J : integer; begin; Result := ''; I := pos(s1,str); if I > 0 then begin; i := i + length(s1); j := posex(s2,str,i); if j > 0 then Result := copy(str,i,j-i); end; end; function ps_Implode(Glue : string; Pieces: TStringArray): string;extdecl; begin result := implode(glue,pieces); end; function ps_Explode(del, str: string): TStringArray;extdecl; begin result := Explode(del,str); end; procedure ps_ExplodeWrap(del, str: string; var res : TStringArray);extdecl; begin res := Explode(del,str); end; function ps_Padl(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char(' '), i - length(s)) + s; end; function ps_Padz(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char('0'), i - length(s)) + s; end; function ps_Padr(s: String; i: longInt): String;extdecl; begin result := s + StringOfChar(Char(' '), i - Length(s)); end; function ps_ExecRegExpr( const RegExpr, InputStr : String) : boolean;extdecl; begin result := execregexpr(RegExpr,InputStr); end; procedure ps_SplitRegExpr( const RegExpr, InputStr : String; Pieces : TStrings);extdecl; begin SplitRegExpr(RegExpr,InputStr,Pieces); end; function ps_ReplaceRegExpr( const RegExpr, InputStr, ReplaceStr : String; UseSubstitution : boolean) : String;extdecl; begin result := ReplaceRegExpr(RegExpr,InputStr,ReplaceStr,UseSubstitution); end; function ps_posex(needle, haystack: String; offset: integer): integer; extdecl; begin result := posex(needle, haystack, offset); end; \ No newline at end of file +function ps_Capitalize(str : string) : string;extdecl;begin result := Capitalize(str); end; function ps_CompressString(const Str : string) : string; extdecl; begin result := CompressString(str); end; function ps_DecompressString(const Compressed : string) : string; extdecl; begin result := DecompressString(Compressed); end; function ps_Base64Encode(const str : string) : string; extdecl; begin result := Base64Encode(str); end; function ps_Base64Decode(const str : string) : string; extdecl; begin result := Base64Decode(str); end; function ps_ExtractFromStr( Str : string; Extract : StrExtr) : string; extdecl; begin result := extractfromstr(str,extract); end; function ps_BoolToStr(bool : boolean) : string; extdecl; begin; result := BoolToStr(bool,true); end; function ps_Replace(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string; extdecl; begin; result := StringReplace(Text,FindStr,ReplaceStr,Flags); end; function ps_IntToStr(int : integer) : string; extdecl; begin result := inttostr(int); end; function ps_FloatToStr(flt : extended) : string; extdecl; begin result := floattostr(flt); end; function ps_StrToInt(value: String): Integer; extdecl; begin result := sysutils.StrToInt(value); end; function ps_StrToIntDef(value: String; default: Integer): Integer; extdecl; begin result := StrToIntDef(value,default); end; function ps_StrToFloat(value: String): Extended; extdecl; begin result := StrToFloat(value); end; function ps_StrToFloatDef(value: String; default: Extended): Extended; extdecl; begin result := StrToFloatDef(value,default); end; function ps_StrToBool(value: String): Boolean;extdecl; begin result := StrToBool(value); end; function ps_StrToBoolDef(value: String; default: Boolean): Boolean; extdecl; begin result := StrToBoolDef(value,default); end; function ps_Between(s1, s2, str: string): string; extdecl; var I,J : integer; begin; Result := ''; I := pos(s1,str); if I > 0 then begin; i := i + length(s1); j := posex(s2,str,i); if j > 0 then Result := copy(str,i,j-i); end; end; function ps_Implode(Glue : string; Pieces: TStringArray): string;extdecl; begin result := implode(glue,pieces); end; function ps_Explode(del, str: string): TStringArray;extdecl; begin result := Explode(del,str); end; procedure ps_ExplodeWrap(del, str: string; var res : TStringArray);extdecl; begin res := Explode(del,str); end; function ps_Padl(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char(' '), i - length(s)) + s; end; function ps_Padz(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char('0'), i - length(s)) + s; end; function ps_Padr(s: String; i: longInt): String;extdecl; begin result := s + StringOfChar(Char(' '), i - Length(s)); end; function ps_ExecRegExpr( const RegExpr, InputStr : String) : boolean;extdecl; begin result := execregexpr(RegExpr,InputStr); end; procedure ps_SplitRegExpr( const RegExpr, InputStr : String; Pieces : TStrings);extdecl; begin SplitRegExpr(RegExpr,InputStr,Pieces); end; function ps_ReplaceRegExpr( const RegExpr, InputStr, ReplaceStr : String; UseSubstitution : boolean) : String;extdecl; begin result := ReplaceRegExpr(RegExpr,InputStr,ReplaceStr,UseSubstitution); end; function ps_posex(needle, haystack: String; offset: integer): integer; extdecl; begin result := posex(needle, haystack, offset); end; \ No newline at end of file From 25e68f3d3ab61c597f10288c3eb81e2db5fab67e Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Sun, 10 Apr 2011 11:51:32 +0200 Subject: [PATCH 7/8] Simba: Allow CTS2 for Bitmap searches. Resolves 297. --- Units/MMLCore/finder.pas | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Units/MMLCore/finder.pas b/Units/MMLCore/finder.pas index 9dcefbf..d9eef25 100644 --- a/Units/MMLCore/finder.pas +++ b/Units/MMLCore/finder.pas @@ -1539,13 +1539,9 @@ begin dY := dY - bmpH; //Compiler hints HMod := 0;SMod := 0;H := 0.0;S := 0.0; L := 0.0; + CCTS := Self.CTS; - //We wont want HSL comparison with BMPs, right? Not for now atleast. - if CCTS > 1 then - begin - mDebugLn('CTS > 1, putting it temporary back to 1. For this (bitmap)search'); - CCTS := 1; - end; + //Get the "skip coords". CalculateBitmapSkipCoords(Bitmap,SkipCoords); for yy := 0 to dY do @@ -1676,13 +1672,8 @@ begin HiSpiral := (dx+1) * (dy+1) - 1; //Compiler hints HMod := 0;SMod := 0;H := 0.0;S := 0.0; L := 0.0; - //NO HSL. CCTS := Self.CTS; - if CCTS > 1 then - begin - mDebugLn('CTS > 1, putting it temporary back to 1. For this (bitmap)search'); - CCTS := 1; - end; + //Get the "skip coords". CalculateBitmapSkipCoords(Bitmap,SkipCoords); for i := 0 to HiSpiral do @@ -1751,13 +1742,7 @@ begin HiSpiral := (dx+1) * (dy+1) - 1; //Compiler hints HMod := 0;SMod := 0;H := 0.0;S := 0.0; L := 0.0; - //NO HSL. CCTS := Self.CTS; - if CCTS > 1 then - begin - mDebugLn('CTS > 1, putting it temporary back to 1. For this (bitmap)search'); - CCTS := 1; - end; FoundC := 0; //Get the "skip coords". CalculateBitmapSkipCoords(Bitmap,SkipCoords); From ca857373c39788ab33bfbc74d00099a55e51148f Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Fri, 15 Apr 2011 18:15:30 +0200 Subject: [PATCH 8/8] Simba: More keybindings on Linux. Ctrl+Alt+R = Start script Ctrl+Alt+S = Stop script Ctrl+Alt+P = Pick Colour --- Projects/Simba/simbaunit.pas | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Projects/Simba/simbaunit.pas b/Projects/Simba/simbaunit.pas index b65cd33..67bc0aa 100644 --- a/Projects/Simba/simbaunit.pas +++ b/Projects/Simba/simbaunit.pas @@ -50,11 +50,11 @@ uses lcltype, ActnList, SynExportHTML, SynEditKeyCmds, SynEditHighlighter, SynEditMarkupHighAll, LMessages, Buttons, - mmisc, stringutil,mufasatypesutil, mufasabase, v_ideCodeParser, + mmisc, stringutil,mufasatypesutil, mufasabase, about, framefunctionlist, ocr, updateform, Simbasettings, psextension, virtualextension, extensionmanager, settingssandbox, - v_ideCodeInsight, CastaliaPasLexTypes, // Code completion units + v_ideCodeParser, v_ideCodeInsight, CastaliaPasLexTypes, // Code completion units CastaliaSimplePasPar, v_AutoCompleteForm, // Code completion units PSDump, @@ -68,7 +68,13 @@ const interp_CP = 2; //CPascal { Place the shortcuts here } - shortcut_StopScript = 'S'; + {$IFDEF LINUX} + shortcut_StartScript = 'R'; + shortcut_StopScript = 'S'; + shortcut_PickColour = 'P'; + {$ELSE} + // Windows shortcuts here + {$ENDIF} type @@ -591,7 +597,15 @@ end; { Used for global callbacks on LINUX } procedure keybinder_callback(keystring: PChar; user_data: PtrUInt); cdecl; begin - SimbaForm.ActionStopScript.Execute; + writeln('Keystring: ' + keystring); + if keystring = shortcut_StartScript then + SimbaForm.ActionRunScript.Execute + else if keystring = shortcut_StopScript then + SimbaForm.ActionStopScript.Execute + else if keystring = shortcut_PickColour then + SimbaForm.ButtonPickClick(nil) + else + writeln('Unknown keystring: ', keystring) end; { XXX, TODO: Pressing the stop shortcut twice (quickly) may crash Simba. } @@ -600,13 +614,19 @@ begin keybinder_init(); { Initialise keybinder } { Bind keys } + if not keybinder_bind(PChar(shortcut_StartScript), @keybinder_callback, PtrUInt(0)) then + mDebugLn('Unable to register '+ shortcut_StartScript + ' as global hotkey'); if not keybinder_bind(PChar(shortcut_StopScript), @keybinder_callback, PtrUInt(0)) then - mDebugLn('Unable to register Ctrl + Alt + S as global hotkey'); + mDebugLn('Unable to register '+ shortcut_StopScript + ' as global hotkey'); + if not keybinder_bind(PChar(shortcut_PickColour), @keybinder_callback, PtrUInt(0)) then + mDebugLn('Unable to register '+ shortcut_PickColour + ' as global hotkey'); end; procedure Unbind_Linux_Keys; begin + keybinder_unbind(PChar(shortcut_StartScript), @keybinder_callback, PtrUInt(0)); keybinder_unbind(PChar(shortcut_StopScript), @keybinder_callback, PtrUInt(0)); + keybinder_unbind(PChar(shortcut_PickColour), @keybinder_callback, PtrUInt(0)); end; {$ENDIF}