@@ -54,33 +54,39 @@ interface
54
54
evCategoryChanged // a category's properties have changed
55
55
);
56
56
57
- {
58
- IDBDataProvider:
59
- Interface supported by objects that provides data about the categories and
60
- snippets in the database.
61
- }
57
+ // / <summary>Interface supported by objects that provide information about
58
+ // / categories and snippets.</summary>
62
59
IDBDataProvider = interface (IInterface)
63
60
[' {D2D57A0D-DB29-4012-891E-E817E0EED8C8}' ]
61
+
62
+ // / <summary>Retrieves all the properties of a category.</summary>
63
+ // / <param name="Cat"><c>Category</c> [in] Category for which properties
64
+ // / are requested.</param>
65
+ // / <returns><c>TCategoryData</c>. Record containing the property data.
66
+ // / </returns>
64
67
function GetCategoryProps (const Cat: TCategory): TCategoryData;
65
- { Retrieves all the properties of a category.
66
- @param Cat [in] Category for which data is requested.
67
- @return Record containing property data.
68
- }
68
+
69
+ // / <summary>Retrieves names of all snippets that belong to a category.
70
+ // / </summary>
71
+ // / <param name="Cat"><c>Category</c> [in] Category for which snippet names
72
+ // / are requested.</param>
73
+ // / <returns><c>IStringList</c>. List of snippet names.</returns>
69
74
function GetCategorySnippets (const Cat: TCategory): IStringList;
70
- { Retrieves names of all snippets that belong to a category.
71
- @param Cat [in] Category for which snippet names are requested.
72
- @return Required list of snippet names.
73
- }
75
+
76
+ // / <summary>Retrieves all the properties of a snippet.</summary>
77
+ // / <param name="Snippet"><c>TSnippet</c> [in] Snippet for which properties
78
+ // / are requested.</param>
79
+ // / <returns><c>TSnippetData</c>. Record containing the property data.
80
+ // / </returns>
74
81
function GetSnippetProps (const Snippet: TSnippet): TSnippetData;
75
- { Retrieves all the properties of a snippet.
76
- @param Snippet [in] Snippet for which data is requested.
77
- @return Record containing property data.
78
- }
82
+
83
+ // / <summary>Retrieves information about all the references of a snippet.
84
+ // / </summary>
85
+ // / <param name="Snippet"><c>TSnippet</c> [in] Snippet for which references
86
+ // / are requested.</param>
87
+ // / <returns><c>TSnippetReferences</c>. Record containing references.
88
+ // / </returns>
79
89
function GetSnippetRefs (const Snippet: TSnippet): TSnippetReferences;
80
- { Retrieves information about all the references of a snippet.
81
- @param Snippet [in] Snippet for which information is requested.
82
- @return Record containing references.
83
- }
84
90
end ;
85
91
86
92
{
@@ -106,11 +112,8 @@ interface
106
112
depends on Kind. May be nil}
107
113
end ;
108
114
109
- {
110
- IDataItemFactory:
111
- Interface to factory object that creates snippet and category objects. For
112
- use by database loader objects.
113
- }
115
+ // / <summary>Interface to factory object that creates snippet and category
116
+ // / objects use by collection loader objects.</summary>
114
117
IDBDataItemFactory = interface (IInterface)
115
118
[' {C6DD85BD-E649-4A90-961C-4011D2714B3E}' ]
116
119
@@ -301,12 +304,10 @@ implementation
301
304
302
305
type
303
306
304
- {
305
- TDBDataItemFactory:
306
- Class that can create category and snippet objects.
307
- }
307
+ // / <summary>Class that can create category and snippet objects.</summary>.
308
308
TDBDataItemFactory = class (TInterfacedObject, IDBDataItemFactory)
309
309
public
310
+
310
311
// / <summary>Creates a new category object.</summary>
311
312
// / <param name="CatID"><c>string</c> [in] ID of new category. Must be
312
313
// / unique.</param>
@@ -540,44 +541,59 @@ TEventInfo = class(TInterfacedObject, IDatabaseChangeEventInfo)
540
541
}
541
542
end ;
542
543
543
- {
544
- TUserDataProvider:
545
- Class that provides data about the categories and snippets in the user-
546
- defined database.
547
- }
548
- TUserDataProvider = class (TInterfacedObject, IDBDataProvider)
544
+ // / <summary>Class that provides data about the categories and snippets in
545
+ // / a given collection.</summary>
546
+ TCollectionDataProvider = class (TInterfacedObject, IDBDataProvider)
549
547
strict private
550
- fSnippets: TSnippetList; // All snippets in the whole database
551
- fCategories: TCategoryList; // All categories in the whole database
548
+ var
549
+ fCollectionID: TCollectionID; // Collection on which to operate
550
+ fSnippets: TSnippetList; // All snippets in the whole database
551
+ fCategories: TCategoryList; // All categories in the whole database
552
552
public
553
- constructor Create(const SnipList: TSnippetList;
553
+ // / <summary>Object constructor. Sets up data provider.</summary>
554
+ // / <param name="ACollectionID"><c>TCollectionID</c> [in] Collection for
555
+ // / which to provide data.</param>
556
+ // / <param name="SnipList"><c>TSnippetList</c> [in] List of all snippets
557
+ // / in the database.</param>
558
+ // / <param name="Categories"><c>TCategoryList</c> [in] List of all
559
+ // / categories in the database.</param>
560
+ constructor Create(const ACollectionID: TCollectionID;
561
+ const SnipList: TSnippetList;
554
562
const Categories: TCategoryList);
555
- { Constructor. Records list of all snippets and categories in both
556
- databases.
557
- @param SnipList [in] List of all snippets in whole database.
558
- @param Categories [in] List of all categories in whole database.
559
- }
560
- { IDBDataProvider methods }
563
+
564
+ // / <summary>Retrieves all the properties of a category.</summary>
565
+ // / <param name="Cat"><c>Category</c> [in] Category for which properties
566
+ // / are requested.</param>
567
+ // / <returns><c>TCategoryData</c>. Record containing the property data.
568
+ // / </returns>
569
+ // / <remarks>Method of <c>IDBDataProvider</c></remarks>
561
570
function GetCategoryProps (const Cat: TCategory): TCategoryData;
562
- { Retrieves all the properties of a category.
563
- @param Cat [in] Category for which data is requested.
564
- @return Record containing property data.
565
- }
571
+
572
+ // / <summary>Retrieves names of all snippets from the collection that
573
+ // / belong to a category.</summary>
574
+ // / <param name="Cat"><c>Category</c> [in] Category for which snippet names
575
+ // / are requested.</param>
576
+ // / <returns><c>IStringList</c>. List of snippet names.</returns>
577
+ // / <remarks>Method of <c>IDBDataProvider</c></remarks>
566
578
function GetCategorySnippets (const Cat: TCategory): IStringList;
567
- { Retrieves names of all user-defined snippets that belong to a category.
568
- @param Cat [in] Category for which snippet names are requested.
569
- @return Required list of snippet names.
570
- }
579
+
580
+ // / <summary>Retrieves all the properties of a snippet.</summary>
581
+ // / <param name="Snippet"><c>TSnippet</c> [in] Snippet for which properties
582
+ // / are requested.</param>
583
+ // / <returns><c>TSnippetData</c>. Record containing the property data.
584
+ // / </returns>
585
+ // / <remarks>Method of <c>IDBDataProvider</c></remarks>
571
586
function GetSnippetProps (const Snippet: TSnippet): TSnippetData;
572
- { Retrieves all the properties of a snippet.
573
- @param Snippet [in] Snippet for which data is requested.
574
- @return Record containing property data.
575
- }
587
+
588
+ // / <summary>Retrieves information about all the references of a snippet.
589
+ // / </summary>
590
+ // / <param name="Snippet"><c>TSnippet</c> [in] Snippet for which references
591
+ // / are requested.</param>
592
+ // / <returns><c>TSnippetReferences</c>. Record containing references.
593
+ // / </returns>
594
+ // / <remarks>Method of <c>IDBDataProvider</c></remarks>
576
595
function GetSnippetRefs (const Snippet: TSnippet): TSnippetReferences;
577
- { Retrieves information about all the references of a snippet.
578
- @param Snippet [in] Snippet for which information is requested.
579
- @return Record containing references.
580
- }
596
+
581
597
end ;
582
598
583
599
function Database : IDatabase;
@@ -1030,15 +1046,12 @@ procedure TDatabase.Save;
1030
1046
{ Saves user defined snippets and all categories to user database.
1031
1047
}
1032
1048
var
1033
- Provider : IDBDataProvider; // object that supplies info to writer
1049
+ MainProvider, UserProvider : IDBDataProvider; // object that supplies info to writer
1034
1050
MainCollectionIdx, UserCollectionIdx: Integer;
1035
1051
Saver: IDataFormatSaver;
1036
1052
Collections: TCollections;
1037
1053
Collection: TCollection;
1038
1054
begin
1039
- // Create object that can provide required information about user database
1040
- Provider := TUserDataProvider.Create(fSnippets, fCategories);
1041
-
1042
1055
Collections := TCollections.Instance;
1043
1056
1044
1057
{ TODO: -cVault: The following code is a kludge to maintain compatibility with
@@ -1055,9 +1068,12 @@ procedure TDatabase.Save;
1055
1068
if MainCollectionIdx >= 0 then
1056
1069
begin
1057
1070
Collection := Collections[MainCollectionIdx];
1071
+ MainProvider := TCollectionDataProvider.Create(
1072
+ TCollectionID.__TMP__MainDBCollectionID, fSnippets, fCategories
1073
+ );
1058
1074
Saver := TDatabaseIOFactory.CreateDBSaver(Collection);
1059
1075
if Assigned(Saver) then
1060
- Saver.Save(fSnippets, fCategories, Provider );
1076
+ Saver.Save(fSnippets, fCategories, MainProvider );
1061
1077
end ;
1062
1078
1063
1079
UserCollectionIdx := TCollections.Instance.IndexOfID(
@@ -1066,9 +1082,12 @@ procedure TDatabase.Save;
1066
1082
if UserCollectionIdx >= 0 then
1067
1083
begin
1068
1084
Collection := Collections[UserCollectionIdx];
1085
+ UserProvider := TCollectionDataProvider.Create(
1086
+ TCollectionID.__TMP__UserDBCollectionID, fSnippets, fCategories
1087
+ );
1069
1088
Saver := TDatabaseIOFactory.CreateDBSaver(Collection);
1070
1089
if Assigned(Saver) then
1071
- Saver.Save(fSnippets, fCategories, Provider );
1090
+ Saver.Save(fSnippets, fCategories, UserProvider );
1072
1091
end ;
1073
1092
1074
1093
fUpdated := False;
@@ -1243,65 +1262,47 @@ function TDBDataItemFactory.CreateSnippet(const Name: string;
1243
1262
Result := TSnippetEx.Create(Name , ACollectionID, Props);
1244
1263
end ;
1245
1264
1246
- { TUserDataProvider }
1265
+ { TCollectionDataProvider }
1247
1266
1248
- constructor TUserDataProvider.Create(const SnipList: TSnippetList;
1249
- const Categories: TCategoryList);
1250
- { Constructor. Records list of all snippets and categories in both databases.
1251
- @param SnipList [in] List of all snippets in whole database.
1252
- @param Categories [in] List of all categories in whole database.
1253
- }
1267
+ constructor TCollectionDataProvider.Create(const ACollectionID: TCollectionID;
1268
+ const SnipList: TSnippetList; const Categories: TCategoryList);
1254
1269
begin
1255
1270
inherited Create;
1271
+ fCollectionID := ACollectionID;
1256
1272
fSnippets := SnipList;
1257
1273
fCategories := Categories;
1258
1274
end ;
1259
1275
1260
- function TUserDataProvider .GetCategoryProps (
1276
+ function TCollectionDataProvider .GetCategoryProps (
1261
1277
const Cat: TCategory): TCategoryData;
1262
- { Retrieves all the properties of a category.
1263
- @param Cat [in] Category for which data is requested.
1264
- @return Record containing property data.
1265
- }
1266
1278
begin
1267
1279
Result.Desc := Cat.Description;
1268
1280
end ;
1269
1281
1270
- function TUserDataProvider .GetCategorySnippets (
1282
+ function TCollectionDataProvider .GetCategorySnippets (
1271
1283
const Cat: TCategory): IStringList;
1272
- { Retrieves names of all user-defined snippets that belong to a category.
1273
- @param Cat [in] Category for which snippet names are requested.
1274
- @return Required list of snippet names.
1275
- }
1276
1284
var
1277
1285
Snippet: TSnippet; // references each snippet in category
1278
1286
begin
1279
1287
Result := TIStringList.Create;
1280
1288
for Snippet in Cat.Snippets do
1281
- if Snippet.CollectionID <> TCollectionID.__TMP__MainDBCollectionID then
1289
+ if Snippet.CollectionID = fCollectionID then
1282
1290
Result.Add(Snippet.Name );
1283
1291
end ;
1284
1292
1285
- function TUserDataProvider .GetSnippetProps (
1293
+ function TCollectionDataProvider .GetSnippetProps (
1286
1294
const Snippet: TSnippet): TSnippetData;
1287
- { Retrieves all the properties of a snippet.
1288
- @param Snippet [in] Snippet for which data is requested.
1289
- @return Record containing property data.
1290
- }
1291
1295
begin
1292
1296
Result := (Snippet as TSnippetEx).GetProps;
1293
1297
end ;
1294
1298
1295
- function TUserDataProvider .GetSnippetRefs (
1299
+ function TCollectionDataProvider .GetSnippetRefs (
1296
1300
const Snippet: TSnippet): TSnippetReferences;
1297
- { Retrieves information about all the references of a snippet.
1298
- @param Snippet [in] Snippet for which information is requested.
1299
- @return Record containing references.
1300
- }
1301
1301
begin
1302
1302
Result := (Snippet as TSnippetEx).GetReferences;
1303
1303
end ;
1304
1304
1305
+
1305
1306
initialization
1306
1307
1307
1308
0 commit comments