File: VirtualShellAutoComplete.pas

package info (click to toggle)
mysql-query-browser 1.1.6-1sarge0
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 36,320 kB
  • ctags: 24,680
  • sloc: pascal: 203,479; xml: 136,561; ansic: 47,502; cpp: 28,926; sh: 12,433; objc: 4,823; java: 1,849; php: 1,485; python: 1,225; sql: 1,128; makefile: 872
file content (284 lines) | stat: -rw-r--r-- 9,020 bytes parent folder | download
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
unit VirtualShellAutoComplete;

// Version 1.1.17
//   The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.mozilla.org/MPL/
//
//   Software distributed under the License is distributed on an
// " AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or
// implied. See the License for the specific language governing rights
// and limitations under the License.
//
//
//   Alternatively, the contents of this file may be used under
// the terms of the GNU General Public License Version 2 or later
// (the "GPL"), in which case the provisions of the GPL are applicable
// instead of those above. If you wish to allow use of your version of
// this file only under the terms of the GPL and not to allow others to
// use your version of this file under the MPL, indicate your decision
// by deleting the provisions above and replace them with the notice and
// other provisions required by the GPL. If you do not delete the provisions
// above, a recipient may use your version of this file under either the
// MPL or the GPL.
//
// The initial developer of this code is Jim Kueneman <jimdk@mindspring.com>
//
//----------------------------------------------------------------------------

interface

{$include ..\Include\Compilers.inc}
{$include ..\Include\VSToolsAddIns.inc}

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  ImgList, ShlObj, ShellAPI, ActiveX, ComObj, VirtualShellTypes,
  VirtualWideStrings, VirtualShellUtilities, VirtualShellContainers;

type
  TAutoCompleteContent = (
    accCurrentDir,            // Include the current directory contents
    accMyComputer,            // Include any objects under MyComputer (drives, control panel etc)
    accDesktop,               // Include objects that are on the desktop
    accFavorites,             // Include the Favorites folder
    accFileSysOnly,           // Only Physical files are added to the list; no virtual objects
    accFileSysDirs,           // Include physical file directories in the search
    accFileSysFiles,          // Include physical files in the search
    accHidden,                // Include Hidden objects
    accRecursive,             // Recurse into sub folders (only valid if accFileSysDirs is enabled)
    accSortList               // Sorts the list
  );
  TAutoCompleteContents = set of TAutoCompleteContent;

const
  AutoCompleteDefault =  [accCurrentDir, accMyComputer, accFileSysDirs, accFileSysFiles];

type
  TVirtualAutoCompleteAddItem = procedure(Sender: TObject; AutoCompleteItem: TNamespace; var Allow: Boolean;
    var Terminate: Boolean) of object;

type
  TCustomVirtualShellAutoComplete = class(TComponent)
  private
    FCurrentDir: WideString;
    FStringsW: TWideStringList;
    FStrings: TStringList;
    FContents: TAutoCompleteContents;
    FOnAutoCompleteAddItem: TVirtualAutoCompleteAddItem;
    FNamespaces: TVirtualNameSpaceList;
    FDirty: Boolean;
    function GetStrings: TStringList;
    function GetStringsW: TWideStringList;

    procedure ReadCurrentDir(Reader: TReader);
    procedure WriteCurrentDir(Writer: TWriter);
    procedure SetCurrentDir(const Value: WideString);

  protected
    function EnumFolder(APIDL: PItemIDList; AParent: TNamespace; Data: Pointer; var Terminate: Boolean): Boolean;
    procedure FillCurrentDir;
    procedure FillMyComputer;
    procedure FillDesktop;
    procedure FillFavorites;
    procedure DefineProperties(Filer: TFiler); override;
    procedure DoAddAutoCompleteItem(AutoCompleteItem: TNamespace; var Allow: Boolean; var Terminate: Boolean);

    property Contents: TAutoCompleteContents read FContents write FContents
      default AutoCompleteDefault;
    property CurrentDir: WideString read FCurrentDir write SetCurrentDir;
    property OnAutoCompleteAddItem: TVirtualAutoCompleteAddItem read FOnAutoCompleteAddItem write FOnAutoCompleteAddItem;
    property Namespaces: TVirtualNameSpaceList read FNamespaces write FNamespaces;
    property Strings: TStringList read GetStrings;
    property StringsW: TWideStringList read GetStringsW;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure Refresh;

    property Dirty: Boolean read FDirty write FDirty;
  end;

  TVirtualShellAutoComplete = class(TCustomVirtualShellAutoComplete)
  public
    property Namespaces;
    property Strings;
    property StringsW;
  published
    property Contents;
    property CurrentDir;
    property OnAutoCompleteAddItem;
  end;

implementation

{ TVirtualShellAutoComplete }

constructor TCustomVirtualShellAutoComplete.Create(AOwner: TComponent);
begin
  inherited;
  FStrings := TStringList.Create;
  FStringsW := TWideStringList.Create;
  Contents := AutoCompleteDefault;
  Namespaces := TVirtualNameSpaceList.Create(True);
