Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
2df1f61d
Commit
2df1f61d
authored
Jan 28, 2018
by
Hisham Muhammad
Browse files
Screens: Fix "New Screen" option
parent
e6c98b6e
Changes
4
Show whitespace changes
Inline
Side-by-side
ScreensPanel.c
View file @
2df1f61d
...
...
@@ -53,9 +53,9 @@ ObjectClass ScreenListItem_class = {
.
compare
=
ListItem_compare
};
ScreenListItem
*
ScreenListItem_new
(
const
char
*
value
,
int
key
,
ScreenSettings
*
ss
)
{
ScreenListItem
*
ScreenListItem_new
(
const
char
*
value
,
ScreenSettings
*
ss
)
{
ScreenListItem
*
this
=
AllocThis
(
ScreenListItem
);
ListItem_init
((
ListItem
*
)
this
,
value
,
key
);
ListItem_init
((
ListItem
*
)
this
,
value
,
0
);
this
->
ss
=
ss
;
return
this
;
}
...
...
@@ -150,6 +150,17 @@ static void rebuildSettingsArray(Panel* super) {
}
}
static
void
addNewScreen
(
Panel
*
super
)
{
ScreensPanel
*
const
this
=
(
ScreensPanel
*
)
super
;
char
*
name
=
"New"
;
ScreenSettings
*
ss
=
Settings_newScreen
(
this
->
settings
,
name
,
"PID Command"
);
ScreenListItem
*
item
=
ScreenListItem_new
(
name
,
ss
);
int
idx
=
Panel_getSelectedIndex
(
super
);
Panel_insert
(
super
,
idx
+
1
,
(
Object
*
)
item
);
Panel_setSelected
(
super
,
idx
+
1
);
}
static
HandlerResult
ScreensPanel_eventHandlerNormal
(
Panel
*
super
,
int
ch
)
{
ScreensPanel
*
const
this
=
(
ScreensPanel
*
)
super
;
...
...
@@ -190,10 +201,7 @@ static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
case
KEY_F
(
5
):
case
KEY_CTRL
(
'N'
):
{
ListItem
*
item
=
ListItem_new
(
""
,
0
);
int
idx
=
Panel_getSelectedIndex
(
super
);
Panel_insert
(
super
,
idx
+
1
,
(
Object
*
)
item
);
Panel_setSelected
(
super
,
idx
+
1
);
addNewScreen
(
super
);
startRenaming
(
super
);
shouldRebuildArray
=
true
;
result
=
HANDLED
;
...
...
@@ -300,7 +308,7 @@ ScreensPanel* ScreensPanel_new(Settings* settings) {
for
(
unsigned
int
i
=
0
;
i
<
settings
->
nScreens
;
i
++
)
{
ScreenSettings
*
ss
=
settings
->
screens
[
i
];
char
*
name
=
ss
->
name
;
Panel_add
(
super
,
(
Object
*
)
ScreenListItem_new
(
name
,
i
,
ss
));
Panel_add
(
super
,
(
Object
*
)
ScreenListItem_new
(
name
,
ss
));
}
return
this
;
}
...
...
ScreensPanel.h
View file @
2df1f61d
...
...
@@ -40,7 +40,7 @@ typedef struct ScreenListItem_ {
extern
ObjectClass
ScreenListItem_class
;
ScreenListItem
*
ScreenListItem_new
(
const
char
*
value
,
int
key
,
ScreenSettings
*
ss
);
ScreenListItem
*
ScreenListItem_new
(
const
char
*
value
,
ScreenSettings
*
ss
);
extern
PanelClass
ScreensPanel_class
;
...
...
Settings.c
View file @
2df1f61d
...
...
@@ -246,7 +246,7 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
String_freeArray
(
ids
);
}
static
void
Settings_
read
Screen
(
Settings
*
this
,
const
char
*
name
,
const
char
*
line
)
{
ScreenSettings
*
Settings_
new
Screen
(
Settings
*
this
,
const
char
*
name
,
const
char
*
line
)
{
ScreenSettings
*
ss
=
xCalloc
(
sizeof
(
ScreenSettings
),
1
);
ss
->
name
=
xStrdup
(
name
);
ss
->
fields
=
xCalloc
(
Platform_numberOfFields
+
1
,
sizeof
(
ProcessField
));
...
...
@@ -258,11 +258,12 @@ static void Settings_readScreen(Settings* this, const char* name, const char* li
this
->
nScreens
++
;
this
->
screens
=
xRealloc
(
this
->
screens
,
sizeof
(
ScreenSettings
*
)
*
(
this
->
nScreens
+
1
));
this
->
screens
[
this
->
nScreens
]
=
NULL
;
return
ss
;
}
static
void
Settings_defaultScreens
(
Settings
*
this
)
{
Settings_
read
Screen
(
this
,
"Default"
,
"PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command"
);
Settings_
read
Screen
(
this
,
"I/O"
,
"PID IO_PRIORITY USER IO_READ_RATE IO_WRITE_RATE Command"
);
Settings_
new
Screen
(
this
,
"Default"
,
"PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command"
);
Settings_
new
Screen
(
this
,
"I/O"
,
"PID IO_PRIORITY USER IO_READ_RATE IO_WRITE_RATE Command"
);
}
static
bool
Settings_read
(
Settings
*
this
,
const
char
*
fileName
)
{
...
...
@@ -343,7 +344,7 @@ static bool Settings_read(Settings* this, const char* fileName) {
Settings_readMeterModes
(
this
,
option
[
1
],
1
);
didReadMeters
=
true
;
}
else
if
(
strncmp
(
option
[
0
],
"screen:"
,
7
)
==
0
)
{
Settings_
read
Screen
(
this
,
option
[
0
]
+
7
,
option
[
1
]);
Settings_
new
Screen
(
this
,
option
[
0
]
+
7
,
option
[
1
]);
}
else
if
(
String_eq
(
option
[
0
],
".tree_view"
))
{
if
(
this
->
nScreens
>
0
)
{
this
->
screens
[
this
->
nScreens
-
1
]
->
treeView
=
atoi
(
option
[
1
]);
...
...
Settings.h
View file @
2df1f61d
...
...
@@ -74,6 +74,8 @@ typedef struct Settings_ {
void
Settings_delete
(
Settings
*
this
);
ScreenSettings
*
Settings_newScreen
(
Settings
*
this
,
const
char
*
name
,
const
char
*
line
);
bool
Settings_write
(
Settings
*
this
);
Settings
*
Settings_new
(
int
cpuCount
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment