Cleaning up and adding comments
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// Option 1 (Standard): Console Text Editor.
|
||||
//
|
||||
// Implements the user-facing console loop for the text editor.
|
||||
// Handles line editing, undo/redo logic, and print job queue operations.
|
||||
|
||||
#include "option1.h"
|
||||
#include <iostream>
|
||||
@@ -16,6 +17,9 @@ bool running = true;
|
||||
int lastIndex = 0;
|
||||
std::string deletedLine;
|
||||
|
||||
// Undo the last text modification.
|
||||
// Reverses INSERT/DELETE actions by applying the inverse operation.
|
||||
// Moves reversed action into redoStack.
|
||||
void Undo()
|
||||
{
|
||||
if (!undoStack.IsEmpty()) {
|
||||
@@ -29,6 +33,10 @@ void Undo()
|
||||
redoStack.Push(action);
|
||||
}
|
||||
}
|
||||
|
||||
// Redo the last undone modification.
|
||||
// Re-applies an action previously undone.
|
||||
// Pushes the executed action back into undoStack.
|
||||
void Redo()
|
||||
{
|
||||
if (!redoStack.IsEmpty()) {
|
||||
@@ -43,7 +51,9 @@ void Redo()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Main menu loop for the Console Text Editor.
|
||||
// Provides editing operations, queueing print jobs,
|
||||
// and demonstrating FIFO behavior through job processing.
|
||||
int RunApp()
|
||||
{
|
||||
// Implement the Console Text Editor application logic here
|
||||
@@ -62,31 +72,56 @@ int RunApp()
|
||||
}
|
||||
case 3: {
|
||||
std::cout << "----------Current document----------" << std::endl;
|
||||
for (int i = 0; i < document.GetSize(); i++)
|
||||
std::cout << i + 1 << ". " << document.GetAtIndex(i) << std::endl;
|
||||
std::cout << "------------------------------------\n\n";
|
||||
for (int i = 0; i < document.GetSize(); i++) {
|
||||
std::cout << document.GetAtIndex(i) << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
// Build a single print job containing the entire document.
|
||||
// Snapshot is stored as a single string and enqueued.
|
||||
case 4: {
|
||||
for (int i = 0; i < document.GetSize(); ++i)
|
||||
printQueue.Enqueue(document.GetAtIndex(i));
|
||||
|
||||
std::cout << "----------Printing queue-----------" << std::endl;
|
||||
|
||||
while (!printQueue.IsEmpty())
|
||||
std::cout << printQueue.Dequeue() << std::endl;
|
||||
std::cout << "------------------------------------\n\n";
|
||||
std::cout << "----------Add print job----------" << std::endl;
|
||||
|
||||
if (document.GetSize() == 0) {
|
||||
std::cout << "Document is empty - nothing added to print queue." << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: {
|
||||
std::string job;
|
||||
for (int i = 0; i < document.GetSize(); i++) {
|
||||
job += document.GetAtIndex(i) + "\n";
|
||||
}
|
||||
printQueue.Enqueue(job);
|
||||
std::cout << "Print job added to queue." << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
// Dequeue and print the next print job.
|
||||
// Demonstrates FIFO (First-In-First-Out) queue behavior.
|
||||
case 5: {
|
||||
if (printQueue.IsEmpty()) {
|
||||
std::cout << "No prints jobs in queue." << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
std::string job = printQueue.Dequeue();
|
||||
std::cout << "----------Printing job-----------" << std::endl;
|
||||
std::cout << job << std::endl;
|
||||
std::cout << "------------------------------------\n\n";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
case 6: {
|
||||
std::cout << "----------UNDO----------" <<std::endl;
|
||||
Undo();
|
||||
break;
|
||||
}
|
||||
|
||||
case 6: {
|
||||
case 7: {
|
||||
std::cout << "----------REDO----------" <<std::endl;
|
||||
Redo();
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
// option1.h : Option 1 (Standard): Console Text Editor.
|
||||
// Option 1: Console Text Editor
|
||||
// Uses a doubly linked list for storing document lines,
|
||||
// two stacks for undo/redo operations,
|
||||
// and a queue for print-job management.
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
Reference in New Issue
Block a user