Skip to content

Commit

Permalink
Merge pull request #81 from 3colorr/v1.1.3
Browse files Browse the repository at this point in the history
V1.1.3
  • Loading branch information
3colorr authored Oct 20, 2023
2 parents 8eae709 + 666a79d commit c7f9f8e
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 38 deletions.
44 changes: 35 additions & 9 deletions Mizuame/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct ContentView: View {
private let io: DataIO
private var data: StickyNote

private let redoUndoManager: RedoUndo

init(delegate: AppDelegate) {
self.delegate = delegate
self.io = DataIO()
Expand All @@ -54,6 +56,8 @@ struct ContentView: View {
}

_stickyText = State(initialValue: self.data.contents[0].body)

redoUndoManager = RedoUndo(initialNote: self.data.contents[0].body)
}

var body: some View {
Expand Down Expand Up @@ -84,12 +88,28 @@ struct ContentView: View {
if isShowSavingMessage && !isExecutableSave {
Text("sitickynote.menu.message.saving")
.padding(.horizontal, 5)
.layoutPriority(1)
.layoutPriority(2)
}

Spacer()
.layoutPriority(1)

Button(action: {
stickyText = redoUndoManager.undo()
}, label: {
Image(systemName: "return.left")
})
.hidden()
.keyboardShortcut("z", modifiers: [.command])

Button(action: {
stickyText = redoUndoManager.redo()
}, label: {
Image(systemName: "return.right")
})
.hidden()
.keyboardShortcut("y", modifiers: [.command])

if isPinNote {
Image(systemName: "pin")
.foregroundColor(Color.red)
Expand Down Expand Up @@ -133,6 +153,7 @@ struct ContentView: View {
.foregroundColor(Color(bodyForegroundTheme))
}
.buttonStyle(SettingsLinkStyle())
.keyboardShortcut(",", modifiers: [.command])
.onHover { _ in
isShowMessagebar = false
userAction = .NONE
Expand All @@ -141,14 +162,16 @@ struct ContentView: View {
// .onTapGesture {}

} else {
Image(systemName: "gearshape.fill")
.foregroundColor(Color(bodyForegroundTheme))
.onTapGesture {
isShowMessagebar = false
userAction = .NONE

delegate.showSettings()
}
Button(action: {
isShowMessagebar = false
userAction = .NONE
delegate.showSettings()
}, label: {
Image(systemName: "gearshape.fill")
.foregroundColor(Color(bodyForegroundTheme))
})
.buttonStyle(SettingsLinkStyle())
.keyboardShortcut(",", modifiers: [.command])
}
}
.padding(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
Expand All @@ -169,6 +192,9 @@ struct ContentView: View {
.scrollContentBackground(.hidden)
.background(Color(bodyBackgroundTheme))
.onChange(of: stickyText) { val in

_ = redoUndoManager.snapshot(of: val)

if isExecutableSave {
Task {
do {
Expand Down
8 changes: 8 additions & 0 deletions Mizuame/DataModel/CalculateModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// CalculateModel.swift
// Mizuame
//
// Created by becomefoolish on 2023/10/14.
//

import Foundation
70 changes: 70 additions & 0 deletions Mizuame/RedoUndo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// RedoUndo.swift
// Mizuame
//
// Created by Nakamura Akira(3colorr) on 2023/10/15.
//

import Foundation

class RedoUndo {
private let MAX_HISTORIES: Int = 30

private var currentIndex: Int = 0
private var noteHistories: [String] = []

init(initialNote: String) {
noteHistories.append(initialNote)
}

// Store snapshot of notes.
// If user was executing redo or undo, this function is not store snapshot of note.
public func snapshot(of note: String) -> Bool {

if note == noteHistories[currentIndex] {
return false
}

if noteHistories.count == MAX_HISTORIES {
noteHistories.removeFirst()
noteHistories.append(note)
currentIndex = noteHistories.count - 1

return true
}

if currentIndex < noteHistories.count - 1 {
noteHistories.removeSubrange((currentIndex + 1)..<noteHistories.count)
noteHistories.append(note)
currentIndex = noteHistories.count - 1

return true
}


noteHistories.append(note)
currentIndex += 1

return true
}

// Return a next generation note.
// If there is no next generation, return the current generation.
public func redo() -> String {
if currentIndex + 1 < noteHistories.count {
currentIndex += 1
}

return noteHistories[currentIndex]
}

// Return a previous generation note.
// If there is no previous generation, return the current generation.
public func undo() -> String {
if currentIndex > 0 {
currentIndex -= 1
}

return noteHistories[currentIndex]
}
}
8 changes: 4 additions & 4 deletions Mizuame/Settings/SettingKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ struct SettingKeys {
let keyHeight: String = "stickyNoteHeight"
let initialWidth: Int = 300
let initialHeight: Int = 150
let minWidth: Int = 150
let maxWidth: Int = 1000
let minHeight: Int = 80
let maxHeight: Int = 1000
let minWidth: NSNumber = 200
let maxWidth: NSNumber = 1000
let minHeight: NSNumber = 100
let maxHeight: NSNumber = 1000

let keyPinNote: String = "stickyNotePin"
let initialPinNote: Bool = false
Expand Down
2 changes: 1 addition & 1 deletion Mizuame/Settings/TabInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct TabInfo: View {
}

VStack(alignment: .leading, spacing: 5) {
Text("Version: 1.1.2").font(.body)
Text("Version: 1.1.3").font(.body)
Text("License: MIT license").font(.body)
HStack {
Text("settings.tab.info.src").font(.body)
Expand Down
34 changes: 13 additions & 21 deletions Mizuame/Settings/TabStickyNote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ struct TabStickyNote: View {
private let INIT_BODY_BACKGROUND_THEME: String = SettingKeys.StickyNoteColor().initialBackgroundTheme
private let INIT_FRAME_THEME: String = SettingKeys.FrameColor().initialTheme

private var numberFormatter = NumberFormatter()
private var noteWidthFormatter = NumberFormatter()
private var noteHeightFormatter = NumberFormatter()

init() {
numberFormatter.minimumIntegerDigits = 1
numberFormatter.maximumIntegerDigits = 4
noteWidthFormatter.minimumIntegerDigits = 1
noteWidthFormatter.maximumIntegerDigits = 4
noteWidthFormatter.minimum = SettingKeys.StickyNote().minWidth
noteWidthFormatter.maximum = SettingKeys.StickyNote().maxWidth

noteHeightFormatter.minimumIntegerDigits = 1
noteHeightFormatter.maximumIntegerDigits = 4
noteHeightFormatter.minimum = SettingKeys.StickyNote().minHeight
noteHeightFormatter.maximum = SettingKeys.StickyNote().maxHeight
}

var body: some View {
Expand Down Expand Up @@ -70,30 +78,14 @@ struct TabStickyNote: View {

HStack {
Text("settings.tab.stickynote.window.size.width")
TextField("\(INIT_WIDTH)", value: $width, formatter: NumberFormatter())
TextField("\(INIT_WIDTH)", value: $width, formatter: noteWidthFormatter)
.frame(width: 80)
.padding(EdgeInsets(top: 2, leading: 0, bottom: 2, trailing: 10))
.onChange(of: width) { val in
if val < SettingKeys.StickyNote().minWidth {
width = SettingKeys.StickyNote().minWidth
}
if val > SettingKeys.StickyNote().maxWidth {
width = SettingKeys.StickyNote().maxWidth
}
}

Text("settings.tab.stickynote.window.size.height")
TextField("\(INIT_HEIGHT)", value: $height, formatter: NumberFormatter())
TextField("\(INIT_HEIGHT)", value: $height, formatter: noteHeightFormatter)
.frame(width: 80)
.padding(EdgeInsets(top: 2, leading: 10, bottom: 2, trailing: 0))
.onChange(of: height) { val in
if val < SettingKeys.StickyNote().minHeight {
height = SettingKeys.StickyNote().minHeight
}
if val > SettingKeys.StickyNote().maxHeight {
height = SettingKeys.StickyNote().maxHeight
}
}
}

Text("settings.tab.stickynote.theme")
Expand Down
70 changes: 70 additions & 0 deletions MizuameTests/MizuameTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,74 @@ final class MizuameTests: XCTestCase {
XCTAssertEqual(data?.contents[1].markercolor, "000000")
XCTAssertEqual(data?.contents[1].body, "test2")
}

// Test RedoUndo class.
//
// String data for testing
// testText = "abc"
// Prepare
// RedoUndo instance is initialized with testText.
//
// test 1: Add "efg" to testText then store testText.
// expected 1: snapshot(of note: String) returns true.
//
// test 2: Run "Undo".
// expected 2: undo() returns "abc".
//
// test 3: Run "Redo".
// expected 3: redo() returns "abcefg".
//
// test 4: Run "Redo" again.(A upper limit of redo history test)
// expected 4: redo() returns "abcefg".
//
// test 5: Run "Undo" then store testText.
// expected 5-1: undo() returns "abc".
// expected 5-2: snapshot(of note: String) returns false.
// Because can not store same strings.
//
// test 6: Run "Undo" again.(A lower limit of undo history test)
// expected 6: undo() returns "abc".
//
// test 7: Store testText while add "x(=1...30)" to one then Run "Undo" 30 times.
// (A upper limit of history test)
// expected 7: 30th undo() returns "abc1".
//
func testRedoUndo() throws {
var testText = "abc"
let manager = RedoUndo(initialNote: testText)

// test 1
testText += "efg"
XCTAssertTrue(manager.snapshot(of: testText))

// test 2
XCTAssertEqual(manager.undo(), "abc")

// test 3
XCTAssertEqual(manager.redo(), "abcefg")

// test 4
XCTAssertEqual(manager.redo(), "abcefg")

// test 5
testText = manager.undo()
XCTAssertEqual(testText, "abc") //5-1
XCTAssertFalse(manager.snapshot(of: testText)) //5-2

// test 6
testText = manager.undo()
XCTAssertEqual(testText, "abc")

// test 7
for x in 1...30 {
testText += String(x)
_ = manager.snapshot(of: testText)
}

for _ in 1...30 {
_ = manager.undo()
}

XCTAssertEqual(manager.undo(), "abc1")
}
}
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@
The app Mizuame is a note on menu bar of Mac.
However, this app is NOT a high performance note app so that you should use other better apps to save your important data.

What is a Good point about the Mizuame?
- It is simple with a few features.
- Quick access from the menu bar.
- Keep your desktop and dock clean.

What is NOT SO GOOD point about the Mizuame?
- You cannot sync data with other devices. (e.g. iPad, Windows)
- This app cannot backup your data, so that your data may be lost unintentionally due to device failure.
- You cannot paste images.

# Website
- Website
- https://3colorr.github.io/Mizuame-pages/
- Repository
- https://github.com/3colorr/Mizuame-pages

# Current state
- main branch
- Releases
# Branch
- main
- Releases.
- Others
- Development.
- It likely contain errors.
Expand Down

0 comments on commit c7f9f8e

Please sign in to comment.