Skip to content

Commit 3275d4a

Browse files
authored
Merge pull request #24 from sysprog21/file-saving
Allow saving default config on first run
2 parents d7397d2 + c50e255 commit 3275d4a

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

guiconfig.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,13 @@ def menuconfig(kconf):
257257
def _load_config():
258258
# Loads any existing .config file. See the Kconfig.load_config() docstring.
259259
#
260-
# Returns True if .config is missing or outdated. We always prompt for
261-
# saving the configuration in that case.
260+
# Returns True if .config is missing or outdated. We prompt for saving the
261+
# configuration if there are actual changes or if no .config file exists
262+
# (so user can save the default configuration).
262263

263264
print(_kconf.load_config())
264265
if not os.path.exists(_conf_filename):
265-
# No .config
266+
# No .config exists - treat as changed so user can save defaults
266267
return True
267268

268269
return _needs_save()
@@ -1774,17 +1775,32 @@ def _vis_after(item):
17741775
def _on_quit(_=None):
17751776
# Called when the user wants to exit
17761777

1777-
if not _conf_changed:
1778+
config_exists = os.path.exists(_conf_filename)
1779+
1780+
if not _conf_changed and config_exists:
17781781
_quit("No changes to save (for '{}')".format(_conf_filename))
17791782
return
17801783

1784+
# Adjust dialog message if .config doesn't exist
1785+
if not config_exists:
1786+
dialog_title = "Quit"
1787+
dialog_message = (
1788+
"No configuration file found.\nSave new configuration before quitting?"
1789+
)
1790+
else:
1791+
dialog_title = "Quit"
1792+
dialog_message = "Save changes?"
1793+
17811794
while True:
1782-
ync = messagebox.askyesnocancel("Quit", "Save changes?")
1795+
ync = messagebox.askyesnocancel(dialog_title, dialog_message)
17831796
if ync is None:
17841797
return
17851798

17861799
if not ync:
1787-
_quit("Configuration ({}) was not saved".format(_conf_filename))
1800+
if not config_exists:
1801+
_quit("Configuration was not saved")
1802+
else:
1803+
_quit("Configuration ({}) was not saved".format(_conf_filename))
17881804
return
17891805

17901806
if _try_save(_kconf.write_config, _conf_filename, "configuration"):

menuconfig.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -863,13 +863,14 @@ def _wrapper(func):
863863
def _load_config():
864864
# Loads any existing .config file. See the Kconfig.load_config() docstring.
865865
#
866-
# Returns True if .config exists and is outdated. We prompt for saving the
867-
# configuration only if there are actual changes.
866+
# Returns True if .config exists and is outdated, or if .config doesn't exist
867+
# at all. We prompt for saving the configuration if there are actual changes
868+
# or if no .config file exists (so user can save the default configuration).
868869

869870
print(_kconf.load_config())
870871
if not os.path.exists(_conf_filename):
871-
# No .config - no changes yet
872-
return False
872+
# No .config exists - treat as changed so user can save defaults
873+
return True
873874

874875
return _needs_save()
875876

@@ -1071,13 +1072,21 @@ def _menuconfig(stdscr):
10711072

10721073

10731074
def _quit_dialog():
1074-
if not _conf_changed:
1075+
config_exists = os.path.exists(_conf_filename)
1076+
1077+
if not _conf_changed and config_exists:
10751078
return "No changes to save (for '{}')".format(_conf_filename)
10761079

10771080
# Use button dialog with Yes/No/Cancel buttons (matching lxdialog style)
1081+
# Adjust message if .config doesn't exist
1082+
if not config_exists:
1083+
dialog_text = "No configuration file found.\nSave new configuration?"
1084+
else:
1085+
dialog_text = "Save configuration?"
1086+
10781087
result = _button_dialog(
10791088
None, # No title in yesno dialog
1080-
"Save configuration?",
1089+
dialog_text,
10811090
[" Yes ", " No ", " Cancel "],
10821091
default_button=0,
10831092
)
@@ -1094,6 +1103,8 @@ def _quit_dialog():
10941103
return None
10951104

10961105
elif result == 1: # No
1106+
if not config_exists:
1107+
return "Configuration was not saved"
10971108
return "Configuration ({}) was not saved".format(_conf_filename)
10981109

10991110

0 commit comments

Comments
 (0)