ui improvements and feature flags for AI integration
Continuous integration / build (push) Failing after 4m9s
Continuous integration / build (push) Failing after 4m9s
This commit is contained in:
@@ -1,34 +1,42 @@
|
||||
use egui::TextEdit;
|
||||
use egui_commonmark::{CommonMarkCache, CommonMarkViewer};
|
||||
use serde::{self, Deserialize, Serialize};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::{
|
||||
PROJECT_FOLDER,
|
||||
editors::{settings_editor::ProjectSettings, tags::Tag},
|
||||
llm_integration::content_llm::{ContentAI, ReadyState, ReasoningEffort},
|
||||
util,
|
||||
};
|
||||
|
||||
#[cfg(feature = "llm")]
|
||||
use crate::llm_integration::content_llm::{ContentAI, ReadyState};
|
||||
|
||||
pub struct MainEditor {
|
||||
pub content: ContentSection,
|
||||
pub show_editor: bool,
|
||||
pub editor_separate_window: bool,
|
||||
pub show_preview: bool,
|
||||
preview_cache: CommonMarkCache,
|
||||
dialog: Option<ContentAI>,
|
||||
|
||||
#[cfg(feature = "llm")]
|
||||
dialog: ContentAI,
|
||||
#[cfg(feature = "llm")]
|
||||
pub show_ai: bool,
|
||||
}
|
||||
|
||||
impl Clone for MainEditor {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
content: self.content.clone(),
|
||||
|
||||
show_editor: self.show_editor,
|
||||
editor_separate_window: self.editor_separate_window,
|
||||
show_preview: self.show_preview,
|
||||
preview_cache: CommonMarkCache::default(),
|
||||
|
||||
#[cfg(feature = "llm")]
|
||||
dialog: self.dialog.clone(),
|
||||
#[cfg(feature = "llm")]
|
||||
show_ai: self.show_ai,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,7 +116,11 @@ impl MainEditor {
|
||||
show_preview: false,
|
||||
editor_separate_window: false,
|
||||
preview_cache: CommonMarkCache::default(),
|
||||
dialog: None,
|
||||
|
||||
#[cfg(feature = "llm")]
|
||||
show_ai: false,
|
||||
#[cfg(feature = "llm")]
|
||||
dialog: ContentAI::new(String::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +131,11 @@ impl MainEditor {
|
||||
show_preview: false,
|
||||
editor_separate_window: false,
|
||||
preview_cache: CommonMarkCache::default(),
|
||||
dialog: None,
|
||||
|
||||
#[cfg(feature = "llm")]
|
||||
show_ai: false,
|
||||
#[cfg(feature = "llm")]
|
||||
dialog: ContentAI::new(String::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +193,10 @@ impl MainEditor {
|
||||
// preview toggle
|
||||
ui.checkbox(&mut self.show_preview, "Preview");
|
||||
|
||||
// assistant toggle
|
||||
#[cfg(feature = "llm")]
|
||||
ui.checkbox(&mut self.show_ai, "AI Assistant");
|
||||
|
||||
// editor toggle
|
||||
ui.checkbox(&mut self.editor_separate_window, "Pop out editor");
|
||||
});
|
||||
@@ -222,10 +242,13 @@ impl MainEditor {
|
||||
|
||||
ui.separator();
|
||||
|
||||
if let Some(dialog) = &mut self.dialog {
|
||||
dialog.ui(ui, project);
|
||||
#[cfg(feature = "llm")]
|
||||
if self.show_ai {
|
||||
let dialog = &mut self.dialog;
|
||||
|
||||
dialog.content = self.content.content.clone();
|
||||
dialog.ui(ui, project);
|
||||
|
||||
if *dialog.ready.lock().unwrap() == ReadyState::Ready {
|
||||
self.content
|
||||
.content
|
||||
@@ -319,50 +342,16 @@ impl MainEditor {
|
||||
|
||||
ui.set_min_width(max_width as f32);
|
||||
|
||||
let text_edit = TextEdit::multiline(&mut self.content.content)
|
||||
.id_source("MainEditor_editor")
|
||||
.font(egui::TextStyle::Monospace)
|
||||
.interactive(true)
|
||||
.frame(false)
|
||||
.lock_focus(true)
|
||||
.hint_text("Type here...")
|
||||
.desired_width(max_width as f32);
|
||||
|
||||
let mut ctx_menu = false;
|
||||
let response = ui
|
||||
.add_sized(
|
||||
egui::vec2(max_width as f32 - 30.0, ui.available_height()),
|
||||
text_edit,
|
||||
)
|
||||
.on_hover_text("Right click to open context menu")
|
||||
.context_menu(|ui| {
|
||||
ctx_menu = true;
|
||||
|
||||
ui.menu_button("AI Actions", |ui| {
|
||||
ui.add_enabled_ui(project.ai_enabled(), |ui| {
|
||||
if ui.button("AI Assistant").clicked() {
|
||||
self.dialog = Some(ContentAI {
|
||||
content: self.content.content.clone(),
|
||||
instruction: String::new(),
|
||||
max_tokens: 1024,
|
||||
reasoning_effort: ReasoningEffort::default(),
|
||||
context_override: "".to_string(),
|
||||
result: Arc::new(Mutex::new(String::new())),
|
||||
open: true,
|
||||
ready: Arc::new(Mutex::new(ReadyState::Idle)),
|
||||
temperature: 0.7,
|
||||
model_override: "".to_string(),
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if let Some(response) = response {
|
||||
if response.response.changed() || ctx_menu {
|
||||
self.content.saved = false;
|
||||
}
|
||||
}
|
||||
ui.add(
|
||||
TextEdit::multiline(&mut self.content.content)
|
||||
.id_source("MainEditor_editor")
|
||||
.font(egui::TextStyle::Monospace)
|
||||
.interactive(true)
|
||||
.frame(false)
|
||||
.lock_focus(true)
|
||||
.hint_text("Type here...")
|
||||
.desired_width(max_width as f32),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user