26 #if defined (HAVE_CONFIG_H)
33 #include <QVBoxLayout>
56 m_doc (doc), m_browser (browser), m_octave_qobj (oct_qobj),
57 m_ctx_menu_item (
nullptr)
59 setObjectName (
"documentation_tab_bookmarks");
65 m_tree =
new QTreeWidget (p);
67 m_tree->setContextMenuPolicy (Qt::CustomContextMenu);
68 m_tree->setSelectionMode (QAbstractItemView::ExtendedSelection);
69 m_tree->setSortingEnabled (
false);
70 m_tree->setDragEnabled(
true);
71 m_tree->viewport()->setAcceptDrops(
true);
72 m_tree->setDropIndicatorShown(
true);
73 m_tree->setDragDropMode(QAbstractItemView::InternalMove);
74 m_tree->setColumnCount (1);
75 m_tree->setHeaderHidden (
true);
76 m_tree->setEditTriggers (QAbstractItemView::EditKeyPressed
77 | QAbstractItemView::SelectedClicked);
79 connect (m_tree, &QTreeWidget::customContextMenuRequested,
81 connect (m_tree, &QTreeWidget::itemDoubleClicked,
85 icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirClosedIcon),
86 QIcon::Normal, QIcon::Off);
87 icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirOpenIcon),
88 QIcon::Normal, QIcon::On);
89 icon_bookmark.addPixmap (style ()->standardPixmap(QStyle::SP_FileIcon));
93 QString f_path =
f.absolutePath ();
95 m_xbel_file.setFileName (
f.absoluteFilePath ());
97 if (m_xbel_file.exists ())
99 QString err = read_bookmarks ();
100 if ( !err.isEmpty ())
102 err.append (tr (
"\nNo documentation bookmarks loaded!"));
104 tr (
"Octave: Loading Documentation Bookmarks"),
106 m_xbel_file.close ();
111 m_filter_widget =
new QWidget (p);
112 m_filter =
new QComboBox (m_filter_widget);
114 m_filter->setToolTip (tr (
"Enter text to search the bookmarks"));
115 m_filter->setEditable (
true);
116 m_filter->setInsertPolicy (QComboBox::NoInsert);
117 m_filter->setMaxCount (10);
118 m_filter->setMaxVisibleItems (10);
119 m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon);
120 QSizePolicy size_pol (QSizePolicy::Expanding, QSizePolicy::Preferred);
121 m_filter->setSizePolicy (size_pol);
122 m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive);
126 connect (m_filter, &QComboBox::editTextChanged,
128 connect (m_filter->lineEdit (), &QLineEdit::editingFinished,
131 m_filter_checkbox =
new QCheckBox (m_filter_widget);
133 m_filter_checkbox->setChecked (filter_state);
134 filter_activate (filter_state);
136 connect (m_filter_checkbox, &QCheckBox::toggled,
139 QLabel *filter_label =
new QLabel (tr (
"Filter"), m_filter_widget);
140 QHBoxLayout *h_box_bm =
new QHBoxLayout (m_filter_widget);
141 h_box_bm->addWidget (filter_label);
142 h_box_bm->addWidget (m_filter_checkbox);
143 h_box_bm->addWidget (m_filter);
144 h_box_bm->setMargin (2);
145 m_filter_widget->setLayout (h_box_bm);
148 m_filter_widget->setVisible (m_filter_shown);
151 QVBoxLayout *v_box_bm =
new QVBoxLayout (
this);
152 v_box_bm->addWidget (m_filter_widget);
153 v_box_bm->addWidget (m_tree);
154 setLayout (v_box_bm);
163 QTreeWidgetItemIterator it (
m_tree);
166 QUrl url_i = (*it)->data (0,
url_role).toUrl ();
169 m_tree->setCurrentItem (*it);
170 (*it)->setExpanded (
true);
185 QTreeWidgetItem* item)
188 QTreeWidgetItem *new_item =
new QTreeWidgetItem (QStringList (title));
190 new_item->setData (0,
url_role, QVariant (url));
191 new_item->setFlags ((new_item->flags () & (~Qt::ItemIsDropEnabled))
193 | Qt::ItemIsDragEnabled);
200 item->addChild (new_item);
202 m_tree->addTopLevelItem (new_item);
208 QTreeWidgetItem *parent_item =
nullptr;
222 QTreeWidgetItem *new_folder =
add_folder (tr (
"New Folder"), parent_item);
224 m_tree->setCurrentItem (new_folder);
225 m_tree->editItem (new_folder);
230 QTreeWidgetItem *item,
bool expanded)
232 QTreeWidgetItem *new_folder =
new QTreeWidgetItem (QStringList (folder));
234 new_folder->setFlags (new_folder->flags() | Qt::ItemIsEditable
235 | Qt::ItemIsDragEnabled
236 | Qt::ItemIsDropEnabled);
237 new_folder->setChildIndicatorPolicy (QTreeWidgetItem::DontShowIndicatorWhenChildless);
239 new_folder->setExpanded (expanded);
243 item->addChild (new_folder);
245 m_tree->addTopLevelItem (new_folder);
252 QTreeWidgetItemIterator it (
m_tree);
256 if ((*it)->text (0).contains (pattern, Qt::CaseInsensitive))
258 (*it)->setHidden (
false);
259 (*it)->setExpanded (
true);
260 QTreeWidgetItem *p = (*it)->parent ();
263 p->setHidden (
false);
264 p->setExpanded (
true);
269 (*it)->setHidden (
true);
288 QString text =
m_filter->currentText ();
289 int index =
m_filter->findText (text);
300 int tag = item->data (0,
tag_role).toInt ();
304 item->setExpanded (! item->isExpanded ());
310 QUrl url = item->data (0,
url_role).toUrl ();
311 if (! url.isEmpty ())
329 menu.addAction (rmgr.
icon (
"window-close"), tr (
"Remo&ve"),
331 menu.addSeparator ();
334 menu.addAction (tr (
"&Add Folder"),
this,
337 menu.addSeparator ();
340 menu.addAction (tr (
"Hide &Filter"),
343 menu.addAction (tr (
"Show &Filter"),
346 menu.exec (
m_tree->mapToGlobal (xpos));
353 if (items.size () > 0)
361 if (items.size () > 0)
362 m_tree->editItem (items.at (0));
369 for (
auto it = items.begin () ; it != items.end (); it++)
372 m_tree->takeTopLevelItem (
373 m_tree->indexOfTopLevelItem (*it));
393 for (
int i = 0; i <
m_filter->count (); i++)
394 mru.append (
m_filter->itemText (i));
402 if (!
m_xbel_file.open (QFile::WriteOnly | QFile::Text))
405 tr(
"Unable to write file %1:\n%2.\n\n"
406 "Documentation bookmarks are not saved!\n")
413 xml_writer.setAutoFormatting (
true);
415 xml_writer.writeStartDocument ();
420 for (
int i = 0; i <
m_tree->topLevelItemCount(); i++)
423 xml_writer.writeEndDocument();
430 const QTreeWidgetItem *item)
432 switch (item->data (0,
tag_role).toInt ())
439 for (
int i = 0; i < item->childCount (); i++)
441 xml_writer->writeEndElement ();
448 xml_writer->writeEndElement ();
455 QString error_message;
458 if (!
m_xbel_file.open (QFile::ReadOnly | QFile::Text))
460 error_message = tr (
"Unable to read file %1:\n%2.")
463 return error_message;
468 if (! xml_reader.readNextStartElement ())
470 error_message = tr (
"No start element found in %1.\n"
471 "Invalid bookmark file?")
473 return error_message;
479 error_message = tr (
"The file\n"
481 "is not a valid XBEL file version 1.0.")
483 return error_message;
487 while (xml_reader.readNextStartElement ())
494 xml_reader.skipCurrentElement ();
499 return error_message;
503 item_tag tag, QTreeWidgetItem *item)
505 QString title (tr (
"Unknown title"));
511 QTreeWidgetItem *new_folder =
add_folder (title, item, expanded);
515 while (xml_reader->readNextStartElement ())
519 title = xml_reader->readElementText();
520 new_folder->setText (0, title);
527 xml_reader->skipCurrentElement ();
534 while (xml_reader->readNextStartElement ())
537 title = xml_reader->readElementText();
539 xml_reader->skipCurrentElement ();
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
documentation_browser * m_browser
QWidget * m_filter_widget
void handle_double_click(QTreeWidgetItem *item, int col=0)
QTreeWidgetItem * m_ctx_menu_item
void write_bookmarks(void)
void filter_activate(bool state)
QString read_bookmarks(void)
void save_settings(gui_settings *settings)
void write_tree_item(QXmlStreamWriter *xml_writer, const QTreeWidgetItem *item)
void read_next_item(QXmlStreamReader *xml_writer, item_tag tag, QTreeWidgetItem *item=nullptr)
base_qobject & m_octave_qobj
void update_filter_history(void)
void filter_bookmarks(const QString &pattern)
void ctx_menu(const QPoint &xpos)
QCheckBox * m_filter_checkbox
Documentation browser derived from Textbrowser.
The documentation main class derived from QSplitter.
QString title_and_anchor(const QString &title, const QUrl &url)
gui_settings * get_settings(void) const
QIcon icon(const QString &icon_name, bool octave_only=false, const QString &icon_alt_name=QString())
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning(const char *fmt,...)
const QLatin1String dc_xbel_value_version("1.0")
const QLatin1String dc_xbel_value_yes("yes")
const gui_pref dc_bookmark_filter_mru("documentation_widget/bookmark_filter_mru", QVariant())
const QLatin1String dc_xbel_name_title("title")
const QLatin1String dc_xbel_name_bookmark("bookmark")
const QLatin1String dc_xbel_attr_version("version")
const QLatin1String dc_xbel_name_folder("folder")
const QLatin1String dc_xbel_name_format("xbel")
const QString dc_bookmark_file("octave-doc-bookmarks.xbel")
const gui_pref dc_bookmark_filter_shown("documentation_widget/filter_shown", QVariant(true))
const gui_pref dc_bookmark_filter_active("documentation_widget/filter_active", QVariant(false))
const QLatin1String dc_xbel_attr_folded("folded")
const QLatin1String dc_xbel_value_no("no")
const QLatin1String dc_xbel_doctype("<!DOCTYPE xbel>")
const QLatin1String dc_xbel_attr_href("href")
F77_RET_T const F77_DBLE const F77_DBLE * f
static uint32_t state[624]