Skip to content

Commit

Permalink
wip: port to sourceview
Browse files Browse the repository at this point in the history
  • Loading branch information
bertob committed Dec 14, 2024
1 parent 99bd85c commit 21c6d5c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aardvark-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gtk = { version = "0.9", package = "gtk4", features = ["gnome_47"] }
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.128"
tokio = { version = "1.42.0", features = ["full"] }
sourceview = { package = "sourceview5", version = "0.9" }

[dependencies.adw]
package = "libadwaita"
Expand Down
6 changes: 4 additions & 2 deletions aardvark-app/src/textbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use adw::subclass::prelude::*;
use glib::subclass::Signal;
use gtk::glib;
use gtk::prelude::*;
use gtk::*;
use std::cell::Cell;
use std::sync::OnceLock;
use sourceview::*;

mod imp {
use super::*;
Expand All @@ -37,7 +39,7 @@ mod imp {
impl ObjectSubclass for AardvarkTextBuffer {
const NAME: &'static str = "AardvarkTextBuffer";
type Type = super::AardvarkTextBuffer;
type ParentType = gtk::TextBuffer;
type ParentType = sourceview::Buffer;
}

impl ObjectImpl for AardvarkTextBuffer {
Expand Down Expand Up @@ -82,7 +84,7 @@ mod imp {

glib::wrapper! {
pub struct AardvarkTextBuffer(ObjectSubclass<imp::AardvarkTextBuffer>)
@extends gtk::TextBuffer;
@extends sourceview::Buffer;
}

impl AardvarkTextBuffer {
Expand Down
5 changes: 3 additions & 2 deletions aardvark-app/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use adw::subclass::prelude::*;
use glib::subclass::Signal;
use gtk::prelude::*;
use gtk::{gio, glib};
use sourceview::*;

use crate::AardvarkTextBuffer;

Expand All @@ -36,7 +37,7 @@ mod imp {
pub struct AardvarkWindow {
// Template widgets
#[template_child]
pub text_view: TemplateChild<gtk::TextView>,
pub text_view: TemplateChild<sourceview::View>,
#[template_child]
pub open_document_button: TemplateChild<gtk::Button>,
#[template_child]
Expand All @@ -63,7 +64,7 @@ mod imp {
self.parent_constructed();

let buffer = AardvarkTextBuffer::new();
self.text_view.set_buffer(Some(&buffer));
self.text_view.clone().upcast::<gtk::TextView>().set_buffer(Some(&buffer));

let obj = self.obj().clone();
buffer.connect_changed(move |buffer| {
Expand Down
3 changes: 2 additions & 1 deletion aardvark-app/src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@
<property name="height-request">180</property>
<property name="width-request">300</property>
<child>
<object class="GtkTextView" id="text_view">
<object class="GtkSourceView" id="text_view">
<property name="top-margin">6</property>
<property name="bottom-margin">12</property>
<property name="left-margin">12</property>
<property name="wrap-mode">GTK_WRAP_WORD_CHAR</property>
<style>
<class name="inline"/>
<class name="editor"/>
Expand Down

0 comments on commit 21c6d5c

Please sign in to comment.