Mercurial > octave
diff libgui/src/documentation-bookmarks.h @ 29330:b92614cfdfed
add bookmark functionality to the documentation browser (bug #54938)
* libgui/src/documentation-bookmarks.cc: new file for the bookmarks tab;
(documentation_bookmarks): initialize the tab, the filter and the tree;
prepare the bookmark file and read existing bookmarks;
(~documentation_bookmarks): empty destructor;
(add_bookmark): slot for the adding bookmark action, get current title
and url;
(add_bookmark): do the adding, possibly as child of a parent item;
(add_folder): slot for context menu action for adding a folder, check
current position where to insert the new folder;
(add_folder): do the folder adding;
(filter_bookmarks): filter bookmarks following the changed filter text;
(filter_activate): enable/disable filter;
(update_filter_history): save a search term when acknowledged by return;
(handle_double_click): open the clicked bookmark;
(ctx_menu): show context menu at current mouse position;
(open): open a bookmark via context menu;
(edit): edit a bookmark via context menu;
(remove): remove selected bookmarks via context menu;
(show_filter): toggle visibility of the filter;
(save_settings): save settings and initiate writing the bookmarks;
(write_bookmarks): open file and initiate writing all top level items;
(write_tree_item): write a single item and its children;
(read_bookmarks): open the file, check if it is valid and loop over
all top level items for reading them from the file;
(read_next_item): read an item and its children in case of a folder;
* documentation-bookmarks.h: class documentation_bookmarks derived
from QWidget, declaration of all required functions and class variables;
* documentation-dock-widget.cc (save_settings): new derived method,
emitting a signal for saving setting in child widgets and callinf the
original method
* documentation-dock-widget.h: derived method save_settings and signal
for child widgets
* documentation.cc: include documentation-bookmarks.h;
(documentation): add bookmark tab, connect signal for saving settings;
(add_action): check reveiver before connection the actions signal;
(construct_tool_bar): add toolbar button for adding a bookmark, connect
its signal the add_bookmark slot and connect signal for saving settings;
(notice_settings): add shortcut for adding a bookmark;
(update_history): move combining page title and current anchor into a
more specific title ...
(title_and_anchor): to here;
* documentation.h: new function title_and_anchor, new action
* gui-preferences-dc.h: new file with constants for some bookmark settings
and for the xbel file syntax
* gui-preferences-sc.h: default value for bookmark action
* bookmark-new.png/bookmark-new.svg: icon for tool bar button
* icons_license: add new icon
* module.mk: add new files
* shortcut-manager.cc (init_data): initialize new short for bookmarking
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 10 Jan 2021 14:04:35 +0100 |
parents | |
children | 7854d5752dd2 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/documentation-bookmarks.h Sun Jan 10 14:04:35 2021 +0100 @@ -0,0 +1,124 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018-2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WiTHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_documentation_bookmarks_h) +#define octave_documentation_bookmarks_h 1 + +#include <QCheckBox> +#include <QComboBox> +#include <QTreeWidget> +#include <QXmlStreamWriter> + +#include "documentation.h" +#include "octave-qobject.h" + + +namespace octave +{ + class base_qobject; + class documentation; + + class documentation_bookmarks : public QWidget + { + Q_OBJECT + + public: + + documentation_bookmarks ( + documentation *doc, documentation_browser *browser, + base_qobject& oct_qobj, QWidget *p = nullptr); + ~documentation_bookmarks (void); + + public slots: + + void add_bookmark (void); + void add_folder (bool); + void save_settings (void); + + private slots: + + void filter_bookmarks (const QString& pattern); + void filter_activate (bool state); + void update_filter_history (void); + void handle_double_click (QTreeWidgetItem *item, int col = 0); + void ctx_menu (const QPoint& xpos); + void open (bool); + void edit (bool); + void remove (bool); + void show_filter (bool); + + private: + + enum item_role + { + url_role = Qt::UserRole, + tag_role = Qt::UserRole + 1 + }; + enum item_tag + { + bookmark_tag, + folder_tag + }; + + void add_bookmark (const QString& title, const QString& url, + QTreeWidgetItem *item = nullptr); + QTreeWidgetItem* add_folder (const QString& folder, + QTreeWidgetItem *item = nullptr, + bool expanded = true); + + /*! + Writing to and reading bookmarks from an xbel-file as + proposed in the qt example + [QXmlStream Bookmarks Example](https://doc.qt.io/qt-5/qtxml-streambookmarks-example.html) + */ + void write_bookmarks (void); + void write_tree_item (QXmlStreamWriter *xml_writer, + const QTreeWidgetItem *item); + QString read_bookmarks (void); + void read_next_item (QXmlStreamReader *xml_writer, item_tag tag, + QTreeWidgetItem *item = nullptr); + + documentation *m_doc; + documentation_browser *m_browser; + base_qobject& m_octave_qobj; + + QComboBox *m_filter; + QTreeWidget *m_tree; + + QTreeWidgetItem *m_ctx_menu_item; + + QIcon icon_folder; + QIcon icon_bookmark; + + QWidget *m_filter_widget; + QCheckBox *m_filter_checkbox; + bool m_filter_shown; + + QFile m_xbel_file; + }; + +} + +#endif