Skip to content

Commit 4ddbcad

Browse files
committed
update
1 parent cd90635 commit 4ddbcad

File tree

4 files changed

+170
-27
lines changed

4 files changed

+170
-27
lines changed

auratext/Components/GitPush.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import subprocess
2+
import os
3+
from PyQt6.QtCore import Qt
4+
from PyQt6.QtWidgets import QListWidget, QVBoxLayout, QWidget, QDockWidget, QPushButton, QListWidgetItem, QCheckBox, \
5+
QMessageBox, QLineEdit, QDialog, QLabel, QComboBox, QSpacerItem
6+
7+
local_app_data = os.path.join(os.getenv("LocalAppData"), "AuraText")
8+
cpath = open(f"{local_app_data}/data/CPath_Project.txt", "r+").read()
9+
10+
11+
class GitPushDialog(QDialog):
12+
def __init__(self, parent=None):
13+
super().__init__(parent)
14+
self.setGeometry(400, 300, 0, 0)
15+
self.setWindowTitle("Git Push")
16+
self.main_layout = QVBoxLayout(self)
17+
self.main_layout.addStretch()
18+
self.branches = ""
19+
20+
spacer_item = QSpacerItem(10, 5)
21+
spacer_item_large = QSpacerItem(20, 20)
22+
23+
label1 = QLabel("Branch:")
24+
self.main_layout.addWidget(label1)
25+
26+
self.branch_list = QComboBox()
27+
self.main_layout.addWidget(self.branch_list)
28+
29+
label2 = QLabel("Remote:")
30+
self.remote_list = QComboBox()
31+
self.main_layout.addWidget(label2)
32+
self.main_layout.addWidget(self.remote_list)
33+
34+
self.command = QLineEdit()
35+
branch = self.branch_list.currentText()
36+
if self.remote_list.currentText() == "":
37+
remote = "origin"
38+
else:
39+
remote = self.remote_list.currentText()
40+
cmd = "git push " + remote + "" + branch
41+
self.command.setText(cmd)
42+
43+
self.main_layout.addSpacerItem(spacer_item)
44+
45+
self.main_layout.addWidget(self.command)
46+
47+
self.main_layout.addSpacerItem(spacer_item_large)
48+
49+
push_button = QPushButton("Push")
50+
self.main_layout.addWidget(push_button)
51+
push_button.clicked.connect(self.push)
52+
53+
try:
54+
result = subprocess.run(['git', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
55+
if result.returncode != 0:
56+
raise FileNotFoundError("Git command not found. Ensure that Git is installed and added to the PATH.")
57+
58+
self.branches = self.get_all_branches()
59+
self.c_branch = self.get_current_branch()
60+
self.remotes = self.get_all_remotes()
61+
self.remotes[0] = "origin"
62+
63+
self.branch_list.addItems(self.branches)
64+
self.remote_list.addItems(self.remotes)
65+
66+
print(self.branches)
67+
68+
except Exception as e:
69+
print(e)
70+
71+
def get_current_branch(self):
72+
result = subprocess.run(['git', 'branch'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cpath, text=True)
73+
if result.returncode == 0:
74+
for line in result.stdout.split('\n'):
75+
if line.startswith('*'):
76+
return line[2:].strip()
77+
else:
78+
raise Exception(f"Failed to get current branch: {result.stderr}")
79+
80+
def get_all_branches(self):
81+
result = subprocess.run(['git', 'branch'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
82+
if result.returncode != 0:
83+
raise Exception(f"Error getting branches: {result.stderr}")
84+
85+
branches = result.stdout.split('\n')
86+
# Strip whitespace, remove empty lines, and remove the '*' from the current branch
87+
branches = [branch[2:] if branch.startswith('*') else branch.strip() for branch in branches if branch.strip()]
88+
return branches
89+
90+
def get_all_remotes(self):
91+
result = subprocess.run(['git', 'remote', '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
92+
if result.returncode != 0:
93+
raise Exception(f"Error getting remotes: {result.stderr}")
94+
95+
remotes = result.stdout.strip().split('\n')
96+
97+
remote_list = []
98+
for line in remotes:
99+
parts = line.split()
100+
if len(parts) >= 2: # Ensure there are enough parts in the line
101+
remote_name = parts[0]
102+
remote_url = parts[1]
103+
remote_list.append((remote_name, remote_url))
104+
105+
# Remove duplicate remotes keeping only one instance
106+
seen = set()
107+
unique_remotes = []
108+
for remote in remote_list:
109+
if remote[0] not in seen:
110+
unique_remotes.append(remote)
111+
seen.add(remote[0])
112+
113+
return unique_remotes
114+
115+
def push(self):
116+
result = subprocess.run((self.command.text()), cwd=cpath, stdout=subprocess.PIPE,
117+
stderr=subprocess.PIPE, text=True)
118+
119+
if result.returncode == 0:
120+
QMessageBox.information(self, 'Push Successful', 'Changes have been pushed.')
121+
else:
122+
QMessageBox.warning(self, 'Push Failed', f"Error: {result.stderr}")
123+
print(f"Push failed: {result.stderr}")

auratext/Components/statusBar.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import time
34

45
from PyQt6.QtGui import QFont
56
from PyQt6.QtWidgets import QFrame, QHBoxLayout, QLabel, QStatusBar, QWidget
@@ -20,6 +21,8 @@ def __init__(self, parent=None):
2021
class StatusBar(QStatusBar):
2122
def __init__(self, parent=None):
2223
super().__init__(parent)
24+
#self.current_editor = parent.current_editor
25+
self.current_widget = parent.tab_widget.currentWidget()
2326
self.setStyleSheet(
2427
f"""
2528
QStatusBar {{
@@ -110,13 +113,7 @@ def updateStats(self, line, column, total_lines, words):
110113

111114
def updateEditMode(self, mode):
112115
self.editModeLabel.setText(mode)
113-
if mode == "ReadOnly":
114-
pass
115-
#self.editModeLabel.setStyleSheet(
116-
# f"color: {color_schemes['editmode_readonly']};"
117-
#)
118-
else:
119-
pass
120-
#self.editModeLabel.setStyleSheet(
121-
# f"color: {color_schemes['editmode_edit']};"
122-
#)
116+
#if mode == "ReadOnly":
117+
# self.current_widget.setReadOnly(True)
118+
#else:
119+
# self.current_widget.setReadOnly(False)

auratext/Core/MenuConfig.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from .plugin_interface import MenuPluginInterface
99

1010
local_app_data = os.path.join(os.getenv("LocalAppData"), "AuraText")
11+
cpath = open(f"{local_app_data}/data/CPath_Project.txt", "r+").read()
12+
1113
with open(f"{local_app_data}/data/theme.json", "r") as themes_file:
1214
_themes = json.load(themes_file)
1315

@@ -61,17 +63,24 @@ def configure_menuBar(self):
6163
file_menu.addAction("Open", self.open_document).setWhatsThis("Open an existing file")
6264
file_menu.addSeparator()
6365
file_menu.addAction("New Project", self.new_project).setWhatsThis("Create a new project")
66+
file_menu.addAction("New Project from VCS", self.gitClone).setWhatsThis("Clone GIT repo")
6467
file_menu.addAction("Open Project", self.open_project).setWhatsThis("Open an existing project")
6568
file_menu.addAction("Open Project as Treeview", self.open_project_as_treeview).setWhatsThis(
6669
"Open an existing project as a treeview dock"
6770
)
6871

6972
git_menu = QMenu("&Git", self)
70-
git_menu.addAction("Clone Project from Git", self.gitClone)
73+
git_menu.addAction("Commit", self.gitCommit)
74+
git_menu.addAction("Push", self.gitPush)
75+
76+
def is_git_repo(path):
77+
return os.path.isdir(os.path.join(path, '.git'))
7178

72-
# Fix indentation here
7379
file_menu.addMenu(new_menu)
74-
file_menu.addMenu(git_menu)
80+
if is_git_repo(cpath):
81+
file_menu.addMenu(git_menu)
82+
else:
83+
pass
7584
file_menu.addSeparator()
7685

7786
file_menu.addAction("Save As", self.save_document).setWhatsThis("Save the document")

auratext/Core/window.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,14 @@
3636
from . import PluginDownload
3737
from . import ThemeDownload
3838
from . import config_page
39-
from ..Components import powershell, terminal, statusBar#, titleBar
39+
from ..Components import powershell, terminal, statusBar, GitCommit, GitPush
4040
from .AuraText import CodeEditor
4141
from auratext.Components.TabWidget import TabWidget
4242
from .plugin_interface import Plugin
4343

4444
local_app_data = os.path.join(os.getenv("LocalAppData"), "AuraText")
45-
46-
47-
path_project = open(f"{local_app_data}/data/CPath_Project.txt", "r+")
48-
cpath = path_project.read()
49-
50-
path_file = open(f"{local_app_data}/data/CPath_File.txt", "r+")
51-
cfile = path_file.read()
45+
cpath = open(f"{local_app_data}/data/CPath_Project.txt", "r+").read()
46+
cfile = open(f"{local_app_data}/data/CPath_File.txt", "r+").read()
5247

5348

5449
class Sidebar(QDockWidget):
@@ -152,6 +147,7 @@ def splashScreen():
152147
self.sidebar_main.setWidget(self.sidebar_widget)
153148
self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, self.sidebar_main)
154149

150+
155151
self.bottom_bar = QStatusBar()
156152
# self.setStatusBar(self.bottom_bar)
157153

@@ -281,8 +277,18 @@ def updateStatusBar(self):
281277
)
282278
self.statusBar.updateStats(lineNumber, columnNumber, totalLines, words)
283279

284-
editMode = "Edit" if not currentWidget.isReadOnly() else "ReadOnly"
285-
self.statusBar.updateEditMode(editMode)
280+
if self.current_editor == "":
281+
editMode = "Edit" if not currentWidget.isReadOnly() else "ReadOnly"
282+
if self.current_editor != "":
283+
self.statusBar.updateEditMode(editMode)
284+
else:
285+
pass
286+
else:
287+
editMode = "Edit" if not self.current_editor.isReadOnly() else "ReadOnly"
288+
if self.current_editor != "":
289+
self.statusBar.updateEditMode(editMode)
290+
else:
291+
pass
286292

287293
def load_plugins(self):
288294
self.plugins = []
@@ -475,6 +481,7 @@ def closeEvent(self, event):
475481
event.accept()
476482

477483
def gitClone(self):
484+
messagebox = QMessageBox()
478485
global path
479486
try:
480487
from git import Repo
@@ -483,7 +490,6 @@ def gitClone(self):
483490
try:
484491
path = filedialog.askdirectory(title="Repo Path", initialdir="./", mustexist=False)
485492
except:
486-
messagebox = QMessageBox()
487493
messagebox.setWindowTitle("Path Error"), messagebox.setText(
488494
"The folder should be EMPTY! Please try again with an EMPTY folder"
489495
)
@@ -493,7 +499,6 @@ def gitClone(self):
493499
Repo.clone_from(repo_url, path)
494500
with open(f"{self.local_app_data}/data/CPath_Project.txt", "w") as file:
495501
file.write(path)
496-
messagebox = QMessageBox()
497502
messagebox.setWindowTitle("Success!"), messagebox.setText(
498503
"The repository has been cloned successfully!"
499504
)
@@ -515,6 +520,15 @@ def markdown_open(self, path_data):
515520
def markdown_new(self):
516521
ModuleFile.markdown_new(self)
517522

523+
def gitCommit(self):
524+
self.gitCommitDock = GitCommit.GitCommitDock(self)
525+
self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.gitCommitDock)
526+
527+
def gitPush(self):
528+
self.gitPushDialog = GitPush.GitPushDialog(self)
529+
self.gitPushDialog.exec()
530+
531+
518532
def open_file(self, index):
519533
path = self.model.filePath(index)
520534
image_extensions = ["png", "jpg", "jpeg", "ico", "gif", "bmp"]
@@ -597,11 +611,11 @@ def html(self):
597611

598612
def toggle_read_only(self):
599613
self.current_editor.setReadOnly(True)
600-
# self.read_only_button.setIcon(self.read_only_icon)
614+
self.statusBar.editModeLabel.setText("ReadOnly")
601615

602616
def read_only_reset(self):
603617
self.current_editor.setReadOnly(False)
604-
# @self.read_only_button.setIcon(self.write_button_icon)
618+
self.statusBar.editModeLabel.setText("Edit")
605619

606620
def cpp(self):
607621
Lexers.cpp(self)

0 commit comments

Comments
 (0)