Skip to content

Commit

Permalink
1. если в DialogInit указать флаг FDLG_NONMODAL, то создастся и сразу…
Browse files Browse the repository at this point in the history
… запустится немодальный диалог.

   DialogRun и DialogFree для такого диалога указывать не нужно. при закрытии диалог автоматически уничтожается.
  • Loading branch information
zg0 committed Sep 28, 2017
1 parent 0fea9b2 commit ac08df3
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 59 deletions.
5 changes: 5 additions & 0 deletions far/changelog
@@ -1,3 +1,8 @@
zg 28.09.2017 19:22:53 FLE Daylight Time - build 5047

1. если в DialogInit указать флаг FDLG_NONMODAL, то создастся и сразу запустится немодальный диалог.
DialogRun и DialogFree для такого диалога указывать не нужно. при закрытии диалог автоматически уничтожается.

drkns 25.09.2017 22:30:09 +0100 - build 5046

1. И ещё одно уточнение 5038.
Expand Down
31 changes: 19 additions & 12 deletions far/dialog.cpp
Expand Up @@ -4208,24 +4208,31 @@ void Dialog::Process()

if (m_ExitCode == -1)
{
static std::atomic_long DialogsCount(0);
std::chrono::steady_clock::time_point btm;

DialogMode.Set(DMODE_BEGINLOOP);

if (!DialogsCount)
if(GetCanLoseFocus())
{
btm = std::chrono::steady_clock::now();
Global->WindowManager->InsertWindow(shared_from_this());
}
else
{
static std::atomic_long DialogsCount(0);
std::chrono::steady_clock::time_point btm;

++DialogsCount;
Global->WindowManager->ExecuteWindow(shared_from_this());
Global->WindowManager->ExecuteModal(shared_from_this());
--DialogsCount;
if (!DialogsCount)
{
btm = std::chrono::steady_clock::now();
}

if (!DialogsCount)
{
WaitUserTime += std::chrono::steady_clock::now() - btm;
++DialogsCount;
Global->WindowManager->ExecuteWindow(shared_from_this());
Global->WindowManager->ExecuteModal(shared_from_this());
--DialogsCount;

if (!DialogsCount)
{
WaitUserTime += std::chrono::steady_clock::now() - btm;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions far/manager.cpp
Expand Up @@ -759,7 +759,7 @@ bool Manager::ProcessKey(Key key)
}
case KEY_F12:
{
if (!std::dynamic_pointer_cast<Modal>(Global->WindowManager->GetCurrentWindow()))
if (!std::dynamic_pointer_cast<Modal>(Global->WindowManager->GetCurrentWindow()) || Global->WindowManager->GetCurrentWindow()->GetCanLoseFocus())
{
WindowMenu();
//_MANAGER(SysLog(-1));
Expand Down Expand Up @@ -1207,7 +1207,7 @@ Manager::sorted_windows Manager::GetSortedWindows(void) const

void* Manager::GetCurrent(const std::function<void*(windows::const_reverse_iterator)>& Check) const
{
const auto iterator = std::find_if(CONST_REVERSE_RANGE(m_windows, i) { return !std::dynamic_pointer_cast<Modal>(i); });
const auto iterator = std::find_if(CONST_REVERSE_RANGE(m_windows, i) { return !std::dynamic_pointer_cast<Modal>(i) || GetCurrentWindow()->GetCanLoseFocus(); });
if (iterator!=m_windows.crend())
{
return Check(iterator);
Expand Down
33 changes: 20 additions & 13 deletions far/plugapi.cpp
Expand Up @@ -1004,7 +1004,11 @@ HANDLE WINAPI apiDialogInit(const GUID* PluginId, const GUID* Id, intptr_t X1, i

if (FarDialog->InitOK())
{
Plugin->AddDialog(FarDialog);
if (Flags & FDLG_NONMODAL)
FarDialog->SetCanLoseFocus(TRUE);
else
Plugin->AddDialog(FarDialog);

hDlg = FarDialog.get();

FarDialog->SetPosition(X1,Y1,X2,Y2);
Expand All @@ -1024,16 +1028,16 @@ HANDLE WINAPI apiDialogInit(const GUID* PluginId, const GUID* Id, intptr_t X1, i
if (Flags & FDLG_KEEPCONSOLETITLE)
FarDialog->SetDialogMode(DMODE_KEEPCONSOLETITLE);

if (Flags & FDLG_NONMODAL)
FarDialog->SetCanLoseFocus(TRUE);

FarDialog->SetHelp(NullToEmpty(HelpTopic));

FarDialog->SetId(*Id);
/* $ 29.08.2000 SVS
Запомним номер плагина - сейчас в основном для формирования HelpTopic
*/
FarDialog->SetPluginOwner(GuidToPlugin(PluginId));

if (FarDialog->GetCanLoseFocus())
FarDialog->Process();
}
}
return hDlg;
Expand All @@ -1051,12 +1055,11 @@ intptr_t WINAPI apiDialogRun(HANDLE hDlg) noexcept

const auto FarDialog = static_cast<Dialog*>(hDlg);

FarDialog->Process();
int ExitCode = FarDialog->GetExitCode();

if (Global->IsMainThread()) // BUGBUG, findfile
Global->WindowManager->RefreshWindow(); //?? - //AY - это нужно чтоб обновлять панели после выхода из диалога
return ExitCode;
if (!FarDialog->GetCanLoseFocus())
{
FarDialog->Process();
return FarDialog->GetExitCode();
}
}
CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr())
return -1;
Expand All @@ -1068,9 +1071,13 @@ void WINAPI apiDialogFree(HANDLE hDlg) noexcept
{
if (hDlg != INVALID_HANDLE_VALUE)
{
const auto Dlg = static_cast<Dialog*>(hDlg)->shared_from_this();
const auto& Plugins = Global->CtrlObject->Plugins;
std::any_of(RANGE(*Plugins, i) { return i->RemoveDialog(Dlg); });
const auto FarDialog = static_cast<Dialog*>(hDlg);
if (!FarDialog->GetCanLoseFocus())
{
const auto Dlg = FarDialog->shared_from_this();
const auto& Plugins = Global->CtrlObject->Plugins;
std::any_of(RANGE(*Plugins, i) { return i->RemoveDialog(Dlg); });
}
}
}
CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr())
Expand Down
2 changes: 0 additions & 2 deletions far/plugin.hpp
Expand Up @@ -642,9 +642,7 @@ static const FARDIALOGFLAGS
FDLG_NODRAWSHADOW = 0x0000000000000004ULL,
FDLG_NODRAWPANEL = 0x0000000000000008ULL,
FDLG_KEEPCONSOLETITLE = 0x0000000000000010ULL,
#ifdef FAR_USE_INTERNALS
FDLG_NONMODAL = 0x0000000000000020ULL,
#endif // END FAR_USE_INTERNALS
FDLG_NONE = 0;

typedef intptr_t(WINAPI *FARWINDOWPROC)(
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,5046)m4_dnl
m4_define(BUILD,5047)m4_dnl
4 changes: 2 additions & 2 deletions plugins/luamacro/_globalinfo.lua
@@ -1,7 +1,7 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 616 },
MinFarVersion = { 3, 0, 0, 5013 },
Version = { 1, 0, 0, 617 },
MinFarVersion = { 3, 0, 0, 5047 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Description = "Far macros in Lua",
Expand Down
6 changes: 5 additions & 1 deletion plugins/luamacro/changelog
@@ -1,4 +1,8 @@
shmuel 27.08.2017 14:24:18 +0200 - build 616
zg 28.09.2017 19:12:08 FLE Daylight Time - build 617

1. поддержка немодальных диалогов.

shmuel 27.08.2017 14:24:18 +0200 - build 616

1. С форума:
lua:@empty.lua qwerty.asdf
Expand Down
74 changes: 49 additions & 25 deletions plugins/luamacro/luafar/service.c
Expand Up @@ -2856,6 +2856,7 @@ TDialogData* NewDialogData(lua_State* L, PSInfo *Info, HANDLE hDlg,
dd->hDlg = hDlg;
dd->isOwned = isOwned;
dd->wasError = FALSE;
dd->isModal = TRUE;
luaL_getmetatable(L, FarDialogType);
lua_setmetatable(L, -2);

Expand Down Expand Up @@ -3621,13 +3622,13 @@ intptr_t ProcessDNResult(lua_State *L, intptr_t Msg, void *Param2)
return ret;
}

intptr_t LF_DlgProc(lua_State *L, HANDLE hDlg, intptr_t Msg, intptr_t Param1, void *Param2)
static intptr_t DoDlgProc(lua_State *L, HANDLE hDlg, intptr_t Msg, intptr_t Param1, void *Param2)
{
intptr_t ret;
PSInfo *Info = GetPluginData(L)->Info;
TDialogData *dd = (TDialogData*) Info->SendDlgMessage(hDlg,DM_GETDLGDATA,0,0);

if(dd->wasError)
if(!dd || dd->wasError)
return Info->DefDlgProc(hDlg, Msg, Param1, Param2);

L = dd->L; // the dialog may be called from a lua_State other than the main one
Expand Down Expand Up @@ -3661,6 +3662,30 @@ intptr_t LF_DlgProc(lua_State *L, HANDLE hDlg, intptr_t Msg, intptr_t Param1, vo
return ret;
}

static void RemoveDialogFromRegistry(lua_State *L, TDialogData *dd)
{
dd->hDlg = INVALID_HANDLE_VALUE;
lua_pushlightuserdata(L, dd);
lua_pushnil(L);
lua_rawset(L, LUA_REGISTRYINDEX);
}

intptr_t LF_DlgProc(lua_State *L, HANDLE hDlg, intptr_t Msg, intptr_t Param1, void *Param2)
{
intptr_t ret=DoDlgProc(L, hDlg, Msg, Param1, Param2);
if (Msg == DN_CLOSE && ret)
{
PSInfo *Info = GetPluginData(L)->Info;
TDialogData *dd = (TDialogData*) Info->SendDlgMessage(hDlg,DM_GETDLGDATA,0,0);
if (dd && !dd->isModal)
{
Info->SendDlgMessage(hDlg, DM_SETDLGDATA, 0, 0);
RemoveDialogFromRegistry(L, dd);
}
}
return ret;
}

static int far_DialogInit(lua_State *L)
{
intptr_t ItemsNumber, i;
Expand Down Expand Up @@ -3708,6 +3733,7 @@ static int far_DialogInit(lua_State *L)
// 8-th parameter (flags)
Flags = CheckFlags(L, 8);
dd = NewDialogData(L, pd->Info, INVALID_HANDLE_VALUE, TRUE);
dd->isOwned = (Flags&0x20) == 0;
// 9-th parameter (DlgProc function)
Proc = NULL;
Param = NULL;
Expand All @@ -3718,29 +3744,30 @@ static int far_DialogInit(lua_State *L)
Param = dd;
}

dd->hDlg = pd->Info->DialogInit(pd->PluginId, &Id, X1, Y1, X2, Y2, HelpTopic,
Items, ItemsNumber, 0, Flags, Proc, Param);
// Put some values into the registry
lua_pushlightuserdata(L, dd); // important: index it with dd
lua_createtable(L, 3, 0);
lua_pushvalue(L, 1); // store the "histories" table
lua_rawseti(L, -2, 1);

if(dd->hDlg != INVALID_HANDLE_VALUE)
if(lua_isfunction(L, 9))
{
// Put some values into the registry
lua_pushlightuserdata(L, dd); // important: index it with dd
lua_createtable(L, 3, 0);
lua_pushvalue(L, 1); // store the "histories" table
lua_rawseti(L, -2, 1);
lua_pushvalue(L, 9); // store the procedure
lua_rawseti(L, -2, 2);
lua_pushvalue(L, -3); // store the handle
lua_rawseti(L, -2, 3);
}

if(lua_isfunction(L, 9))
{
lua_pushvalue(L, 9); // store the procedure
lua_rawseti(L, -2, 2);
lua_pushvalue(L, -3); // store the handle
lua_rawseti(L, -2, 3);
}
lua_rawset(L, LUA_REGISTRYINDEX);

lua_rawset(L, LUA_REGISTRYINDEX);
}
else
dd->hDlg = pd->Info->DialogInit(pd->PluginId, &Id, X1, Y1, X2, Y2, HelpTopic,
Items, ItemsNumber, 0, Flags, Proc, Param);

if(dd->hDlg == INVALID_HANDLE_VALUE)
{
RemoveDialogFromRegistry(L, dd);
lua_pushnil(L);
}

return 1;
}
Expand All @@ -3749,13 +3776,10 @@ static void free_dialog(TDialogData* dd)
{
lua_State* L = dd->L;

if(dd->isOwned && dd->hDlg != INVALID_HANDLE_VALUE)
if(dd->isOwned && dd->isModal && dd->hDlg != INVALID_HANDLE_VALUE)
{
dd->Info->DialogFree(dd->hDlg);
dd->hDlg = INVALID_HANDLE_VALUE;
lua_pushlightuserdata(L, dd);
lua_pushnil(L);
lua_rawset(L, LUA_REGISTRYINDEX);
RemoveDialogFromRegistry(L, dd);
}
}

Expand Down
1 change: 1 addition & 0 deletions plugins/luamacro/luafar/util.h
Expand Up @@ -58,6 +58,7 @@ typedef struct
HANDLE hDlg;
BOOL isOwned;
BOOL wasError;
BOOL isModal;
} TDialogData;

int GetAttrFromTable(lua_State *L);
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luamacro.rc
@@ -1,6 +1,6 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 616
#define PLUGIN_BUILD 617
#define PLUGIN_DESC "Lua Macros for Far Manager"
#define PLUGIN_NAME "LuaMacro"
#define PLUGIN_FILENAME "luamacro.dll"
Expand Down

0 comments on commit ac08df3

Please sign in to comment.