Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit 71827b7

Browse files
committed
More work on the status bar
The VM count per status is now implemented
1 parent a5cdf85 commit 71827b7

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

86BoxManager/frmMain.cs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ private void LoadVMs()
322322
lstVMs.Items.Add(newLvi);
323323
}
324324

325-
lblVMCount.Text += " " + lstVMs.Items.Count;
325+
VMCountRefresh();
326326
}
327327
catch (Exception ex)
328328
{
@@ -555,6 +555,7 @@ private void VMPause()
555555
toolTip.SetToolTip(btnPause, "Resume this virtual machine");
556556

557557
VMSort(sortColumn, sortOrder);
558+
VMCountRefresh();
558559
}
559560

560561
//Resumes the selected VM
@@ -576,6 +577,7 @@ private void VMResume()
576577
toolTip.SetToolTip(btnPause, "Pause this virtual machine");
577578

578579
VMSort(sortColumn, sortOrder);
580+
VMCountRefresh();
579581
}
580582

581583
//Starts the selected VM
@@ -636,6 +638,8 @@ private void VMStart()
636638
btnReset.Enabled = true;
637639
btnCtrlAltDel.Enabled = true;
638640
btnConfigure.Enabled = true;
641+
642+
VMCountRefresh();
639643
}
640644
else
641645
{ //Inform the user what happened
@@ -660,6 +664,7 @@ private void VMStart()
660664
}
661665

662666
VMSort(sortColumn, sortOrder);
667+
663668
}
664669

665670
//Sends a running/pause VM a request to stop without asking the user for confirmation
@@ -679,6 +684,7 @@ private void VMForceStop()
679684
}
680685

681686
VMSort(sortColumn, sortOrder);
687+
VMCountRefresh();
682688
}
683689

684690
//Sends a running/paused VM a request to stop and asking the user for confirmation
@@ -699,6 +705,7 @@ private void VMRequestStop()
699705
}
700706

701707
VMSort(sortColumn, sortOrder);
708+
VMCountRefresh();
702709
}
703710

704711
//Start VM if it's stopped or stop it if it's running/paused
@@ -791,6 +798,7 @@ private void VMConfigure()
791798
}
792799

793800
VMSort(sortColumn, sortOrder);
801+
VMCountRefresh();
794802
}
795803

796804
private void resetCTRLALTDELETEToolStripMenuItem_Click(object sender, EventArgs e)
@@ -812,6 +820,7 @@ private void VMCtrlAltDel()
812820
pauseToolStripMenuItem.Text = "Pause";
813821
pauseToolStripMenuItem.ToolTipText = "Pause this virtual machine";
814822
}
823+
VMCountRefresh();
815824
}
816825

817826
private void hardResetToolStripMenuItem_Click(object sender, EventArgs e)
@@ -828,6 +837,7 @@ private void VMHardReset()
828837
PostMessage(vm.hWnd, 0x8892, IntPtr.Zero, IntPtr.Zero);
829838
SetForegroundWindow(vm.hWnd);
830839
}
840+
VMCountRefresh();
831841
}
832842

833843
//For double clicking an item, do something based on VM status
@@ -893,6 +903,9 @@ public void VMAdd(string name, string desc, bool openCFG, bool startVM)
893903
{
894904
VMConfigure();
895905
}
906+
907+
VMSort(sortColumn, sortOrder);
908+
VMCountRefresh();
896909
}
897910

898911
//Checks if a VM with this name already exists
@@ -1024,6 +1037,7 @@ private void VMRemove()
10241037
}
10251038
}
10261039
VMSort(sortColumn, sortOrder);
1040+
VMCountRefresh();
10271041
}
10281042

