Skip to content

Commit

Permalink
- Implemented "Recent Documents" list, with
Browse files Browse the repository at this point in the history
the latest documents being inserted in it and their word count. When double-clicked, the document
opens in the amStoryWriter.
    - Changed tables to save memory: Now there is a 'last_session' table and a 'sessions' table. They have
different things in them and 'last_session' only has 1 entry, forever.
    - Fixed bugs in amStoryWriter and amStoryWriterNotebook when selecting tabs in the wxAuiNotebook.
    - Changed the left pane notebook to be a wxAuiNotebook so it could use a wxAuiSimpleTabArt (the main notebook
also uses this art now), because that can be a lot better integrated with the Dark Theme.
    - Started emulating a page view in the main notebook in amStoryWriterNotebook, with the wxRTC being restricted
to a maximum width.
    - Fixed a bug in the hot-tracking wxDVC when using headers.
  • Loading branch information
AmadeusK525 committed Jul 17, 2022
1 parent 7bdc96f commit 36a6071
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 175 deletions.
19 changes: 19 additions & 0 deletions Amadeus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ VisualStudioVersion = 16.0.30406.217
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Amadeus", "Amadeus.vcxproj", "{853D1FD7-20AB-586C-9699-9680F84AC985}"
ProjectSection(ProjectDependencies) = postProject
{A16D3832-0F42-57CE-8F48-50E06649ADE8} = {A16D3832-0F42-57CE-8F48-50E06649ADE8}
{3FCC50C2-81E9-5DB2-B8D8-2129427568B1} = {3FCC50C2-81E9-5DB2-B8D8-2129427568B1}
{6744DAD8-9C70-574A-BFF2-9F8DDDB24A75} = {6744DAD8-9C70-574A-BFF2-9F8DDDB24A75}
EndProjectSection
Expand All @@ -12,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "F:\wxWidgets\build\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "F:\wxWidgets\build\msw\wx_core.vcxproj", "{6744DAD8-9C70-574A-BFF2-9F8DDDB24A75}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aui", "F:\wxWidgets\build\msw\wx_aui.vcxproj", "{A16D3832-0F42-57CE-8F48-50E06649ADE8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -72,6 +75,22 @@ Global
{6744DAD8-9C70-574A-BFF2-9F8DDDB24A75}.Release|Win32.Build.0 = Release|Win32
{6744DAD8-9C70-574A-BFF2-9F8DDDB24A75}.Release|x64.ActiveCfg = Release|x64
{6744DAD8-9C70-574A-BFF2-9F8DDDB24A75}.Release|x64.Build.0 = Release|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Debug|Win32.ActiveCfg = Debug|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Debug|Win32.Build.0 = Debug|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Debug|x64.ActiveCfg = Debug|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Debug|x64.Build.0 = Debug|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Debug|Win32.ActiveCfg = DLL Debug|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Debug|Win32.Build.0 = DLL Debug|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Debug|x64.ActiveCfg = DLL Debug|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Debug|x64.Build.0 = DLL Debug|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Release|Win32.ActiveCfg = DLL Release|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Release|Win32.Build.0 = DLL Release|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Release|x64.ActiveCfg = DLL Release|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.DLL Release|x64.Build.0 = DLL Release|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Release|Win32.ActiveCfg = Release|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Release|Win32.Build.0 = Release|Win32
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Release|x64.ActiveCfg = Release|x64
{A16D3832-0F42-57CE-8F48-50E06649ADE8}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions Amadeus.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
<Link>
<AdditionalDependencies>wxmsw$(wxShortVersionString)u_html.lib;wxbase$(wxShortVersionString)u_xml.lib;wxmsw$(wxShortVersionString)u_richtext.lib;wxmsw$(wxShortVersionString)u_aui.lib;wxmsw$(wxShortVersionString)u_core.lib;wxbase$(wxShortVersionString)u.lib;wxjpeg.lib;wxpng.lib;wxzlib.lib;wxregexu.lib;wxexpat.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;shlwapi.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;version.lib;wsock32.lib;wininet.lib;%(AdditionalDependencies);wxmsw28u_wxsf.lib;wxsqlite3.lib</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>$(WXWIN)\lib\vc_lib;$(WXWIN)\lib\vc_lib\mswu;$(WXWIN)\3rdparty\wxSF\lib\vc_lib;$(WXWIN)\3rdparty\wxsqlite3-4.6.4\lib\vc_lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(SolutionDir)\src\Notebook;$(WXWIN)\lib\vc_lib;$(WXWIN)\lib\vc_lib\mswu;$(WXWIN)\3rdparty\wxSF\lib\vc_lib;$(WXWIN)\3rdparty\wxsqlite3-4.6.4\lib\vc_lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
Expand Down Expand Up @@ -460,9 +460,9 @@
<ClCompile Include="src\WordProcessor.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Resource\resource.h" />
<ClInclude Include="src\BookElements.h" />
<ClInclude Include="src\DocumentCreator.h" />
<ClInclude Include="src\Notebook\Notebook.h" />
<ClInclude Include="src\Overview.h" />
<ClInclude Include="src\SortFunctions.h" />
<ClInclude Include="src\StoryNotebook.h" />
Expand Down
6 changes: 3 additions & 3 deletions Amadeus.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@
<ClInclude Include="src\Release.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource\resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\wxmemdbg.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -190,6 +187,9 @@
<ClInclude Include="src\SortFunctions.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Notebook\Notebook.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\resource.bin">
Expand Down
28 changes: 28 additions & 0 deletions src/BookElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <wx\sstream.h>
#include <wx\mstream.h>

#include <sstream>

#include "MyApp.h"

#include "wxmemdbg.h"
Expand Down Expand Up @@ -30,6 +32,11 @@ Document::~Document()
CleanUp();
}

