Skip to content

Commit

Permalink
Merge pull request elfmz#2301 from akruphi/from_far2m
Browse files Browse the repository at this point in the history
Miscellaneous fixes from far2m
  • Loading branch information
elfmz authored Jul 28, 2024
2 parents ed274df + ec269be commit 658c4f4
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 25 deletions.
2 changes: 1 addition & 1 deletion far2l/src/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4041,7 +4041,7 @@ void Dialog::ChangeFocus2(unsigned SetFocusPos)
return;
}

if (FocusPosNeed != -1 && IsItemFocusable(Item[FocusPosNeed]))
if (FocusPosNeed >= 0 && FocusPosNeed < (int)ItemCount && IsItemFocusable(Item[FocusPosNeed]))
SetFocusPos = FocusPosNeed;

Item[FocusPos]->Focus = 0;
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ int64_t Edit::VMProcess(MacroOpcode OpCode, void *vParam, int64_t iParam)
case MCODE_V_ITEMCOUNT:
return (int64_t)StrSize;
case MCODE_V_CURPOS:
return (int64_t)(CursorPos + 1);
return (int64_t)(CurPos + 1);
case MCODE_F_EDITOR_SEL: {
int Action = (int)((INT_PTR)vParam);

Expand Down
2 changes: 1 addition & 1 deletion far2l/src/fileedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,7 @@ int FileEditor::EditorControl(int Command, void *Param)
if (Param) {
EditorSaveFile *esf = (EditorSaveFile *)Param;

if (*esf->FileName)
if (esf->FileName && *esf->FileName)
strName = esf->FileName;

if (esf->FileEOL) {
Expand Down
19 changes: 14 additions & 5 deletions far2l/src/fileview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "mix.hpp"
#include "fileholder.hpp"
#include "GrepFile.hpp"
#include "exitcode.hpp"

FileViewer::FileViewer(FileHolderPtr NewFileHolder, int EnableSwitch, int DisableHistory, int DisableEdit,
long ViewStartPos, const wchar_t *PluginData, NamesList *ViewNamesList, int ToSaveAs, UINT aCodePage)
Expand Down Expand Up @@ -329,11 +330,19 @@ int FileViewer::ProcessKey(FarKey Key)
| (SaveToSaveAs ? FFILEEDIT_SAVETOSAVEAS : 0)
| (DisableHistory ? FFILEEDIT_DISABLEHISTORY : 0),
-2, static_cast<int>(FilePos), strPluginData);
ShellEditor->SetEnableF6(TRUE);
/* $ 07.05.2001 DJ сохраняем NamesList */
ShellEditor->SetNamesList(View.GetNamesList());
FrameManager->DeleteFrame(this); // Insert уже есть внутри конструктора
ShowTime(2);
int load = ShellEditor->GetExitCode();
if (load == XC_LOADING_INTERRUPTED || load == XC_OPEN_ERROR)
{
delete ShellEditor;
}
else
{
ShellEditor->SetEnableF6(TRUE);
/* $ 07.05.2001 DJ сохраняем NamesList */
ShellEditor->SetNamesList(View.GetNamesList());
FrameManager->DeleteFrame(this); // Insert уже есть внутри конструктора
ShowTime(2);
}
}

return TRUE;
Expand Down
4 changes: 2 additions & 2 deletions far2l/src/mix/strmix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ wchar_t GetDecimalSeparator()
}

FARString
ReplaceBrackets(const FARString &SearchStr, const FARString &ReplaceStr, RegExpMatch *Match, int Count)
ReplaceBrackets(const wchar_t* SearchStr, const FARString &ReplaceStr, RegExpMatch *Match, int Count)
{
FARString result;
size_t pos = 0, length = ReplaceStr.GetLength();
Expand All @@ -1205,7 +1205,7 @@ ReplaceBrackets(const FARString &SearchStr, const FARString &ReplaceStr, RegExpM

if (index >= 0) {
if (index < Count) {
FARString bracket(SearchStr.CPtr() + Match[index].start,
FARString bracket(SearchStr + Match[index].start,
Match[index].end - Match[index].start);
result+= bracket;
}
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/mix/strmix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ inline const wchar_t GetDecimalSeparatorDefault() { return L'.'; };
inline const wchar_t* GetDecimalSeparatorDefaultStr() { return L"."; };

FARString
ReplaceBrackets(const FARString &SearchStr, const FARString &ReplaceStr, RegExpMatch *Match, int Count);
ReplaceBrackets(const wchar_t *SearchStr, const FARString &ReplaceStr, RegExpMatch *Match, int Count);

bool SearchString(const wchar_t *Source, int StrSize, const FARString &Str, FARString &ReplaceStr,
int &CurPos, int Position, int Case, int WholeWords, int Reverse, int Regexp, int *SearchLength,
Expand Down
28 changes: 15 additions & 13 deletions far2l/src/panels/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,7 @@ int Panel::SetPluginCommand(int Command, int Param1, LONG_PTR Param2)
ProcessingPluginCommand++;
FilePanels *FPanels = CtrlObject->Cp();
PluginCommand = Command;
auto DestFilePanel = dynamic_cast<FileList*>(this);

switch (Command) {
case FCTL_SETVIEWMODE:
Expand Down Expand Up @@ -1724,7 +1725,6 @@ int Panel::SetPluginCommand(int Command, int Param1, LONG_PTR Param2)
}

if (GetType() == FILE_PANEL) {
FileList *DestFilePanel = (FileList *)this;
static int Reenter = 0;

if (!Reenter && Info->Plugin) {
Expand Down Expand Up @@ -1763,7 +1763,6 @@ int Panel::SetPluginCommand(int Command, int Param1, LONG_PTR Param2)
GetCurDir(strTemp);

if (GetType() == FILE_PANEL) {
FileList *DestFilePanel = (FileList *)this;
static int Reenter = 0;

if (!Reenter && GetMode() == PLUGIN_PANEL) {
Expand Down Expand Up @@ -1800,7 +1799,7 @@ int Panel::SetPluginCommand(int Command, int Param1, LONG_PTR Param2)

if (GetType() == FILE_PANEL) {
FARString strColumnTypes, strColumnWidths;
((FileList *)this)->PluginGetColumnTypesAndWidths(strColumnTypes, strColumnWidths);
DestFilePanel->PluginGetColumnTypesAndWidths(strColumnTypes, strColumnWidths);

if (Command == FCTL_GETCOLUMNTYPES) {
if (Param1 && Param2)
Expand All @@ -1817,50 +1816,53 @@ int Panel::SetPluginCommand(int Command, int Param1, LONG_PTR Param2)
break;

case FCTL_GETPANELITEM: {
Result = (int)((FileList *)this)->PluginGetPanelItem(Param1, (PluginPanelItem *)Param2);
if (DestFilePanel)
Result = (int)DestFilePanel->PluginGetPanelItem(Param1, (PluginPanelItem *)Param2);
break;
}

case FCTL_GETSELECTEDPANELITEM: {
Result = (int)((FileList *)this)->PluginGetSelectedPanelItem(Param1, (PluginPanelItem *)Param2);
if (DestFilePanel)
Result = (int)DestFilePanel->PluginGetSelectedPanelItem(Param1, (PluginPanelItem *)Param2);
break;
}

case FCTL_GETCURRENTPANELITEM: {
PanelInfo Info;
FileList *DestPanel = ((FileList *)this);
DestPanel->PluginGetPanelInfo(Info);
Result = (int)DestPanel->PluginGetPanelItem(Info.CurrentItem, (PluginPanelItem *)Param2);
if (DestFilePanel) {
PanelInfo Info;
DestFilePanel->PluginGetPanelInfo(Info);
Result = (int)DestFilePanel->PluginGetPanelItem(Info.CurrentItem, (PluginPanelItem *)Param2);
}
break;
}

case FCTL_BEGINSELECTION: {
if (GetType() == FILE_PANEL) {
((FileList *)this)->PluginBeginSelection();
DestFilePanel->PluginBeginSelection();
Result = TRUE;
}
break;
}

case FCTL_SETSELECTION: {
if (GetType() == FILE_PANEL) {
((FileList *)this)->PluginSetSelection(Param1, Param2 ? true : false);
DestFilePanel->PluginSetSelection(Param1, Param2 ? true : false);
Result = TRUE;
}
break;
}

case FCTL_CLEARSELECTION: {
if (GetType() == FILE_PANEL) {
reinterpret_cast<FileList *>(this)->PluginClearSelection(Param1);
DestFilePanel->PluginClearSelection(Param1);
Result = TRUE;
}
break;
}

case FCTL_ENDSELECTION: {
if (GetType() == FILE_PANEL) {
((FileList *)this)->PluginEndSelection();
DestFilePanel->PluginEndSelection();
Result = TRUE;
}
break;
Expand Down
6 changes: 6 additions & 0 deletions far2l/src/plug/PluginA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ static const char szCache_ProcessEditorEvent[] = "ProcessEditorEvent";
static const char szCache_ProcessViewerEvent[] = "ProcessViewerEvent";
static const char szCache_ProcessDialogEvent[] = "ProcessDialogEvent";
static const char szCache_Configure[] = "Configure";
static const char szCache_GetFiles[] = "GetFiles";
static const char szCache_ProcessHostFile[] = "ProcessHostFile";

static const char NFMP_OpenPlugin[] = "OpenPlugin";
static const char NFMP_OpenFilePlugin[] = "OpenFilePlugin";
Expand Down Expand Up @@ -163,6 +165,8 @@ bool PluginA::LoadFromCache()
pProcessViewerEvent = (PLUGINPROCESSVIEWEREVENT)(INT_PTR)kfh.GetUInt(szCache_ProcessViewerEvent, 0);
pProcessDialogEvent = (PLUGINPROCESSDIALOGEVENT)(INT_PTR)kfh.GetUInt(szCache_ProcessDialogEvent, 0);
pConfigure = (PLUGINCONFIGURE)(INT_PTR)kfh.GetUInt(szCache_Configure, 0);
pGetFiles = (PLUGINGETFILES)(INT_PTR)kfh.GetUInt(szCache_GetFiles, 0);
pProcessHostFile = (PLUGINPROCESSHOSTFILE)(INT_PTR)kfh.GetUInt(szCache_ProcessHostFile, 0);
WorkFlags.Set(PIWF_CACHED); // too much "cached" flags

if (kfh.GetInt(szCache_Preopen) != 0)
Expand Down Expand Up @@ -232,6 +236,8 @@ bool PluginA::SaveToCache()
kfh.SetUInt(GetSettingsName(), szCache_ProcessViewerEvent, pProcessViewerEvent != nullptr);
kfh.SetUInt(GetSettingsName(), szCache_ProcessDialogEvent, pProcessDialogEvent != nullptr);
kfh.SetUInt(GetSettingsName(), szCache_Configure, pConfigure != nullptr);
kfh.SetUInt(GetSettingsName(), szCache_GetFiles, pGetFiles!=nullptr);
kfh.SetUInt(GetSettingsName(), szCache_ProcessHostFile, pProcessHostFile!=nullptr);
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions far2l/src/plug/PluginW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ static const char szCache_ProcessMacroFunc[] = "ProcessMacroFuncW";
static const char szCache_Configure[] = "ConfigureW";
static const char szCache_Analyse[] = "AnalyseW";
static const char szCache_GetCustomData[] = "GetCustomDataW";
static const char szCache_GetFiles[] = "GetFilesW";
static const char szCache_ProcessHostFile[] = "ProcessHostFileW";

static const char NFMP_OpenPlugin[] = "OpenPluginW";
static const char NFMP_OpenFilePlugin[] = "OpenFilePluginW";
Expand Down Expand Up @@ -200,6 +202,8 @@ bool PluginW::LoadFromCache()
pConfigureW = (PLUGINCONFIGUREW)(INT_PTR)kfh.GetUInt(szCache_Configure, 0);
pAnalyseW = (PLUGINANALYSEW)(INT_PTR)kfh.GetUInt(szCache_Analyse, 0);
pGetCustomDataW = (PLUGINGETCUSTOMDATAW)(INT_PTR)kfh.GetUInt(szCache_GetCustomData, 0);
pGetFilesW = (PLUGINGETFILESW)(INT_PTR)kfh.GetUInt(szCache_GetFiles, 0);
pProcessHostFileW = (PLUGINPROCESSHOSTFILEW)(INT_PTR)kfh.GetUInt(szCache_ProcessHostFile, 0);
WorkFlags.Set(PIWF_CACHED); // too much "cached" flags

if (kfh.GetInt(szCache_Preopen) != 0)
Expand Down Expand Up @@ -279,6 +283,8 @@ bool PluginW::SaveToCache()
kfh.SetUInt(GetSettingsName(), szCache_Configure, pConfigureW != nullptr);
kfh.SetUInt(GetSettingsName(), szCache_Analyse, pAnalyseW != nullptr);
kfh.SetUInt(GetSettingsName(), szCache_GetCustomData, pGetCustomDataW != nullptr);
kfh.SetUInt(GetSettingsName(), szCache_GetFiles, pGetFilesW!=nullptr);
kfh.SetUInt(GetSettingsName(), szCache_ProcessHostFile, pProcessHostFileW!=nullptr);

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions far2l/src/plug/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ HANDLE PluginManager::OpenFilePlugin(const wchar_t *Name, int OpMode, OPENFILEPL

if (!pPlugin->HasOpenFilePlugin() && !(pPlugin->HasAnalyse() && pPlugin->HasOpenPlugin()))
continue;
if ((Type == OFP_EXTRACT && !pPlugin->HasGetFiles()) || (Type == OFP_COMMANDS && !pPlugin->HasProcessHostFile()))
continue;

if (Name && !smm) {
try {
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/vmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ int VMenu::ProcessKey(FarKey Key)
case KEY_NUMENTER:
case KEY_ENTER: {
if (!ParentDialog || CheckFlags(VMENU_COMBOBOX)) {
if (ItemCanBeEntered(Item[SelectPos]->Flags)) {
if (SelectPos < 0 || ItemCanBeEntered(Item[SelectPos]->Flags)) {
EndLoop = TRUE;
Modal::ExitCode = SelectPos;
}
Expand Down

0 comments on commit 658c4f4

Please sign in to comment.