Web+: move BookmarbKar to own file.
It's a bit long for an inline class, and I'm going to add more stuff to it.
This commit is contained in:
@@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014, Adrien Destugues <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "BookmarkBar.h"
|
||||||
|
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <IconMenuItem.h>
|
||||||
|
#include <Messenger.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "NavMenu.h"
|
||||||
|
|
||||||
|
|
||||||
|
BookmarkBar::BookmarkBar(const char* title, BHandler* target,
|
||||||
|
const entry_ref* navDir)
|
||||||
|
: BMenuBar(title)
|
||||||
|
{
|
||||||
|
BEntry(navDir).GetNodeRef(&fNodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BookmarkBar::~BookmarkBar()
|
||||||
|
{
|
||||||
|
stop_watching(BMessenger(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BookmarkBar::AttachedToWindow()
|
||||||
|
{
|
||||||
|
BMenuBar::AttachedToWindow();
|
||||||
|
watch_node(&fNodeRef, B_WATCH_DIRECTORY, BMessenger(this));
|
||||||
|
|
||||||
|
// Enumerate initial directory content
|
||||||
|
BDirectory dir(&fNodeRef);
|
||||||
|
BEntry bookmark;
|
||||||
|
while(dir.GetNextEntry(&bookmark) == B_OK) {
|
||||||
|
node_ref ref;
|
||||||
|
bookmark.GetNodeRef(&ref);
|
||||||
|
_AddItem(ref.node, &bookmark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BookmarkBar::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
switch(message->what) {
|
||||||
|
case B_NODE_MONITOR:
|
||||||
|
{
|
||||||
|
int32 opcode = message->FindInt32("opcode");
|
||||||
|
ino_t inode = message->FindInt64("node");
|
||||||
|
switch(opcode) {
|
||||||
|
case B_ENTRY_CREATED:
|
||||||
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
message->FindInt32("device", &ref.device);
|
||||||
|
message->FindInt64("directory", &ref.directory);
|
||||||
|
message->FindString("name", &name);
|
||||||
|
ref.set_name(name);
|
||||||
|
|
||||||
|
BEntry entry(&ref);
|
||||||
|
_AddItem(inode, &entry);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B_ENTRY_MOVED:
|
||||||
|
{
|
||||||
|
if (fItemsMap[inode] == NULL)
|
||||||
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
message->FindInt32("device", &ref.device);
|
||||||
|
message->FindInt64("to directory", &ref.directory);
|
||||||
|
message->FindString("name", &name);
|
||||||
|
ref.set_name(name);
|
||||||
|
|
||||||
|
BEntry entry(&ref);
|
||||||
|
_AddItem(inode, &entry);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// Existing item. Check if it's a rename or a move
|
||||||
|
// to some other folder.
|
||||||
|
ino_t from, to;
|
||||||
|
message->FindInt64("to directory", &to);
|
||||||
|
message->FindInt64("from directory", &from);
|
||||||
|
if (from == to)
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
message->FindString("name", &name);
|
||||||
|
fItemsMap[inode]->SetLabel(name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fall through: the item was moved from here to
|
||||||
|
// elsewhere, remove it from the bar.
|
||||||
|
}
|
||||||
|
case B_ENTRY_REMOVED:
|
||||||
|
{
|
||||||
|
IconMenuItem* item = fItemsMap[inode];
|
||||||
|
RemoveItem(item);
|
||||||
|
fItemsMap.erase(inode);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BMenuBar::MessageReceived(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BookmarkBar::_AddItem(ino_t inode, BEntry* entry)
|
||||||
|
{
|
||||||
|
char name[B_FILE_NAME_LENGTH];
|
||||||
|
entry->GetName(name);
|
||||||
|
|
||||||
|
// make sure the item doesn't already exists
|
||||||
|
if (fItemsMap[inode] != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
entry->GetRef(&ref);
|
||||||
|
|
||||||
|
IconMenuItem* item = NULL;
|
||||||
|
|
||||||
|
if(entry->IsDirectory()) {
|
||||||
|
BNavMenu* menu = new BNavMenu(name, B_REFS_RECEIVED, Window());
|
||||||
|
menu->SetNavDir(&ref);
|
||||||
|
item = new IconMenuItem(menu, NULL,
|
||||||
|
"application/x-vnd.Be-directory", B_MINI_ICON);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
BNode node(entry);
|
||||||
|
BNodeInfo info(&node);
|
||||||
|
|
||||||
|
BMessage* message = new BMessage(B_REFS_RECEIVED);
|
||||||
|
message->AddRef("refs", &ref);
|
||||||
|
item = new IconMenuItem(name, message, &info,
|
||||||
|
B_MINI_ICON);
|
||||||
|
}
|
||||||
|
|
||||||
|
BMenuBar::AddItem(item);
|
||||||
|
fItemsMap[inode] = item;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014, Adrien Destugues <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef BOOKMARK_BAR_H
|
||||||
|
#define BOOKMARK_BAR_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <MenuBar.h>
|
||||||
|
#include <Node.h>
|
||||||
|
#include <NodeMonitor.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BEntry;
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
class IconMenuItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BookmarkBar: public BMenuBar {
|
||||||
|
public:
|
||||||
|
BookmarkBar(const char* title,
|
||||||
|
BHandler* target,
|
||||||
|
const entry_ref* navDir);
|
||||||
|
~BookmarkBar();
|
||||||
|
|
||||||
|
void AttachedToWindow();
|
||||||
|
void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _AddItem(ino_t inode, BEntry* entry);
|
||||||
|
|
||||||
|
private:
|
||||||
|
node_ref fNodeRef;
|
||||||
|
std::map<ino_t, BPrivate::IconMenuItem*> fItemsMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // BOOKMARK_BAR_H
|
||||||
@@ -74,6 +74,7 @@
|
|||||||
#include "AuthenticationPanel.h"
|
#include "AuthenticationPanel.h"
|
||||||
#include "BaseURL.h"
|
#include "BaseURL.h"
|
||||||
#include "BitmapButton.h"
|
#include "BitmapButton.h"
|
||||||
|
#include "BookmarkBar.h"
|
||||||
#include "BrowserApp.h"
|
#include "BrowserApp.h"
|
||||||
#include "BrowsingHistory.h"
|
#include "BrowsingHistory.h"
|
||||||
#include "CredentialsStorage.h"
|
#include "CredentialsStorage.h"
|
||||||
@@ -176,142 +177,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BookmarkBar: public BMenuBar {
|
|
||||||
public:
|
|
||||||
BookmarkBar(const char* title, BHandler* target, const entry_ref* navDir)
|
|
||||||
: BMenuBar(title)
|
|
||||||
{
|
|
||||||
BEntry(navDir).GetNodeRef(&fNodeRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
~BookmarkBar()
|
|
||||||
{
|
|
||||||
stop_watching(BMessenger(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AttachedToWindow()
|
|
||||||
{
|
|
||||||
BMenuBar::AttachedToWindow();
|
|
||||||
watch_node(&fNodeRef, B_WATCH_DIRECTORY, BMessenger(this));
|
|
||||||
|
|
||||||
// Enumerate initial directory content
|
|
||||||
BDirectory dir(&fNodeRef);
|
|
||||||
BEntry bookmark;
|
|
||||||
while(dir.GetNextEntry(&bookmark) == B_OK) {
|
|
||||||
node_ref ref;
|
|
||||||
bookmark.GetNodeRef(&ref);
|
|
||||||
AddItem(ref.node, &bookmark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MessageReceived(BMessage* message)
|
|
||||||
{
|
|
||||||
switch(message->what) {
|
|
||||||
case B_NODE_MONITOR:
|
|
||||||
int32 opcode = message->FindInt32("opcode");
|
|
||||||
ino_t inode = message->FindInt64("node");
|
|
||||||
switch(opcode) {
|
|
||||||
case B_ENTRY_CREATED:
|
|
||||||
{
|
|
||||||
entry_ref ref;
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
message->FindInt32("device", &ref.device);
|
|
||||||
message->FindInt64("directory", &ref.directory);
|
|
||||||
message->FindString("name", &name);
|
|
||||||
ref.set_name(name);
|
|
||||||
|
|
||||||
BEntry entry(&ref);
|
|
||||||
AddItem(inode, &entry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case B_ENTRY_MOVED:
|
|
||||||
{
|
|
||||||
if (fItemsMap[inode] == NULL)
|
|
||||||
{
|
|
||||||
entry_ref ref;
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
message->FindInt32("device", &ref.device);
|
|
||||||
message->FindInt64("to directory", &ref.directory);
|
|
||||||
message->FindString("name", &name);
|
|
||||||
ref.set_name(name);
|
|
||||||
|
|
||||||
BEntry entry(&ref);
|
|
||||||
AddItem(inode, &entry);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
// Existing item. Check if it's a rename or a move
|
|
||||||
// to some other folder.
|
|
||||||
ino_t from, to;
|
|
||||||
message->FindInt64("to directory", &to);
|
|
||||||
message->FindInt64("from directory", &from);
|
|
||||||
if (from == to)
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
message->FindString("name", &name);
|
|
||||||
fItemsMap[inode]->SetLabel(name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fall through: the item was moved from here to
|
|
||||||
// elsewhere, remove it from the bar.
|
|
||||||
}
|
|
||||||
case B_ENTRY_REMOVED:
|
|
||||||
{
|
|
||||||
IconMenuItem* item = fItemsMap[inode];
|
|
||||||
RemoveItem(item);
|
|
||||||
fItemsMap.erase(inode);
|
|
||||||
delete item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BMenuBar::MessageReceived(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void AddItem(ino_t inode, BEntry* entry)
|
|
||||||
{
|
|
||||||
char name[B_FILE_NAME_LENGTH];
|
|
||||||
entry->GetName(name);
|
|
||||||
|
|
||||||
// make sure the item doesn't already exists
|
|
||||||
if (fItemsMap[inode] != NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
entry_ref ref;
|
|
||||||
entry->GetRef(&ref);
|
|
||||||
|
|
||||||
IconMenuItem* item = NULL;
|
|
||||||
|
|
||||||
if(entry->IsDirectory()) {
|
|
||||||
BNavMenu* menu = new BNavMenu(name, B_REFS_RECEIVED, Window());
|
|
||||||
menu->SetNavDir(&ref);
|
|
||||||
item = new IconMenuItem(menu, NULL,
|
|
||||||
"application/x-vnd.Be-directory", B_MINI_ICON);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
BNode node(entry);
|
|
||||||
BNodeInfo info(&node);
|
|
||||||
|
|
||||||
BMessage* message = new BMessage(B_REFS_RECEIVED);
|
|
||||||
message->AddRef("refs", &ref);
|
|
||||||
item = new IconMenuItem(name, message, &info,
|
|
||||||
B_MINI_ICON);
|
|
||||||
}
|
|
||||||
|
|
||||||
BMenuBar::AddItem(item);
|
|
||||||
fItemsMap[inode] = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
node_ref fNodeRef;
|
|
||||||
std::map<ino_t, IconMenuItem*> fItemsMap;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class PageUserData : public BWebView::UserData {
|
class PageUserData : public BWebView::UserData {
|
||||||
public:
|
public:
|
||||||
PageUserData(BView* focusedView)
|
PageUserData(BView* focusedView)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ local sources =
|
|||||||
# support
|
# support
|
||||||
BaseURL.cpp
|
BaseURL.cpp
|
||||||
BitmapButton.cpp
|
BitmapButton.cpp
|
||||||
|
BookmarkBar.cpp
|
||||||
FontSelectionView.cpp
|
FontSelectionView.cpp
|
||||||
SettingsMessage.cpp
|
SettingsMessage.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
char*
|
||||||
|
strdup(const char *string)
|
||||||
|
{
|
||||||
|
char* copied;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
|
// unlike the standard strdup() function, the BeOS implementation
|
||||||
|
// handles NULL strings gracefully
|
||||||
|
if (string == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
length = strlen(string) + 1;
|
||||||
|
|
||||||
|
if ((copied = (char *)malloc(length)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
memcpy(copied, string, length);
|
||||||
|
return copied;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user