Menu

Commit [r4275]  Maximize  Restore  History

Added new TDatabase.Save method that saves database using new native file format.

Removed old Save method from IDatabaseEdit and _TDatabase.
Changed affected code to use TDatabase.Save instead of IDatabaseEdit.Save.

delphidabbler 2013-12-12

changed /branches/parsnip/Src/DB.UMain.pas
changed /branches/parsnip/Src/FmMain.pas
changed /branches/parsnip/Src/UUserDBMgr.pas
/branches/parsnip/Src/DB.UMain.pas Diff Switch to side-by-side view
--- a/branches/parsnip/Src/DB.UMain.pas
+++ b/branches/parsnip/Src/DB.UMain.pas
@@ -63,6 +63,7 @@
     class property Instance: TDatabase read GetInstance;
   public
     procedure Load;
+    procedure Save;
     function IsDirty: Boolean;
     function LookupEditableSnippet(const ASnippetID: TSnippetID):
       IEditableSnippet;
@@ -254,9 +255,6 @@
     procedure DeleteSnippet(const Snippet: TSnippet);
       {Deletes a snippet from the user database.
         @param Snippet [in] Snippet to be deleted.
-      }
-    procedure Save;
-      {Saves user database.
       }
   end;
 
@@ -460,9 +458,6 @@
       {Deletes a snippet from the user database.
         @param Snippet [in] Snippet to be deleted.
       }
-    procedure Save;
-      {Saves user defined snippets and all categories to user database.
-      }
   end;
 
   {
@@ -754,29 +749,6 @@
   fChangeEvents.RemoveHandler(Handler);
 end;
 
-procedure _TDatabase.Save;
-  {Saves user defined snippets and all categories to user database.
-  }
-var
-  Provider: IDBDataProvider;  // object that supplies info to writer
-  SnipList: _TSnippetList;
-  Snippet: TSnippet;
-begin
-  // Create object that can provide required information about user database
-  Provider := TUserDataProvider.Create;
-  SnipList := _TSnippetList.Create(False);
-  try
-    for Snippet in Database.__SnippetsTable do
-      SnipList.Add(Snippet);
-    // Use a writer object to write out the database
-    with TDatabaseIOFactory.CreateWriter do
-      Write(SnipList, fCategories, Provider);
-  finally
-    SnipList.Free;
-  end;
-  Database.__Updated := False;
-end;
-
 procedure _TDatabase.TriggerEvent(const Kind: TDatabaseChangeEventKind;
   const Info: TObject);
   {Triggers a change event. Notifies all registered listeners.
@@ -1033,6 +1005,15 @@
   Result := Row.CloneAsReadOnly;
 end;
 
+procedure TDatabase.Save;
+var
+  Writer: IDatabaseWriter;
+begin
+  Writer := TDatabaseIOFactory.CreateWriter;
+  Writer.Save(fSnippetsTable, fAllTags, fLastModified);
+  fDirty := False;
+end;
+
 function TDatabase.SelectSnippets(FilterFn: TDBFilterFn): ISnippetIDList;
 var
   Snippet: TDBSnippet;
/branches/parsnip/Src/FmMain.pas Diff Switch to side-by-side view
--- a/branches/parsnip/Src/FmMain.pas
+++ b/branches/parsnip/Src/FmMain.pas
@@ -1362,7 +1362,7 @@
 
   // Save any changes to user database
   if Database.IsDirty then
-    (_Database as IDatabaseEdit).Save;
+    Database.Save;
 
   // Unhook snippets event handler
   _Database.RemoveChangeEventHandler(DBChangeHandler);
/branches/parsnip/Src/UUserDBMgr.pas Diff Switch to side-by-side view
Loading...
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.