Skip to content

Commit

Permalink
part browser window: use escape key to go back to schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Sep 26, 2021
1 parent 2d03580 commit 49e0ae7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/pool-prj-mgr/pool-prj-mgr-app_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,24 @@ bool PoolProjectManagerAppWindow::migrate_project(const std::string &path)
return true;
}

gboolean PoolProjectManagerAppWindow::part_browser_key_pressed(GtkEventControllerKey *controller, guint keyval,
guint keycode, GdkModifierType state, gpointer user_data)
{
if (keyval != GDK_KEY_Escape)
return FALSE;

auto self = reinterpret_cast<PoolProjectManagerAppWindow *>(user_data);
if (auto proc = self->find_top_schematic_process()) {
auto pid = proc->proc->get_pid();
json tx;
tx["op"] = "present";
tx["time"] = gtk_get_current_event_time();
self->app.send_json(pid, tx);
}

return TRUE;
}

void PoolProjectManagerAppWindow::open_file_view(const Glib::RefPtr<Gio::File> &file)
{
auto path = file->get_path();
Expand Down Expand Up @@ -1274,6 +1292,12 @@ void PoolProjectManagerAppWindow::open_file_view(const Glib::RefPtr<Gio::File> &
part_browser_window->signal_assign_part().connect(
sigc::mem_fun(*this, &PoolProjectManagerAppWindow::handle_assign_part));

{
auto ctrl = gtk_event_controller_key_new(GTK_WIDGET(part_browser_window->gobj()));
gtk_event_controller_set_propagation_phase(ctrl, GTK_PHASE_CAPTURE);
g_signal_connect(ctrl, "key-pressed", G_CALLBACK(part_browser_key_pressed), this);
}

set_view_mode(ViewMode::PROJECT);

view_project.update_meta();
Expand Down
2 changes: 2 additions & 0 deletions src/pool-prj-mgr/pool-prj-mgr-app_win.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class PoolProjectManagerAppWindow : public Gtk::ApplicationWindow {
void save_project();
class PartBrowserWindow *part_browser_window = nullptr;
void cleanup();
static gboolean part_browser_key_pressed(GtkEventControllerKey *controller, guint keyval, guint keycode,
GdkModifierType state, gpointer user_data);

ViewMode view_mode = ViewMode::OPEN;
void set_view_mode(ViewMode mode);
Expand Down

0 comments on commit 49e0ae7

Please sign in to comment.