Exemplo n.º 1
0
entry_ref *
listview::FindItem()
{
//	char		string[512];
	int32		index;
	entry_ref	*ref = NULL;
//	status_t	result;
	TListItem	*item;
	
	index = fList->CurrentSelection();
	item = dynamic_cast<TListItem *>(fList->ItemAt(index));
	if (item)
	{
		ref = item->Ref();
		if (ref) 
			return(ref);
	}
	return NULL;
}
Exemplo n.º 2
0
void
RocketView::MouseDown(BPoint where)
{
	// focus the list for scrolling
	MakeFocus(true);	
	
	uint32 buttons;
	
	// retrieve the button state from the MouseDown message
	if (Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons) == B_NO_ERROR) 
	{
		// find item at the mouse location
		int32 item = IndexOf(where);
		// make sure item is valid
		if ((item >= 0) && (item < CountItems())) 
		{
			// if clicked with second mouse button, let's do a context-sensitive menu
			if (buttons & B_SECONDARY_MOUSE_BUTTON) 
			{
				BPoint	point = where;
				ConvertToScreen(&point);
				// select this item
				Select(item);
				
				//see if we need to enable some features
				//mark as source
				int32		index;
				entry_ref	*ref = NULL;
				TListItem	*item;
				
				//finds selected item	
				index = CurrentSelection();
				item = dynamic_cast<TListItem *>(ItemAt(index));
				if (item)
					ref = item->Ref();
  
				BNode node(ref);
				BNodeInfo nodeInfo(&node);
				char type[256];
				nodeInfo.GetType(type);
				BString t;
				t << type;
/*				
				if (t == "text/x-source-code")
					mnuLeft->ItemAt(0)->SetEnabled(false);
				else
					mnuLeft->ItemAt(0)->SetEnabled(true);
*/				
				mnuLeft->Go(point, true,true,(BRect(point.x,point.y,point.x + 1,point.y + 1)),true);
				return;
				
			}
			else if (buttons & B_PRIMARY_MOUSE_BUTTON) 
			{
				if (CurrentSelection() == item)
					Invoke();
				else
					Select(item);
			}
			 
		}
	}
}
Exemplo n.º 3
0
void
TEnclosuresView::MessageReceived(BMessage *msg)
{
	switch (msg->what)
	{
		case LIST_INVOKED:
		{
			BListView *list;
			msg->FindPointer("source", (void **)&list);
			if (list)
			{
				TListItem *item = (TListItem *) (list->ItemAt(msg->FindInt32("index")));
				if (item)
				{
					BMessenger tracker("application/x-vnd.Be-TRAK");
					if (tracker.IsValid())
					{
						BMessage message(B_REFS_RECEIVED);
						message.AddRef("refs", item->Ref());

						tracker.SendMessage(&message);
					}
				}
			}
			break;
		}

		case M_REMOVE:
		{
			int32 index;
			while ((index = fList->CurrentSelection()) >= 0)
			{
				TListItem *item = (TListItem *) fList->ItemAt(index);
				fList->RemoveItem(index);

				if (item->Component())
				{
					TMailWindow *window = dynamic_cast<TMailWindow *>(Window());
					if (window && window->Mail())
						window->Mail()->RemoveComponent(item->Component());

					(new BAlert("", TR(
						"Removing attachments from a forwarded mail is not yet "
						"implemented!\nIt will not yet work correctly."),
						TR("OK")))->Go();
				}
				else
					watch_node(item->NodeRef(), B_STOP_WATCHING, this);
				delete item;
			}
			break;
		}

		case M_SELECT:
			fList->Select(0, fList->CountItems() - 1, true);
			break;

		case B_SIMPLE_DATA:
		case B_REFS_RECEIVED:
		case REFS_RECEIVED:
			if (msg->HasRef("refs"))
			{
				bool badType = false;

				int32 index = 0;
				entry_ref ref;
				while (msg->FindRef("refs", index++, &ref) == B_NO_ERROR)
				{
					BFile file(&ref, O_RDONLY);
					if (file.InitCheck() == B_OK && file.IsFile())
					{
						TListItem *item;
						for (int16 loop = 0; loop < fList->CountItems(); loop++)
						{
							item = (TListItem *) fList->ItemAt(loop);
							if (ref == *(item->Ref()))
							{
								fList->Select(loop);
								fList->ScrollToSelection();
								continue;
							}
						}
						fList->AddItem(item = new TListItem(&ref));
						fList->Select(fList->CountItems() - 1);
						fList->ScrollToSelection();
						
						watch_node(item->NodeRef(), B_WATCH_NAME, this);
					}
					else
						badType = true;
				}
				if (badType)
				{
					beep();
					(new BAlert("",
						TR("Only files can be added as attachments."),
						TR("OK")))->Go();
				}
			}
			break;

		case B_NODE_MONITOR:
		{
			int32 opcode;
			if (msg->FindInt32("opcode", &opcode) == B_NO_ERROR)
			{
				dev_t device;
				if (msg->FindInt32("device", &device) < B_OK)
					break;
				ino_t inode;
				if (msg->FindInt64("node", &inode) < B_OK)
					break;

				for (int32 index = fList->CountItems();index-- > 0;)
				{
					TListItem *item = static_cast<TListItem *>(fList->ItemAt(index));

					if (device == item->NodeRef()->device
						&& inode == item->NodeRef()->node)
					{
						if (opcode == B_ENTRY_REMOVED)
						{
							// don't hide the <missing attachment> item

							//fList->RemoveItem(index);
							//
							//watch_node(item->NodeRef(), B_STOP_WATCHING, this);
							//delete item;
						}
						else if (opcode == B_ENTRY_MOVED)
						{
							item->Ref()->device = device;
							msg->FindInt64("to directory", &item->Ref()->directory);

							const char *name;
							msg->FindString("name", &name);
							item->Ref()->set_name(name);
						}

						fList->InvalidateItem(index);
						break;
					}
				}
			}
			break;
		}

		default:
			BView::MessageReceived(msg);
	}
}