FreeLaunch

Форк
0
/
ProgrammPropertiesFormModule.pas 
274 строки · 9.4 Кб
1
{
2
  ##########################################################################
3
  #  FreeLaunch is a free links manager for Microsoft Windows              #
4
  #                                                                        #
5
  #  Copyright (C) 2023 Alexey Tatuyko <feedback@ta2i4.ru>                 #
6
  #  Copyright (C) 2019 Mykola Petrivskiy                                  #
7
  #  Copyright (C) 2010 Joker-jar <joker-jar@yandex.ru>                    #
8
  #                                                                        #
9
  #  This file is part of FreeLaunch.                                      #
10
  #                                                                        #
11
  #  FreeLaunch is free software: you can redistribute it and/or modify    #
12
  #  it under the terms of the GNU General Public License as published by  #
13
  #  the Free Software Foundation, either version 3 of the License, or     #
14
  #  (at your option) any later version.                                   #
15
  #                                                                        #
16
  #  FreeLaunch is distributed in the hope that it will be useful,         #
17
  #  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
18
  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
19
  #  GNU General Public License for more details.                          #
20
  #                                                                        #
21
  #  You should have received a copy of the GNU General Public License     #
22
  #  along with FreeLaunch. If not, see <http://www.gnu.org/licenses/>.    #
23
  ##########################################################################
24
}
25

26
unit ProgrammPropertiesFormModule;
27

28
interface
29

30
uses
31
  Winapi.Windows, Winapi.Messages, Winapi.ShellAPI,
32
  System.SysUtils, System.Variants, System.Classes, System.IniFiles,
33
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls,
34
  Vcl.ExtCtrls, Vcl.StdCtrls,
35
  ChangeIconFormModule, FLData, FLFunctions, FLLanguage;
36

37
type
38
  TProgrammPropertiesForm = class(TForm)
39
    PageControl1: TPageControl;
40
    TabSheet1: TTabSheet;
41
    Label1: TLabel;
42
    Label2: TLabel;
43
    Label4: TLabel;
44
    ParamsEdit: TEdit;
45
    DescrEdit: TEdit;
46
    Label3: TLabel;
47
    PriorBox: TComboBox;
48
    Bevel1: TBevel;
49
    Label5: TLabel;
50
    Bevel2: TBevel;
51
    Bevel3: TBevel;
52
    Label6: TLabel;
53
    IcImage: TImage;
54
    ChangeIconButton: TButton;
55
    QuesCheckBox: TCheckBox;
56
    Label7: TLabel;
57
    WStyleBox: TComboBox;
58
    OKButton: TButton;
59
    CancelButton: TButton;
60
    DropBox: TCheckBox;
61
    DropParamsEdit: TEdit;
62
    Label8: TLabel;
63
    HideCheckBox: TCheckBox;
64
    Label9: TLabel;
65
    RefProps: TButton;
66
    CommandEdit: TButtonedEdit;
67
    AdminBox: TCheckBox;
68
    WorkFolderEdit: TButtonedEdit;
69
    procedure FormShow(Sender: TObject);
70
    procedure BrowseExecClick(Sender: TObject);
71
    procedure OKButtonClick(Sender: TObject);
72
    procedure ChangeIconButtonClick(Sender: TObject);
73
    procedure DropBoxClick(Sender: TObject);
74
    procedure RefPropsClick(Sender: TObject);
75
    procedure CommandEditChange(Sender: TObject);
76
    procedure WorkFolderClick(Sender: TObject);
77
  private
78
    Link: TLink;
79
  public
80
    procedure RefreshProps;
81
    class function Execute(ALink: TLink): TLink;
82
  end;
83

84
var
85
  ic: string;
86
  iconindex: integer;
87

88
implementation
89

90
uses
91
  FLaunchMainFormModule, FLDialogs;
92

93
{$R *.dfm}
94

95
procedure TProgrammPropertiesForm.ChangeIconButtonClick(Sender: TObject);
96
var
97
  frm: TChangeIconForm;
98
begin
99
  Application.CreateForm(TChangeIconForm, frm);
100
  frm.ShowModal;
101
  FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(ic), iconindex);
