Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bookmarks #354

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/target/
/vendor.tar
/vendor/

.idea
2 changes: 2 additions & 0 deletions i18n/en/cosmic_files.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ filesystem = Filesystem
home = Home
notification-in-progress = File operations are in progress.
trash = Trash
bookmarks = Bookmarks
undo = Undo

# List view
Expand Down Expand Up @@ -154,6 +155,7 @@ new-file = New file...
new-folder = New folder...
open-in-terminal = Open in terminal
move-to-trash = Move to trash
add_remove_bookmark = Add/remove bookmark
restore-from-trash = Restore from trash
remove-from-sidebar = Remove from sidebar
sort-by-name = Sort by name
Expand Down
2 changes: 2 additions & 0 deletions i18n/it/cosmic_files.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ filesystem = Filesystem
home = Home
notification-in-progress = Operazioni sui file in corso ...
trash = Cestino
bookmarks = Segnalibri
undo = Annulla ultima operazione

# List view
Expand Down Expand Up @@ -145,6 +146,7 @@ new-file = Nuovo file
new-folder = Nuova cartella
open-in-terminal = Apri in terminale
move-to-trash = Sposta nel cestino
add_remove_bookmark = Aggiungi/rimuovi segnalibro
restore-from-trash = Ripristina dal cestino
remove-from-sidebar = Rimuovi da sidebar
sort-by-name = Ordina per nome
Expand Down
28 changes: 28 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub enum Action {
ZoomDefault,
ZoomIn,
ZoomOut,
AddBookmark,
}

impl Action {
Expand Down Expand Up @@ -168,6 +169,7 @@ impl Action {
Action::ZoomDefault => Message::TabMessage(entity_opt, tab::Message::ZoomDefault),
Action::ZoomIn => Message::TabMessage(entity_opt, tab::Message::ZoomIn),
Action::ZoomOut => Message::TabMessage(entity_opt, tab::Message::ZoomOut),
Action::AddBookmark => Message::AddBookmark(entity_opt),
}
}
}
Expand Down Expand Up @@ -274,6 +276,7 @@ pub enum Message {
DndExitTab,
DndDropTab(Entity, Option<ClipboardPaste>, DndAction),
DndDropNav(Entity, Option<ClipboardPaste>, DndAction),
AddBookmark(Option<Entity>),
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -527,6 +530,13 @@ impl App {

fn update_nav_model(&mut self) {
let mut nav_model = segmented_button::ModelBuilder::default();

nav_model = nav_model.insert(|b| {
b.text("Bookmark")
.icon(widget::icon::from_name("user-bookmarks-symbolic"))
.data(Location::Bookmarks)
});

for (favorite_i, favorite) in self.config.favorites.iter().enumerate() {
if let Some(path) = favorite.path_opt() {
let name = if matches!(favorite, Favorite::Home) {
Expand Down Expand Up @@ -2252,6 +2262,9 @@ impl Application for App {
Some(Location::Trash) => {
return self.open_tab(Location::Trash, false, None);
}
Some(Location::Bookmarks) => {
return self.open_tab(Location::Bookmarks, false, None);
}
_ => {}
}
}
Expand Down Expand Up @@ -2295,6 +2308,21 @@ impl Application for App {
self.dialog_pages.push_front(DialogPage::EmptyTrash);
}
},
Message::AddBookmark(entity) => {
let selected_paths = self.selected_paths(entity);
let mut bookmarks = self.config.bookmarks.clone();

for path in selected_paths {
if !bookmarks.iter().any(|p| p == &path) {
bookmarks.push(path);
}
else {
bookmarks.retain(|p| p != &path);
}
}

config_set!(bookmarks, bookmarks);
}
}

Command::none()
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct Config {
pub app_theme: AppTheme,
pub favorites: Vec<Favorite>,
pub tab: TabConfig,
pub bookmarks: Vec<PathBuf>,
}

impl Default for Config {
Expand All @@ -110,6 +111,7 @@ impl Default for Config {
Favorite::Videos,
],
tab: TabConfig::default(),
bookmarks: Vec::new(),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn context_menu<'a>(

let mut children: Vec<Element<_>> = Vec::new();
match tab.location {
Location::Path(_) | Location::Search(_, _) => {
Location::Path(_) | Location::Search(_, _) | Location::Bookmarks => {
if selected > 0 {
if selected_dir == 1 && selected == 1 || selected_dir == 0 {
children.push(menu_item(fl!("open"), Action::Open).into());
Expand Down Expand Up @@ -141,6 +141,8 @@ pub fn context_menu<'a>(
children.push(menu_item(fl!("add-to-sidebar"), Action::AddToSidebar).into());
children.push(container(horizontal_rule(1)).padding([0, 8]).into());
children.push(menu_item(fl!("move-to-trash"), Action::MoveToTrash).into());
//TODO this should be add or remove if it already exist not only add
children.push(menu_item(fl!("add_remove_bookmark"), Action::AddBookmark).into());
} else {
//TODO: need better designs for menu with no selection
//TODO: have things like properties but they apply to the folder?
Expand Down
Loading