Skip to content

Commit

Permalink
HaikuDepot: UI for selecting a stability rating...
Browse files Browse the repository at this point in the history
... in the rating window. Not functional.
  • Loading branch information
stippi committed Sep 26, 2014
1 parent 967a281 commit 5c4c4e2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
54 changes: 52 additions & 2 deletions src/apps/haikudepot/RatePackageWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <Catalog.h>
#include <Button.h>
#include <LayoutBuilder.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <ScrollView.h>

#include "MarkupParser.h"
Expand All @@ -23,7 +26,8 @@


enum {
MSG_SEND = 'send'
MSG_SEND = 'send',
MSG_STABILITY_SELECTED = 'stbl'
};

//! Layouts the scrollbar so it looks nice with no border and the document
Expand Down Expand Up @@ -80,6 +84,19 @@ class ScrollView : public BScrollView {
};


static void
add_stabilities_to_menu(const StabilityRatingList& stabilities, BMenu* menu)
{
for (int i = 0; i < stabilities.CountItems(); i++) {
const StabilityRating& stability = stabilities.ItemAtFast(i);
BMessage* message = new BMessage(MSG_STABILITY_SELECTED);
message->AddString("name", stability.Name());
BMenuItem* item = new BMenuItem(stability.Label(), message);
menu->AddItem(item);
}
}


RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame)
:
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Your rating"),
Expand All @@ -103,12 +120,39 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame)
textView->SetTextDocument(fRatingText);
textView->SetTextEditor(TextEditorRef(new TextEditor(), true));

// Construct stability rating popup
// Construct repository popup
BPopUpMenu* stabilityMenu = new BPopUpMenu(B_TRANSLATE("Stability"));
BMenuField* stabilityRatingField = new BMenuField("stability",
B_TRANSLATE("Stability:"), stabilityMenu);

StabilityRatingList stabilities;
stabilities.Add(StabilityRating(
B_TRANSLATE("Not specified"), "UNSPECIFIED"));
stabilities.Add(StabilityRating(
B_TRANSLATE("Mostly stable"), "MOSTLY_STABLE"));
stabilities.Add(StabilityRating(
B_TRANSLATE("Stable"), "STABLE"));
stabilities.Add(StabilityRating(
B_TRANSLATE("Not stable, but usable"), "USABLE"));
stabilities.Add(StabilityRating(
B_TRANSLATE("Unstable"), "UNSTABLE"));
stabilities.Add(StabilityRating(
B_TRANSLATE("Does not start"), "DOES_NOT_START"));

add_stabilities_to_menu(stabilities, stabilityMenu);
stabilityMenu->SetTargetForItems(this);

fStability = stabilities.ItemAt(0).Name();
stabilityMenu->ItemAt(0)->SetMarked(true);

fSendButton = new BButton("send", B_TRANSLATE("Send"),
new BMessage(MSG_SEND));

// Build layout
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(textScrollView)
.Add(stabilityRatingField)
.AddGroup(B_HORIZONTAL)
.AddGlue()
.Add(fSendButton)
Expand All @@ -130,6 +174,9 @@ RatePackageWindow::MessageReceived(BMessage* message)
case MSG_SEND:
_SendRating();
break;
case MSG_STABILITY_SELECTED:
message->FindString("name", &fStability);
break;

default:
BWindow::MessageReceived(message);
Expand All @@ -141,7 +188,10 @@ RatePackageWindow::MessageReceived(BMessage* message)
void
RatePackageWindow::SetPackage(const PackageInfoRef& package)
{
// TODO: Just remember which package the rating is for.
fPackage = package;
// TODO: See if the user already made a rating for this package,
// pre-fill the UI with that rating. When sending the rating, replace
// the old one.
}


Expand Down
3 changes: 2 additions & 1 deletion src/apps/haikudepot/RatePackageWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class BButton;
class TextDocumentView;
class BMenuField;


class RatePackageWindow : public BWindow {
Expand All @@ -29,6 +29,7 @@ class RatePackageWindow : public BWindow {

private:
TextDocumentRef fRatingText;
BString fStability;
BButton* fSendButton;
PackageInfoRef fPackage;
};
Expand Down

0 comments on commit 5c4c4e2

Please sign in to comment.