#include "SidebarManager.h" #include "Window.h" SidebarManager::SidebarManager(Window *window) : sidebarToolbox(window), toolAddPolygon(&window->getEditManager()) { this->window = window; activeSidebar = NULL; sidebar = gtk_vbox_new(FALSE, 0); g_object_ref_sink(G_OBJECT(sidebar)); gtk_box_pack_start(GTK_BOX(sidebar), sidebarToolbox.getWidget(), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(sidebar), gtk_hseparator_new(), FALSE, FALSE, 5); toolLabel = gtk_label_new(sidebarToolbox.getActiveTool().getName()); gtk_box_pack_start(GTK_BOX(sidebar), toolLabel, FALSE, FALSE, 0); scrolledWindow = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_box_pack_start_defaults(GTK_BOX(sidebar), scrolledWindow); gtk_widget_show(scrolledWindow); viewport = gtk_viewport_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(scrolledWindow), viewport); sidebarToolbox.addTool(&toolAddPolygon); gtk_widget_show(sidebar); } SidebarManager::~SidebarManager() { g_object_unref(G_OBJECT(sidebar)); } void SidebarManager::update() { Sidebar *newSidebar = activeSidebar; newSidebar = window->getActiveTool()->getSidebar(); if(activeSidebar != newSidebar) { if(activeSidebar) gtk_container_remove(GTK_CONTAINER(viewport), gtk_bin_get_child(GTK_BIN(viewport))); gtk_container_add(GTK_CONTAINER(viewport), newSidebar->getWidget()); activeSidebar = newSidebar; } gtk_label_set_text(GTK_LABEL(toolLabel), sidebarToolbox.getActiveTool().getName()); sidebarToolbox.update(); activeSidebar->update(); }