end;

procedure TCustomVirtualShellAutoComplete.DefineProperties(Filer: TFiler);
begin
  Filer.DefineProperty('CurrentDir', ReadCurrentDir, WriteCurrentDir, True);
  inherited;    
end;

destructor TCustomVirtualShellAutoComplete.Destroy;
begin
  FStrings.Free;
  FStringsW.Free;
  Namespaces.Free;
  inherited;  
end;

procedure TCustomVirtualShellAutoComplete.DoAddAutoCompleteItem(
  AutoCompleteItem: TNamespace; var Allow: Boolean; var Terminate: Boolean);
begin
  Allow := True;
  if Assigned(OnAutoCompleteAddItem) then
    OnAutoCompleteAddItem(Self, AutoCompleteItem, Allow, Terminate);
end;

function TCustomVirtualShellAutoComplete.EnumFolder(APIDL: PItemIDList;
  AParent: TNamespace; Data: Pointer; var Terminate: Boolean): Boolean;
var
  NS: TNamespace;
  DoAdd: Boolean;
  Allow: Boolean;
begin
  NS := TNamespace.Create(PIDLMgr.AppendPIDL(AParent.AbsolutePIDL, APIDL), nil);
  DoAdd := True;

  if NS.Hidden and not(accHidden in FContents) then
    DoAdd := False;
  if not NS.FileSystem and (accFileSysOnly in FContents) then
    DoAdd := False;

  if DoAdd then
  begin
    if (accRecursive in FContents) and NS.Folder then
    begin
      NS.EnumerateFolder(accFileSysDirs in FContents, accFileSysFiles in FContents,
        accHidden in FContents, EnumFolder, Data);
    end;
    DoAddAutoCompleteItem(NS, Allow, Terminate);
    if Allow then
      Namespaces.Add(NS)
    else
      NS.Free
  end;
  Result := True;
end;

procedure TCustomVirtualShellAutoComplete.FillCurrentDir;
var
  NS: TNamespace;
begin
  if (accCurrentDir in FContents) and DirExistsW(FCurrentDir) then
  begin
    try
      NS := TNamespace.CreateFromFileName(FCurrentDir);
      if Assigned(NS) then
      begin
        NS.EnumerateFolder(accFileSysDirs in FContents, accFileSysFiles in FContents,
          accHidden in FContents, EnumFolder, nil);
        NS.Free
      end
    except
    end
  end
end;

procedure TCustomVirtualShellAutoComplete.FillDesktop;
begin
  if (accDesktop in FContents) and Assigned(DesktopFolder) then
    DesktopFolder.EnumerateFolder(accFileSysDirs in FContents, accFileSysFiles in FContents,
      accHidden in FContents, EnumFolder, nil);
end;

procedure TCustomVirtualShellAutoComplete.FillFavorites;
begin
  if (accFavorites in FContents) and Assigned(FavoritesFolder) then
    FavoritesFolder.EnumerateFolder(accFileSysDirs in FContents, accFileSysFiles in FContents,
      accHidden in FContents, EnumFolder, nil);
end;

procedure TCustomVirtualShellAutoComplete.FillMyComputer;
begin
  if (accMyComputer in FContents) and Assigned(DrivesFolder) then
    DrivesFolder.EnumerateFolder(accFileSysDirs in FContents, accFileSysFiles in FContents,
      accHidden in FContents, EnumFolder, nil);
end;

function TCustomVirtualShellAutoComplete.GetStrings: TStringList;
var
  i: integer;
begin
  FStrings.Clear;
  for i := 0 to Namespaces.Count - 1 do
    FStrings.Add(Namespaces[i].NameParseAddress);
  if accSortList in FContents then
    FStrings.Sort;
  Result := FStrings
end;

function TCustomVirtualShellAutoComplete.GetStringsW: TWideStringList;
 var
  i: integer;
begin
  FStringsW.Clear;
  for i := 0 to Namespaces.Count - 1 do
    FStringsW.Add(Namespaces[i].NameParseAddress);
  if accSortList in FContents then
    FStringsW.Sort;
  Result := FStringsW
end;

procedure TCustomVirtualShellAutoComplete.ReadCurrentDir(Reader: TReader);
begin
  case Reader.NextValue of
    vaLString, vaString:
      FCurrentDir := Reader.ReadString;
  else
    FCurrentDir := Reader.ReadWideString;
  end;
end;

procedure TCustomVirtualShellAutoComplete.Refresh;
begin
  if Dirty then
  begin
    Namespaces.Clear;
    FillCurrentDir;
    FillDesktop;
    FillFavorites;
    FillMyComputer;
  end
end;

procedure TCustomVirtualShellAutoComplete.SetCurrentDir(
  const Value: WideString);
begin
  if (Value <> FCurrentDir) and DirExistsW(Value) then
  begin
    Dirty := True;
    FCurrentDir := Value;
  end
end;

procedure TCustomVirtualShellAutoComplete.WriteCurrentDir(Writer: TWriter);
begin
  Writer.WriteWideString(FCurrentDir);
end;

end.