diff --git a/DevTools/HackStudio/Makefile b/DevTools/HackStudio/Makefile new file mode 100644 index 0000000000..d23b1d60a6 --- /dev/null +++ b/DevTools/HackStudio/Makefile @@ -0,0 +1,23 @@ +include ../../Makefile.common + +OBJS = \ + Project.o \ + main.o + +APP = HackStudio + +DEFINES += -DUSERLAND + +all: $(APP) + +$(APP): $(OBJS) + $(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -ldraw -lcore -lc + +.cpp.o: + @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< + +-include $(OBJS:%.o=%.d) + +clean: + @echo "CLEAN"; rm -f $(APP) $(OBJS) *.d + diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp new file mode 100644 index 0000000000..d1a4da35d1 --- /dev/null +++ b/DevTools/HackStudio/Project.cpp @@ -0,0 +1,48 @@ +#include "Project.h" +#include + +class ProjectModel final : public GModel { +public: + explicit ProjectModel(Project& project) + : m_project(project) + { + } + + virtual int row_count(const GModelIndex& = GModelIndex()) const override { return m_project.m_files.size(); } + virtual int column_count(const GModelIndex& = GModelIndex()) const override { return 1; } + virtual GVariant data(const GModelIndex& index, Role role = Role::Display) const override + { + int row = index.row(); + if (role == Role::Display) { + return m_project.m_files.at(row); + } + return {}; + } + virtual void update() override {} + +private: + Project& m_project; +}; + +Project::Project(Vector&& files) + : m_files(move(files)) +{ + m_model = adopt(*new ProjectModel(*this)); +} + +OwnPtr Project::load_from_file(const String& path) +{ + auto file = CFile::construct(path); + if (!file->open(CFile::ReadOnly)) + return nullptr; + + Vector files; + for (;;) { + auto line = file->read_line(1024); + if (line.is_null()) + break; + files.append(String::copy(line, Chomp)); + } + + return OwnPtr(new Project(move(files))); +} diff --git a/DevTools/HackStudio/Project.h b/DevTools/HackStudio/Project.h new file mode 100644 index 0000000000..3acc043e18 --- /dev/null +++ b/DevTools/HackStudio/Project.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +class Project { + AK_MAKE_NONCOPYABLE(Project) + AK_MAKE_NONMOVABLE(Project) +public: + static OwnPtr load_from_file(const String& path); + + GModel& model() { return *m_model; } + +private: + friend class ProjectModel; + explicit Project(Vector&& files); + + RefPtr m_model; + Vector m_files; +}; diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp new file mode 100644 index 0000000000..1deacd2aec --- /dev/null +++ b/DevTools/HackStudio/main.cpp @@ -0,0 +1,62 @@ +#include "Project.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + GApplication app(argc, argv); + + auto window = GWindow::construct(); + window->set_rect(100, 100, 800, 600); + window->set_title("HackStudio"); + + auto widget = GWidget::construct(); + window->set_main_widget(widget); + + widget->set_fill_with_background_color(true); + widget->set_layout(make(Orientation::Vertical)); + widget->layout()->set_spacing(0); + + if (chdir("/home/anon/serenity") < 0) { + perror("chdir"); + return 1; + } + auto project = Project::load_from_file("serenity.files"); + ASSERT(project); + + auto toolbar = GToolBar::construct(widget); + + auto splitter = GSplitter::construct(Orientation::Horizontal, widget); + auto project_list_view = GListView::construct(splitter); + project_list_view->set_model(project->model()); + project_list_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); + project_list_view->set_preferred_size(200, 0); + + auto text_editor = GTextEditor::construct(GTextEditor::MultiLine, splitter); + + project_list_view->on_activation = [&](auto& index) { + auto filename = project_list_view->model()->data(index).to_string(); + auto file = CFile::construct(filename); + if (!file->open(CFile::ReadOnly)) { + GMessageBox::show("Could not open!", "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window); + return; + } + text_editor->set_text(file->read_all()); + }; + + auto statusbar = GStatusBar::construct(widget); + + window->show(); + return app.exec(); +} diff --git a/Kernel/build-root-filesystem.sh b/Kernel/build-root-filesystem.sh index 6f28ca1115..c05867e1cd 100755 --- a/Kernel/build-root-filesystem.sh +++ b/Kernel/build-root-filesystem.sh @@ -96,6 +96,7 @@ cp ../Demos/HelloWorld2/HelloWorld2 mnt/bin/HelloWorld2 cp ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch cp ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery cp ../Demos/Fire/Fire mnt/bin/Fire +cp ../DevTools/HackStudio/HackStudio mnt/bin/HackStudio cp ../DevTools/VisualBuilder/VisualBuilder mnt/bin/VisualBuilder cp ../DevTools/Inspector/Inspector mnt/bin/Inspector cp ../Games/Minesweeper/Minesweeper mnt/bin/Minesweeper @@ -133,6 +134,7 @@ ln -s Inspector mnt/bin/ins ln -s SoundPlayer mnt/bin/sp ln -s Help mnt/bin/help ln -s Browser mnt/bin/br +ln -s HackStudio mnt/bin/hs echo "done" mkdir -p mnt/boot/ diff --git a/Kernel/makeall.sh b/Kernel/makeall.sh index b86a6de048..43ebc365d8 100755 --- a/Kernel/makeall.sh +++ b/Kernel/makeall.sh @@ -69,6 +69,7 @@ build_targets="$build_targets ../Demos/HelloWorld2" build_targets="$build_targets ../Demos/RetroFetch" build_targets="$build_targets ../Demos/WidgetGallery" +build_targets="$build_targets ../DevTools/HackStudio" build_targets="$build_targets ../DevTools/VisualBuilder" build_targets="$build_targets ../DevTools/Inspector"