New topic: 

Copy, Paste, etc. for two panels on a TabPanel

<http://forums.realsoftware.com/viewtopic.php?t=47828>

         Page 1 of 1
   [ 10 posts ]                 Previous topic | Next topic          Author  
Message        barrytraver          Post subject: Copy, Paste, etc. for two 
panels on a TabPanelPosted: Wed May 08, 2013 11:59 pm                         
Joined: Fri Sep 30, 2005 1:53 pm
Posts: 894
Location: Philadelphia, PA                I'm running Windows and writing for 
Windows and I really don't know what I'm doing, but I'm hoping that I've come 
to the right place for help.

Here's the background. I'm using a TabPanel, one panel of which (SourcePanel) 
contains a SourceEditField  and another panel of which (XMLPanel) contains an 
XMLEditField (I know, I should be using TextArea instead of EditField, but I'm 
building on a program written before EditField was deprecated).

What I want to do is to define (or redefine?) Copy, Paste, Select All, etc. so 
that they work with both panels, so that Copy copies selected text from either 
panel and Paste pastes Copied text to either panel.

Here's what I've come up with so far for the menu bar (and please tell me if 
it's a totally wrong approach)....

  Function mnuEditCopy ( ) As Boolean:

Dim Clipboard1 As New Clipboard
If TabPanel1.Value = SourcePanel Then
  Clipboard1.Text = SourceEditField.SelText
  Clipboard1.Close
End If
If TabPanel1.Value = XMLPanel Then
  Clipboard1.Text = XMLEditField.SelText
  Clipboard1.Close
End If
Return True
  
  Function mnuEditPaste ( ) As Boolean:

Dim Clipboard1 As New Clipboard
If SourceEditField.ReadOnly = False _
  And TabPanel1.Value = SourcePanel Then
  SourceEditField.SelText = Clipboard1.Text
  Clipboard1.Close
End If
If XMLEditField.ReadOnly = False _
  And TabPanel1.Value = XMLPanel Then
  XMLEditField.SelText = Clipboard1.Text
  Clipboard1.Close
End If
Return True
  
  Function mnuEditSelectAll ( ) As Boolean:
  
If TabPanel1.Value = SourcePanel Then
  SourceEditField.SelStart = 0
  SourceEditField.SelLength = Len ( SourceEditField.Text )
End If
If TabPanel1.Value = XMLPanel Then
  XMLEditField.SelStart = 0
  XMLEditField.SelLength = Len ( SourceEditField.Text )
End If
Return True
  
Am I re-inventing the wheel or worse?  I think this is the first time I've used 
Copy, Paste, etc. in a program, so the way I'm approaching this may may be 
entirely the wrong way.  Copy, Paste, and Select All seem to work okay, but I 
don't have the slightest idea on how to approach Cut or Undo, and I'm not 
really sure that I'm using the right approach for Copy, Paste, and Select All.

Any advice will be much appreciated.

Warm regards,

Barry Traver   
                             Top                timhare          Post subject: 
Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 2013 
12:16 am                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12311
Location: Portland, OR  USA                I think you're reinventing the 
wheel.  The standard select-all (ctrl-A), copy (ctrl-C) and paste (ctrl-V) 
commands should work out of the gate.  If not, just add the standard edit menu 
items to the menubar.   
                             Top                barrytraver          Post 
subject: Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 
2013 2:11 am                         
Joined: Fri Sep 30, 2005 1:53 pm
Posts: 894
Location: Philadelphia, PA                TIm,

You're right.  I'm embarrassed because I expected (and, worse yet, assumed) the 
task to be more difficult than it was.  If I had tried it out, I would have 
learned that the fact that two panels of a TabPanel were involved did not 
complicate things. My apologies for asking a question that I shouldn't have 
needed it to ask.

It has been said that there is no such thing as a stupid question.  Well, maybe 
not, but, if not, my question certainly at least comes close....

Barry Traver   
                             Top                Markus Winter          Post 
subject: Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 
2013 2:30 am                         
Joined: Sun Feb 19, 2006 4:00 pm
Posts: 1277
Location: Heidelberg, Germany                I blame Windows - it seems to 
instill a complicated sense of thinking   
                             Top                barrytraver          Post 
subject: Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 
2013 2:39 am                         
Joined: Fri Sep 30, 2005 1:53 pm
Posts: 894
Location: Philadelphia, PA                I've still got a problem. Yes, Copy, 
Paste, and Select All do work in a bare-bones program for testing.  BUT they do 
not work in my real program.

If I do a CTRL-C, CTRL-V, or CTRL-A without my code, nothing happens,  It only 
works if I add the code I provided earlier.  If I comment out my code, as I 
said, nothing happens (and, yes, I make sure that I have made SourceEditField 
to be NOT ReadOnly).

I'm still probably missing something simple, but right now I don't know what it 
is....

Barry Traver   
                             Top                Markus Winter          Post 
subject: Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 
2013 9:03 am                         
Joined: Sun Feb 19, 2006 4:00 pm
Posts: 1277
Location: Heidelberg, Germany                So you are still overriding the 
build-in commands? Using "now empty" code? And you are surprised nothing 
happens?

Commenting code out is not the same as stopping the overriding of the build-in 
routines.

    
                             Top                timhare          Post subject: 
Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 2013 4:35 
pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12311
Location: Portland, OR  USA                As Markus suggests, RB will use the 
first menu handler it encounters as it moves up the hierarchy and execute 
whatever code is in it. If there's no code, then it executes just that: 
nothing.  Unfortunately, there's really no way to comment out a menu handler.  
You have to delete all the text in the handler, including comments.   
                             Top                barrytraver          Post 
subject: Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 
2013 7:11 pm                         
Joined: Fri Sep 30, 2005 1:53 pm
Posts: 894
Location: Philadelphia, PA                TIm and Markus,

Thanks for the comments.  I may not have progressed to the point where I really 
fully understand what I'm doing, so I'll tell you what I did and perhaps you 
can tell me if I did something wrong (but it does seem to work now!).

My attempt to stop the overriding of the built-in routines was to delete 
entirely the routines related to the built-in stuff for Copy, Paste, and Select 
All.

That is, I highlighted in the left column of the screen mnuEditCopy,, 
mnuEditPaste, and mnuEditSelectAll one by one and pressed Delete on the right 
side of the keyboard, acting on my understanding of things that if you have 
anything in such routines, it replaces (prevents from operating) the built-in 
stuff.

Even though I at least partly understood what you were saying, I was still 
surprised when the result of my removing the routines was that Copy, Paste, and 
SelectAll -- rather then staying lost (or getting even more lost) -- 
reappeared, and now Copy, Paste, and SelectAll seem to be working perfectly in 
spite of their now being in a sense invisible.

I was even more surprised to see that removal of mnuEditUndo led to a 
reappearance of Undo, no longer "seen" (as a code routine), but actively 
working to do what Undo is supposed to do.

Here's the paradox.  When there was a visible routine for such things, the mere 
existence of the routine (even or especially if only comments) meant that a 
command didn't work.  When, on the other hand, the routine was removed (i.e., 
not just made invisible but made nonexistent), Copy and the others came out 
from wherever they were hiding to do the work they were supposed to do.

So removing the actual routines -- rather than the mere commenting out of code 
-- led to the stopping the over-writing of the built-in routines.

Thanks for taking the time to explain things.  I hope I've correctly understood 
the main points of what you were saying.

Barry Traver   
                             Top                timhare          Post subject: 
Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Thu May 09, 2013 9:21 
pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12311
Location: Portland, OR  USA                Quote:I hope I've correctly 
understood the main points of what you were saying.
I believe you have.   
                             Top                Markus Winter          Post 
subject: Re: Copy, Paste, etc. for two panels on a TabPanelPosted: Fri May 10, 
2013 8:03 am                         
Joined: Sun Feb 19, 2006 4:00 pm
Posts: 1277
Location: Heidelberg, Germany                The TextArea supports the system's 
handling of copy/cut/paste. As does any custom class you make based on the 
TextArea.

If you want to override it you can add an EventHandler to your custom class and 
write some code yourself.

If you return TRUE from the MenuHandler then that means the MenuHandler has 
handled it all and will not call up the chain: "Yeah, I dealt with it"

If you return FALSE from the MenuHandler then that means the MenuHandler has 
done its thing and will now execute the code further up the chain: "Nah, I 
haven't dealt with it all"

As long as your EventHandler is there it will be called - you have to 
completely remove the EventHandler to get rid of it.

If you keep the EventHandler and just comment out the code then what happens 
depends on what value you return. True doesn't call the normal routines, FALSE 
does.

Put this in a custom EditField and play around with it:

Function EditCopy() As Boolean
  
  beep
  
  Return True
  
End Function
   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 10 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to