Add page notes panel
This commit is contained in:
@@ -6,10 +6,10 @@ use crate::{
|
||||
CoreError,
|
||||
navigation::{
|
||||
about_url, archive_idle_days, archive_url, bookmarks_url, downloads_url, history_url,
|
||||
move_tab_space_name, new_private_profile_name, new_profile_name, new_space_name,
|
||||
plugin_detail_url, plugins_url, reading_list_url, reading_progress_percent, search_url,
|
||||
settings_page_url, settings_url, shortcut_settings_url, space_icon, switch_profile_name,
|
||||
sync_status_url, task_manager_url,
|
||||
move_tab_space_name, new_private_profile_name, new_profile_name, new_space_name, note_body,
|
||||
notes_url, plugin_detail_url, plugins_url, reading_list_url, reading_progress_percent,
|
||||
search_url, settings_page_url, settings_url, shortcut_settings_url, space_icon,
|
||||
switch_profile_name, sync_status_url, tab_note_body, task_manager_url,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -61,6 +61,12 @@ impl BrowserCore {
|
||||
self.command_query.clear();
|
||||
}
|
||||
}
|
||||
CommandIntent::ScopedSearch { scope: CommandScope::Notes, query } => {
|
||||
if let Some(url) = self.find_note_match(query) {
|
||||
self.open_tab(url);
|
||||
self.command_query.clear();
|
||||
}
|
||||
}
|
||||
CommandIntent::ScopedSearch { scope: CommandScope::ReadingList, query } => {
|
||||
if let Some(url) = self.find_reading_list_match(query) {
|
||||
self.open_tab(url);
|
||||
@@ -127,6 +133,14 @@ impl BrowserCore {
|
||||
self.set_active_tab_reading_progress(percent)?;
|
||||
return Ok(true);
|
||||
}
|
||||
if let Some(body) = tab_note_body(command) {
|
||||
self.save_active_tab_note(body)?;
|
||||
return Ok(true);
|
||||
}
|
||||
if let Some(body) = note_body(command) {
|
||||
self.save_active_url_note(body)?;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
match command.to_ascii_lowercase().as_str() {
|
||||
"new-tab" => {
|
||||
@@ -150,6 +164,10 @@ impl BrowserCore {
|
||||
self.open_tab(reading_list_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"notes" | "open-notes" | "open notes" => {
|
||||
self.open_tab(notes_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"history" | "open-history" | "open history" => {
|
||||
self.open_tab(history_url()?);
|
||||
Ok(true)
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ely_domain::{NoteEntry, NoteId, NoteTarget, UrlText};
|
||||
|
||||
use crate::CoreError;
|
||||
|
||||
use super::BrowserCore;
|
||||
|
||||
impl BrowserCore {
|
||||
pub fn save_active_url_note(&mut self, body: impl Into<String>) -> Result<NoteId, CoreError> {
|
||||
let active_tab = self.active_tab()?.clone();
|
||||
let now = SystemTime::now();
|
||||
let target = NoteTarget::Url(active_tab.url().clone());
|
||||
|
||||
if let Some(index) = self.note_index_for_target(active_tab.profile_id(), &target) {
|
||||
self.notes[index].update(
|
||||
active_tab.title(),
|
||||
active_tab.url().clone(),
|
||||
body.into(),
|
||||
now,
|
||||
)?;
|
||||
return Ok(self.notes[index].id().clone());
|
||||
}
|
||||
|
||||
let entry = NoteEntry::new(
|
||||
active_tab.profile_id().clone(),
|
||||
active_tab.space_id().clone(),
|
||||
target,
|
||||
active_tab.title(),
|
||||
active_tab.url().clone(),
|
||||
body,
|
||||
now,
|
||||
)?;
|
||||
let entry_id = entry.id().clone();
|
||||
self.notes.push(entry);
|
||||
Ok(entry_id)
|
||||
}
|
||||
|
||||
pub fn save_active_tab_note(&mut self, body: impl Into<String>) -> Result<NoteId, CoreError> {
|
||||
let active_tab = self.active_tab()?.clone();
|
||||
let now = SystemTime::now();
|
||||
let target = NoteTarget::Tab(active_tab.id().clone());
|
||||
|
||||
if let Some(index) = self.note_index_for_target(active_tab.profile_id(), &target) {
|
||||
self.notes[index].update(
|
||||
active_tab.title(),
|
||||
active_tab.url().clone(),
|
||||
body.into(),
|
||||
now,
|
||||
)?;
|
||||
return Ok(self.notes[index].id().clone());
|
||||
}
|
||||
|
||||
let entry = NoteEntry::new(
|
||||
active_tab.profile_id().clone(),
|
||||
active_tab.space_id().clone(),
|
||||
target,
|
||||
active_tab.title(),
|
||||
active_tab.url().clone(),
|
||||
body,
|
||||
now,
|
||||
)?;
|
||||
let entry_id = entry.id().clone();
|
||||
self.notes.push(entry);
|
||||
Ok(entry_id)
|
||||
}
|
||||
|
||||
pub(super) fn find_note_match(&self, query: &str) -> Option<UrlText> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.notes
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|entry| entry.profile_id() == &self.active_profile_id)
|
||||
.find(|entry| note_entry_matches_query(entry, &normalized_query))
|
||||
.map(|entry| entry.source_url().clone())
|
||||
}
|
||||
|
||||
pub(super) fn visible_notes(&self) -> Vec<NoteEntry> {
|
||||
self.notes
|
||||
.iter()
|
||||
.filter(|entry| entry.profile_id() == &self.active_profile_id)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn note_index_for_target(
|
||||
&self,
|
||||
profile_id: &ely_domain::ProfileId,
|
||||
target: &NoteTarget,
|
||||
) -> Option<usize> {
|
||||
self.notes.iter().position(|entry| {
|
||||
entry.profile_id() == profile_id && note_targets_match(entry.target(), target)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn note_targets_match(left: &NoteTarget, right: &NoteTarget) -> bool {
|
||||
match (left, right) {
|
||||
(NoteTarget::Url(left_url), NoteTarget::Url(right_url)) => left_url == right_url,
|
||||
(NoteTarget::Tab(left_tab), NoteTarget::Tab(right_tab)) => left_tab == right_tab,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn note_entry_matches_query(entry: &NoteEntry, normalized_query: &str) -> bool {
|
||||
entry.title().to_lowercase().contains(normalized_query)
|
||||
|| entry.source_url().as_str().to_lowercase().contains(normalized_query)
|
||||
|| entry.display_url().to_lowercase().contains(normalized_query)
|
||||
|| entry.body().to_lowercase().contains(normalized_query)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ pub(super) struct SyncObjectPolicies {
|
||||
spaces: SyncObjectPolicy,
|
||||
tabs: SyncObjectPolicy,
|
||||
bookmarks: SyncObjectPolicy,
|
||||
notes: SyncObjectPolicy,
|
||||
reading_list: SyncObjectPolicy,
|
||||
profiles: SyncObjectPolicy,
|
||||
site_permissions: SyncObjectPolicy,
|
||||
@@ -20,6 +21,7 @@ impl Default for SyncObjectPolicies {
|
||||
spaces: SyncObjectPolicy::Enabled,
|
||||
tabs: SyncObjectPolicy::Enabled,
|
||||
bookmarks: SyncObjectPolicy::Enabled,
|
||||
notes: SyncObjectPolicy::Enabled,
|
||||
reading_list: SyncObjectPolicy::Enabled,
|
||||
profiles: SyncObjectPolicy::Enabled,
|
||||
site_permissions: SyncObjectPolicy::Enabled,
|
||||
@@ -35,6 +37,7 @@ impl SyncObjectPolicies {
|
||||
SyncObjectKind::Spaces => self.spaces,
|
||||
SyncObjectKind::Tabs => self.tabs,
|
||||
SyncObjectKind::Bookmarks => self.bookmarks,
|
||||
SyncObjectKind::Notes => self.notes,
|
||||
SyncObjectKind::ReadingList => self.reading_list,
|
||||
SyncObjectKind::Profiles => self.profiles,
|
||||
SyncObjectKind::SitePermissions => self.site_permissions,
|
||||
@@ -48,6 +51,7 @@ impl SyncObjectPolicies {
|
||||
SyncObjectKind::Spaces => self.spaces = policy,
|
||||
SyncObjectKind::Tabs => self.tabs = policy,
|
||||
SyncObjectKind::Bookmarks => self.bookmarks = policy,
|
||||
SyncObjectKind::Notes => self.notes = policy,
|
||||
SyncObjectKind::ReadingList => self.reading_list = policy,
|
||||
SyncObjectKind::Profiles => self.profiles = policy,
|
||||
SyncObjectKind::SitePermissions => self.site_permissions = policy,
|
||||
@@ -84,6 +88,11 @@ impl BrowserCore {
|
||||
self.bookmarks.len(),
|
||||
SyncObjectState::LocalOnly,
|
||||
),
|
||||
self.sync_object_status(
|
||||
SyncObjectKind::Notes,
|
||||
self.notes.len(),
|
||||
SyncObjectState::LocalOnly,
|
||||
),
|
||||
self.sync_object_status(
|
||||
SyncObjectKind::ReadingList,
|
||||
self.reading_list.len(),
|
||||
|
||||
Reference in New Issue
Block a user