10291043
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
@@ -1090,10 +1104,11 @@ protected override void WndProc(ref Message m)
10901104
btnConfigure.Enabled = true;
10911105
}
10921106
}
1107+
1108+
VMCountRefresh();
10931109
}
10941110
else if (m.WParam.ToInt32() == 0) //VM was resumed
10951111
{
1096-
Console.WriteLine(m.Msg + ": VM was resumed");
10971112
foreach (ListViewItem lvi in lstVMs.Items)
10981113
{
10991114
VM vm = (VM)lvi.Tag;
@@ -1114,13 +1129,14 @@ protected override void WndProc(ref Message m)
11141129
btnConfigure.Enabled = true;
11151130
}
11161131
}
1132+
1133+
VMCountRefresh();
11171134
}
11181135
}
11191136
if (m.Msg == 0x8896)
11201137
{
11211138
if (m.WParam.ToInt32() == 1) //A dialog was opened
11221139
{
1123-
Console.WriteLine(m.Msg + ": a dialog was opened");
11241140
foreach (ListViewItem lvi in lstVMs.Items)
11251141
{
11261142
VM vm = (VM)lvi.Tag;
@@ -1142,10 +1158,11 @@ protected override void WndProc(ref Message m)
11421158
btnCtrlAltDel.Enabled = false;
11431159
}
11441160
}
1161+
1162+
VMCountRefresh();
11451163
}
11461164
else if (m.WParam.ToInt32() == 0) //A dialog was closed
11471165
{
1148-
Console.WriteLine(m.Msg + ": a dialog was closed");
11491166
foreach (ListViewItem lvi in lstVMs.Items)
11501167
{
11511168
VM vm = (VM)lvi.Tag;
@@ -1171,12 +1188,13 @@ protected override void WndProc(ref Message m)
11711188
btnCtrlAltDel.Enabled = true;
11721189
}
11731190
}
1191+
1192+
VMCountRefresh();
11741193
}
11751194
}
11761195

11771196
if (m.Msg == 0x8897) //Shutdown confirmed
11781197
{
1179-
Console.WriteLine(m.Msg + ": shutdown was confirmed");
11801198
foreach (ListViewItem lvi in lstVMs.Items)
11811199
{
11821200
VM vm = (VM)lvi.Tag;
@@ -1227,6 +1245,8 @@ protected override void WndProc(ref Message m)
12271245
}
12281246
}
12291247
}
1248+
1249+
VMCountRefresh();
12301250
}
12311251
//This is the WM_COPYDATA message, used here to pass command line args to an already running instance
12321252
//NOTE: This code will have to be modified in case more command line arguments are added in the future.
@@ -1471,7 +1491,9 @@ private void VMKill()
14711491
}
14721492
}
14731493
}
1494+
14741495
VMSort(sortColumn, sortOrder);
1496+
VMCountRefresh();
14751497
}
14761498

14771499
private void killToolStripMenuItem_Click(object sender, EventArgs e)
@@ -1632,6 +1654,9 @@ public void VMImport(string name, string desc, string importPath, bool openCFG,
16321654
{
16331655
VMConfigure();
16341656
}
1657+
1658+
VMSort(sortColumn, sortOrder);
1659+
VMCountRefresh();
16351660
}
16361661

16371662
private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
@@ -1640,5 +1665,28 @@ private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
16401665
dlgCloneVM dc = new dlgCloneVM(vm.Path);
16411666
dc.ShowDialog();
16421667
}
1668+
1669+
//Refreshes the VM counter in the status bar
1670+
private void VMCountRefresh()
1671+
{
1672+
int runningVMs = 0;
1673+
int pausedVMs = 0;
1674+
int waitingVMs = 0;
1675+
int stoppedVMs = 0;
1676+
1677+
foreach(ListViewItem lvi in lstVMs.Items)
1678+
{
1679+
VM vm = (VM)lvi.Tag;
1680+
switch (vm.Status)
1681+
{
1682+
case VM.STATUS_PAUSED: pausedVMs++; break;
1683+
case VM.STATUS_RUNNING: runningVMs++; break;
1684+
case VM.STATUS_STOPPED: stoppedVMs++; break;
1685+
case VM.STATUS_WAITING: waitingVMs++; break;
1686+
}
1687+
}
1688+
1689+
lblVMCount.Text = "Total VMs: " + lstVMs.Items.Count + " | Running: " + runningVMs + " | Paused: " + pausedVMs + " | Waiting: " + waitingVMs + " | Stopped: " + stoppedVMs;
1690+
}
16431691
}
16441692
}

0 commit comments

Comments
 (0)