Skip to content

Commit

Permalink
[Dropper] + highlight objects in buffer viewer (2) #182 #181
Browse files Browse the repository at this point in the history
Signed-off-by: Gheorghita Mutu <gheorghitamutu@gmail.com>
  • Loading branch information
gheorghitamutu committed Apr 15, 2024
1 parent 440478e commit 8368171
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
6 changes: 1 addition & 5 deletions GViewCore/include/GView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,6 @@ namespace View
virtual bool GenerateActionOnMove(Reference<Control> sender, int64 deltaStartView, const ViewData& vd) = 0;
};

struct CORE_EXPORT WriteObjectsHighlightingZonesListInterface {
virtual bool WriteObjectsHighlightingZonesList(const GView::Utils::ZonesList& zones) = 0;
};

struct CORE_EXPORT ViewControl : public AppCUI::Controls::UserControl, public AppCUI::Utils::PropertiesInterface {
protected:
const AppCUI::Application::Config& Cfg;
Expand Down Expand Up @@ -895,7 +891,7 @@ namespace View
virtual bool SetOnStartViewMoveCallback(Reference<OnStartViewMoveInterface>);
virtual bool GetViewData(ViewData&, uint64);
virtual bool AdvanceStartView(int64);
virtual bool SetWriteObjectsHighlightingZonesListCallback(Reference<WriteObjectsHighlightingZonesListInterface>);
virtual bool SetObjectsHighlightingZonesList(GView::Utils::ZonesList& zones);

ViewControl(const std::string_view& name, UserControlFlags flags = UserControlFlags::None)
: UserControl("d:c", flags), Cfg(this->GetConfig()), name(name)
Expand Down
3 changes: 2 additions & 1 deletion GViewCore/src/View/BufferViewer/BufferViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class Instance : public View::ViewControl, public GView::Utils::SelectionZoneInt
virtual bool SetBufferColorProcessorCallback(Reference<BufferColorInterface>) override;
virtual bool GetViewData(ViewData&, uint64) override;
virtual bool AdvanceStartView(int64) override;
virtual bool SetObjectsHighlightingZonesList(GView::Utils::ZonesList& zones) override;

public:
Instance(Reference<GView::Object> obj, Settings* settings);
Expand Down Expand Up @@ -360,7 +361,7 @@ class Instance : public View::ViewControl, public GView::Utils::SelectionZoneInt
{
this->settings->zListObjects.Clear();

for (uint32 i = 0; zones.GetCount(); i++) {
for (uint32 i = 0; i < zones.GetCount(); i++) {
const auto zone = zones.GetZone(i);
CHECK(zone.has_value(), false, "");
CHECK(this->settings->zListObjects.Add(*zone), false, "");
Expand Down
31 changes: 26 additions & 5 deletions GViewCore/src/View/BufferViewer/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ bool Instance::AdvanceStartView(int64 offset)
return true;
}

bool Instance::SetObjectsHighlightingZonesList(GView::Utils::ZonesList& zones)
{
return this->SetZones(zones);
}

void Instance::OpenCurrentSelection()
{
uint64 start, end;
Expand Down Expand Up @@ -1032,19 +1037,25 @@ void Instance::Paint(Renderer& renderer)
WriteHeaders(renderer);

const auto& startView = cursor.GetStartView();
settings->zList.SetCache({ startView, ((uint64) Layout.charactersPerLine) * (Layout.visibleRows - 1ull) + startView });
if (showObjectsHighlighting) {
settings->zListObjects.SetCache({ startView, ((uint64) Layout.charactersPerLine) * (Layout.visibleRows - 1ull) + startView });
} else {
settings->zList.SetCache({ startView, ((uint64) Layout.charactersPerLine) * (Layout.visibleRows - 1ull) + startView });
}

DrawLineInfo dli;
for (uint32 tr = 0; tr < Layout.visibleRows; tr++) {
dli.offset = ((uint64) Layout.charactersPerLine) * tr + startView;
if (dli.offset >= obj->GetData().GetSize())
if (dli.offset >= obj->GetData().GetSize()) {
break;
}
PrepareDrawLineInfo(dli);
WriteLineAddress(dli);
if (Layout.nrCols == 0)
if (Layout.nrCols == 0) {
WriteLineTextToChars(dli);
else
} else {
WriteLineNumbersToChars(dli);
}
renderer.WriteSingleLineCharacterBuffer(0, tr + 1, chars, false);
}
}
Expand Down Expand Up @@ -1507,9 +1518,19 @@ int Instance::PrintCursorPosInfo(int x, int y, uint32 width, bool addSeparator,
}
int Instance::PrintCursorZone(int x, int y, uint32 width, Renderer& r)
{
if (auto z = this->settings->zList.OffsetToZone(this->cursor.GetCurrentPosition())) {
std::optional<GView::Utils::Zone> z;
if (showObjectsHighlighting) {
z = this->settings->zListObjects.OffsetToZone(this->cursor.GetCurrentPosition());
}

if (!z) {
z = this->settings->zList.OffsetToZone(this->cursor.GetCurrentPosition());
}

if (z) {
r.WriteSingleLineText(x, y, width, z->name, this->CursorColors.Highlighted);
}

r.WriteSpecialCharacter(x + width, y, SpecialChars::BoxVerticalSingleLine, this->CursorColors.Line);
return x + width + 1;
}
Expand Down
2 changes: 1 addition & 1 deletion GViewCore/src/View/ViewControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool ViewControl::AdvanceStartView(int64)
return false;
}

bool ViewControl::SetWriteObjectsHighlightingZonesListCallback(Reference<WriteObjectsHighlightingZonesListInterface>)
bool ViewControl::SetObjectsHighlightingZonesList(GView::Utils::ZonesList& zones)
{
return false;
}
Expand Down
19 changes: 13 additions & 6 deletions GenericPlugins/Dropper/include/Dropper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class Instance

std::vector<Data> findings;
std::map<std::string_view, uint32> occurences;
GView::Utils::ZonesList zones;

DataCache& cache = object->GetData();
uint64 nextOffset = offset;
Expand Down Expand Up @@ -266,6 +267,7 @@ class Instance
const auto name = dropper->GetName();
occurences[name] += 1;
findings.push_back({ start, end, result, name });
zones.Add(start, end, AppCUI::Graphics::DefaultColorPair, dropper->GetName());
nextOffset = end + 1;
break;
}
Expand All @@ -287,12 +289,12 @@ class Instance
}
}

CHECK(ToggleSync(true), false, "");
CHECK(ToggleSync(true, zones), false, "");

return true;
}

bool ToggleSync(bool value)
bool ToggleSync(bool value, GView::Utils::ZonesList& zones)
{
auto desktop = AppCUI::Application::GetDesktop();
const auto windowsNo = desktop->GetChildrenCount();
Expand All @@ -301,10 +303,15 @@ class Instance
auto interface = window.ToObjectRef<GView::View::WindowInterface>();
auto view = interface->GetCurrentView();

view->OnEvent(
nullptr,
AppCUI::Controls::Event::Command,
value ? View::VIEW_COMMAND_ACTIVATE_OBJECT_HIGHLIGHTING : View::VIEW_COMMAND_DEACTIVATE_OBJECT_HIGHLIGHTING);
if (value) {
CHECK(view->SetObjectsHighlightingZonesList(zones), false, "");
}
CHECK(view->OnEvent(
nullptr,
AppCUI::Controls::Event::Command,
value ? View::VIEW_COMMAND_ACTIVATE_OBJECT_HIGHLIGHTING : View::VIEW_COMMAND_DEACTIVATE_OBJECT_HIGHLIGHTING),
false,
"");
}

return true;
Expand Down

0 comments on commit 8368171

Please sign in to comment.