Skip to content

Commit

Permalink
1. Не теряем уже введённый текст при прокрутке истории в комстроке.
Browse files Browse the repository at this point in the history
2. Рефакторинг.
3. Warnings.
  • Loading branch information
alabuzhev committed Sep 24, 2015
1 parent 0c6f1ca commit 9c32c0f
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 77 deletions.
10 changes: 9 additions & 1 deletion far/changelog
@@ -1,4 +1,12 @@
drkns 23.09.2015 02:45:20 +0200 - build 4425
drkns 24.09.2015 22:50:09 +0200 - build 4426

1. Не теряем уже введённый текст при прокрутке истории в комстроке.

2. Рефакторинг.

3. Warnings.

drkns 23.09.2015 02:45:20 +0200 - build 4425

1. Рефакторинг.

Expand Down
26 changes: 6 additions & 20 deletions far/clipboard.cpp
Expand Up @@ -338,34 +338,20 @@ bool Clipboard::Get(string& data)
{
if (const auto Files = os::memory::global::lock<const LPDROPFILES>(hClipData))
{
auto StartA=reinterpret_cast<const char*>(Files.get())+Files->pFiles;
auto Start = reinterpret_cast<const wchar_t*>(StartA);
const auto StartA=reinterpret_cast<const char*>(Files.get())+Files->pFiles;
const auto Start = reinterpret_cast<const wchar_t*>(StartA);
if(Files->fWide)
{
while(*Start)
FOR(const auto& i, os::enum_strings(Start))
{
size_t l1=data.size();
data+=Start;
Start+=data.size()-l1;
Start++;
if(*Start)
{
data+=L"\r\n";
}
data.append(i.data(), i.size()).append(L"\r\n");
}
}
else
{
while(*StartA)
FOR(const auto& i, (os::enum_strings_t<const char*, const char*>(StartA)))
{
size_t l1=data.size();
data+=wide(StartA);
StartA+=data.size()-l1;
StartA++;
if(*StartA)
{
data+=L"\r\n";
}
data.append(wide(std::string(i.data(), i.size()))).append(L"\r\n");
}
}
Result = true;
Expand Down
12 changes: 8 additions & 4 deletions far/cmdline.cpp
Expand Up @@ -233,6 +233,11 @@ int CommandLine::ProcessKey(const Manager::Key& Key)
case KEY_CTRLX:
case KEY_RCTRLX:
{
if (Global->CtrlObject->CmdHistory->IsOnTop())
{
CmdStr.GetString(m_CurCmdStr);
}

if (LocalKey == KEY_CTRLE || LocalKey == KEY_RCTRLE)
{
Global->CtrlObject->CmdHistory->GetPrev(strStr);
Expand All @@ -244,7 +249,7 @@ int CommandLine::ProcessKey(const Manager::Key& Key)

{
SCOPED_ACTION(SetAutocomplete)(&CmdStr);
SetString(strStr);
SetString(Global->CtrlObject->CmdHistory->IsOnTop()? m_CurCmdStr : strStr);
}

}
Expand Down Expand Up @@ -1009,10 +1014,9 @@ int CommandLine::ProcessOSCommands(const string& CmdLine, bool SeparateWindow, b
string strOut(L"\n");
FOR(const auto& i, os::env::enum_strings())
{
size_t ItemLength = wcslen(i);
if (!StrCmpNI(i, strCmdLine.data(), strCmdLine.size()))
if (!StrCmpNI(i.data(), strCmdLine.data(), strCmdLine.size()))
{
strOut.append(i, ItemLength).append(L"\n");
strOut.append(i.data(), i.size()).append(L"\n");
}
}
strOut.append(L"\n\n", Global->Opt->ShowKeyBar?2:1);
Expand Down
1 change: 1 addition & 0 deletions far/cmdline.hpp
Expand Up @@ -81,5 +81,6 @@ class CommandLine:public SimpleScreenObject
string m_CurDir;
string strLastCmdStr;
int LastCmdPartLength;
string m_CurCmdStr;
std::stack<string> ppstack;
};
2 changes: 1 addition & 1 deletion far/copy.cpp
Expand Up @@ -709,7 +709,7 @@ intptr_t ShellCopy::CopyDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* P
{
if (Param1==ID_SC_USEFILTER) // "Use filter"
{
m_UseFilter = static_cast<int>(reinterpret_cast<intptr_t>(Param2)) == BSTATE_CHECKED;
m_UseFilter = static_cast<FARCHECKEDSTATE>(reinterpret_cast<intptr_t>(Param2)) == BSTATE_CHECKED;
return TRUE;
}

Expand Down
2 changes: 1 addition & 1 deletion far/dialog.cpp
Expand Up @@ -4970,7 +4970,7 @@ intptr_t Dialog::SendMessage(intptr_t Msg,intptr_t Param1,void* Param2)
return Global->IsProcessAssignMacroKey;

BOOL OldIsProcessAssignMacroKey=Global->IsProcessAssignMacroKey;
Global->IsProcessAssignMacroKey=Param1;
Global->IsProcessAssignMacroKey = Param1 != 0;
return OldIsProcessAssignMacroKey;
}
/*****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion far/editcontrol.cpp
Expand Up @@ -375,7 +375,7 @@ static bool EnumEnvironment(VMenu2& Menu, const string& Str)
std::set<string, string_i_less> ResultStrings;
FOR(const auto& i, os::env::enum_strings())
{
auto VarName = L"%" + os::env::split(i).first + L"%";
auto VarName = L"%" + os::env::split(i.data()).first + L"%";

if (!StrCmpNI(Token, VarName.data(), TokenSize))
{
Expand Down
4 changes: 2 additions & 2 deletions far/editor.cpp
Expand Up @@ -2585,8 +2585,8 @@ int Editor::ProcessKey(const Manager::Key& Key)
BeginStreamMarking(m_it_CurLine);
//SelFirst=TRUE;
//BUGBUG, never used
SelStart = static_cast<int>(SBegin);
SelEnd = static_cast<int>(SEnd - 1);
SelStart = SBegin;
SelEnd = SEnd - 1;
}
}

Expand Down
9 changes: 4 additions & 5 deletions far/farwinapi.cpp
Expand Up @@ -1438,10 +1438,9 @@ std::vector<string> GetLogicalDriveStrings()
Ptr = vBuffer.get();
}

while(*Ptr)
FOR(const auto& i, os::enum_strings(Ptr))
{
Result.emplace_back(Ptr);
Ptr += wcslen(Ptr) + 1;
Result.emplace_back(string(i.data(), i.size()));
}
}
return Result;
Expand Down Expand Up @@ -1929,7 +1928,7 @@ DWORD GetAppPathsRedirectionFlag()

provider::strings::~strings()
{
FreeEnvironmentStrings(get());
FreeEnvironmentStrings(*this);
}

provider::block::block()
Expand All @@ -1945,7 +1944,7 @@ DWORD GetAppPathsRedirectionFlag()

provider::block::~block()
{
DestroyEnvironmentBlock(get());
DestroyEnvironmentBlock(*this);
}

std::pair<string, string> split(const wchar_t* Line)
Expand Down
39 changes: 23 additions & 16 deletions far/farwinapi.hpp
Expand Up @@ -466,15 +466,36 @@ namespace os
};
}

// enumerator for string1\0string2\0string3\0...stringN\0\0
template<class Provider, class ResultType = const wchar_t*>
class enum_strings_t: noncopyable, public enumerator<enum_strings_t<Provider, ResultType>, range<ResultType>>
{
public:
enum_strings_t() {}
enum_strings_t(Provider Data): m_Provider(Data) {}
bool get(size_t index, typename enum_strings_t<Provider, ResultType>::value_type& value)
{
auto Begin = index? value.data() + value.size() + 1 : m_Provider, End = Begin;
while (*End) ++End;
value = enum_strings_t<Provider, ResultType>::value_type(Begin, End);
return !value.empty();
}

private:
const Provider m_Provider;
};

typedef enum_strings_t<const wchar_t*> enum_strings;

namespace env
{
namespace detail
{
class provider
{
public:
const wchar_t* get() const { return m_Environment; }
wchar_t* get() { return m_Environment; }
operator const wchar_t*() const { return m_Environment; }
operator wchar_t*() { return m_Environment; }

protected:
wchar_t* m_Environment;
Expand All @@ -500,20 +521,6 @@ namespace os

std::pair<string, string> split(const wchar_t* Line);

template<class T>
class enum_strings_t: noncopyable, public enumerator<enum_strings_t<T>, const wchar_t*>
{
public:
enum_strings_t() {}
bool get(size_t index, typename enum_strings_t<T>::value_type& value)
{
return *(value = index? value + wcslen(value) + 1 : m_Provider.get()) != L'\0';
}

private:
const T m_Provider;
};

typedef enum_strings_t<provider::strings> enum_strings;

bool get_variable(const wchar_t* Name, string& strBuffer);
Expand Down
17 changes: 3 additions & 14 deletions far/filelist.cpp
Expand Up @@ -6019,21 +6019,10 @@ void FileList::PluginPutFilesToNew()
int n = 0;
std::for_each(CONST_RANGE(m_ListData, i)
{
if ((i.FileAttr & FILE_ATTRIBUTE_DIRECTORY) == 0)
if (!(i.FileAttr & FILE_ATTRIBUTE_DIRECTORY) && (!PtrLastPos || PtrLastPos->CreationTime < i.CreationTime))
{
if (PtrLastPos)
{
if (PtrLastPos->CreationTime < i.CreationTime)
{
LastPos = n;
PtrLastPos = &i;
}
}
else
{
LastPos = n;
PtrLastPos = &i;
}
LastPos = n;
PtrLastPos = &i;
}
++n;
});
Expand Down
1 change: 1 addition & 0 deletions far/history.hpp
Expand Up @@ -87,6 +87,7 @@ class History: noncopyable
void ResetPosition() { m_CurrentItem = 0; }
bool DeleteIfUnlocked(unsigned __int64 id);
bool ReadLastItem(const string& HistoryName, string &strStr) const;
bool IsOnTop() const { return !m_CurrentItem; }

static void CompactHistory();

Expand Down
4 changes: 2 additions & 2 deletions far/hotplug.cpp
Expand Up @@ -248,10 +248,10 @@ static DWORD GetRelationDrivesMask(DEVINST hDevInst)
wchar_t_ptr DeviceIdList(dwSize);
if (CM_Get_Device_ID_List(szDeviceID, DeviceIdList.get(), dwSize, CM_GETIDLIST_FILTER_REMOVALRELATIONS) == CR_SUCCESS)
{
for (auto p = DeviceIdList.get(); *p; p += wcslen(p) + 1)
FOR(const auto& i, (os::enum_strings_t<wchar_t*, wchar_t*>(DeviceIdList.get())))
{
DEVINST hRelationDevInst;
if (CM_Locate_DevNode(&hRelationDevInst, p, 0) == CR_SUCCESS)
if (CM_Locate_DevNode(&hRelationDevInst, i.data(), 0) == CR_SUCCESS)
dwMask |= GetDriveMaskFromMountPoints(hRelationDevInst);
}
}
Expand Down
3 changes: 1 addition & 2 deletions far/local.cpp
Expand Up @@ -63,8 +63,7 @@ const string& GetSpacesAndEols()

static const std::vector<wchar_t> create_alt_sort_table()
{
FN_RETURN_TYPE(create_alt_sort_table) alt_sort_table(WCHAR_MAX + 1);
decltype(alt_sort_table) chars(WCHAR_MAX + 1);
FN_RETURN_TYPE(create_alt_sort_table) alt_sort_table(WCHAR_MAX + 1), chars(alt_sort_table.size());

std::iota(ALL_RANGE(chars), 0);

Expand Down
2 changes: 1 addition & 1 deletion far/macro.cpp
Expand Up @@ -4529,7 +4529,7 @@ static bool replaceFunc(FarMacroCall* Data)
const auto Count = Params[3].asInteger();
const auto IgnoreCase = !Params[4].asInteger();

ReplaceStrings(Src, Find, Repl, IgnoreCase, Count <= 0 ? string::npos : static_cast<int>(Count));
ReplaceStrings(Src, Find, Repl, IgnoreCase, Count <= 0 ? string::npos : static_cast<size_t>(Count));
PassString(Src, Data);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions far/mix.cpp
Expand Up @@ -209,9 +209,9 @@ void ReloadEnvironment()
return std::make_pair(i, os::env::get_variable(i));
});

FOR(const auto& i, os::env::enum_strings_t<os::env::provider::block>())
FOR(const auto& i, (os::enum_strings_t<os::env::provider::block>()))
{
const auto Data = os::env::split(i);
const auto Data = os::env::split(i.data());
os::env::set_variable(Data.first, Data.second);
}

Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4425)m4_dnl
m4_define(BUILD,4426)m4_dnl
6 changes: 3 additions & 3 deletions far/viewer.cpp
Expand Up @@ -369,7 +369,7 @@ int Viewer::OpenFile(const string& Name,int warning)
if (m_Codepage == CP_DEFAULT)
m_Codepage = GetDefaultCodePage();

MB.SetCP(static_cast<UINT>(m_Codepage));
MB.SetCP(m_Codepage);
}

ViewFile.SetPointer(0, nullptr, FILE_BEGIN);
Expand Down Expand Up @@ -1703,7 +1703,7 @@ int Viewer::process_key(const Manager::Key& Key)
case KEY_F8:
{
m_Codepage = f8cps.NextCP(m_Codepage);
MB.SetCP(static_cast<UINT>(m_Codepage));
MB.SetCP(m_Codepage);
lcache_ready = false;
AdjustFilePos();
ChangeViewKeyBar();
Expand All @@ -1724,7 +1724,7 @@ int Viewer::process_key(const Manager::Key& Key)
nCodePage = GetDefaultCodePage();
}
m_Codepage = nCodePage;
MB.SetCP(static_cast<UINT>(m_Codepage));
MB.SetCP(m_Codepage);
lcache_ready = false;
AdjustFilePos();
ChangeViewKeyBar();
Expand Down
1 change: 0 additions & 1 deletion far/vmenu.cpp
Expand Up @@ -848,7 +848,6 @@ __int64 VMenu::VMProcess(int OpCode,void *vParam,__int64 iParam)
Res = 0;
strTemp = HiText2Str(Item.strName);
RemoveExternalSpaces(strTemp);
string::const_iterator p;

switch (iParam)
{
Expand Down

0 comments on commit 9c32c0f

Please sign in to comment.