summaryrefslogtreecommitdiff
path: root/plugins/Actman30/ua/i_ua.inc
blob: b3b4cdaa4780733b8c9f2b7cbeb5c02490fd5655 (plain)
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
215
216
217
218
219
{}
function AddUAction(idx:integer; ptr:pChain):integer;
var
  buf:array [0..127] of AnsiChar;
begin
  if idx<0 then idx:=Length(UActionList);
  if idx=Length(UActionList) then
    SetLength(UActionList,Length(UActionList)+1);

  FillChar(UActionList[idx],SizeOf(tMyActionItem),0);

  with UActionList[idx] do
  begin
    // get Action settings
    dwActID:=ptr^.id;
    StrDupW(szActDescr,ptr^.descr);
    wSortIndex:=idx;
    
    // prepare for work
    IntToStr(StrCopyE(buf,'Actions/Action_'),ptr^.id);
    StrDup(szNameID,@buf);
    AddIcolibIcon (UActionList[idx]);
  end;

  SetLength(arMenuRec,Length(UActionList)+1);
  FillChar (arMenuRec[HIGH(arMenuRec)],SizeOf(tuaMenuRecA),0);
  result:=idx;
end;

function CreateUActionList:integer;
var
  ptr,ptr1:pChain;
  i:integer;
begin
  result:=CallService(MS_ACT_GETLIST,0,LPARAM(@ptr));
  SetLength(UActionList,result);

  SetLength(arMenuRec, result+1);
  FillChar (arMenuRec[0],(result+1)*SizeOf(tuaMenuRecA),0);

  if result>0 then
  begin
    ptr1:=ptr;
    inc(pbyte(ptr),4);
    for i:=0 to result-1 do
    begin
      AddUAction(i,ptr);
      LoadUA(i); // just here coz at list changes for new we don't have settings
      if (UActionList[i].flags and UAF_2STATE)<>0 then
        AddIcolibIconP(UActionList[i]);
      SetAllActionUsers(UActionList[i],true);
      inc(ptr);
    end;
    CallService(MS_ACT_FREELIST,0,LPARAM(ptr1));
  end;
end;

// "compact" means need to compact list/delete settings (Delete, not just exit)
procedure DeleteUAction(num:integer;compact:boolean);
var
  ActionItem:pMyActionItem;
  luse:boolean;
  lmenu:tMenuType;
begin
  if compact then
    DeleteUASettings(num);

  ActionItem:=@UActionList[num];

  DeleteIcolibIcon(ActionItem^);

  if (ActionItem.flags and UAF_REGHOTKEY)<>0 then
    DeleteCoreHotkey(ActionItem^);

  if (ActionItem.flags and UAF_REGTTBB)<>0 then
    DeleteTTBButton(ActionItem^);
  mFreeMem(ActionItem.szTTBTooltip);
  mFreeMem(ActionItem.szTTBTooltipPressed);
  mFreeMem(ActionItem.szTTBShowWhenVars);

  if (ActionItem.flags and UAF_REGTABB)<>0 then
    DeleteTabBBButton(ActionItem^);
  mFreeMem(ActionItem.szTabBTooltip);
  mFreeMem(ActionItem.szTabBTooltipPressed);

  luse:=false;
  for lmenu:=main_menu to HIGH(tMenuType) do
  begin
    with ActionItem.UAMenuItem[lmenu] do
    begin
      if (menu_opt and UAF_MENUUSE)<>0 then
      begin
        luse:=true;
        DeleteMenuItem(ActionItem^,lmenu);
      end;
      mFreeMem(szMenuPopup);
      mFreeMem(szMenuNameVars);
      mFreeMem(szMenuShowWhenVars);
    end;
  end;

  if (not luse) and (ActionItem.hMenuService<>0) then
  begin
    DestroyServiceFunction(ActionItem.hMenuService);
    ActionItem.hMenuService:=0;
  end;

  // Free Memory
  mFreeMem(ActionItem.szNameID);
  mFreeMem(ActionItem.szActDescr);
  
  if compact then
  begin
    // compact list
    if num<HIGH(UActionList) then
    begin
      move(UActionList[num+1],UActionList[num],(HIGH(UActionList)-num)*SizeOf(tMyActionItem));
    end;
    SetLength(UActionList,Length(UActionList)-1);
  end;
end;

function ActListChange(wParam:WPARAM;lParam:LPARAM):integer; cdecl;
var
  ptr,ptr1:pChain;
  idx,i,j,count:integer;
  bFound:boolean;
begin
  result:=0;

  count:=CallService(MS_ACT_GETLIST,0,TLPARAM(@ptr));

  if count>0 then
  begin
    ptr1:=ptr;
    inc(pbyte(ptr),4);
    if wParam<>0 then
//    if (wParam and (ACTM_NEW or ACTM_RENAME or ACTM_SORT or ACTM_DELETE))<>0 then
      for i:=0 to count-1 do
      begin
        // search corresponding element
        idx:=-1;
        for j:=0 to HIGH(UActionList) do
        begin
          if UActionList[j].dwActID=ptr^.id then
          begin
            idx:=j;
            break;
          end;
        end;
        // if we have no item in list for this action - then add new one
        if idx<0 then
        begin
          idx:=AddUAction(-1,ptr);
        end
        else
        begin
          if (wParam and ACTM_RENAME)<>0 then
          begin
            // check for time economy - no need to change ALL items
            if StrCmpW(UActionList[idx].szActDescr,ptr^.descr)<>0 then
            begin
              mFreeMem(UActionList[idx].szActDescr);
              StrDupW (UActionList[idx].szActDescr,ptr^.descr);
            end;
          end;
        end;
//      not so necessary to check really
//        if (wParam and (ACTM_SORT or ACTM_DELETE or ACTM_NEW))<>0 then
        UActionList[idx].wSortIndex:=i;

        inc(ptr);
      end;
  end
  else
    ptr1:=nil;

  // now search deleted items
  if (wParam and ACTM_DELETE)<>0 then
  begin
    for j:=HIGH(UActionList) downto 0 do
    begin
      bFound:=false;
      if count>0 then
      begin
        ptr:=ptr1;
        inc(pbyte(ptr),4);
        for i:=0 to count-1 do
        begin
          if UActionList[j].dwActID=ptr^.id then
          begin
            bFound:=true;
            break;
          end;
          inc(ptr);
        end;
      end;
      if not bFound then
        DeleteUAction(j,true);
    end;
  end;

  if count>0 then
    CallService(MS_ACT_FREELIST,0,TLPARAM(ptr1));

  // show changes in dialog
  if settings<>0 then
  begin
    FillActionList(settings);
    ShowAction(settings,-1);
  end;

  SaveUAs;
  FillChar(arMenuRec[0],Length(arMenuRec)*SizeOf(tuaMenuRecA),0);
  for i:=0 to HIGH(UActionList) do
  begin
    SetAllActionUsers(UActionList[i],false);
  end;
end;