Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
fix: IDE stores empty string on Save
Browse files Browse the repository at this point in the history
  • Loading branch information
shanmukhateja committed Mar 6, 2022
1 parent fdeb77a commit 13eb597
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/comms.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::Path;

use gtk::glib::{self, Receiver, Sender};
use gtk::prelude::{ObjectExt, StatusbarExt, TextViewExt};
use gtk::prelude::{ObjectExt, StatusbarExt};
use gtk::traits::TextViewExt;

use crate::{
action_handler,
Expand Down Expand Up @@ -87,29 +88,27 @@ pub fn handle_comm_event(tx: Sender<CommEvents>, rx: Receiver<CommEvents>) {
});
}
CommEvents::SaveEditorChanges() => {
G_TEXT_VIEW.with(|editor| {
let text_editor = &editor.borrow().clone().unwrap();

let text_buffer = text_editor.buffer().unwrap();
let file_absolute_path = Workspace::get_open_file_path();
match file_absolute_path {
Some(file_abs_path) => {
// Get View widget of open file
let text_editor =
ui::notebook::get_current_page_editor(file_abs_path.clone());
let text_buffer = text_editor.expect("Unable to find editor for open file").buffer().unwrap();

let file_absolute_path = Workspace::get_open_file_path();
match file_absolute_path {
Some(file_abs_path) => {
action_handler::save_file_changes(text_buffer, file_abs_path.clone());
G_STATUS_BAR.with(|status_bar| {
let status_bar_ref = status_bar.borrow();
let status_bar =
status_bar_ref.as_ref().expect("Unable to use status_bar");
action_handler::save_file_changes(text_buffer, file_abs_path.clone());
G_STATUS_BAR.with(|status_bar| {
let status_bar_ref = status_bar.borrow();
let status_bar =
status_bar_ref.as_ref().expect("Unable to use status_bar");

status_bar
.push(0, &format!("Saved changes to '{}'", &file_abs_path));
});
}
None => {
println!("Unable to write Workspace#open_file_path");
}
status_bar.push(0, &format!("Saved changes to '{}'", &file_abs_path));
});
}
});
None => {
println!("Unable to write Workspace#open_file_path");
}
}
}
}
// Don't forget to include this!
Expand Down
27 changes: 27 additions & 0 deletions src/ui/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,30 @@ pub fn create_tab(notebook: Notebook, title: &str, widget: Widget) -> u32 {

index
}

pub fn get_current_page_editor(file_path: String) -> Option<sourceview4::View> {


let position = NOTEBOOK_TABS_CACHE.with(|cache| {
let cache = cache.borrow();
let cache = cache.as_ref().unwrap();

let mut result = -1;
for iter in cache {
if iter.file_path == file_path {
result = iter.position as i32;
break;
}
}

result as u32
});

G_NOTEBOOK.with(|notebook| {
let notebook = notebook.borrow();
let notebook = notebook.as_ref().unwrap();

let page = notebook.nth_page(Some(position));
page.map(|page| page.downcast::<sourceview4::View>().unwrap())
})
}

0 comments on commit 13eb597

Please sign in to comment.