forked from clan/clan-core
Merge pull request 'Clan VM Manager: add dropdown to add more machines' (#827) from hsjobeki-main into main
This commit is contained in:
commit
13457eca0a
@ -33,6 +33,7 @@ class ClanGroup(GObject.Object):
|
||||
super().__init__()
|
||||
self.url = url
|
||||
self.vms = vms
|
||||
self.clan_name = vms[0].data.flake.clan_name
|
||||
self.list_store = Gio.ListStore.new(VM)
|
||||
|
||||
for vm in vms:
|
||||
@ -68,6 +69,26 @@ class Clans:
|
||||
|
||||
return cls._instance
|
||||
|
||||
def filter_by_name(self, text: str) -> None:
|
||||
if text:
|
||||
filtered_list = self.list_store
|
||||
filtered_list.remove_all()
|
||||
|
||||
groups: dict[str | Path, list["VM"]] = {}
|
||||
for vm in get_saved_vms():
|
||||
ll = groups.get(vm.data.flake.flake_url, [])
|
||||
print(text, vm.data.flake.vm.machine_name)
|
||||
if text.lower() in vm.data.flake.vm.machine_name.lower():
|
||||
ll.append(vm)
|
||||
groups[vm.data.flake.flake_url] = ll
|
||||
|
||||
for url, vm_list in groups.items():
|
||||
grp = ClanGroup(url, vm_list)
|
||||
filtered_list.append(grp)
|
||||
|
||||
else:
|
||||
self.refresh()
|
||||
|
||||
def refresh(self) -> None:
|
||||
self.list_store.remove_all()
|
||||
init_grp_store(self.list_store)
|
||||
@ -235,7 +256,7 @@ class VMS:
|
||||
filtered_list = self.list_store
|
||||
filtered_list.remove_all()
|
||||
for vm in get_saved_vms():
|
||||
if text.lower() in vm.data.flake.clan_name.lower():
|
||||
if text.lower() in vm.data.flake.vm.machine_name.lower():
|
||||
filtered_list.append(vm)
|
||||
else:
|
||||
self.refresh()
|
||||
|
@ -4,7 +4,7 @@ from functools import partial
|
||||
from typing import Any
|
||||
|
||||
import gi
|
||||
from clan_cli import ClanError, history
|
||||
from clan_cli import ClanError, history, machines
|
||||
from clan_cli.clan_uri import ClanURI
|
||||
|
||||
from clan_vm_manager.models.interfaces import ClanConfig
|
||||
@ -83,7 +83,31 @@ class ClanList(Gtk.Box):
|
||||
# boxed_list.remove_css_class("no-shadow")
|
||||
|
||||
grp = Adw.PreferencesGroup()
|
||||
grp.set_title(group.url)
|
||||
grp.set_title(group.clan_name)
|
||||
grp.set_description(group.url)
|
||||
|
||||
add_action = Gio.SimpleAction.new("add", GLib.VariantType.new("s"))
|
||||
add_action.connect("activate", self.on_add)
|
||||
app = Gio.Application.get_default()
|
||||
app.add_action(add_action)
|
||||
|
||||
menu_model = Gio.Menu()
|
||||
for vm in machines.list.list_machines(flake_url=group.url):
|
||||
if vm not in [item.data.flake.flake_attr for item in group.list_store]:
|
||||
menu_model.append(vm, f"app.add::{vm}")
|
||||
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
|
||||
box.set_valign(Gtk.Align.CENTER)
|
||||
|
||||
add_button = Gtk.MenuButton()
|
||||
add_button.set_icon_name("list-add")
|
||||
add_button.set_has_frame(False)
|
||||
add_button.set_menu_model(menu_model)
|
||||
|
||||
box.append(add_button)
|
||||
box.append(Gtk.Label.new("Add machine"))
|
||||
|
||||
grp.set_header_suffix(box)
|
||||
|
||||
vm_list = create_boxed_list(
|
||||
model=group.list_store, render_row=self.render_vm_row
|
||||
@ -93,8 +117,12 @@ class ClanList(Gtk.Box):
|
||||
|
||||
return grp
|
||||
|
||||
def on_add(self, action: Any, parameter: Any) -> None:
|
||||
target = parameter.get_string()
|
||||
print("Adding new machine", target)
|
||||
|
||||
def on_search_changed(self, entry: Gtk.SearchEntry) -> None:
|
||||
VMS.use().filter_by_name(entry.get_text())
|
||||
Clans.use().filter_by_name(entry.get_text())
|
||||
# Disable the shadow if the list is empty
|
||||
if not VMS.use().list_store.get_n_items():
|
||||
self.group_list.add_css_class("no-shadow")
|
||||
|
Loading…
Reference in New Issue
Block a user