77 <v-form v-model =" valid" @submit.prevent =" saveSegmentGroup" >
88 <v-text-field
99 v-model =" fileName"
10- hint =" Filename that will appear in downloads."
10+ hint =" Filename used for downloads."
1111 label =" Filename"
1212 :rules =" [validFileName]"
1313 required
3737</template >
3838
3939<script setup lang="ts">
40- import { onMounted , ref } from ' vue' ;
40+ import { computed , onMounted , ref } from ' vue' ;
4141import { onKeyDown } from ' @vueuse/core' ;
4242import { saveAs } from ' file-saver' ;
4343import { useSegmentGroupStore } from ' @/src/store/segmentGroups' ;
4444import { writeSegmentation } from ' @/src/io/readWriteImage' ;
4545import { useErrorMessage } from ' @/src/composables/useErrorMessage' ;
46+ import { sanitizeSegmentGroupFileStem } from ' @/src/io/state-file/segmentGroupArchivePath' ;
4647
4748const EXTENSIONS = [
4849 ' seg.nrrd' ,
@@ -63,12 +64,18 @@ const props = defineProps<{
6364
6465const emit = defineEmits ([' done' ]);
6566
66- const fileName = ref (' ' );
67+ const fileNameValue = ref (' ' );
6768const valid = ref (true );
6869const saving = ref (false );
6970const fileFormat = ref (EXTENSIONS [0 ]);
7071
7172const segmentGroupStore = useSegmentGroupStore ();
73+ const fileName = computed ({
74+ get : () => fileNameValue .value ,
75+ set : (value : string ) => {
76+ fileNameValue .value = sanitizeSegmentGroupFileStem (value , ' ' );
77+ },
78+ });
7279
7380async function saveSegmentGroup() {
7481 if (fileName .value .trim ().length === 0 ) {
@@ -77,20 +84,24 @@ async function saveSegmentGroup() {
7784
7885 saving .value = true ;
7986 await useErrorMessage (' Failed to save segment group' , async () => {
87+ const sanitizedFileName = sanitizeSegmentGroupFileStem (fileName .value );
88+ fileNameValue .value = sanitizedFileName ;
8089 const serialized = await writeSegmentation (
8190 fileFormat .value ,
8291 segmentGroupStore .dataIndex [props .id ],
8392 segmentGroupStore .metadataByID [props .id ]
8493 );
85- saveAs (new Blob ([serialized ]), ` ${fileName . value }.${fileFormat .value } ` );
94+ saveAs (new Blob ([serialized ]), ` ${sanitizedFileName }.${fileFormat .value } ` );
8695 });
8796 saving .value = false ;
8897 emit (' done' );
8998}
9099
91100onMounted (() => {
92101 // trigger form validation check so can immediately save with default value
93- fileName .value = segmentGroupStore .metadataByID [props .id ].name ;
102+ fileNameValue .value = sanitizeSegmentGroupFileStem (
103+ segmentGroupStore .metadataByID [props .id ].name
104+ );
94105});
95106
96107onKeyDown (' Enter' , () => {
0 commit comments