102
end;
103

104
procedure TProgrammPropertiesForm.CommandEditChange(Sender: TObject);
105
var
106
  ext: string;
107
begin
108
  ext := extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower;
109
  OKButton.Enabled := FileExists(GetAbsolutePath(CommandEdit.Text)) and IsExecutable(ext);
110
end;
111

112
procedure TProgrammPropertiesForm.OKButtonClick(Sender: TObject);
113
begin
114
  if (not fileexists(GetAbsolutePath(CommandEdit.Text))) then
115
    begin
116
      fillchar(Link, sizeof(TLink), 0);
117
      exit;
118
    end;
119
  link.active := true;
120
  link.ltype := 0;
121
  link.exec := CommandEdit.Text;
122
  link.workdir := WorkFolderEdit.Text;
123
  link.params := ParamsEdit.Text;
124
  link.dropfiles := DropBox.Checked;
125
  link.dropparams := DropParamsEdit.Text;
126
  link.descr := DescrEdit.Text;
127
  link.icon := ic;
128
  link.iconindex := iconindex;
129
  link.ques := QuesCheckBox.Checked;
130
  link.hide := HideCheckBox.Checked;
131
  link.pr := PriorBox.ItemIndex;
132
  link.wst := WStyleBox.ItemIndex;
133
  Link.IsAdmin := AdminBox.Checked;
134
end;
135

136
procedure TProgrammPropertiesForm.RefPropsClick(Sender: TObject);
137
begin
138
  RefreshProps;
139
end;
140

141
procedure TProgrammPropertiesForm.DropBoxClick(Sender: TObject);
142
begin
143
  Label8.Enabled := DropBox.Checked;
144
  DropParamsEdit.Enabled := DropBox.Checked;
145
  if DropBox.Checked then
146
    begin
147
      if DropParamsEdit.Text = '' then
148
        DropParamsEdit.Text := '"%1"';
149
      DropParamsEdit.SetFocus;
150
    end;
151
end;
152

153
class function TProgrammPropertiesForm.Execute(ALink: TLink): TLink;
154
begin
155
  with TProgrammPropertiesForm.Create(Application.MainForm) do
156
  try
157
    Link := ALink;
158
    ShowModal;
159
  finally
160
    Result := Link;
161
    Free;
162
  end;
163
end;
164

165
procedure TProgrammPropertiesForm.FormShow(Sender: TObject);
166
begin
167
  if AlwaysOnTop then FormStyle := fsStayOnTop;
168
  //--Loading language
169
  OKButton.Caption := Language.BtnOk;
170
  CancelButton.Caption := Language.BtnCancel;
171
  PageControl1.Pages[0].Caption := Language.Properties.Caption;
172
  Caption := Language.Properties.Caption;
173
  Label9.Caption := Language.Properties.Folder + ':';
174
  Label1.Caption := Language.Properties.LblObject + ':';
175
  Label2.Caption := Language.Properties.Parameters + ':';
176
  Label8.Caption := Label2.Caption;
177
  Label4.Caption := Language.Properties.Description + ':';
178
  Label3.Caption := Language.Properties.Priority + ':';
179
  PriorBox.Items.Add(Language.Properties.PriorityNormal);
180
  PriorBox.Items.Add(Language.Properties.PriorityHigh);
181
  PriorBox.Items.Add(Language.Properties.PriorityIdle);
182
  PriorBox.Items.Add(Language.Properties.PriorityRealTime);
183
  PriorBox.Items.Add(Language.Properties.PriorityBelowNormal);
184
  PriorBox.Items.Add(Language.Properties.PriorityAboveNormal);
185
  Label7.Caption := Language.Properties.View + ':';
186
  WStyleBox.Items.Add(Language.Properties.ViewNormal);
187
  WStyleBox.Items.Add(Language.Properties.ViewMax);
188
  WStyleBox.Items.Add(Language.Properties.ViewMin);
189
  WStyleBox.Items.Add(Language.Properties.ViewHidden);
190
  CommandEdit.RightButton.Hint := Language.Properties.BeHint;
191
  RefProps.Hint := Language.Properties.RpHint;
