From 4d06f13b2384def805af9a769e9f3604a5ee5be4 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Mon, 22 Jul 2019 16:30:10 +0200 Subject: [PATCH] add command for closing windows --- README.md | 3 ++- ncdc/CMakeLists.txt | 1 + ncdc/include/ncdc/cmds.h | 1 + ncdc/include/ncdc/mainwindow.h | 2 +- ncdc/src/close.c | 9 +++++++++ ncdc/src/cmds.c | 2 ++ ncdc/src/mainwindow.c | 26 ++++++++++++++++++-------- 7 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 ncdc/src/close.c diff --git a/README.md b/README.md index 81c927d..e468512 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ guild names, or user names are all case sensitive. | Command | Function | Arguments | Notes | |----------------|-----------------------------------|-----------------------------------|-------| | /ack | Mark channel as read | | WIP | +| /close | Close current channel view | | | | /connect | Connect as the given account | account, as named in config | | | /friend | List all friends | | | | /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 | | | /post | Post a message to current channel | full message to post | | | /quit | Exit, and quit | | | +| /wc | Alias for /close | | | ## Work In Progress @@ -123,7 +125,6 @@ are a few that would be nice to have: * auto completion * man pages -* closing of chat windows * notification handling if guilds are edited * notification handling if friends send you a message * /markread support diff --git a/ncdc/CMakeLists.txt b/ncdc/CMakeLists.txt index d8c7e37..4574a26 100644 --- a/ncdc/CMakeLists.txt +++ b/ncdc/CMakeLists.txt @@ -17,6 +17,7 @@ SET(SOURCES "src/ack.c" "src/cmds.c" "src/config.c" + "src/close.c" "src/friends.c" "src/input.c" "src/join.c" diff --git a/ncdc/include/ncdc/cmds.h b/ncdc/include/ncdc/cmds.h index 6c73597..94de276 100644 --- a/ncdc/include/ncdc/cmds.h +++ b/ncdc/include/ncdc/cmds.h @@ -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); 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_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); diff --git a/ncdc/include/ncdc/mainwindow.h b/ncdc/include/ncdc/mainwindow.h index de32b8e..41a0b5d 100644 --- a/ncdc/include/ncdc/mainwindow.h +++ b/ncdc/include/ncdc/mainwindow.h @@ -34,8 +34,8 @@ ncdc_mainwindow_t ncdc_mainwindow_new(void); void ncdc_mainwindow_log(ncdc_mainwindow_t w, wchar_t const *fmt, ...); 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); -//void ncdc_mainwindow_switchview(ncdc_mainwindow_t n, int idx); void ncdc_mainwindow_switch_view(ncdc_mainwindow_t n, ncdc_textview_t v); ncdc_textview_t ncdc_mainwindow_channel_view(ncdc_mainwindow_t n, dc_channel_t c); diff --git a/ncdc/src/close.c b/ncdc/src/close.c new file mode 100644 index 0000000..8330131 --- /dev/null +++ b/ncdc/src/close.c @@ -0,0 +1,9 @@ +#include +#include + +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; +} diff --git a/ncdc/src/cmds.c b/ncdc/src/cmds.c index 66cc69b..8439b6b 100644 --- a/ncdc/src/cmds.c +++ b/ncdc/src/cmds.c @@ -2,6 +2,7 @@ ncdc_commands_t cmds[] = { { L"/ack", ncdc_cmd_ack }, + { L"/close", ncdc_cmd_close }, { L"/connect", ncdc_cmd_login }, { L"/friend", ncdc_cmd_friends }, { L"/friends", ncdc_cmd_friends }, @@ -12,6 +13,7 @@ ncdc_commands_t cmds[] = { { L"/msg", ncdc_cmd_msg }, { L"/post", ncdc_cmd_post }, { L"/quit", ncdc_cmd_quit }, + { L"/wc", ncdc_cmd_close }, { NULL, NULL } }; diff --git a/ncdc/src/mainwindow.c b/ncdc/src/mainwindow.c index 41f43aa..e6260d3 100644 --- a/ncdc/src/mainwindow.c +++ b/ncdc/src/mainwindow.c @@ -450,14 +450,6 @@ GPtrArray *ncdc_mainwindow_views(ncdc_mainwindow_t n) 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) { 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); } +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_mainwindow_switch_or_add(ncdc_mainwindow_t n, dc_channel_t c) {