From 9c32c0f62920c9c8fbc101b91fe675712c99d340 Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Thu, 24 Sep 2015 19:57:10 +0000 Subject: [PATCH] =?UTF-8?q?1.=20=D0=9D=D0=B5=20=D1=82=D0=B5=D1=80=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=83=D0=B6=D0=B5=20=D0=B2=D0=B2=D0=B5=D0=B4?= =?UTF-8?q?=D1=91=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=82=D0=B5=D0=BA=D1=81=D1=82?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D0=BF=D1=80=D0=BE=D0=BA=D1=80=D1=83?= =?UTF-8?q?=D1=82=D0=BA=D0=B5=20=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=BE=D0=BC=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D0=B5.=202.=20=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3.=203.=20Warnings.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- far/changelog | 10 +++++++++- far/clipboard.cpp | 26 ++++++-------------------- far/cmdline.cpp | 12 ++++++++---- far/cmdline.hpp | 1 + far/copy.cpp | 2 +- far/dialog.cpp | 2 +- far/editcontrol.cpp | 2 +- far/editor.cpp | 4 ++-- far/farwinapi.cpp | 9 ++++----- far/farwinapi.hpp | 39 +++++++++++++++++++++++---------------- far/filelist.cpp | 17 +++-------------- far/history.hpp | 1 + far/hotplug.cpp | 4 ++-- far/local.cpp | 3 +-- far/macro.cpp | 2 +- far/mix.cpp | 4 ++-- far/vbuild.m4 | 2 +- far/viewer.cpp | 6 +++--- far/vmenu.cpp | 1 - 19 files changed, 70 insertions(+), 77 deletions(-) diff --git a/far/changelog b/far/changelog index b81392d323..27dfedbeed 100644 --- a/far/changelog +++ b/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. Рефакторинг. diff --git a/far/clipboard.cpp b/far/clipboard.cpp index 22d90f36f8..59311c19bd 100644 --- a/far/clipboard.cpp +++ b/far/clipboard.cpp @@ -338,34 +338,20 @@ bool Clipboard::Get(string& data) { if (const auto Files = os::memory::global::lock(hClipData)) { - auto StartA=reinterpret_cast(Files.get())+Files->pFiles; - auto Start = reinterpret_cast(StartA); + const auto StartA=reinterpret_cast(Files.get())+Files->pFiles; + const auto Start = reinterpret_cast(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(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; diff --git a/far/cmdline.cpp b/far/cmdline.cpp index 7479fda461..e95187099b 100644 --- a/far/cmdline.cpp +++ b/far/cmdline.cpp @@ -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); @@ -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); } } @@ -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); diff --git a/far/cmdline.hpp b/far/cmdline.hpp index 29048548d9..2af602ff71 100644 --- a/far/cmdline.hpp +++ b/far/cmdline.hpp @@ -81,5 +81,6 @@ class CommandLine:public SimpleScreenObject string m_CurDir; string strLastCmdStr; int LastCmdPartLength; + string m_CurCmdStr; std::stack ppstack; }; diff --git a/far/copy.cpp b/far/copy.cpp index 48da1147e5..b0e6cb0ca5 100644 --- a/far/copy.cpp +++ b/far/copy.cpp @@ -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(reinterpret_cast(Param2)) == BSTATE_CHECKED; + m_UseFilter = static_cast(reinterpret_cast(Param2)) == BSTATE_CHECKED; return TRUE; } diff --git a/far/dialog.cpp b/far/dialog.cpp index b7c1516137..b34b0e6744 100644 --- a/far/dialog.cpp +++ b/far/dialog.cpp @@ -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; } /*****************************************************************/ diff --git a/far/editcontrol.cpp b/far/editcontrol.cpp index 480983d967..c23e73fef7 100644 --- a/far/editcontrol.cpp +++ b/far/editcontrol.cpp @@ -375,7 +375,7 @@ static bool EnumEnvironment(VMenu2& Menu, const string& Str) std::set 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)) { diff --git a/far/editor.cpp b/far/editor.cpp index 00b21add10..14d484075c 100644 --- a/far/editor.cpp +++ b/far/editor.cpp @@ -2585,8 +2585,8 @@ int Editor::ProcessKey(const Manager::Key& Key) BeginStreamMarking(m_it_CurLine); //SelFirst=TRUE; //BUGBUG, never used - SelStart = static_cast(SBegin); - SelEnd = static_cast(SEnd - 1); + SelStart = SBegin; + SelEnd = SEnd - 1; } } diff --git a/far/farwinapi.cpp b/far/farwinapi.cpp index d5555fc843..d512ae3542 100644 --- a/far/farwinapi.cpp +++ b/far/farwinapi.cpp @@ -1438,10 +1438,9 @@ std::vector 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; @@ -1929,7 +1928,7 @@ DWORD GetAppPathsRedirectionFlag() provider::strings::~strings() { - FreeEnvironmentStrings(get()); + FreeEnvironmentStrings(*this); } provider::block::block() @@ -1945,7 +1944,7 @@ DWORD GetAppPathsRedirectionFlag() provider::block::~block() { - DestroyEnvironmentBlock(get()); + DestroyEnvironmentBlock(*this); } std::pair split(const wchar_t* Line) diff --git a/far/farwinapi.hpp b/far/farwinapi.hpp index 3ac8bf2ab9..4f0a8f4462 100644 --- a/far/farwinapi.hpp +++ b/far/farwinapi.hpp @@ -466,6 +466,27 @@ namespace os }; } + // enumerator for string1\0string2\0string3\0...stringN\0\0 + template + class enum_strings_t: noncopyable, public enumerator, range> + { + public: + enum_strings_t() {} + enum_strings_t(Provider Data): m_Provider(Data) {} + bool get(size_t index, typename enum_strings_t::value_type& value) + { + auto Begin = index? value.data() + value.size() + 1 : m_Provider, End = Begin; + while (*End) ++End; + value = enum_strings_t::value_type(Begin, End); + return !value.empty(); + } + + private: + const Provider m_Provider; + }; + + typedef enum_strings_t enum_strings; + namespace env { namespace detail @@ -473,8 +494,8 @@ namespace os 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; @@ -500,20 +521,6 @@ namespace os std::pair split(const wchar_t* Line); - template - class enum_strings_t: noncopyable, public enumerator, const wchar_t*> - { - public: - enum_strings_t() {} - bool get(size_t index, typename enum_strings_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 enum_strings; bool get_variable(const wchar_t* Name, string& strBuffer); diff --git a/far/filelist.cpp b/far/filelist.cpp index 0450ac12e8..c5f84e64ee 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -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; }); diff --git a/far/history.hpp b/far/history.hpp index b23dd0f1a8..e59ad44066 100644 --- a/far/history.hpp +++ b/far/history.hpp @@ -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(); diff --git a/far/hotplug.cpp b/far/hotplug.cpp index 9d2a0be675..84f2370b8d 100644 --- a/far/hotplug.cpp +++ b/far/hotplug.cpp @@ -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(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); } } diff --git a/far/local.cpp b/far/local.cpp index 3405031053..4029108b10 100644 --- a/far/local.cpp +++ b/far/local.cpp @@ -63,8 +63,7 @@ const string& GetSpacesAndEols() static const std::vector 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); diff --git a/far/macro.cpp b/far/macro.cpp index a2f91ea0e7..f253122235 100644 --- a/far/macro.cpp +++ b/far/macro.cpp @@ -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(Count)); + ReplaceStrings(Src, Find, Repl, IgnoreCase, Count <= 0 ? string::npos : static_cast(Count)); PassString(Src, Data); return true; } diff --git a/far/mix.cpp b/far/mix.cpp index 93eeb9891a..7097601691 100644 --- a/far/mix.cpp +++ b/far/mix.cpp @@ -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()) + FOR(const auto& i, (os::enum_strings_t())) { - const auto Data = os::env::split(i); + const auto Data = os::env::split(i.data()); os::env::set_variable(Data.first, Data.second); } diff --git a/far/vbuild.m4 b/far/vbuild.m4 index a309e99435..6796de4df4 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,4425)m4_dnl +m4_define(BUILD,4426)m4_dnl diff --git a/far/viewer.cpp b/far/viewer.cpp index 9e5548c28f..9ce876d37d 100644 --- a/far/viewer.cpp +++ b/far/viewer.cpp @@ -369,7 +369,7 @@ int Viewer::OpenFile(const string& Name,int warning) if (m_Codepage == CP_DEFAULT) m_Codepage = GetDefaultCodePage(); - MB.SetCP(static_cast(m_Codepage)); + MB.SetCP(m_Codepage); } ViewFile.SetPointer(0, nullptr, FILE_BEGIN); @@ -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(m_Codepage)); + MB.SetCP(m_Codepage); lcache_ready = false; AdjustFilePos(); ChangeViewKeyBar(); @@ -1724,7 +1724,7 @@ int Viewer::process_key(const Manager::Key& Key) nCodePage = GetDefaultCodePage(); } m_Codepage = nCodePage; - MB.SetCP(static_cast(m_Codepage)); + MB.SetCP(m_Codepage); lcache_ready = false; AdjustFilePos(); ChangeViewKeyBar(); diff --git a/far/vmenu.cpp b/far/vmenu.cpp index aa0e9d0c22..b1aa00b94a 100644 --- a/far/vmenu.cpp +++ b/far/vmenu.cpp @@ -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) {