Beispiel #1
0
void
BDirMenu::AddItemToDirMenu(const BEntry* entry, BWindow* originatingWindow,
	bool atEnd, bool addShortcuts, bool navMenuEntries)
{
	Model model(entry);
	if (model.InitCheck() != B_OK)
		return;

	BMessage* message = new BMessage(fCommand);
	message->AddRef(fEntryName.String(), model.EntryRef());

	// add reference to the container windows model so that we can
	// close the window if
	BContainerWindow* window = originatingWindow ?
		dynamic_cast<BContainerWindow*>(originatingWindow) : 0;
	if (window)
		message->AddData("nodeRefsToClose", B_RAW_TYPE,
			window->TargetModel()->NodeRef(), sizeof (node_ref));
	ModelMenuItem* item;
	if (navMenuEntries) {
		BNavMenu* subMenu = new BNavMenu(model.Name(), B_REFS_RECEIVED,
			fTarget, window);
		entry_ref ref;
		entry->GetRef(&ref);
		subMenu->SetNavDir(&ref);
		item = new ModelMenuItem(&model, subMenu);
		item->SetLabel(model.Name());
		item->SetMessage(message);
	} else {
		item = new ModelMenuItem(&model, model.Name(), message);
	}

	if (addShortcuts) {
		if (model.IsDesktop())
			item->SetShortcut('D', B_COMMAND_KEY);
		else if (FSIsHomeDir(entry))
			item->SetShortcut('H', B_COMMAND_KEY);
	}

	if (atEnd)
		AddItem(item);
	else
		AddItem(item, 0);

	item->SetTarget(fTarget);

	if (fMenuBar) {
		ModelMenuItem* menu
			= dynamic_cast<ModelMenuItem*>(fMenuBar->ItemAt(0));
		if (menu) {
			ThrowOnError(menu->SetEntry(entry));
			item->SetMarked(true);
		}
	}
}
Beispiel #2
0
bool
TRecentsMenu::AddRecents(int32 count)
{
	if (fItemIndex == 0) {
		fRecentList.MakeEmpty();
		BRoster roster;

		switch (fWhich) {
			case kRecentDocuments:
				roster.GetRecentDocuments(&fRecentList, count);
				break;
			case kRecentApplications:
				roster.GetRecentApps(&fRecentList, count);
				break;
			case kRecentAppDocuments:
				roster.GetRecentDocuments(&fRecentList, count, NULL,
					fSignature);
				break;
			case kRecentFolders:
				roster.GetRecentFolders(&fRecentList, count);
				break;
			default:
				return false;
		}
	}

	for (;;) {
		entry_ref ref;
		if (fRecentList.FindRef("refs", fItemIndex++, &ref) != B_OK)
			break;

		if (ref.name && strlen(ref.name) > 0) {
			Model model(&ref, true);

			if (fWhich != kRecentApplications) {
				BMessage* message = new BMessage(B_REFS_RECEIVED);
				if (fWhich == kRecentAppDocuments) {
					// add application as handler
					message->AddRef("handler", fAppRef);
				}

				ModelMenuItem* item = BNavMenu::NewModelItem(&model,
					message, Target(), false, NULL, TypesList());

				if (item)
					AddItem(item);
			} else {
				// The application items expand to a list of recent documents
				// for that application - so they must be handled extra
				BFile file(&ref, B_READ_ONLY);
				char signature[B_MIME_TYPE_LENGTH];

				BAppFileInfo appInfo(&file);
				if (appInfo.InitCheck() != B_OK
					|| appInfo.GetSignature(signature) != B_OK)
					continue;

				ModelMenuItem* item = NULL;
				BMessage doc;
				be_roster->GetRecentDocuments(&doc, 1, NULL, signature);
					// ToDo: check if the documents do exist at all to
					//		avoid the creation of the submenu.

				if (doc.CountNames(B_REF_TYPE) > 0) {
					// create recents menu that will contain the recent docs of
					// this app
					TRecentsMenu* docs = new TRecentsMenu(model.Name(),
						fBarView, kRecentAppDocuments, signature, &ref);
					docs->SetTypesList(TypesList());
					docs->SetTarget(Target());

					item = new ModelMenuItem(&model, docs);
				} else
					item = new ModelMenuItem(&model, model.Name(), NULL);

				if (item) {
					// add refs-message so that the recent app can be launched
					BMessage* msg = new BMessage(B_REFS_RECEIVED);
					msg->AddRef("refs", &ref);
					item->SetMessage(msg);
					item->SetTarget(Target());

					AddItem(item);
				}
			}

			// return true so that we know to reenter this list
			return true;
		}
	}

	// return false if we are done with this list
	return false;
}
Beispiel #3
0
BMenuItem*
BRecentItemsList::GetNextMenuItem(const BMessage* fileOpenInvokeMessage,
	const BMessage* containerOpenInvokeMessage, BHandler* target,
	entry_ref* currentItemRef)
{
	entry_ref ref;
	if (GetNextRef(&ref) != B_OK)
		return NULL;

	Model model(&ref, true);
	if (model.InitCheck() != B_OK)
		return NULL;

	bool container = false;
	if (model.IsSymLink()) {

		Model* newResolvedModel = NULL;
		Model* result = model.LinkTo();

		if (result == NULL) {
			newResolvedModel = new Model(model.EntryRef(), true, true);

			if (newResolvedModel->InitCheck() != B_OK) {
				// broken link, still can show though, bail
				delete newResolvedModel;
				result = NULL;
			} else
				result = newResolvedModel;
		} else {
			BModelOpener opener(result);
				// open the model, if it ain't open already

			PoseInfo poseInfo;
			BNode* resultNode = result->Node();
			if (resultNode != NULL) {
				resultNode->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0,
					&poseInfo, sizeof(poseInfo));
			}

			result->CloseNode();

			ref = *result->EntryRef();
			container = result->IsContainer();
		}
		model.SetLinkTo(result);
	} else {
		ref = *model.EntryRef();
		container = model.IsContainer();
	}

	// if user asked for it, return the current item ref
	if (currentItemRef != NULL)
		*currentItemRef = ref;

	BMessage* message;
	if (container && containerOpenInvokeMessage)
		message = new BMessage(*containerOpenInvokeMessage);
	else if (!container && fileOpenInvokeMessage)
		message = new BMessage(*fileOpenInvokeMessage);
	else
		message = new BMessage(B_REFS_RECEIVED);

	message->AddRef("refs", model.EntryRef());

	// Truncate the name if necessary
	BString truncatedString(model.Name());
	be_plain_font->TruncateString(&truncatedString, B_TRUNCATE_END,
		BNavMenu::GetMaxMenuWidth());

	ModelMenuItem* item = NULL;
	if (!container || !fNavMenuFolders)
		item = new ModelMenuItem(&model, truncatedString.String(), message);
	else {
		// add another nav menu item if it's a directory
		BNavMenu* menu = new BNavMenu(truncatedString.String(), message->what,
			target, 0);

		menu->SetNavDir(&ref);
		item = new ModelMenuItem(&model, menu);
		item->SetMessage(message);
	}

	if (item != NULL && target != NULL)
		item->SetTarget(target);

	return item;
}