Hi,
here's a patch that adds a call to an external dictionary (wordnet). I
talked about this some weeks ago and I asked if it is okay just to call an
external tcl/tk program.
I decided not to rebuild the GUI of that dictionary ('wnb') for lyx,
because:
1. the existing GUI is quite good, I wouldn't know how to improve it
2. it's not that simple that one can rebuild it in some hours
3. people without tcl/tk won't lose any *functions*, they will just
lose the *integration* into lyx
The only thing that's sad is that you have to patch your wnb so you can
select a word in lyx and wnb will start up with this word. I submitted
this patch to the wordnet guys but I didn't (yet?) get an answer. An
alternative is to distribute the patched wnb with lyx (it's 44 kb big).
Furthermore I have to say that the wordnet archive is 13 MB big, people
would have to download that if its not in their distribution (you can get
wordnet at http://www.cogsci.princeton.edu/~wn/w3wn.html).
Although this doesn't sound so positive, I still think it's a very useful
feature at least for the power user and integration of external programs
is lyx #1 strength (from my point of view).
The patch is not complete (see all the TODOs, I will care about them). I
also need someone's advice if the wordnet stuff (which is just one
function) should get its own class, if it is okay to call an external
command with system() and probably about other problems... If everything
is okay already I request someone to commit this patch.
Since I'm tired of making diff files, maybe you could give me write access
to the cvs?
ChangeLog:
* src/lyxfunc.C src/menus.C src/include/commandtags.h:
Added "Wordnet..." entry
* src/lyxfr1.C src/lyxfr1.h src/text2.C src/include/lyxtext.h:
moved GetSelectionOrWordAtCursor() and GetCurrentSelectionAsString()
from lyxfr1.C to LyXText
* src/Makefile.am src/wordnet.C: new file with a function to call 'wnb'
wnb.diff is the diff to apply to wnb, wnb-lyx.diff is the diff against the
lyx cvs.
Regards
Daniel
--
PGP Key fingerprint = 3D 98 9E D2 00 B6 E0 9D 7E B9 77 23 17 E2 11 6A
http://cgi4all.alabanza.com/glasatelier/
diff -ur src/Makefile.am /home/dnaber/cvs/lyx/src/Makefile.am
--- src/Makefile.am Fri Apr 2 19:28:53 1999
+++ /home/dnaber/cvs/lyx/src/Makefile.am Fri Apr 2 19:29:00 1999
@@ -150,6 +150,7 @@
trans_mgr.C \
trans_mgr.h \
vspace.C \
+ wordnet.C \
workarea.C
purify: $(OBJS) $(LIBOBJS)
diff -ur src/include/commandtags.h /home/dnaber/cvs/lyx/src/include/commandtags.h
--- src/include/commandtags.h Sat Apr 3 17:16:35 1999
+++ /home/dnaber/cvs/lyx/src/include/commandtags.h Fri Apr 2 21:54:24 1999
@@ -40,6 +40,7 @@
LFUN_COPY,
LFUN_GOTOERROR,
LFUN_GOTONOTE,
+ LFUN_WORDNET,
LFUN_OPENSTUFF,
LFUN_HYPHENATION,
LFUN_HFILL,
diff -ur src/include/lyxtext.h /home/dnaber/cvs/lyx/src/include/lyxtext.h
--- src/include/lyxtext.h Sat Apr 3 17:16:35 1999
+++ /home/dnaber/cvs/lyx/src/include/lyxtext.h Sat Apr 3 15:54:33 1999
@@ -413,6 +413,15 @@
///
void toggleAppendix();
+ /** If nothing selected, select the word at the cursor.
+ Returns the current selection
+ Note: this function should be in LyXText! */
+ LString const GetSelectionOrWordAtCursor();
+
+ /** Returns the current selection. If nothing is selected or if the selection
+ spans 2 paragraphs, an empty string is returned. */
+ LString const GetCurrentSelectionAsString();
+
private:
///
Row* firstrow;
@@ -515,6 +524,7 @@
specified row
*/
int RowLast(Row *row);
+
};
#endif
diff -ur src/lyxfr1.C /home/dnaber/cvs/lyx/src/lyxfr1.C
--- src/lyxfr1.C Fri Apr 2 21:07:56 1999
+++ /home/dnaber/cvs/lyx/src/lyxfr1.C Sat Apr 3 15:59:58 1999
@@ -33,23 +33,10 @@
#include "lyx_gui_misc.h"
#include "buffer.h"
-
-// Maximum length copied from the current selection to the search string
-const int LYXSEARCH_MAXLEN = 128;
-
// function prototypes
bool IsLetterCharOrDigit(char ch);
-// If nothing selected, select the word at the cursor.
-// Returns the current selection
-// Note: this function should be in LyXText!
-LString const GetSelectionOrWordAtCursor(LyXText *lt);
-
-// Returns the current selection. If nothing is selected or if the selection
-// spans 2 paragraphs, an empty string is returned.
-LString const GetCurrentSelectionAsString(LyXText *lt);
-
// This is a copy of SetSelectionOverString from text.C
// It does the same, but uses only the length as a parameter
void SetSelectionOverLenChars(LyXText *lt, int len);
@@ -62,61 +49,6 @@
}
-// Returns the current selection. If nothing is selected or if the selection
-// spans 2 paragraphs, an empty string is returned.
-LString const GetCurrentSelectionAsString(LyXText *lt)
-{
- LyXParagraph *par;
- int pos;
- int endpos;
- int i;
- char sz[LYXSEARCH_MAXLEN];
- char ch;
- bool fPrevIsSpace;
-
- sz[0] = 0;
- par = lt->cursor.par;
- if (lt->selection && (lt->sel_cursor.par == par)) {
- // (selected) and (begin/end in same paragraph)
- pos = lt->sel_start_cursor.pos;
- endpos = lt->sel_end_cursor.pos;
- i = 0;
- fPrevIsSpace = false;
- while ((i < LYXSEARCH_MAXLEN-2) &&
- (pos < par->Last()) && (pos < endpos)) {
- ch = par->GetChar(pos);
-
- //HB??: Maybe (ch <= ' ')
- if ((ch == ' ') || ((unsigned char)ch <= LYX_META_INSET)) {
- // consecutive spaces --> 1 space char
- if (fPrevIsSpace) {
- ++pos; // Next text pos
- continue; // same search pos
- }
- sz[i] = ' ';
- fPrevIsSpace = true;
- } else {
- sz[i] = ch;
- fPrevIsSpace = false;
- }
- ++pos;
- ++i;
- }
- sz[i] = 0;
- }
- return LString(sz);
-}
-
-
-// If nothing selected, select the word at the cursor.
-// Returns the current selection
-LString const GetSelectionOrWordAtCursor(LyXText *lt)
-{
- lt->SelectWordWhenUnderCursor();
- return GetCurrentSelectionAsString(lt);
-}
-
-
// This is a copy of SetSelectionOverString from text.C
// It does the same, but uses only the length as a parameter
void SetSelectionOverLenChars(LyXText *lt, int len)
@@ -137,7 +69,7 @@
SetReplaceEnabled(!view->currentBuffer()->isReadonly());
if (lsSearch.empty())
- SetSearchString(GetSelectionOrWordAtCursor(view->text));
+ SetSearchString(view->text->GetSelectionOrWordAtCursor());
}
diff -ur src/lyxfunc.C /home/dnaber/cvs/lyx/src/lyxfunc.C
--- src/lyxfunc.C Fri Apr 2 21:54:48 1999
+++ /home/dnaber/cvs/lyx/src/lyxfunc.C Fri Apr 2 21:56:05 1999
@@ -96,6 +96,9 @@
// (alkis)
extern tex_accent_struct get_accent(kb_action action);
+// dnaber, 1999-04-02
+extern void StartWordnet(BufferView*);
+
extern void MenuSearch(BufferView*);
extern bool MenuPreview(Buffer*);
extern bool MenuPreviewPS(Buffer*);
@@ -795,6 +798,10 @@
owner->currentView()->gotoNote();
break;
+ case LFUN_WORDNET:
+ StartWordnet(owner->currentView());
+ break;
+
case LFUN_OPENSTUFF:
owner->currentView()->openStuff();
break;
diff -ur src/menus.C /home/dnaber/cvs/lyx/src/menus.C
--- src/menus.C Fri Apr 2 21:49:13 1999
+++ /home/dnaber/cvs/lyx/src/menus.C Sat Apr 3 15:21:04 1999
@@ -765,6 +765,7 @@
"|Floats & Insets%m"
"|Table%m"
"|Spellchecker...."
+ "|Wordnet...%l"
"|Check TeX"
"|Table of Contents...%l"
"|Version Control%m%l"
@@ -784,12 +785,13 @@
fl_setpup_shortcut(EditMenu, 9, scex(_("EM|Ii#i#I")));
fl_setpup_shortcut(EditMenu, 10, scex(_("EM|Tt#t#T")));
fl_setpup_shortcut(EditMenu, 11, scex(_("EM|Ss#s#S")));
- fl_setpup_shortcut(EditMenu, 12, scex(_("EM|hH#h#H")));
- fl_setpup_shortcut(EditMenu, 13, scex(_("EM|aA#a#A")));
- fl_setpup_shortcut(EditMenu, 14, scex(_("EM|Vv#v#V")));
- fl_setpup_shortcut(EditMenu, 15, scex(_("EM|wW#w#W")));
- fl_setpup_shortcut(EditMenu, 16, scex(_("EM|Ll#l#L")));
- fl_setpup_shortcut(EditMenu, 17, scex(_("EM|gG#g#G")));
+ fl_setpup_shortcut(EditMenu, 12, scex(_("EM|Mm#m#M")));
+ fl_setpup_shortcut(EditMenu, 13, scex(_("EM|hH#h#H")));
+ fl_setpup_shortcut(EditMenu, 14, scex(_("EM|aA#a#A")));
+ fl_setpup_shortcut(EditMenu, 15, scex(_("EM|Vv#v#V")));
+ fl_setpup_shortcut(EditMenu, 16, scex(_("EM|wW#w#W")));
+ fl_setpup_shortcut(EditMenu, 17, scex(_("EM|Ll#l#L")));
+ fl_setpup_shortcut(EditMenu, 18, scex(_("EM|gG#g#G")));
// disable unavailable entries.
if(tmpbuffer->undostack.Top() == 0)
@@ -797,9 +799,9 @@
if(tmpbuffer->redostack.Top() == 0)
fl_setpup_mode(EditMenu, 2, FL_PUP_GREY);
if(lyxrc->isp_command == "none")
- fl_setpup_mode(EditMenu, 11, FL_PUP_GREY);
- if(lyxrc->chktex_command == "none")
fl_setpup_mode(EditMenu, 12, FL_PUP_GREY);
+ if(lyxrc->chktex_command == "none")
+ fl_setpup_mode(EditMenu, 13, FL_PUP_GREY);
if (tmpbuffer->isReadonly()) {
fl_setpup_mode(EditMenu, 1, FL_PUP_GREY);
@@ -833,13 +835,14 @@
case 10:// table
break;
case 11: tmpfunc.Dispatch(LFUN_SPELLCHECK); break;
- case 12: tmpfunc.Dispatch(LFUN_RUNCHKTEX); break;
- case 13: tmpfunc.Dispatch(LFUN_TOCVIEW); break;
- case 14: // version control
+ case 12: tmpfunc.Dispatch(LFUN_WORDNET); break;
+ case 13: tmpfunc.Dispatch(LFUN_RUNCHKTEX); break;
+ case 14: tmpfunc.Dispatch(LFUN_TOCVIEW); break;
+ case 15: // version control
break;
- case 15: tmpfunc.Dispatch(LFUN_LATEX_LOG); break;
- case 16: tmpfunc.Dispatch(LFUN_PASTESELECTION, "line"); break;
- case 17: tmpfunc.Dispatch(LFUN_PASTESELECTION, "paragraph"); break;
+ case 16: tmpfunc.Dispatch(LFUN_LATEX_LOG); break;
+ case 17: tmpfunc.Dispatch(LFUN_PASTESELECTION, "line"); break;
+ case 18: tmpfunc.Dispatch(LFUN_PASTESELECTION, "paragraph"); break;
// floats & insets sub-menu
#warning make into a LFUN
diff -ur src/text2.C /home/dnaber/cvs/lyx/src/text2.C
--- src/text2.C Sat Apr 3 15:45:09 1999
+++ /home/dnaber/cvs/lyx/src/text2.C Sat Apr 3 16:02:44 1999
@@ -3281,3 +3281,61 @@
SetCursor(cursor.par, cursor.pos);
}
+
+// Returns the current selection. If nothing is selected or if the selection
+// spans 2 paragraphs, an empty string is returned.
+// (this once was in lyxfr1.C -- dnaber, 1999-04-03)
+LString const LyXText::GetCurrentSelectionAsString()
+{
+ // Maximum length copied from the current selection to the search string
+ const int LYXSEARCH_MAXLEN = 128;
+ LyXParagraph *par;
+ int pos;
+ int endpos;
+ int i;
+ char sz[LYXSEARCH_MAXLEN];
+ char ch;
+ bool fPrevIsSpace;
+
+ sz[0] = 0;
+ par = cursor.par;
+ if (selection && (sel_cursor.par == par)) {
+ // (selected) and (begin/end in same paragraph)
+ pos = sel_start_cursor.pos;
+ endpos = sel_end_cursor.pos;
+ i = 0;
+ fPrevIsSpace = false;
+ while ((i < LYXSEARCH_MAXLEN-2) &&
+ (pos < par->Last()) && (pos < endpos)) {
+ ch = par->GetChar(pos);
+
+ //HB??: Maybe (ch <= ' ')
+ if ((ch == ' ') || ((unsigned char)ch <= LYX_META_INSET)) {
+ // consecutive spaces --> 1 space char
+ if (fPrevIsSpace) {
+ ++pos; // Next text pos
+ continue; // same search pos
+ }
+ sz[i] = ' ';
+ fPrevIsSpace = true;
+ } else {
+ sz[i] = ch;
+ fPrevIsSpace = false;
+ }
+ ++pos;
+ ++i;
+ }
+ sz[i] = 0;
+ }
+ return LString(sz);
+}
+
+
+// If nothing selected, select the word at the cursor.
+// Returns the current selection
+// (this once was in lyxfr1.C -- dnaber, 1999-04-03)
+LString const LyXText::GetSelectionOrWordAtCursor()
+{
+ SelectWordWhenUnderCursor();
+ return GetCurrentSelectionAsString();
+}
--- wnb.bak Sat Mar 20 20:31:07 1999
+++ wnb Sun Mar 21 14:03:16 1999
@@ -955,6 +955,7 @@
bind . <KeyPress-Escape> {}
bind .wordframe.entry <Return> golookup
bind .results.text <Shift-Button-1> {shiftclickhandler %x %y}
+ bind .results.text <Button-2> {shiftclickhandler %x %y}
bind . <Control-s> controlshandler
foreach object $objectlist {
$object configure \
@@ -1472,3 +1473,6 @@
bind . <Control-s> controlshandler
bind . <Control-g> grepword
+# dnaber, 1999-03-20:
+set g_searchword [lindex $argv 0]
+golookup