File: filehistory.h

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (119 lines) | stat: -rw-r--r-- 3,585 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/filehistory.h
// Purpose:     wxFileHistory class
// Author:      Julian Smart, Vaclav Slavik
// Created:     2010-05-03
// Copyright:   (c) Julian Smart, Vaclav Slavik
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_FILEHISTORY_H_
#define _WX_FILEHISTORY_H_

#include "wx/defs.h"

#if wxUSE_FILE_HISTORY

#include "wx/windowid.h"
#include "wx/object.h"
#include "wx/list.h"
#include "wx/string.h"
#include "wx/arrstr.h"

class WXDLLIMPEXP_FWD_CORE wxMenu;
class WXDLLIMPEXP_FWD_BASE wxConfigBase;
class WXDLLIMPEXP_FWD_BASE wxFileName;

enum wxFileHistoryMenuPathStyle
{
    wxFH_PATH_SHOW_IF_DIFFERENT,
    wxFH_PATH_SHOW_NEVER,
    wxFH_PATH_SHOW_ALWAYS
};

// ----------------------------------------------------------------------------
// File history management
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxFileHistoryBase : public wxObject
{
public:
    wxFileHistoryBase(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);

    // Operations
    virtual void AddFileToHistory(const wxString& file);
    virtual void RemoveFileFromHistory(size_t i);
    virtual int GetMaxFiles() const { return (int)m_fileMaxFiles; }
    virtual void UseMenu(wxMenu *menu);

    // Remove menu from the list (MDI child may be closing)
    virtual void RemoveMenu(wxMenu *menu);

#if wxUSE_CONFIG
    virtual void Load(const wxConfigBase& config);
    virtual void Save(wxConfigBase& config);
#endif // wxUSE_CONFIG

    virtual void AddFilesToMenu();
    virtual void AddFilesToMenu(wxMenu* menu); // Single menu

    // Accessors
    virtual wxString GetHistoryFile(size_t i) const { return m_fileHistory[i]; }
    virtual size_t GetCount() const { return m_fileHistory.GetCount(); }

    const wxList& GetMenus() const { return m_fileMenus; }

    // Set/get base id
    void SetBaseId(wxWindowID baseId) { m_idBase = baseId; }
    wxWindowID GetBaseId() const { return m_idBase; }

    void SetMenuPathStyle(wxFileHistoryMenuPathStyle style);
    wxFileHistoryMenuPathStyle GetMenuPathStyle() const { return m_menuPathStyle; }

protected:
    // Last n files
    wxArrayString              m_fileHistory;

    // Menus to maintain (may need several for an MDI app)
    wxList                      m_fileMenus;

    // Max files to maintain
    size_t                      m_fileMaxFiles;

    // Style of the paths in the menu labels
    wxFileHistoryMenuPathStyle m_menuPathStyle;

private:
    void DoRefreshLabels();


    // The ID of the first history menu item (Doesn't have to be wxID_FILE1)
    wxWindowID m_idBase;

    // Normalize a file name to canonical form. We have a special function for
    // this to ensure the same normalization is used everywhere.
    static wxString NormalizeFileName(const wxFileName& filename);

    // Remove any existing entries from the associated menus.
    void RemoveExistingHistory();

    wxDECLARE_NO_COPY_CLASS(wxFileHistoryBase);
};

#if defined(__WXGTK20__)
    #include "wx/gtk/filehistory.h"
#else
    // no platform-specific implementation of wxFileHistory yet
    class WXDLLIMPEXP_CORE wxFileHistory : public wxFileHistoryBase
    {
    public:
        wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1)
            : wxFileHistoryBase(maxFiles, idBase) {}

        wxDECLARE_DYNAMIC_CLASS(wxFileHistory);
    };
#endif

#endif // wxUSE_FILE_HISTORY

#endif // _WX_FILEHISTORY_H_