fix: only save column width on quit

This commit is contained in:
aclist 2025-12-30 21:36:39 +09:00
parent 167935b963
commit 618ee47e53
2 changed files with 22 additions and 15 deletions

View File

@ -7,6 +7,8 @@ from pathlib import Path
from typing import Any, Callable, TYPE_CHECKING
import dzgui.api.pefile as PeFile
import dzgui.util._json as JSON # noqa
from dzgui.api.probe import test_steam_api, test_bm_api
from dzgui.api.mods import (
get_delimited_mods,
@ -176,6 +178,26 @@ class Controller:
self.toggle_config(Preferences.DEBUG)
def save_res_and_quit(self, *args: Any) -> None:
treeview = self.mediator.notebook.servers.get_active_treeview()
columns = treeview.get_columns()
columns_file = self.prefs.paths.columns
try:
data = JSON.read_json(columns_file)
except Exception as e:
logger.critical(e)
data = {"cols": {}}
for column in columns:
title = column.get_title()
size = column.get_width()
data["cols"][title] = size
try:
JSON.write_json(data, columns_file)
except Exception as e:
logger.critical(e)
if self.mediator.window.props.is_maximized:
Gtk.main_quit()
return

View File

@ -133,24 +133,9 @@ class ServerTreeView(TreeView):
"""
Propagate width change to other tabs
"""
# TODO: only update res file on quit
title = col.get_title()
size = col.get_width()
prefs = self.controller.get_prefs()
columns = prefs.paths.columns
try:
data = JSON.read_json(columns)
data["cols"][title] = size
except Exception as e:
logger.critical(e)
data = {"cols": {title: size}}
try:
JSON.write_json(data, columns)
except Exception as e:
logger.critical(e)
# NOTE: get final width after drag action completes
GLib.idle_add(self.controller.propagate_column_width, col)