diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-14 21:38:00 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-14 21:38:08 +0300 |
commit | 639c0dd31d299aaffadbb093a48eaed45e62f81b (patch) | |
tree | 8f220435ad6ce9ca3d165032f0860220bdac8923 /src/ui/sidebarwidget.c | |
parent | f60baccbe3e04769e9bab66625a4f3923a01f191 (diff) |
Added sidebar shortcuts; more View menu items
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r-- | src/ui/sidebarwidget.c | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 78227cf3..7729ccca 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include "labelwidget.h" | 2 | #include "labelwidget.h" |
3 | #include "scrollwidget.h" | 3 | #include "scrollwidget.h" |
4 | #include "documentwidget.h" | 4 | #include "documentwidget.h" |
5 | #include "inputwidget.h" | ||
5 | #include "bookmarks.h" | 6 | #include "bookmarks.h" |
6 | #include "paint.h" | 7 | #include "paint.h" |
7 | #include "util.h" | 8 | #include "util.h" |
@@ -10,6 +11,7 @@ | |||
10 | #include "app.h" | 11 | #include "app.h" |
11 | 12 | ||
12 | #include <the_Foundation/array.h> | 13 | #include <the_Foundation/array.h> |
14 | #include <SDL_clipboard.h> | ||
13 | #include <SDL_mouse.h> | 15 | #include <SDL_mouse.h> |
14 | 16 | ||
15 | iDeclareType(SidebarItem) | 17 | iDeclareType(SidebarItem) |
@@ -132,7 +134,12 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { | |||
132 | pushBack_Array(&d->items, &item); | 134 | pushBack_Array(&d->items, &item); |
133 | } | 135 | } |
134 | d->menu = makeMenu_Widget( | 136 | d->menu = makeMenu_Widget( |
135 | as_Widget(d), (iMenuItem[]){ { "Delete Bookmark", 0, 0, "bookmark.delete" } }, 1); | 137 | as_Widget(d), |
138 | (iMenuItem[]){ { "Edit Bookmark...", 0, 0, "bookmark.edit" }, | ||
139 | { "Copy URL", 0, 0, "bookmark.copy" }, | ||
140 | { "---", 0, 0, NULL }, | ||
141 | { orange_ColorEscape "Delete Bookmark", 0, 0, "bookmark.delete" } }, | ||
142 | 4); | ||
136 | break; | 143 | break; |
137 | } | 144 | } |
138 | case history_SidebarMode: | 145 | case history_SidebarMode: |
@@ -150,7 +157,7 @@ void setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) { | |||
150 | for (enum iSidebarMode i = 0; i < max_SidebarMode; i++) { | 157 | for (enum iSidebarMode i = 0; i < max_SidebarMode; i++) { |
151 | setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode); | 158 | setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode); |
152 | } | 159 | } |
153 | const float heights[max_SidebarMode] = { 1.2f, 2, 3, 3 }; | 160 | const float heights[max_SidebarMode] = { 1.2f, 2.4f, 3, 3 }; |
154 | d->itemHeight = heights[mode] * lineHeight_Text(default_FontId); | 161 | d->itemHeight = heights[mode] * lineHeight_Text(default_FontId); |
155 | } | 162 | } |
156 | 163 | ||
@@ -286,6 +293,13 @@ static void checkModeButtonLayout_SidebarWidget_(iSidebarWidget *d) { | |||
286 | } | 293 | } |
287 | } | 294 | } |
288 | 295 | ||
296 | static iSidebarItem *hoverItem_SidebarWidget_(iSidebarWidget *d) { | ||
297 | if (d->hoverItem < size_Array(&d->items)) { | ||
298 | return at_Array(&d->items, d->hoverItem); | ||
299 | } | ||
300 | return NULL; | ||
301 | } | ||
302 | |||
289 | void setWidth_SidebarWidget(iSidebarWidget *d, int width) { | 303 | void setWidth_SidebarWidget(iSidebarWidget *d, int width) { |
290 | iWidget *w = as_Widget(d); | 304 | iWidget *w = as_Widget(d); |
291 | width = iMax(30 * gap_UI, width); | 305 | width = iMax(30 * gap_UI, width); |
@@ -301,6 +315,16 @@ void setWidth_SidebarWidget(iSidebarWidget *d, int width) { | |||
301 | } | 315 | } |
302 | } | 316 | } |
303 | 317 | ||
318 | iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *cmd) { | ||
319 | iSidebarWidget *d = findWidget_App("sidebar"); | ||
320 | if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) { | ||
321 | setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse); | ||
322 | destroy_Widget(editor); | ||
323 | return iTrue; | ||
324 | } | ||
325 | return iFalse; | ||
326 | } | ||
327 | |||
304 | static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) { | 328 | static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) { |
305 | iWidget *w = as_Widget(d); | 329 | iWidget *w = as_Widget(d); |
306 | /* Handle commands. */ | 330 | /* Handle commands. */ |
@@ -341,6 +365,9 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
341 | else if (equal_Command(cmd, "sidebar.mode")) { | 365 | else if (equal_Command(cmd, "sidebar.mode")) { |
342 | setMode_SidebarWidget(d, arg_Command(cmd)); | 366 | setMode_SidebarWidget(d, arg_Command(cmd)); |
343 | updateItems_SidebarWidget_(d); | 367 | updateItems_SidebarWidget_(d); |
368 | if (argLabel_Command(cmd, "show") && !isVisible_Widget(w)) { | ||
369 | postCommand_App("sidebar.toggle"); | ||
370 | } | ||
344 | return iTrue; | 371 | return iTrue; |
345 | } | 372 | } |
346 | else if (equal_Command(cmd, "sidebar.toggle")) { | 373 | else if (equal_Command(cmd, "sidebar.toggle")) { |
@@ -363,12 +390,29 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
363 | d->scrollY = 0; | 390 | d->scrollY = 0; |
364 | updateItems_SidebarWidget_(d); | 391 | updateItems_SidebarWidget_(d); |
365 | } | 392 | } |
393 | else if (equal_Command(cmd, "bookmark.copy")) { | ||
394 | const iSidebarItem *item = hoverItem_SidebarWidget_(d); | ||
395 | if (d->mode == bookmarks_SidebarMode && item) { | ||
396 | SDL_SetClipboardText(cstr_String(&item->url)); | ||
397 | } | ||
398 | return iTrue; | ||
399 | } | ||
400 | else if (equal_Command(cmd, "bookmark.edit")) { | ||
401 | const iSidebarItem *item = hoverItem_SidebarWidget_(d); | ||
402 | if (d->mode == bookmarks_SidebarMode && item) { | ||
403 | setFlags_Widget(w, disabled_WidgetFlag, iTrue); | ||
404 | iWidget *dlg = makeBookmarkEditor_Widget(); | ||
405 | setText_InputWidget(findChild_Widget(dlg, "bmed.title"), &item->label); | ||
406 | setText_InputWidget(findChild_Widget(dlg, "bmed.url"), &item->url); | ||
407 | //setText_InputWidget(findChild_Widget(dlg, "bmed.tags"), &item->) | ||
408 | setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_); | ||
409 | } | ||
410 | return iTrue; | ||
411 | } | ||
366 | else if (equal_Command(cmd, "bookmark.delete")) { | 412 | else if (equal_Command(cmd, "bookmark.delete")) { |
367 | if (d->mode == bookmarks_SidebarMode && d->hoverItem < size_Array(&d->items)) { | 413 | const iSidebarItem *item = hoverItem_SidebarWidget_(d); |
368 | const iSidebarItem *item = at_Array(&d->items, d->hoverItem); | 414 | if (d->mode == bookmarks_SidebarMode && item && remove_Bookmarks(bookmarks_App(), item->id)) { |
369 | if (remove_Bookmarks(bookmarks_App(), item->id)) { | 415 | postCommand_App("bookmarks.changed"); |
370 | postCommand_App("bookmarks.changed"); | ||
371 | } | ||
372 | } | 416 | } |
373 | return iTrue; | 417 | return iTrue; |
374 | } | 418 | } |
@@ -405,7 +449,9 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
405 | return iTrue; | 449 | return iTrue; |
406 | } | 450 | } |
407 | if (d->menu && ev->type == SDL_MOUSEBUTTONDOWN) { | 451 | if (d->menu && ev->type == SDL_MOUSEBUTTONDOWN) { |
408 | processContextMenuEvent_Widget(d->menu, ev, {}); | 452 | if (d->hoverItem != iInvalidPos || isVisible_Widget(d->menu)) { |
453 | processContextMenuEvent_Widget(d->menu, ev, {}); | ||
454 | } | ||
409 | } | 455 | } |
410 | switch (processEvent_Click(&d->click, ev)) { | 456 | switch (processEvent_Click(&d->click, ev)) { |
411 | case started_ClickResult: | 457 | case started_ClickResult: |
@@ -463,7 +509,7 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) { | |||
463 | "%s", | 509 | "%s", |
464 | cstr_String(&str)); | 510 | cstr_String(&str)); |
465 | deinit_String(&str); | 511 | deinit_String(&str); |
466 | iInt2 textPos = topRight_Rect(iconArea); | 512 | iInt2 textPos = addY_I2(topRight_Rect(iconArea), 0.2f * lineHeight_Text(font)); |
467 | drawRange_Text(font, textPos, fg, range_String(&item->label)); | 513 | drawRange_Text(font, textPos, fg, range_String(&item->label)); |
468 | drawRange_Text(font, | 514 | drawRange_Text(font, |
469 | addY_I2(textPos, lineHeight_Text(font)), | 515 | addY_I2(textPos, lineHeight_Text(font)), |