add command for closing windows

This commit is contained in:
Florian Stinglmayr 2019-07-22 16:30:10 +02:00
parent d2a2e5a392
commit 4d06f13b23
7 changed files with 34 additions and 10 deletions

View File

@ -101,6 +101,7 @@ guild names, or user names are all case sensitive.
| Command | Function | Arguments | Notes | | Command | Function | Arguments | Notes |
|----------------|-----------------------------------|-----------------------------------|-------| |----------------|-----------------------------------|-----------------------------------|-------|
| /ack | Mark channel as read | | WIP | | /ack | Mark channel as read | | WIP |
| /close | Close current channel view | | |
| /connect | Connect as the given account | account, as named in config | | | /connect | Connect as the given account | account, as named in config | |
| /friend | List all friends | | | | /friend | List all friends | | |
| /friend accept | Accept a friend request | full discord name, i.e. name#XXXX | | | /friend accept | Accept a friend request | full discord name, i.e. name#XXXX | |
@ -115,6 +116,7 @@ guild names, or user names are all case sensitive.
| /msg | Private message a friend | full discord name, i.e. name#XXXX | | | /msg | Private message a friend | full discord name, i.e. name#XXXX | |
| /post | Post a message to current channel | full message to post | | | /post | Post a message to current channel | full message to post | |
| /quit | Exit, and quit | | | | /quit | Exit, and quit | | |
| /wc | Alias for /close | | |
## Work In Progress ## Work In Progress
@ -123,7 +125,6 @@ are a few that would be nice to have:
* auto completion * auto completion
* man pages * man pages
* closing of chat windows
* notification handling if guilds are edited * notification handling if guilds are edited
* notification handling if friends send you a message * notification handling if friends send you a message
* /markread support * /markread support

View File

@ -17,6 +17,7 @@ SET(SOURCES
"src/ack.c" "src/ack.c"
"src/cmds.c" "src/cmds.c"
"src/config.c" "src/config.c"
"src/close.c"
"src/friends.c" "src/friends.c"
"src/input.c" "src/input.c"
"src/join.c" "src/join.c"

View File

@ -49,6 +49,7 @@ bool ncdc_dispatch(ncdc_mainwindow_t n, wchar_t const *s);
ncdc_commands_t *ncdc_find_cmd(ncdc_commands_t *cmds, wchar_t const *name); ncdc_commands_t *ncdc_find_cmd(ncdc_commands_t *cmds, wchar_t const *name);
bool ncdc_cmd_ack(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f); bool ncdc_cmd_ack(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f);
bool ncdc_cmd_close(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f);
bool ncdc_cmd_friends(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f); bool ncdc_cmd_friends(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f);
bool ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f); bool ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f);
bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f); bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f);

View File

@ -34,8 +34,8 @@ ncdc_mainwindow_t ncdc_mainwindow_new(void);
void ncdc_mainwindow_log(ncdc_mainwindow_t w, wchar_t const *fmt, ...); void ncdc_mainwindow_log(ncdc_mainwindow_t w, wchar_t const *fmt, ...);
GPtrArray *ncdc_mainwindow_views(ncdc_mainwindow_t n); GPtrArray *ncdc_mainwindow_views(ncdc_mainwindow_t n);
void ncdc_mainwindow_close_view(ncdc_mainwindow_t n, int i);
dc_channel_t ncdc_mainwindow_current_channel(ncdc_mainwindow_t n); dc_channel_t ncdc_mainwindow_current_channel(ncdc_mainwindow_t n);
//void ncdc_mainwindow_switchview(ncdc_mainwindow_t n, int idx);
void ncdc_mainwindow_switch_view(ncdc_mainwindow_t n, ncdc_textview_t v); void ncdc_mainwindow_switch_view(ncdc_mainwindow_t n, ncdc_textview_t v);
ncdc_textview_t ncdc_mainwindow_channel_view(ncdc_mainwindow_t n, ncdc_textview_t ncdc_mainwindow_channel_view(ncdc_mainwindow_t n,
dc_channel_t c); dc_channel_t c);

9
ncdc/src/close.c Normal file
View File

@ -0,0 +1,9 @@
#include <ncdc/cmds.h>
#include <ncdc/ncdc.h>
bool ncdc_cmd_close(ncdc_mainwindow_t n, size_t ac, wchar_t **av,
wchar_t const *f)
{
ncdc_mainwindow_close_view(n, -1);
return true;
}

View File

@ -2,6 +2,7 @@
ncdc_commands_t cmds[] = { ncdc_commands_t cmds[] = {
{ L"/ack", ncdc_cmd_ack }, { L"/ack", ncdc_cmd_ack },
{ L"/close", ncdc_cmd_close },
{ L"/connect", ncdc_cmd_login }, { L"/connect", ncdc_cmd_login },
{ L"/friend", ncdc_cmd_friends }, { L"/friend", ncdc_cmd_friends },
{ L"/friends", ncdc_cmd_friends }, { L"/friends", ncdc_cmd_friends },
@ -12,6 +13,7 @@ ncdc_commands_t cmds[] = {
{ L"/msg", ncdc_cmd_msg }, { L"/msg", ncdc_cmd_msg },
{ L"/post", ncdc_cmd_post }, { L"/post", ncdc_cmd_post },
{ L"/quit", ncdc_cmd_quit }, { L"/quit", ncdc_cmd_quit },
{ L"/wc", ncdc_cmd_close },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -450,14 +450,6 @@ GPtrArray *ncdc_mainwindow_views(ncdc_mainwindow_t n)
return n->views; return n->views;
} }
void ncdc_mainwindow_switchview(ncdc_mainwindow_t n, int idx)
{
return_if_true(n == NULL || n->views == NULL,);
return_if_true(idx >= n->views->len,);
n->curview = idx;
}
void ncdc_mainwindow_switch_view(ncdc_mainwindow_t n, ncdc_textview_t v) void ncdc_mainwindow_switch_view(ncdc_mainwindow_t n, ncdc_textview_t v)
{ {
return_if_true(n == NULL || n->views == NULL || v == NULL,); return_if_true(n == NULL || n->views == NULL || v == NULL,);
@ -508,6 +500,24 @@ void ncdc_mainwindow_log(ncdc_mainwindow_t w, wchar_t const *fmt, ...)
ncdc_textview_append(w->log, buf); ncdc_textview_append(w->log, buf);
} }
void ncdc_mainwindow_close_view(ncdc_mainwindow_t n, int idx)
{
if (idx < 0) {
idx = n->curview;
}
return_if_true(idx < 0,);
/* don't close status view
*/
if (idx == 0) {
return;
}
n->curview = idx - 1;
g_ptr_array_remove_index(n->views, idx);
}
ncdc_textview_t ncdc_textview_t
ncdc_mainwindow_switch_or_add(ncdc_mainwindow_t n, dc_channel_t c) ncdc_mainwindow_switch_or_add(ncdc_mainwindow_t n, dc_channel_t c)
{ {