Documentation
¶
Overview ¶
Package dirsort provides the sort order of the files in each directory, shared by all of the apps (and all of their processes) that show directories: For returns the sort order of a directory, which is the one last Set for it in any app, or else the one that the file manager of the operating system uses for it (the Finder on macOS, from its .DS_Store files, and Dolphin or Nautilus on Linux; see Native), or else Default. The sort orders that are set are saved in a file in DataDir, which is locked for the changes of each process, and read again when another process has changed it.
Index ¶
- Constants
- Variables
- func Set(dir string, s Sort) error
- type Fields
- func (i Fields) Desc() string
- func (i Fields) Int64() int64
- func (i Fields) MarshalText() ([]byte, error)
- func (i *Fields) SetInt64(in int64)
- func (i *Fields) SetString(s string) error
- func (i Fields) String() string
- func (i *Fields) UnmarshalText(text []byte) error
- func (i Fields) Values() []enums.Enum
- type Sort
Constants ¶
const FileName = "dir-sort.json"
FileName is the name of the file of the sort orders in DataDir.
Variables ¶
var DataDir string
DataDir is the directory of the file of the sort orders that are Set, which is shared by all apps: core sets it to the Cogent Core data directory. If it is empty, the sort orders are only kept in memory.
var Default = Sort{}
Default is the sort order of a directory that has none (see For): by name, up.
var MaxDirs = 5000
MaxDirs is the maximum number of directories whose sort orders are saved: those set least recently are dropped beyond it.
var Native = func(dir string) (Sort, bool) { dir = cleanDir(dir) switch runtime.GOOS { case "darwin": return finderSort(dir) case "linux", "freebsd", "openbsd", "netbsd": return linuxSort(dir) } return Sort{}, false }
Native returns the sort order that the file manager of the operating system uses for the given directory, and whether there is one: that of the directory, or else the default of the file manager.
- macOS: the Finder, from the view settings in the .DS_Store file of the directory, or else its standard view settings (see [finderSort]).
- Linux: Dolphin (KDE), from the .directory file of the directory, and Nautilus (GNOME), from the metadata of the directory, or else their defaults (see [linuxSort]).
- Windows: none, as Explorer keeps the views of folders in the registry, in binary records ("shell bags") that are not documented.
It can be set to nil for none, as core does in tests.
Functions ¶
Types ¶
type Fields ¶
type Fields int32 //enums:enum
Fields are the fields of the files in a directory that they can be sorted by, which are named as the fields of fileinfo.FileInfo.
const FieldsN Fields = 4
FieldsN is the highest valid value for type Fields, plus one.
func FieldsValues ¶
func FieldsValues() []Fields
FieldsValues returns all possible values for the type Fields.
func (Fields) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Fields) SetString ¶
SetString sets the Fields value from its string representation, and returns an error if the string is invalid.
func (*Fields) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Sort ¶
type Sort struct {
// By is the field that the files are sorted by.
By Fields
// Down is whether the files are sorted down (descending: Z to A,
// largest or newest first), instead of up (ascending).
Down bool
}
Sort is a sort order of the files in a directory: by the given field, up (ascending: A to Z, smallest or oldest first) or down (descending).
func For ¶
For returns the sort order of the given directory: the one last Set for it, by any app, or else the one of the file manager of the operating system (see Native), or else Default.
func Parse ¶
Parse returns the sort order of the given string, as returned by Sort.String (where :up is the default), and whether it is one.
func Saved ¶
Saved returns the sort order last Set for the given directory, by any app, and whether there is one.
func (Sort) Compare ¶
Compare compares the given files in the sort order, returning -1 if a comes before b, and 1 if after, for slices.SortFunc. Files that are equal in the field of the sort order are in the order of their names (in the direction of the sort order).
func (Sort) SortInfos ¶
SortInfos sorts the given standard file infos in the sort order, as those of a directory listing. Their kinds are those of their names (see fileinfo.FileInfo.MimeFromFilename), without reading the files.