Use multiple-files Save dialog in Document list

Fix #13768, fix #13178, close #13776
This commit is contained in:
Don Ho 2023-06-13 03:28:51 +02:00
parent bdd13c0839
commit 51bddf57ad
7 changed files with 45 additions and 49 deletions

View File

@ -173,7 +173,7 @@ public:
bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from
bool fileCloseAll(bool doDeleteBackup, bool isSnapshotMode = false);
bool fileCloseAllButCurrent();
bool fileCloseAllGiven(const std::vector<int>& krvecBufferIndexes);
bool fileCloseAllGiven(const std::vector<BufferViewInfo>& krvecBuffer);
bool fileCloseAllToLeft();
bool fileCloseAllToRight();
bool fileCloseAllUnchanged();

View File

@ -234,11 +234,10 @@ void Notepad_plus::command(int id)
case IDM_DOCLIST_FILESCLOSEOTHERS:
if (_pDocumentListPanel)
{
vector<SwitcherFileInfo> files = _pDocumentListPanel->getSelectedFiles(id == IDM_DOCLIST_FILESCLOSEOTHERS);
for (size_t i = 0, len = files.size(); i < len; ++i)
{
fileClose((BufferID)files[i]._bufID, files[i]._iView);
}
vector<BufferViewInfo> bufs2Close = _pDocumentListPanel->getSelectedFiles(id == IDM_DOCLIST_FILESCLOSEOTHERS);
fileCloseAllGiven(bufs2Close);
if (id == IDM_DOCLIST_FILESCLOSEOTHERS)
{
// Get current buffer and its view

View File

@ -1213,46 +1213,44 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
return true;
}
bool Notepad_plus::fileCloseAllGiven(const std::vector<int>& krvecBufferIndexes)
bool Notepad_plus::fileCloseAllGiven(const std::vector<BufferViewInfo>& fileInfos)
{
// First check if we need to save any file.
bool noSaveToAll = false;
bool saveToAll = false;
std::vector<int> bufferIndexesToClose;
std::vector<BufferViewInfo> buffersToClose;
// Count the number of dirty file
size_t nbDirtyFiles = 0;
for (const auto& index : krvecBufferIndexes)
for (const auto& i : fileInfos)
{
BufferID id = _pDocTab->getBufferByIndex(index);
Buffer* buf = MainFileManager.getBufferByID(id);
Buffer* buf = MainFileManager.getBufferByID(i._bufID);
if (buf->isDirty())
++nbDirtyFiles;
}
for (const auto& index : krvecBufferIndexes)
for (const auto& i : fileInfos)
{
BufferID id = _pDocTab->getBufferByIndex(index);
Buffer* buf = MainFileManager.getBufferByID(id);
Buffer* buf = MainFileManager.getBufferByID(i._bufID);
if ((buf->isUntitled() && buf->docLength() == 0) || noSaveToAll || !buf->isDirty())
{
// Do nothing, these documents are already ready to close
bufferIndexesToClose.push_back(index);
buffersToClose.push_back(i);
}
else if (buf->isDirty() && !noSaveToAll)
{
if (_activeView == MAIN_VIEW)
{
activateBuffer(id, MAIN_VIEW);
if (!activateBuffer(id, SUB_VIEW))
activateBuffer(i._bufID, MAIN_VIEW);
if (!activateBuffer(i._bufID, SUB_VIEW))
switchEditViewTo(MAIN_VIEW);
}
else
{
activateBuffer(id, SUB_VIEW);
activateBuffer(i._bufID, SUB_VIEW);
switchEditViewTo(SUB_VIEW);
}
@ -1268,17 +1266,17 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int>& krvecBufferIndexes)
if (res == IDYES || res == IDRETRY)
{
if (!fileSave(id))
if (!fileSave(i._bufID))
break; // Abort entire procedure, but close whatever processed so far
bufferIndexesToClose.push_back(index);
buffersToClose.push_back(i);
if (res == IDRETRY)
saveToAll = true;
}
else if (res == IDNO || res == IDIGNORE)
{
bufferIndexesToClose.push_back(index);
buffersToClose.push_back(i);
if (res == IDIGNORE)
noSaveToAll = true;
@ -1292,9 +1290,9 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int>& krvecBufferIndexes)
// Now we close.
bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode();
for (const auto& index : bufferIndexesToClose)
for (const auto& i : buffersToClose)
{
doClose(_pDocTab->getBufferByIndex(index), currentView(), isSnapshotMode);
doClose(i._bufID, i._iView, isSnapshotMode);
}
return true;
@ -1304,32 +1302,32 @@ bool Notepad_plus::fileCloseAllToLeft()
{
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
// indexes (smaller than the one just closed) will point to the wrong tab.
std::vector<int> vecIndexesToClose;
std::vector<BufferViewInfo> bufsToClose;
for (int i = _pDocTab->getCurrentTabIndex() - 1; i >= 0; i--)
{
vecIndexesToClose.push_back(i);
bufsToClose.push_back(BufferViewInfo(_pDocTab->getBufferByIndex(i), currentView()));
}
return fileCloseAllGiven(vecIndexesToClose);
return fileCloseAllGiven(bufsToClose);
}
bool Notepad_plus::fileCloseAllToRight()
{
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
// indexes (smaller than the one just closed) will point to the wrong tab.
const int kiActive = _pDocTab->getCurrentTabIndex();
std::vector<int> vecIndexesToClose;
for (int i = int(_pDocTab->nbItem()) - 1; i > kiActive; i--)
const int iActive = _pDocTab->getCurrentTabIndex();
std::vector<BufferViewInfo> bufsToClose;
for (int i = int(_pDocTab->nbItem()) - 1; i > iActive; i--)
{
vecIndexesToClose.push_back(i);
bufsToClose.push_back(BufferViewInfo(_pDocTab->getBufferByIndex(i), currentView()));
}
return fileCloseAllGiven(vecIndexesToClose);
return fileCloseAllGiven(bufsToClose);
}
bool Notepad_plus::fileCloseAllUnchanged()
{
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
// indexes (smaller than the one just closed) will point to the wrong tab.
std::vector<int> vecIndexesToClose;
std::vector<BufferViewInfo> bufsToClose;
for (int i = int(_pDocTab->nbItem()) - 1; i >= 0; i--)
{
@ -1337,11 +1335,11 @@ bool Notepad_plus::fileCloseAllUnchanged()
Buffer* buf = MainFileManager.getBufferByID(id);
if ((buf->isUntitled() && buf->docLength() == 0) || !buf->isDirty())
{
vecIndexesToClose.push_back(i);
bufsToClose.push_back(BufferViewInfo(_pDocTab->getBufferByIndex(i), currentView()));
}
}
return fileCloseAllGiven(vecIndexesToClose);
return fileCloseAllGiven(bufsToClose);
}
bool Notepad_plus::fileCloseAllButCurrent()

View File

@ -56,6 +56,14 @@ enum SavingStatus {
SaveWritingFailed = 2
};
struct BufferViewInfo {
BufferID _bufID = 0;
int _iView = 0;
BufferViewInfo() = delete;
BufferViewInfo(BufferID buf, int view) : _bufID(buf), _iView(view) {};
};
const TCHAR UNTITLED_STR[] = TEXT("new ");
//File manager class maintains all buffers

View File

@ -82,7 +82,7 @@ public:
return _fileListView.nbSelectedFiles();
};
std::vector<SwitcherFileInfo> getSelectedFiles(bool reverse = false) const {
std::vector<BufferViewInfo> getSelectedFiles(bool reverse = false) const {
return _fileListView.getSelectedFiles(reverse);
};

View File

@ -443,9 +443,9 @@ void VerticalFileSwitcherListView::resizeColumns(int totalWidth)
ListView_SetColumnWidth(_hSelf, 0, totalWidth - totalColWidthDynExceptName);
}
std::vector<SwitcherFileInfo> VerticalFileSwitcherListView::getSelectedFiles(bool reverse) const
std::vector<BufferViewInfo> VerticalFileSwitcherListView::getSelectedFiles(bool reverse) const
{
std::vector<SwitcherFileInfo> files;
std::vector<BufferViewInfo> files;
LVITEM item{};
int nbItem = ListView_GetItemCount(_hSelf);
int i = 0;
@ -460,7 +460,7 @@ std::vector<SwitcherFileInfo> VerticalFileSwitcherListView::getSelectedFiles(boo
ListView_GetItem(_hSelf, &item);
TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;
files.push_back(SwitcherFileInfo(static_cast<BufferID>(tlfs->_bufID), tlfs->_iView));
files.push_back(BufferViewInfo(static_cast<BufferID>(tlfs->_bufID), tlfs->_iView));
}
}

View File

@ -19,9 +19,7 @@
#include "Window.h"
#include "TaskListDlg.h"
class Buffer;
typedef Buffer * BufferID; //each buffer has unique ID by which it can be retrieved
#include "Buffer.h"
#define SORT_DIRECTION_NONE -1
#define SORT_DIRECTION_UP 0
@ -33,13 +31,6 @@ typedef Buffer * BufferID; //each buffer has unique ID by which it can be retrie
#define FS_CLMNPATH "ColumnPath"
#define FS_LVGROUPS "ListGroups"
struct SwitcherFileInfo {
BufferID _bufID = 0;
int _iView = 0;
SwitcherFileInfo() = delete;
SwitcherFileInfo(BufferID buf, int view) : _bufID(buf), _iView(view){};
};
class VerticalFileSwitcherListView : public Window
{
@ -70,7 +61,7 @@ public:
return static_cast<int32_t>(SendMessage(_hSelf, LVM_GETSELECTEDCOUNT, 0, 0));
};
std::vector<SwitcherFileInfo> getSelectedFiles(bool reverse = false) const;
std::vector<BufferViewInfo> getSelectedFiles(bool reverse = false) const;
void reload();
void ensureVisibleCurrentItem() const {
ListView_EnsureVisible(_hSelf, _currentIndex, false);