FreeLaunch

Форк
0
/
ChangeIconFormModule.pas 
189 строк · 7.1 Кб
1
{
2
  ##########################################################################
3
  #  FreeLaunch is a free links manager for Microsoft Windows              #
4
  #                                                                        #
5
  #  Copyright (C) 2024 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 ChangeIconFormModule;
27

28
interface
29

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

38
type
39
  TChangeIconForm = class(TForm)
40
    GroupBox1: TGroupBox;
41
    Label1: TLabel;
42
    Label2: TLabel;
43
    CancelButton: TButton;
44
    OKButton: TButton;
45
    IcImage: TImage;
46
    Label3: TLabel;
47
    IndexEdit: TSpinEdit;
48
    RefProps: TButton;
49
    IconEdit: TButtonedEdit;
50
    NegativeBox: TCheckBox;
51
    procedure FormShow(Sender: TObject);
52
    procedure BrowseIconClick(Sender: TObject);
53
    procedure CancelButtonClick(Sender: TObject);
54
    procedure OKButtonClick(Sender: TObject);
55
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
56
    procedure RefPropsClick(Sender: TObject);
57
    procedure IndexEditChange(Sender: TObject);
58
  private
59
    icindex, iconcount, ncount: integer;
60
  public
61
    procedure RefreshProps;
62
  end;
63

64
var
65
  showform: Boolean = True;
66

67
implementation
68

69
uses
70
  FLaunchMainFormModule, ProgrammPropertiesFormModule, FilePropertiesFormModule,
71
  FLDialogs;
72

73
{$R *.dfm}
74

75
procedure TChangeIconForm.RefreshProps;
76
begin
77
  icindex := 1;
78
  iconcount := GetIconCount(GetAbsolutePath(IconEdit.Text));
79
  ncount := GetNegativeCount(IconEdit.Text);
80
  if iconcount = 0 then iconcount := 1;
81
  Label3.Caption := Format(Language.IconSelect.LblOf, [iconcount]);
82
  IndexEdit.Value := icindex;
83
  IndexEdit.MaxValue := iconcount;
84
  IndexEdit.Enabled := iconcount > 1;
85
  NegativeBox.Enabled := (iconcount > 1) and (ncount > 1);
86
  NegativeBox.Checked := False;
87
  FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(IconEdit.Text),
88
                                          Pred(icindex));
89
end;
90

91
procedure TChangeIconForm.BrowseIconClick(Sender: TObject);
92
var
93
  FileName: string;
94
begin
95
  FileName := FileOrDirSelect(IconEdit.Text);
96
  if FileName <> IconEdit.Text then
97
  begin
98
    IconEdit.Text := FileName;
99
    RefreshProps;
100
  end;
101
end;
102

103
procedure TChangeIconForm.OKButtonClick(Sender: TObject);
104
begin
105
  if PropertiesMode = 0 then
106
    begin
107
      ProgrammPropertiesFormModule.ic         := IconEdit.Text;
108
      ProgrammPropertiesFormModule.iconindex  := icindex +
109
                                                  IfThen(icindex < 0, 1, -1);
110
    end;
111
  if PropertiesMode = 1 then
112
    begin
113
      FilePropertiesFormModule.ic         := IconEdit.Text;
114
      FilePropertiesFormModule.iconindex  := icindex +
115
                                              IfThen(icindex < 0, 1, -1);
116
    end;
117
  Close;
118
end;
119

120
procedure TChangeIconForm.RefPropsClick(Sender: TObject);
121
begin
122
  RefreshProps;
123
end;
124

125
procedure TChangeIconForm.CancelButtonClick(Sender: TObject);
126
begin
127
  Close;
128
end;
129

130
procedure TChangeIconForm.FormClose(Sender: TObject; var Action: TCloseAction);
131
begin
132
  showform  := True;
133
  Action    := CAFree;
134
end;
135

136
procedure TChangeIconForm.FormShow(Sender: TObject);
137
begin
138
  if AlwaysOnTop then FormStyle := fsStayOnTop;
139
  //--Loading language
140
  OKButton.Caption     := Language.BtnOk;
141
  CancelButton.Caption := Language.BtnCancel;
142
  Caption              := Language.IconSelect.Caption;
143
  Label1.Caption       := Language.IconSelect.FileName + ':';
144
  Label2.Caption       := Language.IconSelect.Index + ':';
145
  NegativeBox.Caption  := Language.IconSelect.Negative;
146
  //---------------------------
147
  if PropertiesMode = 0 then begin
148
      IconEdit.Text := ProgrammPropertiesFormModule.ic;
149
      iconcount     := GetIconCount(GetAbsolutePath(ProgrammPropertiesFormModule.Ic));
150
      icindex       := ProgrammPropertiesFormModule.iconindex +
151
                      IfThen(ProgrammPropertiesFormModule.iconindex < 0, -1, 1);
152
      ncount        := GetNegativeCount(GetAbsolutePath(ProgrammPropertiesFormModule.Ic));
153
  end;
154
  if PropertiesMode = 1 then begin
155
      IconEdit.Text := FilePropertiesFormModule.ic;
156
      iconcount     := GetIconCount(GetAbsolutePath(FilePropertiesFormModule.Ic));
157
      icindex       := FilePropertiesFormModule.iconindex +
158
                          IfThen(FilePropertiesFormModule.iconindex < 0, -1, 1);
159
      ncount        := GetNegativeCount(GetAbsolutePath(ProgrammPropertiesFormModule.Ic));
160
  end;
161
  NegativeBox.Enabled := (iconcount > 1) and (ncount > 1);
162
  if iconcount = 0 then iconcount := 1;
163
  NegativeBox.Checked := (icindex < -1) and (ncount >= -icindex);
164
  Label3.Caption := Format(Language.IconSelect.LblOf, [IfThen(NegativeBox.Checked, ncount, iconcount)]);
165
  IndexEdit.Value := IfThen(icindex < 0, -icindex, icindex);
166
  if NegativeBox.Checked
167
    then IndexEdit.Enabled := ncount > 1
168
    else IndexEdit.Enabled := iconcount > 1;
169
  IndexEdit.MaxValue := IfThen(NegativeBox.Checked, ncount, iconcount);
170
  FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(IconEdit.Text), icindex + IfThen(icindex < 0, 1, -1));
171
  IconEdit.SetFocus;
172
  showform := False;
173
end;
174

175
procedure TChangeIconForm.IndexEditChange(Sender: TObject);
176
begin
177
  if showform then Exit;
178
  Label3.Caption := Format(Language.IconSelect.LblOf, [IfThen(NegativeBox.Checked, ncount, iconcount)]);
179
  IndexEdit.MaxValue := IfThen(NegativeBox.Checked, ncount, iconcount);
180
  if NegativeBox.Checked and (IndexEdit.Value > ncount)
181
    then begin
182
      IndexEdit.Value := 1;
183
      IndexEdit.Enabled := ncount > 1;
184
    end;
185
  icindex := IfThen(NegativeBox.Checked, -IndexEdit.Value, IndexEdit.Value);
186
  FlaunchMainForm.LoadIcFromFileNoModif(IcImage, GetAbsolutePath(IconEdit.Text), icindex + IfThen(icindex < 0, 1, -1));
187
end;
188

189
end.
190

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

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

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

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