24#include <wx/textdlg.h>
43static bool findStashByIdUnlocked(
KIGIT_COMMON& aCommon,
const wxString& aId,
size_t& aIndexOut )
68 m_stashesList->AppendColumn(
_(
"Description" ), wxLIST_FORMAT_LEFT, FromDIP( 360 ) );
69 m_stashesList->AppendColumn(
_(
"Date" ), wxLIST_FORMAT_LEFT, FromDIP( 100 ) );
70 m_stashFiles->AppendColumn(
_(
"File" ), wxLIST_FORMAT_LEFT, FromDIP( 300 ) );
71 m_stashFiles->SetToolTip(
_(
"Double click a file to see what the stash changes in it." ) );
82 [
this]( wxListEvent& aEvent )
89 [
this]( wxListEvent& )
92 &&
m_stashesList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ) == -1 )
100 [
this]( wxListEvent& aEvent )
103 wxLIST_STATE_SELECTED );
114 [
this]( wxCommandEvent& )
119 [
this]( wxCommandEvent& )
124 [
this]( wxCommandEvent& )
129 [
this]( wxCommandEvent& )
138 if( !
m_dialog->SessionStillCurrent() )
143 auto stashes = std::make_shared<std::vector<KIGIT_STASH_INFO>>();
149 *stashes = aCommon.GetStashes();
153 if( !m_dialog->SessionStillCurrent() )
156 long selectedRow = m_stashesList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
157 wxString selected = stashIdForRow( selectedRow );
158 long selectRow = wxNOT_FOUND;
160 m_detailQuery.Cancel();
161 m_fillingStashes = true;
162 m_stashesList->DeleteAllItems();
165 for( const KIGIT_STASH_INFO& s : *stashes )
167 long idx = m_stashesList->InsertItem( m_stashesList->GetItemCount(), s.message );
168 m_stashesList->SetItem( idx, 1, KIGIT::RelativeDate( s.when ) );
169 m_stashesList->SetItemData( idx, static_cast<long>( s.index ) );
170 m_stashIds.push_back( s.id );
173 if( s.id == selected || ( selected.IsEmpty() && idx == 0 ) )
178 m_stashCount->SetLabel( wxString::Format( wxPLURAL(
"%d stash",
"%d stashes", shown ), shown ) );
180 if( selectRow != wxNOT_FOUND )
182 m_stashesList->SetItemState( selectRow, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
200 if( aId.IsEmpty() || !
m_dialog->SessionStillCurrent() )
203 auto detail = std::make_shared<KIGIT_STASH_DETAIL>();
209 *detail = aCommon.GetStashDetail( aId );
213 if( !m_dialog->SessionStillCurrent() )
216 long selectedRow = m_stashesList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
218 if( stashIdForRow( selectedRow ) == aId )
219 fillStashDetail( *detail );
239 for(
const wxString& file : aDetail.
files )
258 if( aRow < 0 ||
static_cast<size_t>( aRow ) >=
m_stashIds.size() )
259 return wxEmptyString;
267 if( !
m_dialog->SessionStillCurrent() )
278 m_dialog->RefuseOverUncommittedWork(
281 wxString question = aRemoveAfterApply ?
_(
"Apply this stash and remove it from the list?" )
282 :
_(
"Apply this stash to the working tree?" );
284 if( !
IsOK(
this, question ) )
287 if( !
m_dialog->ConfirmWorkingTreeChange( aStatus ) )
295 if( !findStashByIdUnlocked( aCommon,
id,
index ) )
300 aRemoveAfterApply ?
_(
"Could not pop the stash. Another program may have changed the stash "
301 "list, so nothing was applied." )
302 :
_(
"Could not apply the stash. Another program may have changed the stash "
303 "list, so nothing was applied." ),
323 if( !
m_dialog->SessionStillCurrent() )
333 if( !
IsOK(
this,
_(
"Drop this stash? This cannot be undone." ) ) )
341 if( !findStashByIdUnlocked( aCommon,
id,
index ) )
346 _(
"Could not drop the stash. Another program may have changed the stash list, so nothing "
353 if( !
m_dialog->SessionStillCurrent() )
362 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
363 auto preflight = std::make_shared<PREFLIGHT>();
372 [
this, common, preflight]()
374 if( !
m_dialog->SessionStillCurrent() || !common->GetRepo() )
377 if( !preflight->lfsMessage.IsEmpty() )
389 if( !
m_dialog->ConfirmWorkingTreeChange() )
402 bool hasNewFilesOnly =
false;
405 wxString projectPath =
m_frame->Prj().GetProjectPath();
407 auto outcome = std::make_shared<OUTCOME>();
413 outcome->worktree = ReadGitWorktreeStatus( aCommon, projectPath );
414 outcome->hasNewFilesOnly = !outcome->worktree.hasTrackedChanges
415 && !BuildGitChangeEntries( aCommon, projectPath, dark ).empty();
419 if( !m_dialog->SessionStillCurrent() )
422 if( !ProjectSafeToRewrite( m_frame, this, outcome->worktree, true ) )
425 if( !outcome->worktree.hasTrackedChanges )
429 if( outcome->hasNewFilesOnly )
431 DisplayInfoMessage( this, _(
"The changed files have never been committed, and a stash only "
432 "includes files that have been. Commit them from the Version "
433 "Control panel first, or discard them there." ) );
437 DisplayInfoMessage( this, _(
"There are no changes to stash." ) );
443 wxTextEntryDialog dlg(
this,
_(
"Optional description for this stash:" ),
_(
"Stash Changes" ) );
445 if( dlg.ShowModal() != wxID_OK || !
m_dialog->SessionStillCurrent() )
453 wxString
message = dlg.GetValue().Trim(
true ).Trim(
false );
458 return aCommon.StashSave( message );
460 _(
"Could not stash the changes." ),
true );
The base frame for deriving all KiCad main window classes.
The advanced Git window: a non-modal dialog with a top bar naming the repository and branch and a sid...
static wxString LfsRefusal(KIGIT_COMMON *aCommon)
Return a refusal message for LFS files or an unknown project folder, otherwise empty.
The project's git session.
bool StashPop(size_t aIndex)
std::vector< KIGIT_STASH_INFO > GetStashes() const
bool StashApply(size_t aIndex)
bool StashDrop(size_t aIndex)
PANEL_GIT_STASHES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxListCtrl * m_stashFiles
wxPanel * m_stashListPanel
wxTextCtrl * m_stashMessage
wxButton * m_stashSaveButton
wxStaticText * m_stashBranch
WX_SPLITTER_WINDOW * m_stashesSplitter
wxStaticText * m_stashCount
wxStaticText * m_stashCommit
wxButton * m_popStashButton
wxButton * m_dropStashButton
wxListCtrl * m_stashesList
wxButton * m_applyStashButton
wxStaticText * m_stashWhen
int m_stashSashPos
Where the user left the sash between the list and its detail pane.
void showStashDetail(const wxString &aId)
Fill the detail pane with the stash aId names, or hide it when the id is empty or gone.
void Populate()
Fill the list from the repository's stashes. The repository is read on a worker.
wxString stashIdForRow(long aRow) const
The stash shown on aRow, by its commit, or empty when the row is gone.
PANEL_GIT_STASHES(wxWindow *aParent, GIT_ADVANCED_DIALOG *aDialog, EDA_BASE_FRAME *aFrame)
KIGIT_QUERY m_listQuery
List and detail reads share the session lock without waiting on the UI thread.
KIGIT_QUERY m_detailQuery
void checkStashChanges()
After saving the editors, read the changes before asking for a stash description.
std::vector< wxString > m_stashIds
The stash commit behind each row, since a row's index is only valid for the listing it came from.
void restoreSelectedStash(bool aRemoveAfterApply)
bool m_fillingStashes
True while the list is being refilled, when its selection events are its own.
GIT_ADVANCED_DIALOG * m_dialog
KIGIT_QUERY m_actionQuery
Reads needed before an action's confirmation, separate from list refreshes.
void fillStashDetail(const KIGIT_STASH_DETAIL &aDetail)
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
Base window classes and related definitions.
void ShowGitCommitDiff(EDA_BASE_FRAME *aFrame, const wxString &aCommitHash, wxWindow *aParentWindow, const wxString &aRelativePath)
Open the diff for what a commit changed, comparing it against its parent.
bool ProjectSafeToRewrite(EDA_BASE_FRAME *aFrame, wxWindow *aParent, const GIT_WORKTREE_STATUS &aStatus, bool aAllowTrackedChanges)
Combine the repository snapshot with live editor state and explain any refusal.
GIT_IDENTITY ReadGitIdentity(KIGIT_COMMON &aCommon)
Read on a worker while holding the session's action lock.
bool EnsureGitIdentity(wxWindow *aParent, EDA_BASE_FRAME *aFrame, const std::shared_ptr< KIGIT_COMMON > &aCommon, const GIT_IDENTITY &aIdentity)
Open the same editor when the worker snapshot has no usable Git identity.
void UnsplitKeepingSash(wxSplitterWindow *aSplitter, wxWindow *aPane, int &aSashPos)
Close a splitter's second pane, keeping the sash where the user left it for next time.
wxString RelativeDate(const wxDateTime &aWhen)
"just now", "3 hours ago", or the ISO date once it is more than a month old.
void KeepDetailWidth(WX_SPLITTER_WINDOW *aSplitter)
Keep a split detail pane at the width its controls need, against both a narrow window and a dragged s...
void MarkDestructive(wxButton *aButton)
Paint a button's text the diff's red, for one that throws something away.
Repository state used before an operation that requires a clean working tree.
Repository values and whether Git can use them to record a commit.
wxString branch
The branch the stash was taken on, as its message records it.
std::vector< wxString > files
Paths the stash changes, new files included.
wxString message
What was stashed, without the "WIP on branch:" prefix.
wxString baseHash
Short hash of the commit the stash was taken on.