Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Difference between revisions of "Nasal library/clipboard"

From FlightGear wiki
Jump to: navigation, search
m (getText())
(Doc setText())
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{Nasal Navigation|nocat=1}}
 
{{Nasal Navigation|nocat=1}}
This page contains documentation for the '''<code>clipboard</code> namespace''' in [[Nasal]]. This namespace provides functions for working with text stored in the {{wikipedia|Clipboard (computing)|clipboard}}. The <code>clipboard</code> namespace is implemented in {{flightgear file|src/Scripting/NasalClipboard.cxx}}. There are also several files in the <tt>''Scripting''</tt> folder that implement the backend depending on the OS.
+
This page contains documentation for the '''<code>clipboard</code> namespace''' in [[Nasal]]. This namespace provides functions for working with text stored in the {{wikipedia|Clipboard (computing)|clipboard}}. The <code>clipboard</code> namespace is implemented in {{flightgear source|src/Scripting/NasalClipboard.cxx|pre=flightgear}}. There are also several files in the <tt>''Scripting''</tt> folder that implement the backend depending on the OS.
  
 
{{tip|Copy & paste the examples into your [[Nasal Console]] and execute them to see what they do.|width=70%}}
 
{{tip|Copy & paste the examples into your [[Nasal Console]] and execute them to see what they do.|width=70%}}
Line 8: Line 8:
 
{{Nasal doc
 
{{Nasal doc
 
|syntax = clipboard.getText([type]);
 
|syntax = clipboard.getText([type]);
<!-- |source = {{simgear file|simgear/nasal/mathlib.c|l=196|t=Source}} -->
+
|source = {{flightgear source|src/Scripting/NasalClipboard.cxx|l=69|t=Source}}
 
|text = Returns the contents of the clipboard as a string.
 
|text = Returns the contents of the clipboard as a string.
 
|param1 = type
 
|param1 = type
|param1text = Optional argument that specifies the source of the text. If <code>clipboard.CLIPBOARD</code> (the default) is given, the contents of the clipboard are returned. If <code>clipboard.SELECTION</code> is given, the contents of the selection buffer are given. Note that only X11 systems properly implement <code>clipboard.SELECTION</code>, but this argument may still be used with [[#setText()|setText()]] (see example 2).
+
|param1text = Optional argument that specifies the source of the text. If <code>clipboard.CLIPBOARD</code> (the default) is given, the contents of the clipboard are returned. If <code>clipboard.SELECTION</code> is given, the contents of the selection buffer are given. Note that only X11 systems properly implement <code>clipboard.SELECTION</code>, but this argument may still be used with <code>[[#setText()|setText()]]</code> (see example 2).
 
|example1 = var text = clipboard.getText(); # make sure you copy some text first
 
|example1 = var text = clipboard.getText(); # make sure you copy some text first
 
print("'", text, "'");
 
print("'", text, "'");
Line 20: Line 20:
  
 
=== setText() ===
 
=== setText() ===
 +
{{Nasal doc
 +
|syntax = clipboard.setText(text[, type]);
 +
|source = {{flightgear source|src/Scripting/NasalClipboard.cxx|l=54|t=Source}}
 +
|text = Sets the contents of the clipboard. If the operation is successful, 1 (true) is returned, otherwise 0 (false) is returned.
 +
|param1 = text
 +
|param1text = A string that will be put into the clipboard.
 +
|param2 = type
 +
|param2text = Optional argument that specifies into which part of the clipboard the text should be put. If <code>clipboard.CLIPBOARD</code> (the default) is given, it will go to the normal clipboard. If <code>clipboard.SELECTION</code> is given, the text will be added to the selection buffer. Note that only X11 systems properly implement <code>clipboard.SELECTION</code>, but this argument may still be used with <code>[[#setText()|setText()]]</code> (see example 2).
 +
|example1 = clipboard.setText("Demo");
 +
print("'", clipboard.getText(), "'"); # prints 'Demo'
 +
|example2 = clipboard.setText("Demo", clipboard.SELECTION);
 +
print("'", clipboard.getText(clipboard.SELECTION), "'"); # prints 'Demo'
 +
}}
  
 
== Constants ==
 
== Constants ==

Latest revision as of 09:05, 27 April 2018

This page contains documentation for the clipboard namespace in Nasal. This namespace provides functions for working with text stored in the clipboard This is a link to a Wikipedia article. The clipboard namespace is implemented in flightgear/src/Scripting/NasalClipboard.cxx. There are also several files in the Scripting folder that implement the backend depending on the OS.

Tip  Copy & paste the examples into your Nasal Console and execute them to see what they do.

Functions

getText()

clipboard.getText([type]);

Source

Returns the contents of the clipboard as a string.
type
Optional argument that specifies the source of the text. If clipboard.CLIPBOARD (the default) is given, the contents of the clipboard are returned. If clipboard.SELECTION is given, the contents of the selection buffer are given. Note that only X11 systems properly implement clipboard.SELECTION, but this argument may still be used with setText() (see example 2).

Examples

var text = clipboard.getText(); # make sure you copy some text first
print("'", text, "'");
clipboard.setText("Demo", clipboard.SELECTION);
var text = clipboard.getText(clipboard.SELECTION);
print("'", text, "'"); # prints 'Demo'

setText()

clipboard.setText(text[, type]);

Source

Sets the contents of the clipboard. If the operation is successful, 1 (true) is returned, otherwise 0 (false) is returned.
text
A string that will be put into the clipboard.
type
Optional argument that specifies into which part of the clipboard the text should be put. If clipboard.CLIPBOARD (the default) is given, it will go to the normal clipboard. If clipboard.SELECTION is given, the text will be added to the selection buffer. Note that only X11 systems properly implement clipboard.SELECTION, but this argument may still be used with setText() (see example 2).

Examples

clipboard.setText("Demo");
print("'", clipboard.getText(), "'"); # prints 'Demo'
clipboard.setText("Demo", clipboard.SELECTION);
print("'", clipboard.getText(clipboard.SELECTION), "'"); # prints 'Demo'

Constants

CLIPBOARD

SELECTION