فهرست منبع

open project seems to be funcional

Bachir Soussi Chiadmi 7 سال پیش
والد
کامیت
4ee18726f0
5فایلهای تغییر یافته به همراه97 افزوده شده و 29 حذف شده
  1. 28 11
      classes/content.py
  2. 21 11
      classes/core.py
  3. 23 7
      classes/design.py
  4. 22 0
      classes/mainwindow.py
  5. 3 0
      classes/sasscompiler.py

+ 28 - 11
classes/content.py

@@ -23,9 +23,7 @@ class Summary(QWidget):
       super(Summary, self).__init__(parent)
       self.parent = parent
 
-      jsonfilepath = os.path.join(self.parent.core.cwd,'.config/summary.json')
-      sum_json = open(jsonfilepath).read()
-      self.sum = json.loads(sum_json)
+      self.loadJson()
 
       vbox = QVBoxLayout()
       vbox.setContentsMargins(0,0,0,0)
@@ -38,6 +36,12 @@ class Summary(QWidget):
 
       self.setLayout(vbox)
 
+   def loadJson(self):
+      jsonfilepath = os.path.join(self.parent.core.cwd,'.config/summary.json')
+      sum_json = open(jsonfilepath).read()
+      self.sum = json.loads(sum_json)
+
+
    def addItem(self, text):
       # file
       filename = re.sub(r'\W', "_", text)+".md"
@@ -71,6 +75,10 @@ class Summary(QWidget):
       # reload content compiler
       self.parent.core.contentcompiler.reload()
 
+   def reload(self):
+      self.loadJson()
+      self.list.setItems()
+
 class SummaryList(QListWidget):
    def __init__(self, parent):
       super(SummaryList, self).__init__(parent)
@@ -89,9 +97,7 @@ class SummaryList(QListWidget):
 
       self.itemActivated.connect(self.onItemActivated)
 
-      # add markdown files to the list
-      for itemdata in self.parent.sum:
-         self.addNewItem(itemdata)
+      self.setItems()
 
       # self.setCurrentRow(0)
       # self.setCurrentIndex()
@@ -102,6 +108,12 @@ class SummaryList(QListWidget):
       # TODO: show activated item on the list
       # TODO: show modifed item on the list
 
+   def setItems(self):
+      self.clear()
+      # add markdown files to the list
+      for itemdata in self.parent.sum:
+         self.addNewItem(itemdata)
+
    def onRowsMoved(self, model, start, end, dest):
       # print("onRowsMoved")
       self.parent.recordNewList()
@@ -111,7 +123,7 @@ class SummaryList(QListWidget):
 
    def onItemActivated(self, item):
       # print('onItemActivated', item.data)
-      self.parent.parent.editor.openFile()
+      self.parent.parent.editor.openFile(self.currentRow())
 
 
 class SummaryListWidgetItem(QListWidgetItem):
@@ -199,14 +211,14 @@ class MarkdownEditor(QWidget):
 
       self.refreshViewer()
 
-   def openFile(self):
+   def openFile(self, row = 0):
       # print("openFile")
       sumlist = self.parent.summary.list
-      currentitem = sumlist.currentItem()
-      if currentitem:
+      item = sumlist.item(row)
+      if item:
          if not self.changed:
             self.editor.textChanged.disconnect(self.onTextChanged)
-            filename = currentitem.data['file']
+            filename = item.data['file']
             self.file = os.path.join(self.parent.core.cwd,'contents',filename)
             self.editor.clear()
             self.editor.insertPlainText(open(self.file, 'r').read())
@@ -258,6 +270,7 @@ class ContentStack(QWidget):
       self.hsplitter.addWidget(self.summary)
 
       self.editor = MarkdownEditor(self)
+
       self.hsplitter.addWidget(self.editor)
 
       self.hsplitter.splitterMoved.connect(self.movedSplitter)
@@ -279,3 +292,7 @@ class ContentStack(QWidget):
       settings = QSettings('FiguresLibres', 'Cascade')
       # print(self.hsplitter.sizes())
       settings.setValue('content/hsplitter/sizes', self.hsplitter.sizes())
+
+   def refresh(self):
+      self.summary.reload()
+      self.editor.openFile()

+ 21 - 11
classes/core.py

@@ -37,7 +37,12 @@ class Core():
          self.cwd = os.path.join(self.temp, 'cwd')
          self.tempcwd = True
          self.initnewproject()
+         self.initDeamons()
+      else:
+         self.initDeamons()
 
+
+   def initDeamons(self):
       self.server = server.Server(self)
       self.sasscompiler = sasscompiler.Compiler(self)
       self.contentcompiler = md2html.Compiler(self)
@@ -83,19 +88,18 @@ class Core():
       settings.setValue('mainwindow/curstack', self._mw.mainstack.currentIndex())
 
    def initnewproject(self, cwd = None):
+      print('initnewproject')
       if cwd == None :
          cwd = self.cwd
-      else :
-         self.changeCWD(cwd)
 
-      shutil.copytree('templates/newproject', cwd)
+      shutil.copytree(os.path.join(self.appcwd,'templates/newproject'), cwd)
       self.prefs = json.loads(open(os.path.join(cwd,'.config/prefs.json')).read())
       self.summary = json.loads(open(os.path.join(cwd,'.config/summary.json')).read())
       self.repository = git.Repo.init(cwd)
       self.repository.index.add(['assets','contents','.config'])
       self.repository.index.commit("initial commit")
-      # TODO: set mdtohtml compiler from project md to app index.html
-      # TODO: embed project styles.scss to app scss frame work
+
+      self.changeCWD(cwd)
 
    def saveproject(self, cwd = None):
       if not cwd == None:
@@ -103,13 +107,19 @@ class Core():
          self.tempcwd = False
          self.changeCWD(cwd)
 
+   def openproject(self, cwd=None):
+      if not cwd == None:
+         self.changeCWD(cwd)
+
    def changeCWD(self, cwd):
-      self.cwd = cwd
-      self.server.reload()
-      self.sasscompiler.reload()
-      self.contentcompiler.reload()
-      # if not self.tempcwd:
-      self._mw.setWindowTitle("Cascade – "+self.cwd)
+      if not cwd == self.cwd:
+         self.cwd = cwd
+         self._mw.setWindowTitle("Cascade – "+self.cwd)
+         self.server.reload()
+         self.sasscompiler.reload()
+         self.contentcompiler.reload()
+         self._mw.designstack.refresh()
+         self._mw.contentstack.refresh()
 
    def quit(self):
       self.savePreferences()

+ 23 - 7
classes/design.py

@@ -95,20 +95,29 @@ class CodeEditor(QPlainTextEdit):
       super(CodeEditor, self).__init__()
       self.core = core
       self.tabs = tabs
-      # self.file = file
-      self.file = os.path.join(self.core.cwd,file)
+      self.file = file
+      self.setText()
 
-      self.insertPlainText(open(self.file, 'r').read())
+      self.shortcut = QShortcut(QKeySequence("Ctrl+s"), self)
+      self.shortcut.activated.connect(self.save)
+
+   def setText(self):
+      try:
+         self.textChanged.disconnect(self.onTextChanged)
+      except Exception as e:
+         print(e)
+
+      self.filepath = os.path.join(self.core.cwd,self.file)
+      self.clear()
+      self.insertPlainText(open(self.filepath, 'r').read())
       self.changed = False
       self.textChanged.connect(self.onTextChanged)
 
-      self.shortcut = QShortcut(QKeySequence("Ctrl+s"), self)
-      self.shortcut.activated.connect(self.save)
 
    def onTextChanged(self):
       # print('textChanged')
       # print(self.toPlainText())
-      # open(self.file, 'w').write(self.toPlainText())
+      # open(self.filepath, 'w').write(self.toPlainText())
       if not self.changed:
          self.changed = True
          i = self.tabs.currentIndex()
@@ -116,7 +125,7 @@ class CodeEditor(QPlainTextEdit):
 
    def save(self):
       if self.changed:
-         open(self.file, 'w').write(self.toPlainText())
+         open(self.filepath, 'w').write(self.toPlainText())
          i = self.tabs.currentIndex()
          self.tabs.setTabText(i, re.sub(r'^\*\s', '', self.tabs.tabText(i)))
          self.changed = False
@@ -153,6 +162,9 @@ class Editor(QWidget):
       # self.highlighter = Highlighter(self.document())
       # https://pypi.python.org/pypi/QScintilla/2.9.2
 
+   def refresh(self):
+      self.scsstab.setText()
+      self.jstab.setText()
 
 class DesignStack(QWidget):
    def __init__(self, core):
@@ -226,3 +238,7 @@ class DesignStack(QWidget):
       # print(self.vsplitter.sizes())
       settings.setValue('design/vsplitter/sizes', self.vsplitter.sizes())
       settings.setValue('design/hsplitter/sizes', self.hsplitter.sizes())
+
+   def refresh(self):
+      self.editor.refresh()
+      self.webkitview.reload()

+ 22 - 0
classes/mainwindow.py

@@ -110,6 +110,28 @@ class MainWindow(QMainWindow):
 
    def openprojectdialogue(self):
       print("open")
+      dialog = QFileDialog()
+      dialog.setFileMode(QFileDialog.Directory)
+      dialog.setAcceptMode(QFileDialog.AcceptOpen)
+      options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly
+      folder = dialog.getExistingDirectory(
+         self,
+         'Open Project',
+         self.core.dialog_path,
+         options
+      )
+      try:
+         head, tail = os.path.split(folder)
+         self.core.dialog_path = head
+         # TODO: check if is cascade folder
+         print(folder)
+         if os.path.isdir(folder):
+            self.core.openproject(folder)
+         else:
+            print("folder doesn't exists")
+      except Exception as e:
+         print('Exception', e)
+         pass
 
    def newprojectdialogue(self):
       dialog = QFileDialog()

+ 3 - 0
classes/sasscompiler.py

@@ -41,6 +41,9 @@ class Compiler():
             self.paths.append(os.path.join(self.parent.cwd,'assets/css',f))
 
    def reload(self):
+      # print('Reload sass compiler')
       self.fs_watcher.removePaths(self.paths)
       self.refreshPaths()
+      # print('paths', self.paths)
       self.fs_watcher.addPaths(self.paths)
+      # print('files', self.fs_watcher.files())