Skip to content

Commit

Permalink
corrected issues when loading new files and with new
Browse files Browse the repository at this point in the history
when a new file was loaded or new was selected, the lines previously in
the document were not reported as being deleted and upon new, the last
line 'empty' remaining was not reported as deleted, but this should not
be reported if all the characters and lines in the document are deleted

a number of additional checks were added to the document changed routine
to catch all of these situations, including not setting the remaining
line 0 as modified when new is selected

also corrected a problem when loading an empty file over an existing
non-empty where the window modified flag was still set

the focus policy of the list view widget in the program view dock
widget was set to no focus so that it does not grab the focus from the
edit box
  • Loading branch information
thunder422 committed Mar 10, 2013
1 parent 60e1253 commit 65bd6a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
27 changes: 22 additions & 5 deletions editbox.cpp
Expand Up @@ -199,13 +199,30 @@ void EditBox::documentChanged(int position, int charsRemoved, int charsAdded)
int newLineCount = document()->blockCount();
int netLineCount = newLineCount - m_lineCount;

if (linesModified != 0 || netLineCount != 0) // multiple lines affected?
if (document()->isEmpty())
{
if (document()->isEmpty() && !cursorMoved)
if (!cursorMoved)
{
m_lineModified = -1;
return;
if (charsAdded == 1)
{
m_lineModified = -2;
return;
}
if (m_lineCount == 0)
{
return;
}
}
if (!cursorMoved || m_lineModified == -2)
{
netLineCount = -m_lineCount;
newLineCount = 0;
changeAtLineBegin = true;
}
}

if (linesModified != 0 || netLineCount != 0) // multiple lines affected?
{
if (linesModified == netLineCount && changeAtLineBegin)
{
// single line changed and at begin of line
Expand Down Expand Up @@ -273,7 +290,7 @@ void EditBox::documentChanged(int position, int charsRemoved, int charsAdded)
}
m_lineCount = newLineCount;
}
m_lineModified = cursor.blockNumber();
m_lineModified = m_lineModified == -2 ? -1 : cursor.blockNumber();
}


Expand Down
2 changes: 2 additions & 0 deletions mainwindow.cpp
Expand Up @@ -390,6 +390,8 @@ bool MainWindow::programLoad(const QString &programPath)

m_editBox->setPlainText(input.readAll());
m_editBox->resetModified();
// reset modified flag in case file loaded is empty and document wasn't
setWindowModified(false);

setCurProgram(programPath);
statusBar()->showMessage(tr("Program loaded"), 2000);
Expand Down
3 changes: 3 additions & 0 deletions mainwindow.ui
Expand Up @@ -120,6 +120,9 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="programView">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
Expand Down

0 comments on commit 65bd6a9

Please sign in to comment.