Add ability to add custom remotes

This commit is contained in:
heliguy
2024-07-22 15:46:46 -04:00
parent 15584632d2
commit f8c8dde16f
3 changed files with 41 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
from gi.repository import Adw, Gtk, GLib, Gio
from .host_info import HostInfo
from .error_toast import ErrorToast
import subprocess
import subprocess, re
@Gtk.Template(resource_path="/io/github/flattool/Warehouse/remotes_page/add_remote_dialog.ui")
class AddRemoteDialog(Adw.Dialog):
@@ -58,6 +58,23 @@ class AddRemoteDialog(Adw.Dialog):
Gio.Task.new(None, None, callback).run_in_thread(thread)
def check_entries(self, row):
is_passing = re.match(self.rexes[row], row.get_text())
if is_passing:
row.remove_css_class("error")
else:
row.add_css_class("error")
match row:
case self.title_row:
self.title_passes = bool(is_passing)
case self.name_row:
self.name_passes = bool(is_passing)
case self.url_row:
self.url_passes = bool(is_passing)
self.apply_button.set_sensitive(self.title_passes and self.name_passes and self.url_passes)
def __init__(self, main_window, parent_page, remote_info=None, **kwargs):
super().__init__(**kwargs)
@@ -65,6 +82,15 @@ class AddRemoteDialog(Adw.Dialog):
self.string_list = Gtk.StringList(strings=HostInfo.installations)
self.main_window = main_window
self.parent_page = parent_page
self.rexes = {
self.title_row: "^(?=.*[A-Za-z0-9])[A-Za-z0-9._-]+( +[A-Za-z0-9._-]+)*$", #"^(?=.*[A-Za-z0-9])[A-Za-z0-9._-]+( [A-Za-z0-9._-]+)*$",
self.name_row: "^[a-zA-Z0-9\-._]+$",
self.url_row: "^[a-zA-Z0-9\-._~:/?#[\]@!$&\'()*+,;=]+$"
}
self.title_passes = False
self.name_passes = False
self.url_passes = False
# Apply
self.installation_row.set_model(self.string_list)
@@ -78,4 +104,7 @@ class AddRemoteDialog(Adw.Dialog):
self.apply_button.set_sensitive(True)
# Connections
self.apply_button.connect("clicked", self.on_apply)
self.apply_button.connect("clicked", self.on_apply)
self.title_row.connect("changed", self.check_entries)
self.name_row.connect("changed", self.check_entries)
self.url_row.connect("changed", self.check_entries)

View File

@@ -72,7 +72,6 @@ template $RemotesPage : Adw.NavigationPage {
}
Adw.ActionRow custom_remote_row {
activatable: true;
sensitive: false;
title: _("Add a Custom Remote");
subtitle: _("Manually enter new remote details");
[suffix]

View File

@@ -78,6 +78,8 @@ class RemotesPage(Adw.NavigationPage):
stack = gtc()
current_remotes_group = gtc()
new_remotes_group = gtc()
file_remote_row = gtc()
custom_remote_row = gtc()
# Statuses
loading_remotes = gtc()
@@ -106,10 +108,13 @@ class RemotesPage(Adw.NavigationPage):
self.search_button.set_sensitive(True)
for install in HostInfo.installations:
for remote in HostInfo.remotes[install]:
row = RemoteRow(self, install, remote)
self.current_remotes_group.add(row)
self.current_remote_rows.append(row)
try:
for remote in HostInfo.remotes[install]:
row = RemoteRow(self, install, remote)
self.current_remotes_group.add(row)
self.current_remote_rows.append(row)
except KeyError:
continue
GLib.idle_add(lambda *_: self.stack.set_visible_child(self.content_page))
@@ -174,6 +179,7 @@ class RemotesPage(Adw.NavigationPage):
# Connections
ms.connect("notify::show-sidebar", lambda *_: self.sidebar_button.set_active(ms.get_show_sidebar()))
self.sidebar_button.connect("toggled", lambda *_: ms.set_show_sidebar(self.sidebar_button.get_active()))
self.custom_remote_row.connect("activated", lambda *_: AddRemoteDialog(main_window, self).present(main_window))
# Appply
for item in self.new_remotes: