Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Include Tree Style Tab structure when using "Copy to Clipboard". #185

Closed
Lej77 opened this issue Dec 15, 2017 · 7 comments
Labels

Comments

@Lej77
Copy link
Contributor

Lej77 commented Dec 15, 2017

Description

Currently I use a separate program to export my Tree Style Tab structure to text documents. I posted the code I use on TST Issue 1678. Anyways I think it would also be useful to include TST structure when copying tabs to the clipboard using this extension.


Example Solution

I think that tree structure should be presented as the number of TST ancestor tabs a tab has. An indent text could then be inserted before the text that many times. To allow for customization I think you should add a new placeholder for formatting. For example:
%TST(parameter1, parameter2)%
parameter1: indent text.
parameter2: last indent text. (Optional, same as parameter1 if not specified.)

Some "Copy to Clipboard" alternatives that could be used:

[TST] URI:
%TST(|    ,|--- )%%URL%

[TST] Title and URI:
%TST(|    )%%EOL%%TST(|    ,|--- )%%TITLE%%EOL%%TST(|    )%%URL%

[TST] HTML Link:
%TST(|&nbsp;&nbsp;&nbsp;&nbsp;,|---)%<a title="%TITLE_HTML%" href="%URL_HTML%">%TITLE_HTML%</a>

[TST] Markdown:
%TST(|    ,|--- )%[%TITLE%](%URL% "%TITLE%")                                     

Example results for solution

[TST] Title and URI:


Add-ons for Firefox
https://addons.mozilla.org/en-US/firefox/
|    
|--- All Tabs Helper – Add-ons for Firefox
|    https://addons.mozilla.org/en-US/firefox/addon/all-tabs-helper/
|    
|--- User Info for Piro (piro_or) :: Add-ons for Firefox
|    https://addons.mozilla.org/en-US/firefox/user/piro-piro_or/
|    |    
|    |--- Tree Style Tab – Add-ons for Firefox
|    |    https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab/
|    |    |    
|    |    |--- GitHub - piroor/treestyletab: Tree Style Tab, Show tabs like a tree.
|    |    |    https://github.com/piroor/treestyletab
|    |    |    |    
|    |    |    |--- Issues · piroor/treestyletab · GitHub
|    |    |    |    https://github.com/piroor/treestyletab/issues
|    |    |    |    
|    |    |    |--- Pull Requests · piroor/treestyletab · GitHub
|    |    |    |    https://github.com/piroor/treestyletab/pulls
|    |    |    |    
|    |    |    |--- Commits · piroor/treestyletab · GitHub
|    |    |    |    https://github.com/piroor/treestyletab/commits/master
|    |    |    |    
|    |    |    |--- TST-MiddleClick – Add-ons for Firefox
|    |    |    |    https://addons.mozilla.org/en-US/firefox/addon/tst-middleclick/
|    |    |    |    
|    |    |    |--- Tree Style Tab Mouse Wheel – Add-ons for Firefox
|    |    |    |    https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab-mouse-wheel/
|    |    |    |    |    
|    |    |    |    |--- Reviews for Tree Style Tab Mouse Wheel – Add-ons for Firefox
|    |    |    |    |    https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab-mouse-wheel/reviews/
|    |    |    |    
|    |    |    |--- Tree Style Tab Open in Private – Add-ons for Firefox
|    |    |    |    https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab-open-in-private/
|    |    |    |    
|    |    |    |--- Tree Style Tab Closed Tabs – Add-ons for Firefox
|    |    |    |    https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab-closed-tabs/
|    |    |    |    |    
|    |    |    |    |--- Reviews for Tree Style Tab Closed Tabs – Add-ons for Firefox
|    |    |    |    |    https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab-closed-tabs/reviews/
|    |    |    
|    |    |--- Reviews for Tree Style Tab – Add-ons for Firefox
|    |    |    https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab/reviews/
|    |    
|    |--- Multiple Tab Handler – Add-ons for Firefox
|    |    https://addons.mozilla.org/en-US/firefox/addon/multiple-tab-handler/?src=userprofile
|    |    |    
|    |    |--- GitHub - piroor/multipletab: Multiple Tab Handler, Provides feature to close multiple tabs.
|    |    |    https://github.com/piroor/multipletab
|    |    |    |    
|    |    |    |--- Issues · piroor/multipletab · GitHub
|    |    |    |    https://github.com/piroor/multipletab/issues
|    |    |    |    
|    |    |    |--- Pull Requests · piroor/multipletab · GitHub
|    |    |    |    https://github.com/piroor/multipletab/pulls
|    |    |    |    
|    |    |    |--- Commits · piroor/multipletab · GitHub
|    |    |    |    https://github.com/piroor/multipletab/commits/master
|    
|--- Tab Session Manager – Add-ons for Firefox
|    https://addons.mozilla.org/en-US/firefox/addon/tab-session-manager/

Firefox Nightly News – Let's improve quality, build after build!
https://blog.nightly.mozilla.org/
|    
|--- These Weeks in Firefox: Issue 29 – Firefox Nightly News
|    https://blog.nightly.mozilla.org/2017/12/05/these-weeks-in-firefox-issue-29/
|    |    
|    |--- Using the new theming API in Firefox – Mozilla Hacks – the Web developer blog
|    |    https://hacks.mozilla.org/2017/12/using-the-new-theming-api-in-firefox/
|    |    
|    |--- Roadmap Review: Sync and Storage
|    |    https://mozilla.github.io/firefox-browser-architecture/text/0008-sync-and-storage-review-packet.html

[TST] HTML Link:
Add-ons for Firefox
|---All Tabs Helper – Add-ons for Firefox
|---User Info for Piro (piro_or) :: Add-ons for Firefox
|    |---Tree Style Tab – Add-ons for Firefox
|    |    |---GitHub - piroor/treestyletab: Tree Style Tab, Show tabs like a tree.
|    |    |    |---Issues · piroor/treestyletab · GitHub
|    |    |    |---Pull Requests · piroor/treestyletab · GitHub
|    |    |    |---Commits · piroor/treestyletab · GitHub
|    |    |    |---TST-MiddleClick – Add-ons for Firefox
|    |    |    |---Tree Style Tab Mouse Wheel – Add-ons for Firefox
|    |    |    |    |---Reviews for Tree Style Tab Mouse Wheel – Add-ons for Firefox
|    |    |    |---Tree Style Tab Open in Private – Add-ons for Firefox
|    |    |    |---Tree Style Tab Closed Tabs – Add-ons for Firefox
|    |    |    |    |---Reviews for Tree Style Tab Closed Tabs – Add-ons for Firefox
|    |    |---Reviews for Tree Style Tab – Add-ons for Firefox
|    |---Multiple Tab Handler – Add-ons for Firefox
|    |    |---GitHub - piroor/multipletab: Multiple Tab Handler, Provides feature to close multiple tabs.
|    |    |    |---Issues · piroor/multipletab · GitHub
|    |    |    |---Pull Requests · piroor/multipletab · GitHub
|    |    |    |---Commits · piroor/multipletab · GitHub
|---Tab Session Manager – Add-ons for Firefox
Firefox Nightly News – Let's improve quality, build after build!
|---These Weeks in Firefox: Issue 29 – Firefox Nightly News
|    |---Using the new theming API in Firefox – Mozilla Hacks – the Web developer blog
|    |---Roadmap Review: Sync and Storage

To illustrate how I think ancestor counting should be done I made another example for the copied text but this time with only the last 10 of the tabs above selected:
[TST] HTML Link:
Multiple Tab Handler – Add-ons for Firefox
|---GitHub - piroor/multipletab: Multiple Tab Handler, Provides feature to close multiple tabs.
|    |---Issues · piroor/multipletab · GitHub
|    |---Pull Requests · piroor/multipletab · GitHub
|    |---Commits · piroor/multipletab · GitHub
Tab Session Manager – Add-ons for Firefox
Firefox Nightly News – Let's improve quality, build after build!
|---These Weeks in Firefox: Issue 29 – Firefox Nightly News
|    |---Using the new theming API in Firefox – Mozilla Hacks – the Web developer blog
|    |---Roadmap Review: Sync and Storage

