Skip to content

Commit

Permalink
Merge branch 'main' of github.com:PerfectlyInternal/rnote into eraser…
Browse files Browse the repository at this point in the history
…-speed
  • Loading branch information
PerfectlyInternal committed Oct 7, 2024
2 parents c81783b + 7aa66ba commit e79e673
Show file tree
Hide file tree
Showing 17 changed files with 521 additions and 388 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Seio Inoue
Moritz Mechelk
PhilProg
Silvan Schmidt
Doublonmousse
Doublonmousse
RayJW
9 changes: 5 additions & 4 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ Install all needed dependencies and build tools, e.g. for Fedora:

```bash
sudo dnf install gcc gcc-c++ clang clang-devel python3 make cmake meson git appstream gettext desktop-file-utils \
shared-mime-info kernel-devel gtk4-devel libadwaita-devel poppler-glib-devel poppler-data alsa-lib-devel
shared-mime-info kernel-devel gtk4-devel libadwaita-devel poppler-glib-devel poppler-data alsa-lib-devel \
appstream-devel
```

For debian based distros:
For Debian based distros:

```bash
sudo apt install build-essential clang libclang-dev python3 make cmake meson git appstream gettext \
desktop-file-utils shared-mime-info libgtk-4-dev libadwaita-1-dev libpoppler-glib-dev libasound2-dev
sudo apt install build-essential clang libclang-dev python3 make cmake meson git appstream gettext desktop-file-utils \
shared-mime-info libgtk-4-dev libadwaita-1-dev libpoppler-glib-dev libasound2-dev libappstream-dev
```

