MCPcopy Create free account
hub / github.com/78/tenbox / UpdateCommandStates

Function UpdateCommandStates

src/manager/ui/win32_ui_shell.cpp:743–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

741// ── Update toolbar/menu enable state ──
742
743static void UpdateCommandStates(Impl* p) {
744 bool has_sel = p->selected_index >= 0 &&
745 p->selected_index < static_cast<int>(p->records.size());
746 bool running = has_sel && IsVmRunning(p->records[p->selected_index].state);
747 bool stopping = has_sel && p->records[p->selected_index].state == VmPowerState::kStopping;
748 bool ga_ok = has_sel && p->records[p->selected_index].guest_agent_connected;
749
750 auto EnableCmd = [&](UINT id, bool en) {
751 SendMessage(p->toolbar, TB_ENABLEBUTTON, id, MAKELONG(en ? TRUE : FALSE, 0));
752 HMENU vm_menu = GetSubMenu(p->menu_bar, 1);
753 if (vm_menu) {
754 EnableMenuItem(vm_menu, id, en ? MF_ENABLED : MF_GRAYED);
755 }
756 };
757
758 EnableCmd(IDM_START, has_sel && !running);
759 EnableCmd(IDM_STOP, has_sel && running);
760 EnableCmd(IDM_REBOOT, has_sel && running && !stopping && ga_ok);
761 EnableCmd(IDM_SHUTDOWN, has_sel && running && !stopping && ga_ok);
762 EnableCmd(IDM_EDIT, has_sel);
763 EnableCmd(IDM_CLONE, has_sel && !running);
764 EnableCmd(IDM_DELETE, has_sel && !running);
765 EnableCmd(IDM_SHARED_FOLDERS, has_sel);
766 EnableCmd(IDM_PORT_FORWARDS, has_sel);
767
768 SendMessage(p->toolbar, TB_ENABLEBUTTON, IDM_DPI_ZOOM,
769 MAKELONG((has_sel && p->dpi != 96) ? TRUE : FALSE, 0));
770 bool dpi_scaled = has_sel && p->records[p->selected_index].spec.dpi_scaled;
771 SendMessage(p->toolbar, TB_CHECKBUTTON, IDM_DPI_ZOOM,
772 MAKELONG(dpi_scaled ? TRUE : FALSE, 0));
773
774 InvalidateRect(p->toolbar, nullptr, FALSE);
775
776 p->console_tab.SetEnabled(running);
777}
778
779// ── Splitter hit-test ──
780

Callers 3

MainWndProcFunction · 0.85
Win32UiShellMethod · 0.85
RefreshVmListMethod · 0.85

Calls 3

IsVmRunningFunction · 0.85
SetEnabledMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected