1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-21 08:45:06 -05:00

Simba: Add directives file. Clean up hotkeys.

This commit is contained in:
Merlijn Wajer 2011-04-09 20:45:36 +02:00
parent 00d18b1875
commit c353870a84
3 changed files with 124 additions and 34 deletions

34
Projects/Simba/Simba.inc Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
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

View File

@ -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,

View File

@ -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 = '<Ctrl><Alt>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('<Ctrl><Alt>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;