mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LaunchServer: added additional file parameters
This small commit should allow to specify additionnal parameters in the form of URL queries, when opening a file via a "file://" url through the LaunchServer.
This commit is contained in:
parent
c9f25bca04
commit
a0c0d781e8
2 changed files with 20 additions and 7 deletions
|
@ -176,7 +176,7 @@ bool Launcher::open_url(const URL& url, const String& handler_name)
|
||||||
if (url.protocol() == "file")
|
if (url.protocol() == "file")
|
||||||
return open_file_url(url);
|
return open_file_url(url);
|
||||||
|
|
||||||
return open_with_user_preferences(m_protocol_handlers, url.protocol(), url.to_string());
|
return open_with_user_preferences(m_protocol_handlers, url.protocol(), { url.to_string() });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Launcher::open_with_handler_name(const URL& url, const String& handler_name)
|
bool Launcher::open_with_handler_name(const URL& url, const String& handler_name)
|
||||||
|
@ -225,20 +225,20 @@ Handler Launcher::get_handler_for_executable(Handler::Type handler_type, const S
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Launcher::open_with_user_preferences(const HashMap<String, String>& user_preferences, const String key, const String argument, const String default_program)
|
bool Launcher::open_with_user_preferences(const HashMap<String, String>& user_preferences, const String key, const AK::Vector<String> arguments, const String default_program)
|
||||||
{
|
{
|
||||||
auto program_path = user_preferences.get(key);
|
auto program_path = user_preferences.get(key);
|
||||||
if (program_path.has_value())
|
if (program_path.has_value())
|
||||||
return spawn(program_path.value(), { argument });
|
return spawn(program_path.value(), arguments);
|
||||||
|
|
||||||
// There wasn't a handler for this, so try the fallback instead
|
// There wasn't a handler for this, so try the fallback instead
|
||||||
program_path = user_preferences.get("*");
|
program_path = user_preferences.get("*");
|
||||||
if (program_path.has_value())
|
if (program_path.has_value())
|
||||||
return spawn(program_path.value(), { argument });
|
return spawn(program_path.value(), arguments);
|
||||||
|
|
||||||
// Absolute worst case, try the provided default program, if any
|
// Absolute worst case, try the provided default program, if any
|
||||||
if (!default_program.is_empty())
|
if (!default_program.is_empty())
|
||||||
return spawn(default_program, { argument });
|
return spawn(default_program, arguments);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -317,6 +317,19 @@ bool Launcher::open_file_url(const URL& url)
|
||||||
String extension = {};
|
String extension = {};
|
||||||
if (extension_parts.size() > 1)
|
if (extension_parts.size() > 1)
|
||||||
extension = extension_parts.last();
|
extension = extension_parts.last();
|
||||||
return open_with_user_preferences(m_file_handlers, extension, url.path(), "/bin/TextEditor");
|
|
||||||
|
// Additionnal parameters parsing, specific for the file protocol
|
||||||
|
Vector<String> additional_parameters;
|
||||||
|
additional_parameters.append(url.path());
|
||||||
|
auto parameters = url.query().split('&');
|
||||||
|
for (auto parameter = parameters.begin(); parameter != parameters.end(); ++parameter) {
|
||||||
|
auto pair = parameter->split('=');
|
||||||
|
if (pair[0] == "line_number") {
|
||||||
|
auto line = pair[1].to_int();
|
||||||
|
if (line.has_value())
|
||||||
|
additional_parameters.prepend(String::format("-l%i", *line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return open_with_user_preferences(m_file_handlers, extension, additional_parameters, "/bin/TextEditor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ private:
|
||||||
void for_each_handler(const String& key, HashMap<String, String>& user_preferences, Function<bool(const Handler&)> f);
|
void for_each_handler(const String& key, HashMap<String, String>& user_preferences, Function<bool(const Handler&)> f);
|
||||||
void for_each_handler_for_path(const String&, Function<bool(const Handler&)> f);
|
void for_each_handler_for_path(const String&, Function<bool(const Handler&)> f);
|
||||||
bool open_file_url(const URL&);
|
bool open_file_url(const URL&);
|
||||||
bool open_with_user_preferences(const HashMap<String, String>& user_preferences, const String key, const String argument, const String default_program = {});
|
bool open_with_user_preferences(const HashMap<String, String>& user_preferences, const String key, const AK::Vector<String> arguments, const String default_program = {});
|
||||||
bool open_with_handler_name(const URL&, const String& handler_name);
|
bool open_with_handler_name(const URL&, const String& handler_name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue