mirror of https://gitlab.com/basile.b/dexed.git
try to host a cmd as terminal under win
This commit is contained in:
parent
994566ed9a
commit
489de09761
|
@ -11,7 +11,9 @@ unit TerminalCtrls;
|
|||
interface
|
||||
|
||||
uses
|
||||
Gtk2Term, Classes, SysUtils, Controls, Graphics;
|
||||
Gtk2Term, Classes, SysUtils, Controls,
|
||||
{$ifdef windows} windows, AsyncProcess,{$endif}
|
||||
Graphics, dialogs;
|
||||
|
||||
type
|
||||
|
||||
|
@ -21,6 +23,11 @@ type
|
|||
{$ifdef hasgtk2term}
|
||||
fTerminalHanlde: PVteTerminal;
|
||||
{$endif}
|
||||
{$ifdef windows}
|
||||
fTermProgram: string;
|
||||
fTermProcess: TAsyncProcess;
|
||||
fTermWnd: HWND;
|
||||
{$endif}
|
||||
fOnTerminate: TNotifyEvent;
|
||||
fOnTerminalVisibleChanged: TNotifyEvent;
|
||||
fBackgroundColor: TColor;
|
||||
|
@ -37,10 +44,15 @@ type
|
|||
procedure FontChanged(Sender: TObject); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor destroy; override;
|
||||
procedure Restart;
|
||||
procedure Reparent;
|
||||
// Sends a command, as it would be manually typed. Line feed is automatically added.
|
||||
procedure Command(const data: string);
|
||||
published
|
||||
{$ifdef windows}
|
||||
property terminalProgram: string read fTermProgram write fTermProgram;
|
||||
{$endif}
|
||||
// Background color
|
||||
property backgroundColor: TColor read fBackgroundColor write setBackgroundColor default clBlack;
|
||||
// Font color
|
||||
|
@ -203,6 +215,30 @@ begin
|
|||
fOnTerminalVisibleChanged(Self);
|
||||
end;
|
||||
|
||||
{$ifdef windows}
|
||||
function ReparentTerminalClbck(wnd: HWND; userp: LPARAM):WINBOOL; stdcall;
|
||||
var
|
||||
h: DWORD = 0;
|
||||
begin
|
||||
result := true;
|
||||
with TTerminal(userp) do
|
||||
begin
|
||||
GetWindowThreadProcessId(wnd, h);
|
||||
if (fTermWnd = 0) and (h = fTermProcess.ProcessID) then
|
||||
begin
|
||||
fTermWnd := wnd;
|
||||
windows.SetParent(fTermWnd, Handle);
|
||||
SetWindowLongPtr(fTermWnd, GWL_STYLE, WS_MAXIMIZE or WS_VISIBLE);
|
||||
end;
|
||||
if (fTermWnd <> 0) then
|
||||
begin
|
||||
SetWindowPos(fTermWnd, HWND_TOP, 0, 0, width, height, SWP_SHOWWINDOW);
|
||||
result := false;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
procedure TTerminal.Restart;
|
||||
{$ifdef hasgtk2term}
|
||||
var
|
||||
|
@ -229,6 +265,29 @@ begin
|
|||
g_signal_connect(Info.ClientWidget, 'child-exited', G_CALLBACK(@TerminalExit), nil);
|
||||
g_signal_connect(Info.ClientWidget, 'contents-changed', G_CALLBACK(@TerminalRefresh), nil);
|
||||
{$endif}
|
||||
|
||||
{$ifdef Windows}
|
||||
if assigned(fTermProcess) then
|
||||
begin
|
||||
fTermProcess.Terminate(0);
|
||||
fTermProcess.Free;
|
||||
end;
|
||||
fTermProcess := TAsyncProcess.Create(nil);
|
||||
fTermprocess.Executable:= fTermProgram;
|
||||
fTermProcess.Execute;
|
||||
sleep(10);
|
||||
Reparent();
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
procedure TTerminal.Reparent;
|
||||
begin
|
||||
{$ifdef windows}
|
||||
if assigned(fTermProcess) then
|
||||
begin
|
||||
EnumWindows(@ReparentTerminalClbck, LPARAM(self));
|
||||
end;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
procedure TTerminal.Command(const data: string);
|
||||
|
@ -267,6 +326,21 @@ begin
|
|||
fSelectedColor:= clWhite;
|
||||
Font.Height:=11;
|
||||
Font.Name:='Monospace';
|
||||
|
||||
{$ifdef windows}
|
||||
fTermProgram := 'cmd.exe';
|
||||
//Restart;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
destructor TTerminal.destroy;
|
||||
begin
|
||||
if assigned(fTermProcess) then
|
||||
begin
|
||||
fTermProcess.Terminate(0);
|
||||
fTermProcess.Free;
|
||||
end;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TTerminal.Paint;
|
||||
|
|
|
@ -384,8 +384,8 @@ type
|
|||
fPrjGrpWidg: TCEProjectGroupWidget;
|
||||
{$IFDEF UNIX}
|
||||
fGdbWidg: TCEGdbWidget;
|
||||
fTermWWidg: TCETermWidget;
|
||||
{$ENDIF}
|
||||
fTermWWidg: TCETermWidget;
|
||||
fDfmtWidg: TCEDfmtWidget;
|
||||
fProfWidg: TCEProfileViewerWidget;
|
||||
fCompStart: TDateTime;
|
||||
|
@ -1463,9 +1463,9 @@ begin
|
|||
fDfmtWidg := TCEDfmtWidget.create(self);
|
||||
fPrjGrpWidg := TCEProjectGroupWidget.create(self);
|
||||
fProfWidg := TCEProfileViewerWidget.create(self);
|
||||
fTermWWidg := TCETermWidget.create(self);
|
||||
{$IFDEF UNIX}
|
||||
fGdbWidg := TCEGdbWidget.create(self);
|
||||
fTermWWidg := TCETermWidget.create(self);
|
||||
{$ENDIF}
|
||||
|
||||
getMessageDisplay(fMsgs);
|
||||
|
@ -1487,9 +1487,9 @@ begin
|
|||
fWidgList.addWidget(@fDfmtWidg);
|
||||
fWidgList.addWidget(@fPrjGrpWidg);
|
||||
fWidgList.addWidget(@fProfWidg);
|
||||
fWidgList.addWidget(@fTermWWidg);
|
||||
{$IFDEF UNIX}
|
||||
fWidgList.addWidget(@fGdbWidg);
|
||||
fWidgList.addWidget(@fTermWWidg);
|
||||
{$ENDIF}
|
||||
|
||||
fWidgList.sort(@CompareWidgCaption);
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
inherited CETermWidget: TCETermWidget
|
||||
Left = 1018
|
||||
Height = 296
|
||||
Width = 674
|
||||
Caption = 'Terminal'
|
||||
ClientHeight = 296
|
||||
ClientWidth = 674
|
||||
OnClick = FormResize
|
||||
OnResize = FormResize
|
||||
inherited Back: TPanel
|
||||
Height = 296
|
||||
Width = 674
|
||||
ClientHeight = 296
|
||||
ClientWidth = 674
|
||||
inherited Content: TPanel
|
||||
Height = 85
|
||||
Height = 260
|
||||
Top = 36
|
||||
Width = 674
|
||||
end
|
||||
inherited toolbar: TCEToolBar
|
||||
Width = 666
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,6 +51,7 @@ type
|
|||
{ TCETermWidget }
|
||||
|
||||
TCETermWidget = class(TCEWidget, ICEDocumentObserver, ICEProjectObserver)
|
||||
procedure FormResize(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
private
|
||||
fTerm: TTerminal;
|
||||
|
@ -68,6 +69,11 @@ type
|
|||
procedure projCompiling(project: ICECommonProject);
|
||||
procedure projCompiled(project: ICECommonProject; success: boolean);
|
||||
|
||||
procedure dockingChanged(sender: TCEWidget; newState: TWidgetDockingState);
|
||||
|
||||
protected
|
||||
procedure DoFirstShow; override;
|
||||
|
||||
public
|
||||
constructor create(aOwner: TComponent); override;
|
||||
destructor destroy; override;
|
||||
|
@ -184,11 +190,13 @@ var
|
|||
f: string;
|
||||
begin
|
||||
inherited;
|
||||
toolbarVisible:=false;
|
||||
fTerm := TTerminal.Create(self);
|
||||
fTerm.Align:= alClient;
|
||||
fTerm.BorderSpacing.Around:=4;
|
||||
fterm.Parent := self;
|
||||
fTerm.OnTerminalVisibleChanged:=@FormShow;
|
||||
self.onDockingChanged:=@dockingChanged;
|
||||
|
||||
fOpts:= TCETerminalOptions.Create(self);
|
||||
|
||||
|
@ -206,6 +214,28 @@ begin
|
|||
inherited;
|
||||
end;
|
||||
|
||||
procedure TCETermWidget.dockingChanged(sender: TCEWidget; newState: TWidgetDockingState);
|
||||
begin
|
||||
{$IFDEF WINDOWS}
|
||||
fTerm.Restart;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TCETermWidget.DoFirstShow;
|
||||
begin
|
||||
inherited;
|
||||
{$IFDEF WINDOWS}
|
||||
fTerm.Restart;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TCETermWidget.FormResize(Sender: TObject);
|
||||
begin
|
||||
{$IFDEF WINDOWS}
|
||||
fTerm.Reparent;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TCETermWidget.FormShow(Sender: TObject);
|
||||
begin
|
||||
fOpts.applyChanges;
|
||||
|
|
Loading…
Reference in New Issue