jEdit Community - Resources for users of the jEdit Text Editor
How to clear only invalid entries in Recent Files
Submitted by tvojeho on Wednesday, 22 October, 2008 - 18:26
Hi all,

I was wondering if there was a way for a macro to go through the items in Recent files list and delete invalid entries, leaving the rest. My Java know-how is not very extensive, and after some googling and searching the default macros code, I have put together a few lines of code which luckily do not throw an exception, but unfortunately do not apply the desired changes to Recent Files menu.

I would be grateful for any help.

  Cheers, tvojeho.

  

BufferHistory.Entry[] recentBuffersArray = BufferHistory.getHistory().toArray(new BufferHistory.Entry[0]); // get history

for(i=0;i {

recentPath = recentBuffersArray[i].path;

if( ! new File(recentPath).exists())

{

BufferHistory.Entry removeEntry(recentPath);

}

}

return;

Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Sorry for the previous code,
by tvojeho on Wed, 22/10/2008 - 18:32
Sorry for the previous code, it was scrambled somehow.

BufferHistory.Entry[] recentBuffersArray = BufferHistory.getHistory().toArray(new BufferHistory.Entry[0]); // get history
for(i=0;i<recentBuffersArray.length;++i)
{
recentPath = recentBuffersArray[i].path;
if( ! new File(recentPath).exists())
{
BufferHistory.Entry removeEntry(recentPath);
}
}
return;

 
Try this: [code] import j
by elberry on Thu, 23/10/2008 - 16:45
Try this:
[code]

import java.util.List;
List entries = BufferHistory.getHistory();
for(BufferHistory.Entry entry : entries) {
   if(!new File(entry.path).exists()) {
      BufferHistory.removeEntry(entry.path);
   }
}

[/code]

That should work for you though I'm not quite sure why.

removeEntry is marked as private, so it shouldn't be accessible this way. I guess beanshell follows a bit different rules.

Regardless, hope that helps. Smiling

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
setAccessibility()
by Robert Schwenn on Thu, 23/10/2008 - 20:16
The reason is discussed in this thread in the mailing list .

For short: Actually the startup macro getGraphicsEnvironment.bsh is the reason, that Capabilities.setAccessibility() is invoked at jEdit startup. After this call beanshell has access to private routines.


Robert
 
Thank you, elberry, your c
by tvojeho on Thu, 23/10/2008 - 17:34
Thank you, elberry,

your code works great. I put it in my startup script, and it cleans the recent items nicely.

tvojeho
User login
Browse archives
« April 2024  
MoTuWeThFrSaSu
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
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82348
Context Free Art (*.cfdg)   0.31   46055
JBuilder scheme   .001   18495
BBEdit scheme   1.0   18116
ColdFusion scheme   1.0   18024
R Edit Mode - extensive version   0.1   17473
Advanced HTML edit mode   1.0   16206
Matlab Edit Mode   1.0   16068
jEdit XP icons   1.0   15229
XP icons for jEdit   1.1   14293