store icon information in metadata nodes

svn path=/trunk/; revision=8969
This commit is contained in:
Martin Fuchs 2004-04-04 20:23:51 +00:00
parent 199ffcb9bc
commit 9289b59c37
4 changed files with 143 additions and 47 deletions

View file

@ -772,13 +772,22 @@ int MainFrame::Notify(int id, NMHDR* pnmh)
const BookmarkNode& node = *(BookmarkNode*)pnmgit->lParam; const BookmarkNode& node = *(BookmarkNode*)pnmgit->lParam;
if (node._type == BookmarkNode::BMNT_FOLDER) { if (node._type == BookmarkNode::BMNT_FOLDER) {
// display tooltips for bookmark folders
if (!node._pfolder->_description.empty()) if (!node._pfolder->_description.empty())
lstrcpyn(pnmgit->pszText, node._pfolder->_description.c_str(), pnmgit->cchTextMax); lstrcpyn(pnmgit->pszText, node._pfolder->_description.c_str(), pnmgit->cchTextMax);
} else // BookmarkNode::BMNT_BOOKMARK } else { // BookmarkNode::BMNT_BOOKMARK
if (!node._pbookmark->_description.empty()) // display tooltips for bookmark folders
lstrcpyn(pnmgit->pszText, node._pbookmark->_description.c_str(), pnmgit->cchTextMax); String txt = node._pbookmark->_description;
else
lstrcpyn(pnmgit->pszText, node._pbookmark->_url.c_str(), pnmgit->cchTextMax); if (!node._pbookmark->_url.empty()) {
if (!txt.empty())
txt += TEXT(" - ");
txt += node._pbookmark->_url;
}
lstrcpyn(pnmgit->pszText, txt.c_str(), pnmgit->cchTextMax);
}
break;} break;}
} }
@ -1037,7 +1046,7 @@ void MainFrame::FillBookmarks()
TreeView_DeleteAllItems(_hsidebar); TreeView_DeleteAllItems(_hsidebar);
g_Globals._favorites.fill_tree(_hsidebar, TVI_ROOT); g_Globals._favorites.fill_tree(_hsidebar, TVI_ROOT, _himl);
} }
#endif #endif

View file

