Skip to content

Commit

Permalink
838 split column string into small medium large (#839)
Browse files Browse the repository at this point in the history
* split column STRING into SMALL, MEDIUM and LARGE

* fixed SRRING type, now STRING_MEDIUM
  • Loading branch information
antonvw authored Feb 8, 2025
1 parent 13e61f8 commit c7dbb50
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Changed

- upgrade to lexilla 5.4.2
- split column types STRING into STRING SMALL, MEDIUM and LARGE
- The Open Group Base Specifications Issue 8, 2024 edition
- listview standard column sizes are configurable
- wex::quoted uses std::quoted and includes a delim character
Expand Down
14 changes: 8 additions & 6 deletions include/wex/factory/listview.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: listview.h
// Purpose: Declaration of wex::factory::listview and related classes
// Author: Anton van Wezenbeek
// Copyright: (c) 2021-2023 Anton van Wezenbeek
// Copyright: (c) 2021-2025 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#pragma once
Expand Down Expand Up @@ -33,11 +33,13 @@ class column : public wxListItem
/// get_column types.
enum type_t
{
INVALID, ///< illegal col
INT = 1, ///< integer
DATE, ///< date
FLOAT, ///< float
STRING ///< string
INVALID, ///< illegal col
INT = 1, ///< integer
DATE, ///< date
FLOAT, ///< float
STRING_SMALL, ///< string small size
STRING_MEDIUM, ///< string medium size
STRING_LARGE, ///< string large size
};

/// Default constructor.
Expand Down
2 changes: 1 addition & 1 deletion sample/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ frame::frame(app* app)
m_grid->AppendCols(2);

m_listview->append_columns(
{{"String", wex::column::STRING},
{{"String", wex::column::STRING_MEDIUM},
{"Number", wex::column::INT},
{"Float", wex::column::FLOAT},
{"Date", wex::column::DATE}});
Expand Down
12 changes: 6 additions & 6 deletions src/data/listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: data/listview.cpp
// Purpose: Implementation of wex::data::listview
// Author: Anton van Wezenbeek
// Copyright: (c) 2021-2024 Anton van Wezenbeek
// Copyright: (c) 2021-2025 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#include <wex/data/listview.h>
Expand All @@ -23,14 +23,14 @@ wex::data::listview::listview(data::window& data)

void wex::data::listview::add_columns()
{
m_listview->append_columns({{_("File Name"), column::STRING}});
m_listview->append_columns({{_("File Name"), column::STRING_MEDIUM}});

switch (m_type)
{
case FIND:
m_listview->append_columns(
{{_("Line"), column::STRING, 250},
{_("Match"), column::STRING},
{{_("Line"), column::STRING_MEDIUM},
{_("Match"), column::STRING_SMALL},
{_("Line No")}});
break;
default:
Expand All @@ -39,8 +39,8 @@ void wex::data::listview::add_columns()

m_listview->append_columns(
{{_("Modified"), column::DATE},
{_("In Folder"), column::STRING, 175},
{_("Type"), column::STRING},
{_("In Folder"), column::STRING_MEDIUM},
{_("Type"), column::STRING_SMALL},
{_("Size")}});
}

Expand Down
20 changes: 16 additions & 4 deletions src/factory/listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@
// Name: listview.cpp
// Purpose: Implementation of wex core listview methods
// Author: Anton van Wezenbeek
// Copyright: (c) 2021-2024 Anton van Wezenbeek
// Copyright: (c) 2021-2025 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#include <boost/algorithm/string.hpp>

#include <wex/core/config.h>
#include <wex/core/core.h>
#include <wex/factory/listview.h>

namespace wex
{
std::string skip_underscore(const std::string& text)
{
return boost::algorithm::replace_all_copy(text, "_", " ");
}
} // namespace wex

#define SETUP_COL(NAME, ALIGN, SIZE) \
case column::NAME: \
align = ALIGN; \
\
if (width == 0) \
{ \
width = config("col." #NAME).get(SIZE); \
width = config(skip_underscore("col." #NAME)).get(SIZE); \
} \
break

Expand All @@ -31,10 +41,12 @@ wex::column::column(const std::string& name, type_t type, int width)

switch (m_type)
{
SETUP_COL(DATE, wxLIST_FORMAT_LEFT, 150);
SETUP_COL(DATE, wxLIST_FORMAT_LEFT, 80);
SETUP_COL(FLOAT, wxLIST_FORMAT_RIGHT, 80);
SETUP_COL(INT, wxLIST_FORMAT_RIGHT, 60);
SETUP_COL(STRING, wxLIST_FORMAT_LEFT, 100);
SETUP_COL(STRING_SMALL, wxLIST_FORMAT_LEFT, 60);
SETUP_COL(STRING_MEDIUM, wxLIST_FORMAT_LEFT, 200);
SETUP_COL(STRING_LARGE, wxLIST_FORMAT_LEFT, 400);

default:
assert(0);
Expand Down
18 changes: 8 additions & 10 deletions src/ui/listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ const std::vector<item> config_items()
item::FONTPICKERCTRL,
wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)}}},
{_("Margin"),
{{"col.DATE", 0, 150, 150},
{{"col.DATE", 0, 150, 80},
{"col.FLOAT", 0, 120, 80},
{"col.INT", 0, 100, 60},
{"col.STRING", 0, 500, 100}}},
{"col.STRING SMALL", 0, 500, 60},
{"col.STRING MEDIUM", 0, 500, 200},
{"col.STRING LARGE", 0, 500, 400}}},
{_("Colour"),
{{_("list.Readonly colour"),
item::COLOURPICKERWIDGET,
Expand Down Expand Up @@ -723,9 +725,6 @@ bool wex::listview::insert_item(
(void)std::stoi(col);
break;

case column::STRING:
break;

default:
break;
}
Expand Down Expand Up @@ -979,7 +978,7 @@ bool wex::listview::load(const strings_t& l)
tok.end(),
[this, &i](const auto&)
{
append_columns({{std::to_string(i++ + 1), column::STRING, 50}});
append_columns({{std::to_string(i++ + 1), column::STRING_MEDIUM, 100}});
});
}

Expand Down Expand Up @@ -1300,7 +1299,9 @@ int wxCALLBACK compare_cb(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
return ascending ? wex::compare(std::stoi(str1), std::stoi(str2)) :
wex::compare(std::stoi(str2), std::stoi(str1));

case wex::column::STRING:
case wex::column::STRING_SMALL:
case wex::column::STRING_MEDIUM:
case wex::column::STRING_LARGE:
if (!wex::find_replace_data::get()->match_case())
{
return ascending ? wex::icompare(str1, str2) :
Expand Down Expand Up @@ -1344,9 +1345,6 @@ bool wex::listview::set_item(long index, int column, const std::string& text)
(void)std::stoi(text);
break;

case column::STRING:
break;

default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcs/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class process_dir : public dir
{
if (init)
{
m_listview->append_columns({{"Name", column::STRING, 200}, {"Pid"}});
m_listview->append_columns({{"Name", column::STRING_MEDIUM}, {"Pid"}});
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions src/vcs/revisions-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ int wex::vcs_entry::revisions_dialog(

if (is_new)
{
vb->append_columns({{"branches", wex::column::STRING, 500}});
vt->append_columns({{"tags", wex::column::STRING, 500}});
vb->append_columns({{"branches", wex::column::STRING_LARGE}});
vt->append_columns({{"tags", wex::column::STRING_MEDIUM}});
lv->append_columns(
{{"date", wex::column::STRING, 75},
{"comment", wex::column::STRING, 400},
{"author", wex::column::STRING},
{"hash", wex::column::STRING}});
{{"date", wex::column::DATE},
{"comment", wex::column::STRING_LARGE},
{"author", wex::column::STRING_MEDIUM},
{"hash", wex::column::STRING_SMALL}});

bind_rev(vb, repo_path, tl, "branches");
bind_rev(vt, repo_path, tl, "tags");
Expand Down
4 changes: 2 additions & 2 deletions test/del/test-listview-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: test-listview-file.cpp
// Purpose: Implementation for wex del unit testing
// Author: Anton van Wezenbeek
// Copyright: (c) 2021-2022 Anton van Wezenbeek
// Copyright: (c) 2021-2025 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#include <wex/del/listview-file.h>
Expand Down Expand Up @@ -38,7 +38,7 @@ TEST_CASE("wex::del::file")
SUBCASE("columns")
{
lv->append_columns(
{{"String", wex::column::STRING}, {"Number", wex::column::INT}});
{{"String", wex::column::STRING_SMALL}, {"Number", wex::column::INT}});

// Remember that listview file already has columns.
REQUIRE(lv->find_column("String") > 1);
Expand Down
11 changes: 6 additions & 5 deletions test/ui/test-listview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: test-listview.cpp
// Purpose: Implementation for wex unit testing
// Author: Anton van Wezenbeek
// Copyright: (c) 2015-2024 Anton van Wezenbeek
// Copyright: (c) 2015-2025 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#include <wex/core/log-none.h>
Expand All @@ -23,7 +23,7 @@ TEST_CASE("wex::listview")
{"Int", wex::column::INT},
{"Date", wex::column::DATE},
{"Float", wex::column::FLOAT},
{"String", wex::column::STRING}};
{"String", wex::column::STRING_SMALL}};

SUBCASE("general")
{
Expand All @@ -47,7 +47,7 @@ TEST_CASE("wex::listview")
REQUIRE(lv->append_columns(
{{"Date", wex::column::DATE},
{"Float", wex::column::FLOAT},
{"String", wex::column::STRING}}));
{"String", wex::column::STRING_MEDIUM}}));

REQUIRE(lv->find_column("Int") == 0);
REQUIRE(lv->find_column("Date") == 1);
Expand Down Expand Up @@ -105,7 +105,8 @@ TEST_CASE("wex::listview")
SUBCASE("item_from_to_text")
{
REQUIRE(lv->append_columns(
{{"Text", wex::column::STRING}, {"More", wex::column::STRING}}));
{{"Text", wex::column::STRING_MEDIUM},
{"More", wex::column::STRING_MEDIUM}}));

lv->field_separator('');

Expand Down Expand Up @@ -153,7 +154,7 @@ TEST_CASE("wex::listview")
REQUIRE(lv->data().image() == wex::data::listview::IMAGE_ART);
REQUIRE(!lv->data().type_description().empty());

REQUIRE(lv->append_columns({{"String", wex::column::STRING}}));
REQUIRE(lv->append_columns({{"String", wex::column::STRING_MEDIUM}}));

REQUIRE(lv->item_from_text("test.h\ntest.h"));
REQUIRE(lv->set_item_image(0, wxART_WARNING));
Expand Down

0 comments on commit c7dbb50

Please sign in to comment.