diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-09 23:03:34 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-09 23:03:34 +0300 |
commit | cfcd6bd672829edfbb325e3d264570c034ccc0f1 (patch) | |
tree | d899e48469aa3a48a75e4ef8a31874608d61809a /src/app.c | |
parent | a5407bb3026da0972be19dfc89bb59dac6d5ee0c (diff) |
Closing and duplicating tabs
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -396,20 +396,47 @@ iBool handleCommand_App(const char *cmd) { | |||
396 | iWidget *tabs = findWidget_App("doctabs"); | 396 | iWidget *tabs = findWidget_App("doctabs"); |
397 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); | 397 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); |
398 | removeChild_Widget(newTabButton->parent, newTabButton); | 398 | removeChild_Widget(newTabButton->parent, newTabButton); |
399 | iDocumentWidget *newDoc = new_DocumentWidget(); | 399 | iDocumentWidget *newDoc; |
400 | const iBool isDuplicate = (argLabel_Command(cmd, "duplicate") != 0); | ||
401 | if (isDuplicate) { | ||
402 | newDoc = duplicate_DocumentWidget(document_App()); | ||
403 | } | ||
404 | else { | ||
405 | newDoc = new_DocumentWidget(); | ||
406 | } | ||
400 | setId_Widget(as_Widget(newDoc), format_CStr("document%03d", tabCount_Widget(tabs))); | 407 | setId_Widget(as_Widget(newDoc), format_CStr("document%03d", tabCount_Widget(tabs))); |
401 | appendTabPage_Widget(tabs, iClob(newDoc), "", 0, 0); | 408 | appendTabPage_Widget(tabs, iClob(newDoc), "", 0, 0); |
402 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); | 409 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); |
403 | postCommandf_App("tabs.switch page:%p", newDoc); | 410 | postCommandf_App("tabs.switch page:%p", newDoc); |
404 | postCommand_App("navigate.home"); | 411 | if (!isDuplicate) { |
412 | postCommand_App("navigate.home"); | ||
413 | } | ||
405 | arrange_Widget(tabs); | 414 | arrange_Widget(tabs); |
406 | refresh_Widget(tabs); | 415 | refresh_Widget(tabs); |
407 | return iTrue; | 416 | return iTrue; |
408 | } | 417 | } |
409 | else if (equal_Command(cmd, "tabs.close")) { | 418 | else if (equal_Command(cmd, "tabs.close")) { |
410 | iWidget *tabs = findWidget_App("doctabs"); | 419 | iWidget *tabs = findWidget_App("doctabs"); |
420 | size_t index = tabPageIndex_Widget(tabs, document_App()); | ||
421 | iBool wasClosed = iFalse; | ||
422 | if (argLabel_Command(cmd, "toright")) { | ||
423 | while (tabCount_Widget(tabs) > index + 1) { | ||
424 | destroy_Widget(removeTabPage_Widget(tabs, index + 1)); | ||
425 | } | ||
426 | wasClosed = iTrue; | ||
427 | } | ||
428 | if (argLabel_Command(cmd, "toleft")) { | ||
429 | while (index-- > 0) { | ||
430 | destroy_Widget(removeTabPage_Widget(tabs, 0)); | ||
431 | } | ||
432 | postCommandf_App("tabs.switch page:%p", tabPage_Widget(tabs, 0)); | ||
433 | wasClosed = iTrue; | ||
434 | } | ||
435 | if (wasClosed) { | ||
436 | arrange_Widget(tabs); | ||
437 | return iTrue; | ||
438 | } | ||
411 | if (tabCount_Widget(tabs) > 1) { | 439 | if (tabCount_Widget(tabs) > 1) { |
412 | size_t index = tabPageIndex_Widget(tabs, document_App()); | ||
413 | iWidget *closed = removeTabPage_Widget(tabs, index); | 440 | iWidget *closed = removeTabPage_Widget(tabs, index); |
414 | destroy_Widget(closed); /* released later */ | 441 | destroy_Widget(closed); /* released later */ |
415 | if (index == tabCount_Widget(tabs)) { | 442 | if (index == tabCount_Widget(tabs)) { |