Add version 2.6

This commit is contained in:
No Time To Play 2023-10-06 12:28:01 +00:00
parent b218cfcf75
commit e3c994145e
3 changed files with 110 additions and 20 deletions

View File

@ -1,5 +1,15 @@
# Scrunch Edit news
## Version 2.6 (6 October 2023)
### Added
* Prefix lines command (backported from ToyEd)
### Changed
* File dialogs now use Zenity under X11 if available.
## Version 2.5.1 (5 January 2023)
### Fixed

View File

@ -22,7 +22,7 @@ Recommended screen resolution: 800x600.
## Status
Scrunch Edit 2.5 is the current version as of 25 December 2022.
Scrunch Edit 2.6 is the current version as of 6 October 2023.
This archive contains Scrunch Edit TT, a new port that enables easy bundling. It hasn't been tested as much as previous versions. Please back up your data.
@ -30,11 +30,13 @@ This archive contains Scrunch Edit TT, a new port that enables easy bundling. It
Scrunch Edit guesses formats based on file extensions. There's no other way short of separate "open" commands, since the same text file can be interpreted in different ways based on context.
- The preface is any text that comes before the first heading, in Org mode parlance. That's unusual in Markdown, but you can still have one.
- The preface is any text that comes before the first heading, in Org Mode parlance. That's unusual in Markdown, but you can still have one.
- If you add sections while a search is active, Find Again will skip them.
While an effort has been made to provide key combos for most functions, Scrunch Edit is best used with mouse and keyboard together.
## License and credits
## License and support
Scrunch Edit is made by No Time To Play, based on knowledge gained from TkDocs.com, and offered as open source under the MIT License. See the source code for details.
Scruch Edit is open source under the MIT license. See source code for details.
You can usually find me on IRC, in the #ctrl-c channel of tilde.chat, or else as @notimetoplay on the elekk.xyz Mastodon instance. Would love to hear from you.

View File

@ -1,7 +1,7 @@
#!/usr/bin/env tclsh
#
# Scrunch Edit: a two-pane outliner for Org Mode and Markdown files
# Copyright 2021, 2022 Felix Pleșoianu <https://felix.plesoianu.ro/>
# Copyright 2021, 2022, 2023 Felix Pleșoianu <https://felix.plesoianu.ro/>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@ -23,16 +23,16 @@
package require Tcl 8.6
package require Tk 8.6
package require TclOO
package require getstring
namespace import getstring::*
namespace import oo::class
set about_text "A two-pane outliner\nVersion 2.5.1 (5 Jan 2023)\nMIT License"
set about_text "A two-pane outliner\nVersion 2.6 (6 Oct 2023)\nMIT License"
set credits_text "Made by No Time To Play\nbased on knowledge\nfrom TkDocs.com"
set site_link "https://ctrl-c.club/~nttp/toys/scrunch/"
oo::class create MarkupParser {
class create MarkupParser {
variable lines cursor head_char Heading
constructor {l hc} {
@ -378,6 +378,9 @@ $m add separator
$m add command -label "Lower case" -command lower_case -under 0 -accel "Alt-L"
$m add command -label "Title case" -command title_case -under 1 -accel "Alt-T"
$m add command -label "Upper case" -command upper_case -under 0 -accel "Alt-U"
$m add separator
$m add command -label "Prefix lines..." -command prefix_lines \
-under 0 -accel "Alt-P"
.menubar add cascade -menu .menubar.mFormat -label "Format" -underline 3
set m [menu .menubar.view]
@ -468,6 +471,7 @@ bind $editor <Alt-o> {tk_util::open_line $editor; break}
bind $editor <Alt-l> {lower_case; break}
bind $editor <Alt-t> {title_case; break}
bind $editor <Alt-u> upper_case
bind $editor <Alt-p> prefix_lines
bind . <Control-e> {select_root $tree}
bind . <Control-comma> {tk_util::fold_all $tree}
@ -597,10 +601,16 @@ proc do_open {} {
return
}
}
set choice [tk_getOpenFile -parent . \
-title "Open existing outline" \
-initialdir [file_dir $file_name] \
-filetypes $file_types]
if {[tk windowingsystem] == "x11" && [auto_execok "zenity"] ne ""} {
set choice [open_with_zenity $file_name]
} else {
set choice [tk_getOpenFile -parent . \
-title "Open existing outline" \
-initialdir [file_dir $file_name] \
-filetypes $file_types]
}
if {[string length $choice] == 0} {
set status "Opening canceled."
} elseif {![file isfile $choice]} {
@ -614,6 +624,27 @@ proc do_open {} {
}
}
proc open_with_zenity file_name {
try {
if {$file_name ne ""} {
return [exec zenity --file-selection \
--title "Open existing outline" \
--filename $file_name \
--file-filter "All files | *" \
--file-filter "Org Mode files | *.org" \
--file-filter "Markdown / Gemini | *.md *.gmi"]
} else {
return [exec zenity --file-selection \
--title "Open existing outline" \
--file-filter "All files | *" \
--file-filter "Org Mode files | *.org" \
--file-filter "Markdown / Gemini | *.md *.gmi"]
}
} trap CHILDSTATUS {results options} {
return ""
}
}
proc load_file full_path {
global tree editor node_text modified status
@ -631,9 +662,9 @@ proc load_file full_path {
return 1
} on break e {
tk_messageBox -parent . \
-type "ok" -icon "error" \
-type "ok" -icon "warning" \
-title "Scrunch Edit TT" \
-message "Error parsing file" \
-message "Error parsing outline" \
-detail $e
return 0
} on error e {
@ -679,10 +710,14 @@ proc do_save {} {
proc do_save_as {} {
global file_name file_types status
set choice [tk_getSaveFile -parent . \
-title "Save outline as..." \
-initialdir [file_dir $file_name] \
-filetypes $file_types]
if {[tk windowingsystem] == "x11" && [auto_execok "zenity"] ne ""} {
set choice [save_with_zenity $file_name]
} else {
set choice [tk_getSaveFile -parent . \
-title "Save outline as..." \
-initialdir [file_dir $file_name] \
-filetypes $file_types]
}
if {[string length $choice] == 0} {
set status "Save canceled."
} elseif {[save_file $choice]} {
@ -690,6 +725,29 @@ proc do_save_as {} {
}
}
proc save_with_zenity file_name {
try {
if {$file_name ne ""} {
return [exec zenity --file-selection \
--title "Save outline as..." \
--save --confirm-overwrite \
--filename $file_name \
--file-filter "All files | *" \
--file-filter "Org Mode files | *.org" \
--file-filter "Markdown / Gemini | *.md *.gmi"]
} else {
return [exec zenity --file-selection \
--title "Save outline as..." \
--save --confirm-overwrite \
--file-filter "All files | *" \
--file-filter "Org Mode files | *.org" \
--file-filter "Markdown / Gemini | *.md *.gmi"]
}
} trap CHILDSTATUS {results options} {
return ""
}
}
proc save_file full_path {
global node_text editing editor status
@ -716,7 +774,7 @@ proc save_file full_path {
tk_messageBox -parent . \
-type "ok" -icon "error" \
-title "Scrunch Edit TT" \
-message "Error writing file" \
-message "Error writing outline" \
-detail $e
return 0
} on error e {
@ -780,7 +838,7 @@ proc show_stats {} {
tk_messageBox -parent . \
-type "ok" -icon "info" \
-title "Scrunch Edit TT" \
-message "File statistics" \
-message "Outline statistics" \
-detail $stats
}
@ -1086,6 +1144,26 @@ proc move_right {} {
show_modified
}
proc prefix_lines {} {
global editor status
set sel [tk_util::text_selection $editor]
if {$sel eq ""} {
set status "Nothing selected."
return
}
set ret [tk_getString .gs answer "Prefix selected lines with:"]
if {!$ret} {
set status "Search canceled."
return
}
set lines [split $sel "\n"]
set result [list]
foreach l $lines {
lappend result $answer$l
}
$editor replace sel.first sel.last [join $result "\n"]
}
proc alert message {
tk_messageBox -parent . \
-type "ok" -icon "info" \