Also make sure `rustc` and `cargo` are installed ( see [https://www.rust-lang.org/](https://www.rust-lang.org/) ).
Expand Down
11 changes: 11 additions & 0 deletions crates/rnote-ui/data/ui/dialogs/dialogs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,15 @@ Changes which are not saved will be permanently lost.</property>
<object class="RnIconPicker" id="edit_selected_workspace_icon_picker"></object>
</child>
</object>

<object class="AdwAlertDialog" id="dialog_trash_file">
<property name="heading" translatable="yes">Trash File</property>
<property name="body" translatable="yes">Are you sure you want to move this file to the trash?</property>
<property name="default-response">cancel</property>
<property name="close-response">cancel</property>
<responses>
<response id="cancel" translatable="yes">Cancel</response>
<response id="trash" appearance="destructive" translatable="yes">Trash</response>
</responses>
</object>
</interface>
235 changes: 145 additions & 90 deletions crates/rnote-ui/src/appwindow/actions.rs

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions crates/rnote-ui/src/appwindow/appsettings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ impl RnAppWindow {

{
// Save engine config of the current active tab
self.active_tab_wrapper()
.canvas()
.save_engine_config(&app_settings)?;
if let Some(canvas) = self.active_tab_canvas() {
canvas.save_engine_config(&app_settings)?;
}
}

{
Expand Down Expand Up @@ -490,11 +490,10 @@ impl RnAppWindow {
#[upgrade_or]
glib::ControlFlow::Break,
move || {
if let Err(e) = appwindow
.active_tab_wrapper()
.canvas()
.save_engine_config(&app_settings)
{
let Some(canvas) = appwindow.active_tab_canvas() else {
return glib::ControlFlow::Continue;
};
if let Err(e) = canvas.save_engine_config(&app_settings) {
error!(
"Saving engine config in periodic save task failed , Err: {e:?}"
);
Expand Down
81 changes: 43 additions & 38 deletions crates/rnote-ui/src/appwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ impl RnAppWindow {
.penpicker()
.redo_button()
.set_sensitive(false);
self.refresh_ui_from_engine(&self.active_tab_wrapper());
if let Some(wrapper) = self.active_tab_wrapper() {
self.refresh_ui_from_engine(&wrapper);
}
}

fn setup_icon_theme(&self) {
Expand Down Expand Up @@ -210,7 +212,9 @@ impl RnAppWindow {
canvas.queue_resize();
}
if widget_flags.refresh_ui {
self.refresh_ui_from_engine(&self.active_tab_wrapper());
if let Some(wrapper) = self.active_tab_wrapper() {
self.refresh_ui_from_engine(&wrapper);
}
}
if widget_flags.store_modified {
canvas.set_unsaved_changes(true);
Expand Down Expand Up @@ -263,15 +267,8 @@ impl RnAppWindow {
}

/// Get the active (selected) tab page.
///
/// Panics if there is none, but this should never be the case,
/// since a first one is added initially and the UI hides closing the last tab.
pub(crate) fn active_tab_page(&self) -> adw::TabPage {
self.imp()
.overlays
.tabview()
.selected_page()
.expect("there must always be one active tab")
pub(crate) fn active_tab_page(&self) -> Option<adw::TabPage> {
self.imp().overlays.tabview().selected_page()
}

pub(crate) fn n_tabs_open(&self) -> usize {
Expand Down Expand Up @@ -302,11 +299,14 @@ impl RnAppWindow {
}

/// Get the active (selected) tab page child.
pub(crate) fn active_tab_wrapper(&self) -> RnCanvasWrapper {
pub(crate) fn active_tab_wrapper(&self) -> Option<RnCanvasWrapper> {
self.active_tab_page()
.child()
.downcast::<RnCanvasWrapper>()
.unwrap()
.map(|c| c.child().downcast::<RnCanvasWrapper>().unwrap())
}

/// Get the active (selected) tab page canvas.
pub(crate) fn active_tab_canvas(&self) -> Option<RnCanvas> {
self.active_tab_wrapper().map(|w| w.canvas())
}

/// adds the initial tab to the tabview
Expand All @@ -329,9 +329,8 @@ impl RnAppWindow {
pub(crate) fn new_canvas_wrapper(&self) -> RnCanvasWrapper {
let engine_config = self
.active_tab_wrapper()
.canvas()
.engine_ref()
.extract_engine_config();
.map(|w| w.canvas().engine_ref().extract_engine_config())
.unwrap_or_default();
let wrapper = RnCanvasWrapper::new();
let widget_flags = wrapper
.canvas()
Expand Down Expand Up @@ -465,9 +464,7 @@ impl RnAppWindow {
.close_page_finish(tab_page, confirm);
}

pub(crate) fn refresh_titles(&self, active_tab: &RnCanvasWrapper) {
let canvas = active_tab.canvas();

pub(crate) fn refresh_titles(&self, canvas: &RnCanvas) {
// Titles
let title = canvas.doc_title_display();
let subtitle = canvas.doc_folderpath_display();
Expand Down Expand Up @@ -531,7 +528,7 @@ impl RnAppWindow {
&self,
input_file: gio::File,
target_pos: Option<na::Vector2<f64>>,
rnote_file_new_tab: bool,
mut rnote_file_new_tab: bool,
) -> anyhow::Result<bool> {
let file_imported = match FileType::lookup_file_type(&input_file) {
FileType::RnoteFile => {
Expand All @@ -544,20 +541,16 @@ impl RnAppWindow {
self.overlays().tabview().set_selected_page(&page);
false
} else {
let rnote_file_new_tab = if self.active_tab_wrapper().canvas().empty()
&& self.active_tab_wrapper().canvas().output_file().is_none()
{
false
let wrapper = if let Some(wrapper) = self.active_tab_wrapper() {
wrapper
} else {
rnote_file_new_tab
};

let wrapper = if rnote_file_new_tab {
// a new tab for rnote files
rnote_file_new_tab = true;
self.new_canvas_wrapper()
} else {
self.active_tab_wrapper()
};
if !wrapper.canvas().empty() || wrapper.canvas().output_file().is_some() {
rnote_file_new_tab = true;
}

let (bytes, _) = input_file.load_bytes_future().await?;
let widget_flags = wrapper
.canvas()
Expand All @@ -571,15 +564,21 @@ impl RnAppWindow {
}
}
FileType::VectorImageFile => {
let canvas = self.active_tab_wrapper().canvas();
let canvas = self
.active_tab_wrapper()
.ok_or_else(|| anyhow::anyhow!("No active tab to import into"))?
.canvas();
let (bytes, _) = input_file.load_bytes_future().await?;
canvas
.load_in_vectorimage_bytes(bytes.to_vec(), target_pos, self.respect_borders())
.await?;
true
}
FileType::BitmapImageFile => {
let canvas = self.active_tab_wrapper().canvas();
let canvas = self
.active_tab_wrapper()
.ok_or_else(|| anyhow::anyhow!("No active tab to import into"))?
.canvas();
let (bytes, _) = input_file.load_bytes_future().await?;
canvas
.load_in_bitmapimage_bytes(bytes.to_vec(), target_pos, self.respect_borders())
Expand All @@ -598,12 +597,18 @@ impl RnAppWindow {
file_imported
}
FileType::PdfFile => {
let canvas = self.active_tab_wrapper().canvas();
let canvas = self
.active_tab_wrapper()
.ok_or_else(|| anyhow::anyhow!("No active tab to import into"))?
.canvas();
dialogs::import::dialog_import_pdf_w_prefs(self, &canvas, input_file, target_pos)
.await?
}
FileType::PlaintextFile => {
let canvas = self.active_tab_wrapper().canvas();
let canvas = self
.active_tab_wrapper()
.ok_or_else(|| anyhow::anyhow!("No active tab to import into"))?
.canvas();
let (bytes, _) = input_file.load_bytes_future().await?;
canvas.load_in_text(String::from_utf8(bytes.to_vec())?, target_pos)?;
true
Expand Down Expand Up @@ -873,7 +878,7 @@ impl RnAppWindow {
.tools_page()
.refresh_ui(active_tab);
self.sidebar().settings_panel().refresh_ui(active_tab);
self.refresh_titles(active_tab);
self.refresh_titles(&canvas);
}

/// Sync the state from the previous active tab and the current one. Used when the selected tab changes.
Expand Down
7 changes: 3 additions & 4 deletions crates/rnote-ui/src/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,7 @@ impl RnCanvas {
canvas.clear_output_file_watcher();
canvas.dismiss_output_file_modified_toast();
}

appwindow.refresh_titles(&appwindow.active_tab_wrapper());
appwindow.refresh_titles(canvas);
}
),
);
Expand Down Expand Up @@ -1181,8 +1180,8 @@ impl RnCanvas {
clone!(
#[weak]
appwindow,
move |_, _| {
appwindow.refresh_titles(&appwindow.active_tab_wrapper());
move |canvas, _| {
appwindow.refresh_titles(canvas);
}
),
);
Expand Down
44 changes: 44 additions & 0 deletions crates/rnote-ui/src/dialogs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,50 @@ pub(crate) async fn dialog_edit_selected_workspace(appwindow: &RnAppWindow) {
dialog.present(appwindow.root().as_ref());
}

pub(crate) async fn dialog_trash_file(appwindow: &RnAppWindow, current_file: &gio::File) {
let builder = Builder::from_resource(
(String::from(config::APP_IDPATH) + "ui/dialogs/dialogs.ui").as_str(),
);
let dialog: adw::AlertDialog = builder.object("dialog_trash_file").unwrap();

match dialog.choose_future(appwindow).await.as_str() {
"trash" => {
glib::spawn_future_local(clone!(
#[weak]
appwindow,
#[strong]
current_file,
async move {
current_file.trash_async(
glib::source::Priority::DEFAULT,
None::<&gio::Cancellable>,
clone!(
#[weak]
appwindow,
#[strong]
current_file,
move |res| {
if let Err(e) = res {
appwindow
.overlays()
.dispatch_toast_error(&gettext("Trashing file failed"));
error!(
"Trash filerow file `{current_file:?}` failed , Err: {e:?}"
);
return;
}
}
),
);
}
));
}
_ => {
// Cancel
}
}
}

const WORKSPACELISTENTRY_ICONS_LIST: &[&str] = &[
"workspacelistentryicon-bandaid-symbolic",
"workspacelistentryicon-bank-symbolic",
Expand Down
12 changes: 9 additions & 3 deletions crates/rnote-ui/src/overlays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ impl RnOverlays {
#[weak]
appwindow,
move |colorpicker, _paramspec| {
let Some(canvas) = appwindow.active_tab_canvas() else {
return;
};
let stroke_color = colorpicker.stroke_color().into_compose_color();
let canvas = appwindow.active_tab_wrapper().canvas();
let current_pen_style =
canvas.engine_ref().penholder.current_pen_style_w_override();

Expand Down Expand Up @@ -196,8 +198,10 @@ impl RnOverlays {
#[weak]
appwindow,
move |colorpicker, _paramspec| {
let Some(canvas) = appwindow.active_tab_canvas() else {
return;
};
let fill_color = colorpicker.fill_color().into_compose_color();
let canvas = appwindow.active_tab_wrapper().canvas();
let stroke_style = canvas.engine_ref().penholder.current_pen_style_w_override();

match stroke_style {
Expand Down Expand Up @@ -232,7 +236,9 @@ impl RnOverlays {
#[weak]
appwindow,
move |_| {
let active_tab_page = appwindow.active_tab_page();
let Some(active_tab_page) = appwindow.active_tab_page() else {
return;
};
let active_canvaswrapper = active_tab_page
.child()
.downcast::<RnCanvasWrapper>()
Expand Down
Loading

0 comments on commit e79e673

Please sign in to comment.