Quellcode durchsuchen

HackStudio: Start working on an IDE for SerenityOS

This will be fun. :^)
Andreas Kling vor 5 Jahren
Ursprung
Commit
0311e8d50a

+ 23 - 0
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
+

+ 48 - 0
DevTools/HackStudio/Project.cpp

@@ -0,0 +1,48 @@
+#include "Project.h"
+#include <LibCore/CFile.h>
+
+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<String>&& files)
+    : m_files(move(files))
+{
+    m_model = adopt(*new ProjectModel(*this));
+}
+
+OwnPtr<Project> Project::load_from_file(const String& path)
+{
+    auto file = CFile::construct(path);
+    if (!file->open(CFile::ReadOnly))
+        return nullptr;
+
+    Vector<String> 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)));
+}

+ 21 - 0
DevTools/HackStudio/Project.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include <AK/Noncopyable.h>
+#include <AK/OwnPtr.h>
+#include <LibGUI/GModel.h>
+
+class Project {
+    AK_MAKE_NONCOPYABLE(Project)
+    AK_MAKE_NONMOVABLE(Project)
+public:
+    static OwnPtr<Project> load_from_file(const String& path);
+
+    GModel& model() { return *m_model; }
+
+private:
+    friend class ProjectModel;
+    explicit Project(Vector<String>&& files);
+
+    RefPtr<GModel> m_model;
+    Vector<String> m_files;
+};

+ 62 - 0
DevTools/HackStudio/main.cpp

@@ -0,0 +1,62 @@
+#include "Project.h"
+#include <LibCore/CFile.h>
+#include <LibGUI/GApplication.h>
+#include <LibGUI/GBoxLayout.h>
+#include <LibGUI/GListView.h>
+#include <LibGUI/GMessageBox.h>
+#include <LibGUI/GSplitter.h>
+#include <LibGUI/GStatusBar.h>
+#include <LibGUI/GTextEditor.h>
+#include <LibGUI/GToolBar.h>
+#include <LibGUI/GWidget.h>
+#include <LibGUI/GWindow.h>
+#include <stdio.h>
+#include <unistd.h>
+
+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<GBoxLayout>(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();
+}

+ 2 - 0
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/

+ 1 - 0
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"