Skip to content

Commit

Permalink
bugfix where note created from template might fail
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbannon committed Aug 19, 2024
1 parent 9d6e91b commit 7068938
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
4 changes: 2 additions & 2 deletions source/Tomboy_NG.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@
</PublishOptions>
<RunParams>
<local>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-lots"/>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-small"/>
</local>
<environment>
<UserOverrides Count="2">
Expand All @@ -1079,7 +1079,7 @@
<Modes Count="1">
<Mode0 Name="default">
<local>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-lots"/>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-small"/>
</local>
<environment>
<UserOverrides Count="2">
Expand Down
31 changes: 15 additions & 16 deletions source/note_lister.pas
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ TNoteLister = class
{ Returns a simple note file name, accepts simple filename or ID }
function CleanFileName(const FileOrID: AnsiString): ANSIString;


//procedure GetNoteDetails(const Dir, FileName: ANSIString; {const TermList: TStringList;} DontTestName: boolean=false);

// Indexes one note. Always multithread mode but sometimes its only one thread.
// Does require CriticalSection to be setup before calling.
// If note turns out to be a template, don't add it to main note list
Expand Down Expand Up @@ -347,7 +344,7 @@ TNoteLister = class
{ Returns the LastChangeDate string for ID in the Notes list, empty string
if not found (empty string is its a notebook) }
function GetLastChangeDate(const ID: String): string;
{ Adds details of note of passed to NoteList }
{ Adds details of odd note to NoteList, does NOT update Indexes. }
procedure IndexThisNote(const ID : String);
{ Returns T is ID in current list, takes 36 char GUID or simple file name }
function IsIDPresent(ID : string) : boolean;
Expand Down Expand Up @@ -406,7 +403,8 @@ TNoteLister = class
we may update Indexes, return false if nothing needs to be done, if True
we will refresh displayed list or, if ReRunSearch is true, we'll re-run the
current search, thus updating Search Indexes. We always update DateAllIndex.}
function AlterOrAddNote(out ReRunSearch: boolean; const FFName, LCD, Title: string): boolean;
function AlterOrAddNote(out ReRunSearch : boolean; const FFName, LCD,
Title : string) : boolean;


// New Search methods
Expand Down Expand Up @@ -1273,7 +1271,7 @@ procedure TNoteLister.GetNoteDetails(const Dir, FileName: ANSIString; DontTestNa
end else
break;
until false; }
if DontTestName or (not Sett.AutoSearchUpdate) then NoteP^.Content := '' // silly to record content for, eg, help notes.
if DontTestName or (not Sett.AutoSearchUpdate) then NoteP^.Content := '' // silly to record content for, eg, help notes.
else begin
NoteP^.Content := '';
Node := Doc.DocumentElement.FindNode('text');
Expand Down Expand Up @@ -1407,6 +1405,7 @@ procedure TNoteLister.IndexThisNote(const ID: String);
//debugln('TNoteLister.IndexThisNote');
InitCriticalSection(CriticalSection); // could be done in background thread but rarely called
GetNoteDetails(WorkingDir, CleanFileName(ID), false, self); // while single call, must setup critical
// this should trigger a regeneration of Index Lists, otherwise,
DoneCriticalSection(CriticalSection);
//DebugMode := False;
end;
Expand Down Expand Up @@ -1874,7 +1873,9 @@ function TNoteLister.GetNote(Index: integer; mode: TLVSortMode): PNote;
smRecentUp : result := NoteList[DateSearchIndex[DateSearchIndex.Count - Index -1]];
smAATitleUp : result := NoteList[TitleSearchIndex[Index]];
smAATitleDown : result := NoteList[TitleSearchIndex[TitleSearchIndex.Count - Index -1]];
smAllRecentUp : result := NoteList[DateAllIndex[DateAllIndex.Count - Index -1]];
smAllRecentUp :
result := NoteList[DateAllIndex[DateAllIndex.Count - Index -1]];

end;
end;

Expand Down Expand Up @@ -2060,8 +2061,11 @@ procedure TNoteLister.LoadStrings(const TheStrings: TStrings);
We pass an Out Var, that will be false if the something is just update display
and True if its a full rerun of search. ReRunSearch : boolean.
This function first looks for the note ID in NoteList, if its there, update LCD
and then look to see if its in Title has changed. If it has, rebuild DateAllIndex
This function first looks for the note ID in NoteList, if its there, and
JustIndex is true, its probably a note just added by IndexThisNote(), has
and appropriate entry in NoteList so just needs DateAllIndex updated.
If JustIndex is false we should update LCD and then look
to see if its in Title has changed. If it has, rebuild DateAllIndex
and return True. SearchUnit will trigger a repeat search.
If its just a LCD job, we look to see if its mentioned in DateSearchIndex, if
Expand All @@ -2078,7 +2082,7 @@ procedure TNoteLister.LoadStrings(const TheStrings: TStrings);
New Note T T Add to NoteList (still might not be displayed but too hard to tell)
}

// Note that FFname is always needed, LCD and Title note needed if JustIndex is true
function TNoteLister.AlterOrAddNote(out ReRunSearch : boolean; const FFName, LCD, Title : string) : boolean;
var
ID : string;
Expand Down Expand Up @@ -2122,11 +2126,6 @@ function TNoteLister.AlterOrAddNote(out ReRunSearch : boolean; const FFName, LCD
if ID = NoteList.Items[i]^.ID then break; // Found it
inc(i);
end;

(* while ID <> NoteList.Items[i]^.ID do begin // ToDo : can this cannot handle empty list?
inc(i);
end; *)

if i = NoteList.count then begin // Drop through, must be a new note.
AddNote(ID, Title, LCD); // Add to NoteList
DateAllIndex.Add(NoteList.Count -1); // Added at the end of DateAllIndex, most recent.
Expand All @@ -2140,8 +2139,8 @@ function TNoteLister.AlterOrAddNote(out ReRunSearch : boolean; const FFName, LCD
NoteList.Items[i]^.Title := Title;
NoteList.Items[i]^.TitleLow := lowercase(Title);
end;
UpdateIndex(DateAllIndex); // Always update DateAllIndex, its not done by Search methods
end;
UpdateIndex(DateAllIndex); // Always update DateAllIndex, its not done by Search methods
end;

function TNoteLister.AlterNote(ID, Change: ANSIString; Title: ANSIString): boolean;
Expand Down
21 changes: 14 additions & 7 deletions source/searchunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ TSearchForm = class(TForm)
procedure FileMenuClicked(Sender: TObject);

procedure InitialiseHelpFiles();
// Copy Template to a new name removing the <tag>system:template</tag> and setting a Title
function MakeNoteFromTemplate(const Template: String): string;

// clears then Inserts file items in all main menus, note also removes help items ....
Expand Down Expand Up @@ -1669,22 +1670,24 @@ procedure TSearchForm.ListViewNotesMouseDown(Sender: TObject;
MenuItemNoteBookMembership.Enabled := Val[2];
MenuItemSelectAll.Enabled := Val[3];
MenuItemSelectNone.Enabled := Val[4];
{$ifdef LCLGTK2} // GTK2 resets a select all when you release the mouse.
MenuItemSelectAll.Visible := false;
MenuItemSelectNone.Visible := false;
{$endif}
end;

begin
if Button = mbRight then begin
NoteListRightClickSel := []; // clear it
for Itm in ListViewNotes.Items do begin
if Itm.Selected then begin
//debugln('ListViewNotesMouseDown Selected ' + Itm.Caption {+ ' ' + Itm.SubItems[1]});
insert({Sett.NoteDirectory +} Itm.SubItems[1], NoteListRightClickSel, 0); // save the selected ID.note
insert(Itm.SubItems[1], NoteListRightClickSel, 0); // save the selected ID.note
end;
end;
if ListViewNotes.SelCount = 0 then Val := [false, false, false, true, false]
else if ListViewNotes.SelCount = 1 then Val := [true, true, true, true, true]
else Val := [true, true, false, true, true]; // more than one selected
SetupRightClickMenu;
// debugln('We have selected = ' + inttostr(ListViewNotes.SelCount));
PopupMenuListOptions.PopUp;
end;
end;
Expand Down Expand Up @@ -1757,7 +1760,7 @@ procedure TSearchForm.ScaleListView();
Col1Width : integer;
begin
{$ifdef LCLQT5 }
Col1width := listviewnotes.Canvas.Font.GetTextWidth('2020-06-02 12:30:00000'); // 00 allow for apparent error in scroll with
Col1width := listviewnotes.Canvas.Font.GetTextWidth('2020-06-02 12:30:00000'); // 00 allow for apparent error in scroll width
{$else}
Col1width := listviewnotes.Canvas.Font.GetTextWidth('2020-06-02 12:30:000');
{$endif}
Expand Down Expand Up @@ -2033,12 +2036,11 @@ procedure TSearchForm.MenuNewNoteFromTemplateClick(Sender: TObject);
'', '');
end;

// Copy Template to a new name removing the <tag>system:template</tag> and setting a Title

function TSearchForm.MakeNoteFromTemplate(const Template : String) : string;
var
InFile, OutFile: TextFile;
InString : String;
//Start, Finish : integer;
GUID : TGUID;
RandBit, NewGUID : string;
begin
Expand Down Expand Up @@ -2069,8 +2071,13 @@ function TSearchForm.MakeNoteFromTemplate(const Template : String) : string;
CloseFile(OutFile);
CloseFile(InFile);
end;
TheMainNoteLister.IndexThisNote(NewGUID);
TheMainNoteLister.IndexThisNote(NewGUID); // AAAAAH this does not refresh the indexes, particularly 'All'
result := GetTitleFromFFN(Sett.NoteDirectory + NewGUID + '.note', false);
IndexAndRefresh(); // Reruns the current search with new data in NoteList
TheMainNoteLister.BuildDateAllIndex(); // Must rebuild it before refreshing menus.
RefreshMenus(mkRecentMenu);
MainForm.UpdateNotesFound(TheMainNoteLister.NoteList.Count);

except
on E: EInOutError do begin
debugln('File handling error occurred making new note from template. Details: ' + E.Message);
Expand Down
20 changes: 10 additions & 10 deletions source/syncgui.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object FormSync: TFormSync
Left = 825
Left = 389
Height = 418
Top = 260
Top = 299
Width = 699
Caption = 'Sync'
ClientHeight = 418
Expand All @@ -10,7 +10,7 @@ object FormSync: TFormSync
OnCreate = FormCreate
OnHide = FormHide
OnShow = FormShow
LCLVersion = '3.0.0.3'
LCLVersion = '3.4.0.0'
object Panel1: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Expand All @@ -37,19 +37,19 @@ object FormSync: TFormSync
end
object Label2: TLabel
Left = 35
Height = 19
Height = 20
Top = 56
Width = 43
Width = 45
Caption = 'Label2'
end
object LabelProgress: TLabel
AnchorSideTop.Control = Label1
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 592
Height = 19
Left = 588
Height = 20
Top = 24
Width = 94
Width = 98
Anchors = [akTop, akRight]
BorderSpacing.Right = 12
Caption = 'LabelProgress'
Expand Down Expand Up @@ -185,12 +185,12 @@ object FormSync: TFormSync
item
AutoSize = True
Caption = 'Action'
Width = 49
Width = 53
end
item
AutoSize = True
Caption = 'Title'
Width = 37
Width = 39
end
item
Caption = 'Note ID'
Expand Down

0 comments on commit 7068938

Please sign in to comment.