Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
World
Design Tooling
App Icon Preview
Commits
a3d3c9c6
Unverified
Commit
a3d3c9c6
authored
May 28, 2020
by
Bilal Elmoussaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
export: use a native file chooser
fixes
#60
parent
c0bff8d9
Pipeline
#183098
passed with stage
in 41 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
16 deletions
+11
-16
src/common.rs
src/common.rs
+3
-7
src/project.rs
src/project.rs
+8
-9
No files found.
src/common.rs
View file @
a3d3c9c6
...
...
@@ -114,7 +114,7 @@ pub fn is_valid_app_id(app_id: &str) -> bool {
app_id
.contains
(
'.'
)
&&
!
app_id
.ends_with
(
'.'
)
&&
!
app_id
.starts_with
(
'.'
)
}
pub
fn
clean_svg
(
file
:
PathBuf
)
->
anyhow
::
Result
<
()
>
{
pub
fn
clean_svg
(
svg
:
&
str
)
->
anyhow
::
Result
<
Vec
<
u8
>
>
{
let
options
=
svgcleaner
::
CleaningOptions
{
remove_unused_defs
:
true
,
convert_shapes
:
false
,
...
...
@@ -155,14 +155,10 @@ pub fn clean_svg(file: PathBuf) -> anyhow::Result<()> {
paths_coordinates_precision
:
8
,
transforms_precision
:
8
,
};
let
data
=
svgcleaner
::
cleaner
::
load_file
(
file
.to_str
()
.unwrap
())
?
;
let
mut
document
=
svgcleaner
::
cleaner
::
parse_data
(
&
data
,
&
svgcleaner
::
ParseOptions
::
default
())
.unwrap
();
let
mut
document
=
svgcleaner
::
cleaner
::
parse_data
(
svg
,
&
svgcleaner
::
ParseOptions
::
default
())
.unwrap
();
let
_
=
svgcleaner
::
cleaner
::
clean_doc
(
&
mut
document
,
&
options
,
&
svgcleaner
::
WriteOptions
::
default
());
let
mut
buf
=
vec!
[];
svgcleaner
::
cleaner
::
write_buffer
(
&
document
,
&
svgcleaner
::
WriteOptions
::
default
(),
&
mut
buf
);
svgcleaner
::
cleaner
::
save_file
(
&
buf
,
file
.to_str
()
.unwrap
())
?
;
Ok
(())
Ok
(
buf
)
}
src/project.rs
View file @
a3d3c9c6
...
...
@@ -93,12 +93,7 @@ impl Project {
_
=>
(),
};
let
dialog
=
gtk
::
FileChooserDialog
::
with_buttons
(
Some
(
&
gettext
(
"Export"
)),
Some
(
parent
),
gtk
::
FileChooserAction
::
Save
,
&
[(
&
gettext
(
"_Save"
),
gtk
::
ResponseType
::
Accept
),
(
&
gettext
(
"_Cancel"
),
gtk
::
ResponseType
::
Cancel
)],
);
let
dialog
=
gtk
::
FileChooserNative
::
new
(
Some
(
&
gettext
(
"Export"
)),
Some
(
parent
),
gtk
::
FileChooserAction
::
Save
,
Some
(
&
gettext
(
"_Save"
)),
Some
(
&
gettext
(
"_Cancel"
)));
dialog
.set_modal
(
true
);
dialog
.set_current_name
(
&
icon_name
);
...
...
@@ -108,13 +103,17 @@ impl Project {
svg_filter
.add_mime_type
(
"image/svg+xml"
);
dialog
.add_filter
(
&
svg_filter
);
dialog
.connect_response
(
clone!
(
@
strong
gicon
=>
move
|
dialog
,
response
|
{
dialog
.connect_response
(
clone!
(
@
strong
gicon
,
@
strong
dialog
=>
move
|
_
,
response
|
{
if
response
==
gtk
::
ResponseType
::
Accept
{
let
dest
=
dialog
.get_file
()
.unwrap
();
if
let
Some
(
source
)
=
&
gicon
{
let
save
=
move
||
->
anyhow
::
Result
<
()
>
{
source
.copy
(
&
dest
,
gio
::
FileCopyFlags
::
OVERWRITE
,
gio
::
NONE_CANCELLABLE
,
None
)
?
;
common
::
clean_svg
(
dest
.get_path
()
.unwrap
())
?
;
let
(
svg
,
_
)
=
source
.load_contents
(
gio
::
NONE_CANCELLABLE
)
?
;
let
cleaned_svg
=
common
::
clean_svg
(
std
::
str
::
from_utf8
(
&
svg
)
?
)
?
;
dest
.replace_contents
(
&
cleaned_svg
,
None
,
false
,
gio
::
FileCreateFlags
::
REPLACE_DESTINATION
,
gio
::
NONE_CANCELLABLE
)
?
;
Ok
(())
};
if
save
()
.is_err
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment