Skip to content

Commit

Permalink
Merge branch 'develop' into release/v2.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jun 3, 2022
2 parents 55c7f02 + 3c1f987 commit c433ae1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
17 changes: 4 additions & 13 deletions dialog/fileitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ func (i *fileDialogItem) CreateRenderer() fyne.WidgetRenderer {
}
}

func fileName(path fyne.URI) (name string) {
pathstr := path.String()[len(path.Scheme())+3:]
name = filepath.Base(pathstr)
ext := filepath.Ext(name[1:])
name = name[:len(name)-len(ext)]

return
}

func (i *fileDialogItem) isDirectory() bool {
return i.dir
}
Expand All @@ -80,13 +71,13 @@ func (f *fileDialog) newFileItem(location fyne.URI, dir bool) *fileDialogItem {
item := &fileDialogItem{
picker: f,
location: location,
name: location.Name(),
dir: dir,
}

if dir {
item.name = location.Name()
} else {
item.name = fileName(location)
if f.view == gridView {
ext := filepath.Ext(item.name[1:])
item.name = item.name[:len(item.name)-len(ext)]
}

item.ExtendBaseWidget(item)
Expand Down
25 changes: 24 additions & 1 deletion dialog/fileitem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ func TestFileItem_Name(t *testing.T) {

item = f.newFileItem(storage.NewFileURI("/path/to/.maybeHidden.txt"), false)
assert.Equal(t, ".maybeHidden", item.name)

item = f.newFileItem(storage.NewFileURI("/path/to/noext"), false)
assert.Equal(t, "noext", item.name)

// Test that the extension remains for the list view.
f.view = listView

item = f.newFileItem(storage.NewFileURI("/path/to/filename.txt"), false)
assert.Equal(t, "filename.txt", item.name)

item = f.newFileItem(storage.NewFileURI("/path/to/MyFile.jpeg"), false)
assert.Equal(t, "MyFile.jpeg", item.name)

item = f.newFileItem(storage.NewFileURI("/path/to/.maybeHidden.txt"), false)
assert.Equal(t, ".maybeHidden.txt", item.name)

item = f.newFileItem(storage.NewFileURI("/path/to/noext"), false)
assert.Equal(t, "noext", item.name)
}

func TestFileItem_FolderName(t *testing.T) {
Expand All @@ -32,10 +50,15 @@ func TestFileItem_FolderName(t *testing.T) {
assert.Equal(t, "foldername", item.name)

item = f.newFileItem(storage.NewFileURI("/path/to/myapp.app/"), true)
assert.Equal(t, "myapp.app", item.name)
assert.Equal(t, "myapp", item.name)

item = f.newFileItem(storage.NewFileURI("/path/to/.maybeHidden/"), true)
assert.Equal(t, ".maybeHidden", item.name)

// Test that the extension remains for the list view.
f.view = listView
item = f.newFileItem(storage.NewFileURI("/path/to/myapp.app/"), true)
assert.Equal(t, "myapp.app", item.name)
}

func TestNewFileItem(t *testing.T) {
Expand Down

0 comments on commit c433ae1

Please sign in to comment.