bool Document::IsStory()
{
return type == Document_Chapter || type == Document_Scene || type == Document_Other;
}

bool Document::HasRedNote()
{
for ( Note*& pNote : notes )
Expand All @@ -41,6 +48,27 @@ bool Document::HasRedNote()
return false;
}

int Document::GetWordCount()
{
amProjectSQLDatabase* pDb = amGetManager()->GetStorage();
wxSQLite3ResultSet result = pDb->ExecuteQuery("SELECT plain_text FROM documents WHERE id = " + std::to_string(id));

int count = 0;

if ( result.NextRow() )
{
std::string content = result.GetAsString("plain_text");

if ( !content.empty() )
{
std::stringstream sstream(content);
count = std::distance(std::istream_iterator<std::string>(sstream), std::istream_iterator<std::string>());
}
}

return count;
}

void Document::Save(wxSQLite3Database* db)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/BookElements.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ struct Document
virtual ~Document();

void SetId(int id) { this->id = id; }
bool IsStory();

bool HasRedNote();
int GetWordCount();

void Save(wxSQLite3Database* db);
bool Update(wxSQLite3Database* db, bool updateContent, bool updateNotes);
Expand Down
6 changes: 3 additions & 3 deletions src/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ amMainFrame::amMainFrame(const wxString& title, amProjectManager* manager, const
m_selPanel->SetBackgroundColour(wxColour(40, 40, 40));
m_selPanel->SetDoubleBuffered(true);

wxFont font(wxFontInfo(13).Family(wxFONTFAMILY_MODERN).Bold().AntiAliased());
wxFont font(wxFontInfo(12).Family(wxFONTFAMILY_MODERN).Bold().AntiAliased());

for ( int i = 0; i < 5; i++ )
m_mainButtons.push_back(nullptr);
Expand All @@ -102,12 +102,12 @@ amMainFrame::amMainFrame(const wxString& title, amProjectManager* manager, const
button->SetForegroundColour(wxColour(245, 245, 245));
button->Bind(wxEVT_ENTER_WINDOW, amOnEnterDarkButton);
button->Bind(wxEVT_LEAVE_WINDOW, amOnLeaveDarkButton);
m_buttonSizer->Add(button, wxSizerFlags(1).Expand().Border(wxTOP | wxLEFT | wxRIGHT, 5));
m_buttonSizer->Add(button, wxSizerFlags(1).Expand().Border(wxALL, 2));
}

m_mainButtons[0]->SetBackgroundColour(wxDarkenColour(wxColour(130, 0, 0), 28));

m_buttonSizer->AddStretchSpacer(2);
m_buttonSizer->AddStretchSpacer(3);
m_selPanel->SetSizer(m_buttonSizer);

m_mainBook = new wxSimplebook(m_mainSplitter);
Expand Down
83 changes: 61 additions & 22 deletions src/Overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,42 @@ amOverview::amOverview(wxWindow* parent, amProjectManager* manager) : wxPanel(pa
sizer->Add(m_bookPicker, wxSizerFlags(1).Top());
sizer->Add(m_stBookTitle, wxSizerFlags(1).Top());

// m_recentDocumentsModel = new StoryTreeModel;
//
//#ifdef __WXMSW__
// m_recentDocumentsDVC = m_recentDocumentsHandler.Create(this, -1, m_recentDocumentsModel.get(),
// wxBORDER_NONE | wxDV_MULTIPLE);
//#else
// m_recentDocumentsDVC = new wxDataViewCtrl(m_secondPanel, -1, wxDefaultPosition, wxDefaultSize,
// wxDV_SINGLE | wxBORDER_NONE);
// m_recentDocumentsDVC->AssociateModel(&m_recentDocumentsModel);
//#endif
//
// m_recentDocumentsDVC->SetBackgroundColour(wxColour(90, 90, 90));
// //m_recentDocumentsDVC->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &amElementShowcase::OnDocumentActivated, this);
//
// wxDataViewColumn* pColumn = new wxDataViewColumn(_("Documents"), new wxDataViewIconTextRenderer(wxDataViewIconTextRenderer::GetDefaultType(),
// wxDATAVIEW_CELL_EDITABLE), 0, FromDIP(200), wxALIGN_LEFT);
// m_recentDocumentsDVC->AppendColumn(pColumn);
//
// pColumn = new wxDataViewColumn(_("Words"), new wxDataViewTextRenderer(wxDataViewTextRenderer::GetDefaultType(),
// wxDATAVIEW_CELL_INERT), 1, FromDIP(80), wxALIGN_CENTER);
// m_recentDocumentsDVC->AppendColumn(pColumn);
wxStaticText* pRecentDocumentsLabel = new wxStaticText(this, -1, _("Recent Documents:"));
pRecentDocumentsLabel->SetBackgroundColour(wxColour(40, 40, 40));
pRecentDocumentsLabel->SetForegroundColour(wxColour(240,240,240));
pRecentDocumentsLabel->SetFont(wxFontInfo(10).Bold());

m_recentDocumentsModel = new StoryTreeModel;

#ifdef __WXMSW__
m_recentDocumentsDVC = m_recentDocumentsHandler.Create(this, -1, m_recentDocumentsModel.get(),
wxBORDER_NONE | wxDV_MULTIPLE);
#else
m_recentDocumentsDVC = new wxDataViewCtrl(m_secondPanel, -1, wxDefaultPosition, wxDefaultSize,
wxDV_SINGLE | wxBORDER_NONE);
m_recentDocumentsDVC->AssociateModel(&m_recentDocumentsModel);
#endif

m_recentDocumentsDVC->SetBackgroundColour(wxColour(90, 90, 90));
m_recentDocumentsDVC->SetMinSize(wxSize(FromDIP(250), -1));
m_recentDocumentsDVC->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &amOverview::OnRecentDocument, this);

wxDataViewColumn* pColumn = new wxDataViewColumn(_("Document name"), new wxDataViewIconTextRenderer(wxDataViewIconTextRenderer::GetDefaultType(),
wxDATAVIEW_CELL_EDITABLE), 0, FromDIP(170), wxALIGN_LEFT);
m_recentDocumentsDVC->AppendColumn(pColumn);

pColumn = new wxDataViewColumn(_("Words"), new wxDataViewTextRenderer(wxDataViewTextRenderer::GetDefaultType(),
wxDATAVIEW_CELL_INERT), 1, FromDIP(80), wxALIGN_CENTER);
m_recentDocumentsDVC->AppendColumn(pColumn);

wxBoxSizer* pRecentDocumentsSizer = new wxBoxSizer(wxVERTICAL);
pRecentDocumentsSizer->Add(pRecentDocumentsLabel, wxSizerFlags(0).Expand());
pRecentDocumentsSizer->Add(m_recentDocumentsDVC, wxSizerFlags(1));

m_mainSizer = new wxBoxSizer(wxVERTICAL);
m_mainSizer->Add(sizer, wxSizerFlags(0).Expand());
//m_mainSizer->Add(m_recentDocumentsDVC, wxSizerFlags(1).Left().Border(wxALL, 10));
m_mainSizer->AddSpacer(10);
m_mainSizer->Add(pRecentDocumentsSizer, wxSizerFlags(1).Left());

SetSizer(m_mainSizer);
Layout();
Expand All @@ -154,9 +165,37 @@ void amOverview::SetBookData(Book* book)
m_stBookTitle->Wrap(m_stBookTitle->GetSize().x);
Layout();

LoadRecentDocuments(book);

Thaw();
}

void amOverview::LoadRecentDocuments(Book* book)
{
Freeze();

m_recentDocumentsModel->ClearAll();

for ( Document*& pDocument : book->vRecentDocuments )
{
wxDataViewItem docItem = m_recentDocumentsModel->AddDocument(pDocument, wxDataViewItem(nullptr));
}

Thaw();
}

void amOverview::OnRecentDocument(wxDataViewEvent& event)
{
StoryTreeModelNode* pNode = (StoryTreeModelNode*)event.GetItem().GetID();
if ( !pNode )
return;

if ( pNode->GetDocument() )
m_manager->OpenDocument(pNode->GetDocument());

event.Skip();
}

void amOverview::LoadBookContainer()
{
wxVector<Book*>& books = m_manager->GetBooks();
Expand Down
3 changes: 3 additions & 0 deletions src/Overview.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ class amOverview : public wxPanel
amOverview(wxWindow* parent, amProjectManager* manager);

void SetBookData(Book* book);
void LoadRecentDocuments(Book* book);

void LoadBookContainer();

void OnRecentDocument(wxDataViewEvent& event);
};

#endif
Loading

0 comments on commit 36a6071

Please sign in to comment.