mirror of
https://github.com/RGBCube/serenity
synced 2025-05-17 22:05:08 +00:00
IRCClient: Add menus.
This commit is contained in:
parent
746144f783
commit
5c2d405e1f
6 changed files with 75 additions and 34 deletions
|
@ -1,11 +1,14 @@
|
||||||
#include "IRCAppWindow.h"
|
#include "IRCAppWindow.h"
|
||||||
#include "IRCClientWindow.h"
|
#include "IRCClientWindow.h"
|
||||||
#include "IRCClientWindowListModel.h"
|
#include "IRCClientWindowListModel.h"
|
||||||
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GStackWidget.h>
|
#include <LibGUI/GStackWidget.h>
|
||||||
#include <LibGUI/GTableView.h>
|
#include <LibGUI/GTableView.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
#include <LibGUI/GToolBar.h>
|
#include <LibGUI/GToolBar.h>
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
|
#include <LibGUI/GMenu.h>
|
||||||
|
#include <LibGUI/GMenuBar.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
IRCAppWindow::IRCAppWindow()
|
IRCAppWindow::IRCAppWindow()
|
||||||
|
@ -15,6 +18,8 @@ IRCAppWindow::IRCAppWindow()
|
||||||
set_title(String::format("IRC Client: %s@%s:%d", m_client.nickname().characters(), m_client.hostname().characters(), m_client.port()));
|
set_title(String::format("IRC Client: %s@%s:%d", m_client.nickname().characters(), m_client.hostname().characters(), m_client.port()));
|
||||||
set_rect(200, 200, 600, 400);
|
set_rect(200, 200, 600, 400);
|
||||||
setup_client();
|
setup_client();
|
||||||
|
setup_actions();
|
||||||
|
setup_menus();
|
||||||
setup_widgets();
|
setup_widgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,45 +48,73 @@ void IRCAppWindow::setup_client()
|
||||||
m_client.connect();
|
m_client.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRCAppWindow::setup_actions()
|
||||||
|
{
|
||||||
|
m_join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-join.rgb", { 16, 16 }), [] (auto&) {
|
||||||
|
printf("FIXME: Implement join action\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-part.rgb", { 16, 16 }), [] (auto&) {
|
||||||
|
printf("FIXME: Implement part action\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-whois.rgb", { 16, 16 }), [] (auto&) {
|
||||||
|
printf("FIXME: Implement whois action\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
m_open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-open-query.rgb", { 16, 16 }), [] (auto&) {
|
||||||
|
printf("FIXME: Implement open-query action\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
m_close_query_action = GAction::create("Close query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-close-query.rgb", { 16, 16 }), [] (auto&) {
|
||||||
|
printf("FIXME: Implement close-query action\n");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRCAppWindow::setup_menus()
|
||||||
|
{
|
||||||
|
auto menubar = make<GMenuBar>();
|
||||||
|
auto app_menu = make<GMenu>("IRC Client");
|
||||||
|
app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) {
|
||||||
|
dbgprintf("Terminal: Quit menu activated!\n");
|
||||||
|
GApplication::the().quit(0);
|
||||||
|
return;
|
||||||
|
}));
|
||||||
|
menubar->add_menu(move(app_menu));
|
||||||
|
|
||||||
|
auto server_menu = make<GMenu>("Server");
|
||||||
|
server_menu->add_action(*m_join_action);
|
||||||
|
server_menu->add_action(*m_part_action);
|
||||||
|
server_menu->add_separator();
|
||||||
|
server_menu->add_action(*m_whois_action);
|
||||||
|
server_menu->add_action(*m_open_query_action);
|
||||||
|
server_menu->add_action(*m_close_query_action);
|
||||||
|
menubar->add_menu(move(server_menu));
|
||||||
|
|
||||||
|
auto help_menu = make<GMenu>("Help");
|
||||||
|
help_menu->add_action(GAction::create("About", [] (const GAction&) {
|
||||||
|
dbgprintf("FIXME: Implement Help/About\n");
|
||||||
|
}));
|
||||||
|
menubar->add_menu(move(help_menu));
|
||||||
|
|
||||||
|
GApplication::the().set_menubar(move(menubar));
|
||||||
|
}
|
||||||
|
|
||||||
void IRCAppWindow::setup_widgets()
|
void IRCAppWindow::setup_widgets()
|
||||||
{
|
{
|
||||||
auto* widget = new GWidget(nullptr);
|
auto* widget = new GWidget(nullptr);
|
||||||
set_main_widget(widget);
|
set_main_widget(widget);
|
||||||
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
|
|
||||||
printf("main_widget: %s{%p}\n", widget->class_name(), widget);
|
|
||||||
|
|
||||||
auto join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-join.rgb", { 16, 16 }), [] (auto&) {
|
|
||||||
printf("FIXME: Implement join action\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
auto part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-part.rgb", { 16, 16 }), [] (auto&) {
|
|
||||||
printf("FIXME: Implement part action\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
auto whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-whois.rgb", { 16, 16 }), [] (auto&) {
|
|
||||||
printf("FIXME: Implement whois action\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
auto open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-open-query.rgb", { 16, 16 }), [] (auto&) {
|
|
||||||
printf("FIXME: Implement open-query action\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
auto close_query_action = GAction::create("Close query", GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/irc-close-query.rgb", { 16, 16 }), [] (auto&) {
|
|
||||||
printf("FIXME: Implement close-query action\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
auto* toolbar = new GToolBar(widget);
|
auto* toolbar = new GToolBar(widget);
|
||||||
toolbar->add_action(join_action.copy_ref());
|
toolbar->add_action(*m_join_action);
|
||||||
toolbar->add_action(part_action.copy_ref());
|
toolbar->add_action(*m_part_action.copy_ref());
|
||||||
toolbar->add_separator();
|
toolbar->add_separator();
|
||||||
toolbar->add_action(whois_action.copy_ref());
|
toolbar->add_action(*m_whois_action);
|
||||||
toolbar->add_action(open_query_action.copy_ref());
|
toolbar->add_action(*m_open_query_action);
|
||||||
toolbar->add_action(close_query_action.copy_ref());
|
toolbar->add_action(*m_close_query_action);
|
||||||
|
|
||||||
|
|
||||||
auto* horizontal_container = new GWidget(widget);
|
auto* horizontal_container = new GWidget(widget);
|
||||||
printf("horizontal_widget: %s{%p}\n", horizontal_container->class_name(), horizontal_container);
|
|
||||||
horizontal_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
horizontal_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||||
|
|
||||||
auto* window_list = new GTableView(horizontal_container);
|
auto* window_list = new GTableView(horizontal_container);
|
||||||
|
@ -95,7 +128,6 @@ void IRCAppWindow::setup_widgets()
|
||||||
};
|
};
|
||||||
|
|
||||||
m_container = new GStackWidget(horizontal_container);
|
m_container = new GStackWidget(horizontal_container);
|
||||||
printf("m_container: %s{%p}\n", ((GWidget*)m_container)->class_name(), m_container);
|
|
||||||
|
|
||||||
create_subwindow(IRCClientWindow::Server, "Server");
|
create_subwindow(IRCClientWindow::Server, "Server");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "IRCClient.h"
|
#include "IRCClient.h"
|
||||||
#include "IRCClientWindow.h"
|
#include "IRCClientWindow.h"
|
||||||
|
|
||||||
|
class GAction;
|
||||||
class GStackWidget;
|
class GStackWidget;
|
||||||
|
|
||||||
class IRCAppWindow : public GWindow {
|
class IRCAppWindow : public GWindow {
|
||||||
|
@ -14,6 +15,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setup_client();
|
void setup_client();
|
||||||
|
void setup_actions();
|
||||||
|
void setup_menus();
|
||||||
void setup_widgets();
|
void setup_widgets();
|
||||||
|
|
||||||
IRCClientWindow& create_subwindow(IRCClientWindow::Type, const String& name);
|
IRCClientWindow& create_subwindow(IRCClientWindow::Type, const String& name);
|
||||||
|
@ -22,4 +25,10 @@ private:
|
||||||
IRCClient m_client;
|
IRCClient m_client;
|
||||||
|
|
||||||
GStackWidget* m_container { nullptr };
|
GStackWidget* m_container { nullptr };
|
||||||
|
|
||||||
|
RetainPtr<GAction> m_join_action;
|
||||||
|
RetainPtr<GAction> m_part_action;
|
||||||
|
RetainPtr<GAction> m_whois_action;
|
||||||
|
RetainPtr<GAction> m_open_query_action;
|
||||||
|
RetainPtr<GAction> m_close_query_action;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@ GMenu::~GMenu()
|
||||||
unrealize_menu();
|
unrealize_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu::add_action(RetainPtr<GAction>&& action)
|
void GMenu::add_action(Retained<GAction>&& action)
|
||||||
{
|
{
|
||||||
m_items.append(make<GMenuItem>(move(action)));
|
m_items.append(make<GMenuItem>(move(action)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
|
|
||||||
GAction* action_at(int);
|
GAction* action_at(int);
|
||||||
|
|
||||||
void add_action(RetainPtr<GAction>&&);
|
void add_action(Retained<GAction>&&);
|
||||||
void add_separator();
|
void add_separator();
|
||||||
|
|
||||||
Function<void(unsigned)> on_item_activation;
|
Function<void(unsigned)> on_item_activation;
|
||||||
|
|
|
@ -6,7 +6,7 @@ GMenuItem::GMenuItem(Type type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GMenuItem::GMenuItem(RetainPtr<GAction>&& action)
|
GMenuItem::GMenuItem(Retained<GAction>&& action)
|
||||||
: m_type(Action)
|
: m_type(Action)
|
||||||
, m_action(move(action))
|
, m_action(move(action))
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,7 @@ public:
|
||||||
enum Type { Invalid, Action, Separator };
|
enum Type { Invalid, Action, Separator };
|
||||||
|
|
||||||
explicit GMenuItem(Type);
|
explicit GMenuItem(Type);
|
||||||
explicit GMenuItem(RetainPtr<GAction>&&);
|
explicit GMenuItem(Retained<GAction>&&);
|
||||||
~GMenuItem();
|
~GMenuItem();
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue