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
6 changes: 5 additions & 1 deletion src/application/handler/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use crate::errors::*;

pub fn to_normal_mode(app: &mut Application) -> Result<()> {
if let ModeData::Workspace(ref mode) = app.mode {
app.workspace.select_buffer(mode.prev_buffer_id);
if let Some(buffer_id) = mode.prev_buffer_id {
app.workspace.select_buffer(buffer_id);
} else {
return Ok(());
}
}
app.switch_mode(ModeKey::Normal);
Ok(())
Expand Down
54 changes: 7 additions & 47 deletions src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use state::ApplicationStateData;
use std::{cell::RefCell, collections::HashMap, mem, rc::Rc, sync::Arc};

use crate::{
config::appconfig::AppSetting,
modules::perferences::{Perferences, PerferencesManager},
utils::{file::FileManager, ui::uicore::Ui},
view::monitor::Monitor,
workspace::Workspace,
};
Expand All @@ -28,9 +26,6 @@ pub mod plugin_interafce;
pub mod state;

pub struct Application {
file_manager: FileManager,
bak: bool,
ui: Arc<Ui>,
pub workspace: Workspace,
pub monitor: Monitor,
pub perferences: Rc<RefCell<dyn Perferences>>,
Expand All @@ -50,19 +45,7 @@ pub struct Application {
}

impl Application {
pub fn new(file_path: Option<String>, setting: AppSetting, args: &[String]) -> Result<Self> {
let bak;
let mut file = if file_path.is_some() {
bak = true;
FileManager::new(file_path.unwrap())?
} else {
bak = false;
FileManager::new("held.tmp".to_string())?
};

// 将文件数据读入buf
let buf = file.init(bak)?;

pub fn new(args: &[String]) -> Result<Self> {
let perferences = PerferencesManager::load()?;

let plugin_system = Rc::new(RefCell::new(PluginSystem::init_system(
Expand All @@ -72,10 +55,8 @@ impl Application {
let input_map = InputLoader::load(perferences.borrow().input_config_path()?)?;
let mut monitor = Monitor::new(perferences.clone(), plugin_system.clone())?;
let workspace = Workspace::create_workspace(&mut monitor, perferences.borrow(), args)?;

Ok(Self {
file_manager: file,
bak,
ui: Ui::new(Arc::new(buf), setting),
workspace,
monitor,
perferences,
Expand All @@ -90,15 +71,8 @@ impl Application {
}

fn init(&mut self) -> Result<()> {
// Ui::init_ui()?;
// PluginSystem::init_system();
// self.monitor.terminal.clear().unwrap();
self.init_modes()?;
self.plugin_system.borrow().init();
// if !self.bak {
// self.ui.start_page_ui()?;
// }

Ok(())
}

Expand All @@ -122,12 +96,16 @@ impl Application {
self.mode_history.insert(ModeKey::Delete, ModeData::Delete);
self.mode_history
.insert(ModeKey::Search, ModeData::Search(SearchData::new()));

if self.workspace.current_buffer.is_none() {
self.switch_mode(ModeKey::Workspace);
}

Ok(())
}

pub fn run(&mut self) -> Result<()> {
self.init()?;

loop {
self.render()?;
self.listen_event()?;
Expand All @@ -137,24 +115,6 @@ impl Application {
return Ok(());
}
}

// 主线程
match self.ui.ui_loop() {
Ok(store) => {
if store {
let buffer = &self.ui.core.lock().unwrap().buffer;
self.file_manager.store(buffer)?
} else if self.file_manager.is_first_open() {
self.file_manager.delete_files()?;
}
}
Err(_) => {
// 补救措施:恢复备份文件
todo!()
}
}
disable_raw_mode()?;
Ok(())
}

fn listen_event(&mut self) -> Result<()> {
Expand Down
1 change: 0 additions & 1 deletion src/application/mode/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ impl ModeRenderer for DeleteRenderer {
let mut presenter = monitor.build_presenter()?;

if let Some(buffer) = &workspace.current_buffer {
warn!("Delete buffer id: {}", buffer.id.unwrap());
let data = buffer.data();
presenter.print_buffer(buffer, &data, &workspace.syntax_set, None, None)?;

Expand Down
1 change: 0 additions & 1 deletion src/application/mode/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ impl ModeRenderer for NormalRenderer {
let mut presenter = monitor.build_presenter()?;

if let Some(buffer) = &workspace.current_buffer {
warn!("normal buffer id: {}", buffer.id.unwrap());
let data = buffer.data();
presenter.print_buffer(buffer, &data, &workspace.syntax_set, None, None)?;

Expand Down
21 changes: 12 additions & 9 deletions src/application/mode/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct WorkspaceModeData {
max_index: usize,
opened_dir_inos: HashSet<u64>,
buffer_id: usize,
pub prev_buffer_id: usize,
pub prev_buffer_id: Option<usize>,
highlight_ranges: Vec<(Range, CharStyle, Colors)>,
}

Expand All @@ -37,19 +37,23 @@ impl WorkspaceModeData {
let mut opened_dir_inos = HashSet::new();
opened_dir_inos.insert(workspace.path.metadata()?.ino());

let prev_buffer_id = workspace.current_buffer.as_ref().unwrap().id()?;

let mut prev_buffer_id = None;
if let Some(current_buffer) = workspace.current_buffer.as_ref() {
prev_buffer_id = Some(current_buffer.id()?);
}
let buffer = Buffer::new();
let buffer_id = workspace.add_buffer(buffer);
monitor.init_buffer(workspace.current_buffer.as_mut().unwrap())?;
monitor.init_buffer(workspace.get_buffer_mut(buffer_id).unwrap())?;

workspace.select_buffer(prev_buffer_id);
if let Some(id) = prev_buffer_id {
workspace.select_buffer(id);
}

Ok(WorkspaceModeData {
path: workspace.path.clone(),
selected_index: 0,
opened_dir_inos,
buffer_id: buffer_id,
buffer_id,
prev_buffer_id,
highlight_ranges: Vec::new(),
current_render_index: 0,
Expand Down Expand Up @@ -276,10 +280,9 @@ impl WorkspaceModeData {
Ok(false)
} else {
let buffer = Buffer::from_file(&self.selected_path)?;
let id = workspace.add_buffer(buffer);
workspace.select_buffer(id);
let id = workspace.add_buffer_with_select(buffer);
monitor.init_buffer(workspace.current_buffer.as_mut().unwrap())?;
self.prev_buffer_id = id;
self.prev_buffer_id = Some(id);
Ok(true)
}
}
Expand Down
163 changes: 0 additions & 163 deletions src/config/appconfig.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/config/cmd.rs

This file was deleted.

Loading
Loading