AvailableColumnsPanel.c 1.85 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1

2
#include "AvailableColumnsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
3
4
5
#include "Settings.h"
#include "Header.h"
#include "ScreenManager.h"
6
#include "ColumnsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
7

8
#include "Panel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
9
10
11
12
13
14

#include "debug.h"
#include <assert.h>

/*{

15
16
17
typedef struct AvailableColumnsPanel_ {
   Panel super;
   Panel* columns;
Hisham Muhammad's avatar
Hisham Muhammad committed
18
19
20

   Settings* settings;
   ScreenManager* scr;
21
} AvailableColumnsPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
22
23
24

}*/

25
static void AvailableColumnsPanel_delete(Object* object) {
26
27
28
   Panel* super = (Panel*) object;
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
29
30
31
   free(this);
}

32
static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
33
34
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
   char* text = ((ListItem*) Panel_getSelected(super))->value;
Hisham Muhammad's avatar
Hisham Muhammad committed
35
36
37
38
39
40
41
   HandlerResult result = IGNORED;

   switch(ch) {
      case 13:
      case KEY_ENTER:
      case KEY_F(5):
      {
42
         int at = Panel_getSelectedIndex(this->columns);
43
         Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
44
         Panel_setSelected(this->columns, at+1);
45
         ColumnsPanel_update(this->columns);
Hisham Muhammad's avatar
Hisham Muhammad committed
46
47
48
49
50
51
         result = HANDLED;
         break;
      }
   }
   return result;
}
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) malloc(sizeof(AvailableColumnsPanel));
   Panel* super = (Panel*) this;
   Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
   ((Object*)this)->delete = AvailableColumnsPanel_delete;
   
   this->settings = settings;
   this->scr = scr;
   super->eventHandler = AvailableColumnsPanel_eventHandler;

   Panel_setHeader(super, "Available Columns");

   for (int i = 1; i < LAST_PROCESSFIELD; i++) {
      if (i != COMM)
         Panel_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0));
   }
   this->columns = columns;
   return this;
}