summaryrefslogtreecommitdiffstats
path: root/parts/documentation/interfaces
diff options
context:
space:
mode:
Diffstat (limited to 'parts/documentation/interfaces')
-rw-r--r--parts/documentation/interfaces/kdevdocumentationplugin.cpp74
-rw-r--r--parts/documentation/interfaces/kdevdocumentationplugin.h13
2 files changed, 67 insertions, 20 deletions
diff --git a/parts/documentation/interfaces/kdevdocumentationplugin.cpp b/parts/documentation/interfaces/kdevdocumentationplugin.cpp
index afc9abad..c79d22d6 100644
--- a/parts/documentation/interfaces/kdevdocumentationplugin.cpp
+++ b/parts/documentation/interfaces/kdevdocumentationplugin.cpp
@@ -90,8 +90,8 @@ void DocumentationItem::init( )
DocumentationCatalogItem::DocumentationCatalogItem(DocumentationPlugin* plugin,
- TDEListView *parent, const TQString &name)
- :DocumentationItem(DocumentationItem::Catalog, parent, name), m_plugin(plugin),
+ TDEListView *parent, TDEListViewItem *after, const TQString &name)
+ :DocumentationItem(DocumentationItem::Catalog, parent, after, name), m_plugin(plugin),
isLoaded(false), isActivated(false), m_isProjectDocumentationItem(false)
{
setExpandable(true);
@@ -440,6 +440,21 @@ void DocumentationPlugin::loadIndex(IndexBox *index, DocumentationCatalogItem *i
cacheIndex(item);
}
+TDEListViewItem* DocumentationPlugin::findCatalogPosition(const TQString &key, const TDEListView *contents) const
+{
+ TDEListViewItem *curr_item = (TDEListViewItem*)(contents->firstChild());
+ if (!curr_item)
+ return NULL; // Empty listview
+
+ TDEListViewItem *prev_item = NULL;
+ while (curr_item && curr_item->text(0) <= key)
+ {
+ prev_item = curr_item;
+ curr_item = (TDEListViewItem*)(curr_item->nextSibling());
+ }
+ return prev_item;
+}
+
void DocumentationPlugin::init(TDEListView *contents)
{
config->setGroup("Locations");
@@ -448,8 +463,15 @@ void DocumentationPlugin::init(TDEListView *contents)
for (TQMap<TQString, TQString>::const_iterator it = entryMap.begin();
it != entryMap.end(); ++it)
{
- if (catalogEnabled(it.key()))
- createCatalog(contents, it.key(), config->readPathEntry(it.key()));
+ TQString cat_key = it.key();
+ if (catalogEnabled(cat_key))
+ {
+ // Keep the list in increasing sorted order. Given that the list is
+ // reasonably short, we can affort to scan through the list each time
+ // a new item is created
+ TDEListViewItem *afterItem = findCatalogPosition(cat_key, contents);
+ createCatalog(contents, afterItem, cat_key, config->readPathEntry(cat_key));
+ }
}
}
@@ -472,31 +494,33 @@ void DocumentationPlugin::reinit(TDEListView *contents, IndexBox *index, TQStrin
it != entryMap.end(); ++it)
{
config->setGroup("Locations");
- if (restrictions.contains(it.key()) || (!catalogEnabled(it.key())))
+ TQString cat_key = it.key();
+ if (restrictions.contains(cat_key) || (!catalogEnabled(cat_key)))
{
- if (namedCatalogs.contains(it.key()))
- delete namedCatalogs[it.key()];
+ if (namedCatalogs.contains(cat_key))
+ delete namedCatalogs[cat_key];
}
else
{
kdDebug() << "updating 1" << endl;
- if (!namedCatalogs.contains(it.key())) //create catalog if it does not exist
+ if (!namedCatalogs.contains(cat_key)) //create catalog if it does not exist
{
- DocumentationCatalogItem * item = createCatalog(contents, it.key(), config->readPathEntry(it.key()));
+ TDEListViewItem *afterItem = findCatalogPosition(cat_key, contents);
+ DocumentationCatalogItem *item = createCatalog(contents, afterItem, cat_key, config->readPathEntry(cat_key));
loadIndex(index, item);
index->setDirty(true);
// index->refill(indexes[item]);
}
- else if (!indexEnabled(namedCatalogs[it.key()])) //clear index if it is disabled in configuration
+ else if (!indexEnabled(namedCatalogs[cat_key])) //clear index if it is disabled in configuration
{
kdDebug() << " updating: clearCatalogIndex" << endl;
- clearCatalogIndex(namedCatalogs[it.key()]);
+ clearCatalogIndex(namedCatalogs[cat_key]);
}
- else if ( (indexEnabled(namedCatalogs[it.key()])) //index is requested in configuration but does not yet exist
- && (!indexes.contains(namedCatalogs[it.key()])) )
+ else if ( (indexEnabled(namedCatalogs[cat_key])) //index is requested in configuration but does not yet exist
+ && (!indexes.contains(namedCatalogs[cat_key])) )
{
kdDebug() << " index requested " << endl;
- loadIndex(index, namedCatalogs[it.key()]);
+ loadIndex(index, namedCatalogs[cat_key]);
index->setDirty(true);
}
m_indexCreated = true;
@@ -676,6 +700,21 @@ ProjectDocumentationPlugin::~ProjectDocumentationPlugin()
deinit();
}
+TDEListViewItem* ProjectDocumentationPlugin::findCatalogPosition(const TQString &key, const TDEListView *contents) const
+{
+ TDEListViewItem *curr_item = (TDEListViewItem*)(contents->firstChild());
+ if (!curr_item)
+ return NULL; // Empty listview
+
+ TDEListViewItem *prev_item = NULL;
+ while (curr_item && curr_item->text(0) <= key)
+ {
+ prev_item = curr_item;
+ curr_item = (TDEListViewItem*)(curr_item->nextSibling());
+ }
+ return prev_item;
+}
+
void ProjectDocumentationPlugin::init(TDEListView *contents, IndexBox *index, const TQString &url)
{
m_contents = contents;
@@ -684,9 +723,10 @@ void ProjectDocumentationPlugin::init(TDEListView *contents, IndexBox *index, co
if (m_catalog)
deinit();
- m_catalog = m_docPlugin->createCatalog(contents,
- m_type == DocumentationPlugin::APIDocs ? i18n("Project API Documentation")
- : i18n("Project User Manual"), url);
+ TQString cat_key = (m_type == DocumentationPlugin::APIDocs ? i18n("Project API Documentation")
+ : i18n("Project User Manual"));
+ TDEListViewItem *afterItem = findCatalogPosition(cat_key, contents);
+ m_catalog = m_docPlugin->createCatalog(contents, afterItem, cat_key, url);
if (m_catalog)
{
m_catalog->setProjectDocumentationItem(true);
diff --git a/parts/documentation/interfaces/kdevdocumentationplugin.h b/parts/documentation/interfaces/kdevdocumentationplugin.h
index a5dbe458..dcdc3f9a 100644
--- a/parts/documentation/interfaces/kdevdocumentationplugin.h
+++ b/parts/documentation/interfaces/kdevdocumentationplugin.h
@@ -72,7 +72,7 @@ class DocumentationPlugin;
class DocumentationCatalogItem: public DocumentationItem
{
public:
- DocumentationCatalogItem(DocumentationPlugin* plugin, TDEListView *parent, const TQString &name);
+ DocumentationCatalogItem(DocumentationPlugin* plugin, TDEListView *parent, TDEListViewItem *after, const TQString &name);
DocumentationCatalogItem(DocumentationPlugin* plugin, DocumentationItem *parent, const TQString &name);
virtual ~DocumentationCatalogItem();
@@ -240,8 +240,9 @@ public:
/**Returns the i18n name of the plugin.*/
virtual TQString pluginName() const = 0;
- /**Creates documentation catalog with given title and url.*/
- virtual DocumentationCatalogItem *createCatalog(TDEListView *contents, const TQString &title, const TQString &url) = 0;
+ /**Creates documentation catalog with given title and url. Catalog lists are sorted
+ alphabetically in increasing order.*/
+ virtual DocumentationCatalogItem *createCatalog(TDEListView *contents, TDEListViewItem *after, const TQString &title, const TQString &url) = 0;
/**Initialize a list of catalogs.
@param contents the listview to fill with catalogs
@@ -361,6 +362,9 @@ protected:
/**Loads index from cache or creates and caches it if does not exist.*/
void loadIndex(IndexBox *index, DocumentationCatalogItem *item);
+ /**Find catalog insert position to maintain a sorted order.*/
+ TDEListViewItem* findCatalogPosition(const TQString &key, const TDEListView *contents) const;
+
/**Stores items deleted from configuration. @ref saveCatalogConfiguration
uses this to remove entries from configuration file.*/
TQStringList deletedConfigurationItems;
@@ -408,6 +412,9 @@ public slots:
virtual void reinit();
protected:
+ /**Find catalog insert position to maintain a sorted order.*/
+ TDEListViewItem* findCatalogPosition(const TQString &key, const TDEListView *contents) const;
+
DocumentationPlugin *m_docPlugin;
DocumentationCatalogItem *m_catalog;