Show file path in the tab when there are several files with the same name

360 views Asked by At

Please take a look at the screenshot:

enter image description here

As you can see there are 3 tabs with 3 different "index.xml" files opened. I've been looking for an option to show something like "folder/file.extension" in the tabs name to be able to differentiate the files, but I can't find anything.

Using "Go to file" is not very helpful either, because the name of the path for all the files is so long that I can't see the folder containing the files.

Any ideas?

Cheers

UPDATE:

It's possible to increase the 'Go to file' panel width using the mouse and Komodo will remember the size in the future. That helps!

3

There are 3 answers

0
Naatan On BEST ANSWER

We added the OpenFiles pane specifically for this purpose, please check out View > Tabs & Sidebars > Open Files.

This is what my pane looks like with several files with the same name open:

Open Files Pane

Additionally you can specify your own patterns, currently this is done programmatically via a macro but in the future you will be able to do this through the UI.

For example, I use the following macro for Komodo development:

ko.openfiles.groupers.byPattern.patterns = [
    {
        name:       'Plat - %match% - config',
        pattern:    /\/skin\/plat\/([a-z0-9_-]*)\/_config\//i
    },
    {
        name:       'Plat - %match%',
        pattern:    /\/skin\/plat\/([a-z0-9_-]*)\//i
    },
    {
        name:       'Module - %match% - skin config',
        pattern:    /\/(?:module|modules)\/([a-z0-9_-]*)\/skin\/_config\//i
    },
    {
        name:       'Module - %match%',
        pattern:    /\/(?:module|modules)\/([a-z0-9_-]*)\//i
    },
    {
        name:       'Skin - %match% - config',
        pattern:    /\/chrome\/skins\/([a-z0-9_-]*)\/_config\//i
    },
    {
        name:       'Skin - %match%',
        pattern:    /\/chrome\/skins\/([a-z0-9_-]*)\//i
    },
    {
        name:       'Iconset - %match%',
        pattern:    /\/chrome\/iconsets\/([a-z0-9_-]*)\//i
    },
    {
        name:       'Component - %match%',
        pattern:    /\/(?:component|components)\/([a-z0-9_-]*)/i
    },
    {
        name:       'Locale',
        pattern:    /\/locale(?:\/|$)/i
    },
    {
        name:       'Skin',
        pattern:    /\/skin(?:\/|$)/i
    },
    {
        name:       'Module',
        pattern:    /\/(?:module|modules)(?:\/|$)/i
    },
    {
        name:       'Component',
        pattern:    /\/(?:component|components)(?:\/|$)/i
    },
];

ko.openfiles.reload(true);

You can read up on macro's here: http://docs.activestate.com/komodo/8.5/macros.html#macros_writing

Using the above macro I need to make sure I have the "Group By Pattern" option selected, then I just run the macro and the same files you see in my above screenshot will be grouped according to the patterns I specified:

openfiles pane with patterns

Note that this requires the latest version of Komodo (8.5).

Also note that if you use the Open Files pane you may find that you do not need the regular tabs anymore, you can disable these under "View > View Editor Tabs".

Hope that helps, good luck!

0
Niki On

code updated for Komodo 8.5 (view.document -> view.koDoc)

komodo.assertMacroVersion(3);

try {
var vm = ko.views.manager.topView;
var box = document.getAnonymousNodes(vm)[0];

// get the views-tabbed elements
var tabset1 = box.firstChild;
var tabset2 = box.lastChild;

// replace the updateLeafName implementation to use something different
// for the tab label

tabset1.updateLeafName =
tabset2.updateLeafName = function(view) {
    view.parentNode._tab.label = view.title;
    if (view.koDoc) {
        var language = view.koDoc.language;
        if (language == 'Python') {
            var parts = view.koDoc.displayPath.split('/');
            var len = parts.length;
            var label = '';
            if (len > 2) {
                label += parts[len-2] + '/';
            }
            label += parts[len-1];

            view.parentNode._tab.setAttribute('crop', 'start');
            view.parentNode._tab.label = label;
            view.parentNode._tab.setAttribute('tooltiptext',view.koDoc.displayPath);
            this.tabbox.firstChild.scrollBoxObject.ensureElementIsVisible(this.tabbox.firstChild.selectedItem);
        }
    }
};

// the "on startup" trigger happens after files
// are opened, so we need to call updateLeafName
// for each opened view.  Files opened after startup
// will be fine
var views = ko.views.manager.topView.getViews(true);
for (var i=0; i < views.length; i++) {
    if (views[i].koDoc) {
        views[i].updateLeafName(views[i]);
    }
}

} catch(e) {
    alert(e);
}
0
Paul Sweatte On

Use the Komodo JavaScript API to change the default display of tab titles:

komodo.assertMacroVersion(3);

function changeTabTitles(useLongerTitle, splitLength) {
try {
    var vm = ko.views.manager.topView;
    var box = document.getAnonymousNodes(vm)[0];

    // Get the views-tabbed elements.
    var topTabs = box.firstChild;
    var bottomTabs = box.lastChild;

    if (!useLongerTitle) {
        // Restore the original functionality.
        if (topTabs._tweakui_updateLeafName) {
            topTabs.updateLeafName = topTabs._tweakui_updateLeafName;
            topTabs._tweakui_updateLeafName = null;
        }
        if (bottomTabs._tweakui_updateLeafName) {
            bottomTabs.updateLeafName = bottomTabs._tweakui_updateLeafName;
            bottomTabs._tweakui_updateLeafName = null;
        }

    } else {
        // Save the original functionality.
        if (!topTabs._tweakui_updateLeafName)
            topTabs._tweakui_updateLeafName = topTabs.updateLeafName;
        if (!bottomTabs._tweakui_updateLeafName)
            bottomTabs._tweakui_updateLeafName = bottomTabs.updateLeafName;

        // Replace the updateLeafName implementation to use something
        // different for the tab label.
        var osSvc = Components.classes["@activestate.com/koOs;1"].
                            getService(Components.interfaces.koIOs);
        var dirsep = osSvc.sep;
        topTabs.updateLeafName =
        bottomTabs.updateLeafName = function(view) {
            view.parentNode._tab.label = view.title;
            if (view.document) {
                view.parentNode._tab.setAttribute('crop', 'start');
                var path = view.document.displayPath;
                var sep = dirsep;
                if (path.lastIndexOf(sep) == -1) {
                    // Try using the URI separator.
                    sep = "/";
                }
                var path_split = path.split(sep);
                var l = path_split.length;
                var label = path_split.slice(l-splitLength, l).join(sep);
                view.parentNode._tab.label = label;
                view.parentNode._tab.setAttribute('tooltiptext',view.document.displayPath);
                this.tabbox.firstChild.scrollBoxObject.ensureElementIsVisible(this.tabbox.firstChild.selectedItem);
            }
        }
    }

Save it as a macro and customize it to your liking.