komodo tab macro to ease django development
One annoyance I came across while using komodo for django development was the barrage of ‘models.py’ and ‘views.py’ in editor tab titles.
I looked into what writing this macro would mean by going through the open komodo source only to arrive to the conclusion that it wasn’t possible. I started this thread on the activestate community forums: tab title restriction hurts Komodo’s usability for Django projects. Shane Caraveo came to the rescue and thankfully proved me wrong by posting a macro that sets tab titles. Here’s what I see now:

This macro is a slight extension of his work. My version only shows the immediate parent directory and the current filename, not the entire path. And I only modify the tab title for python files.
Even though some aspects of the api need further documentation this is a testament to Komodo’s extensibility. While I like Komodo, I do think it could use better textmate-like snippet insertion (auto-completion of snippet names would be a good start).
Caveat: I’m guessing this doesn’t work on windows because of the slash.
Add an on startup trigger for it.
http://dpaste.com/hold/47625/
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.document) {
var language = view.document.language;
if (language == 'Python') {
var parts = view.document.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.document.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].document) {
views[i].updateLeafName(views[i]);
}
}
} catch(e) {
alert(e);
}
1 Comment
comments rss | trackback uri