WIP
This commit is contained in:
parent
7c310b36e1
commit
3cbf7dd341
@ -1,8 +1,8 @@
|
|||||||
use directories::UserDirs;
|
use directories::UserDirs;
|
||||||
use gio::prelude::FileExt;
|
use gio::prelude::FileExt;
|
||||||
use glib::object::Cast;
|
use glib::object::Cast;
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{cell::RefCell, env};
|
|
||||||
use walkdir::{DirEntry, WalkDir};
|
use walkdir::{DirEntry, WalkDir};
|
||||||
|
|
||||||
use crate::{LaunchError, LauncherListItem, LauncherPlugin};
|
use crate::{LaunchError, LauncherListItem, LauncherPlugin};
|
||||||
@ -31,10 +31,7 @@ impl LauncherListItem for FileEntry {
|
|||||||
fn execute(&self) -> Result<(), LaunchError> {
|
fn execute(&self) -> Result<(), LaunchError> {
|
||||||
let file_uri = gio::File::for_path(&self.path);
|
let file_uri = gio::File::for_path(&self.path);
|
||||||
let ctx = gio::AppLaunchContext::new();
|
let ctx = gio::AppLaunchContext::new();
|
||||||
match gio::AppInfo::launch_default_for_uri(
|
match gio::AppInfo::launch_default_for_uri(file_uri.uri().as_str(), Some(&ctx)) {
|
||||||
file_uri.uri().as_str(),
|
|
||||||
Some(&ctx),
|
|
||||||
) {
|
|
||||||
Err(_) => Err(LaunchError::CouldNotLaunch(
|
Err(_) => Err(LaunchError::CouldNotLaunch(
|
||||||
"Error opening file".to_string(),
|
"Error opening file".to_string(),
|
||||||
)),
|
)),
|
||||||
@ -57,6 +54,14 @@ impl LauncherListItem for FileEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: There should be a method add_search_path to add new paths
|
||||||
|
// when the plugin is getting initialized. After all paths are
|
||||||
|
// added I should get the lowest common denominator. So for example
|
||||||
|
// if we have:
|
||||||
|
// $HOME/Documents
|
||||||
|
// $HOME/Documents/wallpapers
|
||||||
|
// Then we should just keep $HOME/Documents since wallpapers
|
||||||
|
// will be included in it anyways
|
||||||
pub struct FileSearchPlugin {
|
pub struct FileSearchPlugin {
|
||||||
search_paths: Vec<PathBuf>,
|
search_paths: Vec<PathBuf>,
|
||||||
skip_dirs: Vec<String>,
|
skip_dirs: Vec<String>,
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
use crate::launcher::WaycastLauncher;
|
use crate::launcher::WaycastLauncher;
|
||||||
|
use gio::ListStore;
|
||||||
|
use gio::prelude::ApplicationExt;
|
||||||
use gtk::gdk::Texture;
|
use gtk::gdk::Texture;
|
||||||
use gtk::gdk_pixbuf::Pixbuf;
|
use gtk::gdk_pixbuf::Pixbuf;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{
|
|
||||||
ApplicationWindow, Box as GtkBox, Entry, EventControllerKey, IconTheme, Image,
|
|
||||||
Label, ListView, Orientation, ScrolledWindow, SignalListItemFactory, SingleSelection,
|
|
||||||
};
|
|
||||||
use gio::ListStore;
|
|
||||||
use gtk::subclass::prelude::ObjectSubclassIsExt;
|
use gtk::subclass::prelude::ObjectSubclassIsExt;
|
||||||
|
use gtk::{
|
||||||
|
ApplicationWindow, Box as GtkBox, Entry, EventControllerKey, IconTheme, Image, Label, ListView,
|
||||||
|
Orientation, ScrolledWindow, SignalListItemFactory, SingleSelection,
|
||||||
|
};
|
||||||
use gtk4_layer_shell as layerShell;
|
use gtk4_layer_shell as layerShell;
|
||||||
use layerShell::LayerShell;
|
use layerShell::LayerShell;
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::cell::RefCell;
|
|
||||||
use gio::prelude::ApplicationExt;
|
|
||||||
|
|
||||||
// GObject wrapper to store LauncherListItem in GTK's model system
|
// GObject wrapper to store LauncherListItem in GTK's model system
|
||||||
mod imp {
|
mod imp {
|
||||||
@ -76,12 +76,6 @@ impl LauncherItemObject {
|
|||||||
|
|
||||||
pub struct GtkLauncherUI {
|
pub struct GtkLauncherUI {
|
||||||
window: ApplicationWindow,
|
window: ApplicationWindow,
|
||||||
list_view: ListView,
|
|
||||||
list_store: ListStore,
|
|
||||||
selection: SingleSelection,
|
|
||||||
search_input: Entry,
|
|
||||||
launcher: Rc<RefCell<WaycastLauncher>>,
|
|
||||||
app: gtk::Application,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GtkLauncherUI {
|
impl GtkLauncherUI {
|
||||||
@ -137,7 +131,8 @@ impl GtkLauncherUI {
|
|||||||
// Create icon
|
// Create icon
|
||||||
let image: gtk::Image;
|
let image: gtk::Image;
|
||||||
if let Some(icon_path) = find_icon_file(&item_obj.icon(), "48", &icon_theme) {
|
if let Some(icon_path) = find_icon_file(&item_obj.icon(), "48", &icon_theme) {
|
||||||
image = match Pixbuf::from_file_at_scale(icon_path, icon_size, icon_size, true) {
|
image = match Pixbuf::from_file_at_scale(icon_path, icon_size, icon_size, true)
|
||||||
|
{
|
||||||
Ok(pb) => {
|
Ok(pb) => {
|
||||||
let tex = Texture::for_pixbuf(&pb);
|
let tex = Texture::for_pixbuf(&pb);
|
||||||
gtk::Image::from_paintable(Some(&tex))
|
gtk::Image::from_paintable(Some(&tex))
|
||||||
@ -244,7 +239,7 @@ impl GtkLauncherUI {
|
|||||||
entry.title(),
|
entry.title(),
|
||||||
entry.description(),
|
entry.description(),
|
||||||
entry.icon(),
|
entry.icon(),
|
||||||
index
|
index,
|
||||||
);
|
);
|
||||||
list_store_for_search.append(&item_obj);
|
list_store_for_search.append(&item_obj);
|
||||||
}
|
}
|
||||||
@ -310,7 +305,10 @@ impl GtkLauncherUI {
|
|||||||
let launcher_for_activate = launcher.clone();
|
let launcher_for_activate = launcher.clone();
|
||||||
let app_for_activate = app.clone();
|
let app_for_activate = app.clone();
|
||||||
list_view.connect_activate(move |_, position| {
|
list_view.connect_activate(move |_, position| {
|
||||||
match launcher_for_activate.borrow().execute_item(position as usize) {
|
match launcher_for_activate
|
||||||
|
.borrow()
|
||||||
|
.execute_item(position as usize)
|
||||||
|
{
|
||||||
Ok(_) => app_for_activate.quit(),
|
Ok(_) => app_for_activate.quit(),
|
||||||
Err(e) => eprintln!("Failed to launch app: {:?}", e),
|
Err(e) => eprintln!("Failed to launch app: {:?}", e),
|
||||||
}
|
}
|
||||||
@ -320,12 +318,8 @@ impl GtkLauncherUI {
|
|||||||
let mut launcher_ref = launcher.borrow_mut();
|
let mut launcher_ref = launcher.borrow_mut();
|
||||||
let results = launcher_ref.get_default_results();
|
let results = launcher_ref.get_default_results();
|
||||||
for (index, entry) in results.iter().enumerate() {
|
for (index, entry) in results.iter().enumerate() {
|
||||||
let item_obj = LauncherItemObject::new(
|
let item_obj =
|
||||||
entry.title(),
|
LauncherItemObject::new(entry.title(), entry.description(), entry.icon(), index);
|
||||||
entry.description(),
|
|
||||||
entry.icon(),
|
|
||||||
index
|
|
||||||
);
|
|
||||||
list_store.append(&item_obj);
|
list_store.append(&item_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,12 +331,6 @@ impl GtkLauncherUI {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
window,
|
window,
|
||||||
list_view,
|
|
||||||
list_store,
|
|
||||||
selection,
|
|
||||||
search_input,
|
|
||||||
launcher,
|
|
||||||
app: app.clone(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,7 +364,10 @@ impl GtkLauncherUI {
|
|||||||
|
|
||||||
// Check if file exists first
|
// Check if file exists first
|
||||||
if !css_path.as_ref().exists() {
|
if !css_path.as_ref().exists() {
|
||||||
return Err(format!("CSS file does not exist: {}", css_path.as_ref().display()));
|
return Err(format!(
|
||||||
|
"CSS file does not exist: {}",
|
||||||
|
css_path.as_ref().display()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to load the CSS file
|
// Try to load the CSS file
|
||||||
@ -399,7 +390,7 @@ impl GtkLauncherUI {
|
|||||||
Err("Could not get default display".to_string())
|
Err("Could not get default display".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => Err(format!("Failed to read CSS file: {}", e))
|
Err(e) => Err(format!("Failed to read CSS file: {}", e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user