mirror of https://github.com/berriedale/arun
Refactor the launcher code into a platform specific launcher
This commit is contained in:
parent
7d4e4a0908
commit
58db0578c3
|
@ -29,7 +29,8 @@ with Gtk.Widget;
|
|||
with Gtk.Search_Entry;
|
||||
with Gtkada.Builder; use Gtkada.Builder;
|
||||
|
||||
with Arun.Launcher;
|
||||
with Arun;
|
||||
with Arun.Launchers.Unix;
|
||||
|
||||
package body Arun.Handlers is
|
||||
|
||||
|
@ -59,13 +60,13 @@ package body Arun.Handlers is
|
|||
Widget : Gtk_Search_Entry := Gtk_Search_Entry (Get_Object (Object, "commandEntry"));
|
||||
Command : constant String := Widget.Get_Text;
|
||||
|
||||
Full_Path : aliased constant String := Arun.Launcher.Find_Full_Path (Command);
|
||||
--Full_Path : aliased constant String := Arun.Launcher.Find_Full_Path (Command);
|
||||
begin
|
||||
|
||||
if Full_Path /= "" then
|
||||
Put_Line ("Should Execute: " & Command);
|
||||
Arun.Launcher.Execute (Full_Path);
|
||||
end if;
|
||||
-- if Full_Path /= "" then
|
||||
-- Put_Line ("Should Execute: " & Command);
|
||||
-- --Arun.Launcher.Execute (Full_Path);
|
||||
-- end if;
|
||||
|
||||
Gtk.Main.Main_Quit;
|
||||
end Execute_Command;
|
||||
|
@ -74,11 +75,16 @@ package body Arun.Handlers is
|
|||
Event : in Gdk.Event.Gdk_Event_Key) return Boolean is
|
||||
use Ada.Text_IO;
|
||||
use Gdk.Types;
|
||||
use Gdk.Types.Keysyms;
|
||||
|
||||
begin
|
||||
Put_Line ("Key pressed");
|
||||
|
||||
if Event.Keyval = Gdk.Types.Keysyms.GDK_Escape then
|
||||
if Event.Keyval = GDK_Tab then
|
||||
Put_Line ("Should attempt to auto-complete");
|
||||
end if;
|
||||
|
||||
|
||||
if Event.Keyval = GDK_Escape then
|
||||
Put_Line ("Escape! Exiting arun");
|
||||
Gtk.Main.Main_Quit;
|
||||
end if;
|
||||
|
|
|
@ -24,6 +24,8 @@ with Gtkada.Builder; use Gtkada.Builder;
|
|||
with Gtk.Widget;
|
||||
with Gdk.Event;
|
||||
|
||||
with Arun.Launchers.Unix;
|
||||
|
||||
package Arun.Handlers is
|
||||
|
||||
procedure Quit (Object : access Gtkada_Builder_Record'Class);
|
||||
|
@ -39,4 +41,5 @@ package Arun.Handlers is
|
|||
Event : in Gdk.Event.Gdk_Event_Key) return Boolean;
|
||||
-- On key-presses in the commandEntry field
|
||||
|
||||
|
||||
end Arun.Handlers;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Command_Line.Environment;
|
||||
with Ada.Environment_Variables;
|
||||
|
@ -25,32 +26,40 @@ with GNAT.OS_Lib;
|
|||
with GNAT.String_Split;
|
||||
with Interfaces.C;
|
||||
with Interfaces.C.Strings;
|
||||
with System;
|
||||
|
||||
package body Arun.Launcher is
|
||||
|
||||
function Find_Full_Path (Snippet : in String) return String is
|
||||
use GNAT.String_Split;
|
||||
package body Arun.Launchers.Unix is
|
||||
|
||||
PATH : constant String := Ada.Environment_Variables.Value ("PATH");
|
||||
procedure Initialize (L : in out UnixLauncher) is
|
||||
use Gnat.String_Split;
|
||||
|
||||
PATH : constant String := Ada.Environment_Variables.Value ("PATH");
|
||||
Separator : constant String := ":";
|
||||
Path_Components : Slice_Set;
|
||||
|
||||
begin
|
||||
|
||||
Create (S => Path_Components,
|
||||
From => PATH,
|
||||
Separators => Separator,
|
||||
Mode => Single);
|
||||
Create (L.Path_Components, PATH, Separator, Single);
|
||||
|
||||
L.Initialized := True;
|
||||
end Initialize;
|
||||
|
||||
|
||||
for Index in 1 .. Slice_Count (Path_Components) loop
|
||||
Put_Line ("Looking for an executable in " & Slice (S => Path_Components,
|
||||
function Find_Full_Path (L : in UnixLauncher;
|
||||
Path_Snippet : in String) return String is
|
||||
use GNAT.String_Split;
|
||||
begin
|
||||
|
||||
if L.Initialized /= True then
|
||||
Put_Line ("Uninitialized UnixLauncher!");
|
||||
return "";
|
||||
end if;
|
||||
|
||||
for Index in 1 .. Slice_Count (L.Path_Components) loop
|
||||
Put_Line ("Looking for an executable in " & Slice (S => L.Path_Components,
|
||||
Index => Index));
|
||||
declare
|
||||
Path_Component : constant String := Slice (S => Path_Components,
|
||||
Path_Component : constant String := Slice (S => L.Path_Components,
|
||||
Index => Index);
|
||||
Computed_Location : constant String := Path_Component & "/" & Snippet;
|
||||
Computed_Location : constant String := Path_Component & "/" & Path_Snippet;
|
||||
begin
|
||||
|
||||
if GNAT.OS_Lib.Is_Executable_File (Computed_Location) then
|
||||
|
@ -61,12 +70,13 @@ package body Arun.Launcher is
|
|||
|
||||
end loop;
|
||||
|
||||
|
||||
return "";
|
||||
end Find_Full_Path;
|
||||
|
||||
|
||||
procedure Execute (Executable_Path : in String) is
|
||||
procedure Execute (L : in UnixLauncher;
|
||||
Executable : in String) is
|
||||
|
||||
use GNAT.OS_Lib;
|
||||
use Interfaces.C;
|
||||
use Interfaces.C.Strings;
|
||||
|
@ -84,22 +94,21 @@ package body Arun.Launcher is
|
|||
Convention => C,
|
||||
Link_Name => "perror";
|
||||
|
||||
Default_Args : Chars_Ptr_Array (1 .. 2) := (1 => New_String (Executable_Path), 2 => Null_Ptr);
|
||||
Default_Args : Chars_Ptr_Array (1 .. 2) := (1 => New_String (Executable), 2 => Null_Ptr);
|
||||
Status : Integer;
|
||||
begin
|
||||
Put_Line ("Spawning " & Executable_Path);
|
||||
Put_Line ("Spawning " & Executable);
|
||||
|
||||
Status := Exec_And_Replace (Filename => To_C (Item => Executable_Path,
|
||||
Status := Exec_And_Replace (Filename => To_C (Item => Executable,
|
||||
Append_Nul => True),
|
||||
Arguments => Default_Args);
|
||||
|
||||
-- If the Exec_And_Replace function returns then something has gone wrong
|
||||
Put_Line ("Spawned " & Executable_Path & " with " & Status'Img);
|
||||
Put_Line ("Spawned " & Executable & " with " & Status'Img);
|
||||
|
||||
if Status /= 0 then
|
||||
Print_Errno ("Something went wrong");
|
||||
end if;
|
||||
|
||||
end Execute;
|
||||
|
||||
end Arun.Launcher;
|
||||
end Arun.Launchers.Unix;
|
|
@ -0,0 +1,36 @@
|
|||
------------------------------------------------------------------------------
|
||||
--
|
||||
-- Copyright (C) 2017 R. Tyler Croy <tyler@linux.com>
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or
|
||||
-- modify it under the terms of the GNU General Public License
|
||||
-- as published by the Free Software Foundation; either version 2
|
||||
-- of the License, or (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with Arun;
|
||||
|
||||
private with GNAT.String_Split;
|
||||
|
||||
package Arun.Launchers.Unix is
|
||||
type UnixLauncher is new Arun.Launcher_Type with private;
|
||||
|
||||
procedure Initialize (L : in out UnixLauncher);
|
||||
|
||||
private
|
||||
|
||||
type UnixLauncher is new Arun.Launcher_Type with record
|
||||
Initialized : Boolean := False;
|
||||
Path_Components : Gnat.String_Split.Slice_Set;
|
||||
end record;
|
||||
|
||||
end Arun.Launchers.Unix;
|
|
@ -17,11 +17,6 @@
|
|||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
package Arun.Launcher is
|
||||
|
||||
function Find_Full_Path (Snippet : in String) return String;
|
||||
-- Determine the full path of a Snippet based on the PATH environment variable
|
||||
|
||||
procedure Execute (Executable_Path : in String);
|
||||
-- Spawn the process for the Executable_Path
|
||||
end Arun.Launcher;
|
||||
package Arun.Launchers is
|
||||
end Arun.Launchers;
|
|
@ -0,0 +1,33 @@
|
|||
------------------------------------------------------------------------------
|
||||
--
|
||||
-- Copyright (C) 2017 R. Tyler Croy <tyler@linux.com>
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or
|
||||
-- modify it under the terms of the GNU General Public License
|
||||
-- as published by the Free Software Foundation; either version 2
|
||||
-- of the License, or (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
|
||||
with Gtk.Widget; use Gtk.Widget;
|
||||
|
||||
package body Arun.View is
|
||||
|
||||
function From_Object (Builder : out Arun_Builder_Record'Class;
|
||||
Object_Name : in String) return Gtk_Widget is
|
||||
-- Return the Gtk_Widget for the specified Object_Name in the Builder.
|
||||
-- Basically pass the name of the widget given in Glade.
|
||||
begin
|
||||
return Gtk_Widget (Builder.Get_Object (Object_Name));
|
||||
end From_Object;
|
||||
|
||||
end Arun.View;
|
|
@ -0,0 +1,35 @@
|
|||
------------------------------------------------------------------------------
|
||||
--
|
||||
-- Copyright (C) 2017 R. Tyler Croy <tyler@linux.com>
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or
|
||||
-- modify it under the terms of the GNU General Public License
|
||||
-- as published by the Free Software Foundation; either version 2
|
||||
-- of the License, or (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
with Gtkada.Builder; use Gtkada.Builder;
|
||||
with Arun.Launchers.Unix;
|
||||
|
||||
with Gtk.Widget;
|
||||
|
||||
package Arun.View is
|
||||
|
||||
type Arun_Builder_Record is new Gtkada_Builder_Record with record
|
||||
Launcher : Arun.Launchers.Unix.UnixLauncher;
|
||||
end record;
|
||||
type Arun_Builder is access all Arun_Builder_Record'Class;
|
||||
|
||||
function From_Object (Builder : out Arun_Builder_Record'Class;
|
||||
Object_Name : in String) return Gtk.Widget.Gtk_Widget;
|
||||
|
||||
end Arun.View;
|
Loading…
Reference in New Issue