140 lines
2.7 KiB
C++
140 lines
2.7 KiB
C++
/*
|
|
* Copyright 2024, My Name <my@email.address>
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
*/
|
|
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include <Application.h>
|
|
#include <Catalog.h>
|
|
#include <LayoutBuilder.h>
|
|
#include <Menu.h>
|
|
#include <MenuBar.h>
|
|
#include <Button.h>
|
|
|
|
#include <View.h>
|
|
|
|
#include <cstdio>
|
|
|
|
#undef B_TRANSLATION_CONTEXT
|
|
#define B_TRANSLATION_CONTEXT "Window"
|
|
|
|
static const uint32 kMsgNewFile = 'fnew';
|
|
static const uint32 kMsgOpenFile = 'fopn';
|
|
static const uint32 kMsgSaveFile = 'fsav';
|
|
|
|
static const uint32 kSendPrompt = 'kspt';
|
|
static const uint32 kQuestionChanged = 'kqch';
|
|
|
|
|
|
MainWindow::MainWindow()
|
|
:
|
|
BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW,
|
|
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
|
|
{
|
|
BMenuBar* menuBar = _BuildMenu();
|
|
|
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
|
.Add(menuBar)
|
|
.AddGlue()
|
|
.End();
|
|
|
|
|
|
BTextControl* input = new BTextControl(B_TRANSLATE("question"), "", new BMessage(kQuestionChanged));
|
|
BTextView* answerView = new BTextView("answer", B_WILL_DRAW | B_FOLLOW_ALL_SIDES);
|
|
|
|
BButton *sendButton = new BButton("send",B_TRANSLATE("ask"),new BMessage(kSendPrompt), B_WILL_DRAW | B_NAVIGABLE);
|
|
|
|
|
|
|
|
//BLayoutItem * addMe = new BLayoutItem():
|
|
|
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
|
.AddGroup(B_HORIZONTAL, 0)
|
|
.Add(input)
|
|
.Add(sendButton)
|
|
.End()
|
|
.Add(answerView)
|
|
.SetInsets(5, 5, 5, 5)
|
|
.End();
|
|
|
|
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
}
|
|
|
|
|
|
void
|
|
MainWindow::MessageReceived(BMessage* message)
|
|
{
|
|
switch (message->what) {
|
|
case kMsgNewFile:
|
|
{
|
|
fSaveMenuItem->SetEnabled(false);
|
|
printf("New\n");
|
|
} break;
|
|
|
|
case kMsgOpenFile:
|
|
{
|
|
fSaveMenuItem->SetEnabled(true);
|
|
printf("Open\n");
|
|
} break;
|
|
|
|
case kMsgSaveFile:
|
|
{
|
|
printf("Save\n");
|
|
} break;
|
|
|
|
case kSendPrompt:
|
|
{
|
|
printf("Sending Prompt...");
|
|
|
|
} break;
|
|
|
|
|
|
default:
|
|
{
|
|
BWindow::MessageReceived(message);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
BMenuBar*
|
|
MainWindow::_BuildMenu()
|
|
{
|
|
BMenuBar* menuBar = new BMenuBar("menubar");
|
|
BMenu* menu;
|
|
BMenuItem* item;
|
|
|
|
// menu 'File'
|
|
menu = new BMenu(B_TRANSLATE("File"));
|
|
|
|
item = new BMenuItem(B_TRANSLATE("New"), new BMessage(kMsgNewFile), 'N');
|
|
menu->AddItem(item);
|
|
|
|
item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS), new BMessage(kMsgOpenFile), 'O');
|
|
menu->AddItem(item);
|
|
|
|
fSaveMenuItem = new BMenuItem(B_TRANSLATE("Save"), new BMessage(kMsgSaveFile), 'S');
|
|
fSaveMenuItem->SetEnabled(false);
|
|
menu->AddItem(fSaveMenuItem);
|
|
|
|
menu->AddSeparatorItem();
|
|
|
|
item = new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED));
|
|
item->SetTarget(be_app);
|
|
menu->AddItem(item);
|
|
|
|
item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q');
|
|
menu->AddItem(item);
|
|
|
|
menuBar->AddItem(menu);
|
|
|
|
return menuBar;
|
|
}
|