From 47298c60cca54382b5065e5cb118d25c1399cb46 Mon Sep 17 00:00:00 2001 From: Ashley Trowell Date: Fri, 27 Aug 2021 14:11:09 -0500 Subject: [PATCH] Added default scheme path to uigetfile dialog, with safe fallback. Provided a function getSchemeDialogPathSafely() and use it to set the default folder for the uigetfile dialog box. The function finds thisFilePath (the containing folder of schemer_import.m) and then returns thisFilePath/schemes/, or if that folder doesn't exists, then it returns thisFilePath. --- schemer_import.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/schemer_import.m b/schemer_import.m index 9749ee6..83264e2 100644 --- a/schemer_import.m +++ b/schemer_import.m @@ -155,7 +155,7 @@ else % Dialog asking for input filename % Need to make this dialogue include .txt by default, at least - [filename, pathname] = uigetfile(filefilt); + [filename, pathname] = uigetfile(filefilt,[],getSchemeDialogPathSafely()); % End if user cancels if isequal(filename, 0); if nargout>0; varargout{1} = 0; end; @@ -710,3 +710,17 @@ end end + +function defaultSchemePath = getSchemeDialogPathSafely() +% getSchemeDialogPathSafely() - Get the scheme path for the uigetfile. +% If the folder doesn't exist in the expected relative path, +% this will return the path to the folder containing the current mfile +% to prevent a warning. +expectedRelativePath = '/schemes/'; +[thisFilePath, ~, ~] = fileparts(mfilename('fullpath')); +defaultSchemePath= fullfile(thisFilePath,expectedRelativePath); +% Safe fallback if schemes folder isn't in expected relative path. +if not( exist(defaultSchemePath,'dir') ) + defaultSchemePath = thisFilePath; +end +end