summaryrefslogtreecommitdiff
path: root/cad/src/operations/undo_UI.py
blob: 233cc35aef2f014753a48fb589853633056cd22b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Copyright 2005-2007 Nanorex, Inc.  See LICENSE file for details.
"""
undo_UI.py - Undo-related main menu commands other than Undo/Redo themselves

@author: bruce
@version: $Id$
@copyright: 2005-2007 Nanorex, Inc.  See LICENSE file for details.

History:

bruce 071025 split this out of undo_manager.py
to rationalize import dependencies

TODO:

- general cleanup, especially of comments

WARNING: most comments have not been not reviewed since this code was moved
out of undo_manager.py [as of 071025], so they may be misleadingly out of
context.
"""

from utilities.debug import print_compact_traceback

import foundation.env as env
from utilities.Log import greenmsg, redmsg, _graymsg

from widgets.widget_helpers import PleaseConfirmMsgBox

# ==

def editMakeCheckpoint(win):
    """
    This is called from MWsemantics.editMakeCheckpoint,
    which is documented as:

      "Slot for making a checkpoint (only available when
       Automatic Checkpointing is disabled)."
    """
    env.history.message( greenmsg("Make Checkpoint"))
    # do it
    try:
        #REVIEW: Should make sure this is correct with or without
        # auto-checkpointing enabled, and leaves that setting unchanged.
        # (This is not urgent, since in present UI it can't be called
        #  except when auto-checkpointing is disabled.)
        um = win.assy.undo_manager
        if um:
            um.make_manual_checkpoint()
            # no msg needed, was emitted above:
            ## env.history.message(greenmsg("Make Checkpoint"))
            pass
        else:
            # this should never happen
            msg = "Make Checkpoint: error, no undo_manager"
            env.history.message(redmsg(msg))
    except:
        print_compact_traceback("exception caught in editMakeCheckpoint: ")
        msg = "Internal error in Make Checkpoint. " \
              "Undo/Redo might be unsafe until a new file is opened."
        env.history.message(redmsg(msg))
            #e that wording assumes we can't open more than one file at a time...
    return

def editClearUndoStack(win):
    """
    This is called from MWsemantics.editClearUndoStack,
    which is documented as:

      "Slot for clearing the Undo Stack.  Requires the user to confirm."
    """
    #bruce 060304, modified from Mark's prototype in MWsemantics

    #e the following message should specify the amount of data to be lost...
    #e and the menu item text also should
    msg = "Please confirm that you want to clear the Undo/Redo Stack.<br>" + \
          _graymsg("(This operation cannot be undone.)")
    confirmed = PleaseConfirmMsgBox( msg)
        # TODO: I bet this needs a "don't show this again" checkbox...
        # with a prefs key...
    if not confirmed:
        env.history.message("Clear Undo Stack: Cancelled.") #k needed??
        return
    # do it
    env.history.message(greenmsg("Clear Undo Stack"))
        # no further message needed if it works, I think
    try:
        ##e Note: the following doesn't actually free storage.
        # [update, 060309 -- i think as of a few days ago it does try to... ##k]
        # Once the UI seems to work, we'll either add that to it,
        # or destroy and remake assy.undo_manager itself before doing this
        # (and make sure destroying it frees storage).
        ##e Make sure this can be called with or without auto-checkpointing
        # enabled, and leaves that setting unchanged. #####@@@@@
        win.assy.clear_undo_stack()
    except:
        print_compact_traceback("exception in clear_undo_stack: ")
        msg = "Internal error in Clear Undo Stack. " \
              "Undo/Redo might be unsafe until a new file is opened."
        env.history.message(redmsg(msg))
            #e that wording assumes we can't open more than one file at a time...
    return

# bugs in editClearUndoStack [some fixed as of 060304 1132p PST, removed now]:
# cosmetic:
# + [worked around in this code, for now] '...' needed in menu text;
# - it ought to have ram estimate in menu text;
# - "don't show again" checkbox might be needed
# - does the dialog (or menu item if it doesn't have one) need a wiki help
#   link?
# - dialog starts out too narrow
# - when Undo is disabled at the point where stack was cleared, maybe text
#   should say it was cleared? "Undo stack cleared (%d.)" ???

# end