Skip to content

Commit

Permalink
Fix CMD_insertfile() / Disable "Save selection as" unless there is a …
Browse files Browse the repository at this point in the history
…selection
  • Loading branch information
jtuc committed Nov 1, 2017
1 parent e670dbf commit be338b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
43 changes: 15 additions & 28 deletions FRHED/hexwnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,6 @@ BOOL HexEditorWindow::queryCommandEnabled(UINT id)
// All kinds of editing disabled for drives
return !bReadOnly && Drive == 0;
case IDM_COPY_HEXDUMP:
case IDM_SAVESELAS:
case IDM_SELECT_ALL:
// "Select All" is allowed if file is not empty.
case IDM_SELECT_BLOCK:
Expand Down Expand Up @@ -2380,6 +2379,9 @@ BOOL HexEditorWindow::queryCommandEnabled(UINT id)
case IDM_EDIT_COPY:
// "Copy" is allowed if there is a selection or the caret is on a byte.
return bSelected || iCurByte < m_dataArray.size();
case IDM_SAVESELAS:
// "Save selection as" is allowed if there is a selection.
return bSelected;
case IDM_EDIT_PASTE:
// No editing of drives
if (Drive != 0)
Expand Down Expand Up @@ -4984,7 +4986,7 @@ BOOL HexEditorWindow::select_next_diff(BOOL bFromStart)
BYTE *buffer = get_buffer(length);
int sibling_length = sibling->get_length();
BYTE *sibling_buffer = sibling->get_buffer(sibling_length);
int i = bFromStart ? 0 : bSelected ? iGetEndOfSelection() + 1 : iCurByte;
int i = bFromStart ? 0 : iGetEndOfSelection(1);
while (i < length && i < sibling_length && buffer[i] == sibling_buffer[i])
++i;
int j = i;
Expand Down Expand Up @@ -5171,27 +5173,17 @@ void HexEditorWindow::CMD_insertfile()
int inslen = _filelength(fhandle);
if (inslen != -1)
{
int rs,re,rl;//Remove start, end, len
if (bSelected)
{
rs = iGetStartOfSelection();
re = iGetEndOfSelection();
rl = re + 1 - rs;
}
else
{
rs = iCurByte;
rl = 0;
}
//Remove start, len
int const rs = iGetStartOfSelection();
int const rl = iGetEndOfSelection(1) - rs;
//New & old lens
int ol = m_dataArray.capacity();
int nl = ol + inslen - rl;
bool rssuc = inslen <= rl || get_buffer(nl); // resize succesful
if (rssuc)
int const ol = m_dataArray.size();
int const nl = ol + inslen - rl;
if (inslen <= rl || get_buffer(nl)) // resize successful
{
UndoRecord::Data *olddata = NULL;
if (bSelected)
olddata = UndoRecord::alloc(&m_dataArray[rs], re - rs + 1);
olddata = UndoRecord::alloc(&m_dataArray[rs], rl);
BYTE *src = &m_dataArray[rs + rl];
BYTE *dst = &m_dataArray[rs + inslen];
int count = ol - (rs + rl);
Expand Down Expand Up @@ -5270,13 +5262,8 @@ void HexEditorWindow::CMD_saveselas()
if (filehandle != -1)
{
WaitCursor wc;
int lower = 0;
int upper = m_dataArray.size();
if (bSelected)
{
lower = iGetStartOfSelection();
upper = iGetEndOfSelection() + 1;
}
int const lower = iGetStartOfSelection();
int const upper = iGetEndOfSelection(1);
if (_write(filehandle, &m_dataArray[lower], upper - lower) != -1)
complain = 0;
_close(filehandle);
Expand All @@ -5302,9 +5289,9 @@ int HexEditorWindow::iGetStartOfSelection()
}

//-------------------------------------------------------------------
int HexEditorWindow::iGetEndOfSelection()
int HexEditorWindow::iGetEndOfSelection(int iInclusive)
{
return bSelected ? max(iStartOfSelection, iEndOfSelection) : iCurByte;
return bSelected ? max(iStartOfSelection, iEndOfSelection) + iInclusive : iCurByte;
}

bool HexEditorWindow::load_hexfile(hexfile_stream &hexin)
Expand Down
2 changes: 1 addition & 1 deletion FRHED/hexwnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class HexEditorWindow
public:
int iGetCharsPerLine();
int iGetStartOfSelection();
int iGetEndOfSelection();
int iGetEndOfSelection(int iInclusive = 0);
virtual int STDMETHODCALLTYPE CMD_setselection(int iSelStart, int iSelEnd);// MF new function

//GK20AUG2K
Expand Down

0 comments on commit be338b7

Please sign in to comment.