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
redox-os
orbutils
Commits
40bfb3f1
Commit
40bfb3f1
authored
7 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Allow enter in path dialog
parent
5bc1421d
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/editor/main.rs
+45
-24
45 additions, 24 deletions
src/editor/main.rs
with
45 additions
and
24 deletions
src/editor/main.rs
+
45
−
24
View file @
40bfb3f1
...
@@ -5,13 +5,14 @@ extern crate orbtk;
...
@@ -5,13 +5,14 @@ extern crate orbtk;
use
orbclient
::
WindowFlag
;
use
orbclient
::
WindowFlag
;
use
orbtk
::{
Action
,
Button
,
Menu
,
Point
,
Rect
,
Separator
,
TextBox
,
Window
};
use
orbtk
::{
Action
,
Button
,
Menu
,
Point
,
Rect
,
Separator
,
TextBox
,
Window
};
use
orbtk
::
traits
::{
Click
,
Place
,
Resize
,
Text
};
use
orbtk
::
traits
::{
Click
,
Enter
,
Place
,
Resize
,
Text
};
use
std
::{
cmp
,
env
};
use
std
::{
cmp
,
env
};
use
std
::
cell
::
RefCell
;
use
std
::
cell
::
RefCell
;
use
std
::
fs
::
File
;
use
std
::
fs
::
File
;
use
std
::
io
::{
Read
,
Write
};
use
std
::
io
::{
Read
,
Write
};
use
std
::
ops
::
DerefMut
;
use
std
::
ops
::
DerefMut
;
use
std
::
rc
::
Rc
;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
pub
struct
Editor
{
pub
struct
Editor
{
...
@@ -56,7 +57,7 @@ impl Editor {
...
@@ -56,7 +57,7 @@ impl Editor {
// } DESIGN
// } DESIGN
// CODE {
// CODE {
let
editor_cell
=
Ar
c
::
new
(
RefCell
::
new
(
Editor
{
let
editor_cell
=
R
c
::
new
(
RefCell
::
new
(
Editor
{
path_option
:
path_option
,
path_option
:
path_option
,
text_box
:
text_box
.clone
(),
text_box
:
text_box
.clone
(),
window
:
window
.deref_mut
()
as
*
mut
Window
,
window
:
window
.deref_mut
()
as
*
mut
Window
,
...
@@ -139,6 +140,9 @@ impl Editor {
...
@@ -139,6 +140,9 @@ impl Editor {
}
}
fn
path_dialog
<
F
:
Fn
(
&
str
)
+
'static
>
(
&
mut
self
,
title
:
&
str
,
func
:
F
)
->
Box
<
Window
>
{
fn
path_dialog
<
F
:
Fn
(
&
str
)
+
'static
>
(
&
mut
self
,
title
:
&
str
,
func
:
F
)
->
Box
<
Window
>
{
let
func_rc
=
Rc
::
new
(
func
);
// DESIGN {
let
(
p_x
,
p_y
,
p_w
,
p_h
)
=
{
let
(
p_x
,
p_y
,
p_w
,
p_h
)
=
{
let
window
=
unsafe
{
&
mut
*
self
.window
};
let
window
=
unsafe
{
&
mut
*
self
.window
};
(
window
.x
(),
window
.y
(),
window
.width
(),
window
.height
())
(
window
.x
(),
window
.y
(),
window
.width
(),
window
.height
())
...
@@ -148,6 +152,7 @@ impl Editor {
...
@@ -148,6 +152,7 @@ impl Editor {
let
h
=
8
+
28
+
8
+
28
+
8
;
let
h
=
8
+
28
+
8
+
28
+
8
;
let
x
=
p_x
+
(
p_w
as
i32
-
w
as
i32
)
/
2
;
let
x
=
p_x
+
(
p_w
as
i32
-
w
as
i32
)
/
2
;
let
y
=
p_y
+
(
p_h
as
i32
-
h
as
i32
)
/
2
;
let
y
=
p_y
+
(
p_h
as
i32
-
h
as
i32
)
/
2
;
let
mut
window
=
Box
::
new
(
Window
::
new
(
Rect
::
new
(
x
,
y
,
w
,
h
),
title
));
let
mut
window
=
Box
::
new
(
Window
::
new
(
Rect
::
new
(
x
,
y
,
w
,
h
),
title
));
let
text_box
=
TextBox
::
new
();
let
text_box
=
TextBox
::
new
();
...
@@ -157,37 +162,53 @@ impl Editor {
...
@@ -157,37 +162,53 @@ impl Editor {
.grab_focus
(
true
);
.grab_focus
(
true
);
window
.add
(
&
text_box
);
window
.add
(
&
text_box
);
let
cancel_button
=
Button
::
new
();
cancel_button
.position
(
8
,
8
+
28
+
8
)
.size
((
w
-
16
)
/
2
-
4
,
28
)
.text_offset
(
6
,
6
)
.text
(
"Cancel"
);
window
.add
(
&
cancel_button
);
let
confirm_button
=
Button
::
new
();
confirm_button
.position
((
w
as
i32
)
/
2
+
4
,
8
+
28
+
8
)
.size
((
w
-
16
)
/
2
-
4
,
28
)
.text_offset
(
6
,
6
)
.text
(
title
);
window
.add
(
&
confirm_button
);
// } DESIGN
// CODE {
if
let
Some
(
ref
path
)
=
self
.path_option
{
if
let
Some
(
ref
path
)
=
self
.path_option
{
text_box
.text
.set
(
path
.clone
());
text_box
.text
.set
(
path
.clone
());
}
}
{
{
let
window_cancel
=
window
.deref_mut
()
as
*
mut
Window
;
let
func_rc
=
func_rc
.clone
();
let
button
=
Button
::
new
();
let
window_ptr
=
window
.deref_mut
()
as
*
mut
Window
;
button
.position
(
8
,
8
+
28
+
8
)
text_box
.on_enter
(
move
|
text_box
:
&
TextBox
|
{
.size
((
w
-
16
)
/
2
-
4
,
28
)
let
path
=
text_box
.text
.get
();
.text_offset
(
6
,
6
)
func_rc
(
&
path
);
.text
(
"Cancel"
)
unsafe
{
(
&
mut
*
window_ptr
)
.close
();
}
.on_click
(
move
|
_button
:
&
Button
,
_point
:
Point
|
{
});
unsafe
{
(
&
mut
*
window_cancel
)
.close
();
}
}
});
window
.add
(
&
button
);
{
let
window_ptr
=
window
.deref_mut
()
as
*
mut
Window
;
cancel_button
.on_click
(
move
|
_button
:
&
Button
,
_point
:
Point
|
{
unsafe
{
(
&
mut
*
window_ptr
)
.close
();
}
});
}
}
{
{
let
window_save_as
=
window
.deref_mut
()
as
*
mut
Window
;
let
func_rc
=
func_rc
.clone
();
let
button
=
Button
::
new
();
let
window_ptr
=
window
.deref_mut
()
as
*
mut
Window
;
button
.position
((
w
as
i32
)
/
2
+
4
,
8
+
28
+
8
)
confirm_button
.on_click
(
move
|
_button
:
&
Button
,
_point
:
Point
|
{
.size
((
w
-
16
)
/
2
-
4
,
28
)
let
path
=
text_box
.text
.get
();
.text_offset
(
6
,
6
)
func_rc
(
&
path
);
.text
(
title
)
unsafe
{
(
&
mut
*
window_ptr
)
.close
();
}
.on_click
(
move
|
_button
:
&
Button
,
_point
:
Point
|
{
});
let
path
=
text_box
.text
.get
();
func
(
&
path
);
unsafe
{
(
&
mut
*
window_save_as
)
.close
();
}
});
window
.add
(
&
button
);
}
}
// } CODE
window
window
}
}
...
...
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