Debian Codegraph @

git/gitSettingsDlg.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : gitSettingsDlg.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 "gitSettingsDlg.h"
27
28 #include "cl_config.h"
29 #include "event_notifier.h"
30 #include "gitentry.h"
31 #include "windowattrmanager.h"
32
33 GitSettingsDlg::GitSettingsDlg(wxWindow* parent, const wxString& localRepoPath, const wxString& userEnteredRepoPath,
34 const wxString& projectNameHash)
35 : GitSettingsDlgBase(parent)
36 , m_userEnteredRepoPath(userEnteredRepoPath)
37 , m_projectNameHash(projectNameHash)
38 {
39 GitEntry data;
40 data.Load();
41
42 m_pathGIT->SetPath(data.GetGITExecutablePath());
43 m_pathGITK->SetPath(data.GetGITKExecutablePath());
44 m_textCtrlGitShell->ChangeValue(data.GetGitShellCommand());
45
46 m_checkBoxLog->SetValue(data.GetFlags() & GitEntry::Git_Verbose_Log);
47 m_checkBoxTerminal->SetValue(data.GetFlags() & GitEntry::Git_Show_Terminal);
48 m_checkBoxShowBlameInStatusBar->SetValue(data.IsShowBlameInfoInStatusBar());
49 GitEntry::GitProperties props = GitEntry::ReadGitProperties(localRepoPath);
50
51 m_textCtrlGlobalEmail->ChangeValue(props.global_email);
52 m_textCtrlGlobalName->ChangeValue(props.global_username);
53 m_textCtrlLocalEmail->ChangeValue(props.local_email);
54 m_textCtrlLocalName->ChangeValue(props.local_username);
55 m_dirPickerGitRepoPath->SetPath(m_userEnteredRepoPath);
56
57 SetName("GitSettingsDlg");
58 WindowAttrManager::Load(this);
59 }
60
61 GitSettingsDlg::~GitSettingsDlg() {}
62
63 void GitSettingsDlg::OnOK(wxCommandEvent& event)
64 {
65 GitEntry data;
66 data.Load();
67
68 wxString repopath = m_dirPickerGitRepoPath->GetPath();
69 // Sanity-check the entered path: we don't want /foo/bar/.git/, just /foo/bar
70 if(repopath.Right(1) == "/") {
71 repopath.RemoveLast();
72 }
73 if(repopath.Right(5) == "/.git") {
74 repopath.RemoveLast(5);
75 }
76
77 if(!m_projectNameHash.empty() && (repopath != m_userEnteredRepoPath)) {
78 m_userEnteredRepoPath = repopath;
79 data.SetProjectUserEnteredRepoPath(repopath, m_projectNameHash);
80 data.Save();
81
82 // The git repo path was changed, so we need to flag a reload
83 EndModal(wxID_REFRESH);
84 return;
85 };
86
87 data.SetGITExecutablePath(m_pathGIT->GetPath());
88 data.SetGITKExecutablePath(m_pathGITK->GetPath());
89 data.SetGitShellCommand(m_textCtrlGitShell->GetValue());
90
91 size_t flags = 0;
92 if(m_checkBoxLog->IsChecked())
93 flags |= GitEntry::Git_Verbose_Log;
94
95 if(m_checkBoxTerminal->IsChecked())
96 flags |= GitEntry::Git_Show_Terminal;
97
98 if(m_checkBoxShowBlameInStatusBar->IsChecked())
99 flags |= GitEntry::Git_Show_Commit_Info;
100
101 data.SetFlags(flags);
102 data.Save();
103
104 GitEntry::GitProperties props;
105 props.global_email = m_textCtrlGlobalEmail->GetValue();
106 props.global_username = m_textCtrlGlobalName->GetValue();
107 props.local_email = m_textCtrlLocalEmail->GetValue();
108 props.local_username = m_textCtrlLocalName->GetValue();
109 GitEntry::WriteGitProperties(m_userEnteredRepoPath, props);
110
111 // Notify about configuration changed
112 wxCommandEvent evt(wxEVT_GIT_CONFIG_CHANGED);
113 EventNotifier::Get()->AddPendingEvent(evt);
114
115 EndModal(wxID_OK);
116 }
117
118 void GitSettingsDlg::OnLocalRepoUI(wxUpdateUIEvent& event) { event.Enable(!m_userEnteredRepoPath.IsEmpty()); }