192
  Label5.Caption := Language.Properties.Options;
193
  Bevel2.Left := Label5.Left + Label5.Width + 7;
194
  Bevel2.Width := TabSheet1.Width - Bevel2.Left - 7;
195
  Label6.Caption := Language.Properties.Icon;
196
  Bevel3.Left := Label6.Left + Label6.Width + 7;
197
  Bevel3.Width := TabSheet1.Width - Bevel3.Left - 7;
198
  ChangeIconButton.Caption := Language.Properties.Change;
199
  DropBox.Caption := Language.Properties.ChbDrop;
200
  QuesCheckBox.Caption := Language.Properties.ChbQuestion;
201
  HideCheckBox.Caption := Language.Properties.ChbHide;
202
  AdminBox.Caption := Language.Properties.ChbAdmin;
203

204
  CommandEdit.Text := Link.exec;
205
  WorkFolderEdit.Text := Link.workdir;
206
  ParamsEdit.Text := Link.params;
207
  DropBox.Checked := Link.dropfiles;
208
  DropBoxClick(nil);
209
  DropParamsEdit.Text := Link.dropparams;
210
  DescrEdit.Text := Link.descr;
211
  ic := Link.icon;
212
  iconindex := Link.iconindex;
213
  QuesCheckBox.Checked := Link.ques;
214
  HideCheckBox.Checked := Link.hide;
215
  PriorBox.ItemIndex := Link.pr;
216
  WStyleBox.ItemIndex := Link.wst;
217
  AdminBox.Checked := Link.IsAdmin;
218
  FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(Link.icon),
219
    Link.iconindex);
220
  CommandEditChange(nil);
221
end;
222

223
procedure TProgrammPropertiesForm.RefreshProps;
224
var
225
  lnkinfo: TShellLinkInfoStruct;
226
  FName: string;
227
  ext: string;
228
begin
229
  if (not fileexists(GetAbsolutePath(CommandEdit.Text))) then exit;
230

231
  if extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower = '.lnk' then
232
    begin
233
      StrPLCopy(lnkinfo.FullPathAndNameOfLinkFile, GetAbsolutePath(CommandEdit.Text), MAX_PATH - 1);
234
      GetLinkInfo(@lnkinfo);
235
      FName := lnkinfo.FullPathAndNameOfFileToExecute;
236
      ext := extractfileext(FName).ToLower;
237
      if not IsExecutable(ext) then
238
        exit;
239
      CommandEdit.Text := FName;
240
      Ic := lnkinfo.FullPathAndNameOfFileContiningIcon;
241
      if Ic = '' then Ic := CommandEdit.Text;
242
      iconindex := lnkinfo.IconIndex;
243
      WorkFolderEdit.Text := lnkinfo.FullPathAndNameOfWorkingDirectroy;
244
      ParamsEdit.Text := lnkinfo.ParamStringsOfFileToExecute;
245
      DescrEdit.Text := lnkinfo.Description;
246
    end
247
  else
248
    begin
249
      ext := extractfileext(GetAbsolutePath(CommandEdit.Text)).ToLower;
250
      if not IsExecutable(ext) then
251
        Exit;
252
      Ic := CommandEdit.Text;
253
      //ParamsEdit.Text := '';
254
      DescrEdit.Text := '';
255
      iconindex := 0;
256
    end;
257
  if DescrEdit.Text = '' then
258
    DescrEdit.Text := GetFileDescription(GetAbsolutePath(CommandEdit.Text));
259
  if DescrEdit.Text = '' then
260
    DescrEdit.Text := ExtractFileNameNoExt(GetAbsolutePath(CommandEdit.Text));
261
  FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(Ic), iconindex);
262
end;
263

264
procedure TProgrammPropertiesForm.WorkFolderClick(Sender: TObject);
265
begin
266
  WorkFolderEdit.Text := ExtractFileDir(FileOrDirSelect(WorkFolderEdit.Text));
267
end;
268

269
procedure TProgrammPropertiesForm.BrowseExecClick(Sender: TObject);
270
begin
271
  CommandEdit.Text := ProgramSelect(CommandEdit.Text);
272
end;
273

274
end.
275

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.