Welcome, guest | Sign In | My Account | Store | Cart

Gets the Find Results Manager for the "Find Results 1" tab, if it exists. If the tab has rows in it, then copies out all the data from each row and adds it to an output buffer. Creates a new editor view (or optionally reuses the existing one) and appends the output buffer to it. Note: Be sure to see Bruno's update below, until I get it merged in. ;)

JavaScript, 109 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
/*******************************************************************************************************************
**      GetFindResults Macro
**      Purpose: Collect all current "Find (in Files)" results in Find Results tab 1
**                      into new (or reused) window for subsequent processing.
**      Author: Dave Wald
**      Date:   April, 2012
**      Notes:  Make sure there is a current Find Results window with lines of text in it,
**                      or it will just tell you it can't find anything to process.
**                      It only gets the "Find Results 1" pane now, but could easily be copied to do "Find Results 2" as well.
** 
*******************************************************************************************************************/
(function(){
  var columns;
  var curView;
  var newDocView;
  var targetView;
  var targetViewScimoz;
  var newText;
  var rowcnt = 0;
  var tab;
  var treeWidget;
  var viewMan = ko.views.manager;
  var findresMan = ko.findresults.getManager(1);
          //e.g. if exist "Find Results 1" tab, then parm is '1'
  var messages = get_messages();
  var FindResultsOutputBuffer = [];
  var reuseOutputView = true;
  //  Set this to false to send output to a new view each time.
  //      If you are reusing the view, don't save it to disk or the
  //      viewMan.getUntitledView("Find Results") function won't be able to find it. 
  //  If you are finished searching for a while, or just really want to save
  //      that particular view to disk,   go ahead. It will then just create a new one,
  //      and then start reusing the new one as long as it remains unsaved.
  
  try {
    curView = findresMan.view;
    treeWidget = findresMan.doc.getElementById("findresults");
    columns = treeWidget.columns;
    rowcnt = curView.rowCount;
    if (rowcnt === 0) {
      throw new Error("rowcnt is 0");
    }
  }
  catch(ex){
    error_notify(ex);
    return false;
  }
  if (reuseOutputView){
    targetView = viewMan.getUntitledView("Find Results");
  } else {
    targetView = null;
  }
  if (targetView == null){
    targetView = viewMan._doNewView(null, null);
    targetView.koDoc.baseName = "Find Results";
    tab = targetView.parentNode._tab;
    tab.label = tab.tooltipText = "Find Results";
  }
  for (var i = 0; i < rowcnt; i++){ //see Treeview.js for usage
    FindResultsOutputBuffer.push (curView.getCellText(i, columns[0]) + " | "
                                + curView.getCellText(i, columns[1]) + " | "
                                + curView.getCellText(i, columns[2]) ) ;        
  }
  targetViewScimoz = targetView.scimoz;
  targetViewScimoz.selectAll();
  targetViewScimoz.clear();
  targetViewScimoz.addText(84, "************************** Find Results *******************************************\n");
  newText = FindResultsOutputBuffer.join('\n')
  targetViewScimoz.addText(newText.length, newText);
  
  return true;

  //support functions
  function get_messages () {
    var msgs = {
        m0:"Unknown error.",
        m1:"Could not get Find Results Manager. Make sure you have a Find Results tab in one of the panes.",
        m2:"Could not get results view.",
        m3:"Could not find any results. Make sure your Find Results tab has rows in it.",
        m4:"Could not find any columns with data. Make sure your Find Results tab has rows and columns with data in it.",
        m5:"Could not find any result rows. Make sure your Find Results tab has at least one row with data in it."
        }
    return msgs;
  }
  function error_notify(ex){
    var title = "Get Find Results";
    var messages = get_messages();
    var message = messages.m0;
    if (!findresMan) {
      message = messages.m1;  
    }
    else if (!curView){
      message = messages.m2;
    }
    else if (!treeWidget){
      message = messages.m3;
    }
    else if (!(columns) || columns.count === 0){
      message = messages.m4;  
    }
    else if (!(rowcnt) || rowcnt < 1){
      message = messages.m5;
    }
    else {
      message = ex.message;
    }
    new ko.dialogs.alert(message, null, title);
  }
})();

