Debian Codegraph @

git/gitFileDiffDlg.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : gitFileDiffDlg.cpp
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #include "gitCommitEditor.h"
27 #include "gitFileDiffDlg.h"
28 #include "windowattrmanager.h"
29
30 #include "globals.h"
31 #include <wx/filedlg.h>
32 #include <wx/msgdlg.h>
33
34 #ifndef __WXMSW__
35 #include "icons/icon_git.xpm"
36 #endif
37
38 GitFileDiffDlg::GitFileDiffDlg(wxWindow* parent)
39 : GitFileDiffDlgBase(parent)
40 {
41 m_editor->InitStyles();
42 SetIcon(wxICON(icon_git));
43 SetName("GitFileDiffDlg");
44 WindowAttrManager::Load(this);
45 }
46
47 /*******************************************************************************/
48
49 GitFileDiffDlg::~GitFileDiffDlg() {}
50
51 /*******************************************************************************/
52 void GitFileDiffDlg::SetDiff(const wxString& diff)
53 {
54 m_editor->SetText(diff);
55 m_editor->SetReadOnly(true);
56 }
57
58 void GitFileDiffDlg::OnSaveAsPatch(wxCommandEvent& event)
59 {
60 wxString path = ::wxFileSelector(_("Save as"), "", "untitled", "patch", wxFileSelectorDefaultWildcardStr,
61 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
62 if(!path.IsEmpty()) {
63 ::WriteFileWithBackup(path, m_editor->GetText(), false);
64 ::wxMessageBox("Diff written to:\n" + path, "CodeLite");
65 // Close the dialog
66 CallAfter(&GitFileDiffDlg::EndModal, wxID_CLOSE);
67 }
68 // do nothing
69 }
70
71 void GitFileDiffDlg::OnCloseDialog(wxCommandEvent& event) { EndModal(wxID_OK); }