@ -67,18 +67,113 @@ bool Bookmark::read_url(LPCTSTR path)
} }
/// convert XBEL bookmark node /// convert XBEL bookmark node
bool Bookmark::read_xbel(const_XMLPos& pos) bool Bookmark::read(const_XMLPos& pos)
{ {
_url = pos.get("href"); _url = pos.get("href");
if (!pos.go_down("title")) if (pos.go_down("title")) {
return false;
_name = pos->get_content(); _name = pos->get_content();
pos.back();
}
if (pos.go_down("desc")) {
_description = pos->get_content();
pos.back();
}
if (pos.go_down("info")) {
const_XMLChildrenFilter metadata(pos, "metadata");
for(const_XMLChildrenFilter::const_iterator it=metadata.begin(); it!=metadata.end(); ++it) {
const XMLNode& node = **it;
const_XMLPos sub_pos(&node);
if (node.get("owner") == "ros-explorer") {
if (sub_pos.go_down("icon")) {
_icon_path = sub_pos.get("path");
_icon_idx = _ttoi(sub_pos.get("index"));
sub_pos.back(); // </icon>
}
}
}
pos.back(); // </metadata>
pos.back(); // </info>
}
return !_url.empty(); // _url is mandatory.
}
/// write XBEL bookmark node
void Bookmark::write(XMLPos& pos)
{
pos.create("bookmark");
pos["href"] = _url;
if (!_name.empty()) {
pos.create("title");
pos->set_content(_name);
pos.back();
}
if (!_description.empty()) {
pos.create("desc");
pos->set_content(_description);
pos.back();
}
if (!_icon_path.empty()) {
pos.create("info");
pos.create("metadata");
pos["owner"] = "ros-explorer";
pos.create("icon");
pos["path"] = _icon_path;
pos["index"].printf(TEXT("%d"), _icon_idx);
pos.back(); // </icon>
pos.back(); // </metadata>
pos.back(); // </info>
}
pos.back(); pos.back();
}
return true;
/// read bookmark folder from XBEL formated XML tree
void BookmarkFolder::read(const_XMLPos& pos)
{
if (pos.go_down("title")) {
_name = pos->get_content();
pos.back();
}
if (pos.go_down("desc")) {
_description = pos->get_content();
pos.back();
}
_bookmarks.read(pos);
}
/// write bookmark folder conten from XBEL formated XML tree
void BookmarkFolder::write(XMLPos& pos)
{
pos.create("folder");
if (!_name.empty()) {
pos.create("title");
pos->set_content(_name);
pos.back();
}
if (!_description.empty()) {
pos.create("desc");
pos->set_content(_description);
pos.back();
}
_bookmarks.write(pos);
} }
@ -122,20 +217,15 @@ void BookmarkList::read(const_XMLPos& pos)
const_XMLPos sub_pos(&node); const_XMLPos sub_pos(&node);
if (node == "folder") { if (node == "folder") {
BookmarkFolder new_folder; BookmarkFolder folder;
if (sub_pos.go_down("title")) { folder.read(sub_pos);
new_folder._name = sub_pos->get_content();
sub_pos.back();
}
new_folder._bookmarks.read(sub_pos); push_back(folder);
push_back(new_folder);
} else if (node == "bookmark") { } else if (node == "bookmark") {
Bookmark bookmark; Bookmark bookmark;
if (bookmark.read_xbel(sub_pos)) if (bookmark.read(sub_pos))
push_back(bookmark); push_back(bookmark);
} }
} }
@ -150,36 +240,23 @@ void BookmarkList::write(XMLPos& pos) const
if (node._type == BookmarkNode::BMNT_FOLDER) { if (node._type == BookmarkNode::BMNT_FOLDER) {
BookmarkFolder& folder = *node._pfolder; BookmarkFolder& folder = *node._pfolder;
pos.create("folder"); folder.write(pos);
pos.create("title");
pos->set_content(folder._name);
pos.back();
folder._bookmarks.write(pos);
pos.back(); pos.back();
} else { // BookmarkNode::BMNT_BOOKMARK } else { // BookmarkNode::BMNT_BOOKMARK
Bookmark& bookmark = *node._pbookmark; Bookmark& bookmark = *node._pbookmark;
if (!bookmark._url.empty()) { if (!bookmark._url.empty())
pos.create("bookmark"); bookmark.write(pos);
pos["href"] = bookmark._url;
pos.create("title");
pos->set_content(bookmark._name);
pos.back();
pos.back();
}
} }
} }
} }
void BookmarkList::fill_tree(HWND hwnd, HTREEITEM parent) const void BookmarkList::fill_tree(HWND hwnd, HTREEITEM parent, HIMAGELIST himagelist) const
{ {
HDC hdc = GetDC(hwnd);
TV_INSERTSTRUCT tvi; TV_INSERTSTRUCT tvi;
tvi.hParent = parent; tvi.hParent = parent;
@ -201,16 +278,27 @@ void BookmarkList::fill_tree(HWND hwnd, HTREEITEM parent) const
tv.iSelectedImage = 4; tv.iSelectedImage = 4;
HTREEITEM hitem = TreeView_InsertItem(hwnd, &tvi); HTREEITEM hitem = TreeView_InsertItem(hwnd, &tvi);
folder._bookmarks.fill_tree(hwnd, hitem); folder._bookmarks.fill_tree(hwnd, hitem, himagelist);
} else { } else {
const Bookmark& bookmark = *node._pbookmark; const Bookmark& bookmark = *node._pbookmark;
tv.pszText = (LPTSTR)bookmark._name.c_str(); tv.pszText = (LPTSTR)bookmark._name.c_str();
tv.iImage = 0; tv.iImage = 0;
tv.iSelectedImage = 1; tv.iSelectedImage = 1;
if (!bookmark._icon_path.empty()) {
///@todo retreive "http://.../favicon.ico" icons
const Icon& icon = g_Globals._icon_cache.extract(bookmark._icon_path, bookmark._icon_idx);
if ((ICON_ID)icon != ICID_NONE)
tv.iImage = tv.iSelectedImage = ImageList_Add(himagelist, icon.create_bitmap(RGB(255,255,255), GetStockBrush(WHITE_BRUSH), hdc), 0);
}
TreeView_InsertItem(hwnd, &tvi); TreeView_InsertItem(hwnd, &tvi);
} }
} }
ReleaseDC(hwnd, hdc);
} }

View file

@ -37,7 +37,8 @@ struct Bookmark
int _icon_idx; int _icon_idx;
bool read_url(LPCTSTR path); bool read_url(LPCTSTR path);
bool read_xbel(const_XMLPos& pos); bool read(const_XMLPos& pos);
void write(XMLPos& pos);
}; };
struct BookmarkFolder; struct BookmarkFolder;
@ -68,7 +69,7 @@ struct BookmarkList : public list<BookmarkNode>
void read(const_XMLPos& pos); void read(const_XMLPos& pos);
void write(XMLPos& pos) const; void write(XMLPos& pos) const;
void fill_tree(HWND hwnd, HTREEITEM parent) const; void fill_tree(HWND hwnd, HTREEITEM parent, HIMAGELIST) const;
}; };
struct BookmarkFolder struct BookmarkFolder
@ -76,6 +77,9 @@ struct BookmarkFolder
String _name; String _name;
String _description; String _description;
BookmarkList _bookmarks; BookmarkList _bookmarks;
void read(const_XMLPos& pos);
void write(XMLPos& pos);
}; };
struct Favorites : public BookmarkList struct Favorites : public BookmarkList

View file

@ -733,11 +733,6 @@ struct const_XMLChildrenFilter
return *_cur; return *_cur;
} }
XMLNode* operator*()
{
return *_cur;
}
const_iterator& operator++() const_iterator& operator++()
{ {
++_cur; ++_cur;