Skip to content

Commit

Permalink
GUI: Add option to show/hide hidden files in file selector
Browse files Browse the repository at this point in the history
  • Loading branch information
rcassani committed Sep 16, 2024
1 parent f29aa1b commit cf0baec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions toolbox/core/bst_get.m
Original file line number Diff line number Diff line change
Expand Up @@ -3061,6 +3061,13 @@
else
argout1 = [.33 .0042 .33 .88 .93];
end

case 'ShowHiddenFiles'
if isfield(GlobalData, 'Preferences') && isfield(GlobalData.Preferences, 'ShowHiddenFiles')
argout1 = GlobalData.Preferences.ShowHiddenFiles;
else
argout1 = 0;
end

case 'LastUsedDirs'
defPref = struct(...
Expand Down
2 changes: 1 addition & 1 deletion toolbox/core/bst_set.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function bst_set( varargin )
'MagneticExtrapOptions', 'MriOptions', 'ConnectGraphOptions', 'NodelistOptions', 'IgnoreMemoryWarnings', 'SystemCopy', ...
'TimefreqOptions_morlet', 'TimefreqOptions_hilbert', 'TimefreqOptions_fft', 'TimefreqOptions_psd', 'TimefreqOptions_stft', 'TimefreqOptions_plv', ...
'OpenMEEGOptions', 'DuneuroOptions', 'DigitizeOptions', 'PcaOptions', 'CustomColormaps', 'PluginCustomPath', 'BrainSuiteDir', 'PythonExe', ...
'GridOptions_headmodel', 'GridOptions_dipfit', 'LastPsdDisplayFunction', 'KlustersExecutable', 'ExportBidsOptions'}
'GridOptions_headmodel', 'GridOptions_dipfit', 'LastPsdDisplayFunction', 'KlustersExecutable', 'ExportBidsOptions', 'ShowHiddenFiles'}
GlobalData.Preferences.(contextName) = contextValue;

case 'ReadOnly'
Expand Down
22 changes: 22 additions & 0 deletions toolbox/gui/java_getfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@
% Set dialog callback
java_setcb(jFileChooser, 'ActionPerformedCallback', @FileSelectorAction, ...
'PropertyChangeCallback', @FileSelectorPropertyChanged);
% Add option for show/hide hidden files (starting wiht '.') in jFileChooser popmenu
compList = jFileChooser.getComponents();
for i = 1:length(compList)
if strcmpi(class(compList(i)), 'sun.swing.FilePane') % This class extends JPanel
jFilePane = jFileChooser.getComponent(i-1);
end
end
jPopup = jFilePane.getComponentPopupMenu;
jFont = jPopup.getFont;
showHiddenFiles = bst_get('ShowHiddenFiles');
jCheckHidden = gui_component('CheckBoxMenuItem', jPopup, [], 'Show hidden files', [], [], @(h,ev)ToogleHiddenFiles(), jFont);
jCheckHidden.setSelected(showHiddenFiles);
jFileChooser.setFileHidingEnabled(~showHiddenFiles);

drawnow;
% Display file selector
java_call(jBstSelector, 'showSameThread');
Expand Down Expand Up @@ -269,6 +283,14 @@ function FileSelectorPropertyChanged(h, ev)
end
end
end

function ToogleHiddenFiles()
showHiddenFiles = bst_get('ShowHiddenFiles');
showHiddenFiles = ~showHiddenFiles;
bst_set('ShowHiddenFiles', showHiddenFiles);
jFileChooser.setFileHidingEnabled(~showHiddenFiles);
jCheckHidden.setSelected(showHiddenFiles);
end
end


Expand Down

1 comment on commit cf0baec

@rcassani
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.