コード例 #1
0
ファイル: AbiURLDict.cpp プロジェクト: Distrotech/abiword
//
// URLDict_invoke
// -------------------
//   This is the function that we actually call to invoke the on-line dictionary.
//   It should be called when the user selects from the context menu
//
static bool 
URLDict_invoke(AV_View* /*v*/, EV_EditMethodCallData * /*d*/)
{
  // Get the current view that the user is in.
  XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
  FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView());
  
  // If the user is on a word, but does not have it selected, we need
  // to go ahead and select that word so that the search/replace goes
  // correctly.
  pView->moveInsPtTo(FV_DOCPOS_EOW_MOVE);
  pView->moveInsPtTo(FV_DOCPOS_BOW);
  pView->extSelTo(FV_DOCPOS_EOW_SELECT);   
  
  // Now we will figure out what word to look up when we open our dialog.
  UT_String url ("http://www.dict.org/bin/Dict?Form=Dict1&Database=*&Strategy=*&Query=");
  if (!pView->isSelectionEmpty())
    {
      // We need to get the Ascii version of the current word.
      UT_UCS4Char *ucs4ST;
      pView->getSelectionText(*&ucs4ST);
      char* search = _ucsToAscii(
				 ucs4ST
				 );
      
      url += search;
      DELETEPV(search);
      FREEP(ucs4ST);
    }

  XAP_App::getApp()->openURL( url.c_str() ); 

  return true;
}
コード例 #2
0
ファイル: GdictAbiPlugin.cpp プロジェクト: Distrotech/abiword
//
// GDict_invoke
// -------------------
//   This is the function that we actually call to invoke the thesaurus.
//   It should be called when the user hits the thesaurus key (shift+f7?)
//   or chooses "thesaurus" from a menu.
//
static bool 
GDict_invoke(AV_View* /*v*/, EV_EditMethodCallData */*d*/)
{
  // Get the current view that the user is in.
  XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
  FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView());
  
  // If the user is on a word, but does not have it selected, we need
  // to go ahead and select that word so that the search/replace goes
  // correctly.
  pView->moveInsPtTo(FV_DOCPOS_EOW_MOVE);
  pView->moveInsPtTo(FV_DOCPOS_BOW);
  pView->extSelTo(FV_DOCPOS_EOW_SELECT);   
  
  // We need to get the utf-8 version of the current word.
  UT_UCS4Char *ucs4ST = NULL;
  pView->getSelectionText(*&ucs4ST);
  if (ucs4ST) {
    UT_UTF8String search(ucs4ST);
    GDict_exec (search.utf8_str());
    FREEP(ucs4ST);
  }
    
  return true;
}
コード例 #3
0
ファイル: AbiGoogle.cpp プロジェクト: Distrotech/abiword
//
// AbiGoogle_invoke
// -------------------
//   This is the function that we actually call to invoke the on-line dictionary.
//   It should be called when the user selects from the context menu
//
static bool 
AbiGoogle_invoke(AV_View* /*v*/, EV_EditMethodCallData * /*d*/)
{
  // Get the current view that the user is in.
  XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
  FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView());
  
  // If the user is on a word, but does not have it selected, we need
  // to go ahead and select that word so that the search/replace goes
  // correctly.
  if (pView->isSelectionEmpty()) {
    pView->moveInsPtTo(FV_DOCPOS_EOW_MOVE);
    pView->moveInsPtTo(FV_DOCPOS_BOW);
    pView->extSelTo(FV_DOCPOS_EOW_SELECT);   
  }

  // Now we will figure out what word to look up
  UT_UTF8String url ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=");
  
  // url escaping should be moved somewhere more generic
  UT_UCS4Char *ucs4ST;
  pView->getSelectionText(*&ucs4ST);
  UT_UCS4String data (ucs4ST);
  bool last_was_space = false;
  for (size_t i = 0; i < data.length (); i++) {
    UT_UCS4Char ch = data[i];
    if (!UT_UCS4_isspace (ch)) {
      url.appendUCS4 (&ch, 1);
      last_was_space = false;
    }
    else if (!last_was_space) {
      ch = '+';
      url.appendUCS4 (&ch, 1);
      last_was_space = true;
    }
  }

  XAP_App::getApp()->openURL( url.utf8_str() ); 
  FREEP(ucs4ST);

  return true;
}
コード例 #4
0
ファイル: AiksaurusABI.cpp プロジェクト: hfiguiere/abiword
//
// AiksaurusABI_invoke
// -------------------
//   This is the function that we actually call to invoke the thesaurus.
//   It should be called when the user hits the thesaurus key (shift+f7?)
//   or chooses "thesaurus" from a menu.
//
bool 
AiksaurusABI_invoke(AV_View* /*v*/, EV_EditMethodCallData * /*d*/)
{
    // Get the current view that the user is in.
    XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
    FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView());

    // If the user is on a word, but does not have it selected, we need
    // to go ahead and select that word so that the search/replace goes
    // correctly.
    pView->moveInsPtTo(FV_DOCPOS_EOW_MOVE);
    pView->moveInsPtTo(FV_DOCPOS_BOW);
    pView->extSelTo(FV_DOCPOS_EOW_SELECT);  
	
    // Now we will figure out what word to look up when we open our dialog.
    char* search = 0;
    if (!pView->isSelectionEmpty())
    {
        // We need to get the Ascii version of the current word.
        UT_UCS4Char * ucs4ST;
	 pView->getSelectionText(*&ucs4ST);
	 search = AiksaurusABI_ucsToAscii(
					 ucs4ST
        );
    }

    // Now we will run the thesaurus dialog and get a response.
    // We will automatically do a search for the selected/current word. 

#ifdef _WIN32
	AiksaurusApp thesaurus;
	thesaurus.setInstance( (HINSTANCE)s_hModule );
#else
    AiksaurusGTK thesaurus;    
#endif
    thesaurus.setTitle("Abiword Thesaurus");
    thesaurus.setInitialMessage("Welcome to Aiksaurus");
    const char* response = thesaurus.runThesaurus(search);

    if (response)
    {
        // Now that we have our replacement, we need to convert it to UCS-2. 
        int length;
        UT_UCSChar* replacement = AiksaurusABI_asciiToUcs(response, length);
    
        // Now, if our replacement has length, we can go ahead and run the 
        // replacement.  If the replacement has no length, we will do nothing.
        if (length)
            pView->cmdCharInsert(replacement, length);
    
        // all done with replacement.
        delete[] replacement;
    }
    
    // Finally, we need to remember to delete search and replacement strings.
    // Note that "search" might be null so we only want to delete[] it if it
    // was actually initialized above. 
    if (search) 
        delete[] search;
    
    return true;
}