Ejemplo n.º 1
0
void BrowseView::FindInIndex(bool select, const char *s)
{
	if (s==NULL)
		s = searchTextView->Text();
	BString str(s);
	
	if(!containsSearch)
	{
		unsigned int nL = linksList->CountItems();
	
		for (unsigned int i=0; i<nL; i++)
		{
			BStringItem *it = (BStringItem*)linksList->ItemAt(i);
			if (str.ICompare(it->Text()) <= 0)
			{
				BRect r = linksList->ItemFrame(i);
				linksList->ScrollTo(r.LeftTop());
			
				if (select)
					linksList->Select(i);
				break;
			}
		}
	}
	else
	{
		tasks->GiveUp();
		linksList->MakeEmpty();

		if (str == "")
			return;

		tasks->DoFindInIndex(str,this,select);			
	}
}
Ejemplo n.º 2
0
void
BreakConditionConfigWindow::_UpdateStopImageState()
{
	bool previousStop = fStopOnLoadEnabled;
	bool previousCustomImages = fUseCustomImages && fStopOnLoadEnabled;

	fStopOnLoadEnabled = fTeam->StopOnImageLoad();
	fStopOnImageLoad->SetValue(
		fStopOnLoadEnabled ? B_CONTROL_ON : B_CONTROL_OFF);
	fUseCustomImages = fTeam->StopImageNameListEnabled();
	fStopImageConstraints->Menu()
		->ItemAt(fTeam->StopImageNameListEnabled() ? 1 : 0)->SetMarked(true);

	fStopImageNames->MakeEmpty();
	const BStringList& imageNames = fTeam->StopImageNames();
	for (int32 i = 0; i < imageNames.CountStrings(); i++) {
		BStringItem* item = new(std::nothrow) BStringItem(
			imageNames.StringAt(i));
		if (item == NULL)
			return;
		item->SetEnabled(fUseCustomImages);
		ObjectDeleter<BStringItem> itemDeleter(item);
		if (!fStopImageNames->AddItem(item))
			return;
		itemDeleter.Detach();
	}

	_UpdateStopImageButtons(previousStop, previousCustomImages);
}
Ejemplo n.º 3
0
void
MidiSettingsView::_LoadSettings()
{
	// TODO: Duplicated code between here
	// and BSoftSynth::SetDefaultInstrumentsFile
	char buffer[512];
	BPath path;
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
		path.Append(SETTINGS_FILE);
		BFile file(path.Path(), B_READ_ONLY);
		if (file.InitCheck() == B_OK) {
			file.Read(buffer, sizeof(buffer));
			char soundFont[512];
			sscanf(buffer, "# Midi Settings\n soundfont = %s\n",
				soundFont);

			for (int32 i = 0; i < fListView->CountItems(); i++) {
				BStringItem* item = (BStringItem*)fListView->ItemAt(i);
				if (!strcmp(item->Text(), soundFont)) {
					fListView->Select(i);
					break;
				}
			}
		}
	}
}
Ejemplo n.º 4
0
BStringItem*
CookieWindow::_AddDomain(BString domain, bool fake)
{
	BStringItem* parent = NULL;
	int firstDot = domain.FindFirst('.');
	if (firstDot >= 0) {
		BString parentDomain(domain);
		parentDomain.Remove(0, firstDot + 1);
		parent = _AddDomain(parentDomain, true);
	} else {
		parent = (BStringItem*)fDomains->FullListItemAt(0);
	}

	BListItem* existing;
	int i = 0;
	// check that we aren't already there
	while ((existing = fDomains->ItemUnderAt(parent, true, i++)) != NULL) {
		DomainItem* stringItem = (DomainItem*)existing;
		if (stringItem->Text() == domain) {
			if (fake == false)
				stringItem->fEmpty = false;
			return stringItem;
		}
	}

#if 0
	puts("==============================");
	for (i = 0; i < fDomains->FullListCountItems(); i++) {
		BStringItem* t = (BStringItem*)fDomains->FullListItemAt(i);
		for (unsigned j = 0; j < t->OutlineLevel(); j++)
			printf("  ");
		printf("%s\n", t->Text());
	}
#endif

	// Insert the new item, keeping the list alphabetically sorted
	BStringItem* domainItem = new DomainItem(domain, fake);
	domainItem->SetOutlineLevel(parent->OutlineLevel() + 1);
	BStringItem* sibling = NULL;
	int siblingCount = fDomains->CountItemsUnder(parent, true);
	for (i = 0; i < siblingCount; i++) {
		sibling = (BStringItem*)fDomains->ItemUnderAt(parent, true, i);
		if (strcmp(sibling->Text(), domainItem->Text()) > 0) {
			fDomains->AddItem(domainItem, fDomains->FullListIndexOf(sibling));
			return domainItem;
		}
	}

	if (sibling) {
		// There were siblings, but all smaller than what we try to insert.
		// Insert after the last one (and its subitems)
		fDomains->AddItem(domainItem, fDomains->FullListIndexOf(sibling)
			+ fDomains->CountItemsUnder(sibling, false) + 1);
	} else {
		// There were no siblings, insert right after the parent
		fDomains->AddItem(domainItem, fDomains->FullListIndexOf(parent) + 1);
	}

	return domainItem;
}
Ejemplo n.º 5
0
void
CookieWindow::MessageReceived(BMessage* message)
{
	switch(message->what) {
		case DOMAIN_SELECTED:
		{
			int32 index = message->FindInt32("index");
			BStringItem* item = (BStringItem*)fDomains->ItemAt(index);
			if (item != NULL) {
				BString domain = item->Text();
				_ShowCookiesForDomain(domain);
			}
			return;
		}

		case COOKIE_REFRESH:
			_BuildDomainList();
			return;

		case COOKIE_DELETE:
			_DeleteCookies();
			return;
	}
	BWindow::MessageReceived(message);
}
//Opens the table that is currently selected using the given view.  Or, if the table
//is already open, brings it to the front.
void BeAccessibleWindow::OpenTable(int view)
{
	DBTabView* tab = (DBTabView*)fTabView->GetCurrentTab();
	BStringItem* selectedTable;
	
	//Find the currently selected table
	if (tab->fListView->CurrentSelection() >= 0)
	{
		selectedTable = (BStringItem*)tab->fListView->ItemAt(
		  					        tab->fListView->CurrentSelection() );
	}
	else
	{
		//No table is selected
		return;
	}
	
	
	if (!WindowExists(selectedTable->Text()))
	{
		//Open a new table window if it isn't already
		fNewGrid = new TableWindow(view, selectedTable->Text());
	}
	else
	{
		//If the table is already open, bring it to the front
		BringWindowToFront(selectedTable->Text());
	}
}
// Gets the user's selection, and parses it up to get the server,
//   then formats a BMessage and sends it to whomever opened the window.
void InexactMatchWindow::Save() 
{
	const char *selectedText;	
	int selection = cdList->CurrentSelection();
	if (selection < 0) 
	{
		beep();
		return;
	}
	
	// Copy the selected string.
	BStringItem *item; 
	item = (BStringItem *) cdList->ItemAt(selection); 
	selectedText = item->Text();
	char *parseStr= new char[strlen(selectedText)+1];
	strcpy(parseStr,selectedText);

	char *disc_id;
	char *category;
	 
	//	Send the response to the CDDB looper
	category = strtok(parseStr," ");
	disc_id = strtok(NULL," ");
	printf("Category is %s.\n",category);
	printf("New ID is %s.\n",disc_id);
	BMessage *msg = new BMessage(CDDB_READ);
	msg->AddString("category",category);
	msg->AddString("disc_id",disc_id);
	replyTo.SendMessage(msg);
	delete parseStr;
	PostMessage(B_QUIT_REQUESTED);
}
static int
StringItemComp(const BListItem* first, const BListItem* second)
{
	BStringItem* firstItem = (BStringItem*)first;
	BStringItem* secondItem = (BStringItem*)second;
	return BPrivate::NaturalCompare(firstItem->Text(), secondItem->Text());
}
Ejemplo n.º 9
0
	void
PrefListView::BuildView(XmlNode *node, int level, BListItem* parent)
{
	if (!node) {
		puts("Rebuild mit NULL?!");
		return;
	}

	int anz = node->Children();

	//printf("BuildView: %s %d einträge\n", node->Attribute("text"), anz);

	if (anz>0) {
		if (level==0) {
			for (int i=0;i<anz;i++) {
				XmlNode* c = (XmlNode*)node->ItemAt(i);
				const char* t = c->Attribute("text");

				BStringItem* item = new BStringItem(t);
				item->SetText( t );

				if (level>0)
					AddUnder(item, parent);
				else
					AddItem(item);

				//printf("Hinzufügen war %d\n", b);

				if (c->Children()>0) {
					BuildView(c, level+1, item);
				}
			}
			DeselectAll();
		}
		else {
			for (int i=anz-1;i>=0;i--) {
				XmlNode* c = (XmlNode*)node->ItemAt(i);
				const char* t = c->Attribute("text");

				BStringItem* item = new BStringItem(t);
				item->SetText( t );

				if (level>0)
					AddUnder(item, parent);
				else
					AddItem(item);

				//printf("Hinzufügen war %d\n", b);

				if (c->Children()>0) {
					BuildView(c, level+1, item);
				}
			}
		}
	}
	else {
		//puts("Tja...");
	}	
}
Ejemplo n.º 10
0
void FreqWindow::SetList(){

	BStringItem *it = NULL;
	for (int32 i=0; i<list->CountItems(); i++){
		it = (BStringItem*)list->ItemAt(i);
		it->Deselect();
		float frequency = atof( it->Text() );
		if (Pool.frequency == frequency){	it->Select();	text->SetValue(Pool.frequency);	}
	}
}
Ejemplo n.º 11
0
void CPathsBox::MessageReceived(BMessage *msg)
{
	try
	{
		entry_ref ref;
		BEntry e;
		BPath p;
		
		if (msg->WasDropped() && msg->HasRef("refs"))
		{
			FailOSErr(msg->FindRef("refs", &ref));
			FailOSErr(e.SetTo(&ref));
			FailOSErr(e.GetPath(&p));
			
			fList->AddItem(new BStringItem(p.Path()));
			
			ListBoxChanged();
		}
		else switch (msg->what)
		{
			case msg_AddPath:
			case msg_ChangePath:
				FailOSErr(msg->FindRef("refs", &ref));
				FailOSErr(e.SetTo(&ref));
				FailOSErr(e.GetPath(&p));
				
				if (msg->what == msg_AddPath)
					fList->AddItem(new BStringItem(p.Path()));
				else
				{
					BStringItem *item;
					FailOSErr(msg->FindPointer("item", (void**)&item));
					if (fList->IndexOf(item) < 0)
						THROW(("item was removed from list!"));
					item->SetText(p.Path());
				}
				
				delete fPanel;
				fPanel = NULL;
				
				ListBoxChanged();
				break;
				
			default:
				CListBox::MessageReceived(msg);
				break;
		}
	}
	catch (HErr& e)
	{
		e.DoError();
	}
} /* CPathsBox::MessageReceived */
Ejemplo n.º 12
0
void
GrepWindow::_OnReportResult(BMessage* message)
{
	CALLED();

	entry_ref ref;
	if (message->FindRef("ref", &ref) != B_OK)
		return;

	type_code type;
	int32 count;
	message->GetInfo("text", &type, &count);

	BStringItem* item = NULL;
	if (fModel->fState == STATE_UPDATE) {
		// During updates because of node monitor events, negatives are
		// also reported (count == 0).
		item = fSearchResults->RemoveResults(ref, count == 0);
	}

	if (count == 0)
		return;

	if (item == NULL) {
		item = new ResultItem(ref);
		fSearchResults->AddItem(item);
		item->SetExpanded(fShowLinesCheckbox->Value() == 1);
	}

	const char* buf;
	while (message->FindString("text", --count, &buf) == B_OK) {
		uchar* temp = (uchar*)strdup(buf);
		uchar* ptr = temp;

		while (true) {
			// replace all non-printable characters by spaces
			uchar c = *ptr;

			if (c == '\0')
				break;

			if (!(c & 0x80) && iscntrl(c))
				*ptr = ' ';

			++ptr;
		}

		fSearchResults->AddUnder(new BStringItem((const char*)temp), item);

		free(temp);
	}
}
Ejemplo n.º 13
0
void
KeymapWindow::_SetListViewSize(BListView* listView)
{
	float minWidth = 0;
	for (int32 i = 0; i < listView->CountItems(); i++) {
		BStringItem* item = (BStringItem*)listView->ItemAt(i);
		float width = listView->StringWidth(item->Text());
		if (width > minWidth)
			minWidth = width;
	}

	listView->SetExplicitMinSize(BSize(minWidth + 8, 32));
}
Ejemplo n.º 14
0
/**
 *	@brief	Gets a string at specified index from the control.
 *	@param[in]	index	index
 *	@param[out]	text	a string value is returned.
 */
void BeListViewAdapter::GetItemText(SInt32 index, MBCString& text)
{
	BListView* listView = getListView();
	BStringItem* listItem = dynamic_cast<BStringItem*>(listView->ItemAt(index));
	if (NULL != listItem)
	{
		text = listItem->Text();
	}
	else
	{
		text.Empty();
	}
}
Ejemplo n.º 15
0
void
SearchApp::LaunchFile(BMessage *message)
{
	BListView *searchResults ;
	int32 index ;
	
	message->FindPointer("source", (void**)&searchResults) ;
	message->FindInt32("index", &index) ;
	BStringItem *result = (BStringItem*)searchResults->ItemAt(index) ;
	
	entry_ref ref ;
	BEntry entry(result->Text()) ;
	entry.GetRef(&ref) ;
	be_roster->Launch(&ref) ;
}
Ejemplo n.º 16
0
bool CPasteFunctionDialog::OKClicked()
{
	bool result = true;
	BStringItem *item = (BStringItem *)fList->ItemAt(fList->CurrentSelection());
	char *cp;
	
	if (item)
	{
		BMessage msg(msg_FunctionChosen);
		const char *s = item->Text();
		
		msg.AddString("string", item->Text());
		
		if (strstr(s, "()") != NULL)
			;
		else if ((cp = strchr(s, '(')) != NULL)
		{
			int start;
			
			start = cp - s + 1;
			
			int end = 0;
			char *sp;
			
			if ((sp = strchr(cp, gListSeparator)) != NULL)
			{
				end = sp - cp - 1;
			}
			
			if (!end && (sp = strchr(cp, ')')) != NULL)
			{
				end = sp - cp - 1;
			}
			
			if (!end)
				end = strlen(s) - start - 1;
			
			msg.AddInt32("start", start);
			msg.AddInt32("stop", end);
		}

		fOwner->PostMessage(&msg, fOwner->GetEditBox());
	}
	else
		result = false;

	return result;
} /* CPasteFunctionDialog::OKClicked */
Ejemplo n.º 17
0
void
GrepWindow::_OnTrimSelection()
{
	if (fSearchResults->CurrentSelection() < 0) {
		BString text;
		text << B_TRANSLATE("Please select the files you wish to keep searching.");
		text << "\n";
		text << B_TRANSLATE("The unselected files will be removed from the list.");
		text << "\n";
		BAlert* alert = new BAlert(NULL, text.String(), B_TRANSLATE("OK"), NULL, NULL,
			B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		return;
	}

	BMessage message;
	BString path;

	for (int32 index = 0; ; index++) {
		BStringItem* item = dynamic_cast<BStringItem*>(
			fSearchResults->ItemAt(index));
		if (item == NULL)
			break;

		if (!item->IsSelected() || item->OutlineLevel() != 0)
			continue;

		if (path == item->Text())
			continue;

		path = item->Text();
		entry_ref ref;
		if (get_ref_for_path(path.String(), &ref) == B_OK)
			message.AddRef("refs", &ref);
	}

	fModel->fDirectory = entry_ref();
		// invalidated on purpose

	fModel->fSelectedFiles.MakeEmpty();
	fModel->fSelectedFiles = message;

	PostMessage(MSG_START_CANCEL);

	_SetWindowTitle();
}
Ejemplo n.º 18
0
bool
KeymapWindow::_SelectCurrentMap(BListView* view)
{
	if (fCurrentMapName.Length() <= 0)
		return false;

	for (int32 i = 0; i < view->CountItems(); i++) {
		BStringItem* current = dynamic_cast<BStringItem *>(view->ItemAt(i));
		if (current != NULL && fCurrentMapName == current->Text()) {
			view->Select(i);
			view->ScrollToSelection();
			return true;
		}
	}

	return false;
}
Ejemplo n.º 19
0
void
GrepWindow::_OnCopyText()
{
	bool onlyCopySelection = true;

	if (fSearchResults->CurrentSelection() < 0)
		onlyCopySelection = false;

	BString buffer;

	for (int32 index = 0; ; index++) {
		BStringItem* item = dynamic_cast<BStringItem*>(
			fSearchResults->ItemAt(index));
		if (item == NULL)
			break;

		if (onlyCopySelection) {
			if (item->IsSelected())
				buffer << item->Text() << "\n";
		} else
			buffer << item->Text() << "\n";
	}

	status_t status = B_OK;

	BMessage* clip = NULL;

	if (be_clipboard->Lock()) {
		be_clipboard->Clear();

		clip = be_clipboard->Data();

		clip->AddData("text/plain", B_MIME_TYPE, buffer.String(),
			buffer.Length());

		status = be_clipboard->Commit();

		if (status != B_OK) {
			be_clipboard->Unlock();
			return;
		}

		be_clipboard->Unlock();
	}
}
Ejemplo n.º 20
0
ListChooseWindow::ListChooseWindow(list<string>* strL, string title, 
	string text1, string text2, string str) : 
	BWindow(BRect(200, 200, 415, 400), title.c_str(),
	B_FLOATING_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, 
	B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_CLOSABLE)
{
	BRect rect(200, 200, 415, 400);
	rect.OffsetTo(0, 0);
	BView* backview = new BView(rect, "ListChooseBackView", 0, B_WILL_DRAW);
	backview->SetViewColor(222, 222, 222);
	AddChild(backview);
	
	BStringView* sv = new BStringView(BRect(15, 5, 185, 20),
		"ListChooseSV", text1.c_str());
	backview->AddChild(sv);
	sv = new BStringView(BRect(15, 20, 185, 33),
		"ListChooseSV", text2.c_str());
	backview->AddChild(sv);

	lv = new BListView(BRect(15, 40, 185, 153), "ListChooseLV");
	backview->AddChild(new BScrollView("scrollregister", lv,
		B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true));

	BStringItem* si;
	for (list<string>::iterator iter = strL->begin(); iter !=
		strL->end(); iter++)
	{
		si = new BStringItem((*iter).c_str());
		lv->AddItem(si);
		if (*iter == str)
			si->SetEnabled(false);
	}
	
	BButton* button = new BButton(BRect(15, 165, 95, 185), "okB",
		"OK", new BMessage(ListChooseOKMSG));
	backview->AddChild(button);
	button->MakeDefault(true);
	button = new BButton(BRect(105, 165, 200, 185), "cancelB",
		"Cancel", new BMessage(ListChooseCancelMSG));
	backview->AddChild(button);
	
	clickWait = create_sem(0, "clickWait");
}
Ejemplo n.º 21
0
void
GrepWindow::_OnInvokeItem()
{
	for (int32 selectionIndex = 0; ; selectionIndex++) {
		int32 itemIndex = fSearchResults->CurrentSelection(selectionIndex);
		BListItem* item = fSearchResults->ItemAt(itemIndex);
		if (item == NULL)
			break;

		int32 level = item->OutlineLevel();
		int32 lineNum = -1;

		// Get the line number.
		// only this level has line numbers
		if (level == 1) {
			BStringItem* str = dynamic_cast<BStringItem*>(item);
			if (str != NULL) {
				lineNum = atol(str->Text());
					// fortunately, atol knows when to stop the conversion
			}
		}

		// Get the top-most item and launch its entry_ref.
		while (level != 0) {
			item = fSearchResults->Superitem(item);
			if (item == NULL)
				break;
			level = item->OutlineLevel();
		}

		ResultItem* entry = dynamic_cast<ResultItem*>(item);
		if (entry != NULL) {
			bool done = false;

			if (fModel->fInvokePe)
				done = _OpenInPe(entry->ref, lineNum);

			if (!done)
				be_roster->Launch(&entry->ref);
		}
	}
}
Ejemplo n.º 22
0
BStringItem * GuideWindow::modifyGuide(BMessage *msg)
{
	int32 point;
	int32 list;
	
	BStringItem *item = getFocusSelectedItem();
	if(item) {
		point = atoi(item->Text());
		msg->AddInt32("point", point);
		list = _tv_gridguides->Selection();
		if(list == 0) {
			msg->AddBool("orientation", true);
		}
		else {
			msg->AddBool("orientation", false);
		}
		BMessenger messenger(main_view);
		messenger.SendMessage(msg);
	}	
	
	return item;
}
Ejemplo n.º 23
0
void
MidiSettingsView::_SaveSettings()
{
	int32 selection = fListView->CurrentSelection();
	if (selection < 0)
		return;

	BStringItem* item = (BStringItem*)fListView->ItemAt(selection);
	if (item == NULL)
		return;

	char buffer[512];
	snprintf(buffer, 512, "# Midi Settings\n soundfont = %s\n",
			item->Text());

	BPath path;
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
		path.Append(SETTINGS_FILE);
		BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
		if (file.InitCheck() == B_OK)
			file.Write(buffer, strlen(buffer));
	}
}
Ejemplo n.º 24
0
static char* haikuListGetIdValueAttrib(Ihandle* ih, int id)
{
  BView* view = (BView*)ih->handle;

  BMenuField* menu = dynamic_cast<BMenuField*>(view);
  if(menu)
  {
	UNIMPLEMENTED
	return NULL;
  }

  BListView* listview = iuphaikuGetListView(view);

  if(listview)
  {
	BStringItem* item = (BStringItem*)listview->ItemAt(id - 1);
	return (char*)item->Text();
  } else {
    fprintf(stderr, "View hierarchy problem\n");
  }

  return NULL;
}
Ejemplo n.º 25
0
void FreqWindow::MessageReceived(BMessage* msg){
	int32 i;
	BStringItem *item = NULL;

	switch(msg->what){
	case QUIT:
		Pool.frequency = m_old;
		Quit();
		break;
	
	case SET:
		// set the freq
		Pool.InitBufferPlayer( Pool.frequency );
		Quit();
		break;	

	case SELECT:
		i = list->CurrentSelection();
		if(i < 0)	break;		// nothing selected 
		item = (BStringItem*)list->ItemAt(i);
		
		Pool.frequency = atof( item->Text() );
		text->SetValue(Pool.frequency);
		SetList();
		list->Invalidate();
		break;

	case SET_TEXT:
		Pool.frequency = text->Value();
		SetList();
		list->Invalidate();
		break;

	default:
		BWindow::MessageReceived(msg);
	}
}
Ejemplo n.º 26
0
void CPathsBox::ChangeClicked()
{
	if (fList->CurrentSelection() < 0)
		return;
	
	if (fPanel)
		delete fPanel;

	BStringItem *item = static_cast<BStringItem*>
		(fList->ItemAt(fList->CurrentSelection()));

	entry_ref ref;
	get_ref_for_path(item->Text(), &ref); // may fail
	
	BMessage *msg = new BMessage(msg_ChangePath);
	msg->AddPointer("item", item);
			
	fPanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this),
		&ref, B_DIRECTORY_NODE, false, msg);
	FailNil(fPanel);
	
	fPanel->Window()->SetTitle("Change Directory");
	fPanel->Show();
} /* CPathsBox::ChangeClicked */
Ejemplo n.º 27
0
void
FileTypesWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case B_SIMPLE_DATA:
			type_code type;
			if (message->GetInfo("refs", &type) == B_OK
				&& type == B_REF_TYPE) {
				be_app->PostMessage(message);
			}
			break;

		case kMsgToggleIcons:
		{
			BMenuItem* item;
			if (message->FindPointer("source", (void **)&item) != B_OK)
				break;

			item->SetMarked(!fTypeListView->IsShowingIcons());
			fTypeListView->ShowIcons(item->IsMarked());

			// update settings
			BMessage update(kMsgSettingsChanged);
			update.AddBool("show_icons", item->IsMarked());
			be_app_messenger.SendMessage(&update);
			break;
		}

		case kMsgToggleRule:
		{
			BMenuItem* item;
			if (message->FindPointer("source", (void **)&item) != B_OK)
				break;

			item->SetMarked(fRuleControl->IsHidden());
			_ShowSnifferRule(item->IsMarked());

			// update settings
			BMessage update(kMsgSettingsChanged);
			update.AddBool("show_rule", item->IsMarked());
			be_app_messenger.SendMessage(&update);
			break;
		}

		case kMsgTypeSelected:
		{
			int32 index;
			if (message->FindInt32("index", &index) == B_OK) {
				MimeTypeItem* item = (MimeTypeItem*)fTypeListView->ItemAt(index);
				if (item != NULL) {
					BMimeType type(item->Type());
					_SetType(&type);
				} else
					_SetType(NULL);
			}
			break;
		}

		case kMsgAddType:
		{
			if (fNewTypeWindow == NULL) {
				fNewTypeWindow = new NewFileTypeWindow(this, fCurrentType.Type());
				fNewTypeWindow->Show();
			} else
				fNewTypeWindow->Activate();
			break;
		}
		case kMsgNewTypeWindowClosed:
			fNewTypeWindow = NULL;
			break;

		case kMsgRemoveType:
		{
			if (fCurrentType.Type() == NULL)
				break;

			BAlert* alert;
			if (fCurrentType.IsSupertypeOnly()) {
				alert = new BPrivate::OverrideAlert("FileTypes Request",
					"Removing a super type cannot be reverted.\n"
					"All file types that belong to this super type "
					"will be lost!\n\n"
					"Are you sure you want to do this? To remove the whole "
					"group, hold down the Shift key and press \"Remove\".",
					"Remove", B_SHIFT_KEY, "Cancel", 0, NULL, 0,
					B_WIDTH_AS_USUAL, B_STOP_ALERT);
			} else {
				alert = new BAlert("FileTypes Request",
					"Removing a file type cannot be reverted.\n"
					"Are you sure you want to remove it?",
					"Remove", "Cancel", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
			}
			if (alert->Go())
				break;

			status_t status = fCurrentType.Delete();
			if (status != B_OK)
				fprintf(stderr, "Could not remove file type: %s\n", strerror(status));
			break;
		}

		case kMsgSelectNewType:
		{
			const char* type;
			if (message->FindString("type", &type) == B_OK)
				fTypeListView->SelectNewType(type);
			break;
		}

		// File Recognition group

		case kMsgExtensionSelected:
		{
			int32 index;
			if (message->FindInt32("index", &index) == B_OK) {
				BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index);
				fRemoveExtensionButton->SetEnabled(item != NULL);
			}
			break;
		}

		case kMsgExtensionInvoked:
		{
			if (fCurrentType.Type() == NULL)
				break;

			int32 index;
			if (message->FindInt32("index", &index) == B_OK) {
				BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index);
				if (item == NULL)
					break;

				BWindow* window = new ExtensionWindow(this, fCurrentType, item->Text());
				window->Show();
			}
			break;
		}

		case kMsgAddExtension:
		{
			if (fCurrentType.Type() == NULL)
				break;

			BWindow* window = new ExtensionWindow(this, fCurrentType, NULL);
			window->Show();
			break;
		}

		case kMsgRemoveExtension:
		{
			int32 index = fExtensionListView->CurrentSelection();
			if (index < 0 || fCurrentType.Type() == NULL)
				break;

			BMessage extensions;
			if (fCurrentType.GetFileExtensions(&extensions) == B_OK) {
				extensions.RemoveData("extensions", index);
				fCurrentType.SetFileExtensions(&extensions);
			}
			break;
		}

		case kMsgRuleEntered:
		{
			// check rule
			BString parseError;
			if (BMimeType::CheckSnifferRule(fRuleControl->Text(), &parseError) != B_OK) {
				parseError.Prepend("Recognition rule is not valid:\n\n");
				error_alert(parseError.String());
			} else
				fCurrentType.SetSnifferRule(fRuleControl->Text());
			break;
		}

		// Description group

		case kMsgTypeEntered:
		{
			fCurrentType.SetShortDescription(fTypeNameControl->Text());
			break;
		}

		case kMsgDescriptionEntered:
		{
			fCurrentType.SetLongDescription(fDescriptionControl->Text());
			break;
		}

		// Preferred Application group

		case kMsgPreferredAppChosen:
		{
			const char* signature;
			if (message->FindString("signature", &signature) != B_OK)
				signature = NULL;

			fCurrentType.SetPreferredApp(signature);
			break;
		}

		case kMsgSelectPreferredApp:
		{
			BMessage panel(kMsgOpenFilePanel);
			panel.AddString("title", "Select preferred application");
			panel.AddInt32("message", kMsgPreferredAppOpened);
			panel.AddMessenger("target", this);

			be_app_messenger.SendMessage(&panel);
			break;
		}
		case kMsgPreferredAppOpened:
			_AdoptPreferredApplication(message, false);
			break;

		case kMsgSamePreferredAppAs:
		{
			BMessage panel(kMsgOpenFilePanel);
			panel.AddString("title", "Select same preferred application as");
			panel.AddInt32("message", kMsgSamePreferredAppAsOpened);
			panel.AddMessenger("target", this);

			be_app_messenger.SendMessage(&panel);
			break;
		}
		case kMsgSamePreferredAppAsOpened:
			_AdoptPreferredApplication(message, true);
			break;

		// Extra Attributes group

		case kMsgAttributeSelected:
		{
			int32 index;
			if (message->FindInt32("index", &index) == B_OK) {
				AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index);
				fRemoveAttributeButton->SetEnabled(item != NULL);
			}
			break;
		}

		case kMsgAttributeInvoked:
		{
			if (fCurrentType.Type() == NULL)
				break;

			int32 index;
			if (message->FindInt32("index", &index) == B_OK) {
				AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index);
				if (item == NULL)
					break;

				BWindow* window = new AttributeWindow(this, fCurrentType,
					item);
				window->Show();
			}
			break;
		}

		case kMsgAddAttribute:
		{
			if (fCurrentType.Type() == NULL)
				break;

			BWindow* window = new AttributeWindow(this, fCurrentType, NULL);
			window->Show();
			break;
		}

		case kMsgRemoveAttribute:
		{
			int32 index = fAttributeListView->CurrentSelection();
			if (index < 0 || fCurrentType.Type() == NULL)
				break;

			BMessage attributes;
			if (fCurrentType.GetAttrInfo(&attributes) == B_OK) {
				const char* kAttributeNames[] = {
					"attr:public_name", "attr:name", "attr:type",
					"attr:editable", "attr:viewable", "attr:extra",
					"attr:alignment", "attr:width", "attr:display_as"
				};

				for (uint32 i = 0; i <
						sizeof(kAttributeNames) / sizeof(kAttributeNames[0]); i++) {
					attributes.RemoveData(kAttributeNames[i], index);
				}

				fCurrentType.SetAttrInfo(&attributes);
			}
			break;
		}

		case B_META_MIME_CHANGED:
		{
			const char* type;
			int32 which;
			if (message->FindString("be:type", &type) != B_OK
				|| message->FindInt32("be:which", &which) != B_OK)
				break;

			if (fCurrentType.Type() == NULL)
				break;

			if (!strcasecmp(fCurrentType.Type(), type)) {
				if (which != B_MIME_TYPE_DELETED)
					_SetType(&fCurrentType, which);
				else
					_SetType(NULL);
			} else {
				// this change could still affect our current type

				if (which == B_MIME_TYPE_DELETED
#ifdef __ANTARES__
					|| which == B_SUPPORTED_TYPES_CHANGED
#endif
					|| which == B_PREFERRED_APP_CHANGED)
					_UpdatePreferredApps(&fCurrentType);
			}
			break;
		}

		default:
			BWindow::MessageReceived(message);
	}
}
Ejemplo n.º 28
0
void
GrepWindow::_OnSelectInTracker()
{
	if (fSearchResults->CurrentSelection() < 0) {
		BAlert* alert = new BAlert("Info",
			B_TRANSLATE("Please select the files you wish to have selected for you in "
				"Tracker."),
			B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		return;
	}

	BMessage message;
	BString filePath;
	BPath folderPath;
	BList folderList;
	BString lastFolderAddedToList;

	for (int32 index = 0; ; index++) {
		BStringItem* item = dynamic_cast<BStringItem*>(
			fSearchResults->ItemAt(index));
		if (item == NULL)
			break;

		// only open selected and top level (file) items
		if (!item->IsSelected() || item->OutlineLevel() > 0)
			continue;

		// check if this was previously opened
		if (filePath == item->Text())
			continue;

		filePath = item->Text();
		entry_ref file_ref;
		if (get_ref_for_path(filePath.String(), &file_ref) != B_OK)
			continue;

		message.AddRef("refs", &file_ref);

		// add parent folder to list of folders to open
		folderPath.SetTo(filePath.String());
		if (folderPath.GetParent(&folderPath) == B_OK) {
			BPath* path = new BPath(folderPath);
			if (path->Path() != lastFolderAddedToList) {
				// catches some duplicates
				folderList.AddItem(path);
				lastFolderAddedToList = path->Path();
			} else
				delete path;
		}
	}

	_RemoveFolderListDuplicates(&folderList);
	_OpenFoldersInTracker(&folderList);

	int32 aShortWhile = 100000;
	snooze(aShortWhile);

	if (!_AreAllFoldersOpenInTracker(&folderList)) {
		for (int32 x = 0; x < 5; x++) {
			aShortWhile += 100000;
			snooze(aShortWhile);
			_OpenFoldersInTracker(&folderList);
		}
	}

	if (!_AreAllFoldersOpenInTracker(&folderList)) {
		BString str1;
		str1 << B_TRANSLATE("%APP_NAME couldn't open one or more folders.");
		str1.ReplaceFirst("%APP_NAME",APP_NAME);
		BAlert* alert = new BAlert(NULL, str1.String(), B_TRANSLATE("OK"),
			NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		goto out;
	}

	_SelectFilesInTracker(&folderList, &message);

out:
	// delete folderList contents
	int32 folderCount = folderList.CountItems();
	for (int32 x = 0; x < folderCount; x++)
		delete static_cast<BPath*>(folderList.ItemAt(x));
}
void
ThemeInterfaceView::_ThemeListPopulator()
{
	status_t err;
	int32 i, count;
	int32 importer;
	BString name;
	ThemeItem *ti;
	bool isro;
	BStringItem *si;

	LockLooper();
	fThemeList->MakeEmpty();
	UnlockLooper();

	ThemeManager* tman = GetThemeManager();
	tman->LoadThemes();

	count = tman->CountThemes();
	

	LockLooper();

	si = new BStringItem("(System themes)");
	si->SetEnabled(false);
	fThemeList->AddItem(si);
	si = NULL; // first non-readonly item will set it again

	// native themes
	for (i = 0; i < count; i++) {
		err = tman->ThemeName(i, name);
		isro = tman->ThemeIsReadOnly(i);
		if (err)
			continue;

		if (!isro && si == NULL) {
			si = new BStringItem("(User themes)");
			si->SetEnabled(false);
			fThemeList->AddItem(si);
		}

		ti = new ThemeItem(i, name.String(), isro);
		fThemeList->AddItem(ti);
	}

	UnlockLooper();

	// for each importer
	for (importer = 0; importer < tman->CountThemeImporters(); importer++) {
		err = tman->ImportThemesFor(importer);
		if (err < 0)
			continue;
		PRINT(("Imports for %s: %d\n", tman->ThemeImporterAt(importer), (tman->CountThemes() - count)));
		if (tman->CountThemes() == count)
			continue; // nothing found

		// separator item
		name = "Imported (";
		name << tman->ThemeImporterAt(importer) << ")";
		si = new BStringItem(name.String());
		si->SetEnabled(false);
		LockLooper();
		fThemeList->AddItem(si);
		UnlockLooper();

		// add new themes
		count = tman->CountThemes();
		// we reuse i from where it was left
		for (; i < count; i++) {
			err = tman->ThemeName(i, name);
			isro = true;// importers can't save themes back
			if (err)
				continue;
			ti = new ThemeItem(i, name.String(), isro);
			LockLooper();
			fThemeList->AddItem(ti);
			UnlockLooper();
			// rest a bit
			snooze(1000);
		}
	}

	// enable controls again
	BControl *c;
	LockLooper();
	for (i = 0; ChildAt(i); i++) {
		c = dynamic_cast<BControl *>(ChildAt(i));
		if (c)
			c->SetEnabled(true);
	}
	UnlockLooper();
}
Ejemplo n.º 30
0
void
ProjectSettingsWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case M_SHOW_ADD_PATH:
		{
			fFilePanel->Show();
			break;
		}

		case M_DROP_PATH:
		{
			BString path;
			if (message->FindString("path",&path) == B_OK)
				fProject->AddLocalInclude(path.String());
			break;
		}

		case M_ADD_PATH:
		{
			entry_ref ref;
			int32 i = 0;
			while (message->FindRef("refs", i++, &ref) == B_OK) {
				fDirty = true;
				AddInclude(ref);
			}
			break;
		}

		case M_REMOVE_PATH:
		{
			int32 selection = fIncludeList->CurrentSelection();
			if (selection < 0)
				break;
			
			fDirty = true;
			
			for (int32 i = fIncludeList->CountItems() - 1; i >= 0; i--) {
				BStringItem* item = (BStringItem*)fIncludeList->ItemAt(i);
				if (item->IsSelected()) {
					fIncludeList->RemoveItem(item);
					fProject->RemoveLocalInclude(item->Text());
					delete item;
				}
			}
			break;
		}

		case M_TARGET_NAME_CHANGED:
		{
			if (fTargetText->Text() && strlen(fTargetText->Text()) > 0)
				fProject->SetTargetName(fTargetText->Text());

			fDirty = true;
		}

		case M_TOGGLE_DEBUG:
		{
			if (fDebugBox->Value() == B_CONTROL_ON) {
				fProject->SetDebug(true);
				fOpField->SetEnabled(false);
				fOpSizeBox->SetEnabled(false);
			} else {
				fProject->SetDebug(false);
				fOpField->SetEnabled(true);
				fOpSizeBox->SetEnabled(true);
			}
			fDirty = true;
			break;
		}

		case M_TOGGLE_PROFILE:
		{
			if (fProfileBox->Value() == B_CONTROL_ON)
				fProject->SetProfiling(true);
			else
				fProject->SetProfiling(false);

			fDirty = true;
			break;
		}

		case M_TOGGLE_OPSIZE:
		{
			if (fOpSizeBox->Value() == B_CONTROL_ON)
				fProject->SetOpForSize(true);
			else
				fProject->SetOpForSize(false);

			fDirty = true;
			break;
		}

		case M_SET_OP_VALUE:
		{
			BMenuItem *item = fOpField->Menu()->FindMarked();
			if (item)
				fProject->SetOpLevel(fOpField->Menu()->IndexOf(item));

			fDirty = true;
			break;
		}

		case M_SET_TARGET_TYPE:
		{
			BMenuItem *item = fTypeField->Menu()->FindMarked();
			if (item)
				fProject->SetTargetType(fTypeField->Menu()->IndexOf(item));

			fDirty = true;
			break;
		}

		case M_CCOPTS_CHANGED:
		{
			fProject->SetExtraCompilerOptions(fCompileText->Text());
			fDirty = true;
			break;
		}

		case M_LDOPTS_CHANGED:
		{
			fProject->SetExtraLinkerOptions(fLinkText->Text());
			fDirty = true;
			break;
		}

		default:
			BWindow::MessageReceived(message);
	}
}