Skip to content

Commit a45dabe

Browse files
rjackeyrjackey
authored andcommitted
Add "put" option to FileSelector from legacy widgets #34
1 parent 0973fec commit a45dabe

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

widgets/+wt/+enum/FileFolderState.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
enumeration
1010
file
1111
folder
12+
putfile
1213
end %enumeration
1314

1415

widgets/+wt/FileSelector.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
% File or folder selection control with browse button
88

9-
% Copyright 2020-2022 The MathWorks Inc.
9+
% Copyright 2020-2023 The MathWorks Inc.
1010

1111

1212
%% Public properties
@@ -36,7 +36,7 @@
3636

3737
properties (AbortSet)
3838

39-
% Selection type: file or folder
39+
% Selection type: (get)file, folder, putfile
4040
SelectionType (1,1) wt.enum.FileFolderState = wt.enum.FileFolderState.file
4141

4242
% Optional root directory. If unspecified, Value uses an absolute
@@ -75,8 +75,7 @@
7575

7676

7777
%% Internal Properties
78-
properties ( Transient, NonCopyable, ...
79-
Access = {?matlab.uitest.TestCase, ?matlab.ui.componentcontainer.ComponentContainer} )
78+
properties (Transient, NonCopyable, Hidden, SetAccess = protected)
8079

8180
% Button
8281
ButtonControl (1,1) matlab.ui.control.Button
@@ -197,6 +196,8 @@ function updateButtonIcon(obj)
197196
% Update the button icon
198197
if obj.SelectionType == "file"
199198
obj.ButtonControl.Icon = "folder_file_24.png";
199+
elseif obj.SelectionType == "putfile"
200+
obj.ButtonControl.Icon = "folder_file_24.png";
200201
else
201202
obj.ButtonControl.Icon = "folder_24.png";
202203
end
@@ -260,6 +261,8 @@ function onButtonPushed(obj,~)
260261
% Prompt user for the path
261262
if obj.SelectionType == "file"
262263
[fileName,pathName] = uigetfile(filter,"Select a file",initialPath);
264+
elseif obj.SelectionType == "putfile"
265+
[fileName,pathName] = uiputfile(filter,"Specify an output file",initialPath);
263266
else
264267
pathName = uigetdir(initialPath, "Select a folder");
265268
fileName = "";
@@ -307,6 +310,8 @@ function addToHistory(obj,value)
307310
% Filter to valid paths
308311
if obj.SelectionType == "file"
309312
fcn = @(x)gt(exist(fullfile(obj.RootDirectory, x),"file"), 0);
313+
elseif obj.SelectionType == "putfile"
314+
fcn = @(x)gt(exist(fullfile(obj.RootDirectory, x),"file"), 0);
310315
else
311316
fcn = @(x)eq(exist(fullfile(obj.RootDirectory, x),"dir"), 7);
312317
end
@@ -427,6 +432,7 @@ function setValueFromFullPath(obj,fullPath)
427432
function value = get.ValueIsValidPath(obj)
428433
filePath = fullfile(obj.RootDirectory, obj.Value);
429434
value = ( obj.SelectionType == "file" && isfile(filePath) ) || ...
435+
( obj.SelectionType == "putfile" && isfolder(fileparts(filePath)) ) || ...
430436
( obj.SelectionType == "folder" && isfolder(filePath) );
431437
end
432438

0 commit comments

Comments
 (0)