diff --git a/DevTools/Profiler/CMakeLists.txt b/DevTools/Profiler/CMakeLists.txt index ba6c22ab9e..9e224d3ae4 100644 --- a/DevTools/Profiler/CMakeLists.txt +++ b/DevTools/Profiler/CMakeLists.txt @@ -1,11 +1,9 @@ set(SOURCES DisassemblyModel.cpp main.cpp - ProcessChooser.cpp Profile.cpp ProfileModel.cpp ProfileTimelineWidget.cpp - RunningProcessesModel.cpp ) serenity_bin(Profiler) diff --git a/DevTools/Profiler/main.cpp b/DevTools/Profiler/main.cpp index a04a0d50f4..1478f6d592 100644 --- a/DevTools/Profiler/main.cpp +++ b/DevTools/Profiler/main.cpp @@ -24,13 +24,13 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "ProcessChooser.h" #include "Profile.h" #include "ProfileTimelineWidget.h" #include #include #include #include +#include #include #include #include @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ int main(int argc, char** argv) args_parser.parse(argc, argv, false); auto app = GUI::Application::construct(argc, argv); + auto app_icon = GUI::Icon::default_icon("app-profiler"); const char* path = nullptr; if (argc != 2) { @@ -79,6 +81,7 @@ int main(int argc, char** argv) auto window = GUI::Window::construct(); window->set_title("Profiler"); window->set_rect(100, 100, 800, 600); + window->set_icon(app_icon.bitmap_for_size(16)); auto& main_widget = window->set_main_widget(); main_widget.set_fill_with_background_color(true); @@ -118,6 +121,11 @@ int main(int argc, char** argv) percent_action->set_checked(false); view_menu.add_action(percent_action); + auto& help_menu = menubar->add_menu("Help"); + help_menu.add_action(GUI::Action::create("About", [&](auto&) { + GUI::AboutDialog::show("Profiler", app_icon.bitmap_for_size(32), window); + })); + app->set_menubar(move(menubar)); window->show(); @@ -128,6 +136,7 @@ bool prompt_to_stop_profiling() { auto window = GUI::Window::construct(); window->set_title("Profiling"); + window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-profiler.png")); Gfx::IntRect window_rect { 0, 0, 320, 200 }; window_rect.center_within(GUI::Desktop::the().rect()); window->set_rect(window_rect); @@ -154,7 +163,7 @@ bool prompt_to_stop_profiling() bool generate_profile(pid_t pid) { if (!pid) { - auto process_chooser = Profiler::ProcessChooser::construct(); + auto process_chooser = GUI::ProcessChooser::construct("Profiler", "Profile", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-profiler.png")); if (process_chooser->exec() == GUI::Dialog::ExecCancel) return false; pid = process_chooser->pid(); diff --git a/Libraries/LibGUI/CMakeLists.txt b/Libraries/LibGUI/CMakeLists.txt index fd32ff4b44..88ab51cffe 100644 --- a/Libraries/LibGUI/CMakeLists.txt +++ b/Libraries/LibGUI/CMakeLists.txt @@ -51,9 +51,11 @@ set(SOURCES MultiView.cpp Notification.cpp Painter.cpp + ProcessChooser.cpp ProgressBar.cpp RadioButton.cpp ResizeCorner.cpp + RunningProcessesModel.cpp ScrollableWidget.cpp ScrollBar.cpp Shortcut.cpp diff --git a/DevTools/Profiler/ProcessChooser.cpp b/Libraries/LibGUI/ProcessChooser.cpp similarity index 67% rename from DevTools/Profiler/ProcessChooser.cpp rename to Libraries/LibGUI/ProcessChooser.cpp index 4070b09f2b..0d2cdb2a55 100644 --- a/DevTools/Profiler/ProcessChooser.cpp +++ b/Libraries/LibGUI/ProcessChooser.cpp @@ -24,46 +24,58 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "ProcessChooser.h" -#include "RunningProcessesModel.h" #include #include #include #include +#include +#include #include #include -namespace Profiler { +namespace GUI { -ProcessChooser::ProcessChooser(GUI::Window* parent_window) +ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& button_label, const Gfx::Bitmap* window_icon, GUI::Window* parent_window) : Dialog(parent_window) + , m_window_title(window_title) + , m_button_label(button_label) + , m_window_icon(window_icon) { - build(); -} + set_title(m_window_title); -void ProcessChooser::build() -{ - set_title("Profiler"); - Gfx::IntRect window_rect { 0, 0, 480, 360 }; + if (m_window_icon) + set_icon(m_window_icon); + else if (parent_window) + set_icon(parent_window->icon()); + + Gfx::IntRect window_rect { 0, 0, 300, 340 }; window_rect.center_within(GUI::Desktop::the().rect()); set_rect(window_rect); auto& widget = set_main_widget(); widget.set_fill_with_background_color(true); widget.set_layout(); + widget.layout()->set_margins({ 0, 0, 0, 2 }); + auto& table_view = widget.add(); - auto sorting_model = GUI::SortingProxyModel::create(Profiler::RunningProcessesModel::create()); + auto sorting_model = GUI::SortingProxyModel::create(RunningProcessesModel::create()); sorting_model->set_sort_role(GUI::Model::Role::Display); - sorting_model->set_key_column_and_sort_order(Profiler::RunningProcessesModel::Column::PID, GUI::SortOrder::Descending); + sorting_model->set_key_column_and_sort_order(RunningProcessesModel::Column::PID, GUI::SortOrder::Descending); table_view.set_model(sorting_model); + auto& button_container = widget.add(); button_container.set_preferred_size(0, 30); button_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); button_container.set_layout(); - auto& profile_button = button_container.add("Profile"); - profile_button.on_click = [&](auto) { + button_container.layout()->set_margins({ 0, 0, 4, 0 }); + button_container.layout()->add_spacer(); + + auto& select_button = button_container.add(m_button_label); + select_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); + select_button.set_preferred_size(80, 24); + select_button.on_click = [&](auto) { if (table_view.selection().is_empty()) { - GUI::MessageBox::show(this, "No process selected!", "Profiler", GUI::MessageBox::Type::Error); + GUI::MessageBox::show(this, "No process selected!", m_window_title, GUI::MessageBox::Type::Error); return; } auto index = table_view.selection().first(); @@ -72,6 +84,8 @@ void ProcessChooser::build() done(ExecOK); }; auto& cancel_button = button_container.add("Cancel"); + cancel_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); + cancel_button.set_preferred_size(80, 24); cancel_button.on_click = [this](auto) { done(ExecCancel); }; @@ -79,4 +93,8 @@ void ProcessChooser::build() table_view.model()->update(); } +ProcessChooser::~ProcessChooser() +{ +} + } diff --git a/DevTools/Profiler/ProcessChooser.h b/Libraries/LibGUI/ProcessChooser.h similarity index 82% rename from DevTools/Profiler/ProcessChooser.h rename to Libraries/LibGUI/ProcessChooser.h index eb5e722db2..6b16f4b2ba 100644 --- a/DevTools/Profiler/ProcessChooser.h +++ b/Libraries/LibGUI/ProcessChooser.h @@ -28,20 +28,24 @@ #include -namespace Profiler { +namespace GUI { class ProcessChooser final : public GUI::Dialog { C_OBJECT(ProcessChooser); public: + virtual ~ProcessChooser() override; + pid_t pid() const { return m_pid; } private: - ProcessChooser(GUI::Window* parent_window = nullptr); - - void build(); + ProcessChooser(const StringView& window_title = "Process Chooser", const StringView& button_label = "Select", const Gfx::Bitmap* window_icon = nullptr, GUI::Window* parent_window = nullptr); pid_t m_pid { 0 }; + + String m_window_title; + String m_button_label; + RefPtr m_window_icon; }; } diff --git a/DevTools/Profiler/RunningProcessesModel.cpp b/Libraries/LibGUI/RunningProcessesModel.cpp similarity index 98% rename from DevTools/Profiler/RunningProcessesModel.cpp rename to Libraries/LibGUI/RunningProcessesModel.cpp index 45d08ea850..8d3b2090d4 100644 --- a/DevTools/Profiler/RunningProcessesModel.cpp +++ b/Libraries/LibGUI/RunningProcessesModel.cpp @@ -24,11 +24,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "RunningProcessesModel.h" #include #include +#include -namespace Profiler { +namespace GUI { NonnullRefPtr RunningProcessesModel::create() { diff --git a/DevTools/Profiler/RunningProcessesModel.h b/Libraries/LibGUI/RunningProcessesModel.h similarity index 99% rename from DevTools/Profiler/RunningProcessesModel.h rename to Libraries/LibGUI/RunningProcessesModel.h index 3984fab3eb..ae29cea6f2 100644 --- a/DevTools/Profiler/RunningProcessesModel.h +++ b/Libraries/LibGUI/RunningProcessesModel.h @@ -29,7 +29,7 @@ #include #include -namespace Profiler { +namespace GUI { class RunningProcessesModel final : public GUI::Model { public: