Skip to content

Commit

Permalink
Prevent Race Condition when saving first config (SearchTitleOnly) and…
Browse files Browse the repository at this point in the history
… supply default path for user selected path to notes
  • Loading branch information
davidbannon committed Oct 20, 2024
1 parent 848ad16 commit 1c5e50b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 deletions.
5 changes: 2 additions & 3 deletions package/package.bash
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,15 @@ echo "----- LAZ_CONFIG is $LAZ_CONFIG ------"



# Note: because we must build Qt6 on later that U20.04 and for all others, we must build on U20.04
# due to the libc issue, we cannot build our qt6 one all at the same time.
# Note: as of Oct 2024, we can build our Qt6 one here and now too.

rm -f changelog # we build a new one from ../debian/changelog and ../whatsnew each run

if [ "$2" != "" ]; then
JustMakeBinary "$2" # Does not return.
fi

for BIN in ReleaseLin64 ReleaseLin32 ReleaseWin64 ReleaseWin32 ReleaseRasPi ReleaseQT5; # ReleaseQt6 etc, not yet ! Must build elsewhere, bring biary here.
for BIN in ReleaseLin64 ReleaseLin32 ReleaseWin64 ReleaseWin32 ReleaseRasPi ReleaseQT5 ReleaseQt6;
do BuildAMode $BIN;
done

Expand Down
4 changes: 2 additions & 2 deletions source/Tomboy_NG.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@
</PublishOptions>
<RunParams>
<local>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-alt"/>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-small"/>
</local>
<environment>
<UserOverrides Count="2">
Expand All @@ -1081,7 +1081,7 @@
<Modes Count="1">
<Mode0 Name="default">
<local>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-alt"/>
<CommandLineParams Value="--config-dir=/home/dbannon/.config/tomboy-ng-small"/>
</local>
<environment>
<UserOverrides Count="2">
Expand Down
4 changes: 2 additions & 2 deletions source/mvxwindow.pas
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ function MvXWinWorkSpace(Caption : string; WorkS : integer) : boolean;
WorkS := CurrentWorkSpace(Disp, RootWin);
WinID := 0;
if not FindWindowCaption(Caption, Disp, RootWin, WinID) or (WinID = 0) then begin
MvXWinError := 'ERROR - Failed to find that Window !';
writeln('MvXWinError - Failed to find that Window [', Caption, ']');
MvXWinError := 'Info - Failed to find that Window !';
writeln('MvXWin Info - Failed to find that Window [', Caption, ']');
XCloseDisplay(Disp);
exit(false);
end;
Expand Down
5 changes: 3 additions & 2 deletions source/searchunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ procedure TSearchForm.FormCreate(Sender: TObject);
end;
end;
MenuItemCaseSensitive.checked := Sett.SearchCaseSensitive;
MenuItemSearchTitleOnly.Checked := Sett.SearchOnTitleOnly;
MenuItemSearchTitleOnly.Checked := Sett.SearchTitleOnly;
LabelSearchTitle.Visible := MenuItemSearchTitleOnly.Checked;
MenuItemSWYT.checked := Sett.AutoSearchUpdate;
MenuItemImportNote.Hint := rsHelpImportFile; // Hint shows on StatusBar
Expand Down Expand Up @@ -1997,7 +1997,8 @@ procedure TSearchForm.MenuItemSearchTitleOnlyClick(Sender : TObject);
// Notebook filter is not affected by swap, so if if no active search term,
// do nothing. But if we have a search term (>2char) and we are switching form
// Title to content (ie expect more 'hits') RefineSearch() is NOT enough
Sett.SaveSettings(sender);
Sett.SearchTitleOnly := MenuItemSearchTitleOnly.Checked;
// Sett.SaveSettings(sender);
end;

procedure TSearchForm.ButtonClearSearchClick(Sender: TObject);
Expand Down
8 changes: 4 additions & 4 deletions source/settings.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ object Sett: TSett
Height = 488
Top = 0
Width = 726
ActivePage = TabSync
ActivePage = TabBasic
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Bottom = 2
TabIndex = 2
TabIndex = 0
TabOrder = 0
OnChange = PageControl1Change
object TabBasic: TTabSheet
Expand Down Expand Up @@ -195,7 +195,7 @@ object Sett: TSett
Left = 10
Height = 22
Top = 8
Width = 158
Width = 162
BorderSpacing.Left = 10
Caption = 'tomboy-ng Default'
Checked = True
Expand Down Expand Up @@ -1410,7 +1410,7 @@ object Sett: TSett
OnClick = SpeedButHelpClick
end
object SelectDirectoryDialog1: TSelectDirectoryDialog
Options = [ofShareAware, ofEnableSizing]
Options = [ofShareAware, ofEnableSizing, ofForceShowHidden]
Left = 408
end
object OpenDialogLibrary: TOpenDialog
Expand Down
41 changes: 19 additions & 22 deletions source/settings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ interface
Buttons, ComCtrls, ExtCtrls, Menus, FileUtil, BackUpView,
LCLIntf, Spin{, notifier}, base64, fpttf, LMessages, syncutils, LazUTF8
{$ifdef LCLQT5}, qt5{$endif}
{$ifdef LCLQT6}, qt6{$endif} ;
{$ifdef LCLQT6}, qt6{$endif} , Types;

// Types;

Expand Down Expand Up @@ -299,7 +299,7 @@ TSett = class(TForm)
procedure SetColours;

private

fSearchTitleOnly : boolean; // memory for property SearchTitleOnly
TheHomeDir : string;
SyncTimingFileIndex, SyncTimingGithubIndex : integer; // Holds ComboBox index for each particular sync
SyncTimingFileLast, SyncTimingGitHubLast : TDateTime; // The time the last indicated sync was run (manual or auto).
Expand Down Expand Up @@ -385,6 +385,7 @@ TSett = class(TForm)
function fHomeDir : string;
procedure fSetCaseSensitive(IsIt : boolean);
//function ZipDate: string;
procedure fSetSearchTitleOnly(ItIs : boolean);

public
HelpNotesPath : string; // expected path to help note directories for this OS
Expand Down Expand Up @@ -427,7 +428,7 @@ TSett = class(TForm)
{ Indicates Spell is configured and LabelLibrary and LabelDic should
contain valid full file names.}
SpellConfig : boolean;
SearchOnTitleOnly : boolean;
// SearchOnTitleOnly : boolean;
// Checks to ensure no threads are running. Will hold
// up an App exits for up to 5 seconds.
procedure CloseNowPlease();
Expand All @@ -444,6 +445,8 @@ TSett = class(TForm)
// Does not appear to be implemented
property ExportPath : ANSIString Read fExportPath write fExportPath;

property SearchTitleOnly : boolean read fSearchTitleOnly write fSetSearchTitleOnly;

// Returns users home dir inc trailing slash
property HomeDir : String Read fHomeDir;

Expand Down Expand Up @@ -625,6 +628,13 @@ procedure TSett.fSetCaseSensitive(IsIt : boolean);
WriteConfigFile();
end;

procedure TSett.fSetSearchTitleOnly(ItIs : boolean);
begin
fSearchTitleOnly := ItIs;
if Not MaskSettingsChanged then
WriteConfigFile();
end;

procedure TSett.PageControl1Change(Sender: TObject);
begin
// if NoteDirectory = '' then ButtDefaultNoteDirClick(self);
Expand Down Expand Up @@ -879,6 +889,7 @@ procedure TSett.FormCreate(Sender: TObject);
i : integer;
begin
// gTTFontCache.ReadStandardFonts; // we do this in Kmemo2PDR now.
fSearchTitleOnly := False;
NotesSavedAtClose := 0; // Inc'ed in Main FormClose, dec'ed when a note save finshes (at close time)
Caption := 'tomboy-ng Settings';
ButtonSetNotePath.Enabled := False;
Expand Down Expand Up @@ -1044,7 +1055,7 @@ procedure TSett.ReadConfigFile;
('true' = ConfigFile.readstring('BasicSettings', 'UseUndo', 'true'));
SearchCaseSensitive :=
('true' = Configfile.readstring('BasicSettings', 'CaseSensitive', 'false'));
SearchOnTitleOnly :=
SearchTitleOnly :=
('true' = Configfile.readstring('BasicSettings', 'SearchOnTitle', 'false'));
CheckShowSplash.Checked :=
('true' = Configfile.ReadString('BasicSettings', 'ShowSplash', 'true'));
Expand Down Expand Up @@ -1207,6 +1218,7 @@ function TSett.MyBoolStr(const InBool : boolean) : string;
end;

function TSett.WriteConfigFile(IgnoreMask : boolean = false; WriteLastSync : boolean = false) : boolean;
// Warning, this gets called before Sett is created with a new installation.
var
ConfigFile : TINIFile;
i : integer;
Expand All @@ -1221,7 +1233,7 @@ function TSett.WriteConfigFile(IgnoreMask : boolean = false; WriteLastSync : boo
ConfigFile.writestring('BasicSettings', 'NotesPath', NoteDirectory);
Configfile.writestring('BasicSettings', 'ManyNotebooks', MyBoolStr(CheckManyNoteBooks.checked));
Configfile.writestring('BasicSettings', 'CaseSensitive', MyBoolStr(SearchCaseSensitive));
Configfile.writestring('BasicSettings', 'SearchOnTitle', MyBoolStr(SearchForm.MenuItemSearchTitleOnly.Checked));
Configfile.writestring('BasicSettings', 'SearchOnTitle', MyBoolStr(SearchTitleOnly));
ConfigFile.writestring('BasicSettings', 'ShowIntLinks', MyBoolStr(CheckShowIntLinks.Checked));
ConfigFile.writestring('BasicSettings', 'ShowExtLinks', MyBoolStr(CheckShowExtLinks.Checked));
ConfigFile.WriteString('BasicSettings', 'ShowSplash', MyBoolStr(CheckShowSplash.Checked));
Expand Down Expand Up @@ -1456,27 +1468,12 @@ procedure TSett.ButtonSetNotePathClick(Sender: TObject);
APath : string;
begin
if not DidCleanAndLockSync() then exit; // Also flush notes
SelectDirectoryDialog1.InitialDir := LabelNotesPath.Caption;
if SelectDirectoryDialog1.Execute then begin
APath := TrimFilename(SelectDirectoryDialog1.FileName + PathDelim);
SetNotePath(APath);

(* if CheckDirectory(NoteDirectory) then begin
if not FindFirst(NoteDirectory + '*.note', faAnyFile and faDirectory, Info)=0 then begin
showmessage(rsDirHasNoNotes);
end;
FindClose(Info);
CheckShowIntLinks.enabled := true; // Why is this here ????
// CheckReadOnly.enabled := true;
// SyncFileAuto := False;
// SyncGithubAuto := False;
ComboSyncTypeChange(self);
WriteConfigFile();
SyncSettings();
SearchForm.IndexNotes(True);
end else
NoteDirectory := LabelNotesPath.caption; *)
end;

SelectDirectoryDialog1.InitialDir := '';
end;

{ Colors - most colors will be right, as set instructed by the OS. However, the
Expand Down

0 comments on commit 1c5e50b

Please sign in to comment.