Changeset 3 for trunk/UFormMain.pas


Ignore:
Timestamp:
Jan 14, 2018, 10:48:21 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Prepared context menu actions for Services list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormMain.pas

    r2 r3  
    4141  TFormMain = class(TForm)
    4242    AAlwaysOnTop: TAction;
     43    AServiceStart: TAction;
     44    AServiceRestart: TAction;
     45    AServiceStop: TAction;
    4346    ARestore: TAction;
    4447    ARun: TAction;
     
    8689    MenuItem4: TMenuItem;
    8790    MenuItem40: TMenuItem;
     91    MenuItem41: TMenuItem;
     92    MenuItem42: TMenuItem;
     93    MenuItem43: TMenuItem;
     94    MenuItem44: TMenuItem;
     95    MenuItem45: TMenuItem;
     96    MenuItem46: TMenuItem;
     97    MenuItem47: TMenuItem;
    8898    MenuItem5: TMenuItem;
    8999    MenuItem6: TMenuItem;
     
    95105    PageControl1: TPageControl;
    96106    Panel1: TPanel;
     107    PopupMenuServices: TPopupMenu;
    97108    PopupMenuProcesses: TPopupMenu;
    98109    PopupMenuDetails: TPopupMenu;
     
    110121    procedure ARestoreExecute(Sender: TObject);
    111122    procedure ARunExecute(Sender: TObject);
     123    procedure AServiceRestartExecute(Sender: TObject);
     124    procedure AServiceStartExecute(Sender: TObject);
     125    procedure AServiceStopExecute(Sender: TObject);
    112126    procedure FormCreate(Sender: TObject);
    113127    procedure FormDestroy(Sender: TObject);
     
    118132    procedure ListViewServicesData(Sender: TObject; Item: TListItem);
    119133    procedure PageControl1Change(Sender: TObject);
     134    procedure PopupMenuServicesPopup(Sender: TObject);
    120135    procedure TimerRefreshTimer(Sender: TObject);
    121136    procedure TrayIcon1Click(Sender: TObject);
     
    144159
    145160  var
    146     SystemServiceStatusText: array [TSystemServiceState] of string = ('Running', 'Stopped');
     161    SystemServiceStatusText: array [TSystemServiceState] of string = ('Stopped', 'Running');
    147162{ TFormMain }
    148163
     
    176191end;
    177192
     193procedure TFormMain.AServiceRestartExecute(Sender: TObject);
     194begin
     195  if Assigned(ListViewServices.Selected) then begin
     196    ExecuteAnWaitForOutput('/bin/systemctl', ['restart',
     197      TSystemService(ListViewServices.Selected.Data).Name])
     198  end;
     199end;
     200
     201procedure TFormMain.AServiceStartExecute(Sender: TObject);
     202begin
     203  ExecuteAnWaitForOutput('/bin/systemctl', ['start',
     204    TSystemService(ListViewServices.Selected.Data).Name])
     205end;
     206
     207procedure TFormMain.AServiceStopExecute(Sender: TObject);
     208begin
     209  ExecuteAnWaitForOutput('/bin/systemctl', ['stop',
     210    TSystemService(ListViewServices.Selected.Data).Name])
     211end;
     212
    178213procedure TFormMain.FormCreate(Sender: TObject);
    179214begin
     
    204239  if Item.Index < Processes.Count then
    205240  with TSystemProcess(Processes[Item.Index]) do begin
     241    Item.Data := Processes[Item.Index];
    206242    Item.Caption := Name;
    207243    Item.SubItems.Add(IntToStr(PID));
     
    218254  if Item.Index < Processes.Count then
    219255  with TSystemProcess(Processes[Item.Index]) do begin
     256    Item.Data := Processes[Item.Index];
    220257    Item.Caption := Name;
    221258    Item.SubItems.Add(FloatToStr(Cpu));
     
    230267  if Item.Index < Services.Count then
    231268  with TSystemService(Services[Item.Index]) do begin
     269    Item.Data := Services[Item.Index];
    232270    Item.Caption := Name;
    233271    Item.SubItems.Add('');
     
    241279begin
    242280  ReloadTab;
     281end;
     282
     283procedure TFormMain.PopupMenuServicesPopup(Sender: TObject);
     284begin
     285  AServiceRestart.Enabled := Assigned(ListViewServices.Selected) and
     286    (TSystemService(ListViewServices.Selected.Data).State = ssRunning);
     287  AServiceStop.Enabled := Assigned(ListViewServices.Selected) and
     288    (TSystemService(ListViewServices.Selected.Data).State = ssRunning);
     289  AServiceStart.Enabled := Assigned(ListViewServices.Selected) and
     290    (TSystemService(ListViewServices.Selected.Data).State = ssStopped);
    243291end;
    244292
Note: See TracChangeset for help on using the changeset viewer.