Skip to content

Commit

Permalink
CLI opt to open a new note, allow Tokens without expiry (#321), confo…
Browse files Browse the repository at this point in the history
…rm (partly) with Tomboy indent model (#324, #323, #322)
  • Loading branch information
davidbannon committed Dec 26, 2024
1 parent 0f2286d commit 976143b
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 74 deletions.
6 changes: 3 additions & 3 deletions doc/wiki/Download_Release.note
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ If you wish to sync to a SMB: network share, open that connection before configu


<size:large><bold>Arch and Manjaro</bold></size:large>
And other Linux Distributions that use the Arch, Pacman package system. I have made only a [GTK 64bit]($$PAC64$$) version and, recommended, a [Qt6 64bit]($$PAC64QT6$$] at this stage, could make other combinations if needed. Click the link, choose download and install with this command from ~/Downloads -
And other Linux Distributions that use the Arch, Pacman package system. I have made only a [GTK 64bit]($$PAC64$$) version and, recommended, a [Qt6 64bit]($$PAC64QT6$$) at this stage, could make other combinations if needed. Click the link, choose download and install with this command from ~/Downloads -

sudo pacman -U ./tomboy-ng-$$VERSION$$-1-x86_64.pkg.tar.zst

Expand Down Expand Up @@ -162,8 +162,8 @@ I have not made Raspberry Pi rpms, seems few users.


</note-content></text>
<last-change-date>2024-11-24T14:23:22.9099786+11:00</last-change-date>
<last-metadata-change-date>2024-11-24T14:23:22.9099786+11:00</last-metadata-change-date>
<last-change-date>2024-11-26T17:17:20.6169161+11:00</last-change-date>
<last-metadata-change-date>2024-11-26T17:17:20.6169161+11:00</last-metadata-change-date>
<create-date>2020-01-22T14:51:55.8970000+11:00</create-date>
<cursor-position>1</cursor-position>
<selection-bound-position>1</selection-bound-position>
Expand Down
4 changes: 2 additions & 2 deletions doc/wiki/Download_Release.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ $$RPM64QT6$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v$$VERS
$$DEB32ARM$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v$$VERSION$$/tomboy-ng_$$VERSION$$-0_armhf.deb
$$DEB64ARM$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v$$VERSION$$/tomboy-ng_$$VERSION$$-0_arm64.deb
$$DEB64ARMQT5$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v$$VERSION$$/tomboy-ng_$$VERSION$$-0_arm64Qt5.deb
$$PAC64$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v0.40/tomboy-ng-$$VERSION$$-1-x86_64.pkg.tar.zst
$$PAC64QT6$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v0.40/tomboy-ng-$$VERSION$$-1-Qt6-x86_64.pkg.tar.zst
$$PAC64$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v$$VERSION$$/tomboy-ng-$$VERSION$$-1-x86_64.pkg.tar.zst
$$PAC64QT6$$=https://github.com/tomboy-notes/tomboy-ng/releases/download/v$$VERSION$$/tomboy-ng-$$VERSION$$-1-Qt6-x86_64.pkg.tar.zst
$$GPGKEY$$=https://raw.githubusercontent.com/tomboy-notes/tomboy-ng/master/package/tomboy-ng-GPG-KEY
17 changes: 9 additions & 8 deletions prepare.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,22 @@ Debian need a config file, .dput.cf in $HOME that points to mentors, see mentor

Pacman
======
w have both FPC and Lazarus as non package installs, required removal of them as makedependencies. Both must be added to PATH
We have both FPC and Lazarus as non package installs now, required removal of them as makedependencies. Both must be added to PATH

So, on a clean (in my case Endeavour) machine, install gtk2 and qt6pas


export VER=0.40b
sudo pacmand -S gtk2 qt6pas
[eg]export VER=0.40b
mkdir $VER; cd $VER
wget https://github.com/tomboy-notes/tomboy-ng/raw/master/scripts/PKGBUILD.gtk2
wget https://github.com/tomboy-notes/tomboy-ng/raw/master/scripts/PKGBUILD.Qt6
cp PKGBUILD.gtk2 PKGBUILD
cp PKGBUILD.Qt6 PKGBUILD
makepkg --skipinteg
mv ... ...gtk2...
copy PKGBUILD.Qt6 PKGBUILD
[eg] mv tomboy-ng-0.41-1-x86_64.pkg.tar.zst tomboy-ng-0.41-1-Qt6-x86_64.pkg.tar.zst
copy PKGBUILD.gtk2 PKGBUILD
makepkg --skipinteg
mv ... ...Qt6...


The gtk2 version does not have a widget identifier.

note that makepkg needs to see $VER too.

Expand Down
4 changes: 2 additions & 2 deletions source/Tomboy_NG.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
RequireDerivedFormResource:=True;
Application.Initialize;

if ContinueToGUI then begin
if ContinueToGUI() then begin // This is in the CLI.pas, command line activity that may be all thats needed.

{$ifdef APPINDPATCH}
{$ifdef CPUi386} // Note: unless Ayatana fix their problem, no option for Gnome users
// https://github.com/AyatanaIndicators/libayatana-appindicator/issues/76
// https://github.com/AyatanaIndicators/libayatana-appindicator/issues/76
UnityWSCtrls.GlobalUseAppInd := UnityWSCtrls.UseAppIndNo; // 32bit must be a 'no'.
debugln('Tomboy_NG.lpr : Deciding to set UseAppInd to no to prevent AV.');
debugln('You may over rule that with --useappind=yes to see what happens.');
Expand Down
30 changes: 22 additions & 8 deletions source/cli.pas
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
and also removes anything after it ! But does act on it. Seems both - and -- acceptable -
--platformtheme qt5ct
-platformtheme qt5ct
And an typo in the option value is ignored, use a space as seperator, not '=' !
And a typo in the option value is ignored.
Use a space as seperator, not '=' !
}

interface
Expand All @@ -54,6 +55,7 @@ function Import_Text_MD_File(MD : boolean; FFName : string = '') : string;

var
SingleNoteName : string = ''; // other unit will want to know.....
OpenNewNotePlease : boolean = false;


const Version_string = {$I %TOMBOY_NG_VER};
Expand All @@ -72,7 +74,7 @@ ENoNotesRepoException = class(Exception);
LongOpts : TStringArray; // See initialization section

const
ShortOpts = 'hgo:l:vt:m:n:'; // help gnome3 open lang ver import-[txt md note]
ShortOpts = 'hgo:l:vt:m:n:c'; // help gnome3 open lang ver import-[txt md note]

{ If something on commandline means don't proceed, ret True }
function CommandLineError(inCommingError : string = '') : boolean;
Expand All @@ -95,6 +97,7 @@ function CommandLineError(inCommingError : string = '') : boolean;
debugln(' --dark-theme ' + 'Does not work for GTK2');
debugln(' -l --lang=CCode ' + rsHelpLang); // syntax depends on bugfix https://bugs.freepascal.org/view.php?id=35432
debugln(' -h --help ' + rsHelpHelp);
debugln(' -c ' + 'Create new note'); // ToDo : make rsHelpCreate
debugln(' --version ' + rsHelpVersion);
debugln(' --no-splash ' + rsHelpNoSplash);
debugln(' --debug-sync ' + rsHelpDebugSync);
Expand Down Expand Up @@ -277,6 +280,9 @@ function Import_Text_MD_File(MD : boolean; FFName : string = '') : string;

end;

// Looks to see if user just wants some command line activity, returns
// false if GUI is not needed.

function ContinueToGUI() : boolean ;
begin
if CommandLineError() then exit(False);
Expand All @@ -296,14 +302,21 @@ function ContinueToGUI() : boolean ;
Import_Note();
exit(False);
end;
if Application.HasOption('c', 'create-note') then begin
if CanSendMessage('CREATENOTE') then
exit(false) // no GUI needed, just tell existing one to open a new note
else
OpenNewNotePlease := True; // mainunit FormShow() will look there to see if it got a new note request at startup
end; // applies only when user uses -c and -ng is not already running

// Note that the useappind option is processed in the LPR file.

if HaveCMDParam() then
if HaveCMDParam() then // Only command line parameter is filename of a Single Note
if SingleNoteName = '' then
exit(False) // thats an error, more than one parameter
else exit(True); // proceed in SNM
else exit(True); // proceed in SNM, we set its File Name further up.
// Looks like a normal startup
if CanSendMessage('SHOWSEARCH') then exit(False);
if CanSendMessage('SHOWSEARCH') then exit(False); // will fail if -ng is not already running.
Result := true;
end;

Expand All @@ -314,8 +327,9 @@ initialization
'debug-sync', 'debug-index', 'debug-spell',
'config-dir:', 'open-note:', 'save-exit', // -o for open also legal. save-exit is legecy
'import-txt:', 'import-md:', 'import-note:', // -t, -m -n respectivly
'title-fname', 'gnome3', 'useappind:', // -g and gnome3 is legal but legacy, ignored.
'strict-theme', // Strict-theme applies to only Qt versions
'allow-leftclick'); // overrule wayland decision to use only right click
'title-fname', 'gnome3', 'useappind:', // -g and gnome3 is legal but legacy, ignored.
'strict-theme', // Strict-theme applies to only Qt versions
'allow-leftclick', // overrule wayland decision to use only right click
'create-note'); // create a new note (-ng open or not), added post 0.41
end.

103 changes: 78 additions & 25 deletions source/editbox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
2024/06/07 UTF8 bug, where missed UTF8 char ahead of file link.
2024/10/05 Made DeletingThisNote public so SearchForm can delete an Open note.
2024/10/16 Fixed the way that Save on Quit works, no contention !
2024/12/24 Altered Indent to work (a little) like Tomboy, embedded Tab #9 char at start line
}


Expand Down Expand Up @@ -4123,14 +4124,51 @@ procedure TEditBoxForm.KMemo1Click(Sender: TObject);
// debugln('Mouseclick ' + inttostr(kmemo1.RealSelStart));
end;


procedure TEditBoxForm.KMemo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
ABlock : TKMemoBlock;
ABlockNo, LocIndex : integer;
ABlock : TKMemoParagraph;
ABlockNo : integer;

// returns the para block that controls text the cursor is on right now
function GetParagraphBlock(NotTitle : boolean) : TKMemoParagraph;
var
ABlockNo : integer = -1;
LocIndex : integer;
begin
ABlockNo := Kmemo1.Blocks.IndexToBlockIndex(KMemo1.Blocks.RealSelStart, LocIndex);
if (ABlockNo < 1) and NotTitle then
exit(Nil); // Dont mess with title
if KMemo1.Blocks[ABlockNo].ClassNameIs('TKMemoParagraph') then // if Ablockno is a para, use it, else we look for one further on
Result := TKMemoParagraph(KMemo1.Blocks[ABlockNo]) // works if cursor is just beyond last char in line
else Result := Kmemo1.Blocks.GetNearestParagraphBlock(ABlockNo); // Gets the following one, not the 'nearest' !
end;

(* function GetParagraphIndex(NotTitle : boolean) : integer;
var
LocIndex : integer;
begin
result := Kmemo1.Blocks.IndexToBlockIndex(KMemo1.Blocks.RealSelStart, LocIndex);
if (result < 1) and NotTitle then
exit(-1);
if not KMemo1.Blocks[Result].ClassNameIs('TKMemoParagraph') then
Result := Kmemo1.Blocks.GetNearestParagraphBlockIndex(result);
end; *)

procedure IndentControl(IncreaseIndent : Boolean); // Note : at present, only one indent can be set
begin
ABlock := GetParagraphBlock(True);
if ABlock <> nil then // if zero cannot be a bullet nor indent
if (ABlock.ParaStyle.LeftPadding = 0) then // ToDo : one day, multilevel indent ??
ABlock.ParaStyle.LeftPadding := IndentWidth; // if left padding is set, don't do bullet
Key := 0;
exit();
end;

// ret T if it used the BS to remove an Indent. Will also 'prepare' a non-indented
// para to be merged, by KMemo, with a previous indented one. AnyPosInPara
// means we were called by Shift-Tab meaning Cursor does not need be on first char.
// ret T if it used the BS to remove an Indent. Will also 'prepare' a non-indented
// para to be merged, by KMemo, with a previous indented one. AnyPosInPara
// means we were called by Shift-Tab meaning Cursor does not need be on first char,
// it could be on first to just after the last.
function RemoveIndent(AnyPosInPara : boolean = false) : boolean;
var
ABlock : TKMemoBlock;
Expand All @@ -4139,28 +4177,45 @@ procedure TEditBoxForm.KMemo1KeyDown(Sender: TObject; var Key: Word; Shift: TShi
Result := False;
ABlockNo := Kmemo1.Blocks.IndexToBlockIndex(KMemo1.Blocks.RealSelStart, LocIndex); // LocIndex not certain to be in left most block.
if ABlockNo < 2 then exit;

if not AnyPosInPara // AnyPosInPara means being on first char does not matter
and (not KMemo1.Blocks[ABlockNo-1].ClassNameIs('TKMemoParagraph')) then exit; // was not first block in para.
and (not KMemo1.Blocks[ABlockNo-1].ClassNameIs('TKMemoParagraph')) then exit; // was not first block in para so BS not removing indent
ABlock := Nil;
ABlock := Kmemo1.Blocks.GetNearestParagraphBlock(ABlockNo); // Gets the following one, not the nearest !

if KMemo1.Blocks[ABlockNo].ClassNameIs('TKMemoParagraph') then // if Ablockno is a para, use it, else we look for one further on
ABlock := KMemo1.Blocks[ABlockNo]
else ABlock := Kmemo1.Blocks.GetNearestParagraphBlock(ABlockNo); // Gets the following one, not the 'nearest' !
if ABlock = Nil then exit;
if TKMemoParagraph(ABlock).Numbering <> pnuNone then exit; // Bullets are not my job

if TKMemoParagraph(ABlock).Numbering <> pnuNone then begin // Its a bullet. We reduce bullet or Indent
if AnyPosInPara then BulletControl(False); // don't do this here if called as part of BS keystroke
exit;
end;

// deal with a backspace from first char of an indented para.
if (TKMemoParagraph(ABlock).ParaStyle.LeftPadding > 0) // Has padding, might be Indent
and (not KMemo1.Blocks[ABlockNo].ClassNameIs('TKMemoParagraph')) //
// and (not KMemo1.Blocks[ABlockNo].ClassNameIs('TKMemoParagraph')) // // ??????????????
and (AnyPosInPara or (LocIndex = 0)) then begin // and char position OK, must delete indent
TKMemoParagraph(ABlock).ParaStyle.LeftPadding := 0;
writeln('RemoveIndent() left padding set to 0');
exit(true);
end;

// Deal a para being merged with a previous, indented one. Just indent current one and let KMemo handle it.

// if (LocIndex = 0)
// and KMemo1.Blocks[ABlockNo-1].ClassNameIs('TKMemoParagraph')

if (LocIndex = 0) // this part only applies if first char of block
and KMemo1.Blocks[ABlockNo-1].ClassNameIs('TKMemoParagraph')
and (TKMemoParagraph(KMemo1.Blocks[ABlockNo-1]).ParaStyle.LeftPadding > 0)
and (TKMemoParagraph(KMemo1.Blocks[ABlockNo-1]).Numbering = pnuNone) then
TKMemoParagraph(ABlock).ParaStyle.LeftPadding := IndentWidth; // BS will go through to kmemo who will do merge
end;




begin
if not Ready then begin // Will this help with issue #279
if [ssCtrl] = shift then
Expand All @@ -4180,7 +4235,7 @@ procedure TEditBoxForm.KMemo1KeyDown(Sender: TObject; var Key: Word; Shift: TShi
exit;
end;
if ([ssAlt, ssShift] = Shift) and ((Key = VK_RIGHT) or (Key = VK_LEFT)) then exit; // KMemo - extend selection one word left or right
{$endif}
{$endif DARWIN}

if (Key = VK_ESCAPE) and Sett.CheckEscClosesNote.Checked then close; // Will do normal save stuff first.

Expand All @@ -4203,7 +4258,7 @@ procedure TEditBoxForm.KMemo1KeyDown(Sender: TObject; var Key: Word; Shift: TShi
Key := 0;
exit();
end;
if (Key = VK_TAB) then begin
if (Key = VK_TAB) then begin // Shift-Tab, maybe anywhere in a line, first to last char.
RemoveIndent(True);
Key := 0;
exit();
Expand Down Expand Up @@ -4239,6 +4294,7 @@ procedure TEditBoxForm.KMemo1KeyDown(Sender: TObject; var Key: Word; Shift: TShi
VK_M : begin Key := 0; DoRightClickMenu; end;
VK_N : SearchForm.OpenNote('');
VK_E : InitiateCalc();
VK_TAB : IndentControl(True);
VK_F4 : close; // close just this note, normal saving will take place
VK_C, VK_A, VK_HOME, VK_END, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_PRIOR, VK_NEXT, VK_INSERT : exit;
end;
Expand Down Expand Up @@ -4277,26 +4333,23 @@ procedure TEditBoxForm.KMemo1KeyDown(Sender: TObject; var Key: Word; Shift: TShi
exit();
end;

if Key = VK_TAB then begin // A Tab insets paragraph
ABlockNo := Kmemo1.Blocks.IndexToBlockIndex(KMemo1.Blocks.RealSelStart, LocIndex);
if ABlockNo > 1 then begin // don't mess with title
ABlock := Nil;
ABlock := Kmemo1.Blocks.GetNearestParagraphBlock(ABlockNo);
if (ABlock <> Nil) {and ABlock.ClassNameIs('TKMemoParagraph') } // Might be nil if no para marker at end of content
and (TKMemoParagraph(ABlock).Numbering = pnuNone) then // Don't mix Indent with Bullets
TKMemoParagraph(ABlock).ParaStyle.LeftPadding := IndentWidth;
Key := 0; // Don't let go through to KMemo
MarkDirty();
exit;
end;
if Key = VK_TAB then begin // A Tab insets paragraph
// Tab key sets a bullet or extends that bullet further right.
// Maybe, one day it will also extend Insert too.
ABlock := GetParagraphBlock(True);
if ABlock <> nil then
if (ABlock.ParaStyle.LeftPadding = 0) or (ABlock.Numbering <> pnuNone) then // ToDo : one day, multilevel indent ??
BulletControl(True); // if left padding is set, don't do bullet
Key := 0;
exit();
end;

if Key = VK_F3 then begin
key := 0;
if (EditFind.Text <> rsMenuSearch) then SpeedRightClick(self);
end;
if Key <> 8 then exit(); // ======== We are watching for a BS on a Bullet OR Indent Marker ========
if RemoveIndent() then begin
if Key <> 8 then exit(); // ======== We are watching for a BS on a Bullet ========
if RemoveIndent(False) then begin
if Verbose then debugln('Removed an Indent.');
Key := 0;
MarkDirty();
Expand Down
Loading

0 comments on commit 976143b

Please sign in to comment.