Added gspell

pull/9/head
diamondburned 2020-08-30 21:47:58 -07:00
parent b48526aed3
commit 8838b8e0d8
7 changed files with 54 additions and 40 deletions

15
PLAN.md
View File

@ -1,21 +1,8 @@
## Sidebar refactoring
Maybe put services separately in the left sidebar like so:
![](https://miro.medium.com/max/1600/1*DSH66RN5DA5UQdZ2xE2I-g.png)
## Behavioral changes
Top-level server loads can probably lazy-load, but independent servers can
probably be all loaded at once. This might not be a good idea for guild folders.
cchat-gtk should also store what's expanded into a config. This is pretty
cchat-gtk should store what's expanded into a config. This is pretty
trivial to do.
## Spellcheck
Write a Golang gspell binding and use that.
## Frame limiter
Limit to 25fps if background using glib.TimeoutAdd.

1
go.mod
View File

@ -10,6 +10,7 @@ require (
github.com/diamondburned/cchat v0.0.49
github.com/diamondburned/cchat-discord v0.0.0-20200821041521-647c854d7b5e
github.com/diamondburned/cchat-mock v0.0.0-20200709231652-ad222ce5a74b
github.com/diamondburned/gspell v0.0.0-20200830182722-77e5d27d6894
github.com/diamondburned/handy v0.0.0-20200829011954-4667e7a918f4
github.com/diamondburned/imgutil v0.0.0-20200710174014-8a3be144a972
github.com/disintegration/imaging v1.6.2

11
go.sum
View File

@ -40,6 +40,7 @@ github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3E
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
github.com/dave/jennifer v1.4.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg=
github.com/dave/jennifer v1.4.1/go.mod h1:7jEdnm+qBcxl8PC0zyp7vxcpSRnzXSt9r39tpTVGlwA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -89,6 +90,16 @@ github.com/diamondburned/gotk3 v0.0.0-20200630065217-97aeb06d705d h1:Ha/I6PMKi+B
github.com/diamondburned/gotk3 v0.0.0-20200630065217-97aeb06d705d/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/diamondburned/gotk3 v0.0.0-20200816224505-3cd69b83a48a h1:wEldljb421/Jp84RNb0zBfqmiWt/TTQzUE6R1ap6UuQ=
github.com/diamondburned/gotk3 v0.0.0-20200816224505-3cd69b83a48a/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/diamondburned/gspell v0.0.0-20200829065821-c501924bc87c h1:H1eixeq/t1gjKCozGXT36uiDWA0X8Xis4E44WpS+AO4=
github.com/diamondburned/gspell v0.0.0-20200829065821-c501924bc87c/go.mod h1:IoyMxPKSJOMoP0BiBuFwf2RDMeA4Uqx0HPKN5BzqTtA=
github.com/diamondburned/gspell v0.0.0-20200829070727-5b147f3f7bfb h1:xzmSVFakYqZ8gtJ/iGtancrNHY49t9woKnM/WRP6JcY=
github.com/diamondburned/gspell v0.0.0-20200829070727-5b147f3f7bfb/go.mod h1:IoyMxPKSJOMoP0BiBuFwf2RDMeA4Uqx0HPKN5BzqTtA=
github.com/diamondburned/gspell v0.0.0-20200829071312-d910720ee38b h1:zOfRizc1RdR6m2nmB3l+XjX48N4XLgIlQ/D6ZBJMmFc=
github.com/diamondburned/gspell v0.0.0-20200829071312-d910720ee38b/go.mod h1:IoyMxPKSJOMoP0BiBuFwf2RDMeA4Uqx0HPKN5BzqTtA=
github.com/diamondburned/gspell v0.0.0-20200829071551-d44933c5efb8 h1:Pv/C48jFIlC4jEsTLJijys+kyUT+4NKEtx0WjOMCcaw=
github.com/diamondburned/gspell v0.0.0-20200829071551-d44933c5efb8/go.mod h1:IoyMxPKSJOMoP0BiBuFwf2RDMeA4Uqx0HPKN5BzqTtA=
github.com/diamondburned/gspell v0.0.0-20200830182722-77e5d27d6894 h1:QgI21deaQbCUMnxKkQQUXzQolnAe1dMIXAWwqAyOp2g=
github.com/diamondburned/gspell v0.0.0-20200830182722-77e5d27d6894/go.mod h1:IoyMxPKSJOMoP0BiBuFwf2RDMeA4Uqx0HPKN5BzqTtA=
github.com/diamondburned/handy v0.0.0-20200827040421-5b4a15843526 h1:GnTwaD+RKiCJiJ9yhcUb6M5o4VwFExTqmcl8Dg+EVdw=
github.com/diamondburned/handy v0.0.0-20200827040421-5b4a15843526/go.mod h1:V0qyhW4v6KPFwtDpXdBm5aWH7zWEyrzZpcB6MPnKArQ=
github.com/diamondburned/handy v0.0.0-20200829011954-4667e7a918f4 h1:qF5VHC35+GyCjUmKz+1O94xpFc0JQd4Ui3h+I955pJw=

View File

@ -11,6 +11,7 @@ import (
"github.com/diamondburned/cchat-gtk/internal/ui/messages/input/username"
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
"github.com/diamondburned/cchat-gtk/internal/ui/primitives/scrollinput"
"github.com/diamondburned/gspell"
"github.com/gotk3/gotk3/gtk"
"github.com/pkg/errors"
)
@ -96,8 +97,9 @@ type Field struct {
Username *username.Container
TextScroll *gtk.ScrolledWindow
text *gtk.TextView // const
buffer *gtk.TextBuffer // const
text *gtk.TextView // const
speller *gspell.TextView // const
buffer *gtk.TextBuffer // const
send *gtk.Button
attach *gtk.Button
@ -140,6 +142,8 @@ var scrolledInputCSS = primitives.PrepareClassCSS("scrolled-input", `
func NewField(text *gtk.TextView, ctrl Controller) *Field {
field := &Field{text: text, ctrl: ctrl}
field.buffer, _ = text.GetBuffer()
field.speller = gspell.GetFromGtkTextView(text)
field.speller.BasicSetup()
field.Username = username.NewContainer()
field.Username.Show()

View File

@ -20,7 +20,7 @@ import (
var globalID uint64
// generateNonce creates a nonce that should prevent collision. This function
// will always return a 24-byte long string.
// will always return a 16-byte long string.
func (f *Field) generateNonce() string {
raw := fmt.Sprintf(
"cchat-gtk/%s/%X/%X",
@ -75,18 +75,23 @@ func (f *Field) sendInput() {
// Clear the input field after sending.
f.clearText()
// Refocus the textbox.
f.text.GrabFocus()
}
func (f *Field) SendMessage(data PresendMessage) {
// presend message into the container through the controller
var onErr = f.ctrl.AddPresendMessage(data)
go func(sender cchat.ServerMessageSender) {
// Copy the sender to prevent race conditions.
var sender = f.Sender
gts.Async(func() (func(), error) {
if err := sender.SendMessage(data); err != nil {
gts.ExecAsync(func() { onErr(err) })
log.Error(errors.Wrap(err, "Failed to send message"))
return func() { onErr(err) }, errors.Wrap(err, "Failed to send message")
}
}(f.Sender)
return nil, nil
})
}
type SendMessageData struct {

View File

@ -37,11 +37,7 @@ func init() {
}
// constraints for the left panel
const (
leftMinWidth = 200
leftCurrentWidth = 275
leftMaxWidth = 400
)
const leftCurrentWidth = 300
func clamp(n, min, max int) int {
switch {

View File

@ -1,26 +1,36 @@
{ pkgs ? import <nixpkgs> {} }:
let libhandy = pkgs.libhandy.overrideAttrs(old: {
name = "libhandy-0.90.0";
src = builtins.fetchGit {
url = "https://gitlab.gnome.org/GNOME/libhandy.git";
rev = "c7aaf6f4f50b64ee55fcfee84000e9525fc5f93a";
};
patches = [];
# let hunspell = pkgs.hunspellWithDicts(with pkgs.hunspellDicts; [
# en-us
# en-us-large
# ]);
buildInputs = old.buildInputs ++ (with pkgs; [
gnome3.librsvg
gdk-pixbuf
let hunspellWrapper = pkgs.hunspellWithDicts(with pkgs.hunspellDicts; [
en-us
en-us-large
]);
});
libhandy = pkgs.libhandy.overrideAttrs(old: {
name = "libhandy-0.90.0";
src = builtins.fetchGit {
url = "https://gitlab.gnome.org/GNOME/libhandy.git";
rev = "c7aaf6f4f50b64ee55fcfee84000e9525fc5f93a";
};
patches = [];
buildInputs = old.buildInputs ++ (with pkgs; [
gnome3.librsvg
gdk-pixbuf
]);
});
in pkgs.stdenv.mkDerivation rec {
name = "cchat-gtk";
version = "0.0.2";
buildInputs = [ libhandy ] ++ (with pkgs; [
gnome3.glib gnome3.gtk # libhandy
]);
buildInputs =
[ libhandy hunspellWrapper ]
++ (with pkgs; [ enchant2 gnome3.gspell gnome3.glib gnome3.gtk ]);
nativeBuildInputs = with pkgs; [
pkgconfig go