Пример #1
0
bool CPluginAnsi::OpenEditor(LPCWSTR asFileName, bool abView, bool abDeleteTempFile, bool abDetectCP /*= false*/, int anStartLine /*= 0*/, int anStartChar /*= 1*/)
{
	if (!InfoA)
		return false;

	bool lbRc;
	int iRc;

	char szFileName[MAX_PATH] = "";
	ToOem(asFileName, szFileName, countof(szFileName));
	LPCSTR pszTitle = abDeleteTempFile ? InfoA->GetMsg(InfoA->ModuleNumber,CEConsoleOutput) : NULL;

	if (!abView)
	{
		iRc = InfoA->Editor(szFileName, pszTitle, 0,0,-1,-1,
		                     EF_NONMODAL|EF_IMMEDIATERETURN
		                     |(abDeleteTempFile ? (EF_DELETEONLYFILEONCLOSE|EF_DISABLEHISTORY) : 0)
		                     |EF_ENABLE_F6,
		                     anStartLine, anStartChar);
		lbRc = (iRc != EEC_OPEN_ERROR);
	}
	else
	{
		iRc = InfoA->Viewer(szFileName, pszTitle, 0,0,-1,-1,
		                     VF_NONMODAL|VF_IMMEDIATERETURN
		                     |(abDeleteTempFile ? (VF_DELETEONLYFILEONCLOSE|VF_DISABLEHISTORY) : 0)
		                     |VF_ENABLE_F6);
		lbRc = (iRc != 0);
	}

	return lbRc;
}
Пример #2
0
// Warning, напрямую НЕ вызывать. Пользоваться "общей" PostMacro
void CPluginAnsi::PostMacroApi(const wchar_t* asMacro, INPUT_RECORD* apRec, bool abShowParseErrors)
{
	if (!InfoA || !InfoA->AdvControl) return;

	char* pszMacroA = ToOem(asMacro);
	if (!pszMacroA)
		return;

	char* asMacroA = pszMacroA;

	ActlKeyMacro mcr;
	mcr.Command = MCMD_POSTMACROSTRING;
	mcr.Param.PlainText.Flags = 0; // По умолчанию - вывод на экран разрешен

	while ((asMacroA[0] == '@' || asMacroA[0] == '^') && asMacroA[1] && asMacroA[1] != ' ')
	{
		switch (*asMacroA)
		{
		case '@':
			mcr.Param.PlainText.Flags |= KSFLAGS_DISABLEOUTPUT;
			break;
		case '^':
			mcr.Param.PlainText.Flags |= KSFLAGS_NOSENDKEYSTOPLUGINS;
			break;
		}
		asMacroA++;
	}

	mcr.Param.PlainText.SequenceText = asMacroA;

	InfoA->AdvControl(InfoA->ModuleNumber, ACTL_KEYMACRO, (void*)&mcr);

	free(pszMacroA);
}
Пример #3
0
bool CPluginAnsi::InputBox(LPCWSTR Title, LPCWSTR SubTitle, LPCWSTR HistoryName, LPCWSTR SrcText, wchar_t*& DestText)
{
	_ASSERTE(DestText==NULL);
	if (!InfoA)
		return false;

	char strTemp[MAX_PATH+1] = "", aTitle[64] = "", aSubTitle[128] = "", aHistoryName[64] = "", aSrcText[128];
	ToOem(Title, aTitle, countof(aTitle));
	ToOem(SubTitle, aSubTitle, countof(aSubTitle));
	ToOem(HistoryName, aHistoryName, countof(aHistoryName));
	ToOem(SrcText, aSrcText, countof(aSrcText));

	if (!InfoA->InputBox(aTitle, aSubTitle, aHistoryName, aSrcText, strTemp, countof(strTemp), NULL, FIB_BUTTONS))
		return false;
	DestText = ToUnicode(strTemp);
	return true;
}
Пример #4
0
int CPluginAnsi::ShowMessage(LPCWSTR asMsg, int aiButtons, bool bWarning)
{
	if (!InfoA || !InfoA->Message)
		return -1;

	if (!asMsg)
		asMsg = L"";
	int nLen = lstrlen(asMsg);
	char* szOem = (char*)calloc(nLen+1,sizeof(*szOem));
	ToOem(asMsg, szOem, nLen+1);

	int iMsgRc = InfoA->Message(InfoA->ModuleNumber,
					FMSG_ALLINONE|(aiButtons?0:FMSG_MB_OK)|(bWarning ? FMSG_WARNING : 0), NULL,
					(const char * const *)szOem, 0, aiButtons);
	free(szOem);

	return iMsgRc;
}
Пример #5
0
int WINAPI JsonPlugin::ConfigureW(const ConfigureInfo *info)
{
    if(info->StructSize > sizeof *info /*|| memcmp(info->Guid, &MenuGuid, sizeof MenuGuid)*/)
        return FALSE;
#else
int WINAPI JsonPlugin::EXP_NAME(Configure)(int)
{
#endif

#if 0
 static FarDialogItemID DialogItems[]={
    /*00*/{DI_DOUBLEBOX,3,1,72,13,0,0,0,0,MOptions},
    /*01*/{DI_TEXT,5,2,0,0,0,0,0,0,MExportFormat},
    /*02*/{DI_RADIOBUTTON,5,3,0,0,0,0,DIF_GROUP,0,MExportUTF8},
    /*03*/{DI_RADIOBUTTON,5,4,0,0,0,0,0,0, MExportWin},
    /*04*/{DI_TEXT,4,5,0,0,0,0,DIF_SEPARATOR},
    /*05*/{DI_CHECKBOX,5,6,0,0,0,0,0,0,MAddPluginsMenu},
    /*06*/{DI_CHECKBOX,5,7,0,0,0,0,0,0,MEnableFileOpening},
    /*07*/{DI_CHECKBOX,5,8,0,0,0,0,0,0,MValidateOnParse},
    /*08*/{DI_CHECKBOX,40,8,0,0,0,0,0,0,MResolveExternals},    
    /*09*/{DI_CHECKBOX,5,9,0,0,0,0,0,0,MStartUnsorted},
    /*10*/{DI_TEXT,5,10,0,0,0,0,0,0,MNameAttributes},
    /*11*/{DI_EDIT,40,10,70},
    /*12*/{DI_TEXT,4,11,0,0,0,0,DIF_SEPARATOR},
    /*13*/{DI_BUTTON,0,12,0,0,0,0,DIF_CENTERGROUP,1,MOK},
    /*14*/{DI_BUTTON,0,12,0,0,0,0,DIF_CENTERGROUP,0,MCancel},
    /*15*/{DI_BUTTON,0,12,0,0,0,0,DIF_BTNNOCLOSE|DIF_CENTERGROUP,0,MOverrideColumns},
  };
  extern TCHAR sExportUTF[];
  USE_SETTINGSW;
  bExportUTF = settings.Get(sExportUTF, 1);
  bStartUnsorted = settings.Get(sStartUnsorted, 1);
  DialogItems[2].Selected = bExportUTF;
  DialogItems[3].Selected = !bExportUTF;
  DialogItems[5].Selected = settings.Get(sAddPluginsMenu, 0);
  DialogItems[6].Selected = settings.Get(sBrowseXMLFiles, 1);
  DialogItems[7].Selected = settings.Get(sValidateOnParse, 0);
  DialogItems[8].Selected = settings.Get(sResolveExternals, 0);  
  DialogItems[9].Selected = settings.Get(sStartUnsorted, 1);  

#ifdef FAR3
  PanelInfo panel;
  StartupInfo.PanelControl(PANEL_ACTIVE, FCTL_GETPANELINFO, 0, &panel);
  int itemCount = _countof(DialogItems) - (panel.PluginHandle == 0);
#else
  int itemCount = _countof(DialogItems) - 1;
#endif
  FarDialogItem* ItemsStr = MakeDialogItems(DialogItems, itemCount);

  extern TCHAR sIdAttributes[], sDefIdAttributes[];
#ifdef UNICODE
  wchar_t attrlist[512];
  DWORD attrsize = _countof(attrlist)-1;
  attrlist[attrsize] = 0;
#else
  char* attrlist = ItemsStr[11].Data;
  DWORD attrsize = sizeof ItemsStr[11].Data-1;
#endif
  SetData(ItemsStr[11], attrlist, attrsize);
  settings.Get(sIdAttributes, attrlist, attrsize, sDefIdAttributes);
  ToOem(ItemsStr[10].Data);
  ItemsStr[11].X1 = ItemsStr[10].X1 + _tcslen(ItemsStr[10].ITEMDATA)+1;

  RUN_DIALOG(ConfigDialogGuid, -1, -1, 76, 15, _T("Config"), ItemsStr, itemCount);
  if(DIALOG_RESULT != 13 /*OK*/) {
    delete ItemsStr;
    return FALSE;
  }
  bExportUTF = GetSelected(ItemsStr,2);
  bStartUnsorted = GetSelected(ItemsStr,9);
  ToAnsi(ItemsStr[11].Data);
  settings.Set(sIdAttributes, GetItemText(ItemsStr,11));
  settings.Set(sExportUTF, bExportUTF);
  settings.Set(sAddPluginsMenu, GetSelected(ItemsStr,5));
  settings.Set(sBrowseXMLFiles, GetSelected(ItemsStr,6));
  settings.Set(sValidateOnParse, GetSelected(ItemsStr,7));
  settings.Set(sResolveExternals, GetSelected(ItemsStr,8));
  settings.Set(sStartUnsorted, bStartUnsorted);

  XMLPlugin::LoadIdAttributes();
  delete ItemsStr;

  return TRUE;
#endif

  return FALSE;
}

int
#ifndef FAR3
    WINAPI
#endif
           EXP_NAME(Compare)(HANDLE hPlugin,const struct PluginPanelItem *Item1,const struct PluginPanelItem *Item2,
                                                    unsigned int Mode)
{
    switch(Mode)
    {
        case SM_NAME:
        case SM_EXT:
            {
#ifndef UNICODE
            return mystrcmpi(Item1->FindData.cFileName, Item2->FindData.cFileName);
#else
            PCWSTR s1 = Item1->FileName;
            PCWSTR s2 = Item2->FileName;
            return lstrcmpi(s1,s2);
#endif
            }
        default:
            return -2;
    }
}

#ifdef FAR3
intptr_t WINAPI CompareW(const CompareInfo *info)
{
    if(info->StructSize < sizeof(CompareInfo))
        return -2;
    return CompareW(info->hPanel, info->Item1, info->Item2, info->Mode);
}
#endif

#ifdef FAR3
int WINAPI JsonPlugin::EXP_NAME(ProcessDialogEvent)(const ProcessDialogEventInfo *info)
{
#if 0
    if(info->StructSize != sizeof(ProcessDialogEventInfo) || info->Event != DE_DLGPROCINIT)
        return FALSE;
    FarDialogEvent& evt = *(FarDialogEvent *)info->Param;
    if(evt.Msg == DN_BTNCLICK && evt.Param1 == 15/*Override button*/)
    {
        PanelInfo panel;
        Control(FCTL_GETPANELINFO, 0, &panel);
        if(!panel.PluginHandle || panel.OwnerGuid != PluginGuid)
            return FALSE;
        ((JsonPlugin*)panel.PluginHandle)->EditSpecialDocs();
        return TRUE;
    }
#endif
    return FALSE;
}
Пример #6
0
int YMSPlugin::WinError(LPCTSTR pMsg, LPCSTR pSourceModule)
{
    LPTSTR lpMsgBuf; bool bAllocated = false;
    UINT uErr = GetLastError() & (pSourceModule ? 0xffffffff:0x3fffffff);
    if(pMsg /*&& GetLastError()==0*/)
        lpMsgBuf = (LPTSTR)pMsg;
    else
    {
        HMODULE hModule = 0;
        if(pSourceModule)
	{
            hModule = GetModuleHandleA(pSourceModule);
            if(!hModule)
                hModule = LoadLibraryA(pSourceModule);
        }
        FormatMessage( hModule ?
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE
            : FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
            hModule, uErr,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            (LPTSTR)&lpMsgBuf, 0, NULL );
        bAllocated = true;
#ifndef UNICODE
        ToOem(lpMsgBuf);
#endif
    }

    static HANDLE hConsoleOutput;
    if(!hConsoleOutput) hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    //  if(!hConsoleOutput) hConsoleOutput = ;
    CONSOLE_SCREEN_BUFFER_INFO sbi;
    GetConsoleScreenBufferInfo(hConsoleOutput, &sbi);

    DWORD w = sbi.dwSize.X - 14;
    size_t iw=0;
    for(TCHAR* p = lpMsgBuf, *lastspace=0; *p; p++)
    {
        ++iw;
        switch(*p)
	{
          case ' ': case '\t': lastspace = p; break;
          case '\n': case '\r': iw = 0; lastspace = 0; break;
        }
        if(iw >= w && lastspace)
	{
            *lastspace = '\n';
            iw = p - lastspace;
            lastspace = 0;
        }
    }
    int rc;
#ifndef FAR3
    if(HIWORD(GetFarVersion())<591)
    {
        static LPCTSTR items[]={0,0,0,0};
        items[0] = GetMsg(MError); items[3] = GetMsg(MOK);
        items[1] = _tcstok(lpMsgBuf,_T("\r\n"));
        items[2] = _tcstok(NULL,_T("\r\n")); if(!items[2]) items[2] = items[3];
        rc = Message(FMSG_WARNING,_T("WinError"),items,_countof(items)-(items[2]==items[3]),1);
    } else
#endif
	{
        size_t l;
        TCHAR* buf = new TCHAR[l=_tcslen(lpMsgBuf)+_tcslen(GetMsg(MError))+2];
        _sntprintf(buf, l, _T("%s\n%s"), GetMsg(MError), lpMsgBuf);
        TCHAR*d=buf;
        for(TCHAR*s=buf; *s; s++)
	{
            *d = *s;
            if(!(*s=='\r' && s[1]=='\n' || *s=='\n' && s[1]=='\r'))
                d++;	  
        }
        *d = 0;
        /*char* p = buf + strlen(buf) - 1;
        if(p[-1]=='\r' && *p=='\n') p[-1] = 0;*/
        rc = Message(FMSG_WARNING|FMSG_ALLINONE|FMSG_MB_OK, _T("WinError"), (PCTSTR*)buf, 0, 0);
        delete buf;
    }
    if(bAllocated) LocalFree( lpMsgBuf );
    return rc;
}