-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
75149cd
commit 0b183c2
Showing
6 changed files
with
393 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import | ||
"UILib/Context", | ||
"UILib/Command", | ||
"UILib/Pane", | ||
"UILib/Set", | ||
"UILib/Named" | ||
end; | ||
"UILib/Context", | ||
"UILib/Command", | ||
"UILib/Pane", | ||
"UILib/Set", | ||
"UILib/Named"; |
183 changes: 87 additions & 96 deletions
183
Pinafore/pinafore-lib-script/data/UILib/Command.pinafore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,96 @@ | ||
import "gnome" in | ||
with GTK. in | ||
namespace UILib of | ||
import "gnome" | ||
with GTK. | ||
namespace UILib { | ||
docsec "Commands" { | ||
datatype Command -context { | ||
Mk { | ||
name: Text; | ||
defaultKeyBinding: Maybe Text = Nothing; | ||
action: context -> Action Unit; | ||
}; | ||
}; | ||
|
||
docsec "Commands" of | ||
namespace Command { | ||
toMenuEntry: context -> Command context -> MenuEntry = | ||
fn ctxt, Mk => action.MenuEntry ap{(name, defaultKeyBinding)} ap{action ctxt}; | ||
|
||
datatype Command -context of | ||
Mk of | ||
name: Text; | ||
defaultKeyBinding: Maybe Text = Nothing; | ||
action: context -> Action Unit; | ||
end; | ||
end; | ||
datatype Context { | ||
Mk { | ||
gtk: Context.GTK.; | ||
undoHandler: UndoHandler; | ||
window: Window; | ||
getTextSelection: Action (WholeModel Text); | ||
}; | ||
}; | ||
|
||
namespace Command of | ||
copy: Command Context = | ||
Mk.Command { | ||
name = "Copy"; | ||
defaultKeyBinding = Just "Ctrl+C"; | ||
action = | ||
fn Mk.Context => do { | ||
tmodel <- getTextSelection; | ||
text <- get.WholeModel tmodel; | ||
clipboard ?gtk :=.WholeModel text; | ||
}; | ||
}; | ||
|
||
toMenuEntry: context -> Command context -> MenuEntry = | ||
fn ctxt, Mk => action.MenuEntry {(name, defaultKeyBinding)} {action ctxt}; | ||
cut: Command Context = | ||
Mk.Command { | ||
name = "Cut"; | ||
defaultKeyBinding = Just "Ctrl+X"; | ||
action = | ||
fn Mk.Context => do { | ||
tmodel <- getTextSelection; | ||
text <- get.WholeModel tmodel; | ||
clipboard ?gtk :=.WholeModel text; | ||
tmodel :=.WholeModel ""; | ||
}; | ||
}; | ||
|
||
datatype Context of | ||
Mk of | ||
gtk: Context.GTK.; | ||
undoHandler: UndoHandler; | ||
window: Window; | ||
getTextSelection: Action (WholeModel Text); | ||
end; | ||
end; | ||
paste: Command Context = | ||
Mk.Command { | ||
name = "Paste"; | ||
defaultKeyBinding = Just "Ctrl+V"; | ||
action = | ||
fn Mk.Context => do { | ||
tmodel <- getTextSelection; | ||
clip <- get.WholeModel $ clipboard ?gtk; | ||
clip >- | ||
fn { | ||
text:? Text => tmodel :=.WholeModel text; | ||
_ => pure (); | ||
}; | ||
}; | ||
}; | ||
|
||
copy: Command Context = | ||
Mk.Command of | ||
name = "Copy"; | ||
defaultKeyBinding = Just "Ctrl+C"; | ||
action = | ||
fn Mk.Context => | ||
do | ||
tmodel <- getTextSelection; | ||
text <- get.WholeModel tmodel; | ||
clipboard ?gtk :=.WholeModel text; | ||
end; | ||
end; | ||
undo: Command Context = | ||
Mk.Command { | ||
name = "Undo"; | ||
defaultKeyBinding = Just "Ctrl+Z"; | ||
action = fn Mk.Context => queueUndo undoHandler >> pure (); | ||
}; | ||
|
||
cut: Command Context = | ||
Mk.Command of | ||
name = "Cut"; | ||
defaultKeyBinding = Just "Ctrl+X"; | ||
action = | ||
fn Mk.Context => | ||
do | ||
tmodel <- getTextSelection; | ||
text <- get.WholeModel tmodel; | ||
clipboard ?gtk :=.WholeModel text; | ||
tmodel :=.WholeModel ""; | ||
end; | ||
end; | ||
redo: Command Context = | ||
Mk.Command { | ||
name = "Redo"; | ||
defaultKeyBinding = Just "Ctrl+Y"; | ||
action = fn Mk.Context => queueRedo undoHandler >> pure (); | ||
}; | ||
|
||
paste: Command Context = | ||
Mk.Command of | ||
name = "Paste"; | ||
defaultKeyBinding = Just "Ctrl+V"; | ||
action = | ||
fn Mk.Context => | ||
do | ||
tmodel <- getTextSelection; | ||
clip <- get.WholeModel $ clipboard ?gtk; | ||
clip >- | ||
match | ||
text:? Text => tmodel :=.WholeModel text; | ||
_ => pure (); | ||
end; | ||
end; | ||
end; | ||
close: Command Context = | ||
Mk.Command { | ||
name = "Close"; | ||
defaultKeyBinding = Just "Ctrl+W"; | ||
action = fn Mk.Context => close.Window window; | ||
}; | ||
|
||
undo: Command Context = | ||
Mk.Command of | ||
name = "Undo"; | ||
defaultKeyBinding = Just "Ctrl+Z"; | ||
action = fn Mk.Context => queueUndo undoHandler >> pure (); | ||
end; | ||
|
||
redo: Command Context = | ||
Mk.Command of | ||
name = "Redo"; | ||
defaultKeyBinding = Just "Ctrl+Y"; | ||
action = fn Mk.Context => queueRedo undoHandler >> pure (); | ||
end; | ||
|
||
close: Command Context = | ||
Mk.Command of | ||
name = "Close"; | ||
defaultKeyBinding = Just "Ctrl+W"; | ||
action = fn Mk.Context => close.Window window; | ||
end; | ||
|
||
exit: Command Context = | ||
Mk.Command of | ||
name = "Exit"; | ||
defaultKeyBinding = Just "Ctrl+Q"; | ||
action = fn Mk.Context => exit.GTK gtk; | ||
end; | ||
|
||
end; | ||
|
||
end; | ||
|
||
end; | ||
exit: Command Context = | ||
Mk.Command { | ||
name = "Exit"; | ||
defaultKeyBinding = Just "Ctrl+Q"; | ||
action = fn Mk.Context => exit.GTK gtk; | ||
}; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
import "gnome" in | ||
namespace UILib of | ||
import "gnome" | ||
namespace UILib { | ||
docsec "Running" { | ||
#| Context type for using GTK, storage, and undo together. | ||
datatype Context { | ||
Mk { | ||
gtk: Context.GTK; | ||
undoHandler: UndoHandler; | ||
store: Store; | ||
}; | ||
}; | ||
|
||
docsec "Running" of | ||
|
||
#| Context type for using GTK, storage, and undo together. | ||
datatype Context of | ||
Mk of | ||
gtk: Context.GTK; | ||
undoHandler: UndoHandler; | ||
store: Store; | ||
end; | ||
end; | ||
|
||
namespace Context of | ||
|
||
#| Run an action, giving a `Context`. | ||
run: (Context -> Action a) -> Action a = | ||
fn call => | ||
do | ||
dstore <- openLocal.Store of end; | ||
undoHandler <- new.UndoHandler; | ||
store <- handleStore.UndoHandler undoHandler dstore; | ||
run.GTK $ fn gtk => call Mk.Context; | ||
end; | ||
|
||
end; | ||
|
||
end; | ||
|
||
end; | ||
namespace Context { | ||
#| Run an action, giving a `Context`. | ||
run: (Context -> Action a) -> Action a = | ||
fn call => do { | ||
dstore <- openLocal.Store {}; | ||
undoHandler <- new.UndoHandler; | ||
store <- handleStore.UndoHandler undoHandler dstore; | ||
run.GTK $ fn gtk => call Mk.Context; | ||
}; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.