Skip to content

Commit d62c816

Browse files
committed
Cleaning up flags; removeing ZTestFlags, since this doesn't work very well.
1 parent 659f2f3 commit d62c816

File tree

8 files changed

+51
-42
lines changed

8 files changed

+51
-42
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ BinPackParameters: true
2323
BraceWrapping:
2424
AfterClass: true
2525
AfterControlStatement: true
26+
AfterCaseLabel: true
2627
AfterEnum: true
2728
AfterFunction: true
2829
AfterNamespace: true

appveyor.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ after_build:
6363
# set compiler var
6464
- if "%generator%"=="Visual Studio 16" (set COMPILER="VC16")
6565
# switch to project build folder and zip "tutorials" folder
66-
- cd C:\projects\zep\build
67-
- 7z a -tzip -mx9 "zep-%configuration%-%APPVEYOR_BUILD_VERSION%-%COMPILER%.zip" %configuration%
68-
- appveyor PushArtifact "zep-%configuration%-%APPVEYOR_BUILD_VERSION%-%COMPILER%.zip"
66+
- cd C:\projects\zep\build\demos
67+
- 7z a -tzip -mx9 "zep-imgui-%configuration%-%APPVEYOR_BUILD_VERSION%-%COMPILER%.zip" demo_imgui\%configuration%
68+
- appveyor PushArtifact "zep-imgui-%configuration%-%APPVEYOR_BUILD_VERSION%-%COMPILER%.zip"
69+
- 7z a -tzip -mx9 "zep-qt-%configuration%-%APPVEYOR_BUILD_VERSION%-%COMPILER%.zip" demo_qt\%configuration%
70+
- appveyor PushArtifact "zep-qt-%configuration%-%APPVEYOR_BUILD_VERSION%-%COMPILER%.zip"
71+

include/zep/buffer.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,10 @@ class ZepBuffer : public ZepComponent
305305

306306
bool IsHidden() const;
307307

308-
uint32_t GetFileFlags() const { return m_fileFlags; }
309-
void SetFileFlags(uint32_t flags) { m_fileFlags = flags; }
308+
bool HasFileFlags(uint32_t flags) const;
309+
void SetFileFlags(uint32_t flags, bool set = true);
310+
void ClearFileFlags(uint32_t flags);
311+
void ToggleFileFlag(uint32_t flags);
310312

311313
private:
312314
void ClearRangeMarker(std::shared_ptr<RangeMarker> spMarker);

include/zep/editor.h

-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ struct Region;
5858
inline bool ZTestFlags(const uint32_t& flags, uint32_t value) { return ((flags & value) ? true : false); }
5959
inline uint32_t ZSetFlags(const uint32_t& flags, uint32_t value, bool set = true) { if (set) { return flags | value; } else return flags; }
6060
inline uint32_t ZClearFlags(const uint32_t& flags, uint32_t value) { return flags & ~value; }
61-
inline uint32_t ZToggleFlags(const uint32_t& flags, uint32_t value)
62-
{
63-
if (ZTestFlags(flags, value))
64-
{
65-
return ZClearFlags(flags, value);
66-
}
67-
return ZSetFlags(flags, value);
68-
}
6961

7062
namespace ZepEditorFlags
7163
{

src/buffer.cpp

+25-10
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,6 @@ bool ZepBuffer::GetLineOffsets(const long line, ByteIndex& lineStart, ByteIndex&
528528
return true;
529529
}
530530

531-
532531
std::string ZepBuffer::GetFileExtension() const
533532
{
534533
std::string ext;
@@ -748,8 +747,7 @@ void ZepBuffer::SetText(const std::string& text, bool initFromFile)
748747
}
749748

750749
// If file is only tabs, then force tab mode
751-
if (ZTestFlags(m_fileFlags, FileFlags::HasTabs) &&
752-
!ZTestFlags(m_fileFlags, FileFlags::HasSpaceTabs))
750+
if (HasFileFlags(FileFlags::HasTabs) && !HasFileFlags(FileFlags::HasSpaceTabs))
753751
{
754752
m_fileFlags = ZSetFlags(m_fileFlags, FileFlags::InsertTabs);
755753
}
@@ -799,7 +797,6 @@ ByteIndex ZepBuffer::GetLinePos(ByteIndex bufferLocation, LineLocation lineLocat
799797
GlyphIterator itrBegin = GlyphIterator(*this);
800798
GlyphIterator itrEnd = GlyphIterator(*this, ByteIndex(m_gapBuffer.size()));
801799

802-
803800
GlyphIterator itrLineStart(itr);
804801

805802
// If we are on the CR, move back 1, unless the \n is all that is on the line
@@ -811,8 +808,7 @@ ByteIndex ZepBuffer::GetLinePos(ByteIndex bufferLocation, LineLocation lineLocat
811808
}
812809

813810
// Find the end of the previous line
814-
while (itrLineStart > itrBegin&&
815-
itrLineStart.Char() != '\n')
811+
while (itrLineStart > itrBegin && itrLineStart.Char() != '\n')
816812
{
817813
itrLineStart.Move(-1);
818814
}
@@ -836,7 +832,7 @@ ByteIndex ZepBuffer::GetLinePos(ByteIndex bufferLocation, LineLocation lineLocat
836832
// The point just after the line end
837833
case LineLocation::BeyondLineEnd:
838834
{
839-
while (itr < itrEnd && itr.Char()!= '\n' && itr.Char() != 0)
835+
while (itr < itrEnd && itr.Char() != '\n' && itr.Char() != 0)
840836
{
841837
itr.Move(1);
842838
}
@@ -896,8 +892,7 @@ ByteIndex ZepBuffer::GetLinePos(ByteIndex bufferLocation, LineLocation lineLocat
896892
itr.Move(1);
897893
}
898894

899-
while (itr > itrBegin &&
900-
itr < itrEnd
895+
while (itr > itrBegin && itr < itrEnd
901896
&& !std::isgraph(ToASCII(itr.Char())))
902897
{
903898
itr.Move(-1);
@@ -1301,7 +1296,7 @@ void ZepBuffer::ForEachMarker(uint32_t markerType, SearchDirection dir, ByteInde
13011296
{
13021297
auto itrREnd = std::make_reverse_iterator(itrStart);
13031298
auto itrRStart = std::make_reverse_iterator(itrEnd);
1304-
1299+
13051300
for (auto itr = itrRStart; itr != itrREnd; itr++)
13061301
{
13071302
for (auto& markerItem : itr->second)
@@ -1469,4 +1464,24 @@ bool ZepBuffer::IsHidden() const
14691464
return windows.empty();
14701465
}
14711466

1467+
void ZepBuffer::SetFileFlags(uint32_t flags, bool set)
1468+
{
1469+
m_fileFlags = ZSetFlags(m_fileFlags, flags, set);
1470+
}
1471+
1472+
void ZepBuffer::ClearFileFlags(uint32_t flags)
1473+
{
1474+
m_fileFlags = ZSetFlags(m_fileFlags, flags, false);
1475+
}
1476+
1477+
bool ZepBuffer::HasFileFlags(uint32_t flags) const
1478+
{
1479+
return ZTestFlags(m_fileFlags, flags);
1480+
}
1481+
1482+
void ZepBuffer::ToggleFileFlag(uint32_t flags)
1483+
{
1484+
m_fileFlags = ZSetFlags(m_fileFlags, flags, !ZTestFlags(m_fileFlags, flags));
1485+
}
1486+
14721487
} // namespace Zep

src/editor.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ void ZepEditor::SaveBuffer(ZepBuffer& buffer)
215215
// - We don't check for outside modification yet either, meaning this could overwrite
216216
std::ostringstream strText;
217217

218-
if (ZTestFlags(buffer.GetFileFlags(), FileFlags::ReadOnly))
218+
if (buffer.HasFileFlags(FileFlags::ReadOnly))
219219
{
220220
strText << "Failed to save, Read Only: " << buffer.GetDisplayName();
221221
}
222-
else if (ZTestFlags(buffer.GetFileFlags(), FileFlags::Locked))
222+
else if (buffer.HasFileFlags(FileFlags::Locked))
223223
{
224224
strText << "Failed to save, Locked: " << buffer.GetDisplayName();
225225
}
@@ -280,7 +280,7 @@ void ZepEditor::RemoveBuffer(ZepBuffer* pBuffer)
280280
ZepBuffer* ZepEditor::GetEmptyBuffer(const std::string& name, uint32_t fileFlags)
281281
{
282282
auto pBuffer = CreateNewBuffer(name);
283-
pBuffer->SetFileFlags(ZSetFlags(pBuffer->GetFileFlags(), fileFlags));
283+
pBuffer->SetFileFlags(fileFlags);
284284
return pBuffer;
285285
}
286286

@@ -309,10 +309,7 @@ ZepBuffer* ZepEditor::GetFileBuffer(const ZepPath& filePath, uint32_t fileFlags,
309309

310310
// Create buffer, try to load even if not present, the buffer represents the save path (it just isn't saved yet)
311311
auto pBuffer = CreateNewBuffer(filePath);
312-
313-
auto flags = pBuffer->GetFileFlags();
314-
flags = ZSetFlags(flags, fileFlags);
315-
pBuffer->SetFileFlags(flags);
312+
pBuffer->SetFileFlags(fileFlags);
316313

317314
return pBuffer;
318315
}
@@ -445,8 +442,7 @@ void ZepEditor::UpdateWindowState()
445442
std::vector<ZepBuffer*> victims;
446443
for (auto& buffer : m_buffers)
447444
{
448-
auto bufferFlags = buffer->GetFileFlags();
449-
if (!ZTestFlags(bufferFlags, FileFlags::DefaultBuffer) || ZTestFlags(bufferFlags, FileFlags::Dirty))
445+
if (!buffer->HasFileFlags(FileFlags::DefaultBuffer) || buffer->HasFileFlags(FileFlags::Dirty))
450446
{
451447
continue;
452448
}
@@ -550,13 +546,13 @@ void ZepEditor::UpdateTabs()
550546
}
551547

552548
auto tabColor = GetTheme().GetColor(ThemeColor::TabActive);
553-
if (ZTestFlags(buffer.GetFileFlags(), FileFlags::HasWarnings))
549+
if (buffer.HasFileFlags(FileFlags::HasWarnings))
554550
{
555551
tabColor = GetTheme().GetColor(ThemeColor::Warning);
556552
}
557553

558554
// Errors win for coloring
559-
if (ZTestFlags(buffer.GetFileFlags(), FileFlags::HasErrors))
555+
if (buffer.HasFileFlags(FileFlags::HasErrors))
560556
{
561557
tabColor = GetTheme().GetColor(ThemeColor::Error);
562558
}

src/mode.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void ZepMode::SwitchMode(EditorMode currentMode)
199199
auto cursor = pWindow->GetBufferCursor();
200200

201201
// Force normal mode if the file is read only
202-
if (currentMode == EditorMode::Insert && ZTestFlags(buffer.GetFileFlags(), FileFlags::ReadOnly))
202+
if (currentMode == EditorMode::Insert && buffer.HasFileFlags(FileFlags::ReadOnly))
203203
{
204204
currentMode = EditorMode::Normal;
205205
}
@@ -518,7 +518,7 @@ void ZepMode::AddCommand(std::shared_ptr<ZepCommand> spCmd)
518518
return;
519519
}
520520

521-
if (ZTestFlags(GetCurrentWindow()->GetBuffer().GetFileFlags(), FileFlags::Locked))
521+
if (GetCurrentWindow()->GetBuffer().HasFileFlags(FileFlags::Locked))
522522
{
523523
// Ignore commands on buffers because we are view only,
524524
// and all commands currently modify the buffer!
@@ -1182,7 +1182,7 @@ bool ZepMode::GetCommand(CommandContext& context)
11821182
else if (mappedCommand == id_InsertTab)
11831183
{
11841184
context.beginRange = context.bufferCursor;
1185-
if (ZTestFlags(buffer.GetFileFlags(), FileFlags::InsertTabs))
1185+
if (buffer.HasFileFlags(FileFlags::InsertTabs))
11861186
{
11871187
context.tempReg.text = "\t";
11881188
}
@@ -1902,7 +1902,7 @@ bool ZepMode::HandleExCommand(std::string strCommand)
19021902

19031903
auto pMapBuffer = GetEditor().GetEmptyBuffer("Mappings");
19041904

1905-
pMapBuffer->SetFileFlags(ZSetFlags(pMapBuffer->GetFileFlags(), FileFlags::Locked | FileFlags::ReadOnly));
1905+
pMapBuffer->SetFileFlags(FileFlags::Locked | FileFlags::ReadOnly);
19061906
pMapBuffer->SetText(str.str());
19071907
GetEditor().GetActiveTabWindow()->AddWindow(pMapBuffer, nullptr, RegionLayoutType::VBox);
19081908
}
@@ -2109,7 +2109,7 @@ bool ZepMode::HandleExCommand(std::string strCommand)
21092109
}
21102110
else if (strCommand == ":ZTabs")
21112111
{
2112-
buffer.SetFileFlags(ZToggleFlags(buffer.GetFileFlags(), FileFlags::InsertTabs));
2112+
buffer.ToggleFileFlag(FileFlags::InsertTabs);
21132113
}
21142114
else if (strCommand == ":ZShowCR")
21152115
{
@@ -2179,7 +2179,7 @@ bool ZepMode::HandleExCommand(std::string strCommand)
21792179
str << " ";
21802180
}
21812181

2182-
if (ZTestFlags(editor_buffer->GetFileFlags(), FileFlags::Dirty))
2182+
if (editor_buffer->HasFileFlags(FileFlags::Dirty))
21832183
{
21842184
str << "+";
21852185
}

src/tab_window.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ ZepWindow* ZepTabWindow::AddWindow(ZepBuffer* pBuffer, ZepWindow* pParent, Regio
136136
if (m_windows.size() == 1 && pParent == nullptr)
137137
{
138138
auto& buffer = m_windows[0]->GetBuffer();
139-
if (ZTestFlags(buffer.GetFileFlags(), FileFlags::DefaultBuffer) &&
140-
!ZTestFlags(buffer.GetFileFlags(), FileFlags::Dirty))
139+
if (buffer.HasFileFlags(FileFlags::DefaultBuffer) &&
140+
!buffer.HasFileFlags(FileFlags::Dirty))
141141
{
142142
m_windows[0]->SetBuffer(pBuffer);
143143
return m_windows[0];

0 commit comments

Comments
 (0)