Permalink
Browse files

Added a clipboard history pane, which stores the text every time Ctrl…

…+C or Ctrl+X is pressed while in E. Double click any item in the pane to move it onto the clipboard.
  • Loading branch information...
1 parent 45ea56b commit c18147589295c61701c3302f29871d901e478090 @ajpalkovic ajpalkovic committed Jul 7, 2010
Showing with 293 additions and 2 deletions.
  1. +120 −0 src/ClipboardHistoryPane.cpp
  2. +69 −0 src/ClipboardHistoryPane.h
  3. +5 −0 src/EditorCtrl.cpp
  4. +1 −0 src/EditorCtrl.h
  5. +80 −1 src/EditorFrame.cpp
  6. +10 −1 src/EditorFrame.h
  7. +8 −0 src/e.vcproj
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ *
+ * Copyright (C) 2009, Alexander Stigsen, e-texteditor.com
+ *
+ * This software is licensed under the Open Company License as described
+ * in the file license.txt, which you should have received as part of this
+ * distribution. The terms are also available at http://opencompany.org/license.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ******************************************************************************/
+
+#include "ClipboardHistoryPane.h"
+#include "EditorFrame.h"
+#include "EditorCtrl.h"
+#include "Strings.h"
+#include "SearchListBox.h"
+
+#include <algorithm>
+
+#ifndef WX_PRECOMP
+ #include <wx/sizer.h>
+ #include <wx/dc.h>
+#endif
+
+using namespace std;
+
+enum {
+ CTRL_ACTION_LIST
+};
+
+BEGIN_EVENT_TABLE(ClipboardHistoryPane, wxPanel)
+ EVT_LISTBOX_DCLICK(CTRL_ACTION_LIST, ClipboardHistoryPane::OnAction)
+END_EVENT_TABLE()
+
+ClipboardHistoryPane::ClipboardHistoryPane(EditorFrame& editorFrame, bool keepOpen):
+ wxPanel(dynamic_cast<wxWindow*>(&editorFrame), wxID_ANY),
+ m_parentFrame(editorFrame),
+ m_keepOpen(keepOpen)
+{
+ // Create ctrls
+ m_listBox = new ActionList(this, CTRL_ACTION_LIST, m_clipboardHistory);
+
+ // Create Layout
+ wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
+ mainSizer->Add(m_listBox, 1, wxEXPAND);
+
+ SetSizer(mainSizer);
+}
+
+bool ClipboardHistoryPane::Destroy() {
+ // delayed destruction: the panel will be deleted during the next idle
+ // loop iteration
+ if ( !wxPendingDelete.Member(this) )
+ wxPendingDelete.Append(this);
+
+ return true;
+}
+
+void ClipboardHistoryPane::AddCopyText(wxString copytext) {
+ if(m_clipboardHistory.size() > 0 && m_clipboardHistory[m_clipboardHistory.size()-1] == copytext) {
+ return;
+ }
+
+ m_clipboardHistory.push_back(copytext);
+ m_listBox->SetAllItems();
+ m_listBox->SetSelection(m_clipboardHistory.size() - 1);
+}
+
+void ClipboardHistoryPane::OnAction(wxCommandEvent& WXUNUSED(event)) {
+ if(m_listBox->GetSelectedCount() != 1) return;
+
+ const int hit = m_listBox->GetSelection();
+ if (hit != wxNOT_FOUND && hit < (int)m_clipboardHistory.size()) {
+ m_parentFrame.GetEditorCtrl()->DoCopy(m_clipboardHistory[hit]);
+ }
+}
+
+
+// --- ActionList --------------------------------------------------------
+
+ClipboardHistoryPane::ActionList::ActionList(wxWindow* parent, wxWindowID id, std::vector<wxString>& clipboardHistory):
+ SearchListBox(parent, id),
+ m_clipboardHistory(clipboardHistory)
+{
+ SetAllItems();
+}
+
+void ClipboardHistoryPane::ActionList::SetAllItems() {
+ m_items.clear();
+
+ Freeze();
+
+ m_items.resize(m_clipboardHistory.size());
+ for (unsigned int i = 0; i < m_clipboardHistory.size(); ++i) {
+ m_items[i].id = i;
+ m_items[i].text = &m_clipboardHistory[i];
+ }
+
+ SetItemCount(m_items.size());
+
+ SetSelection(-1);
+ RefreshAll();
+ Thaw();
+}
+
+void ClipboardHistoryPane::ActionList::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const {
+ const bool isCurrent = IsCurrent(n);
+
+ if (isCurrent) dc.SetTextForeground(m_hlTextColor);
+ else dc.SetTextForeground(m_textColor);
+
+ const aItem& ai = m_items[n];
+ const vector<unsigned int>& hl = ai.hlChars;
+ const wxString& name = *ai.text;
+
+ // Draw action name
+ DrawItemText(dc, rect, name, hl, isCurrent);
+}
View
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ *
+ * Copyright (C) 2009, Alexander Stigsen, e-texteditor.com
+ *
+ * This software is licensed under the Open Company License as described
+ * in the file license.txt, which you should have received as part of this
+ * distribution. The terms are also available at http://opencompany.org/license.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ******************************************************************************/
+
+#ifndef __CLIPBOARDHISTORYPANE_H__
+#define __CLIPBOARDHISTORYPANE_H__
+
+#include "wx/wxprec.h"
+#ifndef WX_PRECOMP
+ #include <wx/panel.h>
+ #include <wx/textctrl.h>
+#endif
+
+class EditorFrame;
+#include "SearchListBox.h"
+#include <vector>
+
+class ClipboardHistoryPane : public wxPanel {
+public:
+ ClipboardHistoryPane(EditorFrame& editorFrame, bool keepOpen=true);
+ bool Destroy();
+ void AddCopyText(wxString copytext);
+
+private:
+ void OnAction(wxCommandEvent& event);
+
+ DECLARE_EVENT_TABLE();
+
+ class ActionList : public SearchListBox {
+ public:
+ ActionList(wxWindow* parent, wxWindowID id, std::vector<wxString>& clipboardHistory);
+ void SetAllItems();
+
+ private:
+ void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
+
+ class aItem {
+ public:
+ aItem() : id(0), text(NULL) {};
+ aItem(unsigned int id, const wxString* a, const std::vector<unsigned int>& hl)
+ : id(id), text(a), hlChars(hl) {};
+ unsigned int id;
+ const wxString* text;
+ std::vector<unsigned int> hlChars;
+ };
+
+ std::vector<wxString>& m_clipboardHistory;
+ std::vector<aItem> m_items;
+ };
+
+
+ // Member variables
+ EditorFrame& m_parentFrame;
+ ActionList* m_listBox;
+
+ bool m_keepOpen;
+ std::vector<wxString> m_clipboardHistory;
+};
+
+#endif // __CLIPBOARDHISTORYPANE_H__
View
@@ -4359,6 +4359,11 @@ void EditorCtrl::OnCopy() {
}
}
+ m_parentFrame.AddCopyText(copytext);
+ DoCopy(copytext);
+}
+
+void EditorCtrl::DoCopy(wxString& copytext) {
if (!copytext.empty()) {
#ifdef __WXMSW__
// WINDOWS ONLY!! newline conversion
View
@@ -196,6 +196,7 @@ class EditorCtrl : public KeyHookable<wxControl>,
void OnCut();
void OnPaste();
void OnMarkCopy();
+ void DoCopy(wxString& copytext);
// Selection
bool IsSelected() const;
View
@@ -69,6 +69,7 @@
#include "eauibook.h"
#include "DiffDirPane.h"
#include "SnippetList.h"
+#include "ClipboardHistoryPane.h"
#ifdef __WXMSW__
// For multi-monitor-aware position restore on Windows, include WinUser.h
@@ -171,6 +172,7 @@ BEGIN_EVENT_TABLE(EditorFrame, wxFrame)
EVT_MENU(MENU_SHIFT_PROJECT_FOCUS, EditorFrame::OnShiftProjectFocus)
EVT_MENU(MENU_SHOWSYMBOLS, EditorFrame::OnMenuShowSymbols)
EVT_MENU(MENU_SHOWSNIPPETS, EditorFrame::OnMenuShowSnippets)
+ EVT_MENU(MENU_CLIPBOARD_HISTORY_PANE, EditorFrame::OnMenuShowClipboardHistoryPane)
EVT_MENU(MENU_REVHIS, EditorFrame::OnMenuRevisionHistory)
EVT_MENU(MENU_UNDOHIS, EditorFrame::OnMenuUndoHistory)
EVT_MENU(MENU_COMMANDOUTPUT, EditorFrame::OnMenuShowCommandOutput)
@@ -307,7 +309,7 @@ EditorFrame::EditorFrame(CatalystWrapper cat, unsigned int frameId, const wxStr
m_sizeChanged(false), m_needStateSave(true), m_keyDiags(false), m_inAskReload(false),
m_changeCheckerThread(NULL), editorCtrl(0), m_recentFilesMenu(NULL), m_recentProjectsMenu(NULL), m_bundlePane(NULL), m_diffPane(NULL),
- m_symbolList(NULL), m_findInProjectDlg(NULL), m_pStatBar(NULL), m_snippetList(NULL),
+ m_symbolList(NULL), m_findInProjectDlg(NULL), m_pStatBar(NULL), m_snippetList(NULL), m_clipboardHistoryPane(NULL),
m_previewDlg(NULL), m_ctrlHeldDown(false), m_lastActiveTab(0), m_showGutter(true), m_showIndent(false),
bitmap(1,1)
//,m_incommingBmp(incomming_xpm), m_incommingFullBmp(incomming_full_xpm)
@@ -428,6 +430,13 @@ EditorFrame::EditorFrame(CatalystWrapper cat, unsigned int frameId, const wxStr
if (showsymbols) ShowSymbolList();
}
+ // Check if we should show the clipboard history pane
+ {
+ bool showClipboardHistory = false;
+ m_settings.GetSettingBool(wxT("showClipboardHistory"), showClipboardHistory);
+ if (showClipboardHistory) ShowClipboardHistoryPane();
+ }
+
m_frameManager.Update();
InitAccelerators();
@@ -622,6 +631,7 @@ void EditorFrame::InitMenus() {
//viewMenu->Check(MENU_INCOMMING, true);
viewMenu->Append(MENU_SHOWSYMBOLS, _("&Symbol List\tCtrl+Alt+L"), _("Show Symbol List"), wxITEM_CHECK);
viewMenu->Append(MENU_SHOWSNIPPETS, _("&Snippet List\tCtrl+Alt+S"), _("Show Snippet List"), wxITEM_CHECK);
+ viewMenu->Append(MENU_CLIPBOARD_HISTORY_PANE, _("&Clipboard History"), _("Show Clipboard History Pane"), wxITEM_CHECK);
viewMenu->Append(MENU_REVHIS, _("&Revision History\tF6"), _("Show Revision History"), wxITEM_CHECK);
viewMenu->Check(MENU_REVHIS, true);
viewMenu->Append(MENU_UNDOHIS, _("&Undo History\tF7"), _("Show Undo History"), wxITEM_CHECK);
@@ -2175,6 +2185,10 @@ void EditorFrame::OnOpeningMenu(wxMenuEvent& WXUNUSED(event)) {
wxMenuItem* snItem = GetMenuBar()->FindItem(MENU_SHOWSNIPPETS);
if (snItem) snItem->Check(m_snippetList != NULL);
+ // "Show Clipboard History"
+ wxMenuItem* chItem = GetMenuBar()->FindItem(MENU_CLIPBOARD_HISTORY_PANE);
+ if (chItem) chItem->Check(m_clipboardHistoryPane != NULL);
+
// "Highlight Authors"
wxMenuItem* hlItem = GetMenuBar()->FindItem(MENU_HL_USERS);
if (hlItem) hlItem->Check(m_userHighlight);
@@ -3219,6 +3233,11 @@ void EditorFrame::OnMenuShowSnippets(wxCommandEvent& event) {
else CloseSnippetList();
}
+void EditorFrame::OnMenuShowClipboardHistoryPane(wxCommandEvent& event) {
+ if (event.IsChecked()) ShowClipboardHistoryPane();
+ else CloseClipboardHistoryPane();
+}
+
void EditorFrame::OnMenuSymbols(wxCommandEvent& WXUNUSED(event)) {
if (m_symbolList) {
// If symbol list is already open, we switch focus
@@ -3328,6 +3347,49 @@ void EditorFrame::CloseSnippetList() {
m_frameManager.Update();
}
+void EditorFrame::ShowClipboardHistoryPane() {
+ if (m_clipboardHistoryPane) return; // already shown
+
+ // Create the pane
+ m_clipboardHistoryPane = new ClipboardHistoryPane(*this);
+ wxAuiPaneInfo paneInfo;
+ paneInfo.Name(wxT("Clipboard History")).Right().Caption(_("Clipboard History")).BestSize(wxSize(150,50)); // defaults
+
+ // Load pane settings
+ wxString panePerspective;
+ m_settings.GetSettingString(wxT("clipboardHistory_pane"), panePerspective);
+ m_settings.SetSettingBool(wxT("showClipboardHistory"), true);
+ if (!panePerspective.empty()) m_frameManager.LoadPaneInfo(panePerspective, paneInfo);
+
+ // Add to manager
+ m_frameManager.AddPane(m_clipboardHistoryPane, paneInfo);
+ m_frameManager.Update();
+}
+
+void EditorFrame::CloseClipboardHistoryPane() {
+ if (!m_clipboardHistoryPane) return; // already closed
+
+ wxAuiPaneInfo& pane = m_frameManager.GetPane(m_clipboardHistoryPane);
+
+ // Save pane settings
+ const wxString panePerspective = m_frameManager.SavePaneInfo(pane);
+ m_settings.SetSettingString(wxT("clipboardHistory_pane"), panePerspective);
+ m_settings.SetSettingBool(wxT("showClipboardHistory"), false);
+
+ // Delete the snippet pane
+ m_frameManager.DetachPane(m_clipboardHistoryPane);
+ m_clipboardHistoryPane->Hide();
+ m_clipboardHistoryPane->Destroy();
+ m_clipboardHistoryPane = NULL;
+ m_frameManager.Update();
+}
+
+void EditorFrame::AddCopyText(wxString& copytext) {
+ if(m_clipboardHistoryPane) {
+ m_clipboardHistoryPane->AddCopyText(copytext);
+ }
+}
+
void EditorFrame::CloseWebPreview() {
if (!m_previewDlg) return; // already closed
@@ -3383,6 +3445,13 @@ void EditorFrame::OnPaneClose(wxAuiManagerEvent& event) {
else if (event.GetPane()->window == m_snippetList) {
CloseSnippetList();
+ // We have already deleted the window
+ // so we don't want aui to do any close handling
+ event.Veto();
+ }
+ else if (event.GetPane()->window == m_clipboardHistoryPane) {
+ CloseClipboardHistoryPane();
+
// We have already deleted the window
// so we don't want aui to do any close handling
event.Veto();
@@ -3731,6 +3800,16 @@ void EditorFrame::SaveState() {
m_settings.SetSettingBool(wxT("showsnippets"), true);
}
+ // Save snippet list layout
+ if (m_clipboardHistoryPane) {
+ wxAuiPaneInfo& pane = m_frameManager.GetPane(m_clipboardHistoryPane);
+
+ // Save pane settings
+ const wxString panePerspective = m_frameManager.SavePaneInfo(pane);
+ m_settings.SetSettingString(wxT("clipboardHistory_pane"), panePerspective);
+ m_settings.SetSettingBool(wxT("showClipboardHistory"), true);
+ }
+
m_settings.SetSettingBool(wxT("showproject"), projectPane.IsShown());
m_settings.SetSettingString(wxT("topwin/panes"), perspective);
if (m_tabBar->GetPageCount() != 0) m_settings.SetSettingInt(wxT("topwin/page_id"), m_tabBar->GetSelection());
Oops, something went wrong.

0 comments on commit c181475

Please sign in to comment.