Notice how relationships to tabs that weren't copied is ignored.
For example "Tab Session Manager – Add-ons for Firefox" is shown without parent tabs even though it actually has one.

@Lej77
Copy link
Contributor Author

Lej77 commented Jan 25, 2018

I wrote a function that will format a string in the way I specified above:

const kCOPY_TO_CLIPBOARD_TST_START = "%TST(";
const kCOPY_TO_CLIPBOARD_TST_SEPARATOR = ",";
const kCOPY_TO_CLIPBOARD_TST_END = ")%";

function formatTSTInfo(aFormat, ancestorCount) {
    if ((!ancestorCount && ancestorCount !== 0) || ancestorCount < 0 || !aFormat || aFormat.indexOf(kCOPY_TO_CLIPBOARD_TST_START) < 0)
        return aFormat;

    let formatted = "";
    while (true) {
        // Find next TST Entry:
        let startIndex = aFormat.indexOf(kCOPY_TO_CLIPBOARD_TST_START);
        let endIndex = aFormat.indexOf(kCOPY_TO_CLIPBOARD_TST_END);

        if (startIndex < 0 || endIndex < 0) {
            // No more TST Entries:
            formatted += aFormat;
            break;
        }


        // Find TST Separator:
        let separatorIndex = aFormat.indexOf(kCOPY_TO_CLIPBOARD_TST_SEPARATOR);

        if (separatorIndex > endIndex) {
            // Separator is after end -> ignore it.
            separatorIndex = -1;
        }

        // Find TST Arguments:
        let arg1 = aFormat.substring(startIndex + kCOPY_TO_CLIPBOARD_TST_START.length, separatorIndex < 0 ? endIndex : separatorIndex);
        let arg2 = null;
        if (separatorIndex >= 0) {
            arg2 = aFormat.substring(separatorIndex + 1, endIndex);
        }

        // Create TST Structure representation:
        let tstInfo = "";
        for (let i = 0; i < ancestorCount; i++) {
            if (i + 1 === ancestorCount && arg2) {
                tstInfo += arg2;
            } else {
                tstInfo += arg1;
            }
        }

        // Move Parse location to after TST Entry:
        formatted += aFormat.substr(0, startIndex) + tstInfo;
        aFormat = aFormat.substr(endIndex + kCOPY_TO_CLIPBOARD_TST_END.length)
    }
    return formatted;
}

You should probably apply this function before you do anything else to the format string since you don't want it to do anything if a tab should have the wrong title or something. Also you check that the string has both kCOPY_TO_CLIPBOARD_TST_START and kCOPY_TO_CLIPBOARD_TST_END before you calculate the ancestor count. If it doesn't you can just pass a negative ancestor count or null to skip the function.

Link to current formatting function

@piroor
Copy link
Owner

piroor commented Jan 31, 2018

Thanks to nice suggestion! Finally I've implemented similar placeholder based on your idea. You need to update the format you added like following:

  • %TST(| )% => %TST_INDENT(| )%
  • %TST(| ,|---)% => %TST_INDENT(| )(|---)%

The %TST_INDENT% placeholder accepts zero or more "indenter"s as parameters. You can specify parameters with parenthesis (...), blackets [...], braces {...}, or chevrons <...>. For example:

  • %TST_INDENT% => 2-spaces indent (default)
  • %TST_INDENT( )% => 2-spaces indent
  • %TST_INDENT( )% => 4-spaces indent
  • %TST_INDENT(%TAB%)% => tab indent
  • %TST_INDENT(| )(+---)% =>
    item
    +---item
    |   +---item
    |   |   +---item
    |   |   |   +---item
    

@piroor
Copy link
Owner

piroor commented Jan 31, 2018

Note that this feature depends on TST 2.4.8 (not released yet) and later, because this uses the new property indent of tabs. See also: https://github.com/piroor/treestyletab/wiki/API-for-other-addons#data-format

@Lej77
Copy link
Contributor Author

Lej77 commented Jan 31, 2018

@piroor Great! Looking forward to having this available!

@Lej77 Lej77 closed this as completed Jan 31, 2018
@Lej77
Copy link
Contributor Author

Lej77 commented Feb 7, 2018

@piroor I have been using this functionality a bit and so far its been really helpful.

I am using the following formatting rule:

[TST] HTML Link:
%TST_INDENT(|&nbsp;&nbsp;&nbsp;&nbsp;)(|---)%<a title="%TITLE_HTML%" href="%URL_HTML%">%TITLE_HTML%</a>

When I copy whole trees it works as I expect it to:
Extensions – Add-ons for Firefox
|---Tabs – Extensions – Add-ons for Firefox
|    |---Featured extensions – Add-ons for Firefox
|    |    |---Firefox Multi-Account Containers – Add-ons for Firefox
|    |    |---Print Edit WE – Add-ons for Firefox
|    |    |---FoxyTab – Add-ons for Firefox
|    |---Popular extensions – Add-ons for Firefox
|    |    |---Tree Style Tab – Add-ons for Firefox
|    |    |    |---GitHub - piroor/treestyletab: Tree Style Tab, Show tabs like a tree.
|    |    |    |    |---Issues · piroor/treestyletab · GitHub
|    |    |    |    |    |---Accept group tabs from another session · Issue #1762 · piroor/treestyletab · GitHub
|    |    |    |    |    |---[Feature Request] Bookmark and restore tree information · Issue #1756 · piroor/treestyletab · GitHub
|    |    |    |    |    |---[Feature Request] Configurable behavior for right click on the "New Tab" button · Issue #1751 · piroor/treestyletab · GitHub
|    |    |    |    |---Commits · piroor/treestyletab · GitHub
|    |    |---New Tab Override (WebExtension) – Add-ons for Firefox
|    |    |---Tab Session Manager – Add-ons for Firefox
|    |    |---Firefox Multi-Account Containers – Add-ons for Firefox
|---Appearance – Extensions – Add-ons for Firefox
|    |---Wikipedia Peek – Add-ons for Firefox
|    |---Easy Google Translate – Add-ons for Firefox

But if I copy part of a tree it sometimes shows indents to tabs that weren't copied:
|---GitHub - piroor/treestyletab: Tree Style Tab, Show tabs like a tree.
|    |---Issues · piroor/treestyletab · GitHub
|    |    |---Accept group tabs from another session · Issue #1762 · piroor/treestyletab · GitHub
|    |    |---[Feature Request] Bookmark and restore tree information · Issue #1756 · piroor/treestyletab · GitHub
|    |    |---[Feature Request] Configurable behavior for right click on the "New Tab" button · Issue #1751 · piroor/treestyletab · GitHub
|    |---Commits · piroor/treestyletab · GitHub
New Tab Override (WebExtension) – Add-ons for Firefox
Tab Session Manager – Add-ons for Firefox
Firefox Multi-Account Containers – Add-ons for Firefox

I think the current implementation is quite good but I think it would be better to not show relationships to tabs that weren't copied. Here is some example code for how I think the ancestor count should be computed:

let ancestorCount = ancestorTabs.filter(ancestorTab => selectedTabs.some(selectedTab => ancestorTab.id === selectedTab.id)).length;

where ancestorTabs is an array with tab ids for a specific tab's ancestor tabs and selectedTabs is an array with tab ids for all selected tabs.

Do you think the implementation should be changed or are you happy with the current implementation?

@piroor
Copy link
Owner

piroor commented Feb 7, 2018

Thanks, I realized that I forgot to think about partially selected tree nodes. By 9cdf2e1 now partial tree items are indented correctly.

@Lej77
Copy link
Contributor Author

Lej77 commented Feb 7, 2018

@piroor Thanks!

@Lej77 Lej77 closed this as completed Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants