diff options
Diffstat (limited to 'kjsembed/docs/examples/grepdialog')
-rw-r--r-- | kjsembed/docs/examples/grepdialog/README | 6 | ||||
-rw-r--r-- | kjsembed/docs/examples/grepdialog/grepdlg.js | 23 | ||||
-rw-r--r-- | kjsembed/docs/examples/grepdialog/grepdlg.ui | 199 | ||||
-rw-r--r-- | kjsembed/docs/examples/grepdialog/grepresults.js | 36 | ||||
-rw-r--r-- | kjsembed/docs/examples/grepdialog/grepresults.ui | 131 | ||||
-rwxr-xr-x | kjsembed/docs/examples/grepdialog/guigrep | 6 |
6 files changed, 401 insertions, 0 deletions
diff --git a/kjsembed/docs/examples/grepdialog/README b/kjsembed/docs/examples/grepdialog/README new file mode 100644 index 00000000..e126113f --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/README @@ -0,0 +1,6 @@ +Illustrates a number of useful facilities: + +- Creating dialogs from .ui files. +- Reading files from stdin and parsing them with JS regexps. +- Displaying formatted text using QML. +- Using shell scripts with kjscmd. diff --git a/kjsembed/docs/examples/grepdialog/grepdlg.js b/kjsembed/docs/examples/grepdialog/grepdlg.js new file mode 100644 index 00000000..2df87d98 --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepdlg.js @@ -0,0 +1,23 @@ +// Create and show the dialog +var dlg = Factory.loadui('grepdlg.ui'); +dlg.exec(); + +// Extract the parameters +var search = dlg.child('search_edit').text; +var files = dlg.child('files_edit').text; +var matchcase = dlg.child('case_check').checked; +var shownumbers = dlg.child('shownumbers_check').checked; + +// Build the command line +var options = ''; +if ( !matchcase ) { + options += '-i '; +} +if ( shownumbers ) { + options += '-n '; +} + +cmd = 'grep -H '+options+"'"+search+"' "+files; + +// Print the command line +print( cmd ); diff --git a/kjsembed/docs/examples/grepdialog/grepdlg.ui b/kjsembed/docs/examples/grepdialog/grepdlg.ui new file mode 100644 index 00000000..53a169bd --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepdlg.ui @@ -0,0 +1,199 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>GrepDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>GrepDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>319</width> + <height>213</height> + </rect> + </property> + <property name="caption"> + <string>Grep Dialog</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>search_edit</cstring> + </property> + <property name="text"> + <string>KJSEmbed</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>&Search for:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>search_edit</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel3</cstring> + </property> + <property name="text"> + <string>In &files:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>files_edit</cstring> + </property> + </widget> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>files_edit</cstring> + </property> + <property name="text"> + <string>*</string> + </property> + </widget> + <spacer row="4" column="1"> + <property name="name"> + <cstring>Spacer5</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QCheckBox" row="5" column="1"> + <property name="name"> + <cstring>case_check</cstring> + </property> + <property name="text"> + <string>Match &case</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>TextLabel3_2</cstring> + </property> + <property name="text"> + <string>Options:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + <pointsize>12</pointsize> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Grep Dialog</string> + </property> + </widget> + <widget class="Line" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Line1</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QCheckBox" row="6" column="1"> + <property name="name"> + <cstring>shownumbers_check</cstring> + </property> + <property name="text"> + <string>Show line &numbers</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QLayoutWidget" row="7" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>GrepDialog</receiver> + <slot>accept()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/grepdialog/grepresults.js b/kjsembed/docs/examples/grepdialog/grepresults.js new file mode 100644 index 00000000..99a698cd --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepresults.js @@ -0,0 +1,36 @@ +// Create the dialog +var dlg = Factory.loadui('grepresults.ui'); +var text = dlg.child('results_text'); + +function build_row( file, line, text ) +{ + file = file.replace( /:$/, "" ); + line = line.replace( /:$/, "" ); + return '<tr bgcolor="#eeeeff">' + +'<td><b><font color="blue">'+file+'</font></b></td>' + +'<td align="center"><b><font color="red">'+line+'</font></b></td>' + +'<td>'+text+'</td></tr>'; +} + +var s = '<table cellspacing="2"><tr bgcolor="#cccccc">'; +s += '<th><b>File</b></th>'; +s += '<th align="center"><b>Line</b></th>'; +s += '<th><b>Text</b></th></tr>'; + +var line = readLine(); +while ( line != null ) { + line.replace( /&/g,"&"); + line = line.replace( /"/g,"""); + line = line.replace( /</g,"<"); + + fields = line.match( /^([^:]+:)(\d+:)?(.*)/ ); + + s += build_row( fields[1], fields[2], fields[3] ); + line = readLine(); +} + +s += '</table>'; +text.text = s; + +// Show dialog +dlg.exec(); diff --git a/kjsembed/docs/examples/grepdialog/grepresults.ui b/kjsembed/docs/examples/grepdialog/grepresults.ui new file mode 100644 index 00000000..4bec43f4 --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepresults.ui @@ -0,0 +1,131 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>GrepResults</class> +<widget class="QDialog"> + <property name="name"> + <cstring>GrepResults</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>578</width> + <height>324</height> + </rect> + </property> + <property name="caption"> + <string>Grep Results</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + <pointsize>12</pointsize> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Grep Results</string> + </property> + </widget> + <widget class="Line"> + <property name="name"> + <cstring>Line1</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QTextEdit"> + <property name="name"> + <cstring>results_text</cstring> + </property> + <property name="frameShape"> + <enum>Box</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="lineWidth"> + <number>1</number> + </property> + <property name="textFormat"> + <enum>RichText</enum> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="undoRedoEnabled"> + <bool>false</bool> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&Dismiss</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>GrepResults</receiver> + <slot>accept()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/grepdialog/guigrep b/kjsembed/docs/examples/grepdialog/guigrep new file mode 100755 index 00000000..490e4676 --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/guigrep @@ -0,0 +1,6 @@ +#!/bin/sh + +KJSCMD="`which kjscmd`" +GREP_CMD=`$KJSCMD grepdlg.js` +VIEW_CMD="$KJSCMD grepresults.js" +eval $GREP_CMD | $VIEW_CMD |