Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
orbutils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nick Thomas
orbutils
Commits
626e3410
Commit
626e3410
authored
7 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Catch errors in file manager when loading icons
Make file manager look nicer when scrolling
parent
0bc80635
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/file_manager/main.rs
+54
-28
54 additions, 28 deletions
src/file_manager/main.rs
with
54 additions
and
28 deletions
src/file_manager/main.rs
+
54
−
28
View file @
626e3410
...
...
@@ -85,31 +85,44 @@ struct FileType {
}
impl
FileType
{
fn
new
(
desc
:
String
,
icon
:
&
'static
str
)
->
FileType
{
fn
new
(
desc
:
String
,
icon
:
&
'static
str
)
->
Option
<
Self
>
{
for
folder
in
[
"mimetypes"
,
"places"
]
.iter
()
{
let
mut
path
=
fs
::
canonicalize
(
UI_PATH
)
.unwrap
();
path
.push
(
folder
);
path
.push
(
format!
(
"{}.png"
,
icon
));
if
path
.is_file
()
{
return
FileType
{
description
:
desc
,
icon
:
path
,
};
}
else
{
println!
(
"{} not found in {}"
,
icon
,
folder
);
match
fs
::
canonicalize
(
UI_PATH
)
{
Ok
(
mut
path
)
=>
{
path
.push
(
folder
);
path
.push
(
format!
(
"{}.png"
,
icon
));
if
path
.is_file
()
{
return
Some
(
Self
{
description
:
desc
,
icon
:
path
,
});
}
else
{
println!
(
"{} not found in {}"
,
icon
,
folder
);
}
},
Err
(
err
)
=>
{
println!
(
"failed to canonicalize {}: {}"
,
UI_PATH
,
err
);
}
}
}
println!
(
"{} not found"
,
icon
);
let
mut
path
=
fs
::
canonicalize
(
UI_PATH
)
.unwrap
();
path
.push
(
"mimetypes/unknown.png"
);
FileType
{
description
:
desc
,
icon
:
path
,
match
fs
::
canonicalize
(
UI_PATH
)
{
Ok
(
mut
path
)
=>
{
path
.push
(
"mimetypes/unknown.png"
);
Some
(
Self
{
description
:
desc
,
icon
:
path
,
})
},
Err
(
err
)
=>
{
println!
(
"failed to canonicalize {}: {}"
,
UI_PATH
,
err
);
None
}
}
}
fn
from_filename
(
file_name
:
&
str
)
->
Self
{
fn
from_filename
(
file_name
:
&
str
)
->
Option
<
Self
>
{
if
file_name
.ends_with
(
'/'
)
{
Self
::
new
(
"folder"
.to_owned
(),
"inode-directory"
)
}
else
{
...
...
@@ -134,25 +147,38 @@ impl FileType {
}
struct
FileTypesInfo
{
empty_image
:
Image
,
images
:
BTreeMap
<
PathBuf
,
Image
>
,
}
impl
FileTypesInfo
{
pub
fn
new
()
->
FileTypesInfo
{
FileTypesInfo
{
images
:
BTreeMap
::
new
()
}
pub
fn
new
()
->
Self
{
Self
{
empty_image
:
Image
::
new
(
0
,
0
),
images
:
BTreeMap
::
new
()
}
}
pub
fn
description_for
(
&
self
,
file_name
:
&
str
)
->
String
{
FileType
::
from_filename
(
file_name
)
.description
match
FileType
::
from_filename
(
file_name
)
{
Some
(
file_type
)
=>
file_type
.description
,
None
=>
String
::
new
()
}
}
pub
fn
icon_for
(
&
mut
self
,
file_name
:
&
str
)
->
&
Image
{
let
icon
=
FileType
::
from_filename
(
file_name
)
.icon
;
if
!
self
.images
.contains_key
(
&
icon
)
{
self
.images
.insert
(
icon
.clone
(),
load_icon
(
&
icon
));
match
FileType
::
from_filename
(
file_name
)
{
Some
(
file_type
)
=>
{
let
icon
=
file_type
.icon
;
if
!
self
.images
.contains_key
(
&
icon
)
{
self
.images
.insert
(
icon
.clone
(),
load_icon
(
&
icon
));
}
&
self
.images
[
&
icon
]
},
None
=>
{
&
self
.empty_image
}
}
&
self
.images
[
&
icon
]
}
}
...
...
@@ -248,7 +274,7 @@ impl FileManager {
column_labels
:
Vec
::
new
(),
sort_predicate
:
SortPredicate
::
Name
,
sort_direction
:
SortDirection
::
Asc
,
window
:
Window
::
new
(
Rect
::
new
(
-
1
,
-
1
,
0
,
0
),
""
),
window
:
Window
::
new
(
Rect
::
new
(
-
1
,
-
1
,
32
0
,
24
0
),
"
File Manager
"
),
list_widget_index
:
None
,
tx
:
tx
,
rx
:
rx
,
...
...
@@ -345,7 +371,7 @@ impl FileManager {
let
h
=
if
self
.files
.len
()
<
8
{
(
count
*
ICON_SIZE
as
usize
)
as
u32
+
32
// +32 for the header row
}
else
{
(
7
*
ICON_SIZE
as
usize
)
as
u32
+
32
-
16
// +32 for the header row
, -16 to indicate scrolling
(
7
*
ICON_SIZE
as
usize
)
as
u32
+
32
// +32 for the header row
};
let
list
=
List
::
new
();
...
...
@@ -464,7 +490,7 @@ impl FileManager {
let
h
=
if
self
.files
.len
()
<
8
{
(
count
*
ICON_SIZE
as
usize
)
as
u32
+
32
// +32 for the header row
}
else
{
(
7
*
ICON_SIZE
as
usize
)
as
u32
+
32
-
16
// +32 for the header row
, -16 to indicate scrolling
(
7
*
ICON_SIZE
as
usize
)
as
u32
+
32
// +32 for the header row
};
self
.window
.set_size
(
w
,
h
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment