Skip to content

Commit

Permalink
added settings window in project manager + open in ide ability
Browse files Browse the repository at this point in the history
- `open in ide` uses configurable shell command
  • Loading branch information
mrDIMAS committed Dec 15, 2024
1 parent eefc5e9 commit 4724d98
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 33 deletions.
4 changes: 2 additions & 2 deletions editor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ use crate::{
world::{graph::menu::SceneNodeContextMenu, graph::EditorSceneWrapper, WorldViewer},
};
use fyrox::gui::log::LogPanel;
use fyrox_build_tools::BuildCommand;
use fyrox_build_tools::CommandDescriptor;
pub use message::Message;
use plugins::inspector::InspectorPlugin;
use std::process::Stdio;
Expand Down Expand Up @@ -303,7 +303,7 @@ pub fn make_save_file_selector(
pub enum Mode {
Edit,
Build {
queue: VecDeque<BuildCommand>,
queue: VecDeque<CommandDescriptor>,
process: Option<std::process::Child>,
},
Play {
Expand Down
6 changes: 3 additions & 3 deletions editor/src/plugins/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use crate::{
},
Editor, MSG_SYNC_FLAG,
};
use fyrox_build_tools::{BuildCommand, BuildProfile, EnvironmentVariable};
use fyrox_build_tools::{BuildProfile, CommandDescriptor, EnvironmentVariable};
use std::sync::Arc;

fn make_property_editors_container(
Expand Down Expand Up @@ -100,8 +100,8 @@ fn make_property_editors_container(
container.insert(InspectablePropertyEditorDefinition::<EnvironmentVariable>::new());
container.insert(VecCollectionPropertyEditorDefinition::<BuildProfile>::new());
container.insert(InspectablePropertyEditorDefinition::<BuildProfile>::new());
container.insert(VecCollectionPropertyEditorDefinition::<BuildCommand>::new());
container.insert(InspectablePropertyEditorDefinition::<BuildCommand>::new());
container.insert(VecCollectionPropertyEditorDefinition::<CommandDescriptor>::new());
container.insert(InspectablePropertyEditorDefinition::<CommandDescriptor>::new());
container.insert(HotKeyPropertyEditorDefinition);
Arc::new(container)
}
Expand Down
30 changes: 15 additions & 15 deletions fyrox-build-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ pub struct EnvironmentVariable {

#[derive(Deserialize, Serialize, PartialEq, Clone, Debug, Default, Reflect, TypeUuidProvider)]
#[type_uuid(id = "67b93136-17fe-4776-b5f0-f4a9ef3d8972")]
pub struct BuildCommand {
pub struct CommandDescriptor {
pub command: String,
pub args: Vec<String>,
pub environment_variables: Vec<EnvironmentVariable>,
}

impl BuildCommand {
impl CommandDescriptor {
pub fn make_command(&self) -> std::process::Command {
let mut command = std::process::Command::new(&self.command);

Expand All @@ -52,7 +52,7 @@ impl BuildCommand {
}
}

impl Display for BuildCommand {
impl Display for CommandDescriptor {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
for var in self.environment_variables.iter() {
write!(f, "{}=\"{}\" ", var.name, var.value)?;
Expand All @@ -73,11 +73,11 @@ impl Display for BuildCommand {
pub struct BuildProfile {
pub name: String,
#[reflect(description = "A set of commands that will be used to build your game.")]
pub build_commands: Vec<BuildCommand>,
pub build_commands: Vec<CommandDescriptor>,
#[reflect(description = "A set of commands that will be used to run your game. \
This set of commands will be executed right after build commands (if the \
build was successful)")]
pub run_command: BuildCommand,
pub run_command: CommandDescriptor,
}

impl BuildProfile {
Expand All @@ -91,7 +91,7 @@ impl BuildProfile {
}
}

pub fn build_and_run_queue(&self) -> VecDeque<BuildCommand> {
pub fn build_and_run_queue(&self) -> VecDeque<CommandDescriptor> {
let mut queue = self.build_commands.iter().cloned().collect::<VecDeque<_>>();
queue.push_back(self.run_command.clone());
queue
Expand All @@ -100,7 +100,7 @@ impl BuildProfile {
pub fn debug() -> Self {
BuildProfile {
name: "Debug".to_string(),
build_commands: vec![BuildCommand {
build_commands: vec![CommandDescriptor {
command: "cargo".to_string(),
args: vec![
"build".to_string(),
Expand All @@ -109,7 +109,7 @@ impl BuildProfile {
],
environment_variables: vec![],
}],
run_command: BuildCommand {
run_command: CommandDescriptor {
command: "cargo".to_string(),
args: vec![
"run".to_string(),
Expand All @@ -133,7 +133,7 @@ impl BuildProfile {
name: "Debug (HR)".to_string(),
build_commands: vec![
Self::build_game(), // Build the executor.
BuildCommand {
CommandDescriptor {
command: "cargo".to_string(),
args: vec![
"build".to_string(),
Expand Down Expand Up @@ -163,9 +163,9 @@ impl BuildProfile {
release_hot_reloading
}

fn build_game() -> BuildCommand {
fn build_game() -> CommandDescriptor {
// Build the game plugin DLL first.
BuildCommand {
CommandDescriptor {
command: "cargo".to_string(),
args: vec![
"build".to_string(),
Expand All @@ -184,8 +184,8 @@ impl BuildProfile {
}
}

fn run_hot_reload(package_name: &str) -> BuildCommand {
BuildCommand {
fn run_hot_reload(package_name: &str) -> CommandDescriptor {
CommandDescriptor {
command: "cargo".to_string(),
args: vec![
"run".to_string(),
Expand Down Expand Up @@ -222,7 +222,7 @@ impl BuildProfile {
pub fn debug_editor() -> Self {
BuildProfile {
name: "Debug Editor".to_string(),
build_commands: vec![BuildCommand {
build_commands: vec![CommandDescriptor {
command: "cargo".to_string(),
args: vec![
"build".to_string(),
Expand All @@ -231,7 +231,7 @@ impl BuildProfile {
],
environment_variables: vec![],
}],
run_command: BuildCommand {
run_command: CommandDescriptor {
command: "cargo".to_string(),
args: vec![
"run".to_string(),
Expand Down
Binary file added project-manager/resources/gear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 77 additions & 8 deletions project-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::settings::MANIFEST_PATH_VAR;
use crate::{
build::BuildWindow,
project::ProjectWizard,
settings::{Project, Settings},
settings::{Project, Settings, SettingsWindow},
upgrade::UpgradeTool,
utils::{self, is_production_ready, load_image, make_button},
};
Expand All @@ -47,14 +48,14 @@ use fyrox::{
stack_panel::StackPanelBuilder,
style::{resource::StyleResourceExt, Style},
text::{TextBuilder, TextMessage},
utils::make_simple_tooltip,
utils::{make_image_button_with_tooltip, make_simple_tooltip},
widget::{WidgetBuilder, WidgetMessage},
window::{WindowBuilder, WindowMessage, WindowTitle},
BuildContext, HorizontalAlignment, Orientation, Thickness, UiNode, UserInterface,
VerticalAlignment,
},
};
use fyrox_build_tools::{BuildCommand, BuildProfile};
use fyrox_build_tools::{BuildProfile, CommandDescriptor};
use std::{
collections::VecDeque,
path::{Path, PathBuf},
Expand All @@ -64,7 +65,7 @@ use std::{
enum Mode {
Normal,
Build {
queue: VecDeque<BuildCommand>,
queue: VecDeque<CommandDescriptor>,
process: Option<std::process::Child>,
current_dir: PathBuf,
},
Expand Down Expand Up @@ -94,7 +95,10 @@ pub struct ProjectManager {
deletion_confirmation_dialog: Handle<UiNode>,
upgrade: Handle<UiNode>,
locate: Handle<UiNode>,
open_settings: Handle<UiNode>,
open_ide: Handle<UiNode>,
upgrade_tool: Option<UpgradeTool>,
settings_window: Option<SettingsWindow>,
}

fn make_project_item(
Expand Down Expand Up @@ -294,9 +298,18 @@ impl ProjectManager {
.with_height(25.0),
)
.build(ctx);
let open_settings = make_image_button_with_tooltip(
ctx,
18.0,
18.0,
load_image(include_bytes!("../resources/gear.png")),
"Settings\nHotkey: Ctrl+S",
Some(7),
);
ctx[open_settings].set_column(3);

let message_count;
let open_log = ButtonBuilder::new(WidgetBuilder::new().on_column(3).with_visibility(false))
let open_log = ButtonBuilder::new(WidgetBuilder::new().on_column(4).with_visibility(false))
.with_content(
GridBuilder::new(
WidgetBuilder::new()
Expand Down Expand Up @@ -341,12 +354,14 @@ impl ProjectManager {
.with_child(create)
.with_child(import)
.with_child(search_bar)
.with_child(open_settings)
.with_child(open_log),
)
.add_column(Column::auto())
.add_column(Column::auto())
.add_column(Column::stretch())
.add_column(Column::auto())
.add_column(Column::auto())
.add_row(Row::auto())
.build(ctx);

Expand All @@ -362,13 +377,25 @@ impl ProjectManager {
experimental and unsafe nature of code hot reloading.\
\nHotkey: Ctrl+H";
let locate_tooltip = "Opens project folder in the default OS file manager.\
\nHotkey: Ctrl+O";
\nHotkey: Ctrl+L";
let open_ide_tooltip = "Opens project folder in the currently selected IDE \
(can be changed in settings).\nHotkey: Ctrl+O";

let edit = make_button("Edit", 130.0, 25.0, 5, 0, 0, Some(edit_tooltip), ctx);
let run = make_button("Run", 130.0, 25.0, 6, 0, 0, Some(run_tooltip), ctx);
let delete = make_button("Delete", 130.0, 25.0, 7, 0, 0, Some(delete_tooltip), ctx);
let upgrade = make_button("Upgrade", 130.0, 25.0, 8, 0, 0, Some(upgrade_tooltip), ctx);
let locate = make_button("Locate", 130.0, 25.0, 9, 0, 0, Some(locate_tooltip), ctx);
let open_ide = make_button(
"Open IDE",
130.0,
25.0,
9,
0,
0,
Some(open_ide_tooltip),
ctx,
);
let hot_reload = CheckBoxBuilder::new(
WidgetBuilder::new()
.with_tab_index(Some(4))
Expand All @@ -392,7 +419,8 @@ impl ProjectManager {
.with_child(run)
.with_child(delete)
.with_child(upgrade)
.with_child(locate),
.with_child(locate)
.with_child(open_ide),
)
.build(ctx);

Expand Down Expand Up @@ -468,7 +496,10 @@ impl ProjectManager {
deletion_confirmation_dialog: Default::default(),
upgrade,
locate,
open_settings,
open_ide,
upgrade_tool: None,
settings_window: None,
}
}

Expand Down Expand Up @@ -559,6 +590,8 @@ impl ProjectManager {
if let Some(build_window) = self.build_window.as_mut() {
build_window.update(ui);
}

self.settings.try_save();
}

fn try_import(&mut self, path: &Path, ui: &mut UserInterface) {
Expand Down Expand Up @@ -689,6 +722,10 @@ impl ProjectManager {
self.on_delete_clicked(ui);
} else if button == self.locate {
self.on_locate_click();
} else if button == self.open_ide {
self.on_open_ide_click();
} else if button == self.open_settings {
self.on_open_settings_click(ui);
}
}

Expand All @@ -698,6 +735,32 @@ impl ProjectManager {
Log::verify(open::that_detached(folder));
}

fn on_open_ide_click(&mut self) {
let project = some_or_return!(self.selection.and_then(|i| self.settings.projects.get(i)));
let mut open_ide_command = self.settings.open_ide_command.clone();
if let Some(manifest_path_arg) = open_ide_command
.args
.iter_mut()
.find(|cmd| cmd.as_str() == MANIFEST_PATH_VAR)
{
*manifest_path_arg = project.manifest_path.to_string_lossy().to_string();
} else {
Log::warn(format!("{} variable is not specified!", MANIFEST_PATH_VAR));
}
let mut command = open_ide_command.make_command();
if let Err(err) = command.spawn() {
Log::err(format!(
"Unable to open the IDE using {} command. Reason: {:?}",
open_ide_command, err
));
}
}

fn on_open_settings_click(&mut self, ui: &mut UserInterface) {
let ctx = &mut ui.build_ctx();
self.settings_window = Some(SettingsWindow::new(&self.settings, ctx));
}

fn run_build_profile(
&mut self,
name: &str,
Expand Down Expand Up @@ -740,7 +803,9 @@ impl ProjectManager {
KeyCode::KeyI if modifiers.control => self.on_import_clicked(ui),
KeyCode::KeyC if modifiers.control => self.on_create_clicked(ui),
KeyCode::KeyH if modifiers.control => self.on_hot_reload_changed(true, ui),
KeyCode::KeyO if modifiers.control => self.on_locate_click(),
KeyCode::KeyL if modifiers.control => self.on_locate_click(),
KeyCode::KeyO if modifiers.control => self.on_open_ide_click(),
KeyCode::KeyS if modifiers.control => self.on_open_settings_click(ui),
_ => (),
}
}
Expand All @@ -758,6 +823,10 @@ impl ProjectManager {
build_window.handle_ui_message(message, ui);
}

if let Some(settings_window) = self.settings_window.take() {
self.settings_window = settings_window.handle_ui_message(&mut self.settings, message);
}

if let Some(upgrade_tool) = self.upgrade_tool.take() {
if let Some(index) = self.selection {
if let Some(project) = self.settings.projects.get(index) {
Expand Down
Loading

0 comments on commit 4724d98

Please sign in to comment.