Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
.flatpak-builder
.flatpak-builder
aardvark-app/src/config.rs
Comment thread
jsparber marked this conversation as resolved.
9 changes: 6 additions & 3 deletions aardvark-app/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

use aardvark_doc::service::Service;
use aardvark_doc::{document::DocumentId, service::Service};
use adw::prelude::*;
use adw::subclass::prelude::*;
use gettextrs::gettext;
Expand Down Expand Up @@ -89,11 +89,14 @@ impl AardvarkApplication {
.build()
}

pub fn window_for_document_id(&self, document_id: &str) -> Option<crate::AardvarkWindow> {
pub fn window_for_document_id(
&self,
document_id: &DocumentId,
) -> Option<crate::AardvarkWindow> {
self.windows()
.into_iter()
.filter_map(|window| window.downcast::<super::AardvarkWindow>().ok())
.find(|window| window.document().id() == document_id)
.find(|window| &window.document().id() == document_id)
}

fn setup_gactions(&self) {
Expand Down
4 changes: 2 additions & 2 deletions aardvark-app/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod zoom_level_selector;
mod multiline_entry;
mod zoom_level_selector;

pub use self::zoom_level_selector::ZoomLevelSelector;
pub use self::multiline_entry::MultilineEntry;
pub use self::zoom_level_selector::ZoomLevelSelector;
20 changes: 9 additions & 11 deletions aardvark-app/src/components/multiline_entry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gtk::{glib, subclass::prelude::*, prelude::*, gdk};
use gtk::{gdk, glib, prelude::*, subclass::prelude::*};

mod imp {
use super::*;
Expand All @@ -18,20 +18,18 @@ mod imp {
}

impl ObjectImpl for MultilineEntry {
fn constructed (&self) {
fn constructed(&self) {
let key_events = gtk::EventControllerKey::new();
key_events.connect_key_pressed(|controller, key, _, modifier| {
if modifier.is_empty() && (key == gdk::Key::Return || key == gdk::Key::KP_Enter)
{
if let Some(widget) = controller.widget() {
widget.activate_default();
}
glib::Propagation::Stop
} else {
glib::Propagation::Proceed
if modifier.is_empty() && (key == gdk::Key::Return || key == gdk::Key::KP_Enter) {
if let Some(widget) = controller.widget() {
widget.activate_default();
}
glib::Propagation::Stop
} else {
glib::Propagation::Proceed
}
);
});
self.obj().add_controller(key_events);
}
}
Expand Down
5 changes: 0 additions & 5 deletions aardvark-app/src/config.rs

This file was deleted.

2 changes: 1 addition & 1 deletion aardvark-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use std::path::PathBuf;
use gettextrs::{bind_textdomain_codeset, bindtextdomain, textdomain};
use gtk::prelude::*;
use gtk::{gio, glib};
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
use tracing_subscriber::prelude::*;

use self::application::AardvarkApplication;
use self::config::{GETTEXT_PACKAGE, LOCALEDIR, PKGDATADIR};
Expand Down
42 changes: 28 additions & 14 deletions aardvark-app/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
*/

use std::cell::{Cell, OnceCell, RefCell};
use std::str::FromStr;

use aardvark_doc::{document::Document, service::Service};
use aardvark_doc::{
document::{Document, DocumentId},
service::Service,
};
use adw::prelude::AdwDialogExt;
use adw::subclass::prelude::*;
use gettextrs::gettext;
Expand Down Expand Up @@ -215,15 +219,18 @@ mod imp {
self,
move |_| {
let open_document_buffer = this.open_document_entry.buffer();
let document_id: String = open_document_buffer
.text(
&open_document_buffer.start_iter(),
&open_document_buffer.end_iter(),
false,
)
.chars()
.filter(|c| c.is_digit(16))
.collect();
let document_id = DocumentId::from_str(
&open_document_buffer
.text(
&open_document_buffer.start_iter(),
&open_document_buffer.end_iter(),
false,
)
.chars()
.filter(|c| c.is_digit(16))
.collect::<String>(),
)
.expect("valid document id");

let app = this
.obj()
Expand Down Expand Up @@ -253,15 +260,21 @@ mod imp {
.filter(|c| c.is_digit(16))
.collect();

this.open_document_button.set_sensitive(input.len() == 64);
let document_id = if input.len() == 64 {
DocumentId::from_str(&input).ok()
} else {
None
};
this.open_document_button
.set_sensitive(document_id.is_some());

let existing = if input.len() == 64 {
let existing = if let Some(document_id) = document_id {
let app = this
.obj()
.application()
.and_then(|app| app.downcast::<AardvarkApplication>().ok())
.expect("Application needs to be a AardvarkApplication");
app.window_for_document_id(&input)
app.window_for_document_id(&document_id)
} else {
None
};
Expand Down Expand Up @@ -359,8 +372,9 @@ mod imp {
self.obj().notify("document");
}

fn format_document_id(document_id: &str) -> String {
fn format_document_id(document_id: &DocumentId) -> String {
document_id
.to_string()
.chars()
.enumerate()
.flat_map(|(i, c)| {
Expand Down
Loading