Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Icon Library
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
World
Design Tooling
Icon Library
Commits
105844d3
Commit
105844d3
authored
Jul 23, 2019
by
Bilal Elmoussaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use hashmap collections for data structure.
parent
e4bc262a
Pipeline
#98171
passed with stages
in 9 minutes and 36 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
35 deletions
+15
-35
src/widgets/icons.rs
src/widgets/icons.rs
+15
-35
No files found.
src/widgets/icons.rs
View file @
105844d3
...
...
@@ -7,7 +7,7 @@ use gtk;
use
gtk
::
prelude
::{
BoxExt
,
ContainerExt
,
FlowBoxExt
,
GtkWindowExt
,
IconThemeExt
,
ImageExt
,
StackExt
,
StyleContextExt
,
WidgetExt
};
use
libhandy
::{
Column
,
ColumnExt
};
use
std
::
cell
::
RefCell
;
use
std
::
collections
::
HashMap
;
use
std
::
fs
::
File
;
use
std
::
io
::
BufReader
;
use
std
::
path
::
PathBuf
;
...
...
@@ -150,7 +150,7 @@ struct IconsViewContext {
pub
widget
:
gtk
::
Box
,
pub
context
:
String
,
icons_container
:
gtk
::
FlowBox
,
icons_views
:
Vec
<
RefCell
<
IconView
>
>
,
icons_views
:
HashMap
<
gtk
::
FlowBoxChild
,
Icon
>
,
n_last_search_results
:
u32
,
}
...
...
@@ -158,7 +158,7 @@ impl IconsViewContext {
pub
fn
new
(
context
:
String
,
icons
:
Vec
<
Icon
>
,
parent
:
&
gtk
::
ApplicationWindow
)
->
IconsViewContext
{
let
widget
=
gtk
::
Box
::
new
(
gtk
::
Orientation
::
Vertical
,
6
);
let
icons_container
=
gtk
::
FlowBox
::
new
();
let
icons_views
:
Vec
<
RefCell
<
IconView
>>
=
Vec
::
new
();
let
icons_views
:
HashMap
<
gtk
::
FlowBoxChild
,
Icon
>
=
HashMap
::
new
();
let
n_last_search_results
:
u32
=
0
;
let
mut
icons_view_context
=
IconsViewContext
{
widget
,
...
...
@@ -195,54 +195,34 @@ impl IconsViewContext {
for
icon
in
icons
{
let
icon_view
=
IconView
::
new
(
icon
.clone
());
self
.icons_container
.add
(
&
icon_view
.widget
);
self
.icons_views
.
push
(
RefCell
::
new
(
icon_view
)
);
self
.icons_views
.
insert
(
icon_view
.widget
,
icon
);
}
self
.widget
.add
(
&
self
.icons_container
);
}
fn
connect_signals
(
&
self
,
parent
:
&
gtk
::
ApplicationWindow
)
{
let
parent_window
=
parent
.clone
();
let
icons_views
=
self
.icons_views
.to_vec
()
.into_iter
();
self
.icons_container
.connect_child_activated
(
move
|
_
,
child
|
{
let
icons_views
=
icons_views
.clone
();
let
views
:
Vec
<
RefCell
<
IconView
>>
=
icons_views
.filter
(|
icon_view
|
{
let
flowbox
=
&
icon_view
.borrow_mut
()
.widget
;
flowbox
.get_name
()
.unwrap
()
.as_str
()
==
child
.get_name
()
.unwrap
()
.as_str
()
})
.collect
();
match
views
.get
(
0
)
{
Some
(
icon_view
)
=>
{
let
export_dialog
=
ExportDialog
::
new
(
icon_view
.borrow_mut
()
.icon
.clone
());
export_dialog
.widget
.set_transient_for
(
Some
(
&
parent_window
));
export_dialog
.widget
.show_all
();
}
None
=>
println!
(
"Couldn't find the IconView"
),
};
let
icons_views
=
self
.icons_views
.clone
();
self
.icons_container
.connect_child_activated
(
move
|
_
,
child
|
match
icons_views
.get
(
child
)
{
Some
(
icon
)
=>
{
let
export_dialog
=
ExportDialog
::
new
(
icon
.clone
());
export_dialog
.widget
.set_transient_for
(
Some
(
&
parent_window
));
export_dialog
.widget
.show_all
();
}
None
=>
println!
(
"Couldn't find the icon"
),
});
}
pub
fn
filter
(
&
mut
self
,
search_str
:
String
)
{
self
.n_last_search_results
=
0
;
let
icons_views
=
self
.icons_views
.
to_vec
()
.into_iter
();
let
icons_views
=
self
.icons_views
.
clone
();
let
filter_closure
=
move
|
child
:
&
gtk
::
FlowBoxChild
|
->
bool
{
let
icons_views
=
icons_views
.clone
();
let
views
:
Vec
<
RefCell
<
IconView
>>
=
icons_views
.filter
(|
icon_view
|
{
let
flowbox
=
&
icon_view
.borrow_mut
()
.widget
;
flowbox
.get_name
()
.unwrap
()
.as_str
()
==
child
.get_name
()
.unwrap
()
.as_str
()
})
.collect
();
match
views
.get
(
0
)
{
Some
(
icon_view
)
=>
{
let
icon
:
&
Icon
=
&
icon_view
.borrow_mut
()
.icon
;
icon
.should_display
(
&
search_str
)
}
match
icons_views
.get
(
child
)
{
Some
(
icon
)
=>
icon
.should_display
(
&
search_str
),
None
=>
false
,
}
};
self
.icons_container
.set_filter_func
(
Some
(
Box
::
new
(
filter_closure
)));
for
child
in
self
.icons_container
.get_children
()
{
if
child
.get_child_visible
()
{
self
.n_last_search_results
+=
1
;
...
...
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