Add an information blurb option to PromptWindow.

- PromptWindow now takes a parameter which contains optional
  informational text to display above the text control.

- Adjust callers.
This commit is contained in:
Rene Gollent 2013-04-25 21:35:27 -04:00
parent 31bc74d4bf
commit aa366c07b1
3 changed files with 16 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012, Rene Gollent, rene@gollent.com. * Copyright 2012-2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef PROMPT_WINDOW_H_ #ifndef PROMPT_WINDOW_H_
@ -10,6 +10,7 @@
#include <Window.h> #include <Window.h>
class BStringView;
class BTextControl; class BTextControl;
@ -17,8 +18,9 @@ class PromptWindow : public BWindow
{ {
public: public:
// PromptWindow takes ownership of message // PromptWindow takes ownership of message
PromptWindow(const char* title, const char* label, BMessenger target, PromptWindow(const char* title,
BMessage* message = NULL); const char* label, const char* info,
BMessenger target, BMessage* message = NULL);
~PromptWindow(); ~PromptWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@ -27,6 +29,7 @@ public:
status_t SetMessage(BMessage* message); status_t SetMessage(BMessage* message);
private: private:
BTextControl* fTextControl; BTextControl* fTextControl;
BStringView* fInfoView;
BMessenger fTarget; BMessenger fTarget;
BMessage* fMessage; BMessage* fMessage;
}; };

View File

@ -1517,7 +1517,8 @@ VariablesView::MessageReceived(BMessage* message)
promptMessage->AddPointer("node", fVariableTable promptMessage->AddPointer("node", fVariableTable
->SelectionModel()->NodeAt(0)); ->SelectionModel()->NodeAt(0));
PromptWindow* promptWindow = new(std::nothrow) PromptWindow( PromptWindow* promptWindow = new(std::nothrow) PromptWindow(
"Specify Type", "Type: ", BMessenger(this), promptMessage); "Specify Type", "Type: ", NULL, BMessenger(this),
promptMessage);
if (promptWindow == NULL) if (promptWindow == NULL)
return; return;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012, Rene Gollent, rene@gollent.com. * Copyright 2012-2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "PromptWindow.h" #include "PromptWindow.h"
@ -7,6 +7,7 @@
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
@ -14,13 +15,14 @@ static const uint32 kAcceptInput = 'acin';
PromptWindow::PromptWindow(const char* title, const char* label, PromptWindow::PromptWindow(const char* title, const char* label,
BMessenger target, BMessage* message) const char* info, BMessenger target, BMessage* message)
: :
BWindow(BRect(), title, B_FLOATING_WINDOW, B_NOT_RESIZABLE BWindow(BRect(), title, B_FLOATING_WINDOW, B_NOT_RESIZABLE
| B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
fTarget(target), fTarget(target),
fMessage(message) fMessage(message)
{ {
fInfoView = new BStringView("info", info);
fTextControl = new BTextControl("promptcontrol", label, NULL, fTextControl = new BTextControl("promptcontrol", label, NULL,
new BMessage(kAcceptInput)); new BMessage(kAcceptInput));
BButton* cancelButton = new BButton("Cancel", new BButton* cancelButton = new BButton("Cancel", new
@ -28,11 +30,15 @@ PromptWindow::PromptWindow(const char* title, const char* label,
BButton* acceptButton = new BButton("Accept", new BButton* acceptButton = new BButton("Accept", new
BMessage(kAcceptInput)); BMessage(kAcceptInput));
BLayoutBuilder::Group<>(this, B_VERTICAL) BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(fInfoView)
.Add(fTextControl) .Add(fTextControl)
.AddGroup(B_HORIZONTAL) .AddGroup(B_HORIZONTAL)
.Add(acceptButton) .Add(acceptButton)
.Add(cancelButton); .Add(cancelButton);
if (info == NULL)
fInfoView->Hide();
fTextControl->TextView()->SetExplicitMinSize(BSize( fTextControl->TextView()->SetExplicitMinSize(BSize(
fTextControl->TextView()->StringWidth("1234567890"), B_SIZE_UNSET)); fTextControl->TextView()->StringWidth("1234567890"), B_SIZE_UNSET));
fTextControl->SetTarget(this); fTextControl->SetTarget(this);