Commit d8c0ad46 authored by Grumbel's avatar Grumbel

Converted JoystickListWidget from Gtk::Dialog to Gtk::Window

parent 3d8af5d6
......@@ -22,7 +22,7 @@
#include "joystick.hpp"
#include "joystick_description.hpp"
#include "joystick_list_widget.hpp"
class DeviceListColumns : public Gtk::TreeModel::ColumnRecord
{
private:
......@@ -49,15 +49,21 @@ private:
};
DeviceListColumns* DeviceListColumns::instance_ = 0;
JoystickListWidget::JoystickListWidget()
: Gtk::Dialog("Joystick Preferences"),
label("Below is a list of available joysticks on the system. Press Refresh to "
"update the list, press Properties to get a separate device dialog. The "
"devices listed are only joystick devices, not evdev devices or SDL "
"devices, you can view the other ones via the top tab.")
//frame("Device List"),
JoystickListWidget::JoystickListWidget() :
Gtk::Window(),
label("Below is a list of available joysticks on the system. Press Refresh to "
"update the list, press Properties to get a separate device dialog. The "
"devices listed are only joystick devices, not evdev devices or SDL "
"devices, you can view the other ones via the top tab."),
m_vbox(),
m_buttonbox(),
m_refresh_button(Gtk::Stock::REFRESH),
m_properties_button(Gtk::Stock::PROPERTIES),
m_close_button(Gtk::Stock::CLOSE)
{
set_title("Joystick Preferences");
set_default_size(450, 310);
label.set_line_wrap();
......@@ -66,11 +72,14 @@ JoystickListWidget::JoystickListWidget()
scrolled.set_border_width(5);
scrolled.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
scrolled.add(treeview);
get_vbox()->add(scrolled);
m_vbox.add(scrolled);
m_buttonbox.pack_end(m_refresh_button);
m_buttonbox.pack_end(m_properties_button);
m_buttonbox.pack_end(m_close_button);
m_vbox.pack_end(m_buttonbox, Gtk::PACK_SHRINK);
add_button(Gtk::Stock::REFRESH, 2);
add_button(Gtk::Stock::PROPERTIES, 1);
add_button(Gtk::Stock::CLOSE, 0);
add(m_vbox);
// Set model
device_list = Gtk::ListStore::create(DeviceListColumns::instance());
......@@ -79,9 +88,13 @@ JoystickListWidget::JoystickListWidget()
treeview.append_column("Icon", DeviceListColumns::instance().icon);
treeview.append_column("Name", DeviceListColumns::instance().name);
// Signals
treeview.signal_row_activated().connect(sigc::mem_fun(this, &JoystickListWidget::on_row_activated));
m_refresh_button.signal_clicked().connect([this]{ on_refresh_button(); });
m_properties_button.signal_clicked().connect([this]{ on_properties_button(); });
m_close_button.signal_clicked().connect([this]{ hide(); });
on_refresh();
on_refresh_button();
}
void
......@@ -90,29 +103,12 @@ JoystickListWidget::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::Tree
Gtk::TreeModel::iterator it = treeview.get_model()->get_iter(path);
if (it)
{
Main::current()->show_device_property_dialog((*it)[DeviceListColumns::instance().path]);
Main::current()->show_device_property_dialog((*it)[DeviceListColumns::instance().path], this);
}
}
void
JoystickListWidget::on_response(int v)
{
if (v == 0)
{
hide();
}
else if (v == 1)
{
on_properties();
}
else if (v == 2)
{
on_refresh();
}
}
void
JoystickListWidget::on_refresh()
JoystickListWidget::on_refresh_button()
{
const std::vector<JoystickDescription>& joysticks = Joystick::get_joysticks();
......@@ -147,13 +143,13 @@ JoystickListWidget::on_refresh()
}
void
JoystickListWidget::on_properties()
JoystickListWidget::on_properties_button()
{
Gtk::TreeModel::iterator it = treeview.get_selection()->get_selected();
if (it)
{
Main::current()->show_device_property_dialog((*it)[DeviceListColumns::instance().path]);
Main::current()->show_device_property_dialog((*it)[DeviceListColumns::instance().path], this);
}
}
/* EOF */
......@@ -27,8 +27,9 @@
#include <gtkmm/treeview.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/liststore.h>
class JoystickListWidget : public Gtk::Dialog
#include <gtkmm/window.h>
class JoystickListWidget : public Gtk::Window
{
private:
Gtk::Label label;
......@@ -37,25 +38,26 @@ private:
Gtk::ScrolledWindow scrolled;
Gtk::TreeView treeview;
Gtk::HButtonBox buttonbox;
Gtk::Button refresh_button;
Gtk::Button properties_button;
Gtk::VBox m_vbox;
Gtk::HButtonBox m_buttonbox;
Gtk::Button m_refresh_button;
Gtk::Button m_properties_button;
Gtk::Button m_close_button;
Glib::RefPtr<Gtk::ListStore> device_list;
public:
JoystickListWidget();
void on_refresh();
void on_properties();
void on_response(int v) override;
void on_refresh_button();
void on_properties_button();
void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
private:
JoystickListWidget(const JoystickListWidget&);
JoystickListWidget& operator=(const JoystickListWidget&);
};
#endif
/* EOF */
......@@ -34,12 +34,11 @@
#include "main.hpp"
Main* Main::current_ = 0;
Main::Main(const std::string& datadir_)
: Gtk::Application("com.gmail.grumbel.jstest-gtk"),
datadir(datadir_),
m_simple_ui(false),
list_dialog(0)
m_simple_ui(false)
{
current_ = this;
}
......@@ -49,26 +48,16 @@ Main::~Main()
}
void
Main::show_device_list_dialog()
{
if (list_dialog)
{
list_dialog->show();
}
else
{
list_dialog = new JoystickListWidget();
dialogs.push_back(list_dialog);
list_dialog->signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Main::on_dialog_hide), list_dialog));
list_dialog->show_all();
}
}
void
Main::show_device_property_dialog(const std::string& filename)
Main::show_device_property_dialog(const std::string& filename, Gtk::Window* parent)
{
Joystick* joystick = new Joystick(filename);
JoystickTestWidget* dialog = new JoystickTestWidget(*joystick, m_simple_ui);
if (parent) {
dialog->set_transient_for(*parent);
} else {
dialog->unset_transient_for();
}
dialog->signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Main::on_dialog_hide), dialog));
dialog->show_all();
joysticks.push_back(joystick);
......@@ -154,7 +143,10 @@ Main::run(int argc, char** argv)
if (device_files.empty())
{
show_device_list_dialog();
JoystickListWidget list_dialog;
//list_dialog.signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Main::on_dialog_hide), &list_dialog));
list_dialog.show_all();
return Gtk::Application::run(list_dialog, argc, argv);
}
else
{
......@@ -162,8 +154,8 @@ Main::run(int argc, char** argv)
{
show_device_property_dialog(*i);
}
return Gtk::Application::run(argc, argv);
}
return Gtk::Application::run(*list_dialog, argc, argv);
}
catch(std::exception& err)
{
......@@ -178,7 +170,7 @@ Main::run(int argc, char** argv)
return 0;
}
std::string find_datadir()
{
BrInitError error;
......@@ -203,7 +195,7 @@ std::string find_datadir()
}
}
}
int main(int argc, char** argv)
{
try
......@@ -218,7 +210,7 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
}
Glib::RefPtr<Main> Main::create()
{
return Glib::RefPtr<Main>(new Main(find_datadir()));
......
......@@ -36,8 +36,6 @@ private:
std::string datadir;
bool m_simple_ui;
JoystickListWidget* list_dialog;
std::vector<Joystick*> joysticks;
std::vector<Gtk::Dialog*> dialogs;
......@@ -49,8 +47,7 @@ public:
Main(const std::string& datadir);
~Main();
void show_device_list_dialog();
void show_device_property_dialog(const std::string& filename);
void show_device_property_dialog(const std::string& filename, Gtk::Window* parent = nullptr);
void show_calibration_dialog(Joystick& joystick);
void show_mapping_dialog(Joystick& joystick);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment