37#include <wx/bmpbndl.h>
38#include <wx/filename.h>
41#include <wx/splitter.h>
42#include <wx/treectrl.h>
63 for( wxWindow* child : aWindow->GetChildren() )
65 if(
dynamic_cast<wxTextEntry*
>( child ) )
92 m_book->SetFitToCurrentPage(
true );
95 wxVector<wxBitmapBundle> pageIcons;
103 m_book->SetImages( pageIcons );
130 [
this]( wxCommandEvent& )
139 m_pane->SetBusyChangedHandler(
147 [
this]( wxCommandEvent& )
152 [
this]( wxCommandEvent& )
158 [
this]( wxCommandEvent& )
176 m_book->GetTreeCtrl()->InvalidateBestSize();
178 for(
size_t i = 0; i <
m_book->GetPageCount(); ++i )
179 m_book->GetPage( i )->Layout();
184 wxSize treeSize =
m_book->GetTreeCtrl()->GetSize();
186 m_book->GetTreeCtrl()->SetMinSize( treeSize );
190 m_book->SetMinSize( FromDIP( wxSize( 800, 600 ) ) );
195 [
this]( wxCommandEvent& )
235 dialog->Bind( wxEVT_CLOSE_WINDOW,
236 [dialog]( wxCloseEvent& )
244 dialog->
Show(
false );
290 m_pane->SetBusyChangedHandler(
nullptr );
291 m_pane->SetMessageChangedHandler(
nullptr );
302 session->RemoveRefreshListener(
this );
308 std::shared_ptr<KIGIT_COMMON> common =
m_parent->Prj().GetGitCommon();
320 common->AddRefreshListener(
this,
337 m_pane->SetTransferBusy( aBusy, aStatus );
346 m_pane->ShowTransferProgress( aText );
376 m_book->SetSelection( 1 );
386 m_book->SetSelection( 0 );
393 wxPanel* panel =
new wxPanel( aBook );
394 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
397 m_changesSplitter =
new wxSplitterWindow( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
398 wxSP_LIVE_UPDATE | wxSP_3DSASH );
410 panel->SetSizer( sizer );
426 m_pane->SetMessageChangedHandler(
434 [
this](
const wxString& aPath )
452 if( aPath.IsEmpty() || !
m_parent->Prj().GetGitCommon()->GetRepo() )
460 wxString baseLabel = branch.IsEmpty() ?
_(
"BASE (HEAD)" ) : wxString::Format(
_(
"BASE (%s)" ), branch );
466 return MaterializeWorkingFile( aCommon, aWorkspace, path, aSides );
468 baseLabel,
_(
"WORKING (changes)" ) );
490 std::vector<KIGIT_BRANCH_INFO> branches;
493 std::shared_ptr<KIGIT_COMMON> common =
m_parent->Prj().GetGitCommon();
494 auto result = std::make_shared<RESULT>();
507 if( common !=
m_parent->Prj().GetGitCommon() || common->IsShuttingDown() )
510 wxFileName root = wxFileName::DirName(
result->root );
511 m_repoName->SetLabel( root.GetDirs().empty() ? root.GetFullPath() : root.GetDirs().Last() );
540 std::shared_ptr<KIGIT_COMMON> common =
m_parent->Prj().GetGitCommon();
541 auto hasRemote = std::make_shared<bool>(
false );
554 [
this, common, hasRemote]()
582 bool fetched =
false;
584 bool authFailure =
false;
585 bool cancelled =
false;
588 auto outcome = std::make_shared<OUTCOME>();
594 aCommon->ClearAuthFailure();
596 GIT_PULL_HANDLER handler( aCommon.get() );
597 handler.SetProgressReporter( std::make_unique<KIGIT_STATUS_REPORTER>(
599 [dialog]( const wxString& aText )
601 dialog->ShowTransferProgress( aText );
603 handler.SetCancelToken( aToken );
604 handler.SetWaitForActionLock(
true );
605 outcome->fetched = handler.PerformFetch();
606 outcome->error = handler.GetErrorStrings().empty() ? wxString() : handler.GetErrorString();
607 outcome->authFailure = aCommon->WasAuthFailure();
611 outcome->cancelled = handler.IsThisOperationCancelled();
614 if( outcome->fetched && !outcome->cancelled )
619 aCommon->NotifyRefreshListeners();
623 [
this, aCommon, outcome]()
625 if( !SessionStillCurrent() )
628 m_fetchButton->SetLabel(
_(
"Fetch" ) );
629 m_fetchButton->Enable();
630 SetPaneTransferBusy(
false );
633 if( outcome->cancelled || outcome->fetched )
647 m_fetchButton->SetLabel(
_(
"Fetch" ) );
648 m_fetchButton->Enable();
649 SetPaneTransferBusy(
false );
700 if( IsBeingDeleted() ||
m_parent->IsBeingDeleted() )
706 &&
Pgm().GetCommonSettings()->m_Git.enableGit && !
m_parent->Prj().GetLocalSettings().m_GitIntegrationDisabled )
722 bool aRewritesWorkingTree )
727 return aFn( aCommon );
729 aError, aRewritesWorkingTree );
734 const wxString& aError,
bool aRewritesWorkingTree )
747 if( !lock.owns_lock() )
750 ok = aFn( *common,
detail );
757 if( aRewritesWorkingTree )
760 common->NotifyRefreshListeners();
767 if( aRewritesWorkingTree )
773 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
GIT_ADVANCED_DIALOG(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane)
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 ...
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
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.
void startFetch(std::shared_ptr< KIGIT_COMMON > aCommon)
PANEL_GIT_STASHES * m_stashesPage
void syncListener()
Attach once to the project's session.
static void ShowForFrame(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane)
Raise the one window for this session, creating it on first use.
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.
void onFetch()
Fetch from the remote on a worker, then refresh every surface.
void SetPaneTransferBusy(bool aBusy, const wxString &aStatus=wxEmptyString)
Put the hosted commit panel into, or out of, its transfer state, for a transfer this window or one of...
~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.
void optOutOfTextPersistence(wxWindow *aWindow)
Keep every text box in aWindow out of the dialog's saved control state.
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.
std::shared_ptr< std::atomic< bool > > CANCEL_TOKEN
One token per operation.
static wxString GetLastGitError()
wxString GetCurrentBranchName() const
wxString GetGitRootDirectory() const
bool HasPushAndPullRemote() const
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()
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 SortBranchesForDisplay(std::vector< KIGIT_BRANCH_INFO > &aBranches)
Put the current branch first, then local and remote branches with the newest tips first.
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.
bool PromptForCredentials(wxWindow *aParent, KIGIT_COMMON *aCommon, PROJECT *aProject=nullptr)
Ask the user for the credentials of the session's remote and apply them to the session.
void ShowBusyMessage(wxWindow *aParent)
Show a busy message for a user action. UI thread only.
std::unique_lock< std::mutex > TryLockAction(KIGIT_COMMON &aCommon, wxWindow *aParent)
Try the action lock and show a busy message if it is unavailable.
APIEXPORT wxWindow *& ActiveAdvancedGitWindow()
The advanced git window, or null when none is open.
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.
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.