Skip to content

Commit

Permalink
Export. Some minor adjustments related to note/node headings
Browse files Browse the repository at this point in the history
Symbols will only be applied to node headings. It seems more normal, and makes clearer the use of symbols options.

Also, when adding the token %>, the length calculated from "Length heading" is now reduced if option 'Indent nodes' is checked.
This reduction depends on node level and the value set in "Tab size" (in the Note properties). When exporting to plain text,
it also depends on the relation between "IndentValue" and "Increment indents by", which defines the number of 'tabs' for each level.

Sceenshots to show the difference in #573 (comment)
  • Loading branch information
dpradov committed Dec 29, 2023
1 parent 292b4d6 commit 0bfa663
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 44 deletions.
33 changes: 12 additions & 21 deletions structure/kn_ExportNew.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object Form_ExportNew: TForm_ExportNew
Top = 5
Width = 311
Height = 348
ActivePage = Tab_Options
ActivePage = Tab_Main
HotTrack = False
TabInactiveColor = clBtnFace
TabInactiveFont.Charset = DEFAULT_CHARSET
Expand All @@ -70,10 +70,6 @@ object Form_ExportNew: TForm_ExportNew
ImageIndex = -1
StaticPageIndex = -1
TabVisible = True
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object GroupBox_Source: TGroupBox
Left = 2
Top = 5
Expand Down Expand Up @@ -229,18 +225,14 @@ object Form_ExportNew: TForm_ExportNew
ImageIndex = -1
StaticPageIndex = -1
TabVisible = True
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object GroupBox1: TGroupBox
Left = 3
Top = 5
Width = 293
Height = 151
Caption = ' Optional headings '
TabOrder = 0
object Label3: TLabel
object lblSymbols: TLabel
Left = 19
Top = 126
Width = 39
Expand All @@ -249,7 +241,7 @@ object Form_ExportNew: TForm_ExportNew
Caption = 'Symbols'
FocusControl = Edit_Folder
end
object Label4: TLabel
object lblLength: TLabel
Left = 143
Top = 125
Width = 74
Expand Down Expand Up @@ -285,6 +277,7 @@ object Form_ExportNew: TForm_ExportNew
Hint = 'Include node headings'
Caption = 'No&de headings'
TabOrder = 2
OnClick = CB_IncNodeHeadingClick
end
object Edit_NodeHead: TComboBox
Left = 121
Expand Down Expand Up @@ -326,7 +319,9 @@ object Form_ExportNew: TForm_ExportNew
Top = 73
Width = 80
Height = 17
Hint = 'Set font size of node headings based on level: Max, Dec, Min'
Hint =
'Set font size of headings based on level (including note): Max, ' +
'Dec, Min'
Caption = 'Font sizes'
TabOrder = 5
OnClick = CB_FontSizesClick
Expand All @@ -351,8 +346,8 @@ object Form_ExportNew: TForm_ExportNew
Width = 55
Height = 21
Hint =
'Length of heading to be reached with %> token, based on level: M' +
'ax, Dec, Min'
'Length of heading to be reached with %> token, based on node lev' +
'el: Max, Dec, Min'
Alignment = taCenter
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Expand All @@ -363,11 +358,11 @@ object Form_ExportNew: TForm_ExportNew
TabOrder = 11
end
object Edit_Symbols: TEdit
Left = 65
Top = 122
Left = 64
Top = 120
Width = 55
Height = 21
Hint = 'Symbols to use with %< or %>: Note, Node L1, ...'
Hint = 'Symbols to use with %< or %>: Level1, Level2, ...'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Expand Down Expand Up @@ -450,10 +445,6 @@ object Form_ExportNew: TForm_ExportNew
ImageIndex = -1
StaticPageIndex = -1
TabVisible = True
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object RG_TreePadVersion: TRadioGroup
Left = 5
Top = 5
Expand Down
71 changes: 48 additions & 23 deletions structure/kn_ExportNew.pas
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ TForm_ExportNew = class(TForm)
Edit_LengthHeading: TEdit;
Btn_TknHlp: TBitBtn;
Edit_Symbols: TEdit;
Label3: TLabel;
Label4: TLabel;
lblSymbols: TLabel;
lblLength: TLabel;
CB_IndentNodes: TCheckBox;
Spin_Indent: TSpinEdit;
lblIndent: TLabel;
Expand All @@ -120,6 +120,7 @@ TForm_ExportNew = class(TForm)
procedure Button_HelpClick(Sender: TObject);
procedure CB_FontSizesClick(Sender: TObject);
procedure CB_IndentNodesClick(Sender: TObject);
procedure CB_IncNodeHeadingClick(Sender: TObject);
private
{ Private declarations }
public
Expand Down Expand Up @@ -148,7 +149,7 @@ TForm_ExportNew = class(TForm)

function ConfirmAbort : boolean;

function ExpandExpTokenString( const tpl, filename, notename, nodename : string; const nodelevel, nodeindex : integer ) : string;
function ExpandExpTokenString( const tpl, filename, notename, nodename : string; const nodelevel, nodeindex : integer; TabSize: integer ) : string;
end;


Expand Down Expand Up @@ -229,12 +230,13 @@ procedure PrepareExportOptions (SymbolsRepetition, FontSizesInHeading: string);

function TForm_ExportNew.ExpandExpTokenString(
const tpl, filename, notename, nodename : string;
const nodelevel, nodeindex : integer ) : string;
const nodelevel, nodeindex : integer;
TabSize: integer ) : string;
var
i, len : integer;
wastokenchar : boolean;
thischar : Char;
LenSymbolsLine: integer;
LenSymbolsLine, NumTabsLevel: integer;
foundLineBreak: boolean;


Expand All @@ -243,29 +245,34 @@ function TForm_ExportNew.ExpandExpTokenString(
LenSymbolsLevel, I: integer;
Symbol: char;
begin
if nodelevel = 0 then exit('');

// Calculate length (repetition) of symbols level
if token = EXP_NODELEVELSYMB_INC then begin
if nodelevel = 0 then exit('');
LenSymbolsLevel:= 1 + (1*(nodelevel-1));
end
if token = EXP_NODELEVELSYMB_INC then
LenSymbolsLevel:= 1 + (1*(nodelevel-1))

else begin
if LengthsHeading_Max < 0 then exit('');
LenSymbolsLevel:= LengthsHeading_Max - (LengthsHeading_Inc*nodelevel);
LenSymbolsLevel:= LengthsHeading_Max - (LengthsHeading_Inc* (nodelevel-1));
if LenSymbolsLevel < LengthsHeading_Min then
LenSymbolsLevel:= LengthsHeading_Min;

if ExportOptions.IndentNestedNodes and not ExportOptions.SingleNodeFiles and (ExportOptions.TargetFormat in [xfRTF, xfHTML]) then
Dec(LenSymbolsLevel, 2 * (nodelevel-1));
if ExportOptions.IndentNestedNodes and not ExportOptions.SingleNodeFiles then begin
NumTabsLevel:= 1;
if ExportOptions.TargetFormat = xfPlainText then
NumTabsLevel:= ExportOptions.IndentValue div EditorOptions.IndentInc;
Dec(LenSymbolsLevel, NumTabsLevel*TabSize * (nodelevel-1));
end;

Dec(LenSymbolsLevel, headerLength);
end;

// Determine symbol to use
{ The first element of LevelSymbols always corresponds to level 0 (note) }
if (nodeLevel + 1) > Length(ExportOptions.SymbolsInHeading) then
{ The first element of LevelSymbols corresponds to node level 1 }
if nodeLevel > Length(ExportOptions.SymbolsInHeading) then
Symbol:= ExportOptions.SymbolsInHeading[Length(ExportOptions.SymbolsInHeading)]
else
Symbol:= ExportOptions.SymbolsInHeading[nodeLevel+1];
Symbol:= ExportOptions.SymbolsInHeading[nodeLevel];

Result:= StringOfChar(Symbol, LenSymbolsLevel);
end;
Expand Down Expand Up @@ -320,7 +327,7 @@ function TForm_ExportNew.ExpandExpTokenString(

end;

Result:= StringReplace(Result, _TokenChar + EXP_NODELEVELSYMB_DEC, ExpandSymbolsLevel(thisChar, LenSymbolsLine+2), [rfReplaceAll]);
Result:= StringReplace(Result, _TokenChar + EXP_NODELEVELSYMB_DEC, ExpandSymbolsLevel(thisChar, LenSymbolsLine), [rfReplaceAll]);

end; // ExpandExpTokenString

Expand Down Expand Up @@ -463,10 +470,26 @@ procedure TForm_ExportNew.CB_FontSizesClick(Sender: TObject);
end;


procedure TForm_ExportNew.CB_IncNodeHeadingClick(Sender: TObject);
var
Enabled: boolean;
begin
Enabled:= CB_IncNodeHeading.Checked;
CB_LevelTemplates.Enabled:= Enabled;
Edit_Symbols.Enabled:= Enabled;
Edit_LengthHeading.Enabled:= Enabled;
lblSymbols.Enabled:= Enabled;
lblLength.Enabled:= Enabled;
end;

procedure TForm_ExportNew.CB_IndentNodesClick(Sender: TObject);
var
Enabled: boolean;
begin
Spin_Indent.Enabled:= CB_IndentNodes.Checked;
LblIndent.Enabled:= CB_IndentNodes.Checked;
Enabled:= CB_IndentNodes.Checked;
Spin_Indent.Enabled:= Enabled;
LblIndent.Enabled:= Enabled;
CB_UseTab.Enabled:= Enabled;
end;

procedure TForm_ExportNew.Combo_FormatClick(Sender: TObject);
Expand All @@ -485,6 +508,7 @@ procedure TForm_ExportNew.Combo_FormatClick(Sender: TObject);
Tab_Options.TabVisible := (format <> xfTreePad);
RG_NodeMode.Enabled := (format <> xfTreePad);
RG_HTML.Visible := (format = xfHTML);
CB_UseTab.Enabled:= (format = xfPlainText) and (CB_IndentNodes.Checked);
end;
end;

Expand Down Expand Up @@ -684,11 +708,12 @@ procedure TForm_ExportNew.OptionsToForm;
CB_LevelTemplates.Checked:= NodeLevelTemplates;
CB_FontSizes.Checked:= AutoFontSizesInHeading;
CB_IndentNodes.Checked := IndentNestedNodes;
Spin_Indent.Enabled:= IndentNestedNodes;
LblIndent.Enabled:= IndentNestedNodes;
Spin_Indent.Value:= IndentValue;
CB_UseTab.Checked:= IndentUsingTabs;

CB_IndentNodesClick(nil);
CB_IncNodeHeadingClick(nil);

if TreePadRTF then
RG_TreePadVersion.ItemIndex := 1
else
Expand Down Expand Up @@ -733,7 +758,7 @@ function TForm_ExportNew.Validate : boolean;
DoMessageBox( STR_03, mtError, [mbOK], 0 );
exit;
end;

result := true;
end; // Validate

Expand Down Expand Up @@ -912,7 +937,7 @@ procedure TForm_ExportNew.PerformExport;
// this note has been marked for exporting

if ExportOptions.IncludeNoteHeadings then begin
NoteHeading := ExpandExpTokenString( ExportOptions.NoteHeading, myNotes.Filename, RemoveAccelChar( myNote.Name ), '', 0, 0 );
NoteHeading := ExpandExpTokenString( ExportOptions.NoteHeading, myNotes.Filename, RemoveAccelChar( myNote.Name ), '', 0, 0, myNote.TabSize );
NoteHeadingRTF := MergeHeadingWithRTFTemplate( EscapeTextForRTF( NoteHeading ), NoteHeadingTpl );
end;

Expand Down Expand Up @@ -996,7 +1021,7 @@ procedure TForm_ExportNew.PerformExport;
inc( ThisNodeIndex );

if ExportOptions.IncludeNodeHeadings then begin
NodeHeading := ExpandExpTokenString( ExportOptions.NodeHeading, myNotes.Filename, RemoveAccelChar( myNote.Name ), myNoteNode.Name, myNoteNode.Level+1, ThisNodeIndex );
NodeHeading := ExpandExpTokenString( ExportOptions.NodeHeading, myNotes.Filename, RemoveAccelChar( myNote.Name ), myNoteNode.Name, myNoteNode.Level+1, ThisNodeIndex, myNote.TabSize );
NodeHeadingTpl_Aux := '';
if ExportOptions.NodeLevelTemplates then
NodeHeadingTpl_Aux:= NodeLevelHeadingTpl[myNoteNode.Level];
Expand Down

0 comments on commit 0bfa663

Please sign in to comment.