Mercurial > octave
comparison libgui/src/m-editor/file-editor.cc @ 31181:c6c4c6f04170
also restore bookmarks when restoring an editor session at startup
* gui-preferences-ed.h: add setting for storing bookmarks of editor files
* file-editor-interface.h: additional argument in request_open_file
* file-editor-tab.cc (get_all_bookmarks): new function collecting all
bookmarks and returning it in a list of numbers in a string;
* file-editor-tab.h: new function get_all_bookmarks
* file-editor.cc (restore_session): get list of bookmarks from settings
file and them as argument to request_open_file;
(save_session): collect all bookmarks of open files and store them
into the settings file;
(request_open_file): string with bookmarks as new argument,
if string id non-empty, add all contained bookmarks to the file
* file-editor.h: add bookmarks to session_data, new string argument
with bookmarks for request_open_file
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Wed, 10 Aug 2022 22:24:58 +0200 |
parents | ba701853b1bf |
children | ad014fc78bd6 c6d54dd31a7e |
comparison
equal
deleted
inserted
replaced
31180:6203e303c5ac | 31181:c6c4c6f04170 |
---|---|
335 = settings->value (ed_session_ind).toStringList (); | 335 = settings->value (ed_session_ind).toStringList (); |
336 | 336 |
337 QStringList session_lines | 337 QStringList session_lines |
338 = settings->value (ed_session_lines).toStringList (); | 338 = settings->value (ed_session_lines).toStringList (); |
339 | 339 |
340 QStringList session_bookmarks | |
341 = settings->value (ed_session_bookmarks).toStringList (); | |
342 | |
340 // fill a list of the struct and sort it (depending on index) | 343 // fill a list of the struct and sort it (depending on index) |
341 QList<session_data> s_data; | 344 QList<session_data> s_data; |
342 | 345 |
343 bool do_encoding = (session_encodings.count () == sessionFileNames.count ()); | 346 bool do_encoding = (session_encodings.count () == sessionFileNames.count ()); |
344 bool do_index = (session_index.count () == sessionFileNames.count ()); | 347 bool do_index = (session_index.count () == sessionFileNames.count ()); |
345 bool do_lines = (session_lines.count () == sessionFileNames.count ()); | 348 bool do_lines = (session_lines.count () == sessionFileNames.count ()); |
349 bool do_bookmarks = (session_bookmarks.count () == sessionFileNames.count ()); | |
346 | 350 |
347 for (int n = 0; n < sessionFileNames.count (); ++n) | 351 for (int n = 0; n < sessionFileNames.count (); ++n) |
348 { | 352 { |
349 QFileInfo file = QFileInfo (sessionFileNames.at (n)); | 353 QFileInfo file = QFileInfo (sessionFileNames.at (n)); |
350 if (! file.exists ()) | 354 if (! file.exists ()) |
351 continue; | 355 continue; |
352 | 356 |
353 session_data item = { 0, -1, sessionFileNames.at (n), | 357 session_data item = { 0, -1, sessionFileNames.at (n), |
354 QString (), QString ()}; | 358 QString (), QString (), QString ()}; |
355 if (do_lines) | 359 if (do_lines) |
356 item.line = session_lines.at (n).toInt (); | 360 item.line = session_lines.at (n).toInt (); |
357 if (do_index) | 361 if (do_index) |
358 item.index = session_index.at (n).toInt (); | 362 item.index = session_index.at (n).toInt (); |
359 if (do_encoding) | 363 if (do_encoding) |
360 item.encoding = session_encodings.at (n); | 364 item.encoding = session_encodings.at (n); |
365 if (do_bookmarks) | |
366 item.bookmarks = session_bookmarks.at (n); | |
361 | 367 |
362 s_data << item; | 368 s_data << item; |
363 } | 369 } |
364 | 370 |
365 std::sort (s_data.begin (), s_data.end ()); | 371 std::sort (s_data.begin (), s_data.end ()); |
366 | 372 |
367 // finally open the files with the desired encoding in the desired order | 373 // finally open the files with the desired encoding in the desired order |
368 for (int n = 0; n < s_data.count (); ++n) | 374 for (int n = 0; n < s_data.count (); ++n) |
369 request_open_file (s_data.at (n).file_name, s_data.at (n).encoding, | 375 request_open_file (s_data.at (n).file_name, s_data.at (n).encoding, |
370 s_data.at (n).line); | 376 s_data.at (n).line, false, false, true, "", -1, |
377 s_data.at (n).bookmarks); | |
371 } | 378 } |
372 | 379 |
373 void file_editor::activate (void) | 380 void file_editor::activate (void) |
374 { | 381 { |
375 if (m_no_focus) | 382 if (m_no_focus) |
438 | 445 |
439 QStringList fetFileNames; | 446 QStringList fetFileNames; |
440 QStringList fet_encodings; | 447 QStringList fet_encodings; |
441 QStringList fet_index; | 448 QStringList fet_index; |
442 QStringList fet_lines; | 449 QStringList fet_lines; |
450 QStringList fet_bookmarks; | |
443 | 451 |
444 std::list<file_editor_tab *> editor_tab_lst = m_tab_widget->tab_list (); | 452 std::list<file_editor_tab *> editor_tab_lst = m_tab_widget->tab_list (); |
445 | 453 |
446 for (auto editor_tab : editor_tab_lst) | 454 for (auto editor_tab : editor_tab_lst) |
447 { | 455 { |
458 fet_index.append (index.setNum (m_tab_widget->indexOf (editor_tab))); | 466 fet_index.append (index.setNum (m_tab_widget->indexOf (editor_tab))); |
459 | 467 |
460 int l, c; | 468 int l, c; |
461 editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c); | 469 editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c); |
462 fet_lines.append (index.setNum (l + 1)); | 470 fet_lines.append (index.setNum (l + 1)); |
471 | |
472 fet_bookmarks.append (editor_tab->get_all_bookmarks ()); | |
463 } | 473 } |
464 } | 474 } |
465 | 475 |
466 settings->setValue (ed_session_names.key, fetFileNames); | 476 settings->setValue (ed_session_names.key, fetFileNames); |
467 settings->setValue (ed_session_enc.key, fet_encodings); | 477 settings->setValue (ed_session_enc.key, fet_encodings); |
468 settings->setValue (ed_session_ind.key, fet_index); | 478 settings->setValue (ed_session_ind.key, fet_index); |
469 settings->setValue (ed_session_lines.key, fet_lines); | 479 settings->setValue (ed_session_lines.key, fet_lines); |
480 settings->setValue (ed_session_bookmarks.key, fet_bookmarks); | |
470 settings->sync (); | 481 settings->sync (); |
471 } | 482 } |
472 | 483 |
473 bool file_editor::check_closing (void) | 484 bool file_editor::check_closing (void) |
474 { | 485 { |
1533 // and/or a breakpoint with condition cond. | 1544 // and/or a breakpoint with condition cond. |
1534 void file_editor::request_open_file (const QString& openFileName, | 1545 void file_editor::request_open_file (const QString& openFileName, |
1535 const QString& encoding, | 1546 const QString& encoding, |
1536 int line, bool debug_pointer, | 1547 int line, bool debug_pointer, |
1537 bool breakpoint_marker, bool insert, | 1548 bool breakpoint_marker, bool insert, |
1538 const QString& cond, int index) | 1549 const QString& cond, int index, |
1550 const QString& bookmarks) | |
1539 { | 1551 { |
1540 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | 1552 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); |
1541 gui_settings *settings = rmgr.get_settings (); | 1553 gui_settings *settings = rmgr.get_settings (); |
1542 | 1554 |
1543 if (settings->value (global_use_custom_editor).toBool ()) | 1555 if (settings->value (global_use_custom_editor).toBool ()) |
1706 { | 1718 { |
1707 file.close (); | 1719 file.close (); |
1708 request_open_file (openFileName); | 1720 request_open_file (openFileName); |
1709 } | 1721 } |
1710 } | 1722 } |
1723 } | |
1724 } | |
1725 | |
1726 if (! bookmarks.isEmpty ()) | |
1727 { | |
1728 // Restore bookmarks | |
1729 for (const auto& bms : bookmarks.split (',')) | |
1730 { | |
1731 int bm = bms.toInt (); | |
1732 if (fileEditorTab) | |
1733 fileEditorTab->qsci_edit_area ()->markerAdd (bm, marker::bookmark); | |
1711 } | 1734 } |
1712 } | 1735 } |
1713 | 1736 |
1714 if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ())) | 1737 if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ())) |
1715 { | 1738 { |