AvailableColumnsPanel.c 1.86 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
26
27
28
29
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;
Hisham Muhammad's avatar
Hisham Muhammad committed
30
31
32
   
   this->settings = settings;
   this->scr = scr;
33
   super->eventHandler = AvailableColumnsPanel_eventHandler;
Hisham Muhammad's avatar
Hisham Muhammad committed
34

35
   Panel_setHeader(super, "Available Columns");
Hisham Muhammad's avatar
Hisham Muhammad committed
36
37
38

   for (int i = 1; i < LAST_PROCESSFIELD; i++) {
      if (i != COMM)
39
         Panel_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0));
Hisham Muhammad's avatar
Hisham Muhammad committed
40
41
42
43
44
   }
   this->columns = columns;
   return this;
}

45
46
47
48
void AvailableColumnsPanel_delete(Object* object) {
   Panel* super = (Panel*) object;
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
49
50
51
   free(this);
}

52
53
54
HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
   char* text = ((ListItem*) Panel_getSelected(super))->value;
Hisham Muhammad's avatar
Hisham Muhammad committed
55
56
57
58
59
60
61
   HandlerResult result = IGNORED;

   switch(ch) {
      case 13:
      case KEY_ENTER:
      case KEY_F(5):
      {
62
63
         int at = Panel_getSelectedIndex(this->columns) + 1;
         if (at == Panel_getSize(this->columns))
Hisham Muhammad's avatar
Hisham Muhammad committed
64
            at--;
65
66
         Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
         ColumnsPanel_update(this->columns);
Hisham Muhammad's avatar
Hisham Muhammad committed
67
68
69
70
71
72
         result = HANDLED;
         break;
      }
   }
   return result;
}