mirror of https://github.com/berriedale/arun
Hook up a key-release-event signal for escape in order to quit arun
This commit is contained in:
parent
1c82dafa6b
commit
7d4e4a0908
|
@ -22,6 +22,8 @@
|
|||
|
||||
with Ada.Text_IO;
|
||||
with GNAT.OS_Lib;
|
||||
with Gdk.Event;
|
||||
with Gdk.Types.Keysyms;
|
||||
with Gtk.Main;
|
||||
with Gtk.Widget;
|
||||
with Gtk.Search_Entry;
|
||||
|
@ -68,4 +70,20 @@ package body Arun.Handlers is
|
|||
Gtk.Main.Main_Quit;
|
||||
end Execute_Command;
|
||||
|
||||
function Search_KeyPress (Widget : access Gtk.Widget.Gtk_Widget_Record'Class;
|
||||
Event : in Gdk.Event.Gdk_Event_Key) return Boolean is
|
||||
use Ada.Text_IO;
|
||||
use Gdk.Types;
|
||||
|
||||
begin
|
||||
Put_Line ("Key pressed");
|
||||
|
||||
if Event.Keyval = Gdk.Types.Keysyms.GDK_Escape then
|
||||
Put_Line ("Escape! Exiting arun");
|
||||
Gtk.Main.Main_Quit;
|
||||
end if;
|
||||
|
||||
return True;
|
||||
end Search_KeyPress;
|
||||
|
||||
end Arun.Handlers;
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
------------------------------------------------------------------------------
|
||||
|
||||
with Gtkada.Builder; use Gtkada.Builder;
|
||||
with Gtk.Widget;
|
||||
with Gdk.Event;
|
||||
|
||||
package Arun.Handlers is
|
||||
|
||||
|
@ -33,4 +35,8 @@ package Arun.Handlers is
|
|||
-- On "activate" of the search entry call this handler (basically when the user
|
||||
-- hits the enter key
|
||||
|
||||
function Search_KeyPress (Widget : access Gtk.Widget.Gtk_Widget_Record'Class;
|
||||
Event : in Gdk.Event.Gdk_Event_Key) return Boolean;
|
||||
-- On key-presses in the commandEntry field
|
||||
|
||||
end Arun.Handlers;
|
||||
|
|
|
@ -100,9 +100,6 @@ package body Arun.Launcher is
|
|||
Print_Errno ("Something went wrong");
|
||||
end if;
|
||||
|
||||
|
||||
end Execute;
|
||||
|
||||
|
||||
|
||||
end Arun.Launcher;
|
||||
|
|
33
src/arun.adb
33
src/arun.adb
|
@ -18,22 +18,21 @@
|
|||
------------------------------------------------------------------------------
|
||||
|
||||
|
||||
with Gtk; use Gtk;
|
||||
with Gtk; use Gtk;
|
||||
with Gtk.Box; use Gtk.Box;
|
||||
|
||||
with Gtk.Label; use Gtk.Label;
|
||||
with Gtk.Widget; use Gtk.Widget;
|
||||
|
||||
with Glib; use Glib;
|
||||
with Glib.Error; use Glib.Error;
|
||||
with Gtk.Main; use Gtk.Main;
|
||||
with Glib; use Glib;
|
||||
with Glib.Error; use Glib.Error;
|
||||
with Gtk.Main; use Gtk.Main;
|
||||
with Gtk.Window; use Gtk.Window;
|
||||
with Gtkada.Builder; use Gtkada.Builder;
|
||||
|
||||
with Ada.Text_IO;
|
||||
with Arun.Handlers;
|
||||
|
||||
with Gtkada.Builder; use Gtkada.Builder;
|
||||
|
||||
package body Arun is
|
||||
procedure Main is
|
||||
Builder : Gtkada_Builder;
|
||||
|
@ -41,15 +40,14 @@ package body Arun is
|
|||
Return_Code : Guint;
|
||||
|
||||
use Ada.Text_IO;
|
||||
use Gtkada.Builder;
|
||||
begin
|
||||
-- Initialize GtkAda.
|
||||
|
||||
Gtk.Main.Init;
|
||||
Put_Line ("Starting arun");
|
||||
|
||||
-- Create a window with a size of 400x400
|
||||
Gtk_New (Builder);
|
||||
|
||||
|
||||
Return_Code := Add_From_Resource (Builder => Builder,
|
||||
Resource_Path => "/io/lasagna/arun/arun.glade",
|
||||
Error => Error'Access);
|
||||
|
@ -59,8 +57,6 @@ package body Arun is
|
|||
return;
|
||||
end if;
|
||||
|
||||
-- Step 2: add calls to "Register_Handler" to associate your
|
||||
-- handlers with your callbacks.
|
||||
Register_Handler (Builder => Builder,
|
||||
Handler_Name => "Main_Quit",
|
||||
Handler => Arun.Handlers.Quit'Access);
|
||||
|
@ -72,16 +68,19 @@ package body Arun is
|
|||
Register_Handler (Builder => Builder,
|
||||
Handler_Name => "commandEntry_activate_cb",
|
||||
Handler => Arun.Handlers.Execute_Command'Access);
|
||||
-- Step 3: call Do_Connect. Once to connect all registered handlers
|
||||
|
||||
Do_Connect (Builder);
|
||||
|
||||
-- Find our main window, then display it and all of its children.
|
||||
Gtk.Widget.Show_All ( Gtk_Widget (Gtkada.Builder.Get_Object (Builder, "commandWindow")));
|
||||
declare
|
||||
Command_Entry : Gtk_Widget := Gtk_Widget (Get_Object (builder, "commandEntry"));
|
||||
begin
|
||||
Command_Entry.On_Key_Release_Event (Call => Arun.Handlers.Search_KeyPress'Access,
|
||||
After => False);
|
||||
end;
|
||||
|
||||
Gtk.Widget.Show_All ( Gtk_Widget (Get_Object (Builder, "commandWindow")));
|
||||
Gtk.Main.Main;
|
||||
|
||||
-- Step 4: when the application terminates or all Windows described through
|
||||
-- your builder should be closed, call Unref to free memory
|
||||
-- associated with the Builder.
|
||||
Unref (Builder);
|
||||
end Main;
|
||||
|
||||
|
|
Loading…
Reference in New Issue