-
Notifications
You must be signed in to change notification settings - Fork 0
/
unitdesktop.pas
214 lines (181 loc) · 5.85 KB
/
unitdesktop.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
unit UnitDesktop;
{$mode objfpc}{$H+}
interface
uses
cmem, Classes, SysUtils, IniFiles, process, strutils, FileUtil, Forms,
Controls, Graphics, Dialogs, ComCtrls, ActnList, Menus, ExtCtrls, StdCtrls,
CustomDrawn_Common, CustomDrawnControls, UnitLuaEditor, UnitVariaveisGlobais,
ResizeablePanel, UnitPastasProjetos;
type
{ TDesktop }
{ TExecutarProjeto }
TDesktop = class(TForm)
ActAbrir: TAction;
ActParar: TAction;
ActPlay: TAction;
ActSalvarTudo: TAction;
ActSalvar: TAction;
ActSair: TAction;
ActNovo: TAction;
Actions: TActionList;
ImageList1: TImageList;
MainMenu1: TMainMenu;
ItemArquivo: TMenuItem;
ItemNovo: TMenuItem;
ItemAbrir: TMenuItem;
ItemSair: TMenuItem;
AbrirProjeto: TOpenDialog;
ItemEditar : TMenuItem;
ItemSalvar : TMenuItem;
ItemSalvarTodos : TMenuItem;
ItemExecutar : TMenuItem;
ItemPlay : TMenuItem;
ItemStop : TMenuItem;
Memo1 : TMemo;
MemoMensagens: TMemo;
PageControl1: TCDPageControl;
CtrlLeftPanel: TResizeablePanel;
PcSaidas: TCDPageControl;
PnBottom: TResizeablePanel;
TsMensagens: TCDTabSheet;
TsConsole: TCDTabSheet;
TmExecutor: TTimer;
ToolBar1: TToolBar;
BtnNovo: TToolButton;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure ActAbrirExecute(Sender : TObject);
procedure ActPararExecute(Sender : TObject);
procedure ActPlayExecute(Sender : TObject);
procedure ActSairExecute(Sender : TObject);
procedure ActSalvarExecute(Sender : TObject);
procedure TmExecutorTimer(Sender : TObject);
private
ProjetoPath, LovePath, ProjetoNome : String;
IniConfig : TIniFile;
love : TProcess;
MemSaida : TMemo;
FramePastas : TPastasProjetos;
procedure LimparTela;
public
procedure AlterarCodigo(Sender : TObject);
procedure AbrirCodigo(Caminho, Nome : String);
end;
var
Desktop: TDesktop;
implementation
{$R *.lfm}
{ TDesktop }
procedure TDesktop.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
Application.Terminate;
end;
procedure TDesktop.FormCreate(Sender: TObject);
begin
IniConfig := TIniFile.Create(GetCurrentDir + separadorPasta +'Config.ini');
ProjetoPath := IniConfig.ReadString('Project','Path','');
ProjetoNome := IniConfig.ReadString('Project','Name','');
Self.Caption := ProjetoNome + ' - Pasciön IDE';
LovePath := IniConfig.ReadString('Love2d','Path','');
FramePastas := TPastasProjetos.Create(nil);
FramePastas.popularTreeProjeto(ProjetoPath, ProjetoNome);
FramePastas.Parent := CtrlLeftPanel;
FramePastas.Align := alClient;
FramePastas.Show;
end;
procedure TDesktop.LimparTela;
begin
//PageControl1.;
end;
procedure TDesktop.AlterarCodigo(Sender: TObject);
begin
if PosEx('*',PageControl1.ActivePage.Caption) = 0 then
PageControl1.ActivePage.Caption := '*'+ PageControl1.ActivePage.Caption;
ActSalvar.Enabled := True;
end;
procedure TDesktop.AbrirCodigo(Caminho, Nome : String);
var newTab: TCDTabSheet;
LuaTela : TLuaEditor;
begin
if PosEx('.lua',Nome) > 0 then
begin
newTab := PageControl1.AddPage(Nome);
LuaTela := TLuaEditor.Create(nil);
LuaTela.SetCaminho(ProjetoPath + StringReplace(Caminho, ProjetoNome , '', []));
LuaTela.CarregarArquivo;
LuaTela.GridLinhas.RowCount := LuaTela.RMEditor.Lines.Count;
LuaTela.BorderStyle := bsNone;
LuaTela.Parent := newTab;
LuaTela.Align := alClient;
LuaTela.Show;
end;
end;
procedure TDesktop.TmExecutorTimer(Sender: TObject);
begin
if Assigned(love) and love.Running then
begin
ActParar.Enabled := True;
ActPlay.Enabled := False;
end
else
begin
ActParar.Enabled := False;
ActPlay.Enabled := True;
TmExecutor.Enabled := False;
if Assigned(love) then
begin
//Memo1.Lines.LoadFromStream(love.Output);
FreeAndNil(love);
end;
{if Assigned(ExecutorSaida) then
FreeAndNil(ExecutorSaida);}
end;
end;
procedure TDesktop.ActSairExecute(Sender: TObject);
begin
Close;
end;
procedure TDesktop.ActSalvarExecute(Sender: TObject);
var i : Integer;
begin
for i := 0 to Pred(PageControl1.ActivePage.ControlCount) do
if PageControl1.ActivePage.Controls[i].ClassType = TLuaEditor then
TLuaEditor(PageControl1.ActivePage.Controls[i]).SalvarArquivo;
ActSalvar.Enabled := false;
PageControl1.ActivePage.Caption := StringReplace(PageControl1.ActivePage.Caption,'*','',[]);
end;
procedure TDesktop.ActPlayExecute(Sender: TObject);
begin
MemoMensagens.Lines.Add('Iniciando ' + ProjetoNome);
love := TProcess.Create(nil);
love.CommandLine := LovePath + ' "'+ProjetoPath+'"';
love.Options := love.Options + [poUsePipes, poStderrToOutPut];
love.Active := True;
TmExecutor.Enabled := True;
//SysUtils.ExecuteProcess(Utf8ToAnsi(LovePath),Utf8ToAnsi('"'+ProjetoPath+'"'),[]);
end;
procedure TDesktop.ActPararExecute(Sender: TObject);
begin
love.Terminate(0);
ActPlay.Enabled := True;
ActParar.Enabled := False;
if Assigned(love) then
FreeAndNil(love);
end;
procedure TDesktop.ActAbrirExecute(Sender: TObject);
var caminho : String;
begin
if AbrirProjeto.Execute then
begin
caminho := AbrirProjeto.InitialDir.Substring(0, Length(AbrirProjeto.InitialDir) - 1);
IniConfig.WriteString('Project', 'Path', caminho);
IniConfig.WriteString('Project','Name', ReverseString(ReverseString(caminho).Substring(0, PosEx('\',ReverseString(caminho)) -1 )));
end;
end;
end.