The "Find Results" view in the bottom tabs pane is apparently dead as a rock. You cannot select more than one row, and cannot copy the data to the clipboard. Amazing. But I need to be able to get the results out into a new window for subsequent processing. So, another weekend shot to hell, thanks. (Yes, I know I could have done this easily in Notepad++ and PythonScript). But it was actually kinda fun, so ...

Enjoy!

9 comments

Jeroen Verbeek 12 years ago  # | flag

Hi Dave,

It works perfect! Thank you for spending your weekend on it :). I have question. The Find Results window is opened in a new tab each time. How to change the script that it opens in the same tab, rather than building a long list of tabs? (now I have to close the window every time, and Komodo is asking to save yes or no) Hope you have a solution. Thx in advance,

Kind regards, Jeroen

Dave Wald (author) 12 years ago  # | flag

Jeroen,

Thanks and glad you're getting some use out of it. Good point about the window proliferation. I suppose I could put in a "reuseView" switch or such that you could set to True, wouldn't be anything fancy. Then you could run two versions of it if necessary. I've got a new clean-up revision I need to post anyway, so I'll play around with it and see what I can come up with. (May be a few days...)

Best regards, Dave

Dave Wald (author) 12 years ago  # | flag

OK, Jer, this is your lucky day. Give this a shot. I think you'll like it. ;-)

Jeroen Verbeek 12 years ago  # | flag

Hi Dave,

Sorry for my late reply. We had a long weekend in the Netherlands because of Queensday. And you are right, it's indeed my lucky day! I tested your new script, and it works AWESOME! Thank you so much,

Kind regards, Jeroen

Sarah Eagle 9 years, 11 months ago  # | flag

Brilliant, thanks very much :)

Dave Wald (author) 9 years, 11 months ago  # | flag

Sarah, Thank you. And you're welcome. ;) Glad you're getting some use out of it.

Dave

Bruno Guillemette 9 years, 10 months ago  # | flag

Hi Dave, great script !

I noticed that the copied results are sometimes truncated before the end. I guess it's a limitation on the size of a string (newText, in this case) which appears when there are a lot of results

To circumvent the problem, I've adapted your script to copy each Find entry separately to the output view.

The lines below replaces lines 59-69 from the script above:

targetViewScimoz = targetView.scimoz;
targetViewScimoz.selectAll();
targetViewScimoz.clear();
targetViewScimoz.addText(84, "************************** Find Results   *******************************************\n");
for (var i = 0; i < rowcnt; i++){ //see Treeview.js for usage
  newText = (curView.getCellText(i, columns[0]) + " | "
           + curView.getCellText(i, columns[1]) + " | "
           + curView.getCellText(i, columns[2]) + "\n") ;
  targetViewScimoz.addText(newText.length, newText);
}

Hope this will help someone. :-D

Dave Wald (author) 9 years, 10 months ago  # | flag

Bruno, Thanks!

Yes, that makes sense. Good thing you found that.

Thanks much!

Dave

Bruno Guillemette 9 years, 9 months ago  # | flag

Oops... :-)

Turns out, I fixed the wrong problem with my previous comment.

My original truncated output problem was actually caused by my source code being in UTF-8 (with accented characters). The JavaScript length method doesn't work properly on these strings.

I finally noticed it because my previous changes caused some results rows to be merged in the output, the newline character being chopped off by the incorrect string length.

So, I found this JavaScript function which returns the actual byte length of a string. Using this instead of the length method (byteCount(newText) instead of newText.length) works like a charm !

// from http://stackoverflow.com/a/12205668/854760
function byteCount(s) {
  return encodeURI(s).split(/%..|./).length - 1;
}

Since my source code (and potential search results) are in UTF-8, I probably should set the targetView's encoding to UTF-8 instead of the default CP1252, but it is not obvious how to do that in code.

Created by Dave Wald on Tue, 10 Apr 2012 (MIT)
JavaScript recipes (69)
Dave Wald's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks