Document modification

Post a reply

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: Document modification

Re: Document modification

Post by robert » Tue Aug 21, 2012 4:12 am

No problem. Since there are legitimate uses for it, I went ahead and made setDirty() public, but modified its doc comment to explain that most applications won't have to call it directly.

Re: Document modification

Post by omadawn » Sun Aug 19, 2012 8:43 pm

And thanks

Re: Document modification

Post by omadawn » Sun Aug 19, 2012 8:43 pm

That was excactly why I needed it. I'm getting the source code I will be editing in a list of a custom object type. It's actually pretty inefficient in my case to get each piece of code separately.

I didn't quite understand FileLocation so I was creating the TextEditorPane empty and using setText() to set the editor text.

I have since then realized that using FileLocation was the only way to get it to work so I monkeyed around with that and have mostly figured it out. I have a separate forum thread for an issue that I'm running in to when a save fails.

This functionality would have let me do it without FileLocation.

Re: Document modification

Post by robert » Sat Aug 18, 2012 2:54 pm

The method will be public in SVN later today, and in the next release. I'm including information in the doc comment stating that the programmer usually doesn't need to call the method directly. The only time I can imagine you'd need to do so is if you needed to initialize a TextEditorPane with content that did not come from a file or URL.

Re: Document modification

Post by omadawn » Sat Aug 18, 2012 12:08 am

How do I open an enhancement request to have isDirty(boolean) created so that I can do isDirty(false) the way you describe above? I would love that functionality.

Re: Document modification

Post by robert » Fri Apr 27, 2012 3:13 pm

Oops, didn't realize that was a private method. I guess my thinking was that the editor should always know when it was dirty and when it wasn't.

Re: Document modification

Post by Taneeda » Fri Apr 27, 2012 1:19 pm

robert wrote:...Obviously, calling something like setText() to put the initial text in will set the dirty flag to true. ...


That was the reason. I solved it by using load(), thanks for the help :)

robert wrote:...just call setDirty(false) after your initialization...

The visibility of the setDirty() method in TextEditorPane is set to private... Maybe, this is a bug? Am i misunderstanding you?

Re: Document modification

Post by robert » Fri Apr 27, 2012 1:46 am

Taneeda wrote:So, i have another question: When i check with isDirty() i get true, even if hadn't done any changes. Why that?


It shouldn't be. How did you load the initial text? If you used TextEditorPane.load(), the dirty flag should not be set. Obviously, calling something like setText() to put the initial text in will set the dirty flag to true. So will calling setEncoding() - TextEditorPane considers an encoding change to be an important change. My guess is you're doing one of those two things. If you are, and you have to do them, just call setDirty(false) after your initialization and you should be fine.

Re: Document modification

Post by Taneeda » Wed Apr 25, 2012 5:05 pm

Hi,

i am using TextEditorPane inside RTextScrollPane. So how can i access the TextEditorPane inside the RTextScrollpane, which is stored in a tab of JTabbedPane?

Update:
Found it, just:
Code: Select all
RTextScrollPane sp = (RTextScrollPane)jTabbedPane.getComponentAt(i);
JOptionPane.showConfirmDialog(null, sp.getTextArea().getClass().getName());

Example:
Code: Select all
((TextEditorPane)sp.getTextArea()).isDirty()


So, i have another question: When i check with isDirty() i get true, even if hadn't done any changes. Why that?

Greetz Taneeda

Re: Document modification

Post by robert » Tue Jul 05, 2011 11:07 pm

Hi Golana,

The easiest way to do this is to add a javax.swing.event.DocumentListener to the editor's Document, and add the "*" to the displayed file name when the document is modified. Remove it whenever it is saved.

You can also use the org.fife.ui.rsyntaxtextarea.TextEditorPane class, that comes standard in the library. It has a "dirty" flag that is set/cleared properly when you edit/save/reload the file. You can also query it directly via the isDirty() method. Note that you'll still have to add the DocumentListener though to know when it's first made dirty.

From its documentation:

An extension of RSyntaxTextArea that adds information about the file being edited, such as:

Its name and location.
Is it dirty?
Is it read-only?
The last time it was loaded or saved to disk (local files only).
The file's encoding on disk.
Easy access to the line separator.

Loading and saving is also built into the editor.

Both local and remote files (e.g. ftp) are supported. See the FileLocation class for more information.

Top

cron