Skip to content

Commit

Permalink
fixed recent file list not being saved on macOS, dont save loglevel a…
Browse files Browse the repository at this point in the history
…s array; removed extra call to write_recentfiles in menu clear
  • Loading branch information
danomatika committed Jul 20, 2017
1 parent 7e1552a commit 1903049
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
48 changes: 26 additions & 22 deletions tcl/pd_guiprefs.tcl
Expand Up @@ -19,6 +19,7 @@ set ::recentfiles_key ""
set ::loglevel_key "loglevel"
set ::pd_guiprefs::domain ""
set ::pd_guiprefs::configdir ""
set ::recentfiles_is_array false

#################################################################
# perferences storage locations
Expand Down Expand Up @@ -55,15 +56,13 @@ set ::pd_guiprefs::configdir ""
#
#################################################################


#################################################################
# global procedures
#################################################################
# ------------------------------------------------------------------------------
# init preferences
#
proc ::pd_guiprefs::init {} {
set arr 0
set ::pd_guiprefs::domain org.puredata.pd.pd-gui

switch -- $::platform {
Expand All @@ -88,7 +87,7 @@ proc ::pd_guiprefs::init {} {
set ::recentfiles_key "NSRecentDocuments"
set ::total_recentfiles 10
# osx special case for arrays
set arr 1
set ::recentfiles_is_array true

# ------------------------------------------------------------------------------
# osx: read a plist file
Expand All @@ -99,9 +98,16 @@ proc ::pd_guiprefs::init {} {
set conf [plist_array_to_tcl_list $conf]
}
} else {
# initialize NSRecentDocuments with an empty array
exec defaults write $adomain $akey -array
set conf {}
# value not found, so set empty value
if {$arr} {
# initialize w/ empty array for NSRecentDocuments, etc
exec defaults write $adomain $akey -array
set conf {}
} else {
# not an array
exec defaults write $adomain $akey ""
set ""
}
}
return $conf
}
Expand All @@ -120,21 +126,21 @@ proc ::pd_guiprefs::init {} {
if {$arr} {
foreach filepath $data {
set escaped [escape_for_plist $filepath]
exec /bin/sh -c "defaults write $adomain $akey $escaped"
exec /bin/sh -c "defaults write $adomain $akey -array-add $escaped"
}
} else {
set escaped [escape_for_plist $data]
exec /bin/sh -c "defaults write $adomain $akey $escaped"
}

# Disable window state saving by default for 10.7+ as there is a chance
# pd will hang on start due to conflicting patch resources until the state
# is purged. State saving will still work, it just has to be explicitly
# asked for by holding the Option/Alt button when quitting via the File
# menu or with the Cmd+Q key binding.
exec defaults write $adomain NSQuitAlwaysKeepsWindows -bool false
return
}

# Disable window state saving by default for 10.7+ as there is a chance
# pd will hang on start due to conflicting patch resources until the state
# is purged. State saving will still work, it just has to be explicitly
# asked for by holding the Option/Alt button when quitting via the File
# menu or with the Cmd+Q key binding.
exec defaults write $::pd_guiprefs::domain NSQuitAlwaysKeepsWindows -bool false
}
"registry" {
# windows uses registry
Expand Down Expand Up @@ -196,11 +202,10 @@ proc ::pd_guiprefs::init {} {

}
# assign gui preferences
set ::recentfiles_list ""
set ::recentfiles_list {}
catch {set ::recentfiles_list [get_config $::pd_guiprefs::domain \
$::recentfiles_key $arr]}
catch {set ::loglevel [get_config $::pd_guiprefs::domain \
$::loglevel_key $arr]}
$::recentfiles_key $::recentfiles_is_array]}
catch {set ::loglevel [get_config $::pd_guiprefs::domain $::loglevel_key]}
# reset default if value was not found
if {$::loglevel == ""} {set ::loglevel 2}
}
Expand Down Expand Up @@ -344,17 +349,16 @@ proc ::pd_guiprefs::escape_for_plist {str} {
return '[regsub -all -- {'} $str {\\'}]'
}


#################################################################
# recent files
#################################################################


# ------------------------------------------------------------------------------
# write recent files
#
proc ::pd_guiprefs::write_recentfiles {} {
write_config $::recentfiles_list $::pd_guiprefs::domain $::recentfiles_key true
write_config $::recentfiles_list $::pd_guiprefs::domain $::recentfiles_key \
$::recentfiles_is_array
}

# ------------------------------------------------------------------------------
Expand All @@ -378,5 +382,5 @@ proc ::pd_guiprefs::update_recentfiles {afile} {
# write log level
#
proc ::pd_guiprefs::write_loglevel {} {
write_config $::loglevel $::pd_guiprefs::domain $::loglevel_key true
write_config $::loglevel $::pd_guiprefs::domain $::loglevel_key
}
3 changes: 1 addition & 2 deletions tcl/pd_menus.tcl
Expand Up @@ -370,10 +370,9 @@ proc ::pd_menus::update_recentfiles_menu {{write true}} {
}

proc ::pd_menus::clear_recentfiles_menu {} {
# empty recentfiles in preferences (write empty array)
set ::recentfiles_list {}
::pd_menus::update_recentfiles_menu
# empty recentfiles in preferences (write empty array)
::pd_guiprefs::write_recentfiles
}

proc ::pd_menus::update_openrecent_menu_aqua {mymenu {write}} {
Expand Down

0 comments on commit 1903049

Please sign in to comment.