Skip to content

Commit

Permalink
Merge pull request #351 from udoe/persist_column_settings
Browse files Browse the repository at this point in the history
Make current columns settings (for each view) persistent in the .dbconf file
  • Loading branch information
janwilmans authored Mar 17, 2019
2 parents 291309a + a00500d commit e2c804b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
51 changes: 51 additions & 0 deletions DebugView++/LogView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <unordered_set>
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>
#include "CobaltFusion/AtlWinExt.h"
#include "CobaltFusion/stringbuilder.h"
#include "CobaltFusion/dbgstream.h"
Expand Down Expand Up @@ -1338,6 +1339,11 @@ void CLogView::SetAutoScrollStop(bool enable)
m_autoScrollStop = enable;
}

const std::vector<ColumnInfo>& CLogView::GetColumns() const
{
return m_columns;
}

void CLogView::Clear()
{
m_firstLine = m_logFile.Count();
Expand Down Expand Up @@ -1691,6 +1697,51 @@ bool CLogView::FindPrevious(std::wstring_view text)
return Find(text, -1);
}

boost::property_tree::ptree MakePTree(const std::vector<ColumnInfo>& columns)
{
boost::property_tree::ptree pt;
for (int i = 0; i < Column::Count; ++i)
{
const ColumnInfo& col = columns[i];
boost::property_tree::ptree colPt;
colPt.put("Index", i);
colPt.put("Enable", col.enable);
colPt.put("Width", col.column.cx);
colPt.put("Order", col.column.iOrder);
pt.add_child("Column", colPt);
}
return pt;
}

void CLogView::ReadColumns(const boost::property_tree::ptree& pt)
{
for (auto& item : pt)
{
if (item.first == "Column")
{
const auto& colPt = item.second;
auto index = colPt.get_optional<int>("Index");
if (index && *index < m_columns.size())
{
ColumnInfo& col = m_columns[*index];

auto enable = colPt.get_optional<bool>("Enable");
if (enable)
col.enable = *enable;

auto width = colPt.get_optional<int>("Width");
if (width)
col.column.cx = *width;

auto order = colPt.get_optional<int>("Order");
if (order)
col.column.iOrder = *order;
}
}
}
UpdateColumns();
}

void CLogView::LoadSettings(CRegKey& reg)
{
SetName(Win32::RegGetStringValue(reg));
Expand Down
5 changes: 5 additions & 0 deletions DebugView++/LogView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <vector>
#include <deque>
#include <boost/property_tree/ptree_fwd.hpp>
#include "Win32/Window.h"
#include "Win32/Win32Lib.h"
#include "CobaltFusion/AtlWinExt.h"
Expand Down Expand Up @@ -89,6 +90,8 @@ struct ColumnInfo
LVCOLUMN column;
};

boost::property_tree::ptree MakePTree(const std::vector<ColumnInfo>& columns);

class CMyHeaderCtrl : public CWindowImpl<CMyHeaderCtrl, CHeaderCtrl>
{
public:
Expand Down Expand Up @@ -156,6 +159,8 @@ class CLogView : public CDoubleBufferWindowImpl<CLogView, CListViewCtrl,
void SetAutoScroll(bool enable);
bool GetAutoScrollStop() const;
void SetAutoScrollStop(bool enable);
const std::vector<ColumnInfo>& GetColumns() const;
void ReadColumns(const boost::property_tree::ptree& pt);
void Clear();
int GetFocusLine() const;
void SetFocusLine(int line);
Expand Down
5 changes: 5 additions & 0 deletions DebugView++/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ struct View
bool clockTime;
bool processColors;
LogFilter filters;
boost::optional<boost::property_tree::ptree> columnsPt;
};

struct SourceInfoHelper
Expand Down Expand Up @@ -919,6 +920,7 @@ void CMainFrame::LoadConfiguration(const std::wstring& fileName)
view.processColors = viewPt.get<bool>("ProcessColors");
view.filters.messageFilters = MakeFilters(viewPt.get_child("MessageFilters"));
view.filters.processFilters = MakeFilters(viewPt.get_child("ProcessFilters"));
view.columnsPt = viewPt.get_child_optional("Columns");
views.push_back(view);
}
}
Expand All @@ -937,6 +939,8 @@ void CMainFrame::LoadConfiguration(const std::wstring& fileName)
auto& logView = GetView(i);
logView.SetClockTime(views[i].clockTime);
logView.SetViewProcessColors(views[i].processColors);
if (views[i].columnsPt)
logView.ReadColumns(*(views[i].columnsPt));
}

int i = GetViewCount();
Expand Down Expand Up @@ -1005,6 +1009,7 @@ void CMainFrame::SaveConfiguration(const std::wstring& fileName)
viewPt.put("ProcessColors", logView.GetViewProcessColors());
viewPt.put_child("MessageFilters", MakePTree(filters.messageFilters));
viewPt.put_child("ProcessFilters", MakePTree(filters.processFilters));
viewPt.put_child("Columns", MakePTree(logView.GetColumns()));
mainPt.add_child("Views.View", viewPt);
}

Expand Down

0 comments on commit e2c804b

Please sign in to comment.