summaryrefslogtreecommitdiffstats
path: root/SidebarManager.cpp
blob: 86e70d044fd6646c14894a0e371eb8b2681ddb25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "SidebarManager.h"


SidebarManager::SidebarManager(EditManager *editor)
 : sidebarView(editor), sidebarAdd(editor)
{
  this->editor = editor;
  activeSidebar = NULL;
  
  sidebar = gtk_scrolled_window_new(NULL, NULL);
  g_object_ref_sink(G_OBJECT(sidebar));
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sidebar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  
  viewport = gtk_viewport_new(NULL, NULL);
  gtk_container_add(GTK_CONTAINER(sidebar), viewport);
  gtk_viewport_set_shadow_type(GTK_VIEWPORT(viewport), GTK_SHADOW_NONE);
  
  gtk_widget_show(sidebar);
}

SidebarManager::~SidebarManager() {
  g_object_unref(G_OBJECT(sidebar));
}

void SidebarManager::update() {
  Sidebar *newSidebar = activeSidebar;
  
  switch(editor->getMode()) {
    case EditManager::VIEW:
      newSidebar = &sidebarView;
      break;
    case EditManager::ADD:
      newSidebar = &sidebarAdd;
  }
  
  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;
  }
  
  activeSidebar->update();
}