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

open multiple files in one app instance if possible #451

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

elevenhsoft
Copy link

This will allow to open multiple files in one app instance. So for example, we opening 3x text files, so they will be opened in COSMIC Text (default app for specific mimetype) in 3 tabs, instead of 3 apps. Don't know if this is needed or implementation is fine but I'm sure to not broke anything 😅 If there will be one file selected, it will open just like before. Only handle for multiple files is featured. I tested this on multiple files for the same type:

  • 3x text files: *.rs, *.md and *.txt = opened in 3 tabs of COSMIC Text
  • 2x files with the same mimetype, *.deb = opened in one instance of Wizard app, so expected (also tested it in this app ^^)
  • 4x files with 2 different mimetypes, 2x *.deb and 2x *.zip files = opened in 2x different fileroller instances (so as it should I guess) and 2x deb files opened in one instance of Wizard app.

From my testing, seems to work.

src/mime_app.rs Outdated
@@ -10,16 +10,20 @@ use std::{
cmp::Ordering, collections::HashMap, env, path::PathBuf, process, sync::Mutex, time::Instant,
};

pub fn exec_to_command(exec: &str, path_opt: Option<PathBuf>) -> Option<process::Command> {
pub fn exec_to_command(exec: &str, path_opt: Vec<Option<PathBuf>>) -> Option<process::Command> {
let args_vec: Vec<String> = shlex::split(exec)?;
let mut args = args_vec.iter();
let mut command = process::Command::new(args.next()?);
for arg in args {
if arg.starts_with('%') {
match arg.as_str() {
"%f" | "%F" | "%u" | "%U" => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a program provides %f or %u it means only a single path or URL. %F or %U can accept a list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, did not know. To be honest I was reading about it today, because testing something but I did not consider it here 😓 Should I split this match pattern and in this case provide only first argument from vector and full list in other case?

@@ -2165,6 +2165,51 @@ impl Application for App {
}
}
}
tab::Command::OpenMultipleFiles(items) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a fallback to the original open code if no default apps are found, which will always happen on OSes like macOS and Windows.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, did not think about it. Of course I will make this change :)

@elevenhsoft
Copy link
Author

I made some changes.
First, now checking if Item has default app to open with. If it has, it will push command to open multiple files, otherwise it will use OpenFile command. I think it should works with different OSes but not sure. Someone smarter have to take a look ^^

Second, about arguments. Was not sure how to handle this case, so just passing first argument from vector. I don't know if it's correct tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants