Skip to content

Commit

Permalink
Remove more fake dialogs; minor performance optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Aug 2, 2021
1 parent 21c2022 commit fe709b2
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 230 deletions.
7 changes: 7 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
--------------------------------------------------------------------------------
drkns 02.08.2021 21:01:36 +0100 - build 5865

1. Remove more fake dialogs.

2. Minor performance optimisations.

--------------------------------------------------------------------------------
drkns 01.08.2021 15:34:13 +0100 - build 5864

Expand Down
9 changes: 7 additions & 2 deletions far/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3335,11 +3335,16 @@ std::pair<unsigned long long, unsigned long long> ShellCopy::CalcTotalSize() con
unsigned long long Files{}, Bytes{};

const time_check TimeCheck;
dirinfo_progress const DirinfoProgress(msg(Flags & FCOPY_MOVE? lng::MMoveDlgTitle : lng::MCopyDlgTitle));

const auto DirInfoCallback = [&](string_view const Name, unsigned long long const ItemsCount, unsigned long long const Size)
{
if (TimeCheck)
DirInfoMsg(msg(Flags & FCOPY_MOVE? lng::MMoveDlgTitle : lng::MCopyDlgTitle), Name, Files + ItemsCount, Bytes + Size);
if (!TimeCheck)
return;

DirinfoProgress.set_name(Name);
DirinfoProgress.set_count(Files + ItemsCount);
DirinfoProgress.set_size(Bytes + Size);
};

for (const auto& i: SrcPanel->enum_selected())
Expand Down
6 changes: 0 additions & 6 deletions far/copy_progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ copy_progress::copy_progress(bool Move, bool Total, bool Time):

}

copy_progress::~copy_progress()
{
if (m_Dialog)
m_Dialog->CloseDialog();
}

size_t copy_progress::CanvasWidth()
{
return DlgW - 10;
Expand Down
6 changes: 2 additions & 4 deletions far/copy_progress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,23 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "taskbar.hpp"
#include "wakeful.hpp"
#include "datetime.hpp"
#include "plugin.hpp"
#include "windowsfwd.hpp"
#include "stddlg.hpp"

// Platform:

// Common:
#include "common/2d/rectangle.hpp"

// External:

//----------------------------------------------------------------------------

enum class lng;

class copy_progress: noncopyable
class copy_progress: progress_impl
{
public:
copy_progress(bool Move, bool Total, bool Time);
~copy_progress();

bool IsCancelled() const { return m_IsCancelled; }
bool IsTotalVisible() const { return m_Total; }
Expand Down
9 changes: 7 additions & 2 deletions far/delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,16 @@ static total_items calculate_total(panel_ptr const SrcPanel)

const time_check TimeCheck;
total_items Total;
dirinfo_progress const DirinfoProgress(msg(lng::MDeletingTitle));

const auto DirInfoCallback = [&](string_view const Name, unsigned long long const ItemsCount, unsigned long long const Size)
{
if (TimeCheck)
DirInfoMsg(msg(lng::MDeletingTitle), Name, Total.Items + ItemsCount, Total.Size + Size);
if (!TimeCheck)
return;

DirinfoProgress.set_name(Name);
DirinfoProgress.set_count(Total.Items + ItemsCount);
DirinfoProgress.set_size(Total.Size + Size);
};

// BUGBUG
Expand Down
45 changes: 22 additions & 23 deletions far/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4204,34 +4204,33 @@ void Dialog::Process()
TBE.emplace(TBPF_ERROR);
}

if (m_ExitCode == -1)
if (m_ExitCode != -1)
return;

DialogMode.Set(DMODE_BEGINLOOP);

if(GetCanLoseFocus())
{
DialogMode.Set(DMODE_BEGINLOOP);
Global->WindowManager->InsertWindow(shared_from_this());
return;
}

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

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

++DialogsCount;
Global->WindowManager->ExecuteWindow(shared_from_this());
Global->WindowManager->ExecuteModal(shared_from_this());
--DialogsCount;
++DialogsCount;
Global->WindowManager->ExecuteWindow(shared_from_this());
Global->WindowManager->ExecuteModal(shared_from_this());
--DialogsCount;

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

if (SavedItems)
Expand Down
101 changes: 23 additions & 78 deletions far/dirinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Internal:
#include "keys.hpp"
#include "scantree.hpp"
#include "TPreRedrawFunc.hpp"
#include "ctrlobj.hpp"
#include "filefilter.hpp"
#include "interf.hpp"
Expand All @@ -60,6 +59,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cvtname.hpp"
#include "copy_progress.hpp"
#include "global.hpp"
#include "dialog.hpp"

// Platform:
#include "platform.fs.hpp"
Expand All @@ -71,58 +71,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//----------------------------------------------------------------------------

static void PR_DrawGetDirInfoMsg();

struct DirInfoPreRedrawItem : public PreRedrawItem
{
DirInfoPreRedrawItem():
PreRedrawItem(PR_DrawGetDirInfoMsg)
{}

string_view Title;
string_view Name;
unsigned long long Items{};
unsigned long long Size{};
};

static void DirInfoMsgImpl(string_view const Title, string_view const Name, unsigned long long const Items, unsigned long long const Size)
{
Message(MSG_LEFTALIGN,
Title,
{
msg(lng::MScanningFolder),
pad_right(truncate_right(Name, copy_progress::CanvasWidth()), copy_progress::CanvasWidth()),
L"\1"s,
copy_progress::FormatCounter(lng::MCopyFilesTotalInfo, lng::MCopyBytesTotalInfo, Items, 0, false, copy_progress::CanvasWidth() - 5),
copy_progress::FormatCounter(lng::MCopyBytesTotalInfo, lng::MCopyFilesTotalInfo, Size, 0, false, copy_progress::CanvasWidth() - 5),
},
{});
}

void DirInfoMsg(string_view const Title, string_view const Name, unsigned long long const Items, unsigned long long const Size)
{
DirInfoMsgImpl(Title, Name, Items, Size);

TPreRedrawFunc::instance()([&](DirInfoPreRedrawItem& Item)
{
Item.Title = Title;
Item.Name = Name;
Item.Items = Items;
Item.Size = Size;
});
}

static void PR_DrawGetDirInfoMsg()
{
TPreRedrawFunc::instance()([](const DirInfoPreRedrawItem& Item)
{
DirInfoMsgImpl(Item.Title, Item.Name, Item.Items, Item.Size);
});
}

int GetDirInfo(string_view const DirName, DirInfoData& Data, FileFilter *Filter, dirinfo_callback const Callback, DWORD Flags)
{
SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique<DirInfoPreRedrawItem>());
SCOPED_ACTION(taskbar::indeterminate)(false);
SCOPED_ACTION(wakeful);

Expand Down Expand Up @@ -402,42 +352,37 @@ static bool GetPluginDirListImpl(Plugin* PluginNumber, HANDLE hPlugin, string_vi
hDirListPlugin = DirListPlugin.get();
}

bool StopSearch = false;

{
SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique<DirInfoPreRedrawItem>());
{
const auto strDirName = fit_to_center(truncate_left(Dir, 30), 30);
SetCursorType(false, 0);
PluginSearchMsgOut=FALSE;
const auto strDirName = fit_to_center(truncate_left(Dir, 30), 30);
SetCursorType(false, 0);
PluginSearchMsgOut=FALSE;

OpenPanelInfo Info;
Global->CtrlObject->Plugins->GetOpenPanelInfo(hDirListPlugin,&Info);
const string strPrevDir = NullToEmpty(Info.CurDir);
OpenPanelInfo Info;
Global->CtrlObject->Plugins->GetOpenPanelInfo(hDirListPlugin,&Info);
const string strPrevDir = NullToEmpty(Info.CurDir);

if (Global->CtrlObject->Plugins->SetDirectory(hDirListPlugin, string(Dir), OPM_SILENT | OpMode, UserData))
{
ScanPluginDir(hDirListPlugin, OpMode, Dir, Dir, Items, StopSearch, Data, Callback);
if (!Global->CtrlObject->Plugins->SetDirectory(hDirListPlugin, string(Dir), OPM_SILENT | OpMode, UserData))
return false;

Global->CtrlObject->Plugins->SetDirectory(hDirListPlugin, L".."s, OPM_SILENT | OpMode);
bool StopSearch = false;
ScanPluginDir(hDirListPlugin, OpMode, Dir, Dir, Items, StopSearch, Data, Callback);

OpenPanelInfo NewInfo;
Global->CtrlObject->Plugins->GetOpenPanelInfo(hDirListPlugin,&NewInfo);
Global->CtrlObject->Plugins->SetDirectory(hDirListPlugin, L".."s, OPM_SILENT | OpMode);

if (!equal_icase(strPrevDir, NullToEmpty(NewInfo.CurDir)))
{
span<PluginPanelItem> PanelData;
OpenPanelInfo NewInfo;
Global->CtrlObject->Plugins->GetOpenPanelInfo(hDirListPlugin,&NewInfo);

if (Global->CtrlObject->Plugins->GetFindData(hDirListPlugin, PanelData, OPM_SILENT | OpMode))
{
Global->CtrlObject->Plugins->FreeFindData(hDirListPlugin, PanelData, true);
}
if (!equal_icase(strPrevDir, NullToEmpty(NewInfo.CurDir)))
{
span<PluginPanelItem> PanelData;

Global->CtrlObject->Plugins->SetDirectory(hDirListPlugin,strPrevDir,OPM_SILENT|OpMode,&Info.UserData);
}
}
if (Global->CtrlObject->Plugins->GetFindData(hDirListPlugin, PanelData, OPM_SILENT | OpMode))
{
Global->CtrlObject->Plugins->FreeFindData(hDirListPlugin, PanelData, true);
}

Global->CtrlObject->Plugins->SetDirectory(hDirListPlugin,strPrevDir,OPM_SILENT|OpMode,&Info.UserData);
}

return !StopSearch;
}

Expand Down
8 changes: 0 additions & 8 deletions far/dirinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,8 @@ struct DirInfoData: public BasicDirInfoData
unsigned long long ClusterSize{};
};

enum getdirinfo_message_delay
{
getdirinfo_infinite_delay = -1,
getdirinfo_no_delay = 0,
getdirinfo_default_delay = 500, // ms
};

using dirinfo_callback = function_ref<void(string_view Name, unsigned long long Items, unsigned long long Size)>;
int GetDirInfo(string_view DirName, DirInfoData& Data, FileFilter *Filter, dirinfo_callback Callback, DWORD Flags = GETDIRINFO_SCANSYMLINKDEF);
void DirInfoMsg(string_view Title, string_view Name, unsigned long long Items, unsigned long long Size);

class plugin_panel;

Expand Down
1 change: 0 additions & 1 deletion far/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "poscache.hpp"
#include "bitflags.hpp"
#include "config.hpp"
#include "TPreRedrawFunc.hpp"
#include "mix.hpp"
#include "eol.hpp"

Expand Down
10 changes: 8 additions & 2 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5083,10 +5083,16 @@ void FileList::CountDirSize(bool IsRealNames)
}
Total{};

dirinfo_progress const DirinfoProgress(msg(lng::MDirInfoViewTitle));

const auto DirInfoCallback = [&](string_view const Name, unsigned long long const ItemsCount, unsigned long long const Size)
{
if (TimeCheck)
DirInfoMsg(msg(lng::MDirInfoViewTitle), Name, Total.Items + ItemsCount, Total.Size + Size);
if (!TimeCheck)
return;

DirinfoProgress.set_name(Name);
DirinfoProgress.set_count(Total.Items + ItemsCount);
DirinfoProgress.set_size(Total.Size + Size);
};

for (auto& i: m_ListData)
Expand Down
9 changes: 7 additions & 2 deletions far/plugapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,11 +1664,16 @@ intptr_t WINAPI apiGetPluginDirList(const UUID* PluginId, HANDLE hPlugin, const
// BUGBUG This is API, shouldn't the callback be empty?

const time_check TimeCheck;
dirinfo_progress const DirinfoProgress(msg(lng::MPreparingList));

const auto DirInfoCallback = [&](string_view const Name, unsigned long long const ItemsCount, unsigned long long const Size)
{
if (TimeCheck)
DirInfoMsg(msg(lng::MPreparingList), Name, ItemsCount, Size);
if (!TimeCheck)
return;

DirinfoProgress.set_name(Name);
DirinfoProgress.set_count(ItemsCount);
DirinfoProgress.set_size(Size);
};

const auto Result = GetPluginDirList(UuidToPlugin(PluginId), hPlugin, Dir, nullptr, *Items, DirInfoCallback);
Expand Down
10 changes: 8 additions & 2 deletions far/qview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "global.hpp"
#include "exception.hpp"
#include "log.hpp"
#include "stddlg.hpp"


// Platform:
Expand Down Expand Up @@ -400,11 +401,16 @@ void QuickView::ShowFile(string_view const FileName, const UserDataItem* const U
if (hDirPlugin || os::fs::is_directory(strCurFileName))
{
const time_check TimeCheck;
dirinfo_progress const DirinfoProgress(msg(lng::MQuickViewTitle));

const auto DirInfoCallback = [&](string_view const Name, unsigned long long const ItemsCount, unsigned long long const Size)
{
if (TimeCheck)
DirInfoMsg(msg(lng::MQuickViewTitle), Name, ItemsCount, Size);
if (!TimeCheck)
return;

DirinfoProgress.set_name(Name);
DirinfoProgress.set_count(ItemsCount);
DirinfoProgress.set_size(Size);
};

if (SameFile && !hDirPlugin)
Expand Down
3 changes: 3 additions & 0 deletions far/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ static auto view(const void* const Data, int const Size)
template<auto comparer>
static int combined_comparer(void* const Param, int const Size1, const void* const Data1, int const Size2, const void* const Data2)
{
if (view<char>(Data1, Size1) == view<char>(Data2, Size2))
return 0;

if (reinterpret_cast<intptr_t>(Param) == SQLITE_UTF16)
{
return comparer(
Expand Down
Loading

0 comments on commit fe709b2

Please sign in to comment.