Skip to content

Commit

Permalink
add "Open recent" into File menu (#102) for #101
Browse files Browse the repository at this point in the history
* Add recent files menu and store recently opened files

This commit adds a "Recent Files" submenu to the "File" menu that displays recently opened SGF files. It also stores the list of recent files in the browser storage and updates it whenever a new file is loaded, so the recent files stay in sync across browser sessions.

* cleaning (recover indent from #102)

* polish #102 ("Open recent")

* add qcgm1978 to contributors

* fix typo (resent ==> recent)

---------

Co-authored-by: Hiraoka <[email protected]>
  • Loading branch information
qcgm1978 and kaorahi authored Dec 2, 2023
1 parent c9a6377 commit 63eb172
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ <h1>LizGoban Contributors</h1>
<p><span class="ext" data-url="https://github.com/ivysrono">@ivysrono</span></p>
<p><span class="ext" data-url="https://github.com/zakki">@zakki (Kensuke Matsuzaki)</span></p>
<p><span class="ext" data-url="https://github.com/hebaeba">@hebaeba</span></p>
<p><span class="ext" data-url="https://github.com/qcgm1978">@qcgm1978 (Youth)</span></p>

</body>
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ function menu_template(win) {
(this_item, win) => start_match(win, 3), true, !(R.in_match && R.in_pair_match)),
sep,
item('Open SGF etc....', 'CmdOrCtrl+O', open_sgf_etc, true),
menu('Open recent...', store.get('recent_files', []).map(f =>
item(f, undefined, () => load_sgf_etc(f)))),
item('Save SGF with analysis...', 'CmdOrCtrl+S', () => save_sgf(true), true),
item('Save SGF...', 'CmdOrCtrl+Shift+S', () => save_sgf(false), true),
sep,
Expand Down Expand Up @@ -2006,6 +2008,8 @@ function load_sgf_etc(filename) {
const res = sgf_str => {read_sgf(sgf_str, filename); update_all()}
const rej = () => {load_sgf(filename); update_all()}
XYZ2SGF.fileToConvertedString(filename).then(res, rej)
const recent = new Set([filename, ...store.get('recent_files', [])])
store.set('recent_files', [...recent].slice(0, option.max_recent_files))
}
function load_sgf(filename, internally) {
read_sgf(fs.readFileSync(filename, {encoding: 'utf8'}), filename, internally)
Expand Down
1 change: 1 addition & 0 deletions src/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const default_option = {
sgf_dir: undefined,
exercise_dir: 'exercise',
max_cached_engines: 3,
max_recent_files: 10,
face_image_rule: null,
preset: [{label: "leelaz", engine: ["leelaz", "-g", "-w", "network.gz"]}],
record_note_to_SGF: false,
Expand Down

0 comments on commit 63eb172

Please sign in to comment.