Commit c2b29ade authored by Kai Willadsen's avatar Kai Willadsen

Make our state saving an enum, for both sanity and better debugging

This way at least we get meaningful names when debugging these state
transitions. Also, it's better in every way.

I've used an IntEnum here just so that I keep the state-changed signal
signature, though there's no reason that needs to remain the same,
really.
parent d7d9b9fb
......@@ -35,8 +35,7 @@ from meld.matchers.helpers import CachedSequenceMatcher
from meld.matchers.merge import Merger
from meld.meldbuffer import (
BufferDeletionAction, BufferInsertionAction, BufferLines)
from meld.melddoc import (
MeldDoc, STATE_CLOSING, STATE_NORMAL, STATE_SAVING_ERROR)
from meld.melddoc import ComparisonState, MeldDoc
from meld.patchdialog import PatchDialog
from meld.recent import RecentType
from meld.settings import bind_settings, meldsettings
......@@ -880,12 +879,12 @@ class FileDiff(MeldDoc, Component):
# idle loop; it might never happen.
parent.command('resolve', [conflict_file], sync=True)
elif response == Gtk.ResponseType.CANCEL:
self.state = STATE_NORMAL
self.state = ComparisonState.Normal
return response
def on_delete_event(self):
self.state = STATE_CLOSING
self.state = ComparisonState.Closing
response = self.check_save_modified()
if response == Gtk.ResponseType.OK:
for h in self.settings_handlers:
......@@ -1636,7 +1635,7 @@ class FileDiff(MeldDoc, Component):
secondary=_("Couldn’t save file due to:\n%s") % (
GLib.markup_escape_text(str(err))),
)
self.state = STATE_SAVING_ERROR
self.state = ComparisonState.SavingError
return
self.emit('file-changed', gfile.get_path())
......@@ -1645,11 +1644,11 @@ class FileDiff(MeldDoc, Component):
if pane == 1 and self.num_panes == 3:
self.meta['middle_saved'] = True
if (self.state == STATE_CLOSING and
if (self.state == ComparisonState.Closing and
not any(b.get_modified() for b in self.textbuffer)):
self.on_delete_event()
else:
self.state = STATE_NORMAL
self.state = ComparisonState.Normal
def make_patch(self, *extra):
dialog = PatchDialog(self)
......
......@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import enum
import logging
import pipes
import shlex
......@@ -50,8 +51,11 @@ def make_custom_editor_command(path, line=0):
return shlex.split(cmd)
# TODO: Consider use-cases for states in gedit-enum-types.c
STATE_NORMAL, STATE_CLOSING, STATE_SAVING_ERROR, NUM_STATES = range(4)
class ComparisonState(enum.IntEnum):
# TODO: Consider use-cases for states in gedit-enum-types.c
Normal = 0
Closing = 1
SavingError = 2
class LabeledObjectMixin(GObject.GObject):
......@@ -93,7 +97,7 @@ class MeldDoc(LabeledObjectMixin, GObject.GObject):
self.scheduler = FifoScheduler()
self.num_panes = 0
self.main_actiongroup = None
self._state = STATE_NORMAL
self._state = ComparisonState.Normal
@property
def state(self):
......
......@@ -24,7 +24,7 @@ from meld.conf import _
from meld.dirdiff import DirDiff
from meld.filediff import FileDiff
from meld.filemerge import FileMerge
from meld.melddoc import MeldDoc, STATE_CLOSING
from meld.melddoc import ComparisonState, MeldDoc
from meld.newdifftab import NewDiffTab
from meld.recent import recent_comparisons, RecentType
from meld.settings import interface_settings, settings
......@@ -515,7 +515,7 @@ class MeldWindow(Component):
self.widget.emit('destroy')
def on_page_state_changed(self, page, old_state, new_state):
if self.should_close and old_state == STATE_CLOSING:
if self.should_close and old_state == ComparisonState.Closing:
# Cancel closing if one of our tabs does
self.should_close = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment