38#include <wx/bmpbndl.h>
39#include <wx/filename.h>
42#include <wx/splitter.h>
43#include <wx/treectrl.h>
65 for( wxWindow* child : aWindow->GetChildren() )
67 if(
dynamic_cast<wxTextEntry*
>( child ) )
96 m_book->SetFitToCurrentPage(
false );
121 [
this]( wxCommandEvent& )
131 m_pane->SetBusyChangedHandler(
139 [
this]( wxCommandEvent& )
144 [
this]( wxCommandEvent& )
150 [
this]( wxCommandEvent& )
168 m_book->GetTreeCtrl()->InvalidateBestSize();
170 for(
size_t i = 0; i <
m_book->GetPageCount(); ++i )
171 m_book->GetPage( i )->Layout();
176 wxSize treeSize =
m_book->GetTreeCtrl()->GetSize();
178 m_book->GetTreeCtrl()->SetMinSize( treeSize );
183 wxSize bookMin = FromDIP( wxSize( 800, 600 ) );
184 m_book->InvalidateBestSize();
185 bookMin.IncTo(
m_book->GetBestSize() );
186 m_book->SetMinSize( bookMin );
191 [
this]( wxCommandEvent& )
202 Bind( wxEVT_SYS_COLOUR_CHANGED,
203 [
this]( wxSysColourChangedEvent& aEvent )
233 std::optional<GIT_ADVANCED_PAGE> aPage )
239 dialog->Bind( wxEVT_CLOSE_WINDOW,
240 [dialog]( wxCloseEvent& )
248 dialog->
Show(
false );
298 if(
m_pane && ( !current || current ==
this || current->
m_pane.get() !=
m_pane.get() ) )
300 m_pane->SetBusyChangedHandler(
nullptr );
301 m_pane->SetMessageChangedHandler(
nullptr );
316 session->RemoveRefreshListener(
this );
322 std::shared_ptr<KIGIT_COMMON> common =
m_parent->Prj().GetGitCommon();
334 common->AddRefreshListener(
this,
349 m_pane->ShowTransferProgress( aText );
397 wxVector<wxBitmapBundle> pageIcons;
405 m_book->SetImages( pageIcons );
415 m_book->SetSelection(
static_cast<size_t>( aPage ) );
421 wxPanel* panel =
new wxPanel( aBook );
422 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
425 m_changesSplitter =
new wxSplitterWindow( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
426 wxSP_LIVE_UPDATE | wxSP_3DSASH );
438 panel->SetSizer( sizer );
454 m_pane->SetMessageChangedHandler(
462 [
this](
const wxString& aPath )
480 if( aPath.IsEmpty() || !
m_parent->Prj().GetGitCommon()->GetRepo() )
488 wxString baseLabel = branch.IsEmpty() ?
_(
"BASE (HEAD)" ) : wxString::Format(
_(
"BASE (%s)" ), branch );
494 return MaterializeWorkingFile( aCommon, aWorkspace, path, aSides );
496 baseLabel,
_(
"WORKING (changes)" ) );
518 std::vector<KIGIT_BRANCH_INFO> branches;
521 std::shared_ptr<KIGIT_COMMON> common =
m_parent->Prj().GetGitCommon();
522 auto result = std::make_shared<RESULT>();
535 if( common !=
m_parent->Prj().GetGitCommon() || common->IsShuttingDown() )
538 wxFileName root = wxFileName::DirName(
result->root );
539 m_repoName->SetLabel( root.GetDirs().empty() ? root.GetFullPath() : root.GetDirs().Last() );
568 std::shared_ptr<KIGIT_COMMON> common =
m_parent->Prj().GetGitCommon();
569 auto hasRemote = std::make_shared<bool>(
false );
589 [
this, common, hasRemote, aRetriedAfterTrust]()
627 if( !aStatus.IsEmpty() )
639 if( request == m_fetchRequest && m_fetchPreflight && SessionStillCurrent() )
640 startFetch( aCommon, aRetriedAfterTrust );
654 bool fetched =
false;
657 bool authFailure =
false;
658 bool cancelled =
false;
660 std::optional<KIGIT::HOST_KEY_FAILURE> hostKey;
663 auto outcome = std::make_shared<OUTCOME>();
669 GIT_PULL_HANDLER handler( aCommon.get() );
670 handler.SetProgressReporter( std::make_unique<KIGIT_STATUS_REPORTER>(
672 [dialog]( const wxString& aText )
674 dialog->ShowTransferProgress( aText );
676 handler.SetCancelToken( aToken );
677 handler.SetWaitForActionLock(
true );
678 outcome->fetched = handler.PerformFetch();
680 outcome->error = error.
summary;
681 outcome->details = error.
details;
682 outcome->authFailure = handler.WasAuthFailure();
683 outcome->hostKey = handler.GetHostKeyFailure();
687 outcome->cancelled = handler.IsThisOperationCancelled();
690 if( outcome->fetched && !outcome->cancelled )
695 aCommon->NotifyRefreshListeners();
699 [
this, aCommon, outcome, aRetriedAfterTrust]()
701 if( !SessionStillCurrent() )
704 if( outcome->fetched && !outcome->cancelled )
707 if( outcome->fetched || outcome->cancelled )
709 m_credentialPrompts = 0;
710 endFetch( outcome->fetched ? wxString() : wxString(
_(
"Cancelled." ) ) );
716 failure.
hostKey = outcome->hostKey;
717 failure.
error = outcome->error;
721 aRetriedAfterTrust, m_credentialPrompts ) )
737 endFetch( wxEmptyString );
739 wxString error = outcome->error;
741 if( error.IsEmpty() )
749 endFetch( wxEmptyString );
799 if( IsBeingDeleted() ||
m_parent->IsBeingDeleted() )
805 &&
Pgm().GetCommonSettings()->m_Git.enableGit && !
m_parent->Prj().GetLocalSettings().m_GitIntegrationDisabled )
821 bool aRewritesWorkingTree )
826 return aFn( aCommon );
828 aError, aRewritesWorkingTree );
833 const wxString& aError,
bool aRewritesWorkingTree )
846 if( !lock.owns_lock() )
849 ok = aFn( *common,
detail );
856 if( aRewritesWorkingTree )
859 common->NotifyRefreshListeners();
866 if( aRewritesWorkingTree )
872 common->NotifyRefreshListeners();
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Construct and return a bitmap bundle for the given icon ID, with the default bitmap size being aDefHe...
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
DIALOG_GIT_ADVANCED_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Advanced Git"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxChoice * m_branchChoice
wxStaticText * m_repoName
bool Show(bool show) override
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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...
EDA_BASE_FRAME * m_parent
bool abandonFetchPreflight()
Stop a pending remote check and release what the fetch holds. False when none is pending.
GIT_ADVANCED_DIALOG(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane)
int m_credentialPrompts
Keyring reads and credential prompts the current fetch has shown, reset when it ends.
static void ShowHistoryForFile(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane, const wxString &aPath)
Open the window on its History page, narrowed to the commits that changed aPath.
PANEL_GIT_BRANCHES * m_branchesPage
void RefuseOverUncommittedWork(std::function< void(const GIT_WORKTREE_STATUS &)> aReady)
Check the working tree and LFS on a worker, then continue on the UI thread only when nothing is uncom...
void ShowTransferProgress(const wxString &aText)
Show a line of transfer progress on the hosted commit panel's status line.
void showWorkingDiff(const wxString &aPath)
Show the working copy of aPath against its committed version, or hide that area.
GIT_FILE_DIFF_AREA * m_workingDiff
void SwitchToBranch(const wxString &aBranch)
Switch the working tree to the named branch, after confirming, then refresh.
static void CloseForPane(GIT_COMMIT_PANE *aPane)
Close the live window if the given pane opened it, for when that pane goes away.
PANEL_GIT_REPOSITORY * m_repositoryPage
PANEL_GIT_HISTORY * m_historyPage
PANEL_GIT_REMOTES * m_remotesPage
EDITOR_SNAPSHOT m_docsBeforeChange
On-disk identity of the open documents, taken by ConfirmWorkingTreeChange() so only the documents an ...
void selectPage(GIT_ADVANCED_PAGE aPage)
bool ConfirmWorkingTreeChange()
After the asynchronous LFS check, save the open editors and snapshot their documents before an action...
static void CloseActive()
Close the live window, for when the project it was filled from goes away.
wxSplitterWindow * m_changesSplitter
void endFetch(const wxString &aStatus)
Restore the Fetch button and release the fetch's hold, then show aStatus on the commit panel.
KIGIT_QUERY m_reloadQuery
Reads the top bar and history branch choices without holding up the UI.
std::weak_ptr< KIGIT_COMMON > m_listenerSession
static GIT_ADVANCED_DIALOG * Active()
The live window, or null when none is open.
void RunGitAction(const std::function< bool(KIGIT_COMMON &)> &aFn, const wxString &aError, bool aRewritesWorkingTree=false)
Run a repository write under the action lock, then refresh every surface on success.
PANEL_GIT_STASHES * m_stashesPage
void syncListener()
Attach once to the project's session.
bool m_fetchPreflight
The fetch is checking its remote, before its transfer starts, and holds the panes busy.
KIGIT_QUERY m_actionQuery
Preflight reads for actions that may replace the working tree.
bool SessionStillCurrent()
True while the frame's git session is still the one this window's lists were filled from.
GIT_TRANSFER_BUSY::HOLD m_fetchBusy
The top bar fetch's hold on its repository, from its remote check until it ends.
static void ShowForFrame(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane, std::optional< GIT_ADVANCED_PAGE > aPage=std::nullopt)
Raise the one window for this session, creating it on first use.
unsigned m_fetchRequest
Counts the fetches begun, so a keyring read finishing late starts only its own.
~GIT_ADVANCED_DIALOG() override
wxWindow * buildChangesPage(wxWindow *aBook)
The Changes page: the docked panel's commit controls with the selected file's diff below.
GIT_COMMIT_PANE * m_changesPane
int m_changesSashPos
Where the user left the sash between the Changes page's list and its diff area.
wxWeakRef< GIT_COMMIT_PANE > m_pane
Weak because the pane can be destroyed before this dialog's deferred delete runs.
void optOutOfTextPersistence(wxWindow *aWindow)
Keep every text box in aWindow out of the dialog's saved control state.
void setIcons()
The page and toolbar icons, again after a light or dark switch.
void onFetch(bool aRetriedAfterTrust=false)
Fetch from the remote on a worker, then refresh every surface.
void startFetch(std::shared_ptr< KIGIT_COMMON > aCommon, bool aRetriedAfterTrust)
void ShowAmend(const wxString &aCommitHash)
Open the Changes page to amend the selected history commit.
KIGIT_TRANSFER m_fetch
The fetch the top bar started.
PANEL_GIT_TAGS * m_tagsPage
void populateTopBar()
Fill the top bar's repository name and branch list.
Docked panel for committing: the branch to commit to, a summary and description, the commit options,...
void SetBusyChangedHandler(std::function< void(bool)> aHandler)
Called when a transfer starts and when it ends, so an owning window can follow along.
void SetMessageChangedHandler(std::function< void()> aHandler)
Called when the user edits the message, so another form can follow along.
A private scratch directory for extracting committed file versions to diff, removed when this object ...
Shows what changed in one file: the old and new drawing side by side for a schematic or board,...
The project's git session.
static bool DeferForSecret(const std::shared_ptr< KIGIT_COMMON > &aCommon, const std::weak_ptr< bool > &aOwner, std::function< void()> aRetry)
Read the remote's secret from the keyring on the UI thread without blocking it, so an unlock prompt c...
std::shared_ptr< std::atomic< bool > > CANCEL_TOKEN
One token per operation.
wxString GetCurrentBranchName() const
wxString GetGitRootDirectory() const
bool HasPushAndPullRemote() const
static wxString GetLastGitError()
libgit2's last message, without credentials from any URL it quotes, so it is safe to show or trace.
std::vector< KIGIT_BRANCH_INFO > GetBranches() const
Local and remote branches with their tip commits.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
The advanced git window's Branches page: a searchable list beside the selected branch's detail,...
The advanced git window's History page: filters above a list of commits beside the selected commit's ...
The advanced git window's Remotes page: the list beside the selected remote's detail,...
Show the repository's author and open the shared identity editor.
The advanced git window's Stashes page: the list beside the selected stash's detail,...
virtual std::shared_ptr< KIGIT_COMMON > GetGitCommon() const
This project's Git session, created empty on first use.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
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.
static void setActiveDialog(GIT_ADVANCED_DIALOG *aDialog)
static GIT_ADVANCED_DIALOG * activeDialog()
GIT_ADVANCED_PAGE
The advanced window's pages, in the order its sidebar lists them.
bool PrepareEditorsForGitOperation(EDA_BASE_FRAME *aFrame, GIT_EDITOR_PREP aPurpose, bool *aSavedEditors)
Offer to save unsaved schematic and board edits before a git operation.
EDITOR_SNAPSHOT CaptureOpenEditorDocs(KIWAY &aKiway)
Record the on-disk identity of the open documents, before an operation that may rewrite them.
void ReloadOpenEditors(KIWAY &aKiway, const EDITOR_SNAPSHOT &aBefore)
Tell the open board and schematic editors to reload from disk.
void ProjectClearOfUncommittedWork(EDA_BASE_FRAME *aFrame, wxWindow *aParent, KIGIT_QUERY &aQuery, std::function< void(const GIT_WORKTREE_STATUS &)> aReady)
Check the working tree and Git LFS on a worker, then run aReady on the UI thread when the operation c...
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.
void SwitchProjectToBranch(EDA_BASE_FRAME *aFrame, wxWindow *aParent, const wxString &aBranch, KIGIT_QUERY &aQuery, std::function< void()> aFinished)
Check the working tree on a worker, then confirm switching to aBranch and recheck unsaved editors.
@ WORKING_TREE
The working files are about to be rewritten, by a pull, branch switch or stash.
void ClearSyncWarnings(wxWindow *aWindow)
Clear the background fetch's warnings from the frame holding aWindow.
void SortBranchesForDisplay(std::vector< KIGIT_BRANCH_INFO > &aBranches)
Put the current branch first, then local and remote branches with the newest tips first.
std::unique_lock< std::mutex > WaitForActionLock(KIGIT_COMMON &aCommon, wxWindow *aParent)
TryLockAction that first waits a moment for a status read or fetch to let go.
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.
void ShowBusyMessage(wxWindow *aParent)
Show a busy message for a user action. UI thread only.
TRANSFER_RETRY AnswerTransferFailure(wxWindow *aParent, const std::weak_ptr< bool > &aAlive, KIGIT_COMMON *aCommon, PROJECT *aProject, const TRANSFER_FAILURE &aFailure, bool aRetriedAfterTrust, int &aPrompts)
Answer a failed transfer the way every window does.
APIEXPORT wxWindow *& ActiveAdvancedGitWindow()
The advanced git window, or null when none is open.
@ RETRY_TRUSTED
Run it again, now that the server's key is trusted.
@ GONE
The window closed during a prompt, so the caller must not touch it.
@ CANCELLED
Stop and say so, the user cancelled the transfer or a prompt.
@ RETRY
Run the transfer again.
@ REPORT
Show the failure.
@ HOST_DECLINED
Stop without a message, the user chose not to trust the server.
APIEXPORT wxString UnexplainedFailure(KIGIT_OPERATION aOperation, const wxString &aUrl)
The summary for an operation that failed without saying why, naming the server it was talking to.
void CallOnUi(std::function< void()> aFn)
Run aFn on the UI thread.
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
PGM_BASE & Pgm()
The global program "get" accessor.
The two sides of one file, written out for a comparison.
Repository state used before an operation that requires a clean working tree.
Why a transfer to a remote failed.
std::optional< HOST_KEY_FAILURE > hostKey
The server's key is unknown or has changed.
bool authFailure
The remote refused every credential offered.
wxString error
Shown above the credential fields.
A summary the user can act on, with the raw text that explains it kept apart for the details.
wxString result
Test unit parsing edge cases and error handling.
Functions to provide common constants and other functions to assist in making a consistent UI.