ライブ変換モード #49

This commit is contained in:
Tokuhiro Matsuno
2023-01-29 00:16:08 +09:00
parent 8a9d1479c1
commit 0fbbf6ef34
3 changed files with 31 additions and 2 deletions

View File

@ -9,7 +9,8 @@ use gtk::{Application, ApplicationWindow, Button, Label, Notebook};
use gtk4 as gtk;
use gtk4::gio::ApplicationFlags;
use gtk4::{
ComboBoxText, FileChooserAction, FileChooserDialog, Grid, ResponseType, ScrolledWindow, Window,
CheckButton, ComboBoxText, FileChooserAction, FileChooserDialog, Grid, ResponseType,
ScrolledWindow, Window,
};
use log::{error, info};
@ -60,6 +61,7 @@ fn connect_activate(app: &Application, config: Arc<Mutex<Config>>) -> Result<()>
let config = Config {
keymap: config.keymap.to_string(),
romkan: config.romkan.to_string(),
live_conversion: config.live_conversion,
engine: EngineConfig {
model: config.engine.model.to_string(),
dicts: config.engine.dicts.clone(),
@ -228,6 +230,7 @@ fn build_core_pane(config: Arc<Mutex<Config>>) -> Result<Grid> {
}
cbt.set_active_id(Some(&config.lock().unwrap().engine.model));
let config = config.clone();
cbt.connect_changed(move |f| {
if let Some(id) = f.active_id() {
config.lock().unwrap().engine.model = id.to_string();
@ -241,6 +244,16 @@ fn build_core_pane(config: Arc<Mutex<Config>>) -> Result<Grid> {
1,
1,
);
{
let check_box = CheckButton::builder()
.label("ライブ変換")
.active(config.lock().unwrap().live_conversion)
.build();
grid.attach(&check_box, 0, 3, 1, 1);
check_box.connect_toggled(move |f| {
config.lock().unwrap().live_conversion = f.is_active();
});
}
Ok(grid)
}

View File

@ -66,6 +66,7 @@ pub struct AkazaContext {
// ==== UI 関連 ====
lookup_table: IBusLookupTable,
prop_controller: PropController,
live_conversion: bool,
}
impl AkazaContext {
@ -90,6 +91,7 @@ impl AkazaContext {
keymap: KeyMap::new(config.keymap)?,
prop_controller: PropController::new(input_mode)?,
consonant_suffix_extractor: ConsonantSuffixExtractor::default(),
live_conversion: config.live_conversion,
})
}
@ -225,7 +227,7 @@ impl AkazaContext {
"Insert new character to preedit: '{}'",
self.current_state.preedit
);
if self.lookup_table.get_number_of_candidates() > 0 {
if !self.live_conversion && self.lookup_table.get_number_of_candidates() > 0 {
// 変換の途中に別の文字が入力された。よって、現在の preedit 文字列は確定させる。
self.commit_candidate(engine);
}
@ -236,6 +238,12 @@ impl AkazaContext {
// And update the display status.
self.update_preedit_text_in_precomposition(engine);
// live conversion mode が true であれば、変換をガンガンかける
if self.live_conversion {
self.update_candidates(engine);
}
return true;
}
}

View File

@ -34,6 +34,10 @@ pub struct Config {
#[serde(default = "default_engine_config")]
pub engine: EngineConfig,
/// ライブ変換
#[serde(default = "default_live_conversion")]
pub live_conversion: bool,
}
fn default_romkan() -> String {
@ -52,6 +56,10 @@ fn default_engine_config() -> EngineConfig {
}
}
fn default_live_conversion() -> bool {
false
}
impl Config {
pub fn load_from_file(path: &str) -> Result<Self> {
let file = File::open(path)?;