1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

HackStudio: Start working on an IDE for SerenityOS

This will be fun. :^)
This commit is contained in:
Andreas Kling 2019-10-21 18:46:55 +02:00
parent 74bba649c3
commit 0311e8d50a
6 changed files with 157 additions and 0 deletions

View file

@ -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

View file

@ -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)));
}

View file

@ -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;
};

View file

@ -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();
}