mirror of
https://github.com/aclist/dztui.git
synced 2026-08-25 17:32:36 +02:00
feat: unset fav server by button
Some checks failed
Mirror to Codeberg / mirror-to-codeberg (push) Has been cancelled
Some checks failed
Mirror to Codeberg / mirror-to-codeberg (push) Has been cancelled
This commit is contained in:
parent
42feeae8d0
commit
cf70182733
@ -38,6 +38,7 @@ HEX_ORANGE = "#FFAC1C"
|
||||
CARET_DOWN = "go-down-symbolic"
|
||||
CARET_UP = "go-up-symbolic"
|
||||
CLIPBOARD = "edit-copy-symbolic"
|
||||
CLOSE = "window-close-symbolic"
|
||||
FOLDER = "folder-symbolic"
|
||||
EDIT_DELETE = "edit-delete-symbolic"
|
||||
ERROR = "dialog-error-symbolic"
|
||||
|
||||
@ -402,6 +402,9 @@ class Controller(GObject.GObject):
|
||||
def get_menu(self) -> "MenuTreeView":
|
||||
return self.mediator.menu
|
||||
|
||||
def unset_fav(self) -> None:
|
||||
self.config_man.unset_fav()
|
||||
|
||||
def has_favorites(self) -> bool:
|
||||
favs = self.config_man.get_favorites()
|
||||
if len(favs) < 1:
|
||||
@ -459,6 +462,9 @@ class Controller(GObject.GObject):
|
||||
open_workshop_page(mod, cmd)
|
||||
|
||||
def has_note(self) -> bool:
|
||||
# TODO: get record string, store in memory
|
||||
# get note by record, get is in favs, etc. store as a block
|
||||
# this is only used by context mixin
|
||||
note = self.get_note()
|
||||
if len(note) > 0:
|
||||
return True
|
||||
@ -473,11 +479,13 @@ class Controller(GObject.GObject):
|
||||
return self.notes_man.get_note(record)
|
||||
|
||||
def add_note(self, note: str) -> None:
|
||||
# TODO: record should be cached upon creation of dialog
|
||||
tv = self.get_active_treeview()
|
||||
record = tv.get_record_string()
|
||||
self.notes_man.add_note(record, note)
|
||||
|
||||
def delete_note(self) -> None:
|
||||
# TODO: record should be cached upon creation of dialog
|
||||
tv = self.get_active_treeview()
|
||||
record = tv.get_record_string()
|
||||
self.notes_man.delete_note(record)
|
||||
|
||||
@ -160,6 +160,13 @@ class ConfigManager:
|
||||
except Exception:
|
||||
return
|
||||
|
||||
def unset_fav(self) -> None:
|
||||
try:
|
||||
self.write_config(Preferences.FAV_LBL, "")
|
||||
self.write_config(Preferences.FAV_SRV, "")
|
||||
except Exception:
|
||||
return
|
||||
|
||||
def write_config(self, key: Preferences, value: str) -> None:
|
||||
try:
|
||||
real_key = self.enum_to_key(key)
|
||||
|
||||
@ -10,6 +10,7 @@ from dzgui.util.strings import (
|
||||
)
|
||||
from dzgui.const.constants import (
|
||||
CLIPBOARD,
|
||||
CLOSE,
|
||||
INPUT_KEYBOARD,
|
||||
LIST_ADD,
|
||||
REFRESH_ICON,
|
||||
@ -128,6 +129,14 @@ class CopyIpButton(ClipboardButton):
|
||||
self.set_tooltip_text("Copy IP to clipboard")
|
||||
|
||||
|
||||
class CloseButton(IconTextButton):
|
||||
def __init__(self, label: str) -> None:
|
||||
super().__init__(icon=CLOSE, label=label)
|
||||
|
||||
# TODO: strings
|
||||
self.set_tooltip_text("Unset this server as favorite")
|
||||
|
||||
|
||||
class WebButton(IconTextButton):
|
||||
def __init__(self, label: str) -> None:
|
||||
super().__init__(icon=WEB_BROWSER, label=label)
|
||||
|
||||
@ -6,6 +6,7 @@ from dzgui.strings import connect_panel
|
||||
from dzgui.util.keys import is_ctrl_mask
|
||||
from dzgui.views.components.buttons import (
|
||||
AddButton,
|
||||
CloseButton,
|
||||
CopyIpButton,
|
||||
Icon,
|
||||
IconButton,
|
||||
@ -187,17 +188,27 @@ class FavPanel(Gtk.Frame):
|
||||
self.fav_button = SteamConnectButton()
|
||||
self.fav_button.connect("clicked", self._on_connect_clicked)
|
||||
self.copy_button = CopyIpButton(self.controller, self.get_fav_ip)
|
||||
|
||||
# TODO: strings
|
||||
self.unset_button = CloseButton("Unset")
|
||||
self.unset_button.connect("clicked", self._on_unset_clicked)
|
||||
|
||||
if favorite is None:
|
||||
self.toggle_buttons(False)
|
||||
|
||||
# NOTE: disable vscrollbar to prevent layout jumping behavior
|
||||
scrollable_label = Gtk.ScrolledWindow(vscrollbar_policy=Gtk.PolicyType.NEVER)
|
||||
scrollable_label.add(self.fav_label)
|
||||
self.scrollable_label = Gtk.ScrolledWindow(
|
||||
vscrollbar_policy=Gtk.PolicyType.NEVER, overlay_scrolling=False
|
||||
)
|
||||
self.scrollable_label.add(self.fav_label)
|
||||
|
||||
grid = Gtk.Grid(margin=10, vexpand=False, column_spacing=15, row_spacing=5)
|
||||
grid.attach(scrollable_label, 0, 0, 3, ROWS)
|
||||
grid.attach(self.scrollable_label, 0, 0, 3, ROWS)
|
||||
grid.attach_next_to(
|
||||
self.copy_button, scrollable_label, Gtk.PositionType.RIGHT, COLS, ROWS
|
||||
self.unset_button, self.scrollable_label, Gtk.PositionType.RIGHT, COLS, ROWS
|
||||
)
|
||||
grid.attach_next_to(
|
||||
self.copy_button, self.unset_button, Gtk.PositionType.RIGHT, COLS, ROWS
|
||||
)
|
||||
grid.attach_next_to(
|
||||
self.fav_button, self.copy_button, Gtk.PositionType.RIGHT, COLS, ROWS
|
||||
@ -205,8 +216,16 @@ class FavPanel(Gtk.Frame):
|
||||
|
||||
self.add(grid)
|
||||
|
||||
def _on_unset_clicked(self, button: Gtk.Button) -> None:
|
||||
try:
|
||||
self.controller.unset_fav()
|
||||
except Exception:
|
||||
return
|
||||
self.fav_label.set_text(connect_panel.favs_empty)
|
||||
self.toggle_buttons(False)
|
||||
|
||||
def toggle_buttons(self, state: bool) -> None:
|
||||
for button in self.fav_button, self.copy_button:
|
||||
for button in self.fav_button, self.copy_button, self.unset_button:
|
||||
button.set_sensitive(state)
|
||||
|
||||
def _on_connect_clicked(self, button: Gtk.